blob: c74a27c0dfdd6173e2c9f3c5b23ce805857aa429 [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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Tated4533f142010-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 Tated4533f142010-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 Tated4533f142010-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 Tated4533f142010-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 Tated4533f142010-10-19 15:15:08 -0700664 mNotifiedWindows.clear();
665 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700666 evt.recycle();
667 }
668
Chris Tated4533f142010-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 Tated4533f142010-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 Tated4533f142010-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 Tated4533f142010-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 Tated4533f142010-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 Tated4533f142010-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
827 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
828 boolean endDrag = false;
829 final float newX = event.getRawX();
830 final float newY = event.getRawY();
831
832 try {
833 if (mDragState != null) {
834 switch (event.getAction()) {
835 case MotionEvent.ACTION_DOWN: {
836 if (DEBUG_DRAG) {
837 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
838 }
839 } break;
840
841 case MotionEvent.ACTION_MOVE: {
842 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700843 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700844 mDragState.notifyMoveLw(newX, newY);
845 }
846 } break;
847
848 case MotionEvent.ACTION_UP: {
849 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
850 + newX + "," + newY);
851 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700852 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700853 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700854 } break;
855
856 case MotionEvent.ACTION_CANCEL: {
857 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
858 endDrag = true;
859 } break;
860 }
861
862 if (endDrag) {
863 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
864 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700865 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700866 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700867 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700868 }
869 }
870 } catch (Exception e) {
871 Slog.e(TAG, "Exception caught by drag handleMotion", e);
872 } finally {
873 finishedCallback.run();
874 }
875 }
876 };
877
878 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 * Whether the UI is currently running in touch mode (not showing
880 * navigational focus because the user is directly pressing the screen).
881 */
882 boolean mInTouchMode = false;
883
884 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700885 private ArrayList<WindowChangeListener> mWindowChangeListeners =
886 new ArrayList<WindowChangeListener>();
887 private boolean mWindowsChanged = false;
888
889 public interface WindowChangeListener {
890 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700891 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893
Dianne Hackbornc485a602009-03-24 22:39:49 -0700894 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700895 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700896
897 // The frame use to limit the size of the app running in compatibility mode.
898 Rect mCompatibleScreenFrame = new Rect();
899 // The surface used to fill the outer rim of the app running in compatibility mode.
900 Surface mBackgroundFillerSurface = null;
901 boolean mBackgroundFillerShown = false;
902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 public static WindowManagerService main(Context context,
904 PowerManagerService pm, boolean haveInputMethods) {
905 WMThread thr = new WMThread(context, pm, haveInputMethods);
906 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 synchronized (thr) {
909 while (thr.mService == null) {
910 try {
911 thr.wait();
912 } catch (InterruptedException e) {
913 }
914 }
915 }
Romain Guy06882f82009-06-10 13:36:04 -0700916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 return thr.mService;
918 }
Romain Guy06882f82009-06-10 13:36:04 -0700919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 static class WMThread extends Thread {
921 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 private final Context mContext;
924 private final PowerManagerService mPM;
925 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 public WMThread(Context context, PowerManagerService pm,
928 boolean haveInputMethods) {
929 super("WindowManager");
930 mContext = context;
931 mPM = pm;
932 mHaveInputMethods = haveInputMethods;
933 }
Romain Guy06882f82009-06-10 13:36:04 -0700934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 public void run() {
936 Looper.prepare();
937 WindowManagerService s = new WindowManagerService(mContext, mPM,
938 mHaveInputMethods);
939 android.os.Process.setThreadPriority(
940 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700941 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 synchronized (this) {
944 mService = s;
945 notifyAll();
946 }
Romain Guy06882f82009-06-10 13:36:04 -0700947
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700948 // For debug builds, log event loop stalls to dropbox for analysis.
949 if (StrictMode.conditionallyEnableDebugLogging()) {
950 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
951 }
952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 Looper.loop();
954 }
955 }
956
957 static class PolicyThread extends Thread {
958 private final WindowManagerPolicy mPolicy;
959 private final WindowManagerService mService;
960 private final Context mContext;
961 private final PowerManagerService mPM;
962 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 public PolicyThread(WindowManagerPolicy policy,
965 WindowManagerService service, Context context,
966 PowerManagerService pm) {
967 super("WindowManagerPolicy");
968 mPolicy = policy;
969 mService = service;
970 mContext = context;
971 mPM = pm;
972 }
Romain Guy06882f82009-06-10 13:36:04 -0700973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 public void run() {
975 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800976 WindowManagerPolicyThread.set(this, Looper.myLooper());
977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800979 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 android.os.Process.setThreadPriority(
981 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700982 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 synchronized (this) {
986 mRunning = true;
987 notifyAll();
988 }
Romain Guy06882f82009-06-10 13:36:04 -0700989
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700990 // For debug builds, log event loop stalls to dropbox for analysis.
991 if (StrictMode.conditionallyEnableDebugLogging()) {
992 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
993 }
994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 Looper.loop();
996 }
997 }
998
999 private WindowManagerService(Context context, PowerManagerService pm,
1000 boolean haveInputMethods) {
1001 mContext = context;
1002 mHaveInputMethods = haveInputMethods;
1003 mLimitedAlphaCompositing = context.getResources().getBoolean(
1004 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 mPowerManager = pm;
1007 mPowerManager.setPolicy(mPolicy);
1008 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1009 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1010 "SCREEN_FROZEN");
1011 mScreenFrozenLock.setReferenceCounted(false);
1012
1013 mActivityManager = ActivityManagerNative.getDefault();
1014 mBatteryStats = BatteryStatsService.getService();
1015
1016 // Get persisted window scale setting
1017 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1018 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1019 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1020 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001021
Jim Miller284b62e2010-06-08 14:27:42 -07001022 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1023 IntentFilter filter = new IntentFilter();
1024 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1025 mContext.registerReceiver(mBroadcastReceiver, filter);
1026
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001027 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1028 "KEEP_SCREEN_ON_FLAG");
1029 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030
Jeff Browne33348b2010-07-15 23:54:05 -07001031 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1034 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 synchronized (thr) {
1037 while (!thr.mRunning) {
1038 try {
1039 thr.wait();
1040 } catch (InterruptedException e) {
1041 }
1042 }
1043 }
Romain Guy06882f82009-06-10 13:36:04 -07001044
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001045 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 // Add ourself to the Watchdog monitors.
1048 Watchdog.getInstance().addMonitor(this);
1049 }
1050
1051 @Override
1052 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1053 throws RemoteException {
1054 try {
1055 return super.onTransact(code, data, reply, flags);
1056 } catch (RuntimeException e) {
1057 // The window manager only throws security exceptions, so let's
1058 // log all others.
1059 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001060 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 }
1062 throw e;
1063 }
1064 }
1065
Jeff Browne33348b2010-07-15 23:54:05 -07001066 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 TAG, "Adding window " + window + " at "
1070 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1071 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001072 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 }
1074
Jeff Browne33348b2010-07-15 23:54:05 -07001075 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001077 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 TAG, "Adding window " + window + " at "
1079 + i + " of " + mWindows.size() + " (before " + pos + ")");
1080 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001081 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 }
1083
1084 //This method finds out the index of a window that has the same app token as
1085 //win. used for z ordering the windows in mWindows
1086 private int findIdxBasedOnAppTokens(WindowState win) {
1087 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001088 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 int jmax = localmWindows.size();
1090 if(jmax == 0) {
1091 return -1;
1092 }
1093 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001094 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 if(wentry.mAppToken == win.mAppToken) {
1096 return j;
1097 }
1098 }
1099 return -1;
1100 }
Romain Guy06882f82009-06-10 13:36:04 -07001101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1103 final IWindow client = win.mClient;
1104 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001105 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 final int N = localmWindows.size();
1108 final WindowState attached = win.mAttachedWindow;
1109 int i;
1110 if (attached == null) {
1111 int tokenWindowsPos = token.windows.size();
1112 if (token.appWindowToken != null) {
1113 int index = tokenWindowsPos-1;
1114 if (index >= 0) {
1115 // If this application has existing windows, we
1116 // simply place the new window on top of them... but
1117 // keep the starting window on top.
1118 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1119 // Base windows go behind everything else.
1120 placeWindowBefore(token.windows.get(0), win);
1121 tokenWindowsPos = 0;
1122 } else {
1123 AppWindowToken atoken = win.mAppToken;
1124 if (atoken != null &&
1125 token.windows.get(index) == atoken.startingWindow) {
1126 placeWindowBefore(token.windows.get(index), win);
1127 tokenWindowsPos--;
1128 } else {
1129 int newIdx = findIdxBasedOnAppTokens(win);
1130 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001131 //there is a window above this one associated with the same
1132 //apptoken note that the window could be a floating window
1133 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001135 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001136 TAG, "Adding window " + win + " at "
1137 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001139 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 }
1142 }
1143 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001144 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 TAG, "Figuring out where to add app window "
1146 + client.asBinder() + " (token=" + token + ")");
1147 // Figure out where the window should go, based on the
1148 // order of applications.
1149 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001150 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 for (i=NA-1; i>=0; i--) {
1152 AppWindowToken t = mAppTokens.get(i);
1153 if (t == token) {
1154 i--;
1155 break;
1156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001157
Dianne Hackborna8f60182009-09-01 19:01:50 -07001158 // We haven't reached the token yet; if this token
1159 // is not going to the bottom and has windows, we can
1160 // use it as an anchor for when we do reach the token.
1161 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 pos = t.windows.get(0);
1163 }
1164 }
1165 // We now know the index into the apps. If we found
1166 // an app window above, that gives us the position; else
1167 // we need to look some more.
1168 if (pos != null) {
1169 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001170 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 if (atoken != null) {
1172 final int NC = atoken.windows.size();
1173 if (NC > 0) {
1174 WindowState bottom = atoken.windows.get(0);
1175 if (bottom.mSubLayer < 0) {
1176 pos = bottom;
1177 }
1178 }
1179 }
1180 placeWindowBefore(pos, win);
1181 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001182 // Continue looking down until we find the first
1183 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 while (i >= 0) {
1185 AppWindowToken t = mAppTokens.get(i);
1186 final int NW = t.windows.size();
1187 if (NW > 0) {
1188 pos = t.windows.get(NW-1);
1189 break;
1190 }
1191 i--;
1192 }
1193 if (pos != null) {
1194 // Move in front of any windows attached to this
1195 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001196 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 if (atoken != null) {
1198 final int NC = atoken.windows.size();
1199 if (NC > 0) {
1200 WindowState top = atoken.windows.get(NC-1);
1201 if (top.mSubLayer >= 0) {
1202 pos = top;
1203 }
1204 }
1205 }
1206 placeWindowAfter(pos, win);
1207 } else {
1208 // Just search for the start of this layer.
1209 final int myLayer = win.mBaseLayer;
1210 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001211 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 if (w.mBaseLayer > myLayer) {
1213 break;
1214 }
1215 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001216 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001217 TAG, "Adding window " + win + " at "
1218 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001220 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 }
1222 }
1223 }
1224 } else {
1225 // Figure out where window should go, based on layer.
1226 final int myLayer = win.mBaseLayer;
1227 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001228 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 i++;
1230 break;
1231 }
1232 }
1233 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001234 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001235 TAG, "Adding window " + win + " at "
1236 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001238 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 }
1240 if (addToToken) {
1241 token.windows.add(tokenWindowsPos, win);
1242 }
1243
1244 } else {
1245 // Figure out this window's ordering relative to the window
1246 // it is attached to.
1247 final int NA = token.windows.size();
1248 final int sublayer = win.mSubLayer;
1249 int largestSublayer = Integer.MIN_VALUE;
1250 WindowState windowWithLargestSublayer = null;
1251 for (i=0; i<NA; i++) {
1252 WindowState w = token.windows.get(i);
1253 final int wSublayer = w.mSubLayer;
1254 if (wSublayer >= largestSublayer) {
1255 largestSublayer = wSublayer;
1256 windowWithLargestSublayer = w;
1257 }
1258 if (sublayer < 0) {
1259 // For negative sublayers, we go below all windows
1260 // in the same sublayer.
1261 if (wSublayer >= sublayer) {
1262 if (addToToken) {
1263 token.windows.add(i, win);
1264 }
1265 placeWindowBefore(
1266 wSublayer >= 0 ? attached : w, win);
1267 break;
1268 }
1269 } else {
1270 // For positive sublayers, we go above all windows
1271 // in the same sublayer.
1272 if (wSublayer > sublayer) {
1273 if (addToToken) {
1274 token.windows.add(i, win);
1275 }
1276 placeWindowBefore(w, win);
1277 break;
1278 }
1279 }
1280 }
1281 if (i >= NA) {
1282 if (addToToken) {
1283 token.windows.add(win);
1284 }
1285 if (sublayer < 0) {
1286 placeWindowBefore(attached, win);
1287 } else {
1288 placeWindowAfter(largestSublayer >= 0
1289 ? windowWithLargestSublayer
1290 : attached,
1291 win);
1292 }
1293 }
1294 }
Romain Guy06882f82009-06-10 13:36:04 -07001295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 if (win.mAppToken != null && addToToken) {
1297 win.mAppToken.allAppWindows.add(win);
1298 }
1299 }
Romain Guy06882f82009-06-10 13:36:04 -07001300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 static boolean canBeImeTarget(WindowState w) {
1302 final int fl = w.mAttrs.flags
1303 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1304 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1305 return w.isVisibleOrAdding();
1306 }
1307 return false;
1308 }
Romain Guy06882f82009-06-10 13:36:04 -07001309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001311 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 final int N = localmWindows.size();
1313 WindowState w = null;
1314 int i = N;
1315 while (i > 0) {
1316 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001317 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001318
Joe Onorato8a9b2202010-02-26 18:56:32 -08001319 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 // + Integer.toHexString(w.mAttrs.flags));
1321 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001322 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 // Yet more tricksyness! If this window is a "starting"
1325 // window, we do actually want to be on top of it, but
1326 // it is not -really- where input will go. So if the caller
1327 // is not actually looking to move the IME, look down below
1328 // for a real window to target...
1329 if (!willMove
1330 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1331 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001332 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1334 i--;
1335 w = wb;
1336 }
1337 }
1338 break;
1339 }
1340 }
Romain Guy06882f82009-06-10 13:36:04 -07001341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001343
Joe Onorato8a9b2202010-02-26 18:56:32 -08001344 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 if (willMove && w != null) {
1348 final WindowState curTarget = mInputMethodTarget;
1349 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 // Now some fun for dealing with window animations that
1352 // modify the Z order. We need to look at all windows below
1353 // the current target that are in this app, finding the highest
1354 // visible one in layering.
1355 AppWindowToken token = curTarget.mAppToken;
1356 WindowState highestTarget = null;
1357 int highestPos = 0;
1358 if (token.animating || token.animation != null) {
1359 int pos = 0;
1360 pos = localmWindows.indexOf(curTarget);
1361 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001362 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363 if (win.mAppToken != token) {
1364 break;
1365 }
1366 if (!win.mRemoved) {
1367 if (highestTarget == null || win.mAnimLayer >
1368 highestTarget.mAnimLayer) {
1369 highestTarget = win;
1370 highestPos = pos;
1371 }
1372 }
1373 pos--;
1374 }
1375 }
Romain Guy06882f82009-06-10 13:36:04 -07001376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001378 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 + mNextAppTransition + " " + highestTarget
1380 + " animating=" + highestTarget.isAnimating()
1381 + " layer=" + highestTarget.mAnimLayer
1382 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001383
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001384 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 // If we are currently setting up for an animation,
1386 // hold everything until we can find out what will happen.
1387 mInputMethodTargetWaitingAnim = true;
1388 mInputMethodTarget = highestTarget;
1389 return highestPos + 1;
1390 } else if (highestTarget.isAnimating() &&
1391 highestTarget.mAnimLayer > w.mAnimLayer) {
1392 // If the window we are currently targeting is involved
1393 // with an animation, and it is on top of the next target
1394 // we will be over, then hold off on moving until
1395 // that is done.
1396 mInputMethodTarget = highestTarget;
1397 return highestPos + 1;
1398 }
1399 }
1400 }
1401 }
Romain Guy06882f82009-06-10 13:36:04 -07001402
Joe Onorato8a9b2202010-02-26 18:56:32 -08001403 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 if (w != null) {
1405 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001406 if (DEBUG_INPUT_METHOD) {
1407 RuntimeException e = null;
1408 if (!HIDE_STACK_CRAWLS) {
1409 e = new RuntimeException();
1410 e.fillInStackTrace();
1411 }
1412 Slog.w(TAG, "Moving IM target from "
1413 + mInputMethodTarget + " to " + w, e);
1414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 mInputMethodTarget = w;
1416 if (w.mAppToken != null) {
1417 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1418 } else {
1419 setInputMethodAnimLayerAdjustment(0);
1420 }
1421 }
1422 return i+1;
1423 }
1424 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001425 if (DEBUG_INPUT_METHOD) {
1426 RuntimeException e = null;
1427 if (!HIDE_STACK_CRAWLS) {
1428 e = new RuntimeException();
1429 e.fillInStackTrace();
1430 }
1431 Slog.w(TAG, "Moving IM target from "
1432 + mInputMethodTarget + " to null", e);
1433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 mInputMethodTarget = null;
1435 setInputMethodAnimLayerAdjustment(0);
1436 }
1437 return -1;
1438 }
Romain Guy06882f82009-06-10 13:36:04 -07001439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 void addInputMethodWindowToListLocked(WindowState win) {
1441 int pos = findDesiredInputMethodWindowIndexLocked(true);
1442 if (pos >= 0) {
1443 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001444 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001445 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001447 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 moveInputMethodDialogsLocked(pos+1);
1449 return;
1450 }
1451 win.mTargetAppToken = null;
1452 addWindowToListInOrderLocked(win, true);
1453 moveInputMethodDialogsLocked(pos);
1454 }
Romain Guy06882f82009-06-10 13:36:04 -07001455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001457 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 mInputMethodAnimLayerAdjustment = adj;
1459 WindowState imw = mInputMethodWindow;
1460 if (imw != null) {
1461 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 + " anim layer: " + imw.mAnimLayer);
1464 int wi = imw.mChildWindows.size();
1465 while (wi > 0) {
1466 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001467 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001469 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 + " anim layer: " + cw.mAnimLayer);
1471 }
1472 }
1473 int di = mInputMethodDialogs.size();
1474 while (di > 0) {
1475 di --;
1476 imw = mInputMethodDialogs.get(di);
1477 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001478 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 + " anim layer: " + imw.mAnimLayer);
1480 }
1481 }
Romain Guy06882f82009-06-10 13:36:04 -07001482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1484 int wpos = mWindows.indexOf(win);
1485 if (wpos >= 0) {
1486 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001487 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001489 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 int NC = win.mChildWindows.size();
1491 while (NC > 0) {
1492 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001493 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 int cpos = mWindows.indexOf(cw);
1495 if (cpos >= 0) {
1496 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001497 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001498 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 mWindows.remove(cpos);
1500 }
1501 }
1502 }
1503 return interestingPos;
1504 }
Romain Guy06882f82009-06-10 13:36:04 -07001505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 private void reAddWindowToListInOrderLocked(WindowState win) {
1507 addWindowToListInOrderLocked(win, false);
1508 // This is a hack to get all of the child windows added as well
1509 // at the right position. Child windows should be rare and
1510 // this case should be rare, so it shouldn't be that big a deal.
1511 int wpos = mWindows.indexOf(win);
1512 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001513 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001514 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001516 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 reAddWindowLocked(wpos, win);
1518 }
1519 }
Romain Guy06882f82009-06-10 13:36:04 -07001520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 void logWindowList(String prefix) {
1522 int N = mWindows.size();
1523 while (N > 0) {
1524 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001525 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 }
1527 }
Romain Guy06882f82009-06-10 13:36:04 -07001528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 void moveInputMethodDialogsLocked(int pos) {
1530 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001533 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 for (int i=0; i<N; i++) {
1535 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1536 }
1537 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001538 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 logWindowList(" ");
1540 }
Romain Guy06882f82009-06-10 13:36:04 -07001541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 if (pos >= 0) {
1543 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1544 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001545 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 if (wp == mInputMethodWindow) {
1547 pos++;
1548 }
1549 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001550 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 for (int i=0; i<N; i++) {
1552 WindowState win = dialogs.get(i);
1553 win.mTargetAppToken = targetAppToken;
1554 pos = reAddWindowLocked(pos, win);
1555 }
1556 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001557 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 logWindowList(" ");
1559 }
1560 return;
1561 }
1562 for (int i=0; i<N; i++) {
1563 WindowState win = dialogs.get(i);
1564 win.mTargetAppToken = null;
1565 reAddWindowToListInOrderLocked(win);
1566 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 logWindowList(" ");
1569 }
1570 }
1571 }
Romain Guy06882f82009-06-10 13:36:04 -07001572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1574 final WindowState imWin = mInputMethodWindow;
1575 final int DN = mInputMethodDialogs.size();
1576 if (imWin == null && DN == 0) {
1577 return false;
1578 }
Romain Guy06882f82009-06-10 13:36:04 -07001579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1581 if (imPos >= 0) {
1582 // In this case, the input method windows are to be placed
1583 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 // First check to see if the input method windows are already
1586 // located here, and contiguous.
1587 final int N = mWindows.size();
1588 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001589 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 // Figure out the actual input method window that should be
1592 // at the bottom of their stack.
1593 WindowState baseImWin = imWin != null
1594 ? imWin : mInputMethodDialogs.get(0);
1595 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001596 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 if (cw.mSubLayer < 0) baseImWin = cw;
1598 }
Romain Guy06882f82009-06-10 13:36:04 -07001599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 if (firstImWin == baseImWin) {
1601 // The windows haven't moved... but are they still contiguous?
1602 // First find the top IM window.
1603 int pos = imPos+1;
1604 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001605 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 break;
1607 }
1608 pos++;
1609 }
1610 pos++;
1611 // Now there should be no more input method windows above.
1612 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001613 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 break;
1615 }
1616 pos++;
1617 }
1618 if (pos >= N) {
1619 // All is good!
1620 return false;
1621 }
1622 }
Romain Guy06882f82009-06-10 13:36:04 -07001623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 if (imWin != null) {
1625 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 logWindowList(" ");
1628 }
1629 imPos = tmpRemoveWindowLocked(imPos, imWin);
1630 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001631 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 logWindowList(" ");
1633 }
1634 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1635 reAddWindowLocked(imPos, imWin);
1636 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001637 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 logWindowList(" ");
1639 }
1640 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1641 } else {
1642 moveInputMethodDialogsLocked(imPos);
1643 }
Romain Guy06882f82009-06-10 13:36:04 -07001644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 } else {
1646 // In this case, the input method windows go in a fixed layer,
1647 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001650 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 tmpRemoveWindowLocked(0, imWin);
1652 imWin.mTargetAppToken = null;
1653 reAddWindowToListInOrderLocked(imWin);
1654 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 logWindowList(" ");
1657 }
1658 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1659 } else {
1660 moveInputMethodDialogsLocked(-1);;
1661 }
Romain Guy06882f82009-06-10 13:36:04 -07001662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 }
Romain Guy06882f82009-06-10 13:36:04 -07001664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 if (needAssignLayers) {
1666 assignLayersLocked();
1667 }
Romain Guy06882f82009-06-10 13:36:04 -07001668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 return true;
1670 }
Romain Guy06882f82009-06-10 13:36:04 -07001671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 void adjustInputMethodDialogsLocked() {
1673 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1674 }
Romain Guy06882f82009-06-10 13:36:04 -07001675
Dianne Hackborn25994b42009-09-04 14:21:19 -07001676 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001678 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1679 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1680 ? wallpaperTarget.mAppToken.animation : null)
1681 + " upper=" + mUpperWallpaperTarget
1682 + " lower=" + mLowerWallpaperTarget);
1683 return (wallpaperTarget != null
1684 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1685 && wallpaperTarget.mAppToken.animation != null)))
1686 || mUpperWallpaperTarget != null
1687 || mLowerWallpaperTarget != null;
1688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001689
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001690 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1691 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001693 int adjustWallpaperWindowsLocked() {
1694 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001695
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001696 final int dw = mDisplay.getWidth();
1697 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001698
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001699 // First find top-most window that has asked to be on top of the
1700 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001701 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001702 int N = localmWindows.size();
1703 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001704 WindowState foundW = null;
1705 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001706 WindowState topCurW = null;
1707 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001708 int i = N;
1709 while (i > 0) {
1710 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001711 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001712 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1713 if (topCurW == null) {
1714 topCurW = w;
1715 topCurI = i;
1716 }
1717 continue;
1718 }
1719 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001720 if (w.mAppToken != null) {
1721 // If this window's app token is hidden and not animating,
1722 // it is of no interest to us.
1723 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001724 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001725 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001726 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001727 continue;
1728 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001729 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001730 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001731 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1732 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001733 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001734 && (mWallpaperTarget == w
1735 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001736 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001737 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001738 foundW = w;
1739 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001740 if (w == mWallpaperTarget && ((w.mAppToken != null
1741 && w.mAppToken.animation != null)
1742 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001743 // The current wallpaper target is animating, so we'll
1744 // look behind it for another possible target and figure
1745 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001746 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001747 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001748 continue;
1749 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001750 break;
1751 }
1752 }
1753
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001754 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001755 // If we are currently waiting for an app transition, and either
1756 // the current target or the next target are involved with it,
1757 // then hold off on doing anything with the wallpaper.
1758 // Note that we are checking here for just whether the target
1759 // is part of an app token... which is potentially overly aggressive
1760 // (the app token may not be involved in the transition), but good
1761 // enough (we'll just wait until whatever transition is pending
1762 // executes).
1763 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001764 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001765 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001766 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001767 }
1768 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001771 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001772 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001774
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001775 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001776 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001777 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001778 + " oldTarget: " + mWallpaperTarget);
1779 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001780
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001781 mLowerWallpaperTarget = null;
1782 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001783
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001784 WindowState oldW = mWallpaperTarget;
1785 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001786
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001787 // Now what is happening... if the current and new targets are
1788 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001789 if (foundW != null && oldW != null) {
1790 boolean oldAnim = oldW.mAnimation != null
1791 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1792 boolean foundAnim = foundW.mAnimation != null
1793 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001794 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001795 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001796 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001798 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001799 int oldI = localmWindows.indexOf(oldW);
1800 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001801 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001802 }
1803 if (oldI >= 0) {
1804 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001805 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 + "=" + oldW + "; new#" + foundI
1807 + "=" + foundW);
1808 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001809
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001810 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001811 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001812 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 }
1815 mWallpaperTarget = oldW;
1816 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001817
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 // Now set the upper and lower wallpaper targets
1819 // correctly, and make sure that we are positioning
1820 // the wallpaper below the lower.
1821 if (foundI > oldI) {
1822 // The new target is on top of the old one.
1823 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001824 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001825 }
1826 mUpperWallpaperTarget = foundW;
1827 mLowerWallpaperTarget = oldW;
1828 foundW = oldW;
1829 foundI = oldI;
1830 } else {
1831 // The new target is below the old one.
1832 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001834 }
1835 mUpperWallpaperTarget = oldW;
1836 mLowerWallpaperTarget = foundW;
1837 }
1838 }
1839 }
1840 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001842 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001843 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001844 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1845 || (mLowerWallpaperTarget.mAppToken != null
1846 && mLowerWallpaperTarget.mAppToken.animation != null);
1847 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1848 || (mUpperWallpaperTarget.mAppToken != null
1849 && mUpperWallpaperTarget.mAppToken.animation != null);
1850 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001851 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001852 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001853 }
1854 mLowerWallpaperTarget = null;
1855 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001856 }
1857 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001858
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001859 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001860 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001861 // The window is visible to the compositor... but is it visible
1862 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001863 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001864 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001865
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001866 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001867 // its layer adjustment. Only do this if we are not transfering
1868 // between two wallpaper targets.
1869 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001871 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001872
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001873 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1874 * TYPE_LAYER_MULTIPLIER
1875 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001876
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001877 // Now w is the window we are supposed to be behind... but we
1878 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001879 // AND any starting window associated with it, AND below the
1880 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001881 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001882 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001883 if (wb.mBaseLayer < maxLayer &&
1884 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001885 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001886 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001887 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001888 // This window is not related to the previous one in any
1889 // interesting way, so stop here.
1890 break;
1891 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001892 foundW = wb;
1893 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001894 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001895 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001896 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001898
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001899 if (foundW == null && topCurW != null) {
1900 // There is no wallpaper target, so it goes at the bottom.
1901 // We will assume it is the same place as last time, if known.
1902 foundW = topCurW;
1903 foundI = topCurI+1;
1904 } else {
1905 // Okay i is the position immediately above the wallpaper. Look at
1906 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001907 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001909
Dianne Hackborn284ac932009-08-28 10:34:25 -07001910 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001911 if (mWallpaperTarget.mWallpaperX >= 0) {
1912 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001913 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001914 }
1915 if (mWallpaperTarget.mWallpaperY >= 0) {
1916 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001917 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001918 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001920
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001921 // Start stepping backwards from here, ensuring that our wallpaper windows
1922 // are correctly placed.
1923 int curTokenIndex = mWallpaperTokens.size();
1924 while (curTokenIndex > 0) {
1925 curTokenIndex--;
1926 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001927 if (token.hidden == visible) {
1928 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1929 token.hidden = !visible;
1930 // Need to do a layout to ensure the wallpaper now has the
1931 // correct size.
1932 mLayoutNeeded = true;
1933 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001934
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001935 int curWallpaperIndex = token.windows.size();
1936 while (curWallpaperIndex > 0) {
1937 curWallpaperIndex--;
1938 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001939
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001940 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001941 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001942 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001943
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001944 // First, make sure the client has the current visibility
1945 // state.
1946 if (wallpaper.mWallpaperVisible != visible) {
1947 wallpaper.mWallpaperVisible = visible;
1948 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001949 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001950 "Setting visibility of wallpaper " + wallpaper
1951 + ": " + visible);
1952 wallpaper.mClient.dispatchAppVisibility(visible);
1953 } catch (RemoteException e) {
1954 }
1955 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001956
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001957 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001958 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001959 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001960
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001961 // First, if this window is at the current index, then all
1962 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001963 if (wallpaper == foundW) {
1964 foundI--;
1965 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001966 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001967 continue;
1968 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001969
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001970 // The window didn't match... the current wallpaper window,
1971 // wherever it is, is in the wrong place, so make sure it is
1972 // not in the list.
1973 int oldIndex = localmWindows.indexOf(wallpaper);
1974 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001975 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001976 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001977 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001978 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001979 if (oldIndex < foundI) {
1980 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 }
1982 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001983
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001984 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001985 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001986 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001987 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001989 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001990 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001991 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001992 }
1993 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001994
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001995 return changed;
1996 }
1997
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001998 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001999 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002000 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002001 mWallpaperAnimLayerAdjustment = adj;
2002 int curTokenIndex = mWallpaperTokens.size();
2003 while (curTokenIndex > 0) {
2004 curTokenIndex--;
2005 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2006 int curWallpaperIndex = token.windows.size();
2007 while (curWallpaperIndex > 0) {
2008 curWallpaperIndex--;
2009 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2010 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002012 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002013 }
2014 }
2015 }
2016
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002017 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2018 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002019 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002020 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002021 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002022 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002023 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2024 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2025 changed = wallpaperWin.mXOffset != offset;
2026 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002027 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002028 + wallpaperWin + " x: " + offset);
2029 wallpaperWin.mXOffset = offset;
2030 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002031 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002032 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002033 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002034 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002036
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002037 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002038 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002039 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2040 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2041 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002042 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002043 + wallpaperWin + " y: " + offset);
2044 changed = true;
2045 wallpaperWin.mYOffset = offset;
2046 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002047 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002048 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002049 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002050 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002051 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002052
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002053 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002054 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002055 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002056 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2057 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002058 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002059 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002060 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002061 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002062 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2063 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002064 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002065 if (mWaitingOnWallpaper != null) {
2066 long start = SystemClock.uptimeMillis();
2067 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2068 < start) {
2069 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002070 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002071 "Waiting for offset complete...");
2072 mWindowMap.wait(WALLPAPER_TIMEOUT);
2073 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002074 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002075 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002076 if ((start+WALLPAPER_TIMEOUT)
2077 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002078 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002079 + wallpaperWin);
2080 mLastWallpaperTimeoutTime = start;
2081 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002082 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002083 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002084 }
2085 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002086 } catch (RemoteException e) {
2087 }
2088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002089
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002090 return changed;
2091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002092
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002093 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002094 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002095 if (mWaitingOnWallpaper != null &&
2096 mWaitingOnWallpaper.mClient.asBinder() == window) {
2097 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002098 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002099 }
2100 }
2101 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002102
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002103 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002104 final int dw = mDisplay.getWidth();
2105 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002106
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002107 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002108
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002109 WindowState target = mWallpaperTarget;
2110 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002111 if (target.mWallpaperX >= 0) {
2112 mLastWallpaperX = target.mWallpaperX;
2113 } else if (changingTarget.mWallpaperX >= 0) {
2114 mLastWallpaperX = changingTarget.mWallpaperX;
2115 }
2116 if (target.mWallpaperY >= 0) {
2117 mLastWallpaperY = target.mWallpaperY;
2118 } else if (changingTarget.mWallpaperY >= 0) {
2119 mLastWallpaperY = changingTarget.mWallpaperY;
2120 }
2121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002122
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002123 int curTokenIndex = mWallpaperTokens.size();
2124 while (curTokenIndex > 0) {
2125 curTokenIndex--;
2126 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2127 int curWallpaperIndex = token.windows.size();
2128 while (curWallpaperIndex > 0) {
2129 curWallpaperIndex--;
2130 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2131 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2132 wallpaper.computeShownFrameLocked();
2133 changed = true;
2134 // We only want to be synchronous with one wallpaper.
2135 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002136 }
2137 }
2138 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002139
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002140 return changed;
2141 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002142
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002143 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002144 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002145 final int dw = mDisplay.getWidth();
2146 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002147
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002148 int curTokenIndex = mWallpaperTokens.size();
2149 while (curTokenIndex > 0) {
2150 curTokenIndex--;
2151 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002152 if (token.hidden == visible) {
2153 token.hidden = !visible;
2154 // Need to do a layout to ensure the wallpaper now has the
2155 // correct size.
2156 mLayoutNeeded = true;
2157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002158
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002159 int curWallpaperIndex = token.windows.size();
2160 while (curWallpaperIndex > 0) {
2161 curWallpaperIndex--;
2162 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2163 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002164 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002165 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002166
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002167 if (wallpaper.mWallpaperVisible != visible) {
2168 wallpaper.mWallpaperVisible = visible;
2169 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002170 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002171 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002172 + ": " + visible);
2173 wallpaper.mClient.dispatchAppVisibility(visible);
2174 } catch (RemoteException e) {
2175 }
2176 }
2177 }
2178 }
2179 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 public int addWindow(Session session, IWindow client,
2182 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002183 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 int res = mPolicy.checkAddPermission(attrs);
2185 if (res != WindowManagerImpl.ADD_OKAY) {
2186 return res;
2187 }
Romain Guy06882f82009-06-10 13:36:04 -07002188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 boolean reportNewConfig = false;
2190 WindowState attachedWindow = null;
2191 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002192 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002196 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 }
Romain Guy06882f82009-06-10 13:36:04 -07002198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002200 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2202 }
2203
2204 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002205 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002207 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 + attrs.token + ". Aborting.");
2209 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2210 }
2211 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2212 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002213 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 + attrs.token + ". Aborting.");
2215 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2216 }
2217 }
2218
2219 boolean addToken = false;
2220 WindowToken token = mTokenMap.get(attrs.token);
2221 if (token == null) {
2222 if (attrs.type >= FIRST_APPLICATION_WINDOW
2223 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002224 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 + attrs.token + ". Aborting.");
2226 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2227 }
2228 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002229 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 + attrs.token + ". Aborting.");
2231 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2232 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002233 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002234 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002235 + attrs.token + ". Aborting.");
2236 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 token = new WindowToken(attrs.token, -1, false);
2239 addToken = true;
2240 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2241 && attrs.type <= LAST_APPLICATION_WINDOW) {
2242 AppWindowToken atoken = token.appWindowToken;
2243 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002244 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 + token + ". Aborting.");
2246 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2247 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002248 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 + token + ". Aborting.");
2250 return WindowManagerImpl.ADD_APP_EXITING;
2251 }
2252 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2253 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002254 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2256 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2257 }
2258 } else if (attrs.type == TYPE_INPUT_METHOD) {
2259 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002260 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261 + attrs.token + ". Aborting.");
2262 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2263 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002264 } else if (attrs.type == TYPE_WALLPAPER) {
2265 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002266 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002267 + attrs.token + ". Aborting.");
2268 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 }
2271
2272 win = new WindowState(session, client, token,
2273 attachedWindow, attrs, viewVisibility);
2274 if (win.mDeathRecipient == null) {
2275 // Client has apparently died, so there is no reason to
2276 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002277 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 + " that is dead, aborting.");
2279 return WindowManagerImpl.ADD_APP_EXITING;
2280 }
2281
2282 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 res = mPolicy.prepareAddWindowLw(win, attrs);
2285 if (res != WindowManagerImpl.ADD_OKAY) {
2286 return res;
2287 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002288
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002289 if (outInputChannel != null) {
2290 String name = win.makeInputChannelName();
2291 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2292 win.mInputChannel = inputChannels[0];
2293 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2294
2295 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297
2298 // From now on, no exceptions or errors allowed!
2299
2300 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002301
Dianne Hackborn5132b372010-07-29 12:51:35 -07002302 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 if (addToken) {
2305 mTokenMap.put(attrs.token, token);
2306 mTokenList.add(token);
2307 }
2308 win.attach();
2309 mWindowMap.put(client.asBinder(), win);
2310
2311 if (attrs.type == TYPE_APPLICATION_STARTING &&
2312 token.appWindowToken != null) {
2313 token.appWindowToken.startingWindow = win;
2314 }
2315
2316 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 if (attrs.type == TYPE_INPUT_METHOD) {
2319 mInputMethodWindow = win;
2320 addInputMethodWindowToListLocked(win);
2321 imMayMove = false;
2322 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2323 mInputMethodDialogs.add(win);
2324 addWindowToListInOrderLocked(win, true);
2325 adjustInputMethodDialogsLocked();
2326 imMayMove = false;
2327 } else {
2328 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002329 if (attrs.type == TYPE_WALLPAPER) {
2330 mLastWallpaperTimeoutTime = 0;
2331 adjustWallpaperWindowsLocked();
2332 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002333 adjustWallpaperWindowsLocked();
2334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 }
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 if (mInTouchMode) {
2342 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2343 }
2344 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2345 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2346 }
Romain Guy06882f82009-06-10 13:36:04 -07002347
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002348 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002350 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2351 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 imMayMove = false;
2353 }
2354 }
Romain Guy06882f82009-06-10 13:36:04 -07002355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002357 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358 }
Romain Guy06882f82009-06-10 13:36:04 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 assignLayersLocked();
2361 // Don't do layout here, the window must call
2362 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 //dump();
2365
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002366 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002367 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002368 }
Jeff Brown349703e2010-06-22 01:27:15 -07002369
Joe Onorato8a9b2202010-02-26 18:56:32 -08002370 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 TAG, "New client " + client.asBinder()
2372 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002373
2374 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2375 reportNewConfig = true;
2376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 }
2378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002379 if (reportNewConfig) {
2380 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 return res;
2386 }
Romain Guy06882f82009-06-10 13:36:04 -07002387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 public void removeWindow(Session session, IWindow client) {
2389 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002390 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 if (win == null) {
2392 return;
2393 }
2394 removeWindowLocked(session, win);
2395 }
2396 }
Romain Guy06882f82009-06-10 13:36:04 -07002397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 public void removeWindowLocked(Session session, WindowState win) {
2399
Joe Onorato8a9b2202010-02-26 18:56:32 -08002400 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 TAG, "Remove " + win + " client="
2402 + Integer.toHexString(System.identityHashCode(
2403 win.mClient.asBinder()))
2404 + ", surface=" + win.mSurface);
2405
2406 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002407
2408 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002409
Joe Onorato8a9b2202010-02-26 18:56:32 -08002410 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2412 + " mExiting=" + win.mExiting
2413 + " isAnimating=" + win.isAnimating()
2414 + " app-animation="
2415 + (win.mAppToken != null ? win.mAppToken.animation : null)
2416 + " inPendingTransaction="
2417 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2418 + " mDisplayFrozen=" + mDisplayFrozen);
2419 // Visibility of the removed window. Will be used later to update orientation later on.
2420 boolean wasVisible = false;
2421 // First, see if we need to run an animation. If we do, we have
2422 // to hold off on removing the window until the animation is done.
2423 // If the display is frozen, just remove immediately, since the
2424 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002425 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 // If we are not currently running the exit animation, we
2427 // need to see about starting one.
2428 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2431 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2432 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2433 }
2434 // Try starting an animation.
2435 if (applyAnimationLocked(win, transit, false)) {
2436 win.mExiting = true;
2437 }
2438 }
2439 if (win.mExiting || win.isAnimating()) {
2440 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002441 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 win.mExiting = true;
2443 win.mRemoveOnExit = true;
2444 mLayoutNeeded = true;
2445 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2446 performLayoutAndPlaceSurfacesLocked();
2447 if (win.mAppToken != null) {
2448 win.mAppToken.updateReportedVisibilityLocked();
2449 }
2450 //dump();
2451 Binder.restoreCallingIdentity(origId);
2452 return;
2453 }
2454 }
2455
2456 removeWindowInnerLocked(session, win);
2457 // Removing a visible window will effect the computed orientation
2458 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002459 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002460 != mForcedAppOrientation
2461 && updateOrientationFromAppTokensLocked()) {
2462 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 }
2464 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2465 Binder.restoreCallingIdentity(origId);
2466 }
Romain Guy06882f82009-06-10 13:36:04 -07002467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 if (mInputMethodTarget == win) {
2472 moveInputMethodWindowsIfNeededLocked(false);
2473 }
Romain Guy06882f82009-06-10 13:36:04 -07002474
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002475 if (false) {
2476 RuntimeException e = new RuntimeException("here");
2477 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002478 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002479 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 mPolicy.removeWindowLw(win);
2482 win.removeLocked();
2483
2484 mWindowMap.remove(win.mClient.asBinder());
2485 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002486 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002487 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488
2489 if (mInputMethodWindow == win) {
2490 mInputMethodWindow = null;
2491 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2492 mInputMethodDialogs.remove(win);
2493 }
Romain Guy06882f82009-06-10 13:36:04 -07002494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 final WindowToken token = win.mToken;
2496 final AppWindowToken atoken = win.mAppToken;
2497 token.windows.remove(win);
2498 if (atoken != null) {
2499 atoken.allAppWindows.remove(win);
2500 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002501 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 TAG, "**** Removing window " + win + ": count="
2503 + token.windows.size());
2504 if (token.windows.size() == 0) {
2505 if (!token.explicit) {
2506 mTokenMap.remove(token.token);
2507 mTokenList.remove(token);
2508 } else if (atoken != null) {
2509 atoken.firstWindowDrawn = false;
2510 }
2511 }
2512
2513 if (atoken != null) {
2514 if (atoken.startingWindow == win) {
2515 atoken.startingWindow = null;
2516 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2517 // If this is the last window and we had requested a starting
2518 // transition window, well there is no point now.
2519 atoken.startingData = null;
2520 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2521 // If this is the last window except for a starting transition
2522 // window, we need to get rid of the starting transition.
2523 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002524 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 + ": no more real windows");
2526 }
2527 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2528 mH.sendMessage(m);
2529 }
2530 }
Romain Guy06882f82009-06-10 13:36:04 -07002531
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002532 if (win.mAttrs.type == TYPE_WALLPAPER) {
2533 mLastWallpaperTimeoutTime = 0;
2534 adjustWallpaperWindowsLocked();
2535 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002536 adjustWallpaperWindowsLocked();
2537 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 if (!mInLayout) {
2540 assignLayersLocked();
2541 mLayoutNeeded = true;
2542 performLayoutAndPlaceSurfacesLocked();
2543 if (win.mAppToken != null) {
2544 win.mAppToken.updateReportedVisibilityLocked();
2545 }
2546 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002547
2548 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 }
2550
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002551 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2552 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2553 + ": " + msg + " / " + w.mAttrs.getTitle();
2554 if (where != null) {
2555 Slog.i(TAG, str, where);
2556 } else {
2557 Slog.i(TAG, str);
2558 }
2559 }
2560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2562 long origId = Binder.clearCallingIdentity();
2563 try {
2564 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002565 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002567 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 Surface.openTransaction();
2569 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002570 if (SHOW_TRANSACTIONS) logSurface(w,
2571 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 w.mSurface.setTransparentRegionHint(region);
2573 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002574 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 Surface.closeTransaction();
2576 }
2577 }
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(origId);
2581 }
2582 }
2583
2584 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002585 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586 Rect visibleInsets) {
2587 long origId = Binder.clearCallingIdentity();
2588 try {
2589 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002590 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 if (w != null) {
2592 w.mGivenInsetsPending = false;
2593 w.mGivenContentInsets.set(contentInsets);
2594 w.mGivenVisibleInsets.set(visibleInsets);
2595 w.mTouchableInsets = touchableInsets;
2596 mLayoutNeeded = true;
2597 performLayoutAndPlaceSurfacesLocked();
2598 }
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(origId);
2602 }
2603 }
Romain Guy06882f82009-06-10 13:36:04 -07002604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 public void getWindowDisplayFrame(Session session, IWindow client,
2606 Rect outDisplayFrame) {
2607 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002608 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 if (win == null) {
2610 outDisplayFrame.setEmpty();
2611 return;
2612 }
2613 outDisplayFrame.set(win.mDisplayFrame);
2614 }
2615 }
2616
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002617 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2618 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002619 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2620 window.mWallpaperX = x;
2621 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002622 window.mWallpaperXStep = xStep;
2623 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002624 if (updateWallpaperOffsetLocked(window, true)) {
2625 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002626 }
2627 }
2628 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002629
Dianne Hackborn75804932009-10-20 20:15:20 -07002630 void wallpaperCommandComplete(IBinder window, Bundle result) {
2631 synchronized (mWindowMap) {
2632 if (mWaitingOnWallpaper != null &&
2633 mWaitingOnWallpaper.mClient.asBinder() == window) {
2634 mWaitingOnWallpaper = null;
2635 mWindowMap.notifyAll();
2636 }
2637 }
2638 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002639
Dianne Hackborn75804932009-10-20 20:15:20 -07002640 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2641 String action, int x, int y, int z, Bundle extras, boolean sync) {
2642 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2643 || window == mUpperWallpaperTarget) {
2644 boolean doWait = sync;
2645 int curTokenIndex = mWallpaperTokens.size();
2646 while (curTokenIndex > 0) {
2647 curTokenIndex--;
2648 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2649 int curWallpaperIndex = token.windows.size();
2650 while (curWallpaperIndex > 0) {
2651 curWallpaperIndex--;
2652 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2653 try {
2654 wallpaper.mClient.dispatchWallpaperCommand(action,
2655 x, y, z, extras, sync);
2656 // We only want to be synchronous with one wallpaper.
2657 sync = false;
2658 } catch (RemoteException e) {
2659 }
2660 }
2661 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002662
Dianne Hackborn75804932009-10-20 20:15:20 -07002663 if (doWait) {
2664 // XXX Need to wait for result.
2665 }
2666 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002667
Dianne Hackborn75804932009-10-20 20:15:20 -07002668 return null;
2669 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 public int relayoutWindow(Session session, IWindow client,
2672 WindowManager.LayoutParams attrs, int requestedWidth,
2673 int requestedHeight, int viewVisibility, boolean insetsPending,
2674 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002675 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 boolean displayed = false;
2677 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002678 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002681 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002682 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 if (win == null) {
2684 return 0;
2685 }
2686 win.mRequestedWidth = requestedWidth;
2687 win.mRequestedHeight = requestedHeight;
2688
2689 if (attrs != null) {
2690 mPolicy.adjustWindowParamsLw(attrs);
2691 }
Romain Guy06882f82009-06-10 13:36:04 -07002692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 int attrChanges = 0;
2694 int flagChanges = 0;
2695 if (attrs != null) {
2696 flagChanges = win.mAttrs.flags ^= attrs.flags;
2697 attrChanges = win.mAttrs.copyFrom(attrs);
2698 }
2699
Joe Onorato8a9b2202010-02-26 18:56:32 -08002700 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701
2702 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2703 win.mAlpha = attrs.alpha;
2704 }
2705
2706 final boolean scaledWindow =
2707 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2708
2709 if (scaledWindow) {
2710 // requested{Width|Height} Surface's physical size
2711 // attrs.{width|height} Size on screen
2712 win.mHScale = (attrs.width != requestedWidth) ?
2713 (attrs.width / (float)requestedWidth) : 1.0f;
2714 win.mVScale = (attrs.height != requestedHeight) ?
2715 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002716 } else {
2717 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 }
2719
2720 boolean imMayMove = (flagChanges&(
2721 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2722 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002724 boolean focusMayChange = win.mViewVisibility != viewVisibility
2725 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2726 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002727
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002728 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2729 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 win.mRelayoutCalled = true;
2732 final int oldVisibility = win.mViewVisibility;
2733 win.mViewVisibility = viewVisibility;
2734 if (viewVisibility == View.VISIBLE &&
2735 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2736 displayed = !win.isVisibleLw();
2737 if (win.mExiting) {
2738 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002739 if (win.mAnimation != null) {
2740 win.mAnimation.cancel();
2741 win.mAnimation = null;
2742 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 }
2744 if (win.mDestroying) {
2745 win.mDestroying = false;
2746 mDestroySurface.remove(win);
2747 }
2748 if (oldVisibility == View.GONE) {
2749 win.mEnterAnimationPending = true;
2750 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002751 if (displayed) {
2752 if (win.mSurface != null && !win.mDrawPending
2753 && !win.mCommitDrawPending && !mDisplayFrozen
2754 && mPolicy.isScreenOn()) {
2755 applyEnterAnimationLocked(win);
2756 }
2757 if ((win.mAttrs.flags
2758 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2759 if (DEBUG_VISIBILITY) Slog.v(TAG,
2760 "Relayout window turning screen on: " + win);
2761 win.mTurnOnScreen = true;
2762 }
2763 int diff = 0;
2764 if (win.mConfiguration != mCurConfiguration
2765 && (win.mConfiguration == null
2766 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2767 win.mConfiguration = mCurConfiguration;
2768 if (DEBUG_CONFIGURATION) {
2769 Slog.i(TAG, "Window " + win + " visible with new config: "
2770 + win.mConfiguration + " / 0x"
2771 + Integer.toHexString(diff));
2772 }
2773 outConfig.setTo(mCurConfiguration);
2774 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002775 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2777 // To change the format, we need to re-build the surface.
2778 win.destroySurfaceLocked();
2779 displayed = true;
2780 }
2781 try {
2782 Surface surface = win.createSurfaceLocked();
2783 if (surface != null) {
2784 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002785 win.mReportDestroySurface = false;
2786 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002787 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002788 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002790 // For some reason there isn't a surface. Clear the
2791 // caller's object so they see the same state.
2792 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002793 }
2794 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002795 mInputMonitor.updateInputWindowsLw();
2796
Joe Onorato8a9b2202010-02-26 18:56:32 -08002797 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002798 + client + " (" + win.mAttrs.getTitle() + ")",
2799 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 Binder.restoreCallingIdentity(origId);
2801 return 0;
2802 }
2803 if (displayed) {
2804 focusMayChange = true;
2805 }
2806 if (win.mAttrs.type == TYPE_INPUT_METHOD
2807 && mInputMethodWindow == null) {
2808 mInputMethodWindow = win;
2809 imMayMove = true;
2810 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002811 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2812 && win.mAppToken != null
2813 && win.mAppToken.startingWindow != null) {
2814 // Special handling of starting window over the base
2815 // window of the app: propagate lock screen flags to it,
2816 // to provide the correct semantics while starting.
2817 final int mask =
2818 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002819 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2820 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002821 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2822 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 } else {
2825 win.mEnterAnimationPending = false;
2826 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002827 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002828 + ": mExiting=" + win.mExiting
2829 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 // If we are not currently running the exit animation, we
2831 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002832 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 // Try starting an animation; if there isn't one, we
2834 // can destroy the surface right away.
2835 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2836 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2837 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2838 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002839 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002841 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 } else if (win.isAnimating()) {
2844 // Currently in a hide animation... turn this into
2845 // an exit.
2846 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002847 } else if (win == mWallpaperTarget) {
2848 // If the wallpaper is currently behind this
2849 // window, we need to change both of them inside
2850 // of a transaction to avoid artifacts.
2851 win.mExiting = true;
2852 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 } else {
2854 if (mInputMethodWindow == win) {
2855 mInputMethodWindow = null;
2856 }
2857 win.destroySurfaceLocked();
2858 }
2859 }
2860 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002861
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002862 if (win.mSurface == null || (win.getAttrs().flags
2863 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2864 || win.mSurfacePendingDestroy) {
2865 // We are being called from a local process, which
2866 // means outSurface holds its current surface. Ensure the
2867 // surface object is cleared, but we don't want it actually
2868 // destroyed at this point.
2869 win.mSurfacePendingDestroy = false;
2870 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002871 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002872 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002873 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002874 "Keeping surface, will report destroy: " + win);
2875 win.mReportDestroySurface = true;
2876 outSurface.copyFrom(win.mSurface);
2877 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 }
2879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 if (focusMayChange) {
2881 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2882 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 imMayMove = false;
2884 }
2885 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2886 }
Romain Guy06882f82009-06-10 13:36:04 -07002887
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002888 // updateFocusedWindowLocked() already assigned layers so we only need to
2889 // reassign them at this point if the IM window state gets shuffled
2890 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002893 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2894 // Little hack here -- we -should- be able to rely on the
2895 // function to return true if the IME has moved and needs
2896 // its layer recomputed. However, if the IME was hidden
2897 // and isn't actually moved in the list, its layer may be
2898 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 assignLayers = true;
2900 }
2901 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002902 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002903 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002904 assignLayers = true;
2905 }
2906 }
Romain Guy06882f82009-06-10 13:36:04 -07002907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 mLayoutNeeded = true;
2909 win.mGivenInsetsPending = insetsPending;
2910 if (assignLayers) {
2911 assignLayersLocked();
2912 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002913 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002915 if (displayed && win.mIsWallpaper) {
2916 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002917 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 if (win.mAppToken != null) {
2920 win.mAppToken.updateReportedVisibilityLocked();
2921 }
2922 outFrame.set(win.mFrame);
2923 outContentInsets.set(win.mContentInsets);
2924 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002925 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002927 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 + ", requestedHeight=" + requestedHeight
2929 + ", viewVisibility=" + viewVisibility
2930 + "\nRelayout returning frame=" + outFrame
2931 + ", surface=" + outSurface);
2932
Joe Onorato8a9b2202010-02-26 18:56:32 -08002933 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2935
2936 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002937
2938 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 }
2940
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002941 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 sendNewConfiguration();
2943 }
Romain Guy06882f82009-06-10 13:36:04 -07002944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2948 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2949 }
2950
2951 public void finishDrawingWindow(Session session, IWindow client) {
2952 final long origId = Binder.clearCallingIdentity();
2953 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002954 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002955 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002956 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2957 adjustWallpaperWindowsLocked();
2958 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 mLayoutNeeded = true;
2960 performLayoutAndPlaceSurfacesLocked();
2961 }
2962 }
2963 Binder.restoreCallingIdentity(origId);
2964 }
2965
2966 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002967 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 + (lp != null ? lp.packageName : null)
2969 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2970 if (lp != null && lp.windowAnimations != 0) {
2971 // If this is a system resource, don't try to load it from the
2972 // application resources. It is nice to avoid loading application
2973 // resources if we can.
2974 String packageName = lp.packageName != null ? lp.packageName : "android";
2975 int resId = lp.windowAnimations;
2976 if ((resId&0xFF000000) == 0x01000000) {
2977 packageName = "android";
2978 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002979 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 + packageName);
2981 return AttributeCache.instance().get(packageName, resId,
2982 com.android.internal.R.styleable.WindowAnimation);
2983 }
2984 return null;
2985 }
Romain Guy06882f82009-06-10 13:36:04 -07002986
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002987 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002988 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002989 + packageName + " resId=0x" + Integer.toHexString(resId));
2990 if (packageName != null) {
2991 if ((resId&0xFF000000) == 0x01000000) {
2992 packageName = "android";
2993 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002994 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002995 + packageName);
2996 return AttributeCache.instance().get(packageName, resId,
2997 com.android.internal.R.styleable.WindowAnimation);
2998 }
2999 return null;
3000 }
3001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 private void applyEnterAnimationLocked(WindowState win) {
3003 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3004 if (win.mEnterAnimationPending) {
3005 win.mEnterAnimationPending = false;
3006 transit = WindowManagerPolicy.TRANSIT_ENTER;
3007 }
3008
3009 applyAnimationLocked(win, transit, true);
3010 }
3011
3012 private boolean applyAnimationLocked(WindowState win,
3013 int transit, boolean isEntrance) {
3014 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3015 // If we are trying to apply an animation, but already running
3016 // an animation of the same type, then just leave that one alone.
3017 return true;
3018 }
Romain Guy06882f82009-06-10 13:36:04 -07003019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003020 // Only apply an animation if the display isn't frozen. If it is
3021 // frozen, there is no reason to animate and it can cause strange
3022 // artifacts when we unfreeze the display if some different animation
3023 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003024 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 int anim = mPolicy.selectAnimationLw(win, transit);
3026 int attr = -1;
3027 Animation a = null;
3028 if (anim != 0) {
3029 a = AnimationUtils.loadAnimation(mContext, anim);
3030 } else {
3031 switch (transit) {
3032 case WindowManagerPolicy.TRANSIT_ENTER:
3033 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3034 break;
3035 case WindowManagerPolicy.TRANSIT_EXIT:
3036 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3037 break;
3038 case WindowManagerPolicy.TRANSIT_SHOW:
3039 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3040 break;
3041 case WindowManagerPolicy.TRANSIT_HIDE:
3042 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3043 break;
3044 }
3045 if (attr >= 0) {
3046 a = loadAnimation(win.mAttrs, attr);
3047 }
3048 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003049 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003050 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3051 + " mAnimation=" + win.mAnimation
3052 + " isEntrance=" + isEntrance);
3053 if (a != null) {
3054 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003055 RuntimeException e = null;
3056 if (!HIDE_STACK_CRAWLS) {
3057 e = new RuntimeException();
3058 e.fillInStackTrace();
3059 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003060 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 }
3062 win.setAnimation(a);
3063 win.mAnimationIsEntrance = isEntrance;
3064 }
3065 } else {
3066 win.clearAnimation();
3067 }
3068
3069 return win.mAnimation != null;
3070 }
3071
3072 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3073 int anim = 0;
3074 Context context = mContext;
3075 if (animAttr >= 0) {
3076 AttributeCache.Entry ent = getCachedAnimations(lp);
3077 if (ent != null) {
3078 context = ent.context;
3079 anim = ent.array.getResourceId(animAttr, 0);
3080 }
3081 }
3082 if (anim != 0) {
3083 return AnimationUtils.loadAnimation(context, anim);
3084 }
3085 return null;
3086 }
Romain Guy06882f82009-06-10 13:36:04 -07003087
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003088 private Animation loadAnimation(String packageName, int resId) {
3089 int anim = 0;
3090 Context context = mContext;
3091 if (resId >= 0) {
3092 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3093 if (ent != null) {
3094 context = ent.context;
3095 anim = resId;
3096 }
3097 }
3098 if (anim != 0) {
3099 return AnimationUtils.loadAnimation(context, anim);
3100 }
3101 return null;
3102 }
3103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 private boolean applyAnimationLocked(AppWindowToken wtoken,
3105 WindowManager.LayoutParams lp, int transit, boolean enter) {
3106 // Only apply an animation if the display isn't frozen. If it is
3107 // frozen, there is no reason to animate and it can cause strange
3108 // artifacts when we unfreeze the display if some different animation
3109 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003110 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003111 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003112 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003113 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003114 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003115 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003116 } else if (mNextAppTransitionPackage != null) {
3117 a = loadAnimation(mNextAppTransitionPackage, enter ?
3118 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003119 } else {
3120 int animAttr = 0;
3121 switch (transit) {
3122 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3123 animAttr = enter
3124 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3125 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3126 break;
3127 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3128 animAttr = enter
3129 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3130 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3131 break;
3132 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3133 animAttr = enter
3134 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3135 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3136 break;
3137 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3138 animAttr = enter
3139 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3140 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3141 break;
3142 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3143 animAttr = enter
3144 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3145 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3146 break;
3147 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3148 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003149 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003150 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3151 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003152 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003153 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003154 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3155 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003156 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003157 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003158 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003159 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3160 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3161 break;
3162 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3163 animAttr = enter
3164 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3165 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3166 break;
3167 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3168 animAttr = enter
3169 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3170 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003171 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003172 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003173 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003174 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003175 + " anim=" + a
3176 + " animAttr=0x" + Integer.toHexString(animAttr)
3177 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179 if (a != null) {
3180 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003181 RuntimeException e = null;
3182 if (!HIDE_STACK_CRAWLS) {
3183 e = new RuntimeException();
3184 e.fillInStackTrace();
3185 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003186 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 }
3188 wtoken.setAnimation(a);
3189 }
3190 } else {
3191 wtoken.clearAnimation();
3192 }
3193
3194 return wtoken.animation != null;
3195 }
3196
3197 // -------------------------------------------------------------
3198 // Application Window Tokens
3199 // -------------------------------------------------------------
3200
3201 public void validateAppTokens(List tokens) {
3202 int v = tokens.size()-1;
3203 int m = mAppTokens.size()-1;
3204 while (v >= 0 && m >= 0) {
3205 AppWindowToken wtoken = mAppTokens.get(m);
3206 if (wtoken.removed) {
3207 m--;
3208 continue;
3209 }
3210 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003211 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003212 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3213 }
3214 v--;
3215 m--;
3216 }
3217 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003218 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 v--;
3220 }
3221 while (m >= 0) {
3222 AppWindowToken wtoken = mAppTokens.get(m);
3223 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003224 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 }
3226 m--;
3227 }
3228 }
3229
3230 boolean checkCallingPermission(String permission, String func) {
3231 // Quick check: if the calling permission is me, it's all okay.
3232 if (Binder.getCallingPid() == Process.myPid()) {
3233 return true;
3234 }
Romain Guy06882f82009-06-10 13:36:04 -07003235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 if (mContext.checkCallingPermission(permission)
3237 == PackageManager.PERMISSION_GRANTED) {
3238 return true;
3239 }
3240 String msg = "Permission Denial: " + func + " from pid="
3241 + Binder.getCallingPid()
3242 + ", uid=" + Binder.getCallingUid()
3243 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003244 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 return false;
3246 }
Romain Guy06882f82009-06-10 13:36:04 -07003247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 AppWindowToken findAppWindowToken(IBinder token) {
3249 WindowToken wtoken = mTokenMap.get(token);
3250 if (wtoken == null) {
3251 return null;
3252 }
3253 return wtoken.appWindowToken;
3254 }
Romain Guy06882f82009-06-10 13:36:04 -07003255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 public void addWindowToken(IBinder token, int type) {
3257 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3258 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003259 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 }
Romain Guy06882f82009-06-10 13:36:04 -07003261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 synchronized(mWindowMap) {
3263 WindowToken wtoken = mTokenMap.get(token);
3264 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003265 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 return;
3267 }
3268 wtoken = new WindowToken(token, type, true);
3269 mTokenMap.put(token, wtoken);
3270 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003271 if (type == TYPE_WALLPAPER) {
3272 mWallpaperTokens.add(wtoken);
3273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 }
3275 }
Romain Guy06882f82009-06-10 13:36:04 -07003276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003277 public void removeWindowToken(IBinder token) {
3278 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3279 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003280 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 }
3282
3283 final long origId = Binder.clearCallingIdentity();
3284 synchronized(mWindowMap) {
3285 WindowToken wtoken = mTokenMap.remove(token);
3286 mTokenList.remove(wtoken);
3287 if (wtoken != null) {
3288 boolean delayed = false;
3289 if (!wtoken.hidden) {
3290 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 final int N = wtoken.windows.size();
3293 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 for (int i=0; i<N; i++) {
3296 WindowState win = wtoken.windows.get(i);
3297
3298 if (win.isAnimating()) {
3299 delayed = true;
3300 }
Romain Guy06882f82009-06-10 13:36:04 -07003301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 if (win.isVisibleNow()) {
3303 applyAnimationLocked(win,
3304 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 changed = true;
3306 }
3307 }
3308
3309 if (changed) {
3310 mLayoutNeeded = true;
3311 performLayoutAndPlaceSurfacesLocked();
3312 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3313 }
Romain Guy06882f82009-06-10 13:36:04 -07003314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 if (delayed) {
3316 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003317 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3318 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 }
3320 }
Romain Guy06882f82009-06-10 13:36:04 -07003321
Jeff Brownc5ed5912010-07-14 18:48:53 -07003322 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003324 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 }
3326 }
3327 Binder.restoreCallingIdentity(origId);
3328 }
3329
3330 public void addAppToken(int addPos, IApplicationToken token,
3331 int groupId, int requestedOrientation, boolean fullscreen) {
3332 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3333 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003334 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 }
Jeff Brown349703e2010-06-22 01:27:15 -07003336
3337 // Get the dispatching timeout here while we are not holding any locks so that it
3338 // can be cached by the AppWindowToken. The timeout value is used later by the
3339 // input dispatcher in code that does hold locks. If we did not cache the value
3340 // here we would run the chance of introducing a deadlock between the window manager
3341 // (which holds locks while updating the input dispatcher state) and the activity manager
3342 // (which holds locks while querying the application token).
3343 long inputDispatchingTimeoutNanos;
3344 try {
3345 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3346 } catch (RemoteException ex) {
3347 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3348 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3349 }
Romain Guy06882f82009-06-10 13:36:04 -07003350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003351 synchronized(mWindowMap) {
3352 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3353 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003354 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 return;
3356 }
3357 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003358 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 wtoken.groupId = groupId;
3360 wtoken.appFullscreen = fullscreen;
3361 wtoken.requestedOrientation = requestedOrientation;
3362 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003363 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 mTokenMap.put(token.asBinder(), wtoken);
3365 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 // Application tokens start out hidden.
3368 wtoken.hidden = true;
3369 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 //dump();
3372 }
3373 }
Romain Guy06882f82009-06-10 13:36:04 -07003374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 public void setAppGroupId(IBinder token, int groupId) {
3376 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3377 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003378 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 }
3380
3381 synchronized(mWindowMap) {
3382 AppWindowToken wtoken = findAppWindowToken(token);
3383 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003384 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 return;
3386 }
3387 wtoken.groupId = groupId;
3388 }
3389 }
Romain Guy06882f82009-06-10 13:36:04 -07003390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003391 public int getOrientationFromWindowsLocked() {
3392 int pos = mWindows.size() - 1;
3393 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003394 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 pos--;
3396 if (wtoken.mAppToken != null) {
3397 // We hit an application window. so the orientation will be determined by the
3398 // app window. No point in continuing further.
3399 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3400 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003401 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 continue;
3403 }
3404 int req = wtoken.mAttrs.screenOrientation;
3405 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3406 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3407 continue;
3408 } else {
3409 return req;
3410 }
3411 }
3412 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3413 }
Romain Guy06882f82009-06-10 13:36:04 -07003414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003416 int pos = mAppTokens.size() - 1;
3417 int curGroup = 0;
3418 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3419 boolean findingBehind = false;
3420 boolean haveGroup = false;
3421 boolean lastFullscreen = false;
3422 while (pos >= 0) {
3423 AppWindowToken wtoken = mAppTokens.get(pos);
3424 pos--;
3425 // if we're about to tear down this window and not seek for
3426 // the behind activity, don't use it for orientation
3427 if (!findingBehind
3428 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3429 continue;
3430 }
3431
3432 if (!haveGroup) {
3433 // We ignore any hidden applications on the top.
3434 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003435 continue;
3436 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003437 haveGroup = true;
3438 curGroup = wtoken.groupId;
3439 lastOrientation = wtoken.requestedOrientation;
3440 } else if (curGroup != wtoken.groupId) {
3441 // If we have hit a new application group, and the bottom
3442 // of the previous group didn't explicitly say to use
3443 // the orientation behind it, and the last app was
3444 // full screen, then we'll stick with the
3445 // user's orientation.
3446 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3447 && lastFullscreen) {
3448 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003451 int or = wtoken.requestedOrientation;
3452 // If this application is fullscreen, and didn't explicitly say
3453 // to use the orientation behind it, then just take whatever
3454 // orientation it has and ignores whatever is under it.
3455 lastFullscreen = wtoken.appFullscreen;
3456 if (lastFullscreen
3457 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3458 return or;
3459 }
3460 // If this application has requested an explicit orientation,
3461 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003462 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3463 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003464 return or;
3465 }
3466 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3467 }
3468 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003469 }
Romain Guy06882f82009-06-10 13:36:04 -07003470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003471 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003472 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003473 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3474 "updateOrientationFromAppTokens()")) {
3475 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3476 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003477
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003478 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003479 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003480
3481 synchronized(mWindowMap) {
3482 if (updateOrientationFromAppTokensLocked()) {
3483 if (freezeThisOneIfNeeded != null) {
3484 AppWindowToken wtoken = findAppWindowToken(
3485 freezeThisOneIfNeeded);
3486 if (wtoken != null) {
3487 startAppFreezingScreenLocked(wtoken,
3488 ActivityInfo.CONFIG_ORIENTATION);
3489 }
3490 }
3491 config = computeNewConfigurationLocked();
3492
3493 } else if (currentConfig != null) {
3494 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003495 // state mismatches the activity manager's, update it,
3496 // disregarding font scale, which should remain set to
3497 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003498 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003499 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003500 if (computeNewConfigurationLocked(mTempConfiguration)) {
3501 if (currentConfig.diff(mTempConfiguration) != 0) {
3502 mWaitingForConfig = true;
3503 mLayoutNeeded = true;
3504 startFreezingDisplayLocked();
3505 config = new Configuration(mTempConfiguration);
3506 }
3507 }
3508 }
3509 }
3510
Dianne Hackborncfaef692009-06-15 14:24:44 -07003511 Binder.restoreCallingIdentity(ident);
3512 return config;
3513 }
3514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003516 * Determine the new desired orientation of the display, returning
3517 * a non-null new Configuration if it has changed from the current
3518 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3519 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3520 * SCREEN. This will typically be done for you if you call
3521 * sendNewConfiguration().
3522 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 * The orientation is computed from non-application windows first. If none of
3524 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003525 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3527 * android.os.IBinder)
3528 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003529 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003530 if (mDisplayFrozen) {
3531 // If the display is frozen, some activities may be in the middle
3532 // of restarting, and thus have removed their old window. If the
3533 // window has the flag to hide the lock screen, then the lock screen
3534 // can re-appear and inflict its own orientation on us. Keep the
3535 // orientation stable until this all settles down.
3536 return false;
3537 }
3538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 long ident = Binder.clearCallingIdentity();
3541 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003542 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 mForcedAppOrientation = req;
3546 //send a message to Policy indicating orientation change to take
3547 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003548 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003549 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3550 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3551 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 }
3553 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003554
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003555 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 } finally {
3557 Binder.restoreCallingIdentity(ident);
3558 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 }
Romain Guy06882f82009-06-10 13:36:04 -07003560
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003561 int computeForcedAppOrientationLocked() {
3562 int req = getOrientationFromWindowsLocked();
3563 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3564 req = getOrientationFromAppTokensLocked();
3565 }
3566 return req;
3567 }
Romain Guy06882f82009-06-10 13:36:04 -07003568
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003569 public void setNewConfiguration(Configuration config) {
3570 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3571 "setNewConfiguration()")) {
3572 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3573 }
3574
3575 synchronized(mWindowMap) {
3576 mCurConfiguration = new Configuration(config);
3577 mWaitingForConfig = false;
3578 performLayoutAndPlaceSurfacesLocked();
3579 }
3580 }
3581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3583 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3584 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003585 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 }
Romain Guy06882f82009-06-10 13:36:04 -07003587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 synchronized(mWindowMap) {
3589 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3590 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003591 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 return;
3593 }
Romain Guy06882f82009-06-10 13:36:04 -07003594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 wtoken.requestedOrientation = requestedOrientation;
3596 }
3597 }
Romain Guy06882f82009-06-10 13:36:04 -07003598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 public int getAppOrientation(IApplicationToken token) {
3600 synchronized(mWindowMap) {
3601 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3602 if (wtoken == null) {
3603 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3604 }
Romain Guy06882f82009-06-10 13:36:04 -07003605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 return wtoken.requestedOrientation;
3607 }
3608 }
Romain Guy06882f82009-06-10 13:36:04 -07003609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3611 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3612 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003613 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 }
3615
3616 synchronized(mWindowMap) {
3617 boolean changed = false;
3618 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003619 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 changed = mFocusedApp != null;
3621 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003622 if (changed) {
3623 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 } else {
3626 AppWindowToken newFocus = findAppWindowToken(token);
3627 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003628 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 return;
3630 }
3631 changed = mFocusedApp != newFocus;
3632 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003633 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003634 if (changed) {
3635 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 }
3638
3639 if (moveFocusNow && changed) {
3640 final long origId = Binder.clearCallingIdentity();
3641 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3642 Binder.restoreCallingIdentity(origId);
3643 }
3644 }
3645 }
3646
3647 public void prepareAppTransition(int transit) {
3648 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3649 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003650 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 }
Romain Guy06882f82009-06-10 13:36:04 -07003652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003654 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 TAG, "Prepare app transition: transit=" + transit
3656 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003657 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003658 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3659 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003661 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3662 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3663 // Opening a new task always supersedes a close for the anim.
3664 mNextAppTransition = transit;
3665 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3666 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3667 // Opening a new activity always supersedes a close for the anim.
3668 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 }
3670 mAppTransitionReady = false;
3671 mAppTransitionTimeout = false;
3672 mStartingIconInTransition = false;
3673 mSkipAppTransitionAnimation = false;
3674 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3675 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3676 5000);
3677 }
3678 }
3679 }
3680
3681 public int getPendingAppTransition() {
3682 return mNextAppTransition;
3683 }
Romain Guy06882f82009-06-10 13:36:04 -07003684
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003685 public void overridePendingAppTransition(String packageName,
3686 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003687 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003688 mNextAppTransitionPackage = packageName;
3689 mNextAppTransitionEnter = enterAnim;
3690 mNextAppTransitionExit = exitAnim;
3691 }
3692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 public void executeAppTransition() {
3695 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3696 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003697 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 }
Romain Guy06882f82009-06-10 13:36:04 -07003699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003700 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003701 if (DEBUG_APP_TRANSITIONS) {
3702 RuntimeException e = new RuntimeException("here");
3703 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003704 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003705 + mNextAppTransition, e);
3706 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003707 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 mAppTransitionReady = true;
3709 final long origId = Binder.clearCallingIdentity();
3710 performLayoutAndPlaceSurfacesLocked();
3711 Binder.restoreCallingIdentity(origId);
3712 }
3713 }
3714 }
3715
3716 public void setAppStartingWindow(IBinder token, String pkg,
3717 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3718 IBinder transferFrom, boolean createIfNeeded) {
3719 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3720 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003721 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 }
3723
3724 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003725 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3727 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 AppWindowToken wtoken = findAppWindowToken(token);
3730 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003731 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003732 return;
3733 }
3734
3735 // If the display is frozen, we won't do anything until the
3736 // actual window is displayed so there is no reason to put in
3737 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003738 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 return;
3740 }
Romain Guy06882f82009-06-10 13:36:04 -07003741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 if (wtoken.startingData != null) {
3743 return;
3744 }
Romain Guy06882f82009-06-10 13:36:04 -07003745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 if (transferFrom != null) {
3747 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3748 if (ttoken != null) {
3749 WindowState startingWindow = ttoken.startingWindow;
3750 if (startingWindow != null) {
3751 if (mStartingIconInTransition) {
3752 // In this case, the starting icon has already
3753 // been displayed, so start letting windows get
3754 // shown immediately without any more transitions.
3755 mSkipAppTransitionAnimation = true;
3756 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003757 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 "Moving existing starting from " + ttoken
3759 + " to " + wtoken);
3760 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 // Transfer the starting window over to the new
3763 // token.
3764 wtoken.startingData = ttoken.startingData;
3765 wtoken.startingView = ttoken.startingView;
3766 wtoken.startingWindow = startingWindow;
3767 ttoken.startingData = null;
3768 ttoken.startingView = null;
3769 ttoken.startingWindow = null;
3770 ttoken.startingMoved = true;
3771 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003772 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003774 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003775 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003776 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003777 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 ttoken.windows.remove(startingWindow);
3779 ttoken.allAppWindows.remove(startingWindow);
3780 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 // Propagate other interesting state between the
3783 // tokens. If the old token is displayed, we should
3784 // immediately force the new one to be displayed. If
3785 // it is animating, we need to move that animation to
3786 // the new one.
3787 if (ttoken.allDrawn) {
3788 wtoken.allDrawn = true;
3789 }
3790 if (ttoken.firstWindowDrawn) {
3791 wtoken.firstWindowDrawn = true;
3792 }
3793 if (!ttoken.hidden) {
3794 wtoken.hidden = false;
3795 wtoken.hiddenRequested = false;
3796 wtoken.willBeHidden = false;
3797 }
3798 if (wtoken.clientHidden != ttoken.clientHidden) {
3799 wtoken.clientHidden = ttoken.clientHidden;
3800 wtoken.sendAppVisibilityToClients();
3801 }
3802 if (ttoken.animation != null) {
3803 wtoken.animation = ttoken.animation;
3804 wtoken.animating = ttoken.animating;
3805 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3806 ttoken.animation = null;
3807 ttoken.animLayerAdjustment = 0;
3808 wtoken.updateLayers();
3809 ttoken.updateLayers();
3810 }
Romain Guy06882f82009-06-10 13:36:04 -07003811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 mLayoutNeeded = true;
3814 performLayoutAndPlaceSurfacesLocked();
3815 Binder.restoreCallingIdentity(origId);
3816 return;
3817 } else if (ttoken.startingData != null) {
3818 // The previous app was getting ready to show a
3819 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003820 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 "Moving pending starting from " + ttoken
3822 + " to " + wtoken);
3823 wtoken.startingData = ttoken.startingData;
3824 ttoken.startingData = null;
3825 ttoken.startingMoved = true;
3826 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3827 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3828 // want to process the message ASAP, before any other queued
3829 // messages.
3830 mH.sendMessageAtFrontOfQueue(m);
3831 return;
3832 }
3833 }
3834 }
3835
3836 // There is no existing starting window, and the caller doesn't
3837 // want us to create one, so that's it!
3838 if (!createIfNeeded) {
3839 return;
3840 }
Romain Guy06882f82009-06-10 13:36:04 -07003841
Dianne Hackborn284ac932009-08-28 10:34:25 -07003842 // If this is a translucent or wallpaper window, then don't
3843 // show a starting window -- the current effect (a full-screen
3844 // opaque starting window that fades away to the real contents
3845 // when it is ready) does not work for this.
3846 if (theme != 0) {
3847 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3848 com.android.internal.R.styleable.Window);
3849 if (ent.array.getBoolean(
3850 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3851 return;
3852 }
3853 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003854 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3855 return;
3856 }
3857 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003858 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3859 return;
3860 }
3861 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863 mStartingIconInTransition = true;
3864 wtoken.startingData = new StartingData(
3865 pkg, theme, nonLocalizedLabel,
3866 labelRes, icon);
3867 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3868 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3869 // want to process the message ASAP, before any other queued
3870 // messages.
3871 mH.sendMessageAtFrontOfQueue(m);
3872 }
3873 }
3874
3875 public void setAppWillBeHidden(IBinder token) {
3876 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3877 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003878 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 }
3880
3881 AppWindowToken wtoken;
3882
3883 synchronized(mWindowMap) {
3884 wtoken = findAppWindowToken(token);
3885 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003886 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 -08003887 return;
3888 }
3889 wtoken.willBeHidden = true;
3890 }
3891 }
Romain Guy06882f82009-06-10 13:36:04 -07003892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3894 boolean visible, int transit, boolean performLayout) {
3895 boolean delayed = false;
3896
3897 if (wtoken.clientHidden == visible) {
3898 wtoken.clientHidden = !visible;
3899 wtoken.sendAppVisibilityToClients();
3900 }
Romain Guy06882f82009-06-10 13:36:04 -07003901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003902 wtoken.willBeHidden = false;
3903 if (wtoken.hidden == visible) {
3904 final int N = wtoken.allAppWindows.size();
3905 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3908 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003911
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003912 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003913 if (wtoken.animation == sDummyAnimation) {
3914 wtoken.animation = null;
3915 }
3916 applyAnimationLocked(wtoken, lp, transit, visible);
3917 changed = true;
3918 if (wtoken.animation != null) {
3919 delayed = runningAppAnimation = true;
3920 }
3921 }
Romain Guy06882f82009-06-10 13:36:04 -07003922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003923 for (int i=0; i<N; i++) {
3924 WindowState win = wtoken.allAppWindows.get(i);
3925 if (win == wtoken.startingWindow) {
3926 continue;
3927 }
3928
3929 if (win.isAnimating()) {
3930 delayed = true;
3931 }
Romain Guy06882f82009-06-10 13:36:04 -07003932
Joe Onorato8a9b2202010-02-26 18:56:32 -08003933 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934 //win.dump(" ");
3935 if (visible) {
3936 if (!win.isVisibleNow()) {
3937 if (!runningAppAnimation) {
3938 applyAnimationLocked(win,
3939 WindowManagerPolicy.TRANSIT_ENTER, true);
3940 }
3941 changed = true;
3942 }
3943 } else if (win.isVisibleNow()) {
3944 if (!runningAppAnimation) {
3945 applyAnimationLocked(win,
3946 WindowManagerPolicy.TRANSIT_EXIT, false);
3947 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 changed = true;
3949 }
3950 }
3951
3952 wtoken.hidden = wtoken.hiddenRequested = !visible;
3953 if (!visible) {
3954 unsetAppFreezingScreenLocked(wtoken, true, true);
3955 } else {
3956 // If we are being set visible, and the starting window is
3957 // not yet displayed, then make sure it doesn't get displayed.
3958 WindowState swin = wtoken.startingWindow;
3959 if (swin != null && (swin.mDrawPending
3960 || swin.mCommitDrawPending)) {
3961 swin.mPolicyVisibility = false;
3962 swin.mPolicyVisibilityAfterAnim = false;
3963 }
3964 }
Romain Guy06882f82009-06-10 13:36:04 -07003965
Joe Onorato8a9b2202010-02-26 18:56:32 -08003966 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3968 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003969
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003970 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003972 if (performLayout) {
3973 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3974 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003975 } else {
3976 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978 }
3979 }
3980
3981 if (wtoken.animation != null) {
3982 delayed = true;
3983 }
Romain Guy06882f82009-06-10 13:36:04 -07003984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 return delayed;
3986 }
3987
3988 public void setAppVisibility(IBinder token, boolean visible) {
3989 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3990 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003991 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 }
3993
3994 AppWindowToken wtoken;
3995
3996 synchronized(mWindowMap) {
3997 wtoken = findAppWindowToken(token);
3998 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003999 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 return;
4001 }
4002
4003 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004004 RuntimeException e = null;
4005 if (!HIDE_STACK_CRAWLS) {
4006 e = new RuntimeException();
4007 e.fillInStackTrace();
4008 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004009 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 + "): mNextAppTransition=" + mNextAppTransition
4011 + " hidden=" + wtoken.hidden
4012 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4013 }
Romain Guy06882f82009-06-10 13:36:04 -07004014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 // If we are preparing an app transition, then delay changing
4016 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004017 if (!mDisplayFrozen && mPolicy.isScreenOn()
4018 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 // Already in requested state, don't do anything more.
4020 if (wtoken.hiddenRequested != visible) {
4021 return;
4022 }
4023 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004024
Joe Onorato8a9b2202010-02-26 18:56:32 -08004025 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004026 TAG, "Setting dummy animation on: " + wtoken);
4027 wtoken.setDummyAnimation();
4028 mOpeningApps.remove(wtoken);
4029 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004030 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 wtoken.inPendingTransaction = true;
4032 if (visible) {
4033 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 wtoken.startingDisplayed = false;
4035 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004036
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004037 // If the token is currently hidden (should be the
4038 // common case), then we need to set up to wait for
4039 // its windows to be ready.
4040 if (wtoken.hidden) {
4041 wtoken.allDrawn = false;
4042 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004043
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004044 if (wtoken.clientHidden) {
4045 // In the case where we are making an app visible
4046 // but holding off for a transition, we still need
4047 // to tell the client to make its windows visible so
4048 // they get drawn. Otherwise, we will wait on
4049 // performing the transition until all windows have
4050 // been drawn, they never will be, and we are sad.
4051 wtoken.clientHidden = false;
4052 wtoken.sendAppVisibilityToClients();
4053 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 }
4055 } else {
4056 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004057
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004058 // If the token is currently visible (should be the
4059 // common case), then set up to wait for it to be hidden.
4060 if (!wtoken.hidden) {
4061 wtoken.waitingToHide = true;
4062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004063 }
4064 return;
4065 }
Romain Guy06882f82009-06-10 13:36:04 -07004066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004068 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004069 wtoken.updateReportedVisibilityLocked();
4070 Binder.restoreCallingIdentity(origId);
4071 }
4072 }
4073
4074 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4075 boolean unfreezeSurfaceNow, boolean force) {
4076 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004077 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 + " force=" + force);
4079 final int N = wtoken.allAppWindows.size();
4080 boolean unfrozeWindows = false;
4081 for (int i=0; i<N; i++) {
4082 WindowState w = wtoken.allAppWindows.get(i);
4083 if (w.mAppFreezing) {
4084 w.mAppFreezing = false;
4085 if (w.mSurface != null && !w.mOrientationChanging) {
4086 w.mOrientationChanging = true;
4087 }
4088 unfrozeWindows = true;
4089 }
4090 }
4091 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004092 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 wtoken.freezingScreen = false;
4094 mAppsFreezingScreen--;
4095 }
4096 if (unfreezeSurfaceNow) {
4097 if (unfrozeWindows) {
4098 mLayoutNeeded = true;
4099 performLayoutAndPlaceSurfacesLocked();
4100 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004101 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 }
4103 }
4104 }
Romain Guy06882f82009-06-10 13:36:04 -07004105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004106 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4107 int configChanges) {
4108 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004109 RuntimeException e = null;
4110 if (!HIDE_STACK_CRAWLS) {
4111 e = new RuntimeException();
4112 e.fillInStackTrace();
4113 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004114 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 + ": hidden=" + wtoken.hidden + " freezing="
4116 + wtoken.freezingScreen, e);
4117 }
4118 if (!wtoken.hiddenRequested) {
4119 if (!wtoken.freezingScreen) {
4120 wtoken.freezingScreen = true;
4121 mAppsFreezingScreen++;
4122 if (mAppsFreezingScreen == 1) {
4123 startFreezingDisplayLocked();
4124 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4125 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4126 5000);
4127 }
4128 }
4129 final int N = wtoken.allAppWindows.size();
4130 for (int i=0; i<N; i++) {
4131 WindowState w = wtoken.allAppWindows.get(i);
4132 w.mAppFreezing = true;
4133 }
4134 }
4135 }
Romain Guy06882f82009-06-10 13:36:04 -07004136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004137 public void startAppFreezingScreen(IBinder token, int configChanges) {
4138 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4139 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004140 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 }
4142
4143 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004144 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004145 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004146 return;
4147 }
Romain Guy06882f82009-06-10 13:36:04 -07004148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 AppWindowToken wtoken = findAppWindowToken(token);
4150 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004151 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004152 return;
4153 }
4154 final long origId = Binder.clearCallingIdentity();
4155 startAppFreezingScreenLocked(wtoken, configChanges);
4156 Binder.restoreCallingIdentity(origId);
4157 }
4158 }
Romain Guy06882f82009-06-10 13:36:04 -07004159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 public void stopAppFreezingScreen(IBinder token, boolean force) {
4161 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4162 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004163 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 }
4165
4166 synchronized(mWindowMap) {
4167 AppWindowToken wtoken = findAppWindowToken(token);
4168 if (wtoken == null || wtoken.appToken == null) {
4169 return;
4170 }
4171 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004172 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4174 unsetAppFreezingScreenLocked(wtoken, true, force);
4175 Binder.restoreCallingIdentity(origId);
4176 }
4177 }
Romain Guy06882f82009-06-10 13:36:04 -07004178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 public void removeAppToken(IBinder token) {
4180 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4181 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004182 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004183 }
4184
4185 AppWindowToken wtoken = null;
4186 AppWindowToken startingToken = null;
4187 boolean delayed = false;
4188
4189 final long origId = Binder.clearCallingIdentity();
4190 synchronized(mWindowMap) {
4191 WindowToken basewtoken = mTokenMap.remove(token);
4192 mTokenList.remove(basewtoken);
4193 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004194 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004195 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004196 wtoken.inPendingTransaction = false;
4197 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004198 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 if (mClosingApps.contains(wtoken)) {
4200 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004201 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004203 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 delayed = true;
4205 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004206 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 TAG, "Removing app " + wtoken + " delayed=" + delayed
4208 + " animation=" + wtoken.animation
4209 + " animating=" + wtoken.animating);
4210 if (delayed) {
4211 // set the token aside because it has an active animation to be finished
4212 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004213 } else {
4214 // Make sure there is no animation running on this token,
4215 // so any windows associated with it will be removed as
4216 // soon as their animations are complete
4217 wtoken.animation = null;
4218 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 }
4220 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004221 if (mLastEnterAnimToken == wtoken) {
4222 mLastEnterAnimToken = null;
4223 mLastEnterAnimParams = null;
4224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 wtoken.removed = true;
4226 if (wtoken.startingData != null) {
4227 startingToken = wtoken;
4228 }
4229 unsetAppFreezingScreenLocked(wtoken, true, true);
4230 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004231 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004232 mFocusedApp = null;
4233 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004234 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004235 }
4236 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004237 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 }
Romain Guy06882f82009-06-10 13:36:04 -07004239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004240 if (!delayed && wtoken != null) {
4241 wtoken.updateReportedVisibilityLocked();
4242 }
4243 }
4244 Binder.restoreCallingIdentity(origId);
4245
4246 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004247 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 + startingToken + ": app token removed");
4249 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4250 mH.sendMessage(m);
4251 }
4252 }
4253
4254 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4255 final int NW = token.windows.size();
4256 for (int i=0; i<NW; i++) {
4257 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004258 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004259 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004260 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 int j = win.mChildWindows.size();
4262 while (j > 0) {
4263 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004264 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004265 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004266 "Tmp removing child window " + cwin);
4267 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 }
4269 }
4270 return NW > 0;
4271 }
4272
4273 void dumpAppTokensLocked() {
4274 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004275 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 }
4277 }
Romain Guy06882f82009-06-10 13:36:04 -07004278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 void dumpWindowsLocked() {
4280 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004281 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 }
4283 }
Romain Guy06882f82009-06-10 13:36:04 -07004284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 private int findWindowOffsetLocked(int tokenPos) {
4286 final int NW = mWindows.size();
4287
4288 if (tokenPos >= mAppTokens.size()) {
4289 int i = NW;
4290 while (i > 0) {
4291 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004292 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 if (win.getAppToken() != null) {
4294 return i+1;
4295 }
4296 }
4297 }
4298
4299 while (tokenPos > 0) {
4300 // Find the first app token below the new position that has
4301 // a window displayed.
4302 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004303 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004305 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004306 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004307 "Skipping token -- currently sending to bottom");
4308 tokenPos--;
4309 continue;
4310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 int i = wtoken.windows.size();
4312 while (i > 0) {
4313 i--;
4314 WindowState win = wtoken.windows.get(i);
4315 int j = win.mChildWindows.size();
4316 while (j > 0) {
4317 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004318 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004319 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 for (int pos=NW-1; pos>=0; pos--) {
4321 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004322 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 "Found child win @" + (pos+1));
4324 return pos+1;
4325 }
4326 }
4327 }
4328 }
4329 for (int pos=NW-1; pos>=0; pos--) {
4330 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004331 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 return pos+1;
4333 }
4334 }
4335 }
4336 tokenPos--;
4337 }
4338
4339 return 0;
4340 }
4341
4342 private final int reAddWindowLocked(int index, WindowState win) {
4343 final int NCW = win.mChildWindows.size();
4344 boolean added = false;
4345 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004346 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004348 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004349 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 mWindows.add(index, win);
4351 index++;
4352 added = true;
4353 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004354 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004355 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 mWindows.add(index, cwin);
4357 index++;
4358 }
4359 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004360 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004361 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 mWindows.add(index, win);
4363 index++;
4364 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004365 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 return index;
4367 }
Romain Guy06882f82009-06-10 13:36:04 -07004368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4370 final int NW = token.windows.size();
4371 for (int i=0; i<NW; i++) {
4372 index = reAddWindowLocked(index, token.windows.get(i));
4373 }
4374 return index;
4375 }
4376
4377 public void moveAppToken(int index, IBinder token) {
4378 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4379 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004380 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004381 }
4382
4383 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004384 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 if (DEBUG_REORDER) dumpAppTokensLocked();
4386 final AppWindowToken wtoken = findAppWindowToken(token);
4387 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004388 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 + token + " (" + wtoken + ")");
4390 return;
4391 }
4392 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004393 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004397 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 if (DEBUG_REORDER) dumpWindowsLocked();
4399 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004400 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 if (DEBUG_REORDER) dumpWindowsLocked();
4402 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004403 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404 if (DEBUG_REORDER) dumpWindowsLocked();
4405 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 mLayoutNeeded = true;
4407 performLayoutAndPlaceSurfacesLocked();
4408 }
4409 Binder.restoreCallingIdentity(origId);
4410 }
4411 }
4412
4413 private void removeAppTokensLocked(List<IBinder> tokens) {
4414 // XXX This should be done more efficiently!
4415 // (take advantage of the fact that both lists should be
4416 // ordered in the same way.)
4417 int N = tokens.size();
4418 for (int i=0; i<N; i++) {
4419 IBinder token = tokens.get(i);
4420 final AppWindowToken wtoken = findAppWindowToken(token);
4421 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004422 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 + token + " (" + wtoken + ")");
4424 i--;
4425 N--;
4426 }
4427 }
4428 }
4429
Dianne Hackborna8f60182009-09-01 19:01:50 -07004430 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4431 boolean updateFocusAndLayout) {
4432 // First remove all of the windows from the list.
4433 tmpRemoveAppWindowsLocked(wtoken);
4434
4435 // Where to start adding?
4436 int pos = findWindowOffsetLocked(tokenPos);
4437
4438 // And now add them back at the correct place.
4439 pos = reAddAppWindowsLocked(pos, wtoken);
4440
4441 if (updateFocusAndLayout) {
4442 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4443 assignLayersLocked();
4444 }
4445 mLayoutNeeded = true;
4446 performLayoutAndPlaceSurfacesLocked();
4447 }
4448 }
4449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004450 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4451 // First remove all of the windows from the list.
4452 final int N = tokens.size();
4453 int i;
4454 for (i=0; i<N; i++) {
4455 WindowToken token = mTokenMap.get(tokens.get(i));
4456 if (token != null) {
4457 tmpRemoveAppWindowsLocked(token);
4458 }
4459 }
4460
4461 // Where to start adding?
4462 int pos = findWindowOffsetLocked(tokenPos);
4463
4464 // And now add them back at the correct place.
4465 for (i=0; i<N; i++) {
4466 WindowToken token = mTokenMap.get(tokens.get(i));
4467 if (token != null) {
4468 pos = reAddAppWindowsLocked(pos, token);
4469 }
4470 }
4471
Dianne Hackborna8f60182009-09-01 19:01:50 -07004472 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4473 assignLayersLocked();
4474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 mLayoutNeeded = true;
4476 performLayoutAndPlaceSurfacesLocked();
4477
4478 //dump();
4479 }
4480
4481 public void moveAppTokensToTop(List<IBinder> tokens) {
4482 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4483 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004484 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 }
4486
4487 final long origId = Binder.clearCallingIdentity();
4488 synchronized(mWindowMap) {
4489 removeAppTokensLocked(tokens);
4490 final int N = tokens.size();
4491 for (int i=0; i<N; i++) {
4492 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4493 if (wt != null) {
4494 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004495 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004496 mToTopApps.remove(wt);
4497 mToBottomApps.remove(wt);
4498 mToTopApps.add(wt);
4499 wt.sendingToBottom = false;
4500 wt.sendingToTop = true;
4501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 }
4503 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004504
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004505 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004506 moveAppWindowsLocked(tokens, mAppTokens.size());
4507 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508 }
4509 Binder.restoreCallingIdentity(origId);
4510 }
4511
4512 public void moveAppTokensToBottom(List<IBinder> tokens) {
4513 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4514 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004515 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 }
4517
4518 final long origId = Binder.clearCallingIdentity();
4519 synchronized(mWindowMap) {
4520 removeAppTokensLocked(tokens);
4521 final int N = tokens.size();
4522 int pos = 0;
4523 for (int i=0; i<N; i++) {
4524 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4525 if (wt != null) {
4526 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004527 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004528 mToTopApps.remove(wt);
4529 mToBottomApps.remove(wt);
4530 mToBottomApps.add(i, wt);
4531 wt.sendingToTop = false;
4532 wt.sendingToBottom = true;
4533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004534 pos++;
4535 }
4536 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004537
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004538 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004539 moveAppWindowsLocked(tokens, 0);
4540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004541 }
4542 Binder.restoreCallingIdentity(origId);
4543 }
4544
4545 // -------------------------------------------------------------
4546 // Misc IWindowSession methods
4547 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004548
Jim Miller284b62e2010-06-08 14:27:42 -07004549 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004550 {
Jim Miller284b62e2010-06-08 14:27:42 -07004551 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4552 // called before DevicePolicyManagerService has started.
4553 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4554 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4555 Context.DEVICE_POLICY_SERVICE);
4556 if (dpm != null) {
4557 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4558 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4559 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4560 }
Jim Millerd6b57052010-06-07 17:52:42 -07004561 }
Jim Miller284b62e2010-06-08 14:27:42 -07004562 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004563 }
4564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004566 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004567 != PackageManager.PERMISSION_GRANTED) {
4568 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4569 }
Jim Millerd6b57052010-06-07 17:52:42 -07004570
Jim Miller284b62e2010-06-08 14:27:42 -07004571 synchronized (mKeyguardTokenWatcher) {
4572 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004574 }
4575
4576 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004577 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578 != PackageManager.PERMISSION_GRANTED) {
4579 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581
Jim Miller284b62e2010-06-08 14:27:42 -07004582 synchronized (mKeyguardTokenWatcher) {
4583 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004584
Jim Miller284b62e2010-06-08 14:27:42 -07004585 if (!mKeyguardTokenWatcher.isAcquired()) {
4586 // If we are the last one to reenable the keyguard wait until
4587 // we have actually finished reenabling until returning.
4588 // It is possible that reenableKeyguard() can be called before
4589 // the previous disableKeyguard() is handled, in which case
4590 // neither mKeyguardTokenWatcher.acquired() or released() would
4591 // be called. In that case mKeyguardDisabled will be false here
4592 // and we have nothing to wait for.
4593 while (mKeyguardDisabled) {
4594 try {
4595 mKeyguardTokenWatcher.wait();
4596 } catch (InterruptedException e) {
4597 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 }
4599 }
4600 }
4601 }
4602 }
4603
4604 /**
4605 * @see android.app.KeyguardManager#exitKeyguardSecurely
4606 */
4607 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004608 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004609 != PackageManager.PERMISSION_GRANTED) {
4610 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4611 }
4612 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4613 public void onKeyguardExitResult(boolean success) {
4614 try {
4615 callback.onKeyguardExitResult(success);
4616 } catch (RemoteException e) {
4617 // Client has died, we don't care.
4618 }
4619 }
4620 });
4621 }
4622
4623 public boolean inKeyguardRestrictedInputMode() {
4624 return mPolicy.inKeyguardRestrictedKeyInputMode();
4625 }
Romain Guy06882f82009-06-10 13:36:04 -07004626
Dianne Hackbornffa42482009-09-23 22:20:11 -07004627 public void closeSystemDialogs(String reason) {
4628 synchronized(mWindowMap) {
4629 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004630 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004631 if (w.mSurface != null) {
4632 try {
4633 w.mClient.closeSystemDialogs(reason);
4634 } catch (RemoteException e) {
4635 }
4636 }
4637 }
4638 }
4639 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 static float fixScale(float scale) {
4642 if (scale < 0) scale = 0;
4643 else if (scale > 20) scale = 20;
4644 return Math.abs(scale);
4645 }
Romain Guy06882f82009-06-10 13:36:04 -07004646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004647 public void setAnimationScale(int which, float scale) {
4648 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4649 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004650 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 }
4652
4653 if (scale < 0) scale = 0;
4654 else if (scale > 20) scale = 20;
4655 scale = Math.abs(scale);
4656 switch (which) {
4657 case 0: mWindowAnimationScale = fixScale(scale); break;
4658 case 1: mTransitionAnimationScale = fixScale(scale); break;
4659 }
Romain Guy06882f82009-06-10 13:36:04 -07004660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 // Persist setting
4662 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4663 }
Romain Guy06882f82009-06-10 13:36:04 -07004664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 public void setAnimationScales(float[] scales) {
4666 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4667 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004668 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004669 }
4670
4671 if (scales != null) {
4672 if (scales.length >= 1) {
4673 mWindowAnimationScale = fixScale(scales[0]);
4674 }
4675 if (scales.length >= 2) {
4676 mTransitionAnimationScale = fixScale(scales[1]);
4677 }
4678 }
Romain Guy06882f82009-06-10 13:36:04 -07004679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004680 // Persist setting
4681 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4682 }
Romain Guy06882f82009-06-10 13:36:04 -07004683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 public float getAnimationScale(int which) {
4685 switch (which) {
4686 case 0: return mWindowAnimationScale;
4687 case 1: return mTransitionAnimationScale;
4688 }
4689 return 0;
4690 }
Romain Guy06882f82009-06-10 13:36:04 -07004691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004692 public float[] getAnimationScales() {
4693 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4694 }
Romain Guy06882f82009-06-10 13:36:04 -07004695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 public int getSwitchState(int sw) {
4697 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4698 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004699 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004701 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702 }
Romain Guy06882f82009-06-10 13:36:04 -07004703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004704 public int getSwitchStateForDevice(int devid, int sw) {
4705 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4706 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004707 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004708 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004709 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 }
Romain Guy06882f82009-06-10 13:36:04 -07004711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 public int getScancodeState(int sw) {
4713 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4714 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004715 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004716 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004717 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718 }
Romain Guy06882f82009-06-10 13:36:04 -07004719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004720 public int getScancodeStateForDevice(int devid, int sw) {
4721 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4722 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004723 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004725 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004726 }
Romain Guy06882f82009-06-10 13:36:04 -07004727
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004728 public int getTrackballScancodeState(int sw) {
4729 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4730 "getTrackballScancodeState()")) {
4731 throw new SecurityException("Requires READ_INPUT_STATE permission");
4732 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004733 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004734 }
4735
4736 public int getDPadScancodeState(int sw) {
4737 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4738 "getDPadScancodeState()")) {
4739 throw new SecurityException("Requires READ_INPUT_STATE permission");
4740 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004741 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004742 }
4743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004744 public int getKeycodeState(int sw) {
4745 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4746 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004747 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004748 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004749 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004750 }
Romain Guy06882f82009-06-10 13:36:04 -07004751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004752 public int getKeycodeStateForDevice(int devid, int sw) {
4753 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4754 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004755 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004756 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004757 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004758 }
Romain Guy06882f82009-06-10 13:36:04 -07004759
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004760 public int getTrackballKeycodeState(int sw) {
4761 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4762 "getTrackballKeycodeState()")) {
4763 throw new SecurityException("Requires READ_INPUT_STATE permission");
4764 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004765 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004766 }
4767
4768 public int getDPadKeycodeState(int sw) {
4769 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4770 "getDPadKeycodeState()")) {
4771 throw new SecurityException("Requires READ_INPUT_STATE permission");
4772 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004773 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004774 }
Jeff Browna41ca772010-08-11 14:46:32 -07004775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004776 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004777 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 }
Romain Guy06882f82009-06-10 13:36:04 -07004779
Jeff Browna41ca772010-08-11 14:46:32 -07004780 public InputChannel monitorInput(String inputChannelName) {
4781 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4782 "monitorInput()")) {
4783 throw new SecurityException("Requires READ_INPUT_STATE permission");
4784 }
4785 return mInputManager.monitorInput(inputChannelName);
4786 }
4787
Jeff Brown8d608662010-08-30 03:02:23 -07004788 public InputDevice getInputDevice(int deviceId) {
4789 return mInputManager.getInputDevice(deviceId);
4790 }
4791
4792 public int[] getInputDeviceIds() {
4793 return mInputManager.getInputDeviceIds();
4794 }
4795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 public void enableScreenAfterBoot() {
4797 synchronized(mWindowMap) {
4798 if (mSystemBooted) {
4799 return;
4800 }
4801 mSystemBooted = true;
4802 }
Romain Guy06882f82009-06-10 13:36:04 -07004803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 performEnableScreen();
4805 }
Romain Guy06882f82009-06-10 13:36:04 -07004806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 public void enableScreenIfNeededLocked() {
4808 if (mDisplayEnabled) {
4809 return;
4810 }
4811 if (!mSystemBooted) {
4812 return;
4813 }
4814 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4815 }
Romain Guy06882f82009-06-10 13:36:04 -07004816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004817 public void performEnableScreen() {
4818 synchronized(mWindowMap) {
4819 if (mDisplayEnabled) {
4820 return;
4821 }
4822 if (!mSystemBooted) {
4823 return;
4824 }
Romain Guy06882f82009-06-10 13:36:04 -07004825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004826 // Don't enable the screen until all existing windows
4827 // have been drawn.
4828 final int N = mWindows.size();
4829 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004830 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004831 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004832 return;
4833 }
4834 }
Romain Guy06882f82009-06-10 13:36:04 -07004835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004836 mDisplayEnabled = true;
4837 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004838 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 StringWriter sw = new StringWriter();
4840 PrintWriter pw = new PrintWriter(sw);
4841 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004842 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 }
4844 try {
4845 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4846 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004847 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 Parcel data = Parcel.obtain();
4849 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4850 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4851 data, null, 0);
4852 data.recycle();
4853 }
4854 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004855 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 }
4857 }
Romain Guy06882f82009-06-10 13:36:04 -07004858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004861 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004862 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4863 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 }
Romain Guy06882f82009-06-10 13:36:04 -07004865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004866 public void setInTouchMode(boolean mode) {
4867 synchronized(mWindowMap) {
4868 mInTouchMode = mode;
4869 }
4870 }
4871
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004872 public void freezeRotation() {
4873 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4874 "setRotation()")) {
4875 throw new SecurityException("Requires SET_ORIENTATION permission");
4876 }
4877
4878 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4879 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4880 }
4881
4882 public void thawRotation() {
4883 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4884 "setRotation()")) {
4885 throw new SecurityException("Requires SET_ORIENTATION permission");
4886 }
4887
4888 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4889 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4890 }
4891
Romain Guy06882f82009-06-10 13:36:04 -07004892 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004893 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004894 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004895 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004896 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 }
4898
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004899 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900 }
Romain Guy06882f82009-06-10 13:36:04 -07004901
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004902 public void setRotationUnchecked(int rotation,
4903 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004904 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004905 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004907 long origId = Binder.clearCallingIdentity();
4908 boolean changed;
4909 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004910 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 }
Romain Guy06882f82009-06-10 13:36:04 -07004912
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004913 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004914 sendNewConfiguration();
4915 }
Romain Guy06882f82009-06-10 13:36:04 -07004916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 Binder.restoreCallingIdentity(origId);
4918 }
Romain Guy06882f82009-06-10 13:36:04 -07004919
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004920 /**
4921 * Apply a new rotation to the screen, respecting the requests of
4922 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4923 * re-evaluate the desired rotation.
4924 *
4925 * Returns null if the rotation has been changed. In this case YOU
4926 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4927 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004928 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929 boolean changed;
4930 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4931 rotation = mRequestedRotation;
4932 } else {
4933 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004934 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004936 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004937 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004938 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004939 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004940 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004943 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004944 "Rotation changed to " + rotation
4945 + " from " + mRotation
4946 + " (forceApp=" + mForcedAppOrientation
4947 + ", req=" + mRequestedRotation + ")");
4948 mRotation = rotation;
4949 mWindowsFreezingScreen = true;
4950 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4951 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4952 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004953 mWaitingForConfig = true;
4954 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004956 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004957 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004958 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004959 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004960 }
4961 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004962 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004963 if (w.mSurface != null) {
4964 w.mOrientationChanging = true;
4965 }
4966 }
4967 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4968 try {
4969 mRotationWatchers.get(i).onRotationChanged(rotation);
4970 } catch (RemoteException e) {
4971 }
4972 }
4973 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 return changed;
4976 }
Romain Guy06882f82009-06-10 13:36:04 -07004977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004978 public int getRotation() {
4979 return mRotation;
4980 }
4981
4982 public int watchRotation(IRotationWatcher watcher) {
4983 final IBinder watcherBinder = watcher.asBinder();
4984 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4985 public void binderDied() {
4986 synchronized (mWindowMap) {
4987 for (int i=0; i<mRotationWatchers.size(); i++) {
4988 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004989 IRotationWatcher removed = mRotationWatchers.remove(i);
4990 if (removed != null) {
4991 removed.asBinder().unlinkToDeath(this, 0);
4992 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004993 i--;
4994 }
4995 }
4996 }
4997 }
4998 };
Romain Guy06882f82009-06-10 13:36:04 -07004999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005000 synchronized (mWindowMap) {
5001 try {
5002 watcher.asBinder().linkToDeath(dr, 0);
5003 mRotationWatchers.add(watcher);
5004 } catch (RemoteException e) {
5005 // Client died, no cleanup needed.
5006 }
Romain Guy06882f82009-06-10 13:36:04 -07005007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005008 return mRotation;
5009 }
5010 }
5011
5012 /**
5013 * Starts the view server on the specified port.
5014 *
5015 * @param port The port to listener to.
5016 *
5017 * @return True if the server was successfully started, false otherwise.
5018 *
5019 * @see com.android.server.ViewServer
5020 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5021 */
5022 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005023 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005024 return false;
5025 }
5026
5027 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5028 return false;
5029 }
5030
5031 if (port < 1024) {
5032 return false;
5033 }
5034
5035 if (mViewServer != null) {
5036 if (!mViewServer.isRunning()) {
5037 try {
5038 return mViewServer.start();
5039 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005040 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 }
5042 }
5043 return false;
5044 }
5045
5046 try {
5047 mViewServer = new ViewServer(this, port);
5048 return mViewServer.start();
5049 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005050 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005051 }
5052 return false;
5053 }
5054
Romain Guy06882f82009-06-10 13:36:04 -07005055 private boolean isSystemSecure() {
5056 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5057 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5058 }
5059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005060 /**
5061 * Stops the view server if it exists.
5062 *
5063 * @return True if the server stopped, false if it wasn't started or
5064 * couldn't be stopped.
5065 *
5066 * @see com.android.server.ViewServer
5067 */
5068 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005069 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005070 return false;
5071 }
5072
5073 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5074 return false;
5075 }
5076
5077 if (mViewServer != null) {
5078 return mViewServer.stop();
5079 }
5080 return false;
5081 }
5082
5083 /**
5084 * Indicates whether the view server is running.
5085 *
5086 * @return True if the server is running, false otherwise.
5087 *
5088 * @see com.android.server.ViewServer
5089 */
5090 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005091 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005092 return false;
5093 }
5094
5095 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5096 return false;
5097 }
5098
5099 return mViewServer != null && mViewServer.isRunning();
5100 }
5101
5102 /**
5103 * Lists all availble windows in the system. The listing is written in the
5104 * specified Socket's output stream with the following syntax:
5105 * windowHashCodeInHexadecimal windowName
5106 * Each line of the ouput represents a different window.
5107 *
5108 * @param client The remote client to send the listing to.
5109 * @return False if an error occured, true otherwise.
5110 */
5111 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005112 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005113 return false;
5114 }
5115
5116 boolean result = true;
5117
Jeff Browne33348b2010-07-15 23:54:05 -07005118 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005119 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005120 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005121 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005122 }
5123
5124 BufferedWriter out = null;
5125
5126 // Any uncaught exception will crash the system process
5127 try {
5128 OutputStream clientStream = client.getOutputStream();
5129 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5130
5131 final int count = windows.length;
5132 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005133 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005134 out.write(Integer.toHexString(System.identityHashCode(w)));
5135 out.write(' ');
5136 out.append(w.mAttrs.getTitle());
5137 out.write('\n');
5138 }
5139
5140 out.write("DONE.\n");
5141 out.flush();
5142 } catch (Exception e) {
5143 result = false;
5144 } finally {
5145 if (out != null) {
5146 try {
5147 out.close();
5148 } catch (IOException e) {
5149 result = false;
5150 }
5151 }
5152 }
5153
5154 return result;
5155 }
5156
5157 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005158 * Returns the focused window in the following format:
5159 * windowHashCodeInHexadecimal windowName
5160 *
5161 * @param client The remote client to send the listing to.
5162 * @return False if an error occurred, true otherwise.
5163 */
5164 boolean viewServerGetFocusedWindow(Socket client) {
5165 if (isSystemSecure()) {
5166 return false;
5167 }
5168
5169 boolean result = true;
5170
5171 WindowState focusedWindow = getFocusedWindow();
5172
5173 BufferedWriter out = null;
5174
5175 // Any uncaught exception will crash the system process
5176 try {
5177 OutputStream clientStream = client.getOutputStream();
5178 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5179
5180 if(focusedWindow != null) {
5181 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5182 out.write(' ');
5183 out.append(focusedWindow.mAttrs.getTitle());
5184 }
5185 out.write('\n');
5186 out.flush();
5187 } catch (Exception e) {
5188 result = false;
5189 } finally {
5190 if (out != null) {
5191 try {
5192 out.close();
5193 } catch (IOException e) {
5194 result = false;
5195 }
5196 }
5197 }
5198
5199 return result;
5200 }
5201
5202 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005203 * Sends a command to a target window. The result of the command, if any, will be
5204 * written in the output stream of the specified socket.
5205 *
5206 * The parameters must follow this syntax:
5207 * windowHashcode extra
5208 *
5209 * Where XX is the length in characeters of the windowTitle.
5210 *
5211 * The first parameter is the target window. The window with the specified hashcode
5212 * will be the target. If no target can be found, nothing happens. The extra parameters
5213 * will be delivered to the target window and as parameters to the command itself.
5214 *
5215 * @param client The remote client to sent the result, if any, to.
5216 * @param command The command to execute.
5217 * @param parameters The command parameters.
5218 *
5219 * @return True if the command was successfully delivered, false otherwise. This does
5220 * not indicate whether the command itself was successful.
5221 */
5222 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005223 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 return false;
5225 }
5226
5227 boolean success = true;
5228 Parcel data = null;
5229 Parcel reply = null;
5230
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005231 BufferedWriter out = null;
5232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005233 // Any uncaught exception will crash the system process
5234 try {
5235 // Find the hashcode of the window
5236 int index = parameters.indexOf(' ');
5237 if (index == -1) {
5238 index = parameters.length();
5239 }
5240 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005241 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005242
5243 // Extract the command's parameter after the window description
5244 if (index < parameters.length()) {
5245 parameters = parameters.substring(index + 1);
5246 } else {
5247 parameters = "";
5248 }
5249
5250 final WindowManagerService.WindowState window = findWindow(hashCode);
5251 if (window == null) {
5252 return false;
5253 }
5254
5255 data = Parcel.obtain();
5256 data.writeInterfaceToken("android.view.IWindow");
5257 data.writeString(command);
5258 data.writeString(parameters);
5259 data.writeInt(1);
5260 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5261
5262 reply = Parcel.obtain();
5263
5264 final IBinder binder = window.mClient.asBinder();
5265 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5266 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5267
5268 reply.readException();
5269
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005270 if (!client.isOutputShutdown()) {
5271 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5272 out.write("DONE\n");
5273 out.flush();
5274 }
5275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005276 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005277 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005278 success = false;
5279 } finally {
5280 if (data != null) {
5281 data.recycle();
5282 }
5283 if (reply != null) {
5284 reply.recycle();
5285 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005286 if (out != null) {
5287 try {
5288 out.close();
5289 } catch (IOException e) {
5290
5291 }
5292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005293 }
5294
5295 return success;
5296 }
5297
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005298 public void addWindowChangeListener(WindowChangeListener listener) {
5299 synchronized(mWindowMap) {
5300 mWindowChangeListeners.add(listener);
5301 }
5302 }
5303
5304 public void removeWindowChangeListener(WindowChangeListener listener) {
5305 synchronized(mWindowMap) {
5306 mWindowChangeListeners.remove(listener);
5307 }
5308 }
5309
5310 private void notifyWindowsChanged() {
5311 WindowChangeListener[] windowChangeListeners;
5312 synchronized(mWindowMap) {
5313 if(mWindowChangeListeners.isEmpty()) {
5314 return;
5315 }
5316 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5317 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5318 }
5319 int N = windowChangeListeners.length;
5320 for(int i = 0; i < N; i++) {
5321 windowChangeListeners[i].windowsChanged();
5322 }
5323 }
5324
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005325 private void notifyFocusChanged() {
5326 WindowChangeListener[] windowChangeListeners;
5327 synchronized(mWindowMap) {
5328 if(mWindowChangeListeners.isEmpty()) {
5329 return;
5330 }
5331 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5332 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5333 }
5334 int N = windowChangeListeners.length;
5335 for(int i = 0; i < N; i++) {
5336 windowChangeListeners[i].focusChanged();
5337 }
5338 }
5339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005340 private WindowState findWindow(int hashCode) {
5341 if (hashCode == -1) {
5342 return getFocusedWindow();
5343 }
5344
5345 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005346 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 final int count = windows.size();
5348
5349 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005350 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351 if (System.identityHashCode(w) == hashCode) {
5352 return w;
5353 }
5354 }
5355 }
5356
5357 return null;
5358 }
5359
5360 /*
5361 * Instruct the Activity Manager to fetch the current configuration and broadcast
5362 * that to config-changed listeners if appropriate.
5363 */
5364 void sendNewConfiguration() {
5365 try {
5366 mActivityManager.updateConfiguration(null);
5367 } catch (RemoteException e) {
5368 }
5369 }
Romain Guy06882f82009-06-10 13:36:04 -07005370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005371 public Configuration computeNewConfiguration() {
5372 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005373 return computeNewConfigurationLocked();
5374 }
5375 }
Romain Guy06882f82009-06-10 13:36:04 -07005376
Dianne Hackbornc485a602009-03-24 22:39:49 -07005377 Configuration computeNewConfigurationLocked() {
5378 Configuration config = new Configuration();
5379 if (!computeNewConfigurationLocked(config)) {
5380 return null;
5381 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005382 return config;
5383 }
Romain Guy06882f82009-06-10 13:36:04 -07005384
Dianne Hackbornc485a602009-03-24 22:39:49 -07005385 boolean computeNewConfigurationLocked(Configuration config) {
5386 if (mDisplay == null) {
5387 return false;
5388 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005389
5390 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005391
5392 // Use the effective "visual" dimensions based on current rotation
5393 final boolean rotated = (mRotation == Surface.ROTATION_90
5394 || mRotation == Surface.ROTATION_270);
5395 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5396 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5397
Dianne Hackbornc485a602009-03-24 22:39:49 -07005398 int orientation = Configuration.ORIENTATION_SQUARE;
5399 if (dw < dh) {
5400 orientation = Configuration.ORIENTATION_PORTRAIT;
5401 } else if (dw > dh) {
5402 orientation = Configuration.ORIENTATION_LANDSCAPE;
5403 }
5404 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005405
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005406 DisplayMetrics dm = new DisplayMetrics();
5407 mDisplay.getMetrics(dm);
5408 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5409
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005410 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005411 // Note we only do this once because at this point we don't
5412 // expect the screen to change in this way at runtime, and want
5413 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005414 int longSize = dw;
5415 int shortSize = dh;
5416 if (longSize < shortSize) {
5417 int tmp = longSize;
5418 longSize = shortSize;
5419 shortSize = tmp;
5420 }
5421 longSize = (int)(longSize/dm.density);
5422 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005423
Dianne Hackborn723738c2009-06-25 19:48:04 -07005424 // These semi-magic numbers define our compatibility modes for
5425 // applications with different screens. Don't change unless you
5426 // make sure to test lots and lots of apps!
5427 if (longSize < 470) {
5428 // This is shorter than an HVGA normal density screen (which
5429 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005430 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5431 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005432 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005433 // What size is this screen screen?
5434 if (longSize >= 800 && shortSize >= 600) {
5435 // SVGA or larger screens at medium density are the point
5436 // at which we consider it to be an extra large screen.
5437 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005438 } else if (longSize >= 530 && shortSize >= 400) {
5439 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005440 // at which we consider it to be a large screen.
5441 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5442 } else {
5443 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005444
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005445 // If this screen is wider than normal HVGA, or taller
5446 // than FWVGA, then for old apps we want to run in size
5447 // compatibility mode.
5448 if (shortSize > 321 || longSize > 570) {
5449 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5450 }
5451 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005452
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005453 // Is this a long screen?
5454 if (((longSize*3)/5) >= (shortSize-1)) {
5455 // Anything wider than WVGA (5:3) is considering to be long.
5456 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5457 } else {
5458 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5459 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005460 }
5461 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005462 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005463
Dianne Hackbornc485a602009-03-24 22:39:49 -07005464 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5465 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5466 mPolicy.adjustConfigurationLw(config);
5467 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005468 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005469
5470 // -------------------------------------------------------------
5471 // Drag and drop
5472 // -------------------------------------------------------------
5473
5474 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5475 boolean localOnly, int width, int height, Surface outSurface) {
5476 if (DEBUG_DRAG) {
5477 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5478 + " local=" + localOnly + " win=" + window
5479 + " asbinder=" + window.asBinder());
5480 }
5481
5482 final int callerPid = Binder.getCallingPid();
5483 final long origId = Binder.clearCallingIdentity();
5484 IBinder token = null;
5485
5486 try {
5487 synchronized (mWindowMap) {
5488 try {
5489 // !!! TODO: fail if the given window does not currently have touch focus?
5490
5491 if (mDragState == null) {
5492 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5493 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5494 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005495 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005496 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005497 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005498 mDragState.mSurface = surface;
5499 mDragState.mLocalOnly = localOnly;
5500 token = mDragState.mToken = new Binder();
5501
5502 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005503 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5504 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005505 mH.sendMessageDelayed(msg, 5000);
5506 } else {
5507 Slog.w(TAG, "Drag already in progress");
5508 }
5509 } catch (Surface.OutOfResourcesException e) {
5510 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5511 if (mDragState != null) {
5512 mDragState.reset();
5513 mDragState = null;
5514 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005515 }
5516 }
5517 } finally {
5518 Binder.restoreCallingIdentity(origId);
5519 }
5520
5521 return token;
5522 }
5523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005524 // -------------------------------------------------------------
5525 // Input Events and Focus Management
5526 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005527
Jeff Brown349703e2010-06-22 01:27:15 -07005528 InputMonitor mInputMonitor = new InputMonitor();
5529
5530 /* Tracks the progress of input dispatch and ensures that input dispatch state
5531 * is kept in sync with changes in window focus, visibility, registration, and
5532 * other relevant Window Manager state transitions. */
5533 final class InputMonitor {
5534 // Current window with input focus for keys and other non-touch events. May be null.
5535 private WindowState mInputFocus;
5536
5537 // When true, prevents input dispatch from proceeding until set to false again.
5538 private boolean mInputDispatchFrozen;
5539
5540 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5541 private boolean mInputDispatchEnabled = true;
5542
5543 // Temporary list of windows information to provide to the input dispatcher.
5544 private InputWindowList mTempInputWindows = new InputWindowList();
5545
5546 // Temporary input application object to provide to the input dispatcher.
5547 private InputApplication mTempInputApplication = new InputApplication();
5548
5549 /* Notifies the window manager about a broken input channel.
5550 *
5551 * Called by the InputManager.
5552 */
5553 public void notifyInputChannelBroken(InputChannel inputChannel) {
5554 synchronized (mWindowMap) {
5555 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5556 if (windowState == null) {
5557 return; // irrelevant
5558 }
5559
5560 Slog.i(TAG, "WINDOW DIED " + windowState);
5561 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005562 }
5563 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005564
Jeff Brown519e0242010-09-15 15:18:56 -07005565 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005566 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005567 *
5568 * Called by the InputManager.
5569 */
Jeff Brown519e0242010-09-15 15:18:56 -07005570 public long notifyANR(Object token, InputChannel inputChannel) {
5571 AppWindowToken appWindowToken = null;
5572 if (inputChannel != null) {
5573 synchronized (mWindowMap) {
5574 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5575 if (windowState != null) {
5576 Slog.i(TAG, "Input event dispatching timed out sending to "
5577 + windowState.mAttrs.getTitle());
5578 appWindowToken = windowState.mAppToken;
5579 }
Jeff Brown349703e2010-06-22 01:27:15 -07005580 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005581 }
5582
Jeff Brown519e0242010-09-15 15:18:56 -07005583 if (appWindowToken == null && token != null) {
5584 appWindowToken = (AppWindowToken) token;
5585 Slog.i(TAG, "Input event dispatching timed out sending to application "
5586 + appWindowToken.stringName);
5587 }
Jeff Brown349703e2010-06-22 01:27:15 -07005588
Jeff Brown519e0242010-09-15 15:18:56 -07005589 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005590 try {
5591 // Notify the activity manager about the timeout and let it decide whether
5592 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005593 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005594 if (! abort) {
5595 // The activity manager declined to abort dispatching.
5596 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005597 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005598 }
Jeff Brown349703e2010-06-22 01:27:15 -07005599 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005600 }
5601 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005602 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005603 }
5604
Jeff Brown349703e2010-06-22 01:27:15 -07005605 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5606 synchronized (mWindowMap) {
5607 return getWindowStateForInputChannelLocked(inputChannel);
5608 }
5609 }
5610
5611 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5612 int windowCount = mWindows.size();
5613 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005614 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005615 if (windowState.mInputChannel == inputChannel) {
5616 return windowState;
5617 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005618 }
5619
Jeff Brown349703e2010-06-22 01:27:15 -07005620 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005621 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005622
Chris Tatea32dcf72010-10-14 12:13:50 -07005623 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005624 final InputWindow inputWindow = windowList.add();
5625 inputWindow.inputChannel = mDragState.mServerChannel;
5626 inputWindow.name = "drag";
5627 inputWindow.layoutParamsFlags = 0;
5628 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5629 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5630 inputWindow.visible = true;
5631 inputWindow.canReceiveKeys = false;
5632 inputWindow.hasFocus = true;
5633 inputWindow.hasWallpaper = false;
5634 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005635 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005636 inputWindow.ownerPid = Process.myPid();
5637 inputWindow.ownerUid = Process.myUid();
5638
5639 // The drag window covers the entire display
5640 inputWindow.frameLeft = 0;
5641 inputWindow.frameTop = 0;
5642 inputWindow.frameRight = mDisplay.getWidth();
5643 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005644
Christopher Tatea53146c2010-09-07 11:57:52 -07005645 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5646 inputWindow.visibleFrameTop = inputWindow.frameTop;
5647 inputWindow.visibleFrameRight = inputWindow.frameRight;
5648 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5649
5650 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5651 inputWindow.touchableAreaTop = inputWindow.frameTop;
5652 inputWindow.touchableAreaRight = inputWindow.frameRight;
5653 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5654 }
5655
Jeff Brown349703e2010-06-22 01:27:15 -07005656 /* Updates the cached window information provided to the input dispatcher. */
5657 public void updateInputWindowsLw() {
5658 // Populate the input window list with information about all of the windows that
5659 // could potentially receive input.
5660 // As an optimization, we could try to prune the list of windows but this turns
5661 // out to be difficult because only the native code knows for sure which window
5662 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005663 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005664
5665 // If there's a drag in flight, provide a pseudowindow to catch drag input
5666 final boolean inDrag = (mDragState != null);
5667 if (inDrag) {
5668 if (DEBUG_DRAG) {
5669 Log.d(TAG, "Inserting drag window");
5670 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005671 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005672 }
5673
Jeff Brown7fbdc842010-06-17 20:52:56 -07005674 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005675 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005676 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005677 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005678 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005679 continue;
5680 }
5681
Jeff Brown349703e2010-06-22 01:27:15 -07005682 final int flags = child.mAttrs.flags;
5683 final int type = child.mAttrs.type;
5684
5685 final boolean hasFocus = (child == mInputFocus);
5686 final boolean isVisible = child.isVisibleLw();
5687 final boolean hasWallpaper = (child == mWallpaperTarget)
5688 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005689
5690 // If there's a drag in progress and 'child' is a potential drop target,
5691 // make sure it's been told about the drag
5692 if (inDrag && isVisible) {
5693 mDragState.sendDragStartedIfNeededLw(child);
5694 }
5695
Jeff Brown349703e2010-06-22 01:27:15 -07005696 // Add a window to our list of input windows.
5697 final InputWindow inputWindow = mTempInputWindows.add();
5698 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005699 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005700 inputWindow.layoutParamsFlags = flags;
5701 inputWindow.layoutParamsType = type;
5702 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5703 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005704 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005705 inputWindow.hasFocus = hasFocus;
5706 inputWindow.hasWallpaper = hasWallpaper;
5707 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005708 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005709 inputWindow.ownerPid = child.mSession.mPid;
5710 inputWindow.ownerUid = child.mSession.mUid;
5711
5712 final Rect frame = child.mFrame;
5713 inputWindow.frameLeft = frame.left;
5714 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005715 inputWindow.frameRight = frame.right;
5716 inputWindow.frameBottom = frame.bottom;
5717
5718 final Rect visibleFrame = child.mVisibleFrame;
5719 inputWindow.visibleFrameLeft = visibleFrame.left;
5720 inputWindow.visibleFrameTop = visibleFrame.top;
5721 inputWindow.visibleFrameRight = visibleFrame.right;
5722 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005723
5724 switch (child.mTouchableInsets) {
5725 default:
5726 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5727 inputWindow.touchableAreaLeft = frame.left;
5728 inputWindow.touchableAreaTop = frame.top;
5729 inputWindow.touchableAreaRight = frame.right;
5730 inputWindow.touchableAreaBottom = frame.bottom;
5731 break;
5732
5733 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5734 Rect inset = child.mGivenContentInsets;
5735 inputWindow.touchableAreaLeft = frame.left + inset.left;
5736 inputWindow.touchableAreaTop = frame.top + inset.top;
5737 inputWindow.touchableAreaRight = frame.right - inset.right;
5738 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5739 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005740 }
Jeff Brown349703e2010-06-22 01:27:15 -07005741
5742 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5743 Rect inset = child.mGivenVisibleInsets;
5744 inputWindow.touchableAreaLeft = frame.left + inset.left;
5745 inputWindow.touchableAreaTop = frame.top + inset.top;
5746 inputWindow.touchableAreaRight = frame.right - inset.right;
5747 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005748 break;
5749 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005750 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005751 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005752
Jeff Brown349703e2010-06-22 01:27:15 -07005753 // Send windows to native code.
5754 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005755
Jeff Brown349703e2010-06-22 01:27:15 -07005756 // Clear the list in preparation for the next round.
5757 // Also avoids keeping InputChannel objects referenced unnecessarily.
5758 mTempInputWindows.clear();
5759 }
5760
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005761 /* Notifies that the lid switch changed state. */
5762 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5763 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5764 }
5765
Jeff Brown349703e2010-06-22 01:27:15 -07005766 /* Provides an opportunity for the window manager policy to intercept early key
5767 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005768 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5769 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5770 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5771 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005772 }
5773
5774 /* Provides an opportunity for the window manager policy to process a key before
5775 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005776 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005777 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005778 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005779 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005780 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005781 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005782 }
5783
5784 /* Called when the current input focus changes.
5785 * Layer assignment is assumed to be complete by the time this is called.
5786 */
5787 public void setInputFocusLw(WindowState newWindow) {
5788 if (DEBUG_INPUT) {
5789 Slog.d(TAG, "Input focus has changed to " + newWindow);
5790 }
5791
5792 if (newWindow != mInputFocus) {
5793 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005794 // Displaying a window implicitly causes dispatching to be unpaused.
5795 // This is to protect against bugs if someone pauses dispatching but
5796 // forgets to resume.
5797 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005798 }
Jeff Brown349703e2010-06-22 01:27:15 -07005799
5800 mInputFocus = newWindow;
5801 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005802 }
5803 }
5804
Jeff Brown349703e2010-06-22 01:27:15 -07005805 public void setFocusedAppLw(AppWindowToken newApp) {
5806 // Focused app has changed.
5807 if (newApp == null) {
5808 mInputManager.setFocusedApplication(null);
5809 } else {
5810 mTempInputApplication.name = newApp.toString();
5811 mTempInputApplication.dispatchingTimeoutNanos =
5812 newApp.inputDispatchingTimeoutNanos;
5813 mTempInputApplication.token = newApp;
5814
5815 mInputManager.setFocusedApplication(mTempInputApplication);
5816 }
5817 }
5818
Jeff Brown349703e2010-06-22 01:27:15 -07005819 public void pauseDispatchingLw(WindowToken window) {
5820 if (! window.paused) {
5821 if (DEBUG_INPUT) {
5822 Slog.v(TAG, "Pausing WindowToken " + window);
5823 }
5824
5825 window.paused = true;
5826 updateInputWindowsLw();
5827 }
5828 }
5829
5830 public void resumeDispatchingLw(WindowToken window) {
5831 if (window.paused) {
5832 if (DEBUG_INPUT) {
5833 Slog.v(TAG, "Resuming WindowToken " + window);
5834 }
5835
5836 window.paused = false;
5837 updateInputWindowsLw();
5838 }
5839 }
5840
5841 public void freezeInputDispatchingLw() {
5842 if (! mInputDispatchFrozen) {
5843 if (DEBUG_INPUT) {
5844 Slog.v(TAG, "Freezing input dispatching");
5845 }
5846
5847 mInputDispatchFrozen = true;
5848 updateInputDispatchModeLw();
5849 }
5850 }
5851
5852 public void thawInputDispatchingLw() {
5853 if (mInputDispatchFrozen) {
5854 if (DEBUG_INPUT) {
5855 Slog.v(TAG, "Thawing input dispatching");
5856 }
5857
5858 mInputDispatchFrozen = false;
5859 updateInputDispatchModeLw();
5860 }
5861 }
5862
5863 public void setEventDispatchingLw(boolean enabled) {
5864 if (mInputDispatchEnabled != enabled) {
5865 if (DEBUG_INPUT) {
5866 Slog.v(TAG, "Setting event dispatching to " + enabled);
5867 }
5868
5869 mInputDispatchEnabled = enabled;
5870 updateInputDispatchModeLw();
5871 }
5872 }
5873
5874 private void updateInputDispatchModeLw() {
5875 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5876 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005877 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005879 public void pauseKeyDispatching(IBinder _token) {
5880 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5881 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005882 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883 }
5884
5885 synchronized (mWindowMap) {
5886 WindowToken token = mTokenMap.get(_token);
5887 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005888 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005889 }
5890 }
5891 }
5892
5893 public void resumeKeyDispatching(IBinder _token) {
5894 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5895 "resumeKeyDispatching()")) {
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.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005903 }
5904 }
5905 }
5906
5907 public void setEventDispatching(boolean enabled) {
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) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005914 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 }
5916 }
Romain Guy06882f82009-06-10 13:36:04 -07005917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005918 /**
5919 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005920 * Even when sync is false, this method may block while waiting for current
5921 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005922 *
5923 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005924 * {@link SystemClock#uptimeMillis()} as the timebase.)
5925 * @param sync If true, wait for the event to be completed before returning to the caller.
5926 * @return Returns true if event was dispatched, false if it was dropped for any reason
5927 */
5928 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5929 long downTime = ev.getDownTime();
5930 long eventTime = ev.getEventTime();
5931
5932 int action = ev.getAction();
5933 int code = ev.getKeyCode();
5934 int repeatCount = ev.getRepeatCount();
5935 int metaState = ev.getMetaState();
5936 int deviceId = ev.getDeviceId();
5937 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005938 int source = ev.getSource();
5939
5940 if (source == InputDevice.SOURCE_UNKNOWN) {
5941 source = InputDevice.SOURCE_KEYBOARD;
5942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005943
5944 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5945 if (downTime == 0) downTime = eventTime;
5946
5947 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005948 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005949
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005950 final int pid = Binder.getCallingPid();
5951 final int uid = Binder.getCallingUid();
5952 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005953
Jeff Brownbbda99d2010-07-28 15:48:59 -07005954 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5955 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5956 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5957 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005958
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005959 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005960 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005961 }
5962
5963 /**
5964 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005965 * Even when sync is false, this method may block while waiting for current
5966 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005967 *
5968 * @param ev A motion event describing the pointer (touch) action. (As noted in
5969 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005970 * {@link SystemClock#uptimeMillis()} as the timebase.)
5971 * @param sync If true, wait for the event to be completed before returning to the caller.
5972 * @return Returns true if event was dispatched, false if it was dropped for any reason
5973 */
5974 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005975 final int pid = Binder.getCallingPid();
5976 final int uid = Binder.getCallingUid();
5977 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005978
Jeff Brownc5ed5912010-07-14 18:48:53 -07005979 MotionEvent newEvent = MotionEvent.obtain(ev);
5980 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5981 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5982 }
5983
Jeff Brownbbda99d2010-07-28 15:48:59 -07005984 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5985 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5986 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5987 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005988
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005989 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005990 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005991 }
Romain Guy06882f82009-06-10 13:36:04 -07005992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005993 /**
5994 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005995 * Even when sync is false, this method may block while waiting for current
5996 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005997 *
5998 * @param ev A motion event describing the trackball action. (As noted in
5999 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006000 * {@link SystemClock#uptimeMillis()} as the timebase.)
6001 * @param sync If true, wait for the event to be completed before returning to the caller.
6002 * @return Returns true if event was dispatched, false if it was dropped for any reason
6003 */
6004 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006005 final int pid = Binder.getCallingPid();
6006 final int uid = Binder.getCallingUid();
6007 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006008
Jeff Brownc5ed5912010-07-14 18:48:53 -07006009 MotionEvent newEvent = MotionEvent.obtain(ev);
6010 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6011 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6012 }
6013
Jeff Brownbbda99d2010-07-28 15:48:59 -07006014 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6015 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6016 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6017 INJECTION_TIMEOUT_MILLIS);
6018
6019 Binder.restoreCallingIdentity(ident);
6020 return reportInjectionResult(result);
6021 }
6022
6023 /**
6024 * Inject an input event into the UI without waiting for dispatch to commence.
6025 * This variant is useful for fire-and-forget input event injection. It does not
6026 * block any longer than it takes to enqueue the input event.
6027 *
6028 * @param ev An input event. (Be sure to set the input source correctly.)
6029 * @return Returns true if event was dispatched, false if it was dropped for any reason
6030 */
6031 public boolean injectInputEventNoWait(InputEvent ev) {
6032 final int pid = Binder.getCallingPid();
6033 final int uid = Binder.getCallingUid();
6034 final long ident = Binder.clearCallingIdentity();
6035
6036 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6037 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6038 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006039
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006040 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006041 return reportInjectionResult(result);
6042 }
6043
6044 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006045 switch (result) {
6046 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6047 Slog.w(TAG, "Input event injection permission denied.");
6048 throw new SecurityException(
6049 "Injecting to another application requires INJECT_EVENTS permission");
6050 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006051 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006052 return true;
6053 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6054 Slog.w(TAG, "Input event injection timed out.");
6055 return false;
6056 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6057 default:
6058 Slog.w(TAG, "Input event injection failed.");
6059 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006061 }
Romain Guy06882f82009-06-10 13:36:04 -07006062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006063 private WindowState getFocusedWindow() {
6064 synchronized (mWindowMap) {
6065 return getFocusedWindowLocked();
6066 }
6067 }
6068
6069 private WindowState getFocusedWindowLocked() {
6070 return mCurrentFocus;
6071 }
Romain Guy06882f82009-06-10 13:36:04 -07006072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006073 public boolean detectSafeMode() {
6074 mSafeMode = mPolicy.detectSafeMode();
6075 return mSafeMode;
6076 }
Romain Guy06882f82009-06-10 13:36:04 -07006077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006079 synchronized(mWindowMap) {
6080 if (mDisplay != null) {
6081 throw new IllegalStateException("Display already initialized");
6082 }
6083 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6084 mDisplay = wm.getDefaultDisplay();
6085 mInitialDisplayWidth = mDisplay.getWidth();
6086 mInitialDisplayHeight = mDisplay.getHeight();
6087 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6088 }
6089
6090 try {
6091 mActivityManager.updateConfiguration(null);
6092 } catch (RemoteException e) {
6093 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006094
6095 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006096 }
6097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098 // -------------------------------------------------------------
6099 // Client Session State
6100 // -------------------------------------------------------------
6101
6102 private final class Session extends IWindowSession.Stub
6103 implements IBinder.DeathRecipient {
6104 final IInputMethodClient mClient;
6105 final IInputContext mInputContext;
6106 final int mUid;
6107 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006108 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006109 SurfaceSession mSurfaceSession;
6110 int mNumWindow = 0;
6111 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113 public Session(IInputMethodClient client, IInputContext inputContext) {
6114 mClient = client;
6115 mInputContext = inputContext;
6116 mUid = Binder.getCallingUid();
6117 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006118 StringBuilder sb = new StringBuilder();
6119 sb.append("Session{");
6120 sb.append(Integer.toHexString(System.identityHashCode(this)));
6121 sb.append(" uid ");
6122 sb.append(mUid);
6123 sb.append("}");
6124 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006126 synchronized (mWindowMap) {
6127 if (mInputMethodManager == null && mHaveInputMethods) {
6128 IBinder b = ServiceManager.getService(
6129 Context.INPUT_METHOD_SERVICE);
6130 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6131 }
6132 }
6133 long ident = Binder.clearCallingIdentity();
6134 try {
6135 // Note: it is safe to call in to the input method manager
6136 // here because we are not holding our lock.
6137 if (mInputMethodManager != null) {
6138 mInputMethodManager.addClient(client, inputContext,
6139 mUid, mPid);
6140 } else {
6141 client.setUsingInputMethod(false);
6142 }
6143 client.asBinder().linkToDeath(this, 0);
6144 } catch (RemoteException e) {
6145 // The caller has died, so we can just forget about this.
6146 try {
6147 if (mInputMethodManager != null) {
6148 mInputMethodManager.removeClient(client);
6149 }
6150 } catch (RemoteException ee) {
6151 }
6152 } finally {
6153 Binder.restoreCallingIdentity(ident);
6154 }
6155 }
Romain Guy06882f82009-06-10 13:36:04 -07006156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006157 @Override
6158 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6159 throws RemoteException {
6160 try {
6161 return super.onTransact(code, data, reply, flags);
6162 } catch (RuntimeException e) {
6163 // Log all 'real' exceptions thrown to the caller
6164 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006165 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 }
6167 throw e;
6168 }
6169 }
6170
6171 public void binderDied() {
6172 // Note: it is safe to call in to the input method manager
6173 // here because we are not holding our lock.
6174 try {
6175 if (mInputMethodManager != null) {
6176 mInputMethodManager.removeClient(mClient);
6177 }
6178 } catch (RemoteException e) {
6179 }
6180 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006181 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006182 mClientDead = true;
6183 killSessionLocked();
6184 }
6185 }
6186
6187 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006188 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6189 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6190 outInputChannel);
6191 }
6192
6193 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006194 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006195 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006196 }
Romain Guy06882f82009-06-10 13:36:04 -07006197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006198 public void remove(IWindow window) {
6199 removeWindow(this, window);
6200 }
Romain Guy06882f82009-06-10 13:36:04 -07006201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006202 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6203 int requestedWidth, int requestedHeight, int viewFlags,
6204 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006205 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006206 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6207 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006208 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006209 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006210 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6211 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006212 }
Romain Guy06882f82009-06-10 13:36:04 -07006213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006214 public void setTransparentRegion(IWindow window, Region region) {
6215 setTransparentRegionWindow(this, window, region);
6216 }
Romain Guy06882f82009-06-10 13:36:04 -07006217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 public void setInsets(IWindow window, int touchableInsets,
6219 Rect contentInsets, Rect visibleInsets) {
6220 setInsetsWindow(this, window, touchableInsets, contentInsets,
6221 visibleInsets);
6222 }
Romain Guy06882f82009-06-10 13:36:04 -07006223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006224 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6225 getWindowDisplayFrame(this, window, outDisplayFrame);
6226 }
Romain Guy06882f82009-06-10 13:36:04 -07006227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006229 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006230 TAG, "IWindow finishDrawing called for " + window);
6231 finishDrawingWindow(this, window);
6232 }
6233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006234 public void setInTouchMode(boolean mode) {
6235 synchronized(mWindowMap) {
6236 mInTouchMode = mode;
6237 }
6238 }
6239
6240 public boolean getInTouchMode() {
6241 synchronized(mWindowMap) {
6242 return mInTouchMode;
6243 }
6244 }
6245
6246 public boolean performHapticFeedback(IWindow window, int effectId,
6247 boolean always) {
6248 synchronized(mWindowMap) {
6249 long ident = Binder.clearCallingIdentity();
6250 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006251 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006252 windowForClientLocked(this, window, true),
6253 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254 } finally {
6255 Binder.restoreCallingIdentity(ident);
6256 }
6257 }
6258 }
Romain Guy06882f82009-06-10 13:36:04 -07006259
Christopher Tatea53146c2010-09-07 11:57:52 -07006260 /* Drag/drop */
6261 public IBinder prepareDrag(IWindow window, boolean localOnly,
6262 int width, int height, Surface outSurface) {
6263 return prepareDragSurface(window, mSurfaceSession, localOnly,
6264 width, height, outSurface);
6265 }
6266
6267 public boolean performDrag(IWindow window, IBinder dragToken,
6268 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6269 ClipData data) {
6270 if (DEBUG_DRAG) {
6271 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6272 }
6273
6274 synchronized (mWindowMap) {
6275 if (mDragState == null) {
6276 Slog.w(TAG, "No drag prepared");
6277 throw new IllegalStateException("performDrag() without prepareDrag()");
6278 }
6279
6280 if (dragToken != mDragState.mToken) {
6281 Slog.w(TAG, "Performing mismatched drag");
6282 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6283 }
6284
6285 WindowState callingWin = windowForClientLocked(null, window, false);
6286 if (callingWin == null) {
6287 Slog.w(TAG, "Bad requesting window " + window);
6288 return false; // !!! TODO: throw here?
6289 }
6290
6291 // !!! TODO: if input is not still focused on the initiating window, fail
6292 // the drag initiation (e.g. an alarm window popped up just as the application
6293 // called performDrag()
6294
6295 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6296
Christopher Tate2c095f32010-10-04 14:13:40 -07006297 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6298 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006299
Chris Tateb478f462010-10-15 16:02:26 -07006300 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6301 // the actual drag event dispatch stuff in the dragstate
6302
Christopher Tatea53146c2010-09-07 11:57:52 -07006303 mDragState.register();
6304 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006305 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6306 mDragState.mServerChannel)) {
6307 Slog.e(TAG, "Unable to transfer touch focus");
6308 mDragState.unregister();
6309 mDragState = null;
6310 mInputMonitor.updateInputWindowsLw();
6311 return false;
6312 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006313
6314 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006315 mDragState.mCurrentX = touchX;
6316 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006317 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006318
6319 // remember the thumb offsets for later
6320 mDragState.mThumbOffsetX = thumbCenterX;
6321 mDragState.mThumbOffsetY = thumbCenterY;
6322
6323 // Make the surface visible at the proper location
6324 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006325 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006326 try {
6327 surface.setPosition((int)(touchX - thumbCenterX),
6328 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006329 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006330 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006331 surface.show();
6332 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006333 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006334 }
6335 }
6336
6337 return true; // success!
6338 }
6339
Chris Tated4533f142010-10-19 15:15:08 -07006340 public void reportDropResult(IWindow window, boolean consumed) {
6341 IBinder token = window.asBinder();
6342 if (DEBUG_DRAG) {
6343 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6344 }
6345
6346 synchronized (mWindowMap) {
6347 if (mDragState.mToken != token) {
6348 Slog.w(TAG, "Invalid drop-result claim by " + window);
6349 throw new IllegalStateException("reportDropResult() by non-recipient");
6350 }
6351
6352 // The right window has responded, even if it's no longer around,
6353 // so be sure to halt the timeout even if the later WindowState
6354 // lookup fails.
6355 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6356
6357 WindowState callingWin = windowForClientLocked(null, window, false);
6358 if (callingWin == null) {
6359 Slog.w(TAG, "Bad result-reporting window " + window);
6360 return; // !!! TODO: throw here?
6361 }
6362
6363 mDragState.mDragResult = consumed;
6364 mDragState.endDragLw();
6365 }
6366 }
6367
Christopher Tatea53146c2010-09-07 11:57:52 -07006368 public void dragRecipientEntered(IWindow window) {
6369 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006370 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006371 }
6372 }
6373
6374 public void dragRecipientExited(IWindow window) {
6375 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006376 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006377 }
6378 }
6379
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006380 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006381 synchronized(mWindowMap) {
6382 long ident = Binder.clearCallingIdentity();
6383 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006384 setWindowWallpaperPositionLocked(
6385 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006386 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006387 } finally {
6388 Binder.restoreCallingIdentity(ident);
6389 }
6390 }
6391 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006392
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006393 public void wallpaperOffsetsComplete(IBinder window) {
6394 WindowManagerService.this.wallpaperOffsetsComplete(window);
6395 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006396
Dianne Hackborn75804932009-10-20 20:15:20 -07006397 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6398 int z, Bundle extras, boolean sync) {
6399 synchronized(mWindowMap) {
6400 long ident = Binder.clearCallingIdentity();
6401 try {
6402 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006403 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006404 action, x, y, z, extras, sync);
6405 } finally {
6406 Binder.restoreCallingIdentity(ident);
6407 }
6408 }
6409 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006410
Dianne Hackborn75804932009-10-20 20:15:20 -07006411 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6412 WindowManagerService.this.wallpaperCommandComplete(window, result);
6413 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 void windowAddedLocked() {
6416 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006417 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006418 TAG, "First window added to " + this + ", creating SurfaceSession");
6419 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006420 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006421 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006422 mSessions.add(this);
6423 }
6424 mNumWindow++;
6425 }
6426
6427 void windowRemovedLocked() {
6428 mNumWindow--;
6429 killSessionLocked();
6430 }
Romain Guy06882f82009-06-10 13:36:04 -07006431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 void killSessionLocked() {
6433 if (mNumWindow <= 0 && mClientDead) {
6434 mSessions.remove(this);
6435 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006436 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006437 TAG, "Last window removed from " + this
6438 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006439 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006440 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 try {
6442 mSurfaceSession.kill();
6443 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006444 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006445 + mSurfaceSession + " in session " + this
6446 + ": " + e.toString());
6447 }
6448 mSurfaceSession = null;
6449 }
6450 }
6451 }
Romain Guy06882f82009-06-10 13:36:04 -07006452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006454 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6455 pw.print(" mClientDead="); pw.print(mClientDead);
6456 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006457 }
6458
6459 @Override
6460 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006461 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 }
6463 }
6464
6465 // -------------------------------------------------------------
6466 // Client Window State
6467 // -------------------------------------------------------------
6468
6469 private final class WindowState implements WindowManagerPolicy.WindowState {
6470 final Session mSession;
6471 final IWindow mClient;
6472 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006473 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 AppWindowToken mAppToken;
6475 AppWindowToken mTargetAppToken;
6476 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6477 final DeathRecipient mDeathRecipient;
6478 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006479 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006480 final int mBaseLayer;
6481 final int mSubLayer;
6482 final boolean mLayoutAttached;
6483 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006484 final boolean mIsWallpaper;
6485 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 int mViewVisibility;
6487 boolean mPolicyVisibility = true;
6488 boolean mPolicyVisibilityAfterAnim = true;
6489 boolean mAppFreezing;
6490 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006491 boolean mReportDestroySurface;
6492 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 boolean mAttachedHidden; // is our parent window hidden?
6494 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006495 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 int mRequestedWidth;
6497 int mRequestedHeight;
6498 int mLastRequestedWidth;
6499 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006500 int mLayer;
6501 int mAnimLayer;
6502 int mLastLayer;
6503 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006504 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006505 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006506
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006507 int mLayoutSeq = -1;
6508
6509 Configuration mConfiguration = null;
6510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 // Actual frame shown on-screen (may be modified by animation)
6512 final Rect mShownFrame = new Rect();
6513 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006516 * Set when we have changed the size of the surface, to know that
6517 * we must tell them application to resize (and thus redraw itself).
6518 */
6519 boolean mSurfaceResized;
6520
6521 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006522 * Insets that determine the actually visible area
6523 */
6524 final Rect mVisibleInsets = new Rect();
6525 final Rect mLastVisibleInsets = new Rect();
6526 boolean mVisibleInsetsChanged;
6527
6528 /**
6529 * Insets that are covered by system windows
6530 */
6531 final Rect mContentInsets = new Rect();
6532 final Rect mLastContentInsets = new Rect();
6533 boolean mContentInsetsChanged;
6534
6535 /**
6536 * Set to true if we are waiting for this window to receive its
6537 * given internal insets before laying out other windows based on it.
6538 */
6539 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006541 /**
6542 * These are the content insets that were given during layout for
6543 * this window, to be applied to windows behind it.
6544 */
6545 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 /**
6548 * These are the visible insets that were given during layout for
6549 * this window, to be applied to windows behind it.
6550 */
6551 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 /**
6554 * Flag indicating whether the touchable region should be adjusted by
6555 * the visible insets; if false the area outside the visible insets is
6556 * NOT touchable, so we must use those to adjust the frame during hit
6557 * tests.
6558 */
6559 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 // Current transformation being applied.
6562 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6563 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6564 float mHScale=1, mVScale=1;
6565 float mLastHScale=1, mLastVScale=1;
6566 final Matrix mTmpMatrix = new Matrix();
6567
6568 // "Real" frame that the application sees.
6569 final Rect mFrame = new Rect();
6570 final Rect mLastFrame = new Rect();
6571
6572 final Rect mContainingFrame = new Rect();
6573 final Rect mDisplayFrame = new Rect();
6574 final Rect mContentFrame = new Rect();
6575 final Rect mVisibleFrame = new Rect();
6576
6577 float mShownAlpha = 1;
6578 float mAlpha = 1;
6579 float mLastAlpha = 1;
6580
6581 // Set to true if, when the window gets displayed, it should perform
6582 // an enter animation.
6583 boolean mEnterAnimationPending;
6584
6585 // Currently running animation.
6586 boolean mAnimating;
6587 boolean mLocalAnimating;
6588 Animation mAnimation;
6589 boolean mAnimationIsEntrance;
6590 boolean mHasTransformation;
6591 boolean mHasLocalTransformation;
6592 final Transformation mTransformation = new Transformation();
6593
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006594 // If a window showing a wallpaper: the requested offset for the
6595 // wallpaper; if a wallpaper window: the currently applied offset.
6596 float mWallpaperX = -1;
6597 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006598
6599 // If a window showing a wallpaper: what fraction of the offset
6600 // range corresponds to a full virtual screen.
6601 float mWallpaperXStep = -1;
6602 float mWallpaperYStep = -1;
6603
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006604 // Wallpaper windows: pixels offset based on above variables.
6605 int mXOffset;
6606 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006608 // This is set after IWindowSession.relayout() has been called at
6609 // least once for the window. It allows us to detect the situation
6610 // where we don't yet have a surface, but should have one soon, so
6611 // we can give the window focus before waiting for the relayout.
6612 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006614 // This is set after the Surface has been created but before the
6615 // window has been drawn. During this time the surface is hidden.
6616 boolean mDrawPending;
6617
6618 // This is set after the window has finished drawing for the first
6619 // time but before its surface is shown. The surface will be
6620 // displayed when the next layout is run.
6621 boolean mCommitDrawPending;
6622
6623 // This is set during the time after the window's drawing has been
6624 // committed, and before its surface is actually shown. It is used
6625 // to delay showing the surface until all windows in a token are ready
6626 // to be shown.
6627 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 // Set when the window has been shown in the screen the first time.
6630 boolean mHasDrawn;
6631
6632 // Currently running an exit animation?
6633 boolean mExiting;
6634
6635 // Currently on the mDestroySurface list?
6636 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006638 // Completely remove from window manager after exit animation?
6639 boolean mRemoveOnExit;
6640
6641 // Set when the orientation is changing and this window has not yet
6642 // been updated for the new orientation.
6643 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006645 // Is this window now (or just being) removed?
6646 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006647
Dianne Hackborn16064f92010-03-25 00:47:24 -07006648 // For debugging, this is the last information given to the surface flinger.
6649 boolean mSurfaceShown;
6650 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6651 int mSurfaceLayer;
6652 float mSurfaceAlpha;
6653
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006654 // Input channel
6655 InputChannel mInputChannel;
6656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006657 WindowState(Session s, IWindow c, WindowToken token,
6658 WindowState attachedWindow, WindowManager.LayoutParams a,
6659 int viewVisibility) {
6660 mSession = s;
6661 mClient = c;
6662 mToken = token;
6663 mAttrs.copyFrom(a);
6664 mViewVisibility = viewVisibility;
6665 DeathRecipient deathRecipient = new DeathRecipient();
6666 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006667 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006668 TAG, "Window " + this + " client=" + c.asBinder()
6669 + " token=" + token + " (" + mAttrs.token + ")");
6670 try {
6671 c.asBinder().linkToDeath(deathRecipient, 0);
6672 } catch (RemoteException e) {
6673 mDeathRecipient = null;
6674 mAttachedWindow = null;
6675 mLayoutAttached = false;
6676 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006677 mIsWallpaper = false;
6678 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006679 mBaseLayer = 0;
6680 mSubLayer = 0;
6681 return;
6682 }
6683 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006685 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6686 mAttrs.type <= LAST_SUB_WINDOW)) {
6687 // The multiplier here is to reserve space for multiple
6688 // windows in the same type layer.
6689 mBaseLayer = mPolicy.windowTypeToLayerLw(
6690 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6691 + TYPE_LAYER_OFFSET;
6692 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6693 mAttachedWindow = attachedWindow;
6694 mAttachedWindow.mChildWindows.add(this);
6695 mLayoutAttached = mAttrs.type !=
6696 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6697 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6698 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006699 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6700 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006701 } else {
6702 // The multiplier here is to reserve space for multiple
6703 // windows in the same type layer.
6704 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6705 * TYPE_LAYER_MULTIPLIER
6706 + TYPE_LAYER_OFFSET;
6707 mSubLayer = 0;
6708 mAttachedWindow = null;
6709 mLayoutAttached = false;
6710 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6711 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006712 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6713 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006714 }
6715
6716 WindowState appWin = this;
6717 while (appWin.mAttachedWindow != null) {
6718 appWin = mAttachedWindow;
6719 }
6720 WindowToken appToken = appWin.mToken;
6721 while (appToken.appWindowToken == null) {
6722 WindowToken parent = mTokenMap.get(appToken.token);
6723 if (parent == null || appToken == parent) {
6724 break;
6725 }
6726 appToken = parent;
6727 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006728 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006729 mAppToken = appToken.appWindowToken;
6730
6731 mSurface = null;
6732 mRequestedWidth = 0;
6733 mRequestedHeight = 0;
6734 mLastRequestedWidth = 0;
6735 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006736 mXOffset = 0;
6737 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 mLayer = 0;
6739 mAnimLayer = 0;
6740 mLastLayer = 0;
6741 }
6742
6743 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006744 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 TAG, "Attaching " + this + " token=" + mToken
6746 + ", list=" + mToken.windows);
6747 mSession.windowAddedLocked();
6748 }
6749
6750 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6751 mHaveFrame = true;
6752
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006753 final Rect container = mContainingFrame;
6754 container.set(pf);
6755
6756 final Rect display = mDisplayFrame;
6757 display.set(df);
6758
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006759 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006760 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006761 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6762 display.intersect(mCompatibleScreenFrame);
6763 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006764 }
6765
6766 final int pw = container.right - container.left;
6767 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006768
6769 int w,h;
6770 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6771 w = mAttrs.width < 0 ? pw : mAttrs.width;
6772 h = mAttrs.height< 0 ? ph : mAttrs.height;
6773 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006774 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6775 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 }
Romain Guy06882f82009-06-10 13:36:04 -07006777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006778 final Rect content = mContentFrame;
6779 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006781 final Rect visible = mVisibleFrame;
6782 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006784 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006785 final int fw = frame.width();
6786 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006788 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6789 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6790
6791 Gravity.apply(mAttrs.gravity, w, h, container,
6792 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6793 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6794
6795 //System.out.println("Out: " + mFrame);
6796
6797 // Now make sure the window fits in the overall display.
6798 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 // Make sure the content and visible frames are inside of the
6801 // final window frame.
6802 if (content.left < frame.left) content.left = frame.left;
6803 if (content.top < frame.top) content.top = frame.top;
6804 if (content.right > frame.right) content.right = frame.right;
6805 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6806 if (visible.left < frame.left) visible.left = frame.left;
6807 if (visible.top < frame.top) visible.top = frame.top;
6808 if (visible.right > frame.right) visible.right = frame.right;
6809 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006811 final Rect contentInsets = mContentInsets;
6812 contentInsets.left = content.left-frame.left;
6813 contentInsets.top = content.top-frame.top;
6814 contentInsets.right = frame.right-content.right;
6815 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006817 final Rect visibleInsets = mVisibleInsets;
6818 visibleInsets.left = visible.left-frame.left;
6819 visibleInsets.top = visible.top-frame.top;
6820 visibleInsets.right = frame.right-visible.right;
6821 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006822
Dianne Hackborn284ac932009-08-28 10:34:25 -07006823 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6824 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006825 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006826 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006828 if (localLOGV) {
6829 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6830 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006831 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006832 + mRequestedWidth + ", mRequestedheight="
6833 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6834 + "): frame=" + mFrame.toShortString()
6835 + " ci=" + contentInsets.toShortString()
6836 + " vi=" + visibleInsets.toShortString());
6837 //}
6838 }
6839 }
Romain Guy06882f82009-06-10 13:36:04 -07006840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 public Rect getFrameLw() {
6842 return mFrame;
6843 }
6844
6845 public Rect getShownFrameLw() {
6846 return mShownFrame;
6847 }
6848
6849 public Rect getDisplayFrameLw() {
6850 return mDisplayFrame;
6851 }
6852
6853 public Rect getContentFrameLw() {
6854 return mContentFrame;
6855 }
6856
6857 public Rect getVisibleFrameLw() {
6858 return mVisibleFrame;
6859 }
6860
6861 public boolean getGivenInsetsPendingLw() {
6862 return mGivenInsetsPending;
6863 }
6864
6865 public Rect getGivenContentInsetsLw() {
6866 return mGivenContentInsets;
6867 }
Romain Guy06882f82009-06-10 13:36:04 -07006868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 public Rect getGivenVisibleInsetsLw() {
6870 return mGivenVisibleInsets;
6871 }
Romain Guy06882f82009-06-10 13:36:04 -07006872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006873 public WindowManager.LayoutParams getAttrs() {
6874 return mAttrs;
6875 }
6876
6877 public int getSurfaceLayer() {
6878 return mLayer;
6879 }
Romain Guy06882f82009-06-10 13:36:04 -07006880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006881 public IApplicationToken getAppToken() {
6882 return mAppToken != null ? mAppToken.appToken : null;
6883 }
Jeff Brown349703e2010-06-22 01:27:15 -07006884
6885 public long getInputDispatchingTimeoutNanos() {
6886 return mAppToken != null
6887 ? mAppToken.inputDispatchingTimeoutNanos
6888 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6889 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006890
6891 public boolean hasAppShownWindows() {
6892 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6893 }
6894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006895 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006896 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 TAG, "Setting animation in " + this + ": " + anim);
6898 mAnimating = false;
6899 mLocalAnimating = false;
6900 mAnimation = anim;
6901 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6902 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6903 }
6904
6905 public void clearAnimation() {
6906 if (mAnimation != null) {
6907 mAnimating = true;
6908 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07006909 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006910 mAnimation = null;
6911 }
6912 }
Romain Guy06882f82009-06-10 13:36:04 -07006913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 Surface createSurfaceLocked() {
6915 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006916 mReportDestroySurface = false;
6917 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006918 mDrawPending = true;
6919 mCommitDrawPending = false;
6920 mReadyToShow = false;
6921 if (mAppToken != null) {
6922 mAppToken.allDrawn = false;
6923 }
6924
6925 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006926 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006927 flags |= Surface.PUSH_BUFFERS;
6928 }
6929
6930 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6931 flags |= Surface.SECURE;
6932 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006933 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006934 TAG, "Creating surface in session "
6935 + mSession.mSurfaceSession + " window " + this
6936 + " w=" + mFrame.width()
6937 + " h=" + mFrame.height() + " format="
6938 + mAttrs.format + " flags=" + flags);
6939
6940 int w = mFrame.width();
6941 int h = mFrame.height();
6942 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6943 // for a scaled surface, we always want the requested
6944 // size.
6945 w = mRequestedWidth;
6946 h = mRequestedHeight;
6947 }
6948
Romain Guy9825ec62009-10-01 00:58:09 -07006949 // Something is wrong and SurfaceFlinger will not like this,
6950 // try to revert to sane values
6951 if (w <= 0) w = 1;
6952 if (h <= 0) h = 1;
6953
Dianne Hackborn16064f92010-03-25 00:47:24 -07006954 mSurfaceShown = false;
6955 mSurfaceLayer = 0;
6956 mSurfaceAlpha = 1;
6957 mSurfaceX = 0;
6958 mSurfaceY = 0;
6959 mSurfaceW = w;
6960 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006961 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006962 final boolean isHwAccelerated = (mAttrs.flags &
6963 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6964 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6965 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6966 flags |= Surface.OPAQUE;
6967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006969 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006970 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006971 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006972 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006973 + mSurface + " IN SESSION "
6974 + mSession.mSurfaceSession
6975 + ": pid=" + mSession.mPid + " format="
6976 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006977 + Integer.toHexString(flags)
6978 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006979 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006980 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 reclaimSomeSurfaceMemoryLocked(this, "create");
6982 return null;
6983 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006984 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006985 return null;
6986 }
Romain Guy06882f82009-06-10 13:36:04 -07006987
Joe Onorato8a9b2202010-02-26 18:56:32 -08006988 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006989 TAG, "Got surface: " + mSurface
6990 + ", set left=" + mFrame.left + " top=" + mFrame.top
6991 + ", animLayer=" + mAnimLayer);
6992 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006993 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006994 if (SHOW_TRANSACTIONS) logSurface(this,
6995 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6996 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6997 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006998 }
6999 Surface.openTransaction();
7000 try {
7001 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007002 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007003 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007004 mSurface.setPosition(mSurfaceX, mSurfaceY);
7005 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007006 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007007 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 mSurface.hide();
7009 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007010 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007011 mSurface.setFlags(Surface.SURFACE_DITHER,
7012 Surface.SURFACE_DITHER);
7013 }
7014 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007015 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007016 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7017 }
7018 mLastHidden = true;
7019 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007020 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007021 Surface.closeTransaction();
7022 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007023 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007024 TAG, "Created surface " + this);
7025 }
7026 return mSurface;
7027 }
Romain Guy06882f82009-06-10 13:36:04 -07007028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 if (mAppToken != null && this == mAppToken.startingWindow) {
7031 mAppToken.startingDisplayed = false;
7032 }
Romain Guy06882f82009-06-10 13:36:04 -07007033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007035 mDrawPending = false;
7036 mCommitDrawPending = false;
7037 mReadyToShow = false;
7038
7039 int i = mChildWindows.size();
7040 while (i > 0) {
7041 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007042 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007043 c.mAttachedHidden = true;
7044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007045
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007046 if (mReportDestroySurface) {
7047 mReportDestroySurface = false;
7048 mSurfacePendingDestroy = true;
7049 try {
7050 mClient.dispatchGetNewSurface();
7051 // We'll really destroy on the next time around.
7052 return;
7053 } catch (RemoteException e) {
7054 }
7055 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007058 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007059 RuntimeException e = null;
7060 if (!HIDE_STACK_CRAWLS) {
7061 e = new RuntimeException();
7062 e.fillInStackTrace();
7063 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007064 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007065 + mSurface + ", session " + mSession, e);
7066 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007068 RuntimeException e = null;
7069 if (!HIDE_STACK_CRAWLS) {
7070 e = new RuntimeException();
7071 e.fillInStackTrace();
7072 }
7073 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007075 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007076 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007077 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007078 + " surface " + mSurface + " session " + mSession
7079 + ": " + e.toString());
7080 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007081
Dianne Hackborn16064f92010-03-25 00:47:24 -07007082 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 }
7085 }
7086
7087 boolean finishDrawingLocked() {
7088 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007089 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 TAG, "finishDrawingLocked: " + mSurface);
7091 mCommitDrawPending = true;
7092 mDrawPending = false;
7093 return true;
7094 }
7095 return false;
7096 }
7097
7098 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007099 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007100 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007101 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007102 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 }
7104 mCommitDrawPending = false;
7105 mReadyToShow = true;
7106 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7107 final AppWindowToken atoken = mAppToken;
7108 if (atoken == null || atoken.allDrawn || starting) {
7109 performShowLocked();
7110 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007111 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007112 }
7113
7114 // This must be called while inside a transaction.
7115 boolean performShowLocked() {
7116 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007117 RuntimeException e = null;
7118 if (!HIDE_STACK_CRAWLS) {
7119 e = new RuntimeException();
7120 e.fillInStackTrace();
7121 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007122 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007123 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7124 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7125 }
7126 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007127 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7128 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007129 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 + " during animation: policyVis=" + mPolicyVisibility
7131 + " attHidden=" + mAttachedHidden
7132 + " tok.hiddenRequested="
7133 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007134 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007135 + (mAppToken != null ? mAppToken.hidden : false)
7136 + " animating=" + mAnimating
7137 + " tok animating="
7138 + (mAppToken != null ? mAppToken.animating : false));
7139 if (!showSurfaceRobustlyLocked(this)) {
7140 return false;
7141 }
7142 mLastAlpha = -1;
7143 mHasDrawn = true;
7144 mLastHidden = false;
7145 mReadyToShow = false;
7146 enableScreenIfNeededLocked();
7147
7148 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 int i = mChildWindows.size();
7151 while (i > 0) {
7152 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007153 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007154 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007155 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007156 if (c.mSurface != null) {
7157 c.performShowLocked();
7158 // It hadn't been shown, which means layout not
7159 // performed on it, so now we want to make sure to
7160 // do a layout. If called from within the transaction
7161 // loop, this will cause it to restart with a new
7162 // layout.
7163 mLayoutNeeded = true;
7164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 }
7166 }
Romain Guy06882f82009-06-10 13:36:04 -07007167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007168 if (mAttrs.type != TYPE_APPLICATION_STARTING
7169 && mAppToken != null) {
7170 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007171
Dianne Hackborn248b1882009-09-16 16:46:44 -07007172 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007173 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007174 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007175 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007176 // If this initial window is animating, stop it -- we
7177 // will do an animation to reveal it from behind the
7178 // starting window, so there is no need for it to also
7179 // be doing its own stuff.
7180 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007181 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007182 mAnimation = null;
7183 // Make sure we clean up the animation.
7184 mAnimating = true;
7185 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007186 mFinishedStarting.add(mAppToken);
7187 mH.sendEmptyMessage(H.FINISHED_STARTING);
7188 }
7189 mAppToken.updateReportedVisibilityLocked();
7190 }
7191 }
7192 return true;
7193 }
Romain Guy06882f82009-06-10 13:36:04 -07007194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 // This must be called while inside a transaction. Returns true if
7196 // there is more animation to run.
7197 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007198 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007201 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7202 mHasTransformation = true;
7203 mHasLocalTransformation = true;
7204 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007205 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007206 TAG, "Starting animation in " + this +
7207 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7208 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7209 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7210 mAnimation.setStartTime(currentTime);
7211 mLocalAnimating = true;
7212 mAnimating = true;
7213 }
7214 mTransformation.clear();
7215 final boolean more = mAnimation.getTransformation(
7216 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007217 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007218 TAG, "Stepped animation in " + this +
7219 ": more=" + more + ", xform=" + mTransformation);
7220 if (more) {
7221 // we're not done!
7222 return true;
7223 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007224 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007225 TAG, "Finished animation in " + this +
7226 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007227
7228 if (mAnimation != null) {
7229 mAnimation.cancel();
7230 mAnimation = null;
7231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 //WindowManagerService.this.dump();
7233 }
7234 mHasLocalTransformation = false;
7235 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007236 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007237 // When our app token is animating, we kind-of pretend like
7238 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7239 // part of this check means that we will only do this if
7240 // our window is not currently exiting, or it is not
7241 // locally animating itself. The idea being that one that
7242 // is exiting and doing a local animation should be removed
7243 // once that animation is done.
7244 mAnimating = true;
7245 mHasTransformation = true;
7246 mTransformation.clear();
7247 return false;
7248 } else if (mHasTransformation) {
7249 // Little trick to get through the path below to act like
7250 // we have finished an animation.
7251 mAnimating = true;
7252 } else if (isAnimating()) {
7253 mAnimating = true;
7254 }
7255 } else if (mAnimation != null) {
7256 // If the display is frozen, and there is a pending animation,
7257 // clear it and make sure we run the cleanup code.
7258 mAnimating = true;
7259 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007260 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 mAnimation = null;
7262 }
Romain Guy06882f82009-06-10 13:36:04 -07007263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007264 if (!mAnimating && !mLocalAnimating) {
7265 return false;
7266 }
7267
Joe Onorato8a9b2202010-02-26 18:56:32 -08007268 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007269 TAG, "Animation done in " + this + ": exiting=" + mExiting
7270 + ", reportedVisible="
7271 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007273 mAnimating = false;
7274 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007275 if (mAnimation != null) {
7276 mAnimation.cancel();
7277 mAnimation = null;
7278 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 mAnimLayer = mLayer;
7280 if (mIsImWindow) {
7281 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007282 } else if (mIsWallpaper) {
7283 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007285 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007286 + " anim layer: " + mAnimLayer);
7287 mHasTransformation = false;
7288 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007289 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7290 if (DEBUG_VISIBILITY) {
7291 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7292 + mPolicyVisibilityAfterAnim);
7293 }
7294 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7295 if (!mPolicyVisibility) {
7296 if (mCurrentFocus == this) {
7297 mFocusMayChange = true;
7298 }
7299 // Window is no longer visible -- make sure if we were waiting
7300 // for it to be displayed before enabling the display, that
7301 // we allow the display to be enabled now.
7302 enableScreenIfNeededLocked();
7303 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007304 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 mTransformation.clear();
7306 if (mHasDrawn
7307 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7308 && mAppToken != null
7309 && mAppToken.firstWindowDrawn
7310 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007311 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007312 + mToken + ": first real window done animating");
7313 mFinishedStarting.add(mAppToken);
7314 mH.sendEmptyMessage(H.FINISHED_STARTING);
7315 }
Romain Guy06882f82009-06-10 13:36:04 -07007316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 finishExit();
7318
7319 if (mAppToken != null) {
7320 mAppToken.updateReportedVisibilityLocked();
7321 }
7322
7323 return false;
7324 }
7325
7326 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007327 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007328 TAG, "finishExit in " + this
7329 + ": exiting=" + mExiting
7330 + " remove=" + mRemoveOnExit
7331 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007333 final int N = mChildWindows.size();
7334 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007335 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 }
Romain Guy06882f82009-06-10 13:36:04 -07007337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 if (!mExiting) {
7339 return;
7340 }
Romain Guy06882f82009-06-10 13:36:04 -07007341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 if (isWindowAnimating()) {
7343 return;
7344 }
7345
Joe Onorato8a9b2202010-02-26 18:56:32 -08007346 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 TAG, "Exit animation finished in " + this
7348 + ": remove=" + mRemoveOnExit);
7349 if (mSurface != null) {
7350 mDestroySurface.add(this);
7351 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007352 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007353 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 try {
7355 mSurface.hide();
7356 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007357 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007358 }
7359 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007360 }
7361 mExiting = false;
7362 if (mRemoveOnExit) {
7363 mPendingRemove.add(this);
7364 mRemoveOnExit = false;
7365 }
7366 }
Romain Guy06882f82009-06-10 13:36:04 -07007367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7369 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7370 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7371 if (dtdx < -.000001f || dtdx > .000001f) return false;
7372 if (dsdy < -.000001f || dsdy > .000001f) return false;
7373 return true;
7374 }
Romain Guy06882f82009-06-10 13:36:04 -07007375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 void computeShownFrameLocked() {
7377 final boolean selfTransformation = mHasLocalTransformation;
7378 Transformation attachedTransformation =
7379 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7380 ? mAttachedWindow.mTransformation : null;
7381 Transformation appTransformation =
7382 (mAppToken != null && mAppToken.hasTransformation)
7383 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007384
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007385 // Wallpapers are animated based on the "real" window they
7386 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007387 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007388 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007389 if (mWallpaperTarget.mHasLocalTransformation &&
7390 mWallpaperTarget.mAnimation != null &&
7391 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007392 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007393 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007394 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007395 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007396 }
7397 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007398 mWallpaperTarget.mAppToken.hasTransformation &&
7399 mWallpaperTarget.mAppToken.animation != null &&
7400 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007401 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007402 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007403 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007404 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007405 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007406 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 if (selfTransformation || attachedTransformation != null
7409 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007410 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007411 final Rect frame = mFrame;
7412 final float tmpFloats[] = mTmpFloats;
7413 final Matrix tmpMatrix = mTmpMatrix;
7414
7415 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007416 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007417 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007418 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007419 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007420 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007422 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007423 }
7424 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007425 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007426 }
7427
7428 // "convert" it into SurfaceFlinger's format
7429 // (a 2x2 matrix + an offset)
7430 // Here we must not transform the position of the surface
7431 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007432 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007434 tmpMatrix.getValues(tmpFloats);
7435 mDsDx = tmpFloats[Matrix.MSCALE_X];
7436 mDtDx = tmpFloats[Matrix.MSKEW_X];
7437 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7438 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007439 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7440 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 int w = frame.width();
7442 int h = frame.height();
7443 mShownFrame.set(x, y, x+w, y+h);
7444
7445 // Now set the alpha... but because our current hardware
7446 // can't do alpha transformation on a non-opaque surface,
7447 // turn it off if we are running an animation that is also
7448 // transforming since it is more important to have that
7449 // animation be smooth.
7450 mShownAlpha = mAlpha;
7451 if (!mLimitedAlphaCompositing
7452 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7453 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7454 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007455 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 if (selfTransformation) {
7457 mShownAlpha *= mTransformation.getAlpha();
7458 }
7459 if (attachedTransformation != null) {
7460 mShownAlpha *= attachedTransformation.getAlpha();
7461 }
7462 if (appTransformation != null) {
7463 mShownAlpha *= appTransformation.getAlpha();
7464 }
7465 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007466 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 }
Romain Guy06882f82009-06-10 13:36:04 -07007468
Joe Onorato8a9b2202010-02-26 18:56:32 -08007469 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 TAG, "Continuing animation in " + this +
7471 ": " + mShownFrame +
7472 ", alpha=" + mTransformation.getAlpha());
7473 return;
7474 }
Romain Guy06882f82009-06-10 13:36:04 -07007475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007477 if (mXOffset != 0 || mYOffset != 0) {
7478 mShownFrame.offset(mXOffset, mYOffset);
7479 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 mShownAlpha = mAlpha;
7481 mDsDx = 1;
7482 mDtDx = 0;
7483 mDsDy = 0;
7484 mDtDy = 1;
7485 }
Romain Guy06882f82009-06-10 13:36:04 -07007486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007487 /**
7488 * Is this window visible? It is not visible if there is no
7489 * surface, or we are in the process of running an exit animation
7490 * that will remove the surface, or its app token has been hidden.
7491 */
7492 public boolean isVisibleLw() {
7493 final AppWindowToken atoken = mAppToken;
7494 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7495 && (atoken == null || !atoken.hiddenRequested)
7496 && !mExiting && !mDestroying;
7497 }
7498
7499 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007500 * Like {@link #isVisibleLw}, but also counts a window that is currently
7501 * "hidden" behind the keyguard as visible. This allows us to apply
7502 * things like window flags that impact the keyguard.
7503 * XXX I am starting to think we need to have ANOTHER visibility flag
7504 * for this "hidden behind keyguard" state rather than overloading
7505 * mPolicyVisibility. Ungh.
7506 */
7507 public boolean isVisibleOrBehindKeyguardLw() {
7508 final AppWindowToken atoken = mAppToken;
7509 return mSurface != null && !mAttachedHidden
7510 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007511 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007512 && !mExiting && !mDestroying;
7513 }
7514
7515 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 * Is this window visible, ignoring its app token? It is not visible
7517 * if there is no surface, or we are in the process of running an exit animation
7518 * that will remove the surface.
7519 */
7520 public boolean isWinVisibleLw() {
7521 final AppWindowToken atoken = mAppToken;
7522 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7523 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7524 && !mExiting && !mDestroying;
7525 }
7526
7527 /**
7528 * The same as isVisible(), but follows the current hidden state of
7529 * the associated app token, not the pending requested hidden state.
7530 */
7531 boolean isVisibleNow() {
7532 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007533 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007534 }
7535
7536 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007537 * Can this window possibly be a drag/drop target? The test here is
7538 * a combination of the above "visible now" with the check that the
7539 * Input Manager uses when discarding windows from input consideration.
7540 */
7541 boolean isPotentialDragTarget() {
7542 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7543 }
7544
7545 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 * Same as isVisible(), but we also count it as visible between the
7547 * call to IWindowSession.add() and the first relayout().
7548 */
7549 boolean isVisibleOrAdding() {
7550 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007551 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007552 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7553 && mPolicyVisibility && !mAttachedHidden
7554 && (atoken == null || !atoken.hiddenRequested)
7555 && !mExiting && !mDestroying;
7556 }
7557
7558 /**
7559 * Is this window currently on-screen? It is on-screen either if it
7560 * is visible or it is currently running an animation before no longer
7561 * being visible.
7562 */
7563 boolean isOnScreen() {
7564 final AppWindowToken atoken = mAppToken;
7565 if (atoken != null) {
7566 return mSurface != null && mPolicyVisibility && !mDestroying
7567 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007568 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 } else {
7570 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007571 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 }
7573 }
Romain Guy06882f82009-06-10 13:36:04 -07007574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 /**
7576 * Like isOnScreen(), but we don't return true if the window is part
7577 * of a transition that has not yet been started.
7578 */
7579 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007580 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007581 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007582 return false;
7583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007585 final boolean animating = atoken != null
7586 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007588 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7589 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007590 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 }
7592
7593 /** Is the window or its container currently animating? */
7594 boolean isAnimating() {
7595 final WindowState attached = mAttachedWindow;
7596 final AppWindowToken atoken = mAppToken;
7597 return mAnimation != null
7598 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007599 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007600 (atoken.animation != null
7601 || atoken.inPendingTransaction));
7602 }
7603
7604 /** Is this window currently animating? */
7605 boolean isWindowAnimating() {
7606 return mAnimation != null;
7607 }
7608
7609 /**
7610 * Like isOnScreen, but returns false if the surface hasn't yet
7611 * been drawn.
7612 */
7613 public boolean isDisplayedLw() {
7614 final AppWindowToken atoken = mAppToken;
7615 return mSurface != null && mPolicyVisibility && !mDestroying
7616 && !mDrawPending && !mCommitDrawPending
7617 && ((!mAttachedHidden &&
7618 (atoken == null || !atoken.hiddenRequested))
7619 || mAnimating);
7620 }
7621
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007622 /**
7623 * Returns true if the window has a surface that it has drawn a
7624 * complete UI in to.
7625 */
7626 public boolean isDrawnLw() {
7627 final AppWindowToken atoken = mAppToken;
7628 return mSurface != null && !mDestroying
7629 && !mDrawPending && !mCommitDrawPending;
7630 }
7631
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007632 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007633 * Return true if the window is opaque and fully drawn. This indicates
7634 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007635 */
7636 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007637 return (mAttrs.format == PixelFormat.OPAQUE
7638 || mAttrs.type == TYPE_WALLPAPER)
7639 && mSurface != null && mAnimation == null
7640 && (mAppToken == null || mAppToken.animation == null)
7641 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007642 }
7643
7644 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7645 return
7646 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007647 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7648 // only if it's visible
7649 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007650 // and only if the application fills the compatible screen
7651 mFrame.left <= mCompatibleScreenFrame.left &&
7652 mFrame.top <= mCompatibleScreenFrame.top &&
7653 mFrame.right >= mCompatibleScreenFrame.right &&
7654 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007655 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007656 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007657 }
7658
7659 boolean isFullscreen(int screenWidth, int screenHeight) {
7660 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007661 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007662 }
7663
7664 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007665 disposeInputChannel();
7666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007667 if (mAttachedWindow != null) {
7668 mAttachedWindow.mChildWindows.remove(this);
7669 }
7670 destroySurfaceLocked();
7671 mSession.windowRemovedLocked();
7672 try {
7673 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7674 } catch (RuntimeException e) {
7675 // Ignore if it has already been removed (usually because
7676 // we are doing this as part of processing a death note.)
7677 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007678 }
7679
7680 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007681 if (mInputChannel != null) {
7682 mInputManager.unregisterInputChannel(mInputChannel);
7683
7684 mInputChannel.dispose();
7685 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007687 }
7688
7689 private class DeathRecipient implements IBinder.DeathRecipient {
7690 public void binderDied() {
7691 try {
7692 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007693 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007694 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007695 if (win != null) {
7696 removeWindowLocked(mSession, win);
7697 }
7698 }
7699 } catch (IllegalArgumentException ex) {
7700 // This will happen if the window has already been
7701 // removed.
7702 }
7703 }
7704 }
7705
7706 /** Returns true if this window desires key events. */
7707 public final boolean canReceiveKeys() {
7708 return isVisibleOrAdding()
7709 && (mViewVisibility == View.VISIBLE)
7710 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7711 }
7712
7713 public boolean hasDrawnLw() {
7714 return mHasDrawn;
7715 }
7716
7717 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007718 return showLw(doAnimation, true);
7719 }
7720
7721 boolean showLw(boolean doAnimation, boolean requestAnim) {
7722 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7723 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007725 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007726 if (doAnimation) {
7727 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7728 + mPolicyVisibility + " mAnimation=" + mAnimation);
7729 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7730 doAnimation = false;
7731 } else if (mPolicyVisibility && mAnimation == null) {
7732 // Check for the case where we are currently visible and
7733 // not animating; we do not want to do animation at such a
7734 // point to become visible when we already are.
7735 doAnimation = false;
7736 }
7737 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007738 mPolicyVisibility = true;
7739 mPolicyVisibilityAfterAnim = true;
7740 if (doAnimation) {
7741 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7742 }
7743 if (requestAnim) {
7744 requestAnimationLocked(0);
7745 }
7746 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007747 }
7748
7749 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007750 return hideLw(doAnimation, true);
7751 }
7752
7753 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007754 if (doAnimation) {
7755 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7756 doAnimation = false;
7757 }
7758 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7760 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007761 if (!current) {
7762 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007763 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007764 if (doAnimation) {
7765 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7766 if (mAnimation == null) {
7767 doAnimation = false;
7768 }
7769 }
7770 if (doAnimation) {
7771 mPolicyVisibilityAfterAnim = false;
7772 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007773 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007774 mPolicyVisibilityAfterAnim = false;
7775 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007776 // Window is no longer visible -- make sure if we were waiting
7777 // for it to be displayed before enabling the display, that
7778 // we allow the display to be enabled now.
7779 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007780 if (mCurrentFocus == this) {
7781 mFocusMayChange = true;
7782 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007783 }
7784 if (requestAnim) {
7785 requestAnimationLocked(0);
7786 }
7787 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007788 }
7789
7790 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007791 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7792 pw.print(" mClient="); pw.println(mClient.asBinder());
7793 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7794 if (mAttachedWindow != null || mLayoutAttached) {
7795 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7796 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7797 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007798 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7799 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7800 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007801 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7802 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007803 }
7804 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7805 pw.print(" mSubLayer="); pw.print(mSubLayer);
7806 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7807 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7808 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7809 pw.print("="); pw.print(mAnimLayer);
7810 pw.print(" mLastLayer="); pw.println(mLastLayer);
7811 if (mSurface != null) {
7812 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007813 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7814 pw.print(" layer="); pw.print(mSurfaceLayer);
7815 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7816 pw.print(" rect=("); pw.print(mSurfaceX);
7817 pw.print(","); pw.print(mSurfaceY);
7818 pw.print(") "); pw.print(mSurfaceW);
7819 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007820 }
7821 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7822 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7823 if (mAppToken != null) {
7824 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7825 }
7826 if (mTargetAppToken != null) {
7827 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7828 }
7829 pw.print(prefix); pw.print("mViewVisibility=0x");
7830 pw.print(Integer.toHexString(mViewVisibility));
7831 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007832 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7833 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007834 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7835 pw.print(prefix); pw.print("mPolicyVisibility=");
7836 pw.print(mPolicyVisibility);
7837 pw.print(" mPolicyVisibilityAfterAnim=");
7838 pw.print(mPolicyVisibilityAfterAnim);
7839 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7840 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007841 if (!mRelayoutCalled) {
7842 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7843 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007844 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007845 pw.print(" h="); pw.print(mRequestedHeight);
7846 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007847 if (mXOffset != 0 || mYOffset != 0) {
7848 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7849 pw.print(" y="); pw.println(mYOffset);
7850 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007851 pw.print(prefix); pw.print("mGivenContentInsets=");
7852 mGivenContentInsets.printShortString(pw);
7853 pw.print(" mGivenVisibleInsets=");
7854 mGivenVisibleInsets.printShortString(pw);
7855 pw.println();
7856 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7857 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7858 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7859 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007860 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007861 pw.print(prefix); pw.print("mShownFrame=");
7862 mShownFrame.printShortString(pw);
7863 pw.print(" last="); mLastShownFrame.printShortString(pw);
7864 pw.println();
7865 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7866 pw.print(" last="); mLastFrame.printShortString(pw);
7867 pw.println();
7868 pw.print(prefix); pw.print("mContainingFrame=");
7869 mContainingFrame.printShortString(pw);
7870 pw.print(" mDisplayFrame=");
7871 mDisplayFrame.printShortString(pw);
7872 pw.println();
7873 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7874 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7875 pw.println();
7876 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7877 pw.print(" last="); mLastContentInsets.printShortString(pw);
7878 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7879 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7880 pw.println();
7881 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7882 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7883 pw.print(" mAlpha="); pw.print(mAlpha);
7884 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7885 }
7886 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7887 || mAnimation != null) {
7888 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7889 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7890 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7891 pw.print(" mAnimation="); pw.println(mAnimation);
7892 }
7893 if (mHasTransformation || mHasLocalTransformation) {
7894 pw.print(prefix); pw.print("XForm: has=");
7895 pw.print(mHasTransformation);
7896 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7897 pw.print(" "); mTransformation.printShortString(pw);
7898 pw.println();
7899 }
7900 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7901 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7902 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7903 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7904 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7905 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7906 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7907 pw.print(" mDestroying="); pw.print(mDestroying);
7908 pw.print(" mRemoved="); pw.println(mRemoved);
7909 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007910 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007911 pw.print(prefix); pw.print("mOrientationChanging=");
7912 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007913 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7914 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007915 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007916 if (mHScale != 1 || mVScale != 1) {
7917 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7918 pw.print(" mVScale="); pw.println(mVScale);
7919 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007920 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007921 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7922 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7923 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007924 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7925 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7926 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007928 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007929
7930 String makeInputChannelName() {
7931 return Integer.toHexString(System.identityHashCode(this))
7932 + " " + mAttrs.getTitle();
7933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007934
7935 @Override
7936 public String toString() {
7937 return "Window{"
7938 + Integer.toHexString(System.identityHashCode(this))
7939 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7940 }
7941 }
Romain Guy06882f82009-06-10 13:36:04 -07007942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007943 // -------------------------------------------------------------
7944 // Window Token State
7945 // -------------------------------------------------------------
7946
7947 class WindowToken {
7948 // The actual token.
7949 final IBinder token;
7950
7951 // The type of window this token is for, as per WindowManager.LayoutParams.
7952 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007954 // Set if this token was explicitly added by a client, so should
7955 // not be removed when all windows are removed.
7956 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007957
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007958 // For printing.
7959 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007961 // If this is an AppWindowToken, this is non-null.
7962 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007964 // All of the windows associated with this token.
7965 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7966
7967 // Is key dispatching paused for this token?
7968 boolean paused = false;
7969
7970 // Should this token's windows be hidden?
7971 boolean hidden;
7972
7973 // Temporary for finding which tokens no longer have visible windows.
7974 boolean hasVisible;
7975
Dianne Hackborna8f60182009-09-01 19:01:50 -07007976 // Set to true when this token is in a pending transaction where it
7977 // will be shown.
7978 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007979
Dianne Hackborna8f60182009-09-01 19:01:50 -07007980 // Set to true when this token is in a pending transaction where it
7981 // will be hidden.
7982 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007983
Dianne Hackborna8f60182009-09-01 19:01:50 -07007984 // Set to true when this token is in a pending transaction where its
7985 // windows will be put to the bottom of the list.
7986 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007987
Dianne Hackborna8f60182009-09-01 19:01:50 -07007988 // Set to true when this token is in a pending transaction where its
7989 // windows will be put to the top of the list.
7990 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007992 WindowToken(IBinder _token, int type, boolean _explicit) {
7993 token = _token;
7994 windowType = type;
7995 explicit = _explicit;
7996 }
7997
7998 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007999 pw.print(prefix); pw.print("token="); pw.println(token);
8000 pw.print(prefix); pw.print("windows="); pw.println(windows);
8001 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8002 pw.print(" hidden="); pw.print(hidden);
8003 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008004 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8005 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8006 pw.print(" waitingToHide="); pw.print(waitingToHide);
8007 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8008 pw.print(" sendingToTop="); pw.println(sendingToTop);
8009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008010 }
8011
8012 @Override
8013 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008014 if (stringName == null) {
8015 StringBuilder sb = new StringBuilder();
8016 sb.append("WindowToken{");
8017 sb.append(Integer.toHexString(System.identityHashCode(this)));
8018 sb.append(" token="); sb.append(token); sb.append('}');
8019 stringName = sb.toString();
8020 }
8021 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 }
8023 };
8024
8025 class AppWindowToken extends WindowToken {
8026 // Non-null only for application tokens.
8027 final IApplicationToken appToken;
8028
8029 // All of the windows and child windows that are included in this
8030 // application token. Note this list is NOT sorted!
8031 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8032
8033 int groupId = -1;
8034 boolean appFullscreen;
8035 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008036
8037 // The input dispatching timeout for this application token in nanoseconds.
8038 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008040 // These are used for determining when all windows associated with
8041 // an activity have been drawn, so they can be made visible together
8042 // at the same time.
8043 int lastTransactionSequence = mTransactionSequence-1;
8044 int numInterestingWindows;
8045 int numDrawnWindows;
8046 boolean inPendingTransaction;
8047 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008049 // Is this token going to be hidden in a little while? If so, it
8050 // won't be taken into account for setting the screen orientation.
8051 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008053 // Is this window's surface needed? This is almost like hidden, except
8054 // it will sometimes be true a little earlier: when the token has
8055 // been shown, but is still waiting for its app transition to execute
8056 // before making its windows shown.
8057 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008059 // Have we told the window clients to hide themselves?
8060 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 // Last visibility state we reported to the app token.
8063 boolean reportedVisible;
8064
8065 // Set to true when the token has been removed from the window mgr.
8066 boolean removed;
8067
8068 // Have we been asked to have this token keep the screen frozen?
8069 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008071 boolean animating;
8072 Animation animation;
8073 boolean hasTransformation;
8074 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 // Offset to the window of all layers in the token, for use by
8077 // AppWindowToken animations.
8078 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008080 // Information about an application starting window if displayed.
8081 StartingData startingData;
8082 WindowState startingWindow;
8083 View startingView;
8084 boolean startingDisplayed;
8085 boolean startingMoved;
8086 boolean firstWindowDrawn;
8087
8088 AppWindowToken(IApplicationToken _token) {
8089 super(_token.asBinder(),
8090 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8091 appWindowToken = this;
8092 appToken = _token;
8093 }
Romain Guy06882f82009-06-10 13:36:04 -07008094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008095 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008096 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008097 TAG, "Setting animation in " + this + ": " + anim);
8098 animation = anim;
8099 animating = false;
8100 anim.restrictDuration(MAX_ANIMATION_DURATION);
8101 anim.scaleCurrentDuration(mTransitionAnimationScale);
8102 int zorder = anim.getZAdjustment();
8103 int adj = 0;
8104 if (zorder == Animation.ZORDER_TOP) {
8105 adj = TYPE_LAYER_OFFSET;
8106 } else if (zorder == Animation.ZORDER_BOTTOM) {
8107 adj = -TYPE_LAYER_OFFSET;
8108 }
Romain Guy06882f82009-06-10 13:36:04 -07008109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008110 if (animLayerAdjustment != adj) {
8111 animLayerAdjustment = adj;
8112 updateLayers();
8113 }
8114 }
Romain Guy06882f82009-06-10 13:36:04 -07008115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008116 public void setDummyAnimation() {
8117 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008118 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008119 TAG, "Setting dummy animation in " + this);
8120 animation = sDummyAnimation;
8121 }
8122 }
8123
8124 public void clearAnimation() {
8125 if (animation != null) {
8126 animation = null;
8127 animating = true;
8128 }
8129 }
Romain Guy06882f82009-06-10 13:36:04 -07008130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008131 void updateLayers() {
8132 final int N = allAppWindows.size();
8133 final int adj = animLayerAdjustment;
8134 for (int i=0; i<N; i++) {
8135 WindowState w = allAppWindows.get(i);
8136 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008137 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008138 + w.mAnimLayer);
8139 if (w == mInputMethodTarget) {
8140 setInputMethodAnimLayerAdjustment(adj);
8141 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008142 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008143 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 }
8146 }
Romain Guy06882f82009-06-10 13:36:04 -07008147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148 void sendAppVisibilityToClients() {
8149 final int N = allAppWindows.size();
8150 for (int i=0; i<N; i++) {
8151 WindowState win = allAppWindows.get(i);
8152 if (win == startingWindow && clientHidden) {
8153 // Don't hide the starting window.
8154 continue;
8155 }
8156 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008157 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008158 "Setting visibility of " + win + ": " + (!clientHidden));
8159 win.mClient.dispatchAppVisibility(!clientHidden);
8160 } catch (RemoteException e) {
8161 }
8162 }
8163 }
Romain Guy06882f82009-06-10 13:36:04 -07008164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008165 void showAllWindowsLocked() {
8166 final int NW = allAppWindows.size();
8167 for (int i=0; i<NW; i++) {
8168 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008169 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008170 "performing show on: " + w);
8171 w.performShowLocked();
8172 }
8173 }
Romain Guy06882f82009-06-10 13:36:04 -07008174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008175 // This must be called while inside a transaction.
8176 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008177 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008178 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008180 if (animation == sDummyAnimation) {
8181 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008182 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008183 // when it is really time to animate, this will be set to
8184 // a real animation and the next call will execute normally.
8185 return false;
8186 }
Romain Guy06882f82009-06-10 13:36:04 -07008187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008188 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8189 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008190 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008191 TAG, "Starting animation in " + this +
8192 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8193 + " scale=" + mTransitionAnimationScale
8194 + " allDrawn=" + allDrawn + " animating=" + animating);
8195 animation.initialize(dw, dh, dw, dh);
8196 animation.setStartTime(currentTime);
8197 animating = true;
8198 }
8199 transformation.clear();
8200 final boolean more = animation.getTransformation(
8201 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008202 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008203 TAG, "Stepped animation in " + this +
8204 ": more=" + more + ", xform=" + transformation);
8205 if (more) {
8206 // we're done!
8207 hasTransformation = true;
8208 return true;
8209 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008210 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008211 TAG, "Finished animation in " + this +
8212 " @ " + currentTime);
8213 animation = null;
8214 }
8215 } else if (animation != null) {
8216 // If the display is frozen, and there is a pending animation,
8217 // clear it and make sure we run the cleanup code.
8218 animating = true;
8219 animation = null;
8220 }
8221
8222 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008224 if (!animating) {
8225 return false;
8226 }
8227
8228 clearAnimation();
8229 animating = false;
8230 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8231 moveInputMethodWindowsIfNeededLocked(true);
8232 }
Romain Guy06882f82009-06-10 13:36:04 -07008233
Joe Onorato8a9b2202010-02-26 18:56:32 -08008234 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008235 TAG, "Animation done in " + this
8236 + ": reportedVisible=" + reportedVisible);
8237
8238 transformation.clear();
8239 if (animLayerAdjustment != 0) {
8240 animLayerAdjustment = 0;
8241 updateLayers();
8242 }
Romain Guy06882f82009-06-10 13:36:04 -07008243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008244 final int N = windows.size();
8245 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008246 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008247 }
8248 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250 return false;
8251 }
8252
8253 void updateReportedVisibilityLocked() {
8254 if (appToken == null) {
8255 return;
8256 }
Romain Guy06882f82009-06-10 13:36:04 -07008257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008258 int numInteresting = 0;
8259 int numVisible = 0;
8260 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008261
Joe Onorato8a9b2202010-02-26 18:56:32 -08008262 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008263 final int N = allAppWindows.size();
8264 for (int i=0; i<N; i++) {
8265 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008266 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008267 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008268 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8269 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008270 continue;
8271 }
8272 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008273 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008274 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008275 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008276 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008277 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008278 + " pv=" + win.mPolicyVisibility
8279 + " dp=" + win.mDrawPending
8280 + " cdp=" + win.mCommitDrawPending
8281 + " ah=" + win.mAttachedHidden
8282 + " th="
8283 + (win.mAppToken != null
8284 ? win.mAppToken.hiddenRequested : false)
8285 + " a=" + win.mAnimating);
8286 }
8287 }
8288 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008289 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008290 if (!win.isAnimating()) {
8291 numVisible++;
8292 }
8293 nowGone = false;
8294 } else if (win.isAnimating()) {
8295 nowGone = false;
8296 }
8297 }
Romain Guy06882f82009-06-10 13:36:04 -07008298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008299 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008300 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008301 + numInteresting + " visible=" + numVisible);
8302 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008303 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008304 TAG, "Visibility changed in " + this
8305 + ": vis=" + nowVisible);
8306 reportedVisible = nowVisible;
8307 Message m = mH.obtainMessage(
8308 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8309 nowVisible ? 1 : 0,
8310 nowGone ? 1 : 0,
8311 this);
8312 mH.sendMessage(m);
8313 }
8314 }
Romain Guy06882f82009-06-10 13:36:04 -07008315
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008316 WindowState findMainWindow() {
8317 int j = windows.size();
8318 while (j > 0) {
8319 j--;
8320 WindowState win = windows.get(j);
8321 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8322 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8323 return win;
8324 }
8325 }
8326 return null;
8327 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008329 void dump(PrintWriter pw, String prefix) {
8330 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008331 if (appToken != null) {
8332 pw.print(prefix); pw.println("app=true");
8333 }
8334 if (allAppWindows.size() > 0) {
8335 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8336 }
8337 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008338 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008339 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8340 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8341 pw.print(" clientHidden="); pw.print(clientHidden);
8342 pw.print(" willBeHidden="); pw.print(willBeHidden);
8343 pw.print(" reportedVisible="); pw.println(reportedVisible);
8344 if (paused || freezingScreen) {
8345 pw.print(prefix); pw.print("paused="); pw.print(paused);
8346 pw.print(" freezingScreen="); pw.println(freezingScreen);
8347 }
8348 if (numInterestingWindows != 0 || numDrawnWindows != 0
8349 || inPendingTransaction || allDrawn) {
8350 pw.print(prefix); pw.print("numInterestingWindows=");
8351 pw.print(numInterestingWindows);
8352 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8353 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8354 pw.print(" allDrawn="); pw.println(allDrawn);
8355 }
8356 if (animating || animation != null) {
8357 pw.print(prefix); pw.print("animating="); pw.print(animating);
8358 pw.print(" animation="); pw.println(animation);
8359 }
8360 if (animLayerAdjustment != 0) {
8361 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8362 }
8363 if (hasTransformation) {
8364 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8365 pw.print(" transformation="); transformation.printShortString(pw);
8366 pw.println();
8367 }
8368 if (startingData != null || removed || firstWindowDrawn) {
8369 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8370 pw.print(" removed="); pw.print(removed);
8371 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8372 }
8373 if (startingWindow != null || startingView != null
8374 || startingDisplayed || startingMoved) {
8375 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8376 pw.print(" startingView="); pw.print(startingView);
8377 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8378 pw.print(" startingMoved"); pw.println(startingMoved);
8379 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008380 }
8381
8382 @Override
8383 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008384 if (stringName == null) {
8385 StringBuilder sb = new StringBuilder();
8386 sb.append("AppWindowToken{");
8387 sb.append(Integer.toHexString(System.identityHashCode(this)));
8388 sb.append(" token="); sb.append(token); sb.append('}');
8389 stringName = sb.toString();
8390 }
8391 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008392 }
8393 }
Romain Guy06882f82009-06-10 13:36:04 -07008394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008395 // -------------------------------------------------------------
8396 // DummyAnimation
8397 // -------------------------------------------------------------
8398
8399 // This is an animation that does nothing: it just immediately finishes
8400 // itself every time it is called. It is used as a stub animation in cases
8401 // where we want to synchronize multiple things that may be animating.
8402 static final class DummyAnimation extends Animation {
8403 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8404 return false;
8405 }
8406 }
8407 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 // -------------------------------------------------------------
8410 // Async Handler
8411 // -------------------------------------------------------------
8412
8413 static final class StartingData {
8414 final String pkg;
8415 final int theme;
8416 final CharSequence nonLocalizedLabel;
8417 final int labelRes;
8418 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008420 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8421 int _labelRes, int _icon) {
8422 pkg = _pkg;
8423 theme = _theme;
8424 nonLocalizedLabel = _nonLocalizedLabel;
8425 labelRes = _labelRes;
8426 icon = _icon;
8427 }
8428 }
8429
8430 private final class H extends Handler {
8431 public static final int REPORT_FOCUS_CHANGE = 2;
8432 public static final int REPORT_LOSING_FOCUS = 3;
8433 public static final int ANIMATE = 4;
8434 public static final int ADD_STARTING = 5;
8435 public static final int REMOVE_STARTING = 6;
8436 public static final int FINISHED_STARTING = 7;
8437 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008438 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8439 public static final int HOLD_SCREEN_CHANGED = 12;
8440 public static final int APP_TRANSITION_TIMEOUT = 13;
8441 public static final int PERSIST_ANIMATION_SCALE = 14;
8442 public static final int FORCE_GC = 15;
8443 public static final int ENABLE_SCREEN = 16;
8444 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008445 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008446 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008447 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008448 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008450 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 public H() {
8453 }
Romain Guy06882f82009-06-10 13:36:04 -07008454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008455 @Override
8456 public void handleMessage(Message msg) {
8457 switch (msg.what) {
8458 case REPORT_FOCUS_CHANGE: {
8459 WindowState lastFocus;
8460 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 synchronized(mWindowMap) {
8463 lastFocus = mLastFocus;
8464 newFocus = mCurrentFocus;
8465 if (lastFocus == newFocus) {
8466 // Focus is not changing, so nothing to do.
8467 return;
8468 }
8469 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008470 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008471 // + " to " + newFocus);
8472 if (newFocus != null && lastFocus != null
8473 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008474 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008475 mLosingFocus.add(lastFocus);
8476 lastFocus = null;
8477 }
8478 }
8479
8480 if (lastFocus != newFocus) {
8481 //System.out.println("Changing focus from " + lastFocus
8482 // + " to " + newFocus);
8483 if (newFocus != null) {
8484 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008485 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8487 } catch (RemoteException e) {
8488 // Ignore if process has died.
8489 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008490 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 }
8492
8493 if (lastFocus != null) {
8494 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008495 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8497 } catch (RemoteException e) {
8498 // Ignore if process has died.
8499 }
8500 }
8501 }
8502 } break;
8503
8504 case REPORT_LOSING_FOCUS: {
8505 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008507 synchronized(mWindowMap) {
8508 losers = mLosingFocus;
8509 mLosingFocus = new ArrayList<WindowState>();
8510 }
8511
8512 final int N = losers.size();
8513 for (int i=0; i<N; i++) {
8514 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008515 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8517 } catch (RemoteException e) {
8518 // Ignore if process has died.
8519 }
8520 }
8521 } break;
8522
8523 case ANIMATE: {
8524 synchronized(mWindowMap) {
8525 mAnimationPending = false;
8526 performLayoutAndPlaceSurfacesLocked();
8527 }
8528 } break;
8529
8530 case ADD_STARTING: {
8531 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8532 final StartingData sd = wtoken.startingData;
8533
8534 if (sd == null) {
8535 // Animation has been canceled... do nothing.
8536 return;
8537 }
Romain Guy06882f82009-06-10 13:36:04 -07008538
Joe Onorato8a9b2202010-02-26 18:56:32 -08008539 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008542 View view = null;
8543 try {
8544 view = mPolicy.addStartingWindow(
8545 wtoken.token, sd.pkg,
8546 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8547 sd.icon);
8548 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008549 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008550 }
8551
8552 if (view != null) {
8553 boolean abort = false;
8554
8555 synchronized(mWindowMap) {
8556 if (wtoken.removed || wtoken.startingData == null) {
8557 // If the window was successfully added, then
8558 // we need to remove it.
8559 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008560 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 "Aborted starting " + wtoken
8562 + ": removed=" + wtoken.removed
8563 + " startingData=" + wtoken.startingData);
8564 wtoken.startingWindow = null;
8565 wtoken.startingData = null;
8566 abort = true;
8567 }
8568 } else {
8569 wtoken.startingView = view;
8570 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008571 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008572 "Added starting " + wtoken
8573 + ": startingWindow="
8574 + wtoken.startingWindow + " startingView="
8575 + wtoken.startingView);
8576 }
8577
8578 if (abort) {
8579 try {
8580 mPolicy.removeStartingWindow(wtoken.token, view);
8581 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008582 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583 }
8584 }
8585 }
8586 } break;
8587
8588 case REMOVE_STARTING: {
8589 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8590 IBinder token = null;
8591 View view = null;
8592 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008593 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008594 + wtoken + ": startingWindow="
8595 + wtoken.startingWindow + " startingView="
8596 + wtoken.startingView);
8597 if (wtoken.startingWindow != null) {
8598 view = wtoken.startingView;
8599 token = wtoken.token;
8600 wtoken.startingData = null;
8601 wtoken.startingView = null;
8602 wtoken.startingWindow = null;
8603 }
8604 }
8605 if (view != null) {
8606 try {
8607 mPolicy.removeStartingWindow(token, view);
8608 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008609 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008610 }
8611 }
8612 } break;
8613
8614 case FINISHED_STARTING: {
8615 IBinder token = null;
8616 View view = null;
8617 while (true) {
8618 synchronized (mWindowMap) {
8619 final int N = mFinishedStarting.size();
8620 if (N <= 0) {
8621 break;
8622 }
8623 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8624
Joe Onorato8a9b2202010-02-26 18:56:32 -08008625 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 "Finished starting " + wtoken
8627 + ": startingWindow=" + wtoken.startingWindow
8628 + " startingView=" + wtoken.startingView);
8629
8630 if (wtoken.startingWindow == null) {
8631 continue;
8632 }
8633
8634 view = wtoken.startingView;
8635 token = wtoken.token;
8636 wtoken.startingData = null;
8637 wtoken.startingView = null;
8638 wtoken.startingWindow = null;
8639 }
8640
8641 try {
8642 mPolicy.removeStartingWindow(token, view);
8643 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008644 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008645 }
8646 }
8647 } break;
8648
8649 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8650 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8651
8652 boolean nowVisible = msg.arg1 != 0;
8653 boolean nowGone = msg.arg2 != 0;
8654
8655 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008656 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008657 TAG, "Reporting visible in " + wtoken
8658 + " visible=" + nowVisible
8659 + " gone=" + nowGone);
8660 if (nowVisible) {
8661 wtoken.appToken.windowsVisible();
8662 } else {
8663 wtoken.appToken.windowsGone();
8664 }
8665 } catch (RemoteException ex) {
8666 }
8667 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008669 case WINDOW_FREEZE_TIMEOUT: {
8670 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008671 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008672 int i = mWindows.size();
8673 while (i > 0) {
8674 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008675 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008676 if (w.mOrientationChanging) {
8677 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008678 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008679 }
8680 }
8681 performLayoutAndPlaceSurfacesLocked();
8682 }
8683 break;
8684 }
Romain Guy06882f82009-06-10 13:36:04 -07008685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 case HOLD_SCREEN_CHANGED: {
8687 Session oldHold;
8688 Session newHold;
8689 synchronized (mWindowMap) {
8690 oldHold = mLastReportedHold;
8691 newHold = (Session)msg.obj;
8692 mLastReportedHold = newHold;
8693 }
Romain Guy06882f82009-06-10 13:36:04 -07008694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008695 if (oldHold != newHold) {
8696 try {
8697 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008698 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008699 "window",
8700 BatteryStats.WAKE_TYPE_WINDOW);
8701 }
8702 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008703 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 "window",
8705 BatteryStats.WAKE_TYPE_WINDOW);
8706 }
8707 } catch (RemoteException e) {
8708 }
8709 }
8710 break;
8711 }
Romain Guy06882f82009-06-10 13:36:04 -07008712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008713 case APP_TRANSITION_TIMEOUT: {
8714 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008715 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008716 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008717 "*** APP TRANSITION TIMEOUT");
8718 mAppTransitionReady = true;
8719 mAppTransitionTimeout = true;
8720 performLayoutAndPlaceSurfacesLocked();
8721 }
8722 }
8723 break;
8724 }
Romain Guy06882f82009-06-10 13:36:04 -07008725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008726 case PERSIST_ANIMATION_SCALE: {
8727 Settings.System.putFloat(mContext.getContentResolver(),
8728 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8729 Settings.System.putFloat(mContext.getContentResolver(),
8730 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8731 break;
8732 }
Romain Guy06882f82009-06-10 13:36:04 -07008733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734 case FORCE_GC: {
8735 synchronized(mWindowMap) {
8736 if (mAnimationPending) {
8737 // If we are animating, don't do the gc now but
8738 // delay a bit so we don't interrupt the animation.
8739 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8740 2000);
8741 return;
8742 }
8743 // If we are currently rotating the display, it will
8744 // schedule a new message when done.
8745 if (mDisplayFrozen) {
8746 return;
8747 }
8748 mFreezeGcPending = 0;
8749 }
8750 Runtime.getRuntime().gc();
8751 break;
8752 }
Romain Guy06882f82009-06-10 13:36:04 -07008753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008754 case ENABLE_SCREEN: {
8755 performEnableScreen();
8756 break;
8757 }
Romain Guy06882f82009-06-10 13:36:04 -07008758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008759 case APP_FREEZE_TIMEOUT: {
8760 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008761 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008762 int i = mAppTokens.size();
8763 while (i > 0) {
8764 i--;
8765 AppWindowToken tok = mAppTokens.get(i);
8766 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008767 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768 unsetAppFreezingScreenLocked(tok, true, true);
8769 }
8770 }
8771 }
8772 break;
8773 }
Romain Guy06882f82009-06-10 13:36:04 -07008774
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008775 case SEND_NEW_CONFIGURATION: {
8776 removeMessages(SEND_NEW_CONFIGURATION);
8777 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008778 break;
8779 }
Romain Guy06882f82009-06-10 13:36:04 -07008780
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008781 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008782 if (mWindowsChanged) {
8783 synchronized (mWindowMap) {
8784 mWindowsChanged = false;
8785 }
8786 notifyWindowsChanged();
8787 }
8788 break;
8789 }
8790
Christopher Tatea53146c2010-09-07 11:57:52 -07008791 case DRAG_START_TIMEOUT: {
8792 IBinder win = (IBinder)msg.obj;
8793 if (DEBUG_DRAG) {
8794 Slog.w(TAG, "Timeout starting drag by win " + win);
8795 }
8796 synchronized (mWindowMap) {
8797 // !!! TODO: ANR the app that has failed to start the drag in time
8798 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008799 mDragState.unregister();
8800 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008801 mDragState.reset();
8802 mDragState = null;
8803 }
8804 }
Chris Tated4533f142010-10-19 15:15:08 -07008805 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008806 }
8807
Chris Tated4533f142010-10-19 15:15:08 -07008808 case DRAG_END_TIMEOUT: {
8809 IBinder win = (IBinder)msg.obj;
8810 if (DEBUG_DRAG) {
8811 Slog.w(TAG, "Timeout ending drag to win " + win);
8812 }
8813 synchronized (mWindowMap) {
8814 // !!! TODO: ANR the drag-receiving app
8815 mDragState.mDragResult = false;
8816 mDragState.endDragLw();
8817 }
8818 break;
8819 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008820 }
8821 }
8822 }
8823
8824 // -------------------------------------------------------------
8825 // IWindowManager API
8826 // -------------------------------------------------------------
8827
8828 public IWindowSession openSession(IInputMethodClient client,
8829 IInputContext inputContext) {
8830 if (client == null) throw new IllegalArgumentException("null client");
8831 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008832 Session session = new Session(client, inputContext);
8833 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008834 }
8835
8836 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8837 synchronized (mWindowMap) {
8838 // The focus for the client is the window immediately below
8839 // where we would place the input method window.
8840 int idx = findDesiredInputMethodWindowIndexLocked(false);
8841 WindowState imFocus;
8842 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008843 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008844 if (imFocus != null) {
8845 if (imFocus.mSession.mClient != null &&
8846 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8847 return true;
8848 }
8849 }
8850 }
8851 }
8852 return false;
8853 }
Romain Guy06882f82009-06-10 13:36:04 -07008854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008855 // -------------------------------------------------------------
8856 // Internals
8857 // -------------------------------------------------------------
8858
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008859 final WindowState windowForClientLocked(Session session, IWindow client,
8860 boolean throwOnError) {
8861 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008862 }
Romain Guy06882f82009-06-10 13:36:04 -07008863
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008864 final WindowState windowForClientLocked(Session session, IBinder client,
8865 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008867 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 TAG, "Looking up client " + client + ": " + win);
8869 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008870 RuntimeException ex = new IllegalArgumentException(
8871 "Requested window " + client + " does not exist");
8872 if (throwOnError) {
8873 throw ex;
8874 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008875 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008876 return null;
8877 }
8878 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008879 RuntimeException ex = new IllegalArgumentException(
8880 "Requested window " + client + " is in session " +
8881 win.mSession + ", not " + session);
8882 if (throwOnError) {
8883 throw ex;
8884 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008885 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008886 return null;
8887 }
8888
8889 return win;
8890 }
8891
Dianne Hackborna8f60182009-09-01 19:01:50 -07008892 final void rebuildAppWindowListLocked() {
8893 int NW = mWindows.size();
8894 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008895 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008896 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008897
Dianne Hackborna8f60182009-09-01 19:01:50 -07008898 // First remove all existing app windows.
8899 i=0;
8900 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008901 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008902 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008903 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008904 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008905 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008906 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008907 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008908 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008909 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008910 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8911 && lastWallpaper == i-1) {
8912 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008913 }
8914 i++;
8915 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008916
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008917 // The wallpaper window(s) typically live at the bottom of the stack,
8918 // so skip them before adding app tokens.
8919 lastWallpaper++;
8920 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008921
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008922 // First add all of the exiting app tokens... these are no longer
8923 // in the main app list, but still have windows shown. We put them
8924 // in the back because now that the animation is over we no longer
8925 // will care about them.
8926 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008927 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008928 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8929 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008930
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008931 // And add in the still active app tokens in Z order.
8932 NT = mAppTokens.size();
8933 for (int j=0; j<NT; j++) {
8934 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008935 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008936
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008937 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008938 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008939 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008940 + " windows but added " + i);
8941 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008942 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008944 private final void assignLayersLocked() {
8945 int N = mWindows.size();
8946 int curBaseLayer = 0;
8947 int curLayer = 0;
8948 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008950 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008951 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008952 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8953 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 curLayer += WINDOW_LAYER_MULTIPLIER;
8955 w.mLayer = curLayer;
8956 } else {
8957 curBaseLayer = curLayer = w.mBaseLayer;
8958 w.mLayer = curLayer;
8959 }
8960 if (w.mTargetAppToken != null) {
8961 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8962 } else if (w.mAppToken != null) {
8963 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8964 } else {
8965 w.mAnimLayer = w.mLayer;
8966 }
8967 if (w.mIsImWindow) {
8968 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008969 } else if (w.mIsWallpaper) {
8970 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008971 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008972 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 + w.mAnimLayer);
8974 //System.out.println(
8975 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8976 }
8977 }
8978
8979 private boolean mInLayout = false;
8980 private final void performLayoutAndPlaceSurfacesLocked() {
8981 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008982 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008983 throw new RuntimeException("Recursive call!");
8984 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008985 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008986 return;
8987 }
8988
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008989 if (mWaitingForConfig) {
8990 // Our configuration has changed (most likely rotation), but we
8991 // don't yet have the complete configuration to report to
8992 // applications. Don't do any window layout until we have it.
8993 return;
8994 }
8995
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008996 if (mDisplay == null) {
8997 // Not yet initialized, nothing to do.
8998 return;
8999 }
9000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 boolean recoveringMemory = false;
9002 if (mForceRemoves != null) {
9003 recoveringMemory = true;
9004 // Wait a little it for things to settle down, and off we go.
9005 for (int i=0; i<mForceRemoves.size(); i++) {
9006 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009007 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 removeWindowInnerLocked(ws.mSession, ws);
9009 }
9010 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009011 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009012 Object tmp = new Object();
9013 synchronized (tmp) {
9014 try {
9015 tmp.wait(250);
9016 } catch (InterruptedException e) {
9017 }
9018 }
9019 }
Romain Guy06882f82009-06-10 13:36:04 -07009020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009021 mInLayout = true;
9022 try {
9023 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009025 int i = mPendingRemove.size()-1;
9026 if (i >= 0) {
9027 while (i >= 0) {
9028 WindowState w = mPendingRemove.get(i);
9029 removeWindowInnerLocked(w.mSession, w);
9030 i--;
9031 }
9032 mPendingRemove.clear();
9033
9034 mInLayout = false;
9035 assignLayersLocked();
9036 mLayoutNeeded = true;
9037 performLayoutAndPlaceSurfacesLocked();
9038
9039 } else {
9040 mInLayout = false;
9041 if (mLayoutNeeded) {
9042 requestAnimationLocked(0);
9043 }
9044 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009045 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009046 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9047 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009049 } catch (RuntimeException e) {
9050 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009051 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009052 }
9053 }
9054
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009055 private final int performLayoutLockedInner() {
9056 if (!mLayoutNeeded) {
9057 return 0;
9058 }
9059
9060 mLayoutNeeded = false;
9061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009062 final int dw = mDisplay.getWidth();
9063 final int dh = mDisplay.getHeight();
9064
9065 final int N = mWindows.size();
9066 int i;
9067
Joe Onorato8a9b2202010-02-26 18:56:32 -08009068 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009069 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9070
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009071 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009072
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009073 int seq = mLayoutSeq+1;
9074 if (seq < 0) seq = 0;
9075 mLayoutSeq = seq;
9076
9077 // First perform layout of any root windows (not attached
9078 // to another window).
9079 int topAttached = -1;
9080 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009081 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009082
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009083 // Don't do layout of a window if it is not visible, or
9084 // soon won't be visible, to avoid wasting time and funky
9085 // changes while a window is animating away.
9086 final AppWindowToken atoken = win.mAppToken;
9087 final boolean gone = win.mViewVisibility == View.GONE
9088 || !win.mRelayoutCalled
9089 || win.mRootToken.hidden
9090 || (atoken != null && atoken.hiddenRequested)
9091 || win.mAttachedHidden
9092 || win.mExiting || win.mDestroying;
9093
9094 if (!win.mLayoutAttached) {
9095 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9096 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9097 + " mLayoutAttached=" + win.mLayoutAttached);
9098 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9099 + win.mViewVisibility + " mRelayoutCalled="
9100 + win.mRelayoutCalled + " hidden="
9101 + win.mRootToken.hidden + " hiddenRequested="
9102 + (atoken != null && atoken.hiddenRequested)
9103 + " mAttachedHidden=" + win.mAttachedHidden);
9104 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009105
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009106 // If this view is GONE, then skip it -- keep the current
9107 // frame, and let the caller know so they can ignore it
9108 // if they want. (We do the normal layout for INVISIBLE
9109 // windows, since that means "perform layout as normal,
9110 // just don't display").
9111 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009112 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009113 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9114 win.mLayoutSeq = seq;
9115 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9116 + win.mFrame + " mContainingFrame="
9117 + win.mContainingFrame + " mDisplayFrame="
9118 + win.mDisplayFrame);
9119 } else {
9120 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009121 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009123 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009124
9125 // Now perform layout of attached windows, which usually
9126 // depend on the position of the window they are attached to.
9127 // XXX does not deal with windows that are attached to windows
9128 // that are themselves attached.
9129 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009130 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009131
9132 // If this view is GONE, then skip it -- keep the current
9133 // frame, and let the caller know so they can ignore it
9134 // if they want. (We do the normal layout for INVISIBLE
9135 // windows, since that means "perform layout as normal,
9136 // just don't display").
9137 if (win.mLayoutAttached) {
9138 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9139 + " mHaveFrame=" + win.mHaveFrame
9140 + " mViewVisibility=" + win.mViewVisibility
9141 + " mRelayoutCalled=" + win.mRelayoutCalled);
9142 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9143 || !win.mHaveFrame) {
9144 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9145 win.mLayoutSeq = seq;
9146 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9147 + win.mFrame + " mContainingFrame="
9148 + win.mContainingFrame + " mDisplayFrame="
9149 + win.mDisplayFrame);
9150 }
9151 }
9152 }
Jeff Brown349703e2010-06-22 01:27:15 -07009153
9154 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009155 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009156
9157 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009158 }
Romain Guy06882f82009-06-10 13:36:04 -07009159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009160 private final void performLayoutAndPlaceSurfacesLockedInner(
9161 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009162 if (mDisplay == null) {
9163 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9164 return;
9165 }
9166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009167 final long currentTime = SystemClock.uptimeMillis();
9168 final int dw = mDisplay.getWidth();
9169 final int dh = mDisplay.getHeight();
9170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 int i;
9172
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009173 if (mFocusMayChange) {
9174 mFocusMayChange = false;
9175 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9176 }
9177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009178 // Initialize state of exiting tokens.
9179 for (i=mExitingTokens.size()-1; i>=0; i--) {
9180 mExitingTokens.get(i).hasVisible = false;
9181 }
9182
9183 // Initialize state of exiting applications.
9184 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9185 mExitingAppTokens.get(i).hasVisible = false;
9186 }
9187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009188 boolean orientationChangeComplete = true;
9189 Session holdScreen = null;
9190 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009191 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009192 boolean focusDisplayed = false;
9193 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009194 boolean createWatermark = false;
9195
9196 if (mFxSession == null) {
9197 mFxSession = new SurfaceSession();
9198 createWatermark = true;
9199 }
9200
9201 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009202
9203 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009204
9205 if (createWatermark) {
9206 createWatermark();
9207 }
9208 if (mWatermark != null) {
9209 mWatermark.positionSurface(dw, dh);
9210 }
9211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009212 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009213 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009214 int repeats = 0;
9215 int changes = 0;
9216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009217 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009218 repeats++;
9219 if (repeats > 6) {
9220 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9221 mLayoutNeeded = false;
9222 break;
9223 }
9224
9225 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9226 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9227 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9228 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9229 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9230 assignLayersLocked();
9231 mLayoutNeeded = true;
9232 }
9233 }
9234 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9235 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9236 if (updateOrientationFromAppTokensLocked()) {
9237 mLayoutNeeded = true;
9238 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9239 }
9240 }
9241 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9242 mLayoutNeeded = true;
9243 }
9244 }
9245
9246 // FIRST LOOP: Perform a layout, if needed.
9247 if (repeats < 4) {
9248 changes = performLayoutLockedInner();
9249 if (changes != 0) {
9250 continue;
9251 }
9252 } else {
9253 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9254 changes = 0;
9255 }
9256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 final int transactionSequence = ++mTransactionSequence;
9258
9259 // Update animations of all applications, including those
9260 // associated with exiting/removed apps
9261 boolean tokensAnimating = false;
9262 final int NAT = mAppTokens.size();
9263 for (i=0; i<NAT; i++) {
9264 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9265 tokensAnimating = true;
9266 }
9267 }
9268 final int NEAT = mExitingAppTokens.size();
9269 for (i=0; i<NEAT; i++) {
9270 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9271 tokensAnimating = true;
9272 }
9273 }
9274
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009275 // SECOND LOOP: Execute animations and update visibility of windows.
9276
Joe Onorato8a9b2202010-02-26 18:56:32 -08009277 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009278 + transactionSequence + " tokensAnimating="
9279 + tokensAnimating);
9280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009281 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009282
9283 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009284 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009285 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009286
9287 mPolicy.beginAnimationLw(dw, dh);
9288
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009289 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009291 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009292 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009293
9294 final WindowManager.LayoutParams attrs = w.mAttrs;
9295
9296 if (w.mSurface != null) {
9297 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009298 if (w.commitFinishDrawingLocked(currentTime)) {
9299 if ((w.mAttrs.flags
9300 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009301 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009302 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009303 wallpaperMayChange = true;
9304 }
9305 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009306
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009307 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009308 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9309 animating = true;
9310 //w.dump(" ");
9311 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009312 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9313 wallpaperMayChange = true;
9314 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009315
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009316 if (mPolicy.doesForceHide(w, attrs)) {
9317 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009318 if (DEBUG_VISIBILITY) Slog.v(TAG,
9319 "Animation done that could impact force hide: "
9320 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009321 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009322 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009323 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9324 forceHiding = true;
9325 }
9326 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9327 boolean changed;
9328 if (forceHiding) {
9329 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009330 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9331 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009332 } else {
9333 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009334 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9335 "Now policy shown: " + w);
9336 if (changed) {
9337 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009338 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009339 // Assume we will need to animate. If
9340 // we don't (because the wallpaper will
9341 // stay with the lock screen), then we will
9342 // clean up later.
9343 Animation a = mPolicy.createForceHideEnterAnimation();
9344 if (a != null) {
9345 w.setAnimation(a);
9346 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009347 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009348 if (mCurrentFocus == null ||
9349 mCurrentFocus.mLayer < w.mLayer) {
9350 // We are showing on to of the current
9351 // focus, so re-evaluate focus to make
9352 // sure it is correct.
9353 mFocusMayChange = true;
9354 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009355 }
9356 }
9357 if (changed && (attrs.flags
9358 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9359 wallpaperMayChange = true;
9360 }
9361 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009363 mPolicy.animatingWindowLw(w, attrs);
9364 }
9365
9366 final AppWindowToken atoken = w.mAppToken;
9367 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9368 if (atoken.lastTransactionSequence != transactionSequence) {
9369 atoken.lastTransactionSequence = transactionSequence;
9370 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9371 atoken.startingDisplayed = false;
9372 }
9373 if ((w.isOnScreen() || w.mAttrs.type
9374 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9375 && !w.mExiting && !w.mDestroying) {
9376 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009377 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009378 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009380 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009381 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009382 + " pv=" + w.mPolicyVisibility
9383 + " dp=" + w.mDrawPending
9384 + " cdp=" + w.mCommitDrawPending
9385 + " ah=" + w.mAttachedHidden
9386 + " th=" + atoken.hiddenRequested
9387 + " a=" + w.mAnimating);
9388 }
9389 }
9390 if (w != atoken.startingWindow) {
9391 if (!atoken.freezingScreen || !w.mAppFreezing) {
9392 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009393 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009394 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009395 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009396 "tokenMayBeDrawn: " + atoken
9397 + " freezingScreen=" + atoken.freezingScreen
9398 + " mAppFreezing=" + w.mAppFreezing);
9399 tokenMayBeDrawn = true;
9400 }
9401 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009402 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009403 atoken.startingDisplayed = true;
9404 }
9405 }
9406 } else if (w.mReadyToShow) {
9407 w.performShowLocked();
9408 }
9409 }
9410
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009411 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009412
9413 if (tokenMayBeDrawn) {
9414 // See if any windows have been drawn, so they (and others
9415 // associated with them) can now be shown.
9416 final int NT = mTokenList.size();
9417 for (i=0; i<NT; i++) {
9418 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9419 if (wtoken == null) {
9420 continue;
9421 }
9422 if (wtoken.freezingScreen) {
9423 int numInteresting = wtoken.numInterestingWindows;
9424 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009425 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 "allDrawn: " + wtoken
9427 + " interesting=" + numInteresting
9428 + " drawn=" + wtoken.numDrawnWindows);
9429 wtoken.showAllWindowsLocked();
9430 unsetAppFreezingScreenLocked(wtoken, false, true);
9431 orientationChangeComplete = true;
9432 }
9433 } else if (!wtoken.allDrawn) {
9434 int numInteresting = wtoken.numInterestingWindows;
9435 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009436 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009437 "allDrawn: " + wtoken
9438 + " interesting=" + numInteresting
9439 + " drawn=" + wtoken.numDrawnWindows);
9440 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009441 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442
9443 // We can now show all of the drawn windows!
9444 if (!mOpeningApps.contains(wtoken)) {
9445 wtoken.showAllWindowsLocked();
9446 }
9447 }
9448 }
9449 }
9450 }
9451
9452 // If we are ready to perform an app transition, check through
9453 // all of the app tokens to be shown and see if they are ready
9454 // to go.
9455 if (mAppTransitionReady) {
9456 int NN = mOpeningApps.size();
9457 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009458 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009459 "Checking " + NN + " opening apps (frozen="
9460 + mDisplayFrozen + " timeout="
9461 + mAppTransitionTimeout + ")...");
9462 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9463 // If the display isn't frozen, wait to do anything until
9464 // all of the apps are ready. Otherwise just go because
9465 // we'll unfreeze the display when everyone is ready.
9466 for (i=0; i<NN && goodToGo; i++) {
9467 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009468 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469 "Check opening app" + wtoken + ": allDrawn="
9470 + wtoken.allDrawn + " startingDisplayed="
9471 + wtoken.startingDisplayed);
9472 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9473 && !wtoken.startingMoved) {
9474 goodToGo = false;
9475 }
9476 }
9477 }
9478 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009479 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 int transit = mNextAppTransition;
9481 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009482 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009483 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009484 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009486 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009487 mAppTransitionTimeout = false;
9488 mStartingIconInTransition = false;
9489 mSkipAppTransitionAnimation = false;
9490
9491 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9492
Dianne Hackborna8f60182009-09-01 19:01:50 -07009493 // If there are applications waiting to come to the
9494 // top of the stack, now is the time to move their windows.
9495 // (Note that we don't do apps going to the bottom
9496 // here -- we want to keep their windows in the old
9497 // Z-order until the animation completes.)
9498 if (mToTopApps.size() > 0) {
9499 NN = mAppTokens.size();
9500 for (i=0; i<NN; i++) {
9501 AppWindowToken wtoken = mAppTokens.get(i);
9502 if (wtoken.sendingToTop) {
9503 wtoken.sendingToTop = false;
9504 moveAppWindowsLocked(wtoken, NN, false);
9505 }
9506 }
9507 mToTopApps.clear();
9508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009509
Dianne Hackborn25994b42009-09-04 14:21:19 -07009510 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009511
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009512 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009513 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009514
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009515 // The top-most window will supply the layout params,
9516 // and we will determine it below.
9517 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009518 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009519 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009520
Joe Onorato8a9b2202010-02-26 18:56:32 -08009521 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009522 "New wallpaper target=" + mWallpaperTarget
9523 + ", lower target=" + mLowerWallpaperTarget
9524 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009525 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009526 // Do a first pass through the tokens for two
9527 // things:
9528 // (1) Determine if both the closing and opening
9529 // app token sets are wallpaper targets, in which
9530 // case special animations are needed
9531 // (since the wallpaper needs to stay static
9532 // behind them).
9533 // (2) Find the layout params of the top-most
9534 // application window in the tokens, which is
9535 // what will control the animation theme.
9536 final int NC = mClosingApps.size();
9537 NN = NC + mOpeningApps.size();
9538 for (i=0; i<NN; i++) {
9539 AppWindowToken wtoken;
9540 int mode;
9541 if (i < NC) {
9542 wtoken = mClosingApps.get(i);
9543 mode = 1;
9544 } else {
9545 wtoken = mOpeningApps.get(i-NC);
9546 mode = 2;
9547 }
9548 if (mLowerWallpaperTarget != null) {
9549 if (mLowerWallpaperTarget.mAppToken == wtoken
9550 || mUpperWallpaperTarget.mAppToken == wtoken) {
9551 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009552 }
9553 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009554 if (wtoken.appFullscreen) {
9555 WindowState ws = wtoken.findMainWindow();
9556 if (ws != null) {
9557 // If this is a compatibility mode
9558 // window, we will always use its anim.
9559 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9560 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009561 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009562 bestAnimLayer = Integer.MAX_VALUE;
9563 } else if (ws.mLayer > bestAnimLayer) {
9564 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009565 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009566 bestAnimLayer = ws.mLayer;
9567 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009568 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009569 }
9570 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009571
Dianne Hackborn25994b42009-09-04 14:21:19 -07009572 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009573 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009574 "Wallpaper animation!");
9575 switch (transit) {
9576 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9577 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9578 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9579 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9580 break;
9581 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9582 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9583 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9584 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9585 break;
9586 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009587 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009588 "New transit: " + transit);
9589 } else if (oldWallpaper != null) {
9590 // We are transitioning from an activity with
9591 // a wallpaper to one without.
9592 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009593 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009594 "New transit away from wallpaper: " + transit);
9595 } else if (mWallpaperTarget != null) {
9596 // We are transitioning from an activity without
9597 // a wallpaper to now showing the wallpaper
9598 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009599 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009600 "New transit into wallpaper: " + transit);
9601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009603 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9604 mLastEnterAnimToken = animToken;
9605 mLastEnterAnimParams = animLp;
9606 } else if (mLastEnterAnimParams != null) {
9607 animLp = mLastEnterAnimParams;
9608 mLastEnterAnimToken = null;
9609 mLastEnterAnimParams = null;
9610 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009611
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009612 // If all closing windows are obscured, then there is
9613 // no need to do an animation. This is the case, for
9614 // example, when this transition is being done behind
9615 // the lock screen.
9616 if (!mPolicy.allowAppAnimationsLw()) {
9617 animLp = null;
9618 }
9619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009620 NN = mOpeningApps.size();
9621 for (i=0; i<NN; i++) {
9622 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009623 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009624 "Now opening app" + wtoken);
9625 wtoken.reportedVisible = false;
9626 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009627 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009628 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009629 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009630 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009631 wtoken.showAllWindowsLocked();
9632 }
9633 NN = mClosingApps.size();
9634 for (i=0; i<NN; i++) {
9635 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009636 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009637 "Now closing app" + wtoken);
9638 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009639 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009640 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009641 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009642 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009643 // Force the allDrawn flag, because we want to start
9644 // this guy's animations regardless of whether it's
9645 // gotten drawn.
9646 wtoken.allDrawn = true;
9647 }
9648
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009649 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651 mOpeningApps.clear();
9652 mClosingApps.clear();
9653
9654 // This has changed the visibility of windows, so perform
9655 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009656 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009657 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009658 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9659 assignLayersLocked();
9660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009662 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009663 }
9664 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009665
Dianne Hackborn16064f92010-03-25 00:47:24 -07009666 int adjResult = 0;
9667
Dianne Hackborna8f60182009-09-01 19:01:50 -07009668 if (!animating && mAppTransitionRunning) {
9669 // We have finished the animation of an app transition. To do
9670 // this, we have delayed a lot of operations like showing and
9671 // hiding apps, moving apps in Z-order, etc. The app token list
9672 // reflects the correct Z-order, but the window list may now
9673 // be out of sync with it. So here we will just rebuild the
9674 // entire app window list. Fun!
9675 mAppTransitionRunning = false;
9676 // Clear information about apps that were moving.
9677 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009678
Dianne Hackborna8f60182009-09-01 19:01:50 -07009679 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009680 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009681 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009682 moveInputMethodWindowsIfNeededLocked(false);
9683 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009684 // Since the window list has been rebuilt, focus might
9685 // have to be recomputed since the actual order of windows
9686 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009687 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009689
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009690 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009691 // At this point, there was a window with a wallpaper that
9692 // was force hiding other windows behind it, but now it
9693 // is going away. This may be simple -- just animate
9694 // away the wallpaper and its window -- or it may be
9695 // hard -- the wallpaper now needs to be shown behind
9696 // something that was hidden.
9697 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009698 if (mLowerWallpaperTarget != null
9699 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009700 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009701 "wallpaperForceHiding changed with lower="
9702 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009703 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009704 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9705 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9706 if (mLowerWallpaperTarget.mAppToken.hidden) {
9707 // The lower target has become hidden before we
9708 // actually started the animation... let's completely
9709 // re-evaluate everything.
9710 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009711 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009712 }
9713 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009714 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009715 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009716 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009717 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009718 + " NEW: " + mWallpaperTarget
9719 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009720 if (mLowerWallpaperTarget == null) {
9721 // Whoops, we don't need a special wallpaper animation.
9722 // Clear them out.
9723 forceHiding = false;
9724 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009725 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009726 if (w.mSurface != null) {
9727 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009728 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009729 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009730 forceHiding = true;
9731 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9732 if (!w.mAnimating) {
9733 // We set the animation above so it
9734 // is not yet running.
9735 w.clearAnimation();
9736 }
9737 }
9738 }
9739 }
9740 }
9741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009742
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009743 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009744 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009745 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009746 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009747 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009748
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009749 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009751 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009752 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009753 assignLayersLocked();
9754 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009755 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009756 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009757 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009759
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009760 if (mFocusMayChange) {
9761 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009762 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009763 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009764 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009765 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009766 }
9767
9768 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009769 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009770 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009771
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009772 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9773 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009774
Jeff Browne33348b2010-07-15 23:54:05 -07009775 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009776 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009777
9778 // THIRD LOOP: Update the surfaces of all windows.
9779
9780 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9781
9782 boolean obscured = false;
9783 boolean blurring = false;
9784 boolean dimming = false;
9785 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009786 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009787 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009789 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009792 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009793
9794 boolean displayed = false;
9795 final WindowManager.LayoutParams attrs = w.mAttrs;
9796 final int attrFlags = attrs.flags;
9797
9798 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009799 // XXX NOTE: The logic here could be improved. We have
9800 // the decision about whether to resize a window separated
9801 // from whether to hide the surface. This can cause us to
9802 // resize a surface even if we are going to hide it. You
9803 // can see this by (1) holding device in landscape mode on
9804 // home screen; (2) tapping browser icon (device will rotate
9805 // to landscape; (3) tap home. The wallpaper will be resized
9806 // in step 2 but then immediately hidden, causing us to
9807 // have to resize and then redraw it again in step 3. It
9808 // would be nice to figure out how to avoid this, but it is
9809 // difficult because we do need to resize surfaces in some
9810 // cases while they are hidden such as when first showing a
9811 // window.
9812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009814 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009815 TAG, "Placing surface #" + i + " " + w.mSurface
9816 + ": new=" + w.mShownFrame + ", old="
9817 + w.mLastShownFrame);
9818
9819 boolean resize;
9820 int width, height;
9821 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9822 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9823 w.mLastRequestedHeight != w.mRequestedHeight;
9824 // for a scaled surface, we just want to use
9825 // the requested size.
9826 width = w.mRequestedWidth;
9827 height = w.mRequestedHeight;
9828 w.mLastRequestedWidth = width;
9829 w.mLastRequestedHeight = height;
9830 w.mLastShownFrame.set(w.mShownFrame);
9831 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009832 if (SHOW_TRANSACTIONS) logSurface(w,
9833 "POS " + w.mShownFrame.left
9834 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009835 w.mSurfaceX = w.mShownFrame.left;
9836 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009837 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9838 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009839 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009840 if (!recoveringMemory) {
9841 reclaimSomeSurfaceMemoryLocked(w, "position");
9842 }
9843 }
9844 } else {
9845 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9846 width = w.mShownFrame.width();
9847 height = w.mShownFrame.height();
9848 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009849 }
9850
9851 if (resize) {
9852 if (width < 1) width = 1;
9853 if (height < 1) height = 1;
9854 if (w.mSurface != null) {
9855 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009856 if (SHOW_TRANSACTIONS) logSurface(w,
9857 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009858 + w.mShownFrame.top + " SIZE "
9859 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009860 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009861 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009862 w.mSurfaceW = width;
9863 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009864 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009865 w.mSurfaceX = w.mShownFrame.left;
9866 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867 w.mSurface.setPosition(w.mShownFrame.left,
9868 w.mShownFrame.top);
9869 } catch (RuntimeException e) {
9870 // If something goes wrong with the surface (such
9871 // as running out of memory), don't take down the
9872 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009873 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009874 + "size=(" + width + "x" + height
9875 + "), pos=(" + w.mShownFrame.left
9876 + "," + w.mShownFrame.top + ")", e);
9877 if (!recoveringMemory) {
9878 reclaimSomeSurfaceMemoryLocked(w, "size");
9879 }
9880 }
9881 }
9882 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009883 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009884 w.mContentInsetsChanged =
9885 !w.mLastContentInsets.equals(w.mContentInsets);
9886 w.mVisibleInsetsChanged =
9887 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009888 boolean configChanged =
9889 w.mConfiguration != mCurConfiguration
9890 && (w.mConfiguration == null
9891 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009892 if (DEBUG_CONFIGURATION && configChanged) {
9893 Slog.v(TAG, "Win " + w + " config changed: "
9894 + mCurConfiguration);
9895 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009896 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009897 + ": configChanged=" + configChanged
9898 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009899 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009901 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009902 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009903 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009904 w.mLastFrame.set(w.mFrame);
9905 w.mLastContentInsets.set(w.mContentInsets);
9906 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009907 // If the screen is currently frozen, then keep
9908 // it frozen until this window draws at its new
9909 // orientation.
9910 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009911 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009912 "Resizing while display frozen: " + w);
9913 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009914 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009915 mWindowsFreezingScreen = true;
9916 // XXX should probably keep timeout from
9917 // when we first froze the display.
9918 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9919 mH.sendMessageDelayed(mH.obtainMessage(
9920 H.WINDOW_FREEZE_TIMEOUT), 2000);
9921 }
9922 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009923 // If the orientation is changing, then we need to
9924 // hold off on unfreezing the display until this
9925 // window has been redrawn; to do that, we need
9926 // to go through the process of getting informed
9927 // by the application when it has finished drawing.
9928 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009929 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009930 "Orientation start waiting for draw in "
9931 + w + ", surface " + w.mSurface);
9932 w.mDrawPending = true;
9933 w.mCommitDrawPending = false;
9934 w.mReadyToShow = false;
9935 if (w.mAppToken != null) {
9936 w.mAppToken.allDrawn = false;
9937 }
9938 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009939 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009940 "Resizing window " + w + " to " + w.mFrame);
9941 mResizingWindows.add(w);
9942 } else if (w.mOrientationChanging) {
9943 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009944 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009945 "Orientation not waiting for draw in "
9946 + w + ", surface " + w.mSurface);
9947 w.mOrientationChanging = false;
9948 }
9949 }
9950 }
9951
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009952 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009953 if (!w.mLastHidden) {
9954 //dump();
9955 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009956 if (SHOW_TRANSACTIONS) logSurface(w,
9957 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009958 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009959 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009960 try {
9961 w.mSurface.hide();
9962 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009963 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009964 }
9965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009966 }
9967 // If we are waiting for this window to handle an
9968 // orientation change, well, it is hidden, so
9969 // doesn't really matter. Note that this does
9970 // introduce a potential glitch if the window
9971 // becomes unhidden before it has drawn for the
9972 // new orientation.
9973 if (w.mOrientationChanging) {
9974 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009975 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009976 "Orientation change skips hidden " + w);
9977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009978 } else if (w.mLastLayer != w.mAnimLayer
9979 || w.mLastAlpha != w.mShownAlpha
9980 || w.mLastDsDx != w.mDsDx
9981 || w.mLastDtDx != w.mDtDx
9982 || w.mLastDsDy != w.mDsDy
9983 || w.mLastDtDy != w.mDtDy
9984 || w.mLastHScale != w.mHScale
9985 || w.mLastVScale != w.mVScale
9986 || w.mLastHidden) {
9987 displayed = true;
9988 w.mLastAlpha = w.mShownAlpha;
9989 w.mLastLayer = w.mAnimLayer;
9990 w.mLastDsDx = w.mDsDx;
9991 w.mLastDtDx = w.mDtDx;
9992 w.mLastDsDy = w.mDsDy;
9993 w.mLastDtDy = w.mDtDy;
9994 w.mLastHScale = w.mHScale;
9995 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009996 if (SHOW_TRANSACTIONS) logSurface(w,
9997 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009998 + " matrix=[" + (w.mDsDx*w.mHScale)
9999 + "," + (w.mDtDx*w.mVScale)
10000 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010001 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010002 if (w.mSurface != null) {
10003 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010004 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010006 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010007 w.mSurface.setLayer(w.mAnimLayer);
10008 w.mSurface.setMatrix(
10009 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10010 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10011 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010012 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010013 if (!recoveringMemory) {
10014 reclaimSomeSurfaceMemoryLocked(w, "update");
10015 }
10016 }
10017 }
10018
10019 if (w.mLastHidden && !w.mDrawPending
10020 && !w.mCommitDrawPending
10021 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010022 if (SHOW_TRANSACTIONS) logSurface(w,
10023 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010024 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 + " during relayout");
10026 if (showSurfaceRobustlyLocked(w)) {
10027 w.mHasDrawn = true;
10028 w.mLastHidden = false;
10029 } else {
10030 w.mOrientationChanging = false;
10031 }
10032 }
10033 if (w.mSurface != null) {
10034 w.mToken.hasVisible = true;
10035 }
10036 } else {
10037 displayed = true;
10038 }
10039
10040 if (displayed) {
10041 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010042 if (attrs.width == LayoutParams.MATCH_PARENT
10043 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010044 covered = true;
10045 }
10046 }
10047 if (w.mOrientationChanging) {
10048 if (w.mDrawPending || w.mCommitDrawPending) {
10049 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010050 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010051 "Orientation continue waiting for draw in " + w);
10052 } else {
10053 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010054 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055 "Orientation change complete in " + w);
10056 }
10057 }
10058 w.mToken.hasVisible = true;
10059 }
10060 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010061 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010062 "Orientation change skips hidden " + w);
10063 w.mOrientationChanging = false;
10064 }
10065
10066 final boolean canBeSeen = w.isDisplayedLw();
10067
10068 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10069 focusDisplayed = true;
10070 }
10071
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010072 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010074 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010075 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010076 if (w.mSurface != null) {
10077 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10078 holdScreen = w.mSession;
10079 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010080 if (!syswin && w.mAttrs.screenBrightness >= 0
10081 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010082 screenBrightness = w.mAttrs.screenBrightness;
10083 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010084 if (!syswin && w.mAttrs.buttonBrightness >= 0
10085 && buttonBrightness < 0) {
10086 buttonBrightness = w.mAttrs.buttonBrightness;
10087 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010088 if (canBeSeen
10089 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10090 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10091 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010092 syswin = true;
10093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010094 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010095
Dianne Hackborn25994b42009-09-04 14:21:19 -070010096 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10097 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010098 // This window completely covers everything behind it,
10099 // so we want to leave all of them as unblurred (for
10100 // performance reasons).
10101 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010102 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010103 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010104 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010105 obscured = true;
10106 if (mBackgroundFillerSurface == null) {
10107 try {
10108 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010109 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010110 0, dw, dh,
10111 PixelFormat.OPAQUE,
10112 Surface.FX_SURFACE_NORMAL);
10113 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010114 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010115 }
10116 }
10117 try {
10118 mBackgroundFillerSurface.setPosition(0, 0);
10119 mBackgroundFillerSurface.setSize(dw, dh);
10120 // Using the same layer as Dim because they will never be shown at the
10121 // same time.
10122 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10123 mBackgroundFillerSurface.show();
10124 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010125 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010126 }
10127 backgroundFillerShown = true;
10128 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010129 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010130 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010131 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010132 + ": blurring=" + blurring
10133 + " obscured=" + obscured
10134 + " displayed=" + displayed);
10135 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10136 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010137 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010138 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010139 if (mDimAnimator == null) {
10140 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010141 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010142 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010143 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010145 }
10146 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10147 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010148 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010149 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010150 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010151 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010152 + mBlurSurface + ": CREATE");
10153 try {
Romain Guy06882f82009-06-10 13:36:04 -070010154 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010155 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010156 -1, 16, 16,
10157 PixelFormat.OPAQUE,
10158 Surface.FX_SURFACE_BLUR);
10159 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010160 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010161 }
10162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010163 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010164 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10165 + mBlurSurface + ": pos=(0,0) (" +
10166 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010167 mBlurSurface.setPosition(0, 0);
10168 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010169 mBlurSurface.setLayer(w.mAnimLayer-2);
10170 if (!mBlurShown) {
10171 try {
10172 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10173 + mBlurSurface + ": SHOW");
10174 mBlurSurface.show();
10175 } catch (RuntimeException e) {
10176 Slog.w(TAG, "Failure showing blur surface", e);
10177 }
10178 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010179 }
10180 }
10181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010182 }
10183 }
10184 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010185
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010186 if (obscuredChanged && mWallpaperTarget == w) {
10187 // This is the wallpaper target and its obscured state
10188 // changed... make sure the current wallaper's visibility
10189 // has been updated accordingly.
10190 updateWallpaperVisibilityLocked();
10191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010192 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010193
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010194 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10195 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010196 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010197 try {
10198 mBackgroundFillerSurface.hide();
10199 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010200 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010201 }
10202 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010203
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010204 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010205 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10206 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010207 }
Romain Guy06882f82009-06-10 13:36:04 -070010208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010209 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010210 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010211 + ": HIDE");
10212 try {
10213 mBlurSurface.hide();
10214 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010215 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010216 }
10217 mBlurShown = false;
10218 }
10219
Joe Onorato8a9b2202010-02-26 18:56:32 -080010220 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010221 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010222 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010223 }
10224
Jeff Browne33348b2010-07-15 23:54:05 -070010225 mInputMonitor.updateInputWindowsLw();
10226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010227 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010228
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010229 if (mWatermark != null) {
10230 mWatermark.drawIfNeeded();
10231 }
10232
Joe Onorato8a9b2202010-02-26 18:56:32 -080010233 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010234 "With display frozen, orientationChangeComplete="
10235 + orientationChangeComplete);
10236 if (orientationChangeComplete) {
10237 if (mWindowsFreezingScreen) {
10238 mWindowsFreezingScreen = false;
10239 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10240 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010241 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010242 }
Romain Guy06882f82009-06-10 13:36:04 -070010243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010244 i = mResizingWindows.size();
10245 if (i > 0) {
10246 do {
10247 i--;
10248 WindowState win = mResizingWindows.get(i);
10249 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010250 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10251 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010252 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010253 boolean configChanged =
10254 win.mConfiguration != mCurConfiguration
10255 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010256 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10257 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10258 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010259 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010260 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010261 + " / " + mCurConfiguration + " / 0x"
10262 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010263 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010264 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010265 win.mClient.resized(win.mFrame.width(),
10266 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010267 win.mLastVisibleInsets, win.mDrawPending,
10268 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010269 win.mContentInsetsChanged = false;
10270 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010271 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 } catch (RemoteException e) {
10273 win.mOrientationChanging = false;
10274 }
10275 } while (i > 0);
10276 mResizingWindows.clear();
10277 }
Romain Guy06882f82009-06-10 13:36:04 -070010278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010279 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010280 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 i = mDestroySurface.size();
10282 if (i > 0) {
10283 do {
10284 i--;
10285 WindowState win = mDestroySurface.get(i);
10286 win.mDestroying = false;
10287 if (mInputMethodWindow == win) {
10288 mInputMethodWindow = null;
10289 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010290 if (win == mWallpaperTarget) {
10291 wallpaperDestroyed = true;
10292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 win.destroySurfaceLocked();
10294 } while (i > 0);
10295 mDestroySurface.clear();
10296 }
10297
10298 // Time to remove any exiting tokens?
10299 for (i=mExitingTokens.size()-1; i>=0; i--) {
10300 WindowToken token = mExitingTokens.get(i);
10301 if (!token.hasVisible) {
10302 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010303 if (token.windowType == TYPE_WALLPAPER) {
10304 mWallpaperTokens.remove(token);
10305 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010306 }
10307 }
10308
10309 // Time to remove any exiting applications?
10310 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10311 AppWindowToken token = mExitingAppTokens.get(i);
10312 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010313 // Make sure there is no animation running on this token,
10314 // so any windows associated with it will be removed as
10315 // soon as their animations are complete
10316 token.animation = null;
10317 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010318 mAppTokens.remove(token);
10319 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010320 if (mLastEnterAnimToken == token) {
10321 mLastEnterAnimToken = null;
10322 mLastEnterAnimParams = null;
10323 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 }
10325 }
10326
Dianne Hackborna8f60182009-09-01 19:01:50 -070010327 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010328
Dianne Hackborna8f60182009-09-01 19:01:50 -070010329 if (!animating && mAppTransitionRunning) {
10330 // We have finished the animation of an app transition. To do
10331 // this, we have delayed a lot of operations like showing and
10332 // hiding apps, moving apps in Z-order, etc. The app token list
10333 // reflects the correct Z-order, but the window list may now
10334 // be out of sync with it. So here we will just rebuild the
10335 // entire app window list. Fun!
10336 mAppTransitionRunning = false;
10337 needRelayout = true;
10338 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010339 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010340 // Clear information about apps that were moving.
10341 mToBottomApps.clear();
10342 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010344 if (focusDisplayed) {
10345 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10346 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010347 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010348 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010349 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010350 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010351 requestAnimationLocked(0);
10352 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10354 }
Jeff Browneb857f12010-07-16 10:06:33 -070010355
Jeff Browne33348b2010-07-15 23:54:05 -070010356 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010357
Jeff Brown8e03b752010-06-13 19:16:55 -070010358 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10360 mPowerManager.setScreenBrightnessOverride(-1);
10361 } else {
10362 mPowerManager.setScreenBrightnessOverride((int)
10363 (screenBrightness * Power.BRIGHTNESS_ON));
10364 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010365 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10366 mPowerManager.setButtonBrightnessOverride(-1);
10367 } else {
10368 mPowerManager.setButtonBrightnessOverride((int)
10369 (buttonBrightness * Power.BRIGHTNESS_ON));
10370 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010371 if (holdScreen != mHoldingScreenOn) {
10372 mHoldingScreenOn = holdScreen;
10373 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10374 mH.sendMessage(m);
10375 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010376
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010377 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010378 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010379 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10380 LocalPowerManager.BUTTON_EVENT, true);
10381 mTurnOnScreen = false;
10382 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010383
10384 // Check to see if we are now in a state where the screen should
10385 // be enabled, because the window obscured flags have changed.
10386 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010388
10389 /**
10390 * Must be called with the main window manager lock held.
10391 */
10392 void setHoldScreenLocked(boolean holding) {
10393 boolean state = mHoldingScreenWakeLock.isHeld();
10394 if (holding != state) {
10395 if (holding) {
10396 mHoldingScreenWakeLock.acquire();
10397 } else {
10398 mPolicy.screenOnStoppedLw();
10399 mHoldingScreenWakeLock.release();
10400 }
10401 }
10402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403
10404 void requestAnimationLocked(long delay) {
10405 if (!mAnimationPending) {
10406 mAnimationPending = true;
10407 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10408 }
10409 }
Romain Guy06882f82009-06-10 13:36:04 -070010410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010411 /**
10412 * Have the surface flinger show a surface, robustly dealing with
10413 * error conditions. In particular, if there is not enough memory
10414 * to show the surface, then we will try to get rid of other surfaces
10415 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010416 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417 * @return Returns true if the surface was successfully shown.
10418 */
10419 boolean showSurfaceRobustlyLocked(WindowState win) {
10420 try {
10421 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010422 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010424 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010425 if (DEBUG_VISIBILITY) Slog.v(TAG,
10426 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010427 win.mTurnOnScreen = false;
10428 mTurnOnScreen = true;
10429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010430 }
10431 return true;
10432 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010433 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010434 }
Romain Guy06882f82009-06-10 13:36:04 -070010435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010436 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010438 return false;
10439 }
Romain Guy06882f82009-06-10 13:36:04 -070010440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010441 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10442 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010443
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010444 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010445 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010447 if (mForceRemoves == null) {
10448 mForceRemoves = new ArrayList<WindowState>();
10449 }
Romain Guy06882f82009-06-10 13:36:04 -070010450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010451 long callingIdentity = Binder.clearCallingIdentity();
10452 try {
10453 // There was some problem... first, do a sanity check of the
10454 // window list to make sure we haven't left any dangling surfaces
10455 // around.
10456 int N = mWindows.size();
10457 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010458 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010460 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 if (ws.mSurface != null) {
10462 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010463 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010464 + ws + " surface=" + ws.mSurface
10465 + " token=" + win.mToken
10466 + " pid=" + ws.mSession.mPid
10467 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010468 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010469 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010470 ws.mSurface = null;
10471 mForceRemoves.add(ws);
10472 i--;
10473 N--;
10474 leakedSurface = true;
10475 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010476 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 + ws + " surface=" + ws.mSurface
10478 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010479 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010480 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010481 ws.mSurface = null;
10482 leakedSurface = true;
10483 }
10484 }
10485 }
Romain Guy06882f82009-06-10 13:36:04 -070010486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010487 boolean killedApps = false;
10488 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010489 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010490 SparseIntArray pidCandidates = new SparseIntArray();
10491 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010492 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 if (ws.mSurface != null) {
10494 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10495 }
10496 }
10497 if (pidCandidates.size() > 0) {
10498 int[] pids = new int[pidCandidates.size()];
10499 for (int i=0; i<pids.length; i++) {
10500 pids[i] = pidCandidates.keyAt(i);
10501 }
10502 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010503 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 killedApps = true;
10505 }
10506 } catch (RemoteException e) {
10507 }
10508 }
10509 }
Romain Guy06882f82009-06-10 13:36:04 -070010510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 if (leakedSurface || killedApps) {
10512 // We managed to reclaim some memory, so get rid of the trouble
10513 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010514 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010516 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010517 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 win.mSurface = null;
10519 }
Romain Guy06882f82009-06-10 13:36:04 -070010520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010521 try {
10522 win.mClient.dispatchGetNewSurface();
10523 } catch (RemoteException e) {
10524 }
10525 }
10526 } finally {
10527 Binder.restoreCallingIdentity(callingIdentity);
10528 }
10529 }
Romain Guy06882f82009-06-10 13:36:04 -070010530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 private boolean updateFocusedWindowLocked(int mode) {
10532 WindowState newFocus = computeFocusedWindowLocked();
10533 if (mCurrentFocus != newFocus) {
10534 // This check makes sure that we don't already have the focus
10535 // change message pending.
10536 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10537 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010538 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010539 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10540 final WindowState oldFocus = mCurrentFocus;
10541 mCurrentFocus = newFocus;
10542 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010544 final WindowState imWindow = mInputMethodWindow;
10545 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010546 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010547 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010548 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10549 mLayoutNeeded = true;
10550 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010551 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10552 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010553 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10554 // Client will do the layout, but we need to assign layers
10555 // for handleNewWindowLocked() below.
10556 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010557 }
10558 }
Jeff Brown349703e2010-06-22 01:27:15 -070010559
10560 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10561 // If we defer assigning layers, then the caller is responsible for
10562 // doing this part.
10563 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010565 return true;
10566 }
10567 return false;
10568 }
Jeff Brown349703e2010-06-22 01:27:15 -070010569
10570 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010571 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573
10574 private WindowState computeFocusedWindowLocked() {
10575 WindowState result = null;
10576 WindowState win;
10577
10578 int i = mWindows.size() - 1;
10579 int nextAppIndex = mAppTokens.size()-1;
10580 WindowToken nextApp = nextAppIndex >= 0
10581 ? mAppTokens.get(nextAppIndex) : null;
10582
10583 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010584 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010585
Joe Onorato8a9b2202010-02-26 18:56:32 -080010586 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010587 TAG, "Looking for focus: " + i
10588 + " = " + win
10589 + ", flags=" + win.mAttrs.flags
10590 + ", canReceive=" + win.canReceiveKeys());
10591
10592 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 // If this window's application has been removed, just skip it.
10595 if (thisApp != null && thisApp.removed) {
10596 i--;
10597 continue;
10598 }
Romain Guy06882f82009-06-10 13:36:04 -070010599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010600 // If there is a focused app, don't allow focus to go to any
10601 // windows below it. If this is an application window, step
10602 // through the app tokens until we find its app.
10603 if (thisApp != null && nextApp != null && thisApp != nextApp
10604 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10605 int origAppIndex = nextAppIndex;
10606 while (nextAppIndex > 0) {
10607 if (nextApp == mFocusedApp) {
10608 // Whoops, we are below the focused app... no focus
10609 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010610 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 TAG, "Reached focused app: " + mFocusedApp);
10612 return null;
10613 }
10614 nextAppIndex--;
10615 nextApp = mAppTokens.get(nextAppIndex);
10616 if (nextApp == thisApp) {
10617 break;
10618 }
10619 }
10620 if (thisApp != nextApp) {
10621 // Uh oh, the app token doesn't exist! This shouldn't
10622 // happen, but if it does we can get totally hosed...
10623 // so restart at the original app.
10624 nextAppIndex = origAppIndex;
10625 nextApp = mAppTokens.get(nextAppIndex);
10626 }
10627 }
10628
10629 // Dispatch to this window if it is wants key events.
10630 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010631 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 TAG, "Found focus @ " + i + " = " + win);
10633 result = win;
10634 break;
10635 }
10636
10637 i--;
10638 }
10639
10640 return result;
10641 }
10642
10643 private void startFreezingDisplayLocked() {
10644 if (mDisplayFrozen) {
10645 return;
10646 }
Romain Guy06882f82009-06-10 13:36:04 -070010647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010648 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010650 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010651 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010652 if (mFreezeGcPending != 0) {
10653 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010654 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 mH.removeMessages(H.FORCE_GC);
10656 Runtime.getRuntime().gc();
10657 mFreezeGcPending = now;
10658 }
10659 } else {
10660 mFreezeGcPending = now;
10661 }
Romain Guy06882f82009-06-10 13:36:04 -070010662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010663 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010664
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010665 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010666
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010667 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10668 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010669 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010670 mAppTransitionReady = true;
10671 }
Romain Guy06882f82009-06-10 13:36:04 -070010672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010673 if (PROFILE_ORIENTATION) {
10674 File file = new File("/data/system/frozen");
10675 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10676 }
10677 Surface.freezeDisplay(0);
10678 }
Romain Guy06882f82009-06-10 13:36:04 -070010679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010680 private void stopFreezingDisplayLocked() {
10681 if (!mDisplayFrozen) {
10682 return;
10683 }
Romain Guy06882f82009-06-10 13:36:04 -070010684
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010685 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10686 return;
10687 }
10688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010689 mDisplayFrozen = false;
10690 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10691 if (PROFILE_ORIENTATION) {
10692 Debug.stopMethodTracing();
10693 }
10694 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010695
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010696 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010697
Christopher Tateb696aee2010-04-02 19:08:30 -070010698 // While the display is frozen we don't re-compute the orientation
10699 // to avoid inconsistent states. However, something interesting
10700 // could have actually changed during that time so re-evaluate it
10701 // now to catch that.
10702 if (updateOrientationFromAppTokensLocked()) {
10703 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10704 }
10705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010706 // A little kludge: a lot could have happened while the
10707 // display was frozen, so now that we are coming back we
10708 // do a gc so that any remote references the system
10709 // processes holds on others can be released if they are
10710 // no longer needed.
10711 mH.removeMessages(H.FORCE_GC);
10712 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10713 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010715 mScreenFrozenLock.release();
10716 }
Romain Guy06882f82009-06-10 13:36:04 -070010717
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010718 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10719 DisplayMetrics dm) {
10720 if (index < tokens.length) {
10721 String str = tokens[index];
10722 if (str != null && str.length() > 0) {
10723 try {
10724 int val = Integer.parseInt(str);
10725 return val;
10726 } catch (Exception e) {
10727 }
10728 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010729 }
10730 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10731 return defDps;
10732 }
10733 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10734 return val;
10735 }
10736
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010737 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010738 final String[] mTokens;
10739 final String mText;
10740 final Paint mTextPaint;
10741 final int mTextWidth;
10742 final int mTextHeight;
10743 final int mTextAscent;
10744 final int mTextDescent;
10745 final int mDeltaX;
10746 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010747
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010748 Surface mSurface;
10749 int mLastDW;
10750 int mLastDH;
10751 boolean mDrawNeeded;
10752
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010753 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010754 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010755 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010756
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010757 if (false) {
10758 Log.i(TAG, "*********************** WATERMARK");
10759 for (int i=0; i<tokens.length; i++) {
10760 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10761 }
10762 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010763
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010764 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010765
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010766 StringBuilder builder = new StringBuilder(32);
10767 int len = mTokens[0].length();
10768 len = len & ~1;
10769 for (int i=0; i<len; i+=2) {
10770 int c1 = mTokens[0].charAt(i);
10771 int c2 = mTokens[0].charAt(i+1);
10772 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10773 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10774 else c1 -= '0';
10775 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10776 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10777 else c2 -= '0';
10778 builder.append((char)(255-((c1*16)+c2)));
10779 }
10780 mText = builder.toString();
10781 if (false) {
10782 Log.i(TAG, "Final text: " + mText);
10783 }
10784
10785 int fontSize = getPropertyInt(tokens, 1,
10786 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10787
10788 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10789 mTextPaint.setTextSize(fontSize);
10790 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10791
10792 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10793 mTextWidth = (int)mTextPaint.measureText(mText);
10794 mTextAscent = fm.ascent;
10795 mTextDescent = fm.descent;
10796 mTextHeight = fm.descent - fm.ascent;
10797
10798 mDeltaX = getPropertyInt(tokens, 2,
10799 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10800 mDeltaY = getPropertyInt(tokens, 3,
10801 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10802 int shadowColor = getPropertyInt(tokens, 4,
10803 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10804 int color = getPropertyInt(tokens, 5,
10805 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10806 int shadowRadius = getPropertyInt(tokens, 6,
10807 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10808 int shadowDx = getPropertyInt(tokens, 8,
10809 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10810 int shadowDy = getPropertyInt(tokens, 9,
10811 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10812
10813 mTextPaint.setColor(color);
10814 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010815
10816 try {
10817 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010818 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010819 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010820 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010821 mSurface.show();
10822 } catch (OutOfResourcesException e) {
10823 }
10824 }
10825
10826 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010827 if (mLastDW != dw || mLastDH != dh) {
10828 mLastDW = dw;
10829 mLastDH = dh;
10830 mSurface.setSize(dw, dh);
10831 mDrawNeeded = true;
10832 }
10833 }
10834
10835 void drawIfNeeded() {
10836 if (mDrawNeeded) {
10837 final int dw = mLastDW;
10838 final int dh = mLastDH;
10839
10840 mDrawNeeded = false;
10841 Rect dirty = new Rect(0, 0, dw, dh);
10842 Canvas c = null;
10843 try {
10844 c = mSurface.lockCanvas(dirty);
10845 } catch (IllegalArgumentException e) {
10846 } catch (OutOfResourcesException e) {
10847 }
10848 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010849 c.drawColor(0, PorterDuff.Mode.CLEAR);
10850
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010851 int deltaX = mDeltaX;
10852 int deltaY = mDeltaY;
10853
10854 // deltaX shouldn't be close to a round fraction of our
10855 // x step, or else things will line up too much.
10856 int div = (dw+mTextWidth)/deltaX;
10857 int rem = (dw+mTextWidth) - (div*deltaX);
10858 int qdelta = deltaX/4;
10859 if (rem < qdelta || rem > (deltaX-qdelta)) {
10860 deltaX += deltaX/3;
10861 }
10862
10863 int y = -mTextHeight;
10864 int x = -mTextWidth;
10865 while (y < (dh+mTextHeight)) {
10866 c.drawText(mText, x, y, mTextPaint);
10867 x += deltaX;
10868 if (x >= dw) {
10869 x -= (dw+mTextWidth);
10870 y += deltaY;
10871 }
10872 }
10873 mSurface.unlockCanvasAndPost(c);
10874 }
10875 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010876 }
10877 }
10878
10879 void createWatermark() {
10880 if (mWatermark != null) {
10881 return;
10882 }
10883
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010884 File file = new File("/system/etc/setup.conf");
10885 FileInputStream in = null;
10886 try {
10887 in = new FileInputStream(file);
10888 DataInputStream ind = new DataInputStream(in);
10889 String line = ind.readLine();
10890 if (line != null) {
10891 String[] toks = line.split("%");
10892 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010893 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010894 }
10895 }
10896 } catch (FileNotFoundException e) {
10897 } catch (IOException e) {
10898 } finally {
10899 if (in != null) {
10900 try {
10901 in.close();
10902 } catch (IOException e) {
10903 }
10904 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010905 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010906 }
10907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010908 @Override
10909 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10910 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10911 != PackageManager.PERMISSION_GRANTED) {
10912 pw.println("Permission Denial: can't dump WindowManager from from pid="
10913 + Binder.getCallingPid()
10914 + ", uid=" + Binder.getCallingUid());
10915 return;
10916 }
Romain Guy06882f82009-06-10 13:36:04 -070010917
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010918 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010919 pw.println(" ");
10920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010921 synchronized(mWindowMap) {
10922 pw.println("Current Window Manager state:");
10923 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010924 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010925 pw.print(" Window #"); pw.print(i); pw.print(' ');
10926 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010927 w.dump(pw, " ");
10928 }
10929 if (mInputMethodDialogs.size() > 0) {
10930 pw.println(" ");
10931 pw.println(" Input method dialogs:");
10932 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10933 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010934 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010935 }
10936 }
10937 if (mPendingRemove.size() > 0) {
10938 pw.println(" ");
10939 pw.println(" Remove pending for:");
10940 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10941 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010942 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10943 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010944 w.dump(pw, " ");
10945 }
10946 }
10947 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10948 pw.println(" ");
10949 pw.println(" Windows force removing:");
10950 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10951 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010952 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10953 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010954 w.dump(pw, " ");
10955 }
10956 }
10957 if (mDestroySurface.size() > 0) {
10958 pw.println(" ");
10959 pw.println(" Windows waiting to destroy their surface:");
10960 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10961 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010962 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10963 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010964 w.dump(pw, " ");
10965 }
10966 }
10967 if (mLosingFocus.size() > 0) {
10968 pw.println(" ");
10969 pw.println(" Windows losing focus:");
10970 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10971 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010972 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10973 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010974 w.dump(pw, " ");
10975 }
10976 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010977 if (mResizingWindows.size() > 0) {
10978 pw.println(" ");
10979 pw.println(" Windows waiting to resize:");
10980 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10981 WindowState w = mResizingWindows.get(i);
10982 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10983 pw.print(w); pw.println(":");
10984 w.dump(pw, " ");
10985 }
10986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 if (mSessions.size() > 0) {
10988 pw.println(" ");
10989 pw.println(" All active sessions:");
10990 Iterator<Session> it = mSessions.iterator();
10991 while (it.hasNext()) {
10992 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010993 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010994 s.dump(pw, " ");
10995 }
10996 }
10997 if (mTokenMap.size() > 0) {
10998 pw.println(" ");
10999 pw.println(" All tokens:");
11000 Iterator<WindowToken> it = mTokenMap.values().iterator();
11001 while (it.hasNext()) {
11002 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011003 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011004 token.dump(pw, " ");
11005 }
11006 }
11007 if (mTokenList.size() > 0) {
11008 pw.println(" ");
11009 pw.println(" Window token list:");
11010 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011011 pw.print(" #"); pw.print(i); pw.print(": ");
11012 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011013 }
11014 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011015 if (mWallpaperTokens.size() > 0) {
11016 pw.println(" ");
11017 pw.println(" Wallpaper tokens:");
11018 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11019 WindowToken token = mWallpaperTokens.get(i);
11020 pw.print(" Wallpaper #"); pw.print(i);
11021 pw.print(' '); pw.print(token); pw.println(':');
11022 token.dump(pw, " ");
11023 }
11024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011025 if (mAppTokens.size() > 0) {
11026 pw.println(" ");
11027 pw.println(" Application tokens in Z order:");
11028 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011029 pw.print(" App #"); pw.print(i); pw.print(": ");
11030 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011031 }
11032 }
11033 if (mFinishedStarting.size() > 0) {
11034 pw.println(" ");
11035 pw.println(" Finishing start of application tokens:");
11036 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11037 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011038 pw.print(" Finished Starting #"); pw.print(i);
11039 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011040 token.dump(pw, " ");
11041 }
11042 }
11043 if (mExitingTokens.size() > 0) {
11044 pw.println(" ");
11045 pw.println(" Exiting tokens:");
11046 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11047 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011048 pw.print(" Exiting #"); pw.print(i);
11049 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011050 token.dump(pw, " ");
11051 }
11052 }
11053 if (mExitingAppTokens.size() > 0) {
11054 pw.println(" ");
11055 pw.println(" Exiting application tokens:");
11056 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11057 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011058 pw.print(" Exiting App #"); pw.print(i);
11059 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011060 token.dump(pw, " ");
11061 }
11062 }
11063 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011064 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11065 pw.print(" mLastFocus="); pw.println(mLastFocus);
11066 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11067 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11068 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011069 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011070 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11071 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11072 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11073 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011074 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11075 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11076 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011077 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11078 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11079 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11080 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011081 if (mDimAnimator != null) {
11082 mDimAnimator.printTo(pw);
11083 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011084 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011085 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011086 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011087 pw.print(mInputMethodAnimLayerAdjustment);
11088 pw.print(" mWallpaperAnimLayerAdjustment=");
11089 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011090 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11091 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011092 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11093 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011094 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11095 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011096 pw.print(" mRotation="); pw.print(mRotation);
11097 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11098 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11099 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11100 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11101 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11102 pw.print(" mNextAppTransition=0x");
11103 pw.print(Integer.toHexString(mNextAppTransition));
11104 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011105 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011106 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011107 if (mNextAppTransitionPackage != null) {
11108 pw.print(" mNextAppTransitionPackage=");
11109 pw.print(mNextAppTransitionPackage);
11110 pw.print(", mNextAppTransitionEnter=0x");
11111 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11112 pw.print(", mNextAppTransitionExit=0x");
11113 pw.print(Integer.toHexString(mNextAppTransitionExit));
11114 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011115 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11116 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011117 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11118 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11119 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11120 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011121 if (mOpeningApps.size() > 0) {
11122 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11123 }
11124 if (mClosingApps.size() > 0) {
11125 pw.print(" mClosingApps="); pw.println(mClosingApps);
11126 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011127 if (mToTopApps.size() > 0) {
11128 pw.print(" mToTopApps="); pw.println(mToTopApps);
11129 }
11130 if (mToBottomApps.size() > 0) {
11131 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11132 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011133 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11134 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011135 }
11136 }
11137
Jeff Brown349703e2010-06-22 01:27:15 -070011138 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011139 public void monitor() {
11140 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011141 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011142 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011143
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011144 /**
11145 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011146 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011147 */
11148 private static class DimAnimator {
11149 Surface mDimSurface;
11150 boolean mDimShown = false;
11151 float mDimCurrentAlpha;
11152 float mDimTargetAlpha;
11153 float mDimDeltaPerMs;
11154 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011155
11156 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011157
11158 DimAnimator (SurfaceSession session) {
11159 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011160 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011161 + mDimSurface + ": CREATE");
11162 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011163 mDimSurface = new Surface(session, 0,
11164 "DimSurface",
11165 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011166 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011167 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011168 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011169 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011170 }
11171 }
11172 }
11173
11174 /**
11175 * Show the dim surface.
11176 */
11177 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011178 if (!mDimShown) {
11179 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11180 dw + "x" + dh + ")");
11181 mDimShown = true;
11182 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011183 mLastDimWidth = dw;
11184 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011185 mDimSurface.setPosition(0, 0);
11186 mDimSurface.setSize(dw, dh);
11187 mDimSurface.show();
11188 } catch (RuntimeException e) {
11189 Slog.w(TAG, "Failure showing dim surface", e);
11190 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011191 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11192 mLastDimWidth = dw;
11193 mLastDimHeight = dh;
11194 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011195 }
11196 }
11197
11198 /**
11199 * Set's the dim surface's layer and update dim parameters that will be used in
11200 * {@link updateSurface} after all windows are examined.
11201 */
11202 void updateParameters(WindowState w, long currentTime) {
11203 mDimSurface.setLayer(w.mAnimLayer-1);
11204
11205 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011206 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011207 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011208 if (mDimTargetAlpha != target) {
11209 // If the desired dim level has changed, then
11210 // start an animation to it.
11211 mLastDimAnimTime = currentTime;
11212 long duration = (w.mAnimating && w.mAnimation != null)
11213 ? w.mAnimation.computeDurationHint()
11214 : DEFAULT_DIM_DURATION;
11215 if (target > mDimTargetAlpha) {
11216 // This is happening behind the activity UI,
11217 // so we can make it run a little longer to
11218 // give a stronger impression without disrupting
11219 // the user.
11220 duration *= DIM_DURATION_MULTIPLIER;
11221 }
11222 if (duration < 1) {
11223 // Don't divide by zero
11224 duration = 1;
11225 }
11226 mDimTargetAlpha = target;
11227 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11228 }
11229 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011230
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011231 /**
11232 * Updating the surface's alpha. Returns true if the animation continues, or returns
11233 * false when the animation is finished and the dim surface is hidden.
11234 */
11235 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11236 if (!dimming) {
11237 if (mDimTargetAlpha != 0) {
11238 mLastDimAnimTime = currentTime;
11239 mDimTargetAlpha = 0;
11240 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11241 }
11242 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011243
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011244 boolean animating = false;
11245 if (mLastDimAnimTime != 0) {
11246 mDimCurrentAlpha += mDimDeltaPerMs
11247 * (currentTime-mLastDimAnimTime);
11248 boolean more = true;
11249 if (displayFrozen) {
11250 // If the display is frozen, there is no reason to animate.
11251 more = false;
11252 } else if (mDimDeltaPerMs > 0) {
11253 if (mDimCurrentAlpha > mDimTargetAlpha) {
11254 more = false;
11255 }
11256 } else if (mDimDeltaPerMs < 0) {
11257 if (mDimCurrentAlpha < mDimTargetAlpha) {
11258 more = false;
11259 }
11260 } else {
11261 more = false;
11262 }
11263
11264 // Do we need to continue animating?
11265 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011266 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011267 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11268 mLastDimAnimTime = currentTime;
11269 mDimSurface.setAlpha(mDimCurrentAlpha);
11270 animating = true;
11271 } else {
11272 mDimCurrentAlpha = mDimTargetAlpha;
11273 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011274 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011275 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11276 mDimSurface.setAlpha(mDimCurrentAlpha);
11277 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011278 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011279 + ": HIDE");
11280 try {
11281 mDimSurface.hide();
11282 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011283 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011284 }
11285 mDimShown = false;
11286 }
11287 }
11288 }
11289 return animating;
11290 }
11291
11292 public void printTo(PrintWriter pw) {
11293 pw.print(" mDimShown="); pw.print(mDimShown);
11294 pw.print(" current="); pw.print(mDimCurrentAlpha);
11295 pw.print(" target="); pw.print(mDimTargetAlpha);
11296 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11297 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11298 }
11299 }
11300
11301 /**
11302 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11303 * This is used for opening/closing transition for apps in compatible mode.
11304 */
11305 private static class FadeInOutAnimation extends Animation {
11306 int mWidth;
11307 boolean mFadeIn;
11308
11309 public FadeInOutAnimation(boolean fadeIn) {
11310 setInterpolator(new AccelerateInterpolator());
11311 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11312 mFadeIn = fadeIn;
11313 }
11314
11315 @Override
11316 protected void applyTransformation(float interpolatedTime, Transformation t) {
11317 float x = interpolatedTime;
11318 if (!mFadeIn) {
11319 x = 1.0f - x; // reverse the interpolation for fade out
11320 }
11321 if (x < 0.5) {
11322 // move the window out of the screen.
11323 t.getMatrix().setTranslate(mWidth, 0);
11324 } else {
11325 t.getMatrix().setTranslate(0, 0);// show
11326 t.setAlpha((x - 0.5f) * 2);
11327 }
11328 }
11329
11330 @Override
11331 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11332 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11333 mWidth = width;
11334 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011335
11336 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011337 public int getZAdjustment() {
11338 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011339 }
11340 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011341}