blob: b2e78f15685b662062f72a244a9496518182860f [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
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080017package com.android.server.wm;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
26import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070027import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
29import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
31import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
32import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
36import com.android.internal.app.IBatteryStats;
37import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080038import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070039import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import com.android.internal.view.IInputContext;
41import com.android.internal.view.IInputMethodClient;
42import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080043import com.android.internal.view.WindowManagerPolicyThread;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080044import com.android.server.AttributeCache;
45import com.android.server.EventLogTags;
46import com.android.server.PowerManagerService;
47import com.android.server.Watchdog;
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;
Joe Onoratoac0ee892011-01-30 15:38:30 -080053import android.app.StatusBarManager;
Jim Millerd6b57052010-06-07 17:52:42 -070054import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070057import android.content.Intent;
58import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.content.pm.ActivityInfo;
60import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070061import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.content.res.Configuration;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080063import android.graphics.Bitmap;
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;
66import android.graphics.PixelFormat;
Dianne Hackborn44bc17c2011-04-20 18:18:51 -070067import android.graphics.Point;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.Rect;
69import android.graphics.Region;
70import android.os.BatteryStats;
71import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070072import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.Debug;
74import android.os.Handler;
75import android.os.IBinder;
76import android.os.LocalPowerManager;
77import android.os.Looper;
78import android.os.Message;
79import android.os.Parcel;
80import android.os.ParcelFileDescriptor;
81import android.os.Power;
82import android.os.PowerManager;
83import android.os.Process;
84import android.os.RemoteException;
85import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070086import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087import android.os.SystemClock;
88import android.os.SystemProperties;
89import android.os.TokenWatcher;
90import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070091import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070093import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080094import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070096import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.view.Display;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700106import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700107import android.view.InputHandler;
108import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109import android.view.KeyEvent;
110import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111import android.view.Surface;
112import android.view.SurfaceSession;
113import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.WindowManager;
115import android.view.WindowManagerImpl;
116import android.view.WindowManagerPolicy;
117import android.view.WindowManager.LayoutParams;
118import android.view.animation.Animation;
119import android.view.animation.AnimationUtils;
120import android.view.animation.Transformation;
121
122import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700123import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import java.io.File;
125import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700126import java.io.FileInputStream;
127import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128import java.io.IOException;
129import java.io.OutputStream;
130import java.io.OutputStreamWriter;
131import java.io.PrintWriter;
132import java.io.StringWriter;
133import java.net.Socket;
134import java.util.ArrayList;
135import java.util.HashMap;
136import java.util.HashSet;
137import java.util.Iterator;
138import java.util.List;
139
140/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700141public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700142 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 static final String TAG = "WindowManager";
144 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800145 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 static final boolean DEBUG_FOCUS = false;
147 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800148 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800149 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final boolean DEBUG_LAYERS = false;
151 static final boolean DEBUG_INPUT = false;
152 static final boolean DEBUG_INPUT_METHOD = false;
153 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700154 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800155 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700157 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 static final boolean DEBUG_APP_TRANSITIONS = false;
159 static final boolean DEBUG_STARTING_WINDOW = false;
160 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700161 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800162 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700164 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 static final boolean PROFILE_ORIENTATION = false;
167 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700168 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 /** How much to multiply the policy's type layer, to reserve room
171 * for multiple windows of the same type and Z-ordering adjustment
172 * with TYPE_LAYER_OFFSET. */
173 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
176 * or below others in the same layer. */
177 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 /** How much to increment the layer for each window, to reserve room
180 * for effect surfaces between them.
181 */
182 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700183
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800184 /**
185 * Dim surface layer is immediately below target window.
186 */
187 static final int LAYER_OFFSET_DIM = 1;
188
189 /**
190 * Blur surface layer is immediately below dim layer.
191 */
192 static final int LAYER_OFFSET_BLUR = 2;
193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 /** The maximum length we will accept for a loaded animation duration:
195 * this is 10 seconds.
196 */
197 static final int MAX_ANIMATION_DURATION = 10*1000;
198
199 /** Amount of time (in milliseconds) to animate the dim surface from one
200 * value to another, when no window animation is driving it.
201 */
202 static final int DEFAULT_DIM_DURATION = 200;
203
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700204 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
205 * compatible windows.
206 */
207 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
208
Dianne Hackborna1111872010-11-23 20:55:11 -0800209 /**
210 * If true, the window manager will do its own custom freezing and general
211 * management of the screen during rotation.
212 */
213 static final boolean CUSTOM_SCREEN_ROTATION = true;
214
Jeff Brown7fbdc842010-06-17 20:52:56 -0700215 // Maximum number of milliseconds to wait for input event injection.
216 // FIXME is this value reasonable?
217 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800218
219 // Maximum number of milliseconds to wait for input devices to be enumerated before
220 // proceding with safe mode detection.
221 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700222
223 // Default input dispatching timeout in nanoseconds.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 static final int UPDATE_FOCUS_NORMAL = 0;
227 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
228 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
229 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700232 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233
234 /**
235 * Condition waited on by {@link #reenableKeyguard} to know the call to
236 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 * This is set to true only if mKeyguardTokenWatcher.acquired() has
238 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500240 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241
Jim Miller284b62e2010-06-08 14:27:42 -0700242 private static final int ALLOW_DISABLE_YES = 1;
243 private static final int ALLOW_DISABLE_NO = 0;
244 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
245 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
246
Mike Lockwood983ee092009-11-22 01:42:24 -0500247 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
248 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700250 if (shouldAllowDisableKeyguard()) {
251 mPolicy.enableKeyguard(false);
252 mKeyguardDisabled = true;
253 } else {
254 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 }
257 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700258 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500259 synchronized (mKeyguardTokenWatcher) {
260 mKeyguardDisabled = false;
261 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 }
263 }
264 };
265
Jim Miller284b62e2010-06-08 14:27:42 -0700266 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
267 @Override
268 public void onReceive(Context context, Intent intent) {
269 mPolicy.enableKeyguard(true);
270 synchronized(mKeyguardTokenWatcher) {
271 // lazily evaluate this next time we're asked to disable keyguard
272 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
273 mKeyguardDisabled = false;
274 }
275 }
276 };
277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 final Context mContext;
279
280 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
285
286 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 /**
291 * All currently active sessions with clients.
292 */
293 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 /**
296 * Mapping from an IWindow IBinder to the server's Window object.
297 * This is also used as the lock for all of our state.
298 */
299 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
300
301 /**
302 * Mapping from a token IBinder to a WindowToken object.
303 */
304 final HashMap<IBinder, WindowToken> mTokenMap =
305 new HashMap<IBinder, WindowToken>();
306
307 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 * Window tokens that are in the process of exiting, but still
309 * on screen for animations.
310 */
311 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
312
313 /**
314 * Z-ordered (bottom-most first) list of all application tokens, for
315 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800316 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 */
318 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
319
320 /**
321 * Application tokens that are in the process of exiting, but still
322 * on screen for animations.
323 */
324 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
325
326 /**
327 * List of window tokens that have finished starting their application,
328 * and now need to have the policy remove their windows.
329 */
330 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
331
332 /**
333 * Z-ordered (bottom-most first) list of all Window objects.
334 */
Jeff Browne33348b2010-07-15 23:54:05 -0700335 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
337 /**
338 * Windows that are being resized. Used so we can tell the client about
339 * the resize after closing the transaction in which we resized the
340 * underlying surface.
341 */
342 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
343
344 /**
345 * Windows whose animations have ended and now must be removed.
346 */
347 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
348
349 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800350 * Used when processing mPendingRemove to avoid working on the original array.
351 */
352 WindowState[] mPendingRemoveTmp = new WindowState[20];
353
354 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 * Windows whose surface should be destroyed.
356 */
357 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
358
359 /**
360 * Windows that have lost input focus and are waiting for the new
361 * focus window to be displayed before they are told about this.
362 */
363 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
364
365 /**
366 * This is set when we have run out of memory, and will either be an empty
367 * list or contain windows that need to be force removed.
368 */
369 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700370
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800371 /**
372 * Used when rebuilding window list to keep track of windows that have
373 * been removed.
374 */
375 WindowState[] mRebuildTmp = new WindowState[20];
376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700380 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 Surface mBlurSurface;
382 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700383 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800384 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800385 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 final float[] mTmpFloats = new float[9];
390
391 boolean mSafeMode;
392 boolean mDisplayEnabled = false;
393 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700394 int mInitialDisplayWidth = 0;
395 int mInitialDisplayHeight = 0;
Dianne Hackborn44bc17c2011-04-20 18:18:51 -0700396 int mCurDisplayWidth = 0;
397 int mCurDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 int mRotation = 0;
399 int mRequestedRotation = 0;
400 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700401 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 ArrayList<IRotationWatcher> mRotationWatchers
403 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800404 int mDeferredRotation;
405 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 boolean mLayoutNeeded = true;
408 boolean mAnimationPending = false;
409 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800410 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 boolean mWindowsFreezingScreen = false;
412 long mFreezeGcPending = 0;
413 int mAppsFreezingScreen = 0;
414
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800415 int mLayoutSeq = 0;
416
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800417 // State while inside of layoutAndPlaceSurfacesLocked().
418 boolean mFocusMayChange;
419
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800420 Configuration mCurConfiguration = new Configuration();
421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // This is held as long as we have the screen frozen, to give us time to
423 // perform a rotation animation when turning off shows the lock screen which
424 // changes the orientation.
425 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 // State management of app transitions. When we are preparing for a
428 // transition, mNextAppTransition will be the kind of transition to
429 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
430 // mOpeningApps and mClosingApps are the lists of tokens that will be
431 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700432 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700433 String mNextAppTransitionPackage;
434 int mNextAppTransitionEnter;
435 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700437 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 boolean mAppTransitionTimeout = false;
439 boolean mStartingIconInTransition = false;
440 boolean mSkipAppTransitionAnimation = false;
441 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
442 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700443 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
444 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 H mH = new H();
449
450 WindowState mCurrentFocus = null;
451 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 // This just indicates the window the input method is on top of, not
454 // necessarily the window its input is going to.
455 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 boolean mInputMethodTargetWaitingAnim;
457 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 WindowState mInputMethodWindow = null;
460 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
461
Jeff Brown2992ea72011-01-28 22:04:14 -0800462 boolean mHardKeyboardAvailable;
463 boolean mHardKeyboardEnabled;
464 OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
465
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700466 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800467
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700468 // If non-null, this is the currently visible window that is associated
469 // with the wallpaper.
470 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700471 // If non-null, we are in the middle of animating from one wallpaper target
472 // to another, and this is the lower one in Z-order.
473 WindowState mLowerWallpaperTarget = null;
474 // If non-null, we are in the middle of animating from one wallpaper target
475 // to another, and this is the higher one in Z-order.
476 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800477 // Window currently running an animation that has requested it be detached
478 // from the wallpaper. This means we need to ensure the wallpaper is
479 // visible behind it in case it animates in a way that would allow it to be
480 // seen.
481 WindowState mWindowDetachedWallpaper = null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800482 DimSurface mWindowAnimationBackgroundSurface = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700483 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700484 float mLastWallpaperX = -1;
485 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800486 float mLastWallpaperXStep = -1;
487 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700488 // This is set when we are waiting for a wallpaper to tell us it is done
489 // changing its scroll position.
490 WindowState mWaitingOnWallpaper;
491 // The last time we had a timeout when waiting for a wallpaper.
492 long mLastWallpaperTimeoutTime;
493 // We give a wallpaper up to 150ms to finish scrolling.
494 static final long WALLPAPER_TIMEOUT = 150;
495 // Time we wait after a timeout before trying to wait again.
496 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 AppWindowToken mFocusedApp = null;
499
500 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 float mWindowAnimationScale = 1.0f;
503 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700504
Jeff Brown46b9ac02010-04-22 18:58:52 -0700505 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506
507 // Who is holding the screen on.
508 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700509 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700510
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700511 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800512
Christopher Tatea53146c2010-09-07 11:57:52 -0700513 DragState mDragState = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800514 final InputHandler mDragInputHandler = new BaseInputHandler() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700516 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
517 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700518 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700519 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
520 && mDragState != null) {
521 boolean endDrag = false;
522 final float newX = event.getRawX();
523 final float newY = event.getRawY();
524
Christopher Tatea53146c2010-09-07 11:57:52 -0700525 switch (event.getAction()) {
526 case MotionEvent.ACTION_DOWN: {
527 if (DEBUG_DRAG) {
528 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
529 }
530 } break;
531
532 case MotionEvent.ACTION_MOVE: {
533 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700534 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700535 mDragState.notifyMoveLw(newX, newY);
536 }
537 } break;
538
539 case MotionEvent.ACTION_UP: {
540 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
541 + newX + "," + newY);
542 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700543 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700544 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700545 } break;
546
547 case MotionEvent.ACTION_CANCEL: {
548 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
549 endDrag = true;
550 } break;
551 }
552
553 if (endDrag) {
554 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
555 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700556 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700557 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700558 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700559 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700560
561 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700562 }
563 } catch (Exception e) {
564 Slog.e(TAG, "Exception caught by drag handleMotion", e);
565 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700566 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 }
568 }
569 };
570
571 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 * Whether the UI is currently running in touch mode (not showing
573 * navigational focus because the user is directly pressing the screen).
574 */
575 boolean mInTouchMode = false;
576
577 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700578 private ArrayList<WindowChangeListener> mWindowChangeListeners =
579 new ArrayList<WindowChangeListener>();
580 private boolean mWindowsChanged = false;
581
582 public interface WindowChangeListener {
583 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700584 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586
Dianne Hackbornc485a602009-03-24 22:39:49 -0700587 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700588 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700589
590 // The frame use to limit the size of the app running in compatibility mode.
591 Rect mCompatibleScreenFrame = new Rect();
592 // The surface used to fill the outer rim of the app running in compatibility mode.
593 Surface mBackgroundFillerSurface = null;
Dianne Hackbornac1471a2011-02-03 13:46:06 -0800594 WindowState mBackgroundFillerTarget = null;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 public static WindowManagerService main(Context context,
597 PowerManagerService pm, boolean haveInputMethods) {
598 WMThread thr = new WMThread(context, pm, haveInputMethods);
599 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 synchronized (thr) {
602 while (thr.mService == null) {
603 try {
604 thr.wait();
605 } catch (InterruptedException e) {
606 }
607 }
Jozef BABJAK06e57b52011-01-20 08:09:25 +0100608 return thr.mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 }
Romain Guy06882f82009-06-10 13:36:04 -0700611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 static class WMThread extends Thread {
613 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 private final Context mContext;
616 private final PowerManagerService mPM;
617 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 public WMThread(Context context, PowerManagerService pm,
620 boolean haveInputMethods) {
621 super("WindowManager");
622 mContext = context;
623 mPM = pm;
624 mHaveInputMethods = haveInputMethods;
625 }
Romain Guy06882f82009-06-10 13:36:04 -0700626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 public void run() {
628 Looper.prepare();
629 WindowManagerService s = new WindowManagerService(mContext, mPM,
630 mHaveInputMethods);
631 android.os.Process.setThreadPriority(
632 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700633 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 synchronized (this) {
636 mService = s;
637 notifyAll();
638 }
Romain Guy06882f82009-06-10 13:36:04 -0700639
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700640 // For debug builds, log event loop stalls to dropbox for analysis.
641 if (StrictMode.conditionallyEnableDebugLogging()) {
642 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
643 }
644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 Looper.loop();
646 }
647 }
648
649 static class PolicyThread extends Thread {
650 private final WindowManagerPolicy mPolicy;
651 private final WindowManagerService mService;
652 private final Context mContext;
653 private final PowerManagerService mPM;
654 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 public PolicyThread(WindowManagerPolicy policy,
657 WindowManagerService service, Context context,
658 PowerManagerService pm) {
659 super("WindowManagerPolicy");
660 mPolicy = policy;
661 mService = service;
662 mContext = context;
663 mPM = pm;
664 }
Romain Guy06882f82009-06-10 13:36:04 -0700665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 public void run() {
667 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800668 WindowManagerPolicyThread.set(this, Looper.myLooper());
669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800671 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 android.os.Process.setThreadPriority(
673 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700674 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 synchronized (this) {
678 mRunning = true;
679 notifyAll();
680 }
Romain Guy06882f82009-06-10 13:36:04 -0700681
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700682 // For debug builds, log event loop stalls to dropbox for analysis.
683 if (StrictMode.conditionallyEnableDebugLogging()) {
684 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
685 }
686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 Looper.loop();
688 }
689 }
690
691 private WindowManagerService(Context context, PowerManagerService pm,
692 boolean haveInputMethods) {
693 mContext = context;
694 mHaveInputMethods = haveInputMethods;
695 mLimitedAlphaCompositing = context.getResources().getBoolean(
696 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 mPowerManager = pm;
699 mPowerManager.setPolicy(mPolicy);
700 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
701 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
702 "SCREEN_FROZEN");
703 mScreenFrozenLock.setReferenceCounted(false);
704
705 mActivityManager = ActivityManagerNative.getDefault();
706 mBatteryStats = BatteryStatsService.getService();
707
708 // Get persisted window scale setting
709 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
710 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
711 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
712 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700713
Jim Miller284b62e2010-06-08 14:27:42 -0700714 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
715 IntentFilter filter = new IntentFilter();
716 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
717 mContext.registerReceiver(mBroadcastReceiver, filter);
718
Jeff Brown46b9ac02010-04-22 18:58:52 -0700719 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
720 "KEEP_SCREEN_ON_FLAG");
721 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722
Jeff Browne33348b2010-07-15 23:54:05 -0700723 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
726 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 synchronized (thr) {
729 while (!thr.mRunning) {
730 try {
731 thr.wait();
732 } catch (InterruptedException e) {
733 }
734 }
735 }
Romain Guy06882f82009-06-10 13:36:04 -0700736
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700737 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 // Add ourself to the Watchdog monitors.
740 Watchdog.getInstance().addMonitor(this);
741 }
742
743 @Override
744 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
745 throws RemoteException {
746 try {
747 return super.onTransact(code, data, reply, flags);
748 } catch (RuntimeException e) {
749 // The window manager only throws security exceptions, so let's
750 // log all others.
751 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800752 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 }
754 throw e;
755 }
756 }
757
Jeff Browne33348b2010-07-15 23:54:05 -0700758 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800760 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 TAG, "Adding window " + window + " at "
762 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
763 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700764 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 }
766
Jeff Browne33348b2010-07-15 23:54:05 -0700767 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800769 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 TAG, "Adding window " + window + " at "
771 + i + " of " + mWindows.size() + " (before " + pos + ")");
772 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700773 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 }
775
776 //This method finds out the index of a window that has the same app token as
777 //win. used for z ordering the windows in mWindows
778 private int findIdxBasedOnAppTokens(WindowState win) {
779 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700780 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 int jmax = localmWindows.size();
782 if(jmax == 0) {
783 return -1;
784 }
785 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700786 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 if(wentry.mAppToken == win.mAppToken) {
788 return j;
789 }
790 }
791 return -1;
792 }
Romain Guy06882f82009-06-10 13:36:04 -0700793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
795 final IWindow client = win.mClient;
796 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700797 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 final int N = localmWindows.size();
800 final WindowState attached = win.mAttachedWindow;
801 int i;
802 if (attached == null) {
803 int tokenWindowsPos = token.windows.size();
804 if (token.appWindowToken != null) {
805 int index = tokenWindowsPos-1;
806 if (index >= 0) {
807 // If this application has existing windows, we
808 // simply place the new window on top of them... but
809 // keep the starting window on top.
810 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
811 // Base windows go behind everything else.
812 placeWindowBefore(token.windows.get(0), win);
813 tokenWindowsPos = 0;
814 } else {
815 AppWindowToken atoken = win.mAppToken;
816 if (atoken != null &&
817 token.windows.get(index) == atoken.startingWindow) {
818 placeWindowBefore(token.windows.get(index), win);
819 tokenWindowsPos--;
820 } else {
821 int newIdx = findIdxBasedOnAppTokens(win);
822 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700823 //there is a window above this one associated with the same
824 //apptoken note that the window could be a floating window
825 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800827 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
828 Slog.v(TAG, "Adding window " + win + " at "
829 + (newIdx+1) + " of " + N);
830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700832 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 }
835 }
836 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800837 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 TAG, "Figuring out where to add app window "
839 + client.asBinder() + " (token=" + token + ")");
840 // Figure out where the window should go, based on the
841 // order of applications.
842 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700843 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 for (i=NA-1; i>=0; i--) {
845 AppWindowToken t = mAppTokens.get(i);
846 if (t == token) {
847 i--;
848 break;
849 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800850
Dianne Hackborna8f60182009-09-01 19:01:50 -0700851 // We haven't reached the token yet; if this token
852 // is not going to the bottom and has windows, we can
853 // use it as an anchor for when we do reach the token.
854 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 pos = t.windows.get(0);
856 }
857 }
858 // We now know the index into the apps. If we found
859 // an app window above, that gives us the position; else
860 // we need to look some more.
861 if (pos != null) {
862 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700863 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 if (atoken != null) {
865 final int NC = atoken.windows.size();
866 if (NC > 0) {
867 WindowState bottom = atoken.windows.get(0);
868 if (bottom.mSubLayer < 0) {
869 pos = bottom;
870 }
871 }
872 }
873 placeWindowBefore(pos, win);
874 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700875 // Continue looking down until we find the first
876 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 while (i >= 0) {
878 AppWindowToken t = mAppTokens.get(i);
879 final int NW = t.windows.size();
880 if (NW > 0) {
881 pos = t.windows.get(NW-1);
882 break;
883 }
884 i--;
885 }
886 if (pos != null) {
887 // Move in front of any windows attached to this
888 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700889 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 if (atoken != null) {
891 final int NC = atoken.windows.size();
892 if (NC > 0) {
893 WindowState top = atoken.windows.get(NC-1);
894 if (top.mSubLayer >= 0) {
895 pos = top;
896 }
897 }
898 }
899 placeWindowAfter(pos, win);
900 } else {
901 // Just search for the start of this layer.
902 final int myLayer = win.mBaseLayer;
903 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700904 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 if (w.mBaseLayer > myLayer) {
906 break;
907 }
908 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800909 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
910 Slog.v(TAG, "Adding window " + win + " at "
911 + i + " of " + N);
912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700914 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 }
916 }
917 }
918 } else {
919 // Figure out where window should go, based on layer.
920 final int myLayer = win.mBaseLayer;
921 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700922 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 i++;
924 break;
925 }
926 }
927 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800928 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700929 TAG, "Adding window " + win + " at "
930 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700932 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 }
934 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800935 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 token.windows.add(tokenWindowsPos, win);
937 }
938
939 } else {
940 // Figure out this window's ordering relative to the window
941 // it is attached to.
942 final int NA = token.windows.size();
943 final int sublayer = win.mSubLayer;
944 int largestSublayer = Integer.MIN_VALUE;
945 WindowState windowWithLargestSublayer = null;
946 for (i=0; i<NA; i++) {
947 WindowState w = token.windows.get(i);
948 final int wSublayer = w.mSubLayer;
949 if (wSublayer >= largestSublayer) {
950 largestSublayer = wSublayer;
951 windowWithLargestSublayer = w;
952 }
953 if (sublayer < 0) {
954 // For negative sublayers, we go below all windows
955 // in the same sublayer.
956 if (wSublayer >= sublayer) {
957 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800958 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 token.windows.add(i, win);
960 }
961 placeWindowBefore(
962 wSublayer >= 0 ? attached : w, win);
963 break;
964 }
965 } else {
966 // For positive sublayers, we go above all windows
967 // in the same sublayer.
968 if (wSublayer > sublayer) {
969 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800970 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 token.windows.add(i, win);
972 }
973 placeWindowBefore(w, win);
974 break;
975 }
976 }
977 }
978 if (i >= NA) {
979 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800980 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 token.windows.add(win);
982 }
983 if (sublayer < 0) {
984 placeWindowBefore(attached, win);
985 } else {
986 placeWindowAfter(largestSublayer >= 0
987 ? windowWithLargestSublayer
988 : attached,
989 win);
990 }
991 }
992 }
Romain Guy06882f82009-06-10 13:36:04 -0700993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 if (win.mAppToken != null && addToToken) {
995 win.mAppToken.allAppWindows.add(win);
996 }
997 }
Romain Guy06882f82009-06-10 13:36:04 -0700998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 static boolean canBeImeTarget(WindowState w) {
1000 final int fl = w.mAttrs.flags
1001 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001002 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
1003 || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
1004 if (DEBUG_INPUT_METHOD) {
1005 Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1006 if (!w.isVisibleOrAdding()) {
1007 Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface
1008 + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
1009 + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
1010 + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
1011 if (w.mAppToken != null) {
1012 Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1013 }
1014 }
1015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 return w.isVisibleOrAdding();
1017 }
1018 return false;
1019 }
Romain Guy06882f82009-06-10 13:36:04 -07001020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001022 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 final int N = localmWindows.size();
1024 WindowState w = null;
1025 int i = N;
1026 while (i > 0) {
1027 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001028 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001029
Dianne Hackborne75d8722011-01-27 19:37:40 -08001030 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
1031 + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001033 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 // Yet more tricksyness! If this window is a "starting"
1036 // window, we do actually want to be on top of it, but
1037 // it is not -really- where input will go. So if the caller
1038 // is not actually looking to move the IME, look down below
1039 // for a real window to target...
1040 if (!willMove
1041 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1042 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001043 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1045 i--;
1046 w = wb;
1047 }
1048 }
1049 break;
1050 }
1051 }
Romain Guy06882f82009-06-10 13:36:04 -07001052
Dianne Hackborne75d8722011-01-27 19:37:40 -08001053 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
1054
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001055 // Now, a special case -- if the last target's window is in the
1056 // process of exiting, and is above the new target, keep on the
1057 // last target to avoid flicker. Consider for example a Dialog with
1058 // the IME shown: when the Dialog is dismissed, we want to keep
1059 // the IME above it until it is completely gone so it doesn't drop
1060 // behind the dialog or its full-screen scrim.
1061 if (mInputMethodTarget != null && w != null
1062 && mInputMethodTarget.isDisplayedLw()
1063 && mInputMethodTarget.mExiting) {
1064 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1065 w = mInputMethodTarget;
1066 i = localmWindows.indexOf(w);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001067 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w);
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001068 }
1069 }
Romain Guy06882f82009-06-10 13:36:04 -07001070
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 if (willMove && w != null) {
1075 final WindowState curTarget = mInputMethodTarget;
1076 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 // Now some fun for dealing with window animations that
1079 // modify the Z order. We need to look at all windows below
1080 // the current target that are in this app, finding the highest
1081 // visible one in layering.
1082 AppWindowToken token = curTarget.mAppToken;
1083 WindowState highestTarget = null;
1084 int highestPos = 0;
1085 if (token.animating || token.animation != null) {
1086 int pos = 0;
1087 pos = localmWindows.indexOf(curTarget);
1088 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001089 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 if (win.mAppToken != token) {
1091 break;
1092 }
1093 if (!win.mRemoved) {
1094 if (highestTarget == null || win.mAnimLayer >
1095 highestTarget.mAnimLayer) {
1096 highestTarget = win;
1097 highestPos = pos;
1098 }
1099 }
1100 pos--;
1101 }
1102 }
Romain Guy06882f82009-06-10 13:36:04 -07001103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001105 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 + mNextAppTransition + " " + highestTarget
1107 + " animating=" + highestTarget.isAnimating()
1108 + " layer=" + highestTarget.mAnimLayer
1109 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001110
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001111 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 // If we are currently setting up for an animation,
1113 // hold everything until we can find out what will happen.
1114 mInputMethodTargetWaitingAnim = true;
1115 mInputMethodTarget = highestTarget;
1116 return highestPos + 1;
1117 } else if (highestTarget.isAnimating() &&
1118 highestTarget.mAnimLayer > w.mAnimLayer) {
1119 // If the window we are currently targeting is involved
1120 // with an animation, and it is on top of the next target
1121 // we will be over, then hold off on moving until
1122 // that is done.
Dianne Hackborne75d8722011-01-27 19:37:40 -08001123 mInputMethodTargetWaitingAnim = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 mInputMethodTarget = highestTarget;
1125 return highestPos + 1;
1126 }
1127 }
1128 }
1129 }
Romain Guy06882f82009-06-10 13:36:04 -07001130
Joe Onorato8a9b2202010-02-26 18:56:32 -08001131 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 if (w != null) {
1133 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001134 if (DEBUG_INPUT_METHOD) {
1135 RuntimeException e = null;
1136 if (!HIDE_STACK_CRAWLS) {
1137 e = new RuntimeException();
1138 e.fillInStackTrace();
1139 }
1140 Slog.w(TAG, "Moving IM target from "
1141 + mInputMethodTarget + " to " + w, e);
1142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 mInputMethodTarget = w;
Dianne Hackborne75d8722011-01-27 19:37:40 -08001144 mInputMethodTargetWaitingAnim = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 if (w.mAppToken != null) {
1146 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1147 } else {
1148 setInputMethodAnimLayerAdjustment(0);
1149 }
1150 }
1151 return i+1;
1152 }
1153 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001154 if (DEBUG_INPUT_METHOD) {
1155 RuntimeException e = null;
1156 if (!HIDE_STACK_CRAWLS) {
1157 e = new RuntimeException();
1158 e.fillInStackTrace();
1159 }
1160 Slog.w(TAG, "Moving IM target from "
1161 + mInputMethodTarget + " to null", e);
1162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 mInputMethodTarget = null;
1164 setInputMethodAnimLayerAdjustment(0);
1165 }
1166 return -1;
1167 }
Romain Guy06882f82009-06-10 13:36:04 -07001168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 void addInputMethodWindowToListLocked(WindowState win) {
1170 int pos = findDesiredInputMethodWindowIndexLocked(true);
1171 if (pos >= 0) {
1172 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001173 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001174 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001176 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 moveInputMethodDialogsLocked(pos+1);
1178 return;
1179 }
1180 win.mTargetAppToken = null;
1181 addWindowToListInOrderLocked(win, true);
1182 moveInputMethodDialogsLocked(pos);
1183 }
Romain Guy06882f82009-06-10 13:36:04 -07001184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001186 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 mInputMethodAnimLayerAdjustment = adj;
1188 WindowState imw = mInputMethodWindow;
1189 if (imw != null) {
1190 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001191 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 + " anim layer: " + imw.mAnimLayer);
1193 int wi = imw.mChildWindows.size();
1194 while (wi > 0) {
1195 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001196 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001198 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 + " anim layer: " + cw.mAnimLayer);
1200 }
1201 }
1202 int di = mInputMethodDialogs.size();
1203 while (di > 0) {
1204 di --;
1205 imw = mInputMethodDialogs.get(di);
1206 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001207 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 + " anim layer: " + imw.mAnimLayer);
1209 }
1210 }
Romain Guy06882f82009-06-10 13:36:04 -07001211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1213 int wpos = mWindows.indexOf(win);
1214 if (wpos >= 0) {
1215 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001216 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001218 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 int NC = win.mChildWindows.size();
1220 while (NC > 0) {
1221 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001222 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 int cpos = mWindows.indexOf(cw);
1224 if (cpos >= 0) {
1225 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001226 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001227 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 mWindows.remove(cpos);
1229 }
1230 }
1231 }
1232 return interestingPos;
1233 }
Romain Guy06882f82009-06-10 13:36:04 -07001234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 private void reAddWindowToListInOrderLocked(WindowState win) {
1236 addWindowToListInOrderLocked(win, false);
1237 // This is a hack to get all of the child windows added as well
1238 // at the right position. Child windows should be rare and
1239 // this case should be rare, so it shouldn't be that big a deal.
1240 int wpos = mWindows.indexOf(win);
1241 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001242 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001243 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001245 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 reAddWindowLocked(wpos, win);
1247 }
1248 }
Romain Guy06882f82009-06-10 13:36:04 -07001249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 void logWindowList(String prefix) {
1251 int N = mWindows.size();
1252 while (N > 0) {
1253 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001254 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 }
1256 }
Romain Guy06882f82009-06-10 13:36:04 -07001257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 void moveInputMethodDialogsLocked(int pos) {
1259 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001262 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 for (int i=0; i<N; i++) {
1264 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1265 }
1266 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001267 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 logWindowList(" ");
1269 }
Romain Guy06882f82009-06-10 13:36:04 -07001270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 if (pos >= 0) {
1272 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1273 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001274 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 if (wp == mInputMethodWindow) {
1276 pos++;
1277 }
1278 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001279 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 for (int i=0; i<N; i++) {
1281 WindowState win = dialogs.get(i);
1282 win.mTargetAppToken = targetAppToken;
1283 pos = reAddWindowLocked(pos, win);
1284 }
1285 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001286 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 logWindowList(" ");
1288 }
1289 return;
1290 }
1291 for (int i=0; i<N; i++) {
1292 WindowState win = dialogs.get(i);
1293 win.mTargetAppToken = null;
1294 reAddWindowToListInOrderLocked(win);
1295 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001296 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 logWindowList(" ");
1298 }
1299 }
1300 }
Romain Guy06882f82009-06-10 13:36:04 -07001301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1303 final WindowState imWin = mInputMethodWindow;
1304 final int DN = mInputMethodDialogs.size();
1305 if (imWin == null && DN == 0) {
1306 return false;
1307 }
Romain Guy06882f82009-06-10 13:36:04 -07001308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1310 if (imPos >= 0) {
1311 // In this case, the input method windows are to be placed
1312 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 // First check to see if the input method windows are already
1315 // located here, and contiguous.
1316 final int N = mWindows.size();
1317 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001318 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 // Figure out the actual input method window that should be
1321 // at the bottom of their stack.
1322 WindowState baseImWin = imWin != null
1323 ? imWin : mInputMethodDialogs.get(0);
1324 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001325 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 if (cw.mSubLayer < 0) baseImWin = cw;
1327 }
Romain Guy06882f82009-06-10 13:36:04 -07001328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 if (firstImWin == baseImWin) {
1330 // The windows haven't moved... but are they still contiguous?
1331 // First find the top IM window.
1332 int pos = imPos+1;
1333 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001334 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 break;
1336 }
1337 pos++;
1338 }
1339 pos++;
1340 // Now there should be no more input method windows above.
1341 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001342 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 break;
1344 }
1345 pos++;
1346 }
1347 if (pos >= N) {
1348 // All is good!
1349 return false;
1350 }
1351 }
Romain Guy06882f82009-06-10 13:36:04 -07001352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 if (imWin != null) {
1354 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001355 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 logWindowList(" ");
1357 }
1358 imPos = tmpRemoveWindowLocked(imPos, imWin);
1359 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001360 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 logWindowList(" ");
1362 }
1363 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1364 reAddWindowLocked(imPos, imWin);
1365 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001366 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 logWindowList(" ");
1368 }
1369 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1370 } else {
1371 moveInputMethodDialogsLocked(imPos);
1372 }
Romain Guy06882f82009-06-10 13:36:04 -07001373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 } else {
1375 // In this case, the input method windows go in a fixed layer,
1376 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001379 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 tmpRemoveWindowLocked(0, imWin);
1381 imWin.mTargetAppToken = null;
1382 reAddWindowToListInOrderLocked(imWin);
1383 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001384 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 logWindowList(" ");
1386 }
1387 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1388 } else {
1389 moveInputMethodDialogsLocked(-1);;
1390 }
Romain Guy06882f82009-06-10 13:36:04 -07001391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 }
Romain Guy06882f82009-06-10 13:36:04 -07001393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 if (needAssignLayers) {
1395 assignLayersLocked();
1396 }
Romain Guy06882f82009-06-10 13:36:04 -07001397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 return true;
1399 }
Romain Guy06882f82009-06-10 13:36:04 -07001400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 void adjustInputMethodDialogsLocked() {
1402 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1403 }
Romain Guy06882f82009-06-10 13:36:04 -07001404
Dianne Hackborn25994b42009-09-04 14:21:19 -07001405 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001406 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001407 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1408 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1409 ? wallpaperTarget.mAppToken.animation : null)
1410 + " upper=" + mUpperWallpaperTarget
1411 + " lower=" + mLowerWallpaperTarget);
1412 return (wallpaperTarget != null
1413 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1414 && wallpaperTarget.mAppToken.animation != null)))
1415 || mUpperWallpaperTarget != null
1416 || mLowerWallpaperTarget != null;
1417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001418
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001419 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1420 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001421
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001422 int adjustWallpaperWindowsLocked() {
1423 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001424
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001425 final int dw = mCurDisplayWidth;
1426 final int dh = mCurDisplayHeight;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001427
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001428 // First find top-most window that has asked to be on top of the
1429 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001430 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001431 int N = localmWindows.size();
1432 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001433 WindowState foundW = null;
1434 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001435 WindowState topCurW = null;
1436 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001437 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001438 int i = N;
1439 while (i > 0) {
1440 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001441 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001442 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1443 if (topCurW == null) {
1444 topCurW = w;
1445 topCurI = i;
1446 }
1447 continue;
1448 }
1449 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001450 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001451 // If this window's app token is hidden and not animating,
1452 // it is of no interest to us.
1453 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001454 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001455 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001456 continue;
1457 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001459 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001460 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1461 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001462 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001463 && (mWallpaperTarget == w
1464 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001465 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001466 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001467 foundW = w;
1468 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001469 if (w == mWallpaperTarget && ((w.mAppToken != null
1470 && w.mAppToken.animation != null)
1471 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001472 // The current wallpaper target is animating, so we'll
1473 // look behind it for another possible target and figure
1474 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001475 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001476 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001477 continue;
1478 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001479 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001480 } else if (w == mWindowDetachedWallpaper) {
1481 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001482 }
1483 }
1484
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001485 if (foundW == null && windowDetachedI >= 0) {
1486 if (DEBUG_WALLPAPER) Slog.v(TAG,
1487 "Found animating detached wallpaper activity: #" + i + "=" + w);
1488 foundW = w;
1489 foundI = windowDetachedI;
1490 }
1491
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001492 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001493 // If we are currently waiting for an app transition, and either
1494 // the current target or the next target are involved with it,
1495 // then hold off on doing anything with the wallpaper.
1496 // Note that we are checking here for just whether the target
1497 // is part of an app token... which is potentially overly aggressive
1498 // (the app token may not be involved in the transition), but good
1499 // enough (we'll just wait until whatever transition is pending
1500 // executes).
1501 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001502 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001503 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001504 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001505 }
1506 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001508 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001509 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001510 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001511 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001512
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001513 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001514 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001515 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001516 + " oldTarget: " + mWallpaperTarget);
1517 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001518
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001519 mLowerWallpaperTarget = null;
1520 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001521
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001522 WindowState oldW = mWallpaperTarget;
1523 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001524
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001525 // Now what is happening... if the current and new targets are
1526 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001527 if (foundW != null && oldW != null) {
1528 boolean oldAnim = oldW.mAnimation != null
1529 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1530 boolean foundAnim = foundW.mAnimation != null
1531 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001532 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001533 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001534 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001535 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001536 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001537 int oldI = localmWindows.indexOf(oldW);
1538 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001539 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001540 }
1541 if (oldI >= 0) {
1542 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001544 + "=" + oldW + "; new#" + foundI
1545 + "=" + foundW);
1546 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001547
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001548 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001549 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001550 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001551 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001552 }
1553 mWallpaperTarget = oldW;
1554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001555
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001556 // Now set the upper and lower wallpaper targets
1557 // correctly, and make sure that we are positioning
1558 // the wallpaper below the lower.
1559 if (foundI > oldI) {
1560 // The new target is on top of the old one.
1561 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001563 }
1564 mUpperWallpaperTarget = foundW;
1565 mLowerWallpaperTarget = oldW;
1566 foundW = oldW;
1567 foundI = oldI;
1568 } else {
1569 // The new target is below the old one.
1570 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001571 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001572 }
1573 mUpperWallpaperTarget = oldW;
1574 mLowerWallpaperTarget = foundW;
1575 }
1576 }
1577 }
1578 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001579
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001580 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001581 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001582 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1583 || (mLowerWallpaperTarget.mAppToken != null
1584 && mLowerWallpaperTarget.mAppToken.animation != null);
1585 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1586 || (mUpperWallpaperTarget.mAppToken != null
1587 && mUpperWallpaperTarget.mAppToken.animation != null);
1588 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001589 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001590 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001591 }
1592 mLowerWallpaperTarget = null;
1593 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001594 }
1595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001596
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001597 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001598 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001599 // The window is visible to the compositor... but is it visible
1600 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001601 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001602 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001603
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001604 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001605 // its layer adjustment. Only do this if we are not transfering
1606 // between two wallpaper targets.
1607 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001608 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001609 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001610
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001611 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1612 * TYPE_LAYER_MULTIPLIER
1613 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001614
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001615 // Now w is the window we are supposed to be behind... but we
1616 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001617 // AND any starting window associated with it, AND below the
1618 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001619 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001620 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001621 if (wb.mBaseLayer < maxLayer &&
1622 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001623 (foundW.mAttachedWindow == null ||
1624 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001625 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001626 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001627 // This window is not related to the previous one in any
1628 // interesting way, so stop here.
1629 break;
1630 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001631 foundW = wb;
1632 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001633 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001634 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001635 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001636 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001637
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001638 if (foundW == null && topCurW != null) {
1639 // There is no wallpaper target, so it goes at the bottom.
1640 // We will assume it is the same place as last time, if known.
1641 foundW = topCurW;
1642 foundI = topCurI+1;
1643 } else {
1644 // Okay i is the position immediately above the wallpaper. Look at
1645 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001646 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001647 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001648
Dianne Hackborn284ac932009-08-28 10:34:25 -07001649 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 if (mWallpaperTarget.mWallpaperX >= 0) {
1651 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001652 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001653 }
1654 if (mWallpaperTarget.mWallpaperY >= 0) {
1655 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001656 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001657 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001659
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001660 // Start stepping backwards from here, ensuring that our wallpaper windows
1661 // are correctly placed.
1662 int curTokenIndex = mWallpaperTokens.size();
1663 while (curTokenIndex > 0) {
1664 curTokenIndex--;
1665 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001666 if (token.hidden == visible) {
1667 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1668 token.hidden = !visible;
1669 // Need to do a layout to ensure the wallpaper now has the
1670 // correct size.
1671 mLayoutNeeded = true;
1672 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001673
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001674 int curWallpaperIndex = token.windows.size();
1675 while (curWallpaperIndex > 0) {
1676 curWallpaperIndex--;
1677 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001678
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001679 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001680 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001682
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001683 // First, make sure the client has the current visibility
1684 // state.
1685 if (wallpaper.mWallpaperVisible != visible) {
1686 wallpaper.mWallpaperVisible = visible;
1687 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001688 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001689 "Setting visibility of wallpaper " + wallpaper
1690 + ": " + visible);
1691 wallpaper.mClient.dispatchAppVisibility(visible);
1692 } catch (RemoteException e) {
1693 }
1694 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001695
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001696 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001697 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001698 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001699
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001700 // First, if this window is at the current index, then all
1701 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001702 if (wallpaper == foundW) {
1703 foundI--;
1704 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001705 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001706 continue;
1707 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001709 // The window didn't match... the current wallpaper window,
1710 // wherever it is, is in the wrong place, so make sure it is
1711 // not in the list.
1712 int oldIndex = localmWindows.indexOf(wallpaper);
1713 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001714 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001715 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001716 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001717 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001718 if (oldIndex < foundI) {
1719 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001720 }
1721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001723 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001724 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1725 Slog.v(TAG, "Moving wallpaper " + wallpaper
1726 + " from " + oldIndex + " to " + foundI);
1727 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001728
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001729 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001730 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001731 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001732 }
1733 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001734
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001735 return changed;
1736 }
1737
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001738 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001739 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001740 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001741 mWallpaperAnimLayerAdjustment = adj;
1742 int curTokenIndex = mWallpaperTokens.size();
1743 while (curTokenIndex > 0) {
1744 curTokenIndex--;
1745 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1746 int curWallpaperIndex = token.windows.size();
1747 while (curWallpaperIndex > 0) {
1748 curWallpaperIndex--;
1749 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1750 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001751 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001752 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001753 }
1754 }
1755 }
1756
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001757 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1758 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001759 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001760 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001761 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001762 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001763 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1764 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1765 changed = wallpaperWin.mXOffset != offset;
1766 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001767 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001768 + wallpaperWin + " x: " + offset);
1769 wallpaperWin.mXOffset = offset;
1770 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001771 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001772 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001773 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001774 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001775 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001776
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001777 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001778 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001779 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1780 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1781 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001782 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001783 + wallpaperWin + " y: " + offset);
1784 changed = true;
1785 wallpaperWin.mYOffset = offset;
1786 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001787 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001788 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001789 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001790 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001791 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001792
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001793 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001794 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001795 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001796 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1797 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001798 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001799 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001800 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001801 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001802 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1803 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001804 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001805 if (mWaitingOnWallpaper != null) {
1806 long start = SystemClock.uptimeMillis();
1807 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1808 < start) {
1809 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001810 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001811 "Waiting for offset complete...");
1812 mWindowMap.wait(WALLPAPER_TIMEOUT);
1813 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001814 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001816 if ((start+WALLPAPER_TIMEOUT)
1817 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001818 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001819 + wallpaperWin);
1820 mLastWallpaperTimeoutTime = start;
1821 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001822 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001823 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001824 }
1825 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001826 } catch (RemoteException e) {
1827 }
1828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001829
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001830 return changed;
1831 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001832
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001833 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001834 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001835 if (mWaitingOnWallpaper != null &&
1836 mWaitingOnWallpaper.mClient.asBinder() == window) {
1837 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001838 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001839 }
1840 }
1841 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001842
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001843 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001844 final int dw = mCurDisplayWidth;
1845 final int dh = mCurDisplayHeight;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001846
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001847 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001848
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001849 WindowState target = mWallpaperTarget;
1850 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001851 if (target.mWallpaperX >= 0) {
1852 mLastWallpaperX = target.mWallpaperX;
1853 } else if (changingTarget.mWallpaperX >= 0) {
1854 mLastWallpaperX = changingTarget.mWallpaperX;
1855 }
1856 if (target.mWallpaperY >= 0) {
1857 mLastWallpaperY = target.mWallpaperY;
1858 } else if (changingTarget.mWallpaperY >= 0) {
1859 mLastWallpaperY = changingTarget.mWallpaperY;
1860 }
1861 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001862
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001863 int curTokenIndex = mWallpaperTokens.size();
1864 while (curTokenIndex > 0) {
1865 curTokenIndex--;
1866 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1867 int curWallpaperIndex = token.windows.size();
1868 while (curWallpaperIndex > 0) {
1869 curWallpaperIndex--;
1870 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1871 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1872 wallpaper.computeShownFrameLocked();
1873 changed = true;
1874 // We only want to be synchronous with one wallpaper.
1875 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001876 }
1877 }
1878 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001879
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001880 return changed;
1881 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001882
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001883 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001884 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001885 final int dw = mCurDisplayWidth;
1886 final int dh = mCurDisplayHeight;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001887
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001888 int curTokenIndex = mWallpaperTokens.size();
1889 while (curTokenIndex > 0) {
1890 curTokenIndex--;
1891 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001892 if (token.hidden == visible) {
1893 token.hidden = !visible;
1894 // Need to do a layout to ensure the wallpaper now has the
1895 // correct size.
1896 mLayoutNeeded = true;
1897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001898
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001899 int curWallpaperIndex = token.windows.size();
1900 while (curWallpaperIndex > 0) {
1901 curWallpaperIndex--;
1902 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1903 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001904 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001905 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001906
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001907 if (wallpaper.mWallpaperVisible != visible) {
1908 wallpaper.mWallpaperVisible = visible;
1909 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001910 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001911 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001912 + ": " + visible);
1913 wallpaper.mClient.dispatchAppVisibility(visible);
1914 } catch (RemoteException e) {
1915 }
1916 }
1917 }
1918 }
1919 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 public int addWindow(Session session, IWindow client,
1922 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001923 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 int res = mPolicy.checkAddPermission(attrs);
1925 if (res != WindowManagerImpl.ADD_OKAY) {
1926 return res;
1927 }
Romain Guy06882f82009-06-10 13:36:04 -07001928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 boolean reportNewConfig = false;
1930 WindowState attachedWindow = null;
1931 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07001932 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07001933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07001936 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 }
Romain Guy06882f82009-06-10 13:36:04 -07001938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001940 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1942 }
1943
1944 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001945 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001947 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 + attrs.token + ". Aborting.");
1949 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1950 }
1951 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1952 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001953 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 + attrs.token + ". Aborting.");
1955 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1956 }
1957 }
1958
1959 boolean addToken = false;
1960 WindowToken token = mTokenMap.get(attrs.token);
1961 if (token == null) {
1962 if (attrs.type >= FIRST_APPLICATION_WINDOW
1963 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001964 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 + attrs.token + ". Aborting.");
1966 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1967 }
1968 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001969 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 + attrs.token + ". Aborting.");
1971 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1972 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001973 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001974 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001975 + attrs.token + ". Aborting.");
1976 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1977 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001978 token = new WindowToken(this, attrs.token, -1, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 addToken = true;
1980 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1981 && attrs.type <= LAST_APPLICATION_WINDOW) {
1982 AppWindowToken atoken = token.appWindowToken;
1983 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001984 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 + token + ". Aborting.");
1986 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1987 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001988 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 + token + ". Aborting.");
1990 return WindowManagerImpl.ADD_APP_EXITING;
1991 }
1992 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1993 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001994 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1996 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1997 }
1998 } else if (attrs.type == TYPE_INPUT_METHOD) {
1999 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002000 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 + attrs.token + ". Aborting.");
2002 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2003 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002004 } else if (attrs.type == TYPE_WALLPAPER) {
2005 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002006 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002007 + attrs.token + ". Aborting.");
2008 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 }
2011
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002012 win = new WindowState(this, session, client, token,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 attachedWindow, attrs, viewVisibility);
2014 if (win.mDeathRecipient == null) {
2015 // Client has apparently died, so there is no reason to
2016 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002017 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 + " that is dead, aborting.");
2019 return WindowManagerImpl.ADD_APP_EXITING;
2020 }
2021
2022 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 res = mPolicy.prepareAddWindowLw(win, attrs);
2025 if (res != WindowManagerImpl.ADD_OKAY) {
2026 return res;
2027 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002028
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002029 if (outInputChannel != null) {
2030 String name = win.makeInputChannelName();
2031 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2032 win.mInputChannel = inputChannels[0];
2033 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2034
Jeff Brown928e0542011-01-10 11:17:36 -08002035 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037
2038 // From now on, no exceptions or errors allowed!
2039
2040 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002041
Dianne Hackborn5132b372010-07-29 12:51:35 -07002042 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 if (addToken) {
2045 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 }
2047 win.attach();
2048 mWindowMap.put(client.asBinder(), win);
2049
2050 if (attrs.type == TYPE_APPLICATION_STARTING &&
2051 token.appWindowToken != null) {
2052 token.appWindowToken.startingWindow = win;
2053 }
2054
2055 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 if (attrs.type == TYPE_INPUT_METHOD) {
2058 mInputMethodWindow = win;
2059 addInputMethodWindowToListLocked(win);
2060 imMayMove = false;
2061 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2062 mInputMethodDialogs.add(win);
2063 addWindowToListInOrderLocked(win, true);
2064 adjustInputMethodDialogsLocked();
2065 imMayMove = false;
2066 } else {
2067 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002068 if (attrs.type == TYPE_WALLPAPER) {
2069 mLastWallpaperTimeoutTime = 0;
2070 adjustWallpaperWindowsLocked();
2071 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002072 adjustWallpaperWindowsLocked();
2073 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 }
Romain Guy06882f82009-06-10 13:36:04 -07002075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 if (mInTouchMode) {
2081 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2082 }
2083 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2084 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2085 }
Romain Guy06882f82009-06-10 13:36:04 -07002086
Jeff Brown2e44b072011-01-24 15:21:56 -08002087 mInputMonitor.setUpdateInputWindowsNeededLw();
2088
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002089 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002091 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2092 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002093 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 imMayMove = false;
2095 }
2096 }
Romain Guy06882f82009-06-10 13:36:04 -07002097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002099 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 }
Romain Guy06882f82009-06-10 13:36:04 -07002101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 assignLayersLocked();
2103 // Don't do layout here, the window must call
2104 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 //dump();
2107
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002108 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002109 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002110 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002111 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002112
Joe Onorato8a9b2202010-02-26 18:56:32 -08002113 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002114 TAG, "New client " + client.asBinder()
2115 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002116
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002117 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002118 reportNewConfig = true;
2119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 }
2121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 if (reportNewConfig) {
2123 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002124 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 return res;
2129 }
Romain Guy06882f82009-06-10 13:36:04 -07002130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 public void removeWindow(Session session, IWindow client) {
2132 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002133 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002134 if (win == null) {
2135 return;
2136 }
2137 removeWindowLocked(session, win);
2138 }
2139 }
Romain Guy06882f82009-06-10 13:36:04 -07002140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141 public void removeWindowLocked(Session session, WindowState win) {
2142
Joe Onorato8a9b2202010-02-26 18:56:32 -08002143 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 TAG, "Remove " + win + " client="
2145 + Integer.toHexString(System.identityHashCode(
2146 win.mClient.asBinder()))
2147 + ", surface=" + win.mSurface);
2148
2149 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002150
2151 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002152
Joe Onorato8a9b2202010-02-26 18:56:32 -08002153 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2155 + " mExiting=" + win.mExiting
2156 + " isAnimating=" + win.isAnimating()
2157 + " app-animation="
2158 + (win.mAppToken != null ? win.mAppToken.animation : null)
2159 + " inPendingTransaction="
2160 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2161 + " mDisplayFrozen=" + mDisplayFrozen);
2162 // Visibility of the removed window. Will be used later to update orientation later on.
2163 boolean wasVisible = false;
2164 // First, see if we need to run an animation. If we do, we have
2165 // to hold off on removing the window until the animation is done.
2166 // If the display is frozen, just remove immediately, since the
2167 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002168 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 // If we are not currently running the exit animation, we
2170 // need to see about starting one.
2171 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2174 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2175 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2176 }
2177 // Try starting an animation.
2178 if (applyAnimationLocked(win, transit, false)) {
2179 win.mExiting = true;
2180 }
2181 }
2182 if (win.mExiting || win.isAnimating()) {
2183 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002184 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 win.mExiting = true;
2186 win.mRemoveOnExit = true;
2187 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002188 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2189 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002191 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 if (win.mAppToken != null) {
2193 win.mAppToken.updateReportedVisibilityLocked();
2194 }
2195 //dump();
2196 Binder.restoreCallingIdentity(origId);
2197 return;
2198 }
2199 }
2200
2201 removeWindowInnerLocked(session, win);
2202 // Removing a visible window will effect the computed orientation
2203 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002204 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002205 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002206 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002207 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002209 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 Binder.restoreCallingIdentity(origId);
2211 }
Romain Guy06882f82009-06-10 13:36:04 -07002212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002214 if (win.mRemoved) {
2215 // Nothing to do.
2216 return;
2217 }
2218
2219 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2220 WindowState cwin = win.mChildWindows.get(i);
2221 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2222 + win);
2223 removeWindowInnerLocked(cwin.mSession, cwin);
2224 }
2225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 if (mInputMethodTarget == win) {
2229 moveInputMethodWindowsIfNeededLocked(false);
2230 }
Romain Guy06882f82009-06-10 13:36:04 -07002231
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002232 if (false) {
2233 RuntimeException e = new RuntimeException("here");
2234 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002235 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002236 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 mPolicy.removeWindowLw(win);
2239 win.removeLocked();
2240
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002241 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 mWindowMap.remove(win.mClient.asBinder());
2243 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002244 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002245 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002246 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247
2248 if (mInputMethodWindow == win) {
2249 mInputMethodWindow = null;
2250 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2251 mInputMethodDialogs.remove(win);
2252 }
Romain Guy06882f82009-06-10 13:36:04 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 final WindowToken token = win.mToken;
2255 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002256 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 token.windows.remove(win);
2258 if (atoken != null) {
2259 atoken.allAppWindows.remove(win);
2260 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002261 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 TAG, "**** Removing window " + win + ": count="
2263 + token.windows.size());
2264 if (token.windows.size() == 0) {
2265 if (!token.explicit) {
2266 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 } else if (atoken != null) {
2268 atoken.firstWindowDrawn = false;
2269 }
2270 }
2271
2272 if (atoken != null) {
2273 if (atoken.startingWindow == win) {
2274 atoken.startingWindow = null;
2275 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2276 // If this is the last window and we had requested a starting
2277 // transition window, well there is no point now.
2278 atoken.startingData = null;
2279 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2280 // If this is the last window except for a starting transition
2281 // window, we need to get rid of the starting transition.
2282 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002283 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 + ": no more real windows");
2285 }
2286 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2287 mH.sendMessage(m);
2288 }
2289 }
Romain Guy06882f82009-06-10 13:36:04 -07002290
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002291 if (win.mAttrs.type == TYPE_WALLPAPER) {
2292 mLastWallpaperTimeoutTime = 0;
2293 adjustWallpaperWindowsLocked();
2294 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002295 adjustWallpaperWindowsLocked();
2296 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 if (!mInLayout) {
2299 assignLayersLocked();
2300 mLayoutNeeded = true;
2301 performLayoutAndPlaceSurfacesLocked();
2302 if (win.mAppToken != null) {
2303 win.mAppToken.updateReportedVisibilityLocked();
2304 }
2305 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002306
Jeff Brown2e44b072011-01-24 15:21:56 -08002307 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 }
2309
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002310 static void logSurface(WindowState w, String msg, RuntimeException where) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002311 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2312 + ": " + msg + " / " + w.mAttrs.getTitle();
2313 if (where != null) {
2314 Slog.i(TAG, str, where);
2315 } else {
2316 Slog.i(TAG, str);
2317 }
2318 }
2319
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002320 void setTransparentRegionWindow(Session session, IWindow client, Region region) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 long origId = Binder.clearCallingIdentity();
2322 try {
2323 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002324 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002326 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2327 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 Surface.openTransaction();
2329 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002330 if (SHOW_TRANSACTIONS) logSurface(w,
2331 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 w.mSurface.setTransparentRegionHint(region);
2333 } finally {
2334 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002335 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2336 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 }
2338 }
2339 }
2340 } finally {
2341 Binder.restoreCallingIdentity(origId);
2342 }
2343 }
2344
2345 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002346 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002347 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 long origId = Binder.clearCallingIdentity();
2349 try {
2350 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002351 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 if (w != null) {
2353 w.mGivenInsetsPending = false;
2354 w.mGivenContentInsets.set(contentInsets);
2355 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002356 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 w.mTouchableInsets = touchableInsets;
2358 mLayoutNeeded = true;
2359 performLayoutAndPlaceSurfacesLocked();
2360 }
2361 }
2362 } finally {
2363 Binder.restoreCallingIdentity(origId);
2364 }
2365 }
Romain Guy06882f82009-06-10 13:36:04 -07002366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 public void getWindowDisplayFrame(Session session, IWindow client,
2368 Rect outDisplayFrame) {
2369 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002370 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 if (win == null) {
2372 outDisplayFrame.setEmpty();
2373 return;
2374 }
2375 outDisplayFrame.set(win.mDisplayFrame);
2376 }
2377 }
2378
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002379 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2380 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002381 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2382 window.mWallpaperX = x;
2383 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002384 window.mWallpaperXStep = xStep;
2385 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002386 if (updateWallpaperOffsetLocked(window, true)) {
2387 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002388 }
2389 }
2390 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002391
Dianne Hackborn75804932009-10-20 20:15:20 -07002392 void wallpaperCommandComplete(IBinder window, Bundle result) {
2393 synchronized (mWindowMap) {
2394 if (mWaitingOnWallpaper != null &&
2395 mWaitingOnWallpaper.mClient.asBinder() == window) {
2396 mWaitingOnWallpaper = null;
2397 mWindowMap.notifyAll();
2398 }
2399 }
2400 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002401
Dianne Hackborn75804932009-10-20 20:15:20 -07002402 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2403 String action, int x, int y, int z, Bundle extras, boolean sync) {
2404 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2405 || window == mUpperWallpaperTarget) {
2406 boolean doWait = sync;
2407 int curTokenIndex = mWallpaperTokens.size();
2408 while (curTokenIndex > 0) {
2409 curTokenIndex--;
2410 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2411 int curWallpaperIndex = token.windows.size();
2412 while (curWallpaperIndex > 0) {
2413 curWallpaperIndex--;
2414 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2415 try {
2416 wallpaper.mClient.dispatchWallpaperCommand(action,
2417 x, y, z, extras, sync);
2418 // We only want to be synchronous with one wallpaper.
2419 sync = false;
2420 } catch (RemoteException e) {
2421 }
2422 }
2423 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002424
Dianne Hackborn75804932009-10-20 20:15:20 -07002425 if (doWait) {
2426 // XXX Need to wait for result.
2427 }
2428 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002429
Dianne Hackborn75804932009-10-20 20:15:20 -07002430 return null;
2431 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 public int relayoutWindow(Session session, IWindow client,
2434 WindowManager.LayoutParams attrs, int requestedWidth,
2435 int requestedHeight, int viewVisibility, boolean insetsPending,
2436 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002437 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 boolean displayed = false;
2439 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002440 boolean configChanged;
Joe Onoratoac0ee892011-01-30 15:38:30 -08002441
2442 // if they don't have this permission, mask out the status bar bits
2443 if (attrs != null) {
2444 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
2445 != PackageManager.PERMISSION_GRANTED) {
2446 attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2447 attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2448 }
2449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002453 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002454 if (win == null) {
2455 return 0;
2456 }
2457 win.mRequestedWidth = requestedWidth;
2458 win.mRequestedHeight = requestedHeight;
2459
2460 if (attrs != null) {
2461 mPolicy.adjustWindowParamsLw(attrs);
2462 }
Romain Guy06882f82009-06-10 13:36:04 -07002463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 int attrChanges = 0;
2465 int flagChanges = 0;
2466 if (attrs != null) {
2467 flagChanges = win.mAttrs.flags ^= attrs.flags;
2468 attrChanges = win.mAttrs.copyFrom(attrs);
2469 }
2470
Joe Onorato8a9b2202010-02-26 18:56:32 -08002471 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002472
2473 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2474 win.mAlpha = attrs.alpha;
2475 }
2476
2477 final boolean scaledWindow =
2478 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2479
2480 if (scaledWindow) {
2481 // requested{Width|Height} Surface's physical size
2482 // attrs.{width|height} Size on screen
2483 win.mHScale = (attrs.width != requestedWidth) ?
2484 (attrs.width / (float)requestedWidth) : 1.0f;
2485 win.mVScale = (attrs.height != requestedHeight) ?
2486 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002487 } else {
2488 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 }
2490
2491 boolean imMayMove = (flagChanges&(
2492 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2493 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 boolean focusMayChange = win.mViewVisibility != viewVisibility
2496 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2497 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002498
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002499 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2500 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 win.mRelayoutCalled = true;
2503 final int oldVisibility = win.mViewVisibility;
2504 win.mViewVisibility = viewVisibility;
2505 if (viewVisibility == View.VISIBLE &&
2506 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2507 displayed = !win.isVisibleLw();
2508 if (win.mExiting) {
2509 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002510 if (win.mAnimation != null) {
2511 win.mAnimation.cancel();
2512 win.mAnimation = null;
2513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 }
2515 if (win.mDestroying) {
2516 win.mDestroying = false;
2517 mDestroySurface.remove(win);
2518 }
2519 if (oldVisibility == View.GONE) {
2520 win.mEnterAnimationPending = true;
2521 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002522 if (displayed) {
2523 if (win.mSurface != null && !win.mDrawPending
2524 && !win.mCommitDrawPending && !mDisplayFrozen
2525 && mPolicy.isScreenOn()) {
2526 applyEnterAnimationLocked(win);
2527 }
2528 if ((win.mAttrs.flags
2529 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2530 if (DEBUG_VISIBILITY) Slog.v(TAG,
2531 "Relayout window turning screen on: " + win);
2532 win.mTurnOnScreen = true;
2533 }
2534 int diff = 0;
2535 if (win.mConfiguration != mCurConfiguration
2536 && (win.mConfiguration == null
2537 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2538 win.mConfiguration = mCurConfiguration;
2539 if (DEBUG_CONFIGURATION) {
2540 Slog.i(TAG, "Window " + win + " visible with new config: "
2541 + win.mConfiguration + " / 0x"
2542 + Integer.toHexString(diff));
2543 }
2544 outConfig.setTo(mCurConfiguration);
2545 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2548 // To change the format, we need to re-build the surface.
2549 win.destroySurfaceLocked();
2550 displayed = true;
2551 }
2552 try {
2553 Surface surface = win.createSurfaceLocked();
2554 if (surface != null) {
2555 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002556 win.mReportDestroySurface = false;
2557 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002558 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002559 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002561 // For some reason there isn't a surface. Clear the
2562 // caller's object so they see the same state.
2563 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 }
2565 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002566 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002567
Joe Onorato8a9b2202010-02-26 18:56:32 -08002568 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002569 + client + " (" + win.mAttrs.getTitle() + ")",
2570 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 Binder.restoreCallingIdentity(origId);
2572 return 0;
2573 }
2574 if (displayed) {
2575 focusMayChange = true;
2576 }
2577 if (win.mAttrs.type == TYPE_INPUT_METHOD
2578 && mInputMethodWindow == null) {
2579 mInputMethodWindow = win;
2580 imMayMove = true;
2581 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002582 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2583 && win.mAppToken != null
2584 && win.mAppToken.startingWindow != null) {
2585 // Special handling of starting window over the base
2586 // window of the app: propagate lock screen flags to it,
2587 // to provide the correct semantics while starting.
2588 final int mask =
2589 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002590 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2591 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002592 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2593 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 } else {
2596 win.mEnterAnimationPending = false;
2597 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002598 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002599 + ": mExiting=" + win.mExiting
2600 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 // If we are not currently running the exit animation, we
2602 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002603 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 // Try starting an animation; if there isn't one, we
2605 // can destroy the surface right away.
2606 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2607 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2608 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2609 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002610 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002612 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 } else if (win.isAnimating()) {
2615 // Currently in a hide animation... turn this into
2616 // an exit.
2617 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002618 } else if (win == mWallpaperTarget) {
2619 // If the wallpaper is currently behind this
2620 // window, we need to change both of them inside
2621 // of a transaction to avoid artifacts.
2622 win.mExiting = true;
2623 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 } else {
2625 if (mInputMethodWindow == win) {
2626 mInputMethodWindow = null;
2627 }
2628 win.destroySurfaceLocked();
2629 }
2630 }
2631 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002632
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002633 if (win.mSurface == null || (win.getAttrs().flags
2634 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2635 || win.mSurfacePendingDestroy) {
2636 // We are being called from a local process, which
2637 // means outSurface holds its current surface. Ensure the
2638 // surface object is cleared, but we don't want it actually
2639 // destroyed at this point.
2640 win.mSurfacePendingDestroy = false;
2641 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002642 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002643 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002644 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002645 "Keeping surface, will report destroy: " + win);
2646 win.mReportDestroySurface = true;
2647 outSurface.copyFrom(win.mSurface);
2648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 }
2650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 if (focusMayChange) {
2652 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002653 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2654 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 imMayMove = false;
2656 }
2657 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2658 }
Romain Guy06882f82009-06-10 13:36:04 -07002659
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002660 // updateFocusedWindowLocked() already assigned layers so we only need to
2661 // reassign them at this point if the IM window state gets shuffled
2662 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002665 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2666 // Little hack here -- we -should- be able to rely on the
2667 // function to return true if the IME has moved and needs
2668 // its layer recomputed. However, if the IME was hidden
2669 // and isn't actually moved in the list, its layer may be
2670 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 assignLayers = true;
2672 }
2673 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002674 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002675 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002676 assignLayers = true;
2677 }
2678 }
Romain Guy06882f82009-06-10 13:36:04 -07002679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002680 mLayoutNeeded = true;
2681 win.mGivenInsetsPending = insetsPending;
2682 if (assignLayers) {
2683 assignLayersLocked();
2684 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002685 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002687 if (displayed && win.mIsWallpaper) {
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07002688 updateWallpaperOffsetLocked(win, mCurDisplayWidth, mCurDisplayHeight, false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 if (win.mAppToken != null) {
2691 win.mAppToken.updateReportedVisibilityLocked();
2692 }
2693 outFrame.set(win.mFrame);
2694 outContentInsets.set(win.mContentInsets);
2695 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002696 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002698 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002699 + ", requestedHeight=" + requestedHeight
2700 + ", viewVisibility=" + viewVisibility
2701 + "\nRelayout returning frame=" + outFrame
2702 + ", surface=" + outSurface);
2703
Joe Onorato8a9b2202010-02-26 18:56:32 -08002704 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2706
2707 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002708
Jeff Brown2e44b072011-01-24 15:21:56 -08002709 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 }
2711
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002712 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 sendNewConfiguration();
2714 }
Romain Guy06882f82009-06-10 13:36:04 -07002715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2719 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2720 }
2721
Dianne Hackborn64825172011-03-02 21:32:58 -08002722 public boolean outOfMemoryWindow(Session session, IWindow client) {
2723 long origId = Binder.clearCallingIdentity();
2724
2725 try {
2726 synchronized(mWindowMap) {
2727 WindowState win = windowForClientLocked(session, client, false);
2728 if (win == null) {
2729 return false;
2730 }
2731 return reclaimSomeSurfaceMemoryLocked(win, "from-client", false);
2732 }
2733 } finally {
2734 Binder.restoreCallingIdentity(origId);
2735 }
2736 }
2737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 public void finishDrawingWindow(Session session, IWindow client) {
2739 final long origId = Binder.clearCallingIdentity();
2740 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002741 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002743 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2744 adjustWallpaperWindowsLocked();
2745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002746 mLayoutNeeded = true;
2747 performLayoutAndPlaceSurfacesLocked();
2748 }
2749 }
2750 Binder.restoreCallingIdentity(origId);
2751 }
2752
2753 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08002754 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 + (lp != null ? lp.packageName : null)
2756 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2757 if (lp != null && lp.windowAnimations != 0) {
2758 // If this is a system resource, don't try to load it from the
2759 // application resources. It is nice to avoid loading application
2760 // resources if we can.
2761 String packageName = lp.packageName != null ? lp.packageName : "android";
2762 int resId = lp.windowAnimations;
2763 if ((resId&0xFF000000) == 0x01000000) {
2764 packageName = "android";
2765 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002766 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002767 + packageName);
2768 return AttributeCache.instance().get(packageName, resId,
2769 com.android.internal.R.styleable.WindowAnimation);
2770 }
2771 return null;
2772 }
Romain Guy06882f82009-06-10 13:36:04 -07002773
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002774 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08002775 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002776 + packageName + " resId=0x" + Integer.toHexString(resId));
2777 if (packageName != null) {
2778 if ((resId&0xFF000000) == 0x01000000) {
2779 packageName = "android";
2780 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002781 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002782 + packageName);
2783 return AttributeCache.instance().get(packageName, resId,
2784 com.android.internal.R.styleable.WindowAnimation);
2785 }
2786 return null;
2787 }
2788
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002789 void applyEnterAnimationLocked(WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2791 if (win.mEnterAnimationPending) {
2792 win.mEnterAnimationPending = false;
2793 transit = WindowManagerPolicy.TRANSIT_ENTER;
2794 }
2795
2796 applyAnimationLocked(win, transit, true);
2797 }
2798
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002799 boolean applyAnimationLocked(WindowState win,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 int transit, boolean isEntrance) {
2801 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2802 // If we are trying to apply an animation, but already running
2803 // an animation of the same type, then just leave that one alone.
2804 return true;
2805 }
Romain Guy06882f82009-06-10 13:36:04 -07002806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 // Only apply an animation if the display isn't frozen. If it is
2808 // frozen, there is no reason to animate and it can cause strange
2809 // artifacts when we unfreeze the display if some different animation
2810 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002811 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 int anim = mPolicy.selectAnimationLw(win, transit);
2813 int attr = -1;
2814 Animation a = null;
2815 if (anim != 0) {
2816 a = AnimationUtils.loadAnimation(mContext, anim);
2817 } else {
2818 switch (transit) {
2819 case WindowManagerPolicy.TRANSIT_ENTER:
2820 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2821 break;
2822 case WindowManagerPolicy.TRANSIT_EXIT:
2823 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2824 break;
2825 case WindowManagerPolicy.TRANSIT_SHOW:
2826 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2827 break;
2828 case WindowManagerPolicy.TRANSIT_HIDE:
2829 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2830 break;
2831 }
2832 if (attr >= 0) {
2833 a = loadAnimation(win.mAttrs, attr);
2834 }
2835 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002836 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2838 + " mAnimation=" + win.mAnimation
2839 + " isEntrance=" + isEntrance);
2840 if (a != null) {
2841 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002842 RuntimeException e = null;
2843 if (!HIDE_STACK_CRAWLS) {
2844 e = new RuntimeException();
2845 e.fillInStackTrace();
2846 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002847 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 }
2849 win.setAnimation(a);
2850 win.mAnimationIsEntrance = isEntrance;
2851 }
2852 } else {
2853 win.clearAnimation();
2854 }
2855
2856 return win.mAnimation != null;
2857 }
2858
2859 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2860 int anim = 0;
2861 Context context = mContext;
2862 if (animAttr >= 0) {
2863 AttributeCache.Entry ent = getCachedAnimations(lp);
2864 if (ent != null) {
2865 context = ent.context;
2866 anim = ent.array.getResourceId(animAttr, 0);
2867 }
2868 }
2869 if (anim != 0) {
2870 return AnimationUtils.loadAnimation(context, anim);
2871 }
2872 return null;
2873 }
Romain Guy06882f82009-06-10 13:36:04 -07002874
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002875 private Animation loadAnimation(String packageName, int resId) {
2876 int anim = 0;
2877 Context context = mContext;
2878 if (resId >= 0) {
2879 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2880 if (ent != null) {
2881 context = ent.context;
2882 anim = resId;
2883 }
2884 }
2885 if (anim != 0) {
2886 return AnimationUtils.loadAnimation(context, anim);
2887 }
2888 return null;
2889 }
2890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 private boolean applyAnimationLocked(AppWindowToken wtoken,
2892 WindowManager.LayoutParams lp, int transit, boolean enter) {
2893 // Only apply an animation if the display isn't frozen. If it is
2894 // frozen, there is no reason to animate and it can cause strange
2895 // artifacts when we unfreeze the display if some different animation
2896 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002897 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002898 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002899 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002900 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002901 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002902 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002903 } else if (mNextAppTransitionPackage != null) {
2904 a = loadAnimation(mNextAppTransitionPackage, enter ?
2905 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002906 } else {
2907 int animAttr = 0;
2908 switch (transit) {
2909 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2910 animAttr = enter
2911 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2912 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2913 break;
2914 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2915 animAttr = enter
2916 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2917 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2918 break;
2919 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2920 animAttr = enter
2921 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2922 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2923 break;
2924 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2925 animAttr = enter
2926 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2927 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2928 break;
2929 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2930 animAttr = enter
2931 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2932 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2933 break;
2934 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2935 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002936 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002937 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2938 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002939 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002940 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002941 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2942 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002943 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002944 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002945 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002946 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2947 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2948 break;
2949 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2950 animAttr = enter
2951 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2952 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2953 break;
2954 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2955 animAttr = enter
2956 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2957 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002958 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002959 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002960 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002961 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002962 + " anim=" + a
2963 + " animAttr=0x" + Integer.toHexString(animAttr)
2964 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 if (a != null) {
2967 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002968 RuntimeException e = null;
2969 if (!HIDE_STACK_CRAWLS) {
2970 e = new RuntimeException();
2971 e.fillInStackTrace();
2972 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002973 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 }
2975 wtoken.setAnimation(a);
2976 }
2977 } else {
2978 wtoken.clearAnimation();
2979 }
2980
2981 return wtoken.animation != null;
2982 }
2983
2984 // -------------------------------------------------------------
2985 // Application Window Tokens
2986 // -------------------------------------------------------------
2987
2988 public void validateAppTokens(List tokens) {
2989 int v = tokens.size()-1;
2990 int m = mAppTokens.size()-1;
2991 while (v >= 0 && m >= 0) {
2992 AppWindowToken wtoken = mAppTokens.get(m);
2993 if (wtoken.removed) {
2994 m--;
2995 continue;
2996 }
2997 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002998 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3000 }
3001 v--;
3002 m--;
3003 }
3004 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003005 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 v--;
3007 }
3008 while (m >= 0) {
3009 AppWindowToken wtoken = mAppTokens.get(m);
3010 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003011 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 }
3013 m--;
3014 }
3015 }
3016
3017 boolean checkCallingPermission(String permission, String func) {
3018 // Quick check: if the calling permission is me, it's all okay.
3019 if (Binder.getCallingPid() == Process.myPid()) {
3020 return true;
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 if (mContext.checkCallingPermission(permission)
3024 == PackageManager.PERMISSION_GRANTED) {
3025 return true;
3026 }
3027 String msg = "Permission Denial: " + func + " from pid="
3028 + Binder.getCallingPid()
3029 + ", uid=" + Binder.getCallingUid()
3030 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003031 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 return false;
3033 }
Romain Guy06882f82009-06-10 13:36:04 -07003034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 AppWindowToken findAppWindowToken(IBinder token) {
3036 WindowToken wtoken = mTokenMap.get(token);
3037 if (wtoken == null) {
3038 return null;
3039 }
3040 return wtoken.appWindowToken;
3041 }
Romain Guy06882f82009-06-10 13:36:04 -07003042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 public void addWindowToken(IBinder token, int type) {
3044 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3045 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003046 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 }
Romain Guy06882f82009-06-10 13:36:04 -07003048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003049 synchronized(mWindowMap) {
3050 WindowToken wtoken = mTokenMap.get(token);
3051 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003052 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003053 return;
3054 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003055 wtoken = new WindowToken(this, token, type, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003057 if (type == TYPE_WALLPAPER) {
3058 mWallpaperTokens.add(wtoken);
3059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 }
3061 }
Romain Guy06882f82009-06-10 13:36:04 -07003062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 public void removeWindowToken(IBinder token) {
3064 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3065 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003066 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003067 }
3068
3069 final long origId = Binder.clearCallingIdentity();
3070 synchronized(mWindowMap) {
3071 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 if (wtoken != null) {
3073 boolean delayed = false;
3074 if (!wtoken.hidden) {
3075 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 final int N = wtoken.windows.size();
3078 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 for (int i=0; i<N; i++) {
3081 WindowState win = wtoken.windows.get(i);
3082
3083 if (win.isAnimating()) {
3084 delayed = true;
3085 }
Romain Guy06882f82009-06-10 13:36:04 -07003086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 if (win.isVisibleNow()) {
3088 applyAnimationLocked(win,
3089 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 changed = true;
3091 }
3092 }
3093
3094 if (changed) {
3095 mLayoutNeeded = true;
3096 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003097 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3098 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 }
Romain Guy06882f82009-06-10 13:36:04 -07003100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 if (delayed) {
3102 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003103 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3104 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 }
3106 }
Romain Guy06882f82009-06-10 13:36:04 -07003107
Jeff Brown2e44b072011-01-24 15:21:56 -08003108 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003110 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003111 }
3112 }
3113 Binder.restoreCallingIdentity(origId);
3114 }
3115
3116 public void addAppToken(int addPos, IApplicationToken token,
3117 int groupId, int requestedOrientation, boolean fullscreen) {
3118 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3119 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003120 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003121 }
Jeff Brown349703e2010-06-22 01:27:15 -07003122
3123 // Get the dispatching timeout here while we are not holding any locks so that it
3124 // can be cached by the AppWindowToken. The timeout value is used later by the
3125 // input dispatcher in code that does hold locks. If we did not cache the value
3126 // here we would run the chance of introducing a deadlock between the window manager
3127 // (which holds locks while updating the input dispatcher state) and the activity manager
3128 // (which holds locks while querying the application token).
3129 long inputDispatchingTimeoutNanos;
3130 try {
3131 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3132 } catch (RemoteException ex) {
3133 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3134 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3135 }
Romain Guy06882f82009-06-10 13:36:04 -07003136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003137 synchronized(mWindowMap) {
3138 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3139 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003140 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 return;
3142 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003143 wtoken = new AppWindowToken(this, token);
Jeff Brown349703e2010-06-22 01:27:15 -07003144 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 wtoken.groupId = groupId;
3146 wtoken.appFullscreen = fullscreen;
3147 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003148 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 // Application tokens start out hidden.
3153 wtoken.hidden = true;
3154 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 //dump();
3157 }
3158 }
Romain Guy06882f82009-06-10 13:36:04 -07003159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 public void setAppGroupId(IBinder token, int groupId) {
3161 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3162 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003163 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 }
3165
3166 synchronized(mWindowMap) {
3167 AppWindowToken wtoken = findAppWindowToken(token);
3168 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003169 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 return;
3171 }
3172 wtoken.groupId = groupId;
3173 }
3174 }
Romain Guy06882f82009-06-10 13:36:04 -07003175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 public int getOrientationFromWindowsLocked() {
3177 int pos = mWindows.size() - 1;
3178 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003179 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 pos--;
3181 if (wtoken.mAppToken != null) {
3182 // We hit an application window. so the orientation will be determined by the
3183 // app window. No point in continuing further.
3184 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3185 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003186 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 continue;
3188 }
3189 int req = wtoken.mAttrs.screenOrientation;
3190 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3191 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3192 continue;
3193 } else {
3194 return req;
3195 }
3196 }
3197 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3198 }
Romain Guy06882f82009-06-10 13:36:04 -07003199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003201 int pos = mAppTokens.size() - 1;
3202 int curGroup = 0;
3203 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3204 boolean findingBehind = false;
3205 boolean haveGroup = false;
3206 boolean lastFullscreen = false;
3207 while (pos >= 0) {
3208 AppWindowToken wtoken = mAppTokens.get(pos);
3209 pos--;
3210 // if we're about to tear down this window and not seek for
3211 // the behind activity, don't use it for orientation
3212 if (!findingBehind
3213 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3214 continue;
3215 }
3216
3217 if (!haveGroup) {
3218 // We ignore any hidden applications on the top.
3219 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003220 continue;
3221 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003222 haveGroup = true;
3223 curGroup = wtoken.groupId;
3224 lastOrientation = wtoken.requestedOrientation;
3225 } else if (curGroup != wtoken.groupId) {
3226 // If we have hit a new application group, and the bottom
3227 // of the previous group didn't explicitly say to use
3228 // the orientation behind it, and the last app was
3229 // full screen, then we'll stick with the
3230 // user's orientation.
3231 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3232 && lastFullscreen) {
3233 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003236 int or = wtoken.requestedOrientation;
3237 // If this application is fullscreen, and didn't explicitly say
3238 // to use the orientation behind it, then just take whatever
3239 // orientation it has and ignores whatever is under it.
3240 lastFullscreen = wtoken.appFullscreen;
3241 if (lastFullscreen
3242 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3243 return or;
3244 }
3245 // If this application has requested an explicit orientation,
3246 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003247 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3248 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003249 return or;
3250 }
3251 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3252 }
3253 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 }
Romain Guy06882f82009-06-10 13:36:04 -07003255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003257 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003258 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3259 "updateOrientationFromAppTokens()")) {
3260 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3261 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003262
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003263 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003265
3266 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003267 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003268 if (freezeThisOneIfNeeded != null) {
3269 AppWindowToken wtoken = findAppWindowToken(
3270 freezeThisOneIfNeeded);
3271 if (wtoken != null) {
3272 startAppFreezingScreenLocked(wtoken,
3273 ActivityInfo.CONFIG_ORIENTATION);
3274 }
3275 }
3276 config = computeNewConfigurationLocked();
3277
3278 } else if (currentConfig != null) {
3279 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003280 // state mismatches the activity manager's, update it,
3281 // disregarding font scale, which should remain set to
3282 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003283 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003284 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003285 if (computeNewConfigurationLocked(mTempConfiguration)) {
3286 if (currentConfig.diff(mTempConfiguration) != 0) {
3287 mWaitingForConfig = true;
3288 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003289 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003290 config = new Configuration(mTempConfiguration);
3291 }
3292 }
3293 }
3294 }
3295
Dianne Hackborncfaef692009-06-15 14:24:44 -07003296 Binder.restoreCallingIdentity(ident);
3297 return config;
3298 }
3299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003301 * Determine the new desired orientation of the display, returning
3302 * a non-null new Configuration if it has changed from the current
3303 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3304 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3305 * SCREEN. This will typically be done for you if you call
3306 * sendNewConfiguration().
3307 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 * The orientation is computed from non-application windows first. If none of
3309 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003310 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3312 * android.os.IBinder)
3313 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003314 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3315 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003316 // If the display is frozen, some activities may be in the middle
3317 // of restarting, and thus have removed their old window. If the
3318 // window has the flag to hide the lock screen, then the lock screen
3319 // can re-appear and inflict its own orientation on us. Keep the
3320 // orientation stable until this all settles down.
3321 return false;
3322 }
3323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 long ident = Binder.clearCallingIdentity();
3326 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003327 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 mForcedAppOrientation = req;
3331 //send a message to Policy indicating orientation change to take
3332 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003333 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003334 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003335 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3336 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003337 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 }
3339 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003340
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003341 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 } finally {
3343 Binder.restoreCallingIdentity(ident);
3344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 }
Romain Guy06882f82009-06-10 13:36:04 -07003346
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003347 int computeForcedAppOrientationLocked() {
3348 int req = getOrientationFromWindowsLocked();
3349 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3350 req = getOrientationFromAppTokensLocked();
3351 }
3352 return req;
3353 }
Romain Guy06882f82009-06-10 13:36:04 -07003354
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003355 public void setNewConfiguration(Configuration config) {
3356 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3357 "setNewConfiguration()")) {
3358 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3359 }
3360
3361 synchronized(mWindowMap) {
3362 mCurConfiguration = new Configuration(config);
3363 mWaitingForConfig = false;
3364 performLayoutAndPlaceSurfacesLocked();
3365 }
3366 }
3367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3369 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3370 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003371 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 }
Romain Guy06882f82009-06-10 13:36:04 -07003373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 synchronized(mWindowMap) {
3375 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3376 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003377 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 return;
3379 }
Romain Guy06882f82009-06-10 13:36:04 -07003380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 wtoken.requestedOrientation = requestedOrientation;
3382 }
3383 }
Romain Guy06882f82009-06-10 13:36:04 -07003384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 public int getAppOrientation(IApplicationToken token) {
3386 synchronized(mWindowMap) {
3387 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3388 if (wtoken == null) {
3389 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3390 }
Romain Guy06882f82009-06-10 13:36:04 -07003391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 return wtoken.requestedOrientation;
3393 }
3394 }
Romain Guy06882f82009-06-10 13:36:04 -07003395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003396 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3397 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3398 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003399 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 }
3401
3402 synchronized(mWindowMap) {
3403 boolean changed = false;
3404 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003405 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 changed = mFocusedApp != null;
3407 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003408 if (changed) {
3409 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 } else {
3412 AppWindowToken newFocus = findAppWindowToken(token);
3413 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003414 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 return;
3416 }
3417 changed = mFocusedApp != newFocus;
3418 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003419 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003420 if (changed) {
3421 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003423 }
3424
3425 if (moveFocusNow && changed) {
3426 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003427 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 Binder.restoreCallingIdentity(origId);
3429 }
3430 }
3431 }
3432
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003433 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3435 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003436 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 }
Romain Guy06882f82009-06-10 13:36:04 -07003438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003440 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 TAG, "Prepare app transition: transit=" + transit
3442 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003443 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003444 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3445 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003447 } else if (!alwaysKeepCurrent) {
3448 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3449 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3450 // Opening a new task always supersedes a close for the anim.
3451 mNextAppTransition = transit;
3452 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3453 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3454 // Opening a new activity always supersedes a close for the anim.
3455 mNextAppTransition = transit;
3456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003457 }
3458 mAppTransitionReady = false;
3459 mAppTransitionTimeout = false;
3460 mStartingIconInTransition = false;
3461 mSkipAppTransitionAnimation = false;
3462 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3463 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3464 5000);
3465 }
3466 }
3467 }
3468
3469 public int getPendingAppTransition() {
3470 return mNextAppTransition;
3471 }
Romain Guy06882f82009-06-10 13:36:04 -07003472
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003473 public void overridePendingAppTransition(String packageName,
3474 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003475 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003476 mNextAppTransitionPackage = packageName;
3477 mNextAppTransitionEnter = enterAnim;
3478 mNextAppTransitionExit = exitAnim;
3479 }
3480 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 public void executeAppTransition() {
3483 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3484 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003485 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 }
Romain Guy06882f82009-06-10 13:36:04 -07003487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003489 if (DEBUG_APP_TRANSITIONS) {
3490 RuntimeException e = new RuntimeException("here");
3491 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003492 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003493 + mNextAppTransition, e);
3494 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003495 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 mAppTransitionReady = true;
3497 final long origId = Binder.clearCallingIdentity();
3498 performLayoutAndPlaceSurfacesLocked();
3499 Binder.restoreCallingIdentity(origId);
3500 }
3501 }
3502 }
3503
3504 public void setAppStartingWindow(IBinder token, String pkg,
3505 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003506 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3508 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003509 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 }
3511
3512 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003513 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3515 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 AppWindowToken wtoken = findAppWindowToken(token);
3518 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003519 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 return;
3521 }
3522
3523 // If the display is frozen, we won't do anything until the
3524 // actual window is displayed so there is no reason to put in
3525 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003526 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 return;
3528 }
Romain Guy06882f82009-06-10 13:36:04 -07003529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 if (wtoken.startingData != null) {
3531 return;
3532 }
Romain Guy06882f82009-06-10 13:36:04 -07003533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 if (transferFrom != null) {
3535 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3536 if (ttoken != null) {
3537 WindowState startingWindow = ttoken.startingWindow;
3538 if (startingWindow != null) {
3539 if (mStartingIconInTransition) {
3540 // In this case, the starting icon has already
3541 // been displayed, so start letting windows get
3542 // shown immediately without any more transitions.
3543 mSkipAppTransitionAnimation = true;
3544 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003545 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 "Moving existing starting from " + ttoken
3547 + " to " + wtoken);
3548 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 // Transfer the starting window over to the new
3551 // token.
3552 wtoken.startingData = ttoken.startingData;
3553 wtoken.startingView = ttoken.startingView;
3554 wtoken.startingWindow = startingWindow;
3555 ttoken.startingData = null;
3556 ttoken.startingView = null;
3557 ttoken.startingWindow = null;
3558 ttoken.startingMoved = true;
3559 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003560 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003562 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003563 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003565 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003566 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3567 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 ttoken.windows.remove(startingWindow);
3569 ttoken.allAppWindows.remove(startingWindow);
3570 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 // Propagate other interesting state between the
3573 // tokens. If the old token is displayed, we should
3574 // immediately force the new one to be displayed. If
3575 // it is animating, we need to move that animation to
3576 // the new one.
3577 if (ttoken.allDrawn) {
3578 wtoken.allDrawn = true;
3579 }
3580 if (ttoken.firstWindowDrawn) {
3581 wtoken.firstWindowDrawn = true;
3582 }
3583 if (!ttoken.hidden) {
3584 wtoken.hidden = false;
3585 wtoken.hiddenRequested = false;
3586 wtoken.willBeHidden = false;
3587 }
3588 if (wtoken.clientHidden != ttoken.clientHidden) {
3589 wtoken.clientHidden = ttoken.clientHidden;
3590 wtoken.sendAppVisibilityToClients();
3591 }
3592 if (ttoken.animation != null) {
3593 wtoken.animation = ttoken.animation;
3594 wtoken.animating = ttoken.animating;
3595 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3596 ttoken.animation = null;
3597 ttoken.animLayerAdjustment = 0;
3598 wtoken.updateLayers();
3599 ttoken.updateLayers();
3600 }
Romain Guy06882f82009-06-10 13:36:04 -07003601
Jeff Brown3a22cd92011-01-21 13:59:04 -08003602 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3603 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 mLayoutNeeded = true;
3605 performLayoutAndPlaceSurfacesLocked();
3606 Binder.restoreCallingIdentity(origId);
3607 return;
3608 } else if (ttoken.startingData != null) {
3609 // The previous app was getting ready to show a
3610 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003611 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 "Moving pending starting from " + ttoken
3613 + " to " + wtoken);
3614 wtoken.startingData = ttoken.startingData;
3615 ttoken.startingData = null;
3616 ttoken.startingMoved = true;
3617 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3618 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3619 // want to process the message ASAP, before any other queued
3620 // messages.
3621 mH.sendMessageAtFrontOfQueue(m);
3622 return;
3623 }
3624 }
3625 }
3626
3627 // There is no existing starting window, and the caller doesn't
3628 // want us to create one, so that's it!
3629 if (!createIfNeeded) {
3630 return;
3631 }
Romain Guy06882f82009-06-10 13:36:04 -07003632
Dianne Hackborn284ac932009-08-28 10:34:25 -07003633 // If this is a translucent or wallpaper window, then don't
3634 // show a starting window -- the current effect (a full-screen
3635 // opaque starting window that fades away to the real contents
3636 // when it is ready) does not work for this.
3637 if (theme != 0) {
3638 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3639 com.android.internal.R.styleable.Window);
3640 if (ent.array.getBoolean(
3641 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3642 return;
3643 }
3644 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003645 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3646 return;
3647 }
3648 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003649 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3650 return;
3651 }
3652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 mStartingIconInTransition = true;
3655 wtoken.startingData = new StartingData(
3656 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003657 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3659 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3660 // want to process the message ASAP, before any other queued
3661 // messages.
3662 mH.sendMessageAtFrontOfQueue(m);
3663 }
3664 }
3665
3666 public void setAppWillBeHidden(IBinder token) {
3667 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3668 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003669 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 }
3671
3672 AppWindowToken wtoken;
3673
3674 synchronized(mWindowMap) {
3675 wtoken = findAppWindowToken(token);
3676 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003677 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 -08003678 return;
3679 }
3680 wtoken.willBeHidden = true;
3681 }
3682 }
Romain Guy06882f82009-06-10 13:36:04 -07003683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3685 boolean visible, int transit, boolean performLayout) {
3686 boolean delayed = false;
3687
3688 if (wtoken.clientHidden == visible) {
3689 wtoken.clientHidden = !visible;
3690 wtoken.sendAppVisibilityToClients();
3691 }
Romain Guy06882f82009-06-10 13:36:04 -07003692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003693 wtoken.willBeHidden = false;
3694 if (wtoken.hidden == visible) {
3695 final int N = wtoken.allAppWindows.size();
3696 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003697 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3699 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003702
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003703 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 if (wtoken.animation == sDummyAnimation) {
3705 wtoken.animation = null;
3706 }
3707 applyAnimationLocked(wtoken, lp, transit, visible);
3708 changed = true;
3709 if (wtoken.animation != null) {
3710 delayed = runningAppAnimation = true;
3711 }
3712 }
Romain Guy06882f82009-06-10 13:36:04 -07003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 for (int i=0; i<N; i++) {
3715 WindowState win = wtoken.allAppWindows.get(i);
3716 if (win == wtoken.startingWindow) {
3717 continue;
3718 }
3719
3720 if (win.isAnimating()) {
3721 delayed = true;
3722 }
Romain Guy06882f82009-06-10 13:36:04 -07003723
Joe Onorato8a9b2202010-02-26 18:56:32 -08003724 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 //win.dump(" ");
3726 if (visible) {
3727 if (!win.isVisibleNow()) {
3728 if (!runningAppAnimation) {
3729 applyAnimationLocked(win,
3730 WindowManagerPolicy.TRANSIT_ENTER, true);
3731 }
3732 changed = true;
3733 }
3734 } else if (win.isVisibleNow()) {
3735 if (!runningAppAnimation) {
3736 applyAnimationLocked(win,
3737 WindowManagerPolicy.TRANSIT_EXIT, false);
3738 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 changed = true;
3740 }
3741 }
3742
3743 wtoken.hidden = wtoken.hiddenRequested = !visible;
3744 if (!visible) {
3745 unsetAppFreezingScreenLocked(wtoken, true, true);
3746 } else {
3747 // If we are being set visible, and the starting window is
3748 // not yet displayed, then make sure it doesn't get displayed.
3749 WindowState swin = wtoken.startingWindow;
3750 if (swin != null && (swin.mDrawPending
3751 || swin.mCommitDrawPending)) {
3752 swin.mPolicyVisibility = false;
3753 swin.mPolicyVisibilityAfterAnim = false;
3754 }
3755 }
Romain Guy06882f82009-06-10 13:36:04 -07003756
Joe Onorato8a9b2202010-02-26 18:56:32 -08003757 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3759 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003760
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003761 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08003763 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003764 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08003765 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3766 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003767 performLayoutAndPlaceSurfacesLocked();
3768 }
Jeff Brown2e44b072011-01-24 15:21:56 -08003769 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 }
3771 }
3772
3773 if (wtoken.animation != null) {
3774 delayed = true;
3775 }
Romain Guy06882f82009-06-10 13:36:04 -07003776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 return delayed;
3778 }
3779
3780 public void setAppVisibility(IBinder token, boolean visible) {
3781 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3782 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003783 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 }
3785
3786 AppWindowToken wtoken;
3787
3788 synchronized(mWindowMap) {
3789 wtoken = findAppWindowToken(token);
3790 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003791 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 return;
3793 }
3794
3795 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003796 RuntimeException e = null;
3797 if (!HIDE_STACK_CRAWLS) {
3798 e = new RuntimeException();
3799 e.fillInStackTrace();
3800 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003801 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 + "): mNextAppTransition=" + mNextAppTransition
3803 + " hidden=" + wtoken.hidden
3804 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3805 }
Romain Guy06882f82009-06-10 13:36:04 -07003806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 // If we are preparing an app transition, then delay changing
3808 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003809 if (!mDisplayFrozen && mPolicy.isScreenOn()
3810 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 // Already in requested state, don't do anything more.
3812 if (wtoken.hiddenRequested != visible) {
3813 return;
3814 }
3815 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003816
Joe Onorato8a9b2202010-02-26 18:56:32 -08003817 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 TAG, "Setting dummy animation on: " + wtoken);
3819 wtoken.setDummyAnimation();
3820 mOpeningApps.remove(wtoken);
3821 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003822 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 wtoken.inPendingTransaction = true;
3824 if (visible) {
3825 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 wtoken.startingDisplayed = false;
3827 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003828
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003829 // If the token is currently hidden (should be the
3830 // common case), then we need to set up to wait for
3831 // its windows to be ready.
3832 if (wtoken.hidden) {
3833 wtoken.allDrawn = false;
3834 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003835
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003836 if (wtoken.clientHidden) {
3837 // In the case where we are making an app visible
3838 // but holding off for a transition, we still need
3839 // to tell the client to make its windows visible so
3840 // they get drawn. Otherwise, we will wait on
3841 // performing the transition until all windows have
3842 // been drawn, they never will be, and we are sad.
3843 wtoken.clientHidden = false;
3844 wtoken.sendAppVisibilityToClients();
3845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 }
3847 } else {
3848 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003849
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003850 // If the token is currently visible (should be the
3851 // common case), then set up to wait for it to be hidden.
3852 if (!wtoken.hidden) {
3853 wtoken.waitingToHide = true;
3854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 }
3856 return;
3857 }
Romain Guy06882f82009-06-10 13:36:04 -07003858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003860 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003861 wtoken.updateReportedVisibilityLocked();
3862 Binder.restoreCallingIdentity(origId);
3863 }
3864 }
3865
3866 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3867 boolean unfreezeSurfaceNow, boolean force) {
3868 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003869 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003870 + " force=" + force);
3871 final int N = wtoken.allAppWindows.size();
3872 boolean unfrozeWindows = false;
3873 for (int i=0; i<N; i++) {
3874 WindowState w = wtoken.allAppWindows.get(i);
3875 if (w.mAppFreezing) {
3876 w.mAppFreezing = false;
3877 if (w.mSurface != null && !w.mOrientationChanging) {
3878 w.mOrientationChanging = true;
3879 }
3880 unfrozeWindows = true;
3881 }
3882 }
3883 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003884 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 wtoken.freezingScreen = false;
3886 mAppsFreezingScreen--;
3887 }
3888 if (unfreezeSurfaceNow) {
3889 if (unfrozeWindows) {
3890 mLayoutNeeded = true;
3891 performLayoutAndPlaceSurfacesLocked();
3892 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003893 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 }
3895 }
3896 }
Romain Guy06882f82009-06-10 13:36:04 -07003897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003898 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3899 int configChanges) {
3900 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003901 RuntimeException e = null;
3902 if (!HIDE_STACK_CRAWLS) {
3903 e = new RuntimeException();
3904 e.fillInStackTrace();
3905 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 + ": hidden=" + wtoken.hidden + " freezing="
3908 + wtoken.freezingScreen, e);
3909 }
3910 if (!wtoken.hiddenRequested) {
3911 if (!wtoken.freezingScreen) {
3912 wtoken.freezingScreen = true;
3913 mAppsFreezingScreen++;
3914 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003915 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3917 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3918 5000);
3919 }
3920 }
3921 final int N = wtoken.allAppWindows.size();
3922 for (int i=0; i<N; i++) {
3923 WindowState w = wtoken.allAppWindows.get(i);
3924 w.mAppFreezing = true;
3925 }
3926 }
3927 }
Romain Guy06882f82009-06-10 13:36:04 -07003928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 public void startAppFreezingScreen(IBinder token, int configChanges) {
3930 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3931 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003932 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 }
3934
3935 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003936 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003937 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938 return;
3939 }
Romain Guy06882f82009-06-10 13:36:04 -07003940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003941 AppWindowToken wtoken = findAppWindowToken(token);
3942 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003943 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944 return;
3945 }
3946 final long origId = Binder.clearCallingIdentity();
3947 startAppFreezingScreenLocked(wtoken, configChanges);
3948 Binder.restoreCallingIdentity(origId);
3949 }
3950 }
Romain Guy06882f82009-06-10 13:36:04 -07003951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 public void stopAppFreezingScreen(IBinder token, boolean force) {
3953 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3954 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003955 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956 }
3957
3958 synchronized(mWindowMap) {
3959 AppWindowToken wtoken = findAppWindowToken(token);
3960 if (wtoken == null || wtoken.appToken == null) {
3961 return;
3962 }
3963 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003964 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3966 unsetAppFreezingScreenLocked(wtoken, true, force);
3967 Binder.restoreCallingIdentity(origId);
3968 }
3969 }
Romain Guy06882f82009-06-10 13:36:04 -07003970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 public void removeAppToken(IBinder token) {
3972 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3973 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003974 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 }
3976
3977 AppWindowToken wtoken = null;
3978 AppWindowToken startingToken = null;
3979 boolean delayed = false;
3980
3981 final long origId = Binder.clearCallingIdentity();
3982 synchronized(mWindowMap) {
3983 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003984 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003985 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003986 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 wtoken.inPendingTransaction = false;
3988 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003989 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 if (mClosingApps.contains(wtoken)) {
3991 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003992 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003994 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 delayed = true;
3996 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003997 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 TAG, "Removing app " + wtoken + " delayed=" + delayed
3999 + " animation=" + wtoken.animation
4000 + " animating=" + wtoken.animating);
4001 if (delayed) {
4002 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004003 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4004 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004006 } else {
4007 // Make sure there is no animation running on this token,
4008 // so any windows associated with it will be removed as
4009 // soon as their animations are complete
4010 wtoken.animation = null;
4011 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004013 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4014 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 mAppTokens.remove(wtoken);
4016 wtoken.removed = true;
4017 if (wtoken.startingData != null) {
4018 startingToken = wtoken;
4019 }
4020 unsetAppFreezingScreenLocked(wtoken, true, true);
4021 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004022 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004024 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004025 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004026 }
4027 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004028 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 }
Romain Guy06882f82009-06-10 13:36:04 -07004030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 if (!delayed && wtoken != null) {
4032 wtoken.updateReportedVisibilityLocked();
4033 }
4034 }
4035 Binder.restoreCallingIdentity(origId);
4036
4037 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004038 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004039 + startingToken + ": app token removed");
4040 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4041 mH.sendMessage(m);
4042 }
4043 }
4044
4045 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4046 final int NW = token.windows.size();
4047 for (int i=0; i<NW; i++) {
4048 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004049 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004051 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004052 int j = win.mChildWindows.size();
4053 while (j > 0) {
4054 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004055 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004056 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004057 "Tmp removing child window " + cwin);
4058 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004059 }
4060 }
4061 return NW > 0;
4062 }
4063
4064 void dumpAppTokensLocked() {
4065 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004066 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 }
4068 }
Romain Guy06882f82009-06-10 13:36:04 -07004069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004070 void dumpWindowsLocked() {
4071 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004072 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004073 }
4074 }
Romain Guy06882f82009-06-10 13:36:04 -07004075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 private int findWindowOffsetLocked(int tokenPos) {
4077 final int NW = mWindows.size();
4078
4079 if (tokenPos >= mAppTokens.size()) {
4080 int i = NW;
4081 while (i > 0) {
4082 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004083 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 if (win.getAppToken() != null) {
4085 return i+1;
4086 }
4087 }
4088 }
4089
4090 while (tokenPos > 0) {
4091 // Find the first app token below the new position that has
4092 // a window displayed.
4093 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004094 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004095 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004096 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004097 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004098 "Skipping token -- currently sending to bottom");
4099 tokenPos--;
4100 continue;
4101 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 int i = wtoken.windows.size();
4103 while (i > 0) {
4104 i--;
4105 WindowState win = wtoken.windows.get(i);
4106 int j = win.mChildWindows.size();
4107 while (j > 0) {
4108 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004109 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004110 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 for (int pos=NW-1; pos>=0; pos--) {
4112 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004113 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 "Found child win @" + (pos+1));
4115 return pos+1;
4116 }
4117 }
4118 }
4119 }
4120 for (int pos=NW-1; pos>=0; pos--) {
4121 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004122 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 return pos+1;
4124 }
4125 }
4126 }
4127 tokenPos--;
4128 }
4129
4130 return 0;
4131 }
4132
4133 private final int reAddWindowLocked(int index, WindowState win) {
4134 final int NCW = win.mChildWindows.size();
4135 boolean added = false;
4136 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004137 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004138 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004139 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004140 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004141 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004142 mWindows.add(index, win);
4143 index++;
4144 added = true;
4145 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004146 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004147 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004148 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 mWindows.add(index, cwin);
4150 index++;
4151 }
4152 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004153 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004154 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004155 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004156 mWindows.add(index, win);
4157 index++;
4158 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004159 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 return index;
4161 }
Romain Guy06882f82009-06-10 13:36:04 -07004162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4164 final int NW = token.windows.size();
4165 for (int i=0; i<NW; i++) {
4166 index = reAddWindowLocked(index, token.windows.get(i));
4167 }
4168 return index;
4169 }
4170
4171 public void moveAppToken(int index, IBinder token) {
4172 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4173 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004174 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 }
4176
4177 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004178 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 if (DEBUG_REORDER) dumpAppTokensLocked();
4180 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004181 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4182 "Start moving token " + wtoken + " initially at "
4183 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004185 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 + token + " (" + wtoken + ")");
4187 return;
4188 }
4189 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004190 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004191 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004195 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004196 if (DEBUG_REORDER) dumpWindowsLocked();
4197 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004198 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 if (DEBUG_REORDER) dumpWindowsLocked();
4200 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004201 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004203 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4204 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004206 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004208 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 }
4210 Binder.restoreCallingIdentity(origId);
4211 }
4212 }
4213
4214 private void removeAppTokensLocked(List<IBinder> tokens) {
4215 // XXX This should be done more efficiently!
4216 // (take advantage of the fact that both lists should be
4217 // ordered in the same way.)
4218 int N = tokens.size();
4219 for (int i=0; i<N; i++) {
4220 IBinder token = tokens.get(i);
4221 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004222 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4223 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004224 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004225 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 + token + " (" + wtoken + ")");
4227 i--;
4228 N--;
4229 }
4230 }
4231 }
4232
Dianne Hackborna8f60182009-09-01 19:01:50 -07004233 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4234 boolean updateFocusAndLayout) {
4235 // First remove all of the windows from the list.
4236 tmpRemoveAppWindowsLocked(wtoken);
4237
4238 // Where to start adding?
4239 int pos = findWindowOffsetLocked(tokenPos);
4240
4241 // And now add them back at the correct place.
4242 pos = reAddAppWindowsLocked(pos, wtoken);
4243
4244 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004245 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004246 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4247 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004248 assignLayersLocked();
4249 }
4250 mLayoutNeeded = true;
4251 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004252 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004253 }
4254 }
4255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004256 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4257 // First remove all of the windows from the list.
4258 final int N = tokens.size();
4259 int i;
4260 for (i=0; i<N; i++) {
4261 WindowToken token = mTokenMap.get(tokens.get(i));
4262 if (token != null) {
4263 tmpRemoveAppWindowsLocked(token);
4264 }
4265 }
4266
4267 // Where to start adding?
4268 int pos = findWindowOffsetLocked(tokenPos);
4269
4270 // And now add them back at the correct place.
4271 for (i=0; i<N; i++) {
4272 WindowToken token = mTokenMap.get(tokens.get(i));
4273 if (token != null) {
4274 pos = reAddAppWindowsLocked(pos, token);
4275 }
4276 }
4277
Jeff Brown2e44b072011-01-24 15:21:56 -08004278 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004279 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4280 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004281 assignLayersLocked();
4282 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004283 mLayoutNeeded = true;
4284 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004285 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286
4287 //dump();
4288 }
4289
4290 public void moveAppTokensToTop(List<IBinder> tokens) {
4291 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4292 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004293 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 }
4295
4296 final long origId = Binder.clearCallingIdentity();
4297 synchronized(mWindowMap) {
4298 removeAppTokensLocked(tokens);
4299 final int N = tokens.size();
4300 for (int i=0; i<N; i++) {
4301 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4302 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004303 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4304 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004306 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004307 mToTopApps.remove(wt);
4308 mToBottomApps.remove(wt);
4309 mToTopApps.add(wt);
4310 wt.sendingToBottom = false;
4311 wt.sendingToTop = true;
4312 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 }
4314 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004315
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004316 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004317 moveAppWindowsLocked(tokens, mAppTokens.size());
4318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 }
4320 Binder.restoreCallingIdentity(origId);
4321 }
4322
4323 public void moveAppTokensToBottom(List<IBinder> tokens) {
4324 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4325 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004326 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 }
4328
4329 final long origId = Binder.clearCallingIdentity();
4330 synchronized(mWindowMap) {
4331 removeAppTokensLocked(tokens);
4332 final int N = tokens.size();
4333 int pos = 0;
4334 for (int i=0; i<N; i++) {
4335 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4336 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004337 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4338 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004340 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004341 mToTopApps.remove(wt);
4342 mToBottomApps.remove(wt);
4343 mToBottomApps.add(i, wt);
4344 wt.sendingToTop = false;
4345 wt.sendingToBottom = true;
4346 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 pos++;
4348 }
4349 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004350
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004351 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004352 moveAppWindowsLocked(tokens, 0);
4353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 }
4355 Binder.restoreCallingIdentity(origId);
4356 }
4357
4358 // -------------------------------------------------------------
4359 // Misc IWindowSession methods
4360 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004361
Jim Miller284b62e2010-06-08 14:27:42 -07004362 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004363 {
Jim Miller284b62e2010-06-08 14:27:42 -07004364 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4365 // called before DevicePolicyManagerService has started.
4366 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4367 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4368 Context.DEVICE_POLICY_SERVICE);
4369 if (dpm != null) {
4370 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4371 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4372 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4373 }
Jim Millerd6b57052010-06-07 17:52:42 -07004374 }
Jim Miller284b62e2010-06-08 14:27:42 -07004375 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004376 }
4377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004379 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004380 != PackageManager.PERMISSION_GRANTED) {
4381 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4382 }
Jim Millerd6b57052010-06-07 17:52:42 -07004383
Jim Miller284b62e2010-06-08 14:27:42 -07004384 synchronized (mKeyguardTokenWatcher) {
4385 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004386 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 }
4388
4389 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004390 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004391 != PackageManager.PERMISSION_GRANTED) {
4392 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394
Jim Miller284b62e2010-06-08 14:27:42 -07004395 synchronized (mKeyguardTokenWatcher) {
4396 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004397
Jim Miller284b62e2010-06-08 14:27:42 -07004398 if (!mKeyguardTokenWatcher.isAcquired()) {
4399 // If we are the last one to reenable the keyguard wait until
4400 // we have actually finished reenabling until returning.
4401 // It is possible that reenableKeyguard() can be called before
4402 // the previous disableKeyguard() is handled, in which case
4403 // neither mKeyguardTokenWatcher.acquired() or released() would
4404 // be called. In that case mKeyguardDisabled will be false here
4405 // and we have nothing to wait for.
4406 while (mKeyguardDisabled) {
4407 try {
4408 mKeyguardTokenWatcher.wait();
4409 } catch (InterruptedException e) {
4410 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 }
4412 }
4413 }
4414 }
4415 }
4416
4417 /**
4418 * @see android.app.KeyguardManager#exitKeyguardSecurely
4419 */
4420 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004421 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004422 != PackageManager.PERMISSION_GRANTED) {
4423 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4424 }
4425 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4426 public void onKeyguardExitResult(boolean success) {
4427 try {
4428 callback.onKeyguardExitResult(success);
4429 } catch (RemoteException e) {
4430 // Client has died, we don't care.
4431 }
4432 }
4433 });
4434 }
4435
4436 public boolean inKeyguardRestrictedInputMode() {
4437 return mPolicy.inKeyguardRestrictedKeyInputMode();
4438 }
Romain Guy06882f82009-06-10 13:36:04 -07004439
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004440 public boolean isKeyguardLocked() {
4441 return mPolicy.isKeyguardLocked();
4442 }
4443
4444 public boolean isKeyguardSecure() {
4445 return mPolicy.isKeyguardSecure();
4446 }
4447
Dianne Hackbornffa42482009-09-23 22:20:11 -07004448 public void closeSystemDialogs(String reason) {
4449 synchronized(mWindowMap) {
4450 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004451 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004452 if (w.mSurface != null) {
4453 try {
4454 w.mClient.closeSystemDialogs(reason);
4455 } catch (RemoteException e) {
4456 }
4457 }
4458 }
4459 }
4460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 static float fixScale(float scale) {
4463 if (scale < 0) scale = 0;
4464 else if (scale > 20) scale = 20;
4465 return Math.abs(scale);
4466 }
Romain Guy06882f82009-06-10 13:36:04 -07004467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004468 public void setAnimationScale(int which, float scale) {
4469 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4470 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004471 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
4473
4474 if (scale < 0) scale = 0;
4475 else if (scale > 20) scale = 20;
4476 scale = Math.abs(scale);
4477 switch (which) {
4478 case 0: mWindowAnimationScale = fixScale(scale); break;
4479 case 1: mTransitionAnimationScale = fixScale(scale); break;
4480 }
Romain Guy06882f82009-06-10 13:36:04 -07004481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 // Persist setting
4483 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4484 }
Romain Guy06882f82009-06-10 13:36:04 -07004485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 public void setAnimationScales(float[] scales) {
4487 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4488 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004489 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 }
4491
4492 if (scales != null) {
4493 if (scales.length >= 1) {
4494 mWindowAnimationScale = fixScale(scales[0]);
4495 }
4496 if (scales.length >= 2) {
4497 mTransitionAnimationScale = fixScale(scales[1]);
4498 }
4499 }
Romain Guy06882f82009-06-10 13:36:04 -07004500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 // Persist setting
4502 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4503 }
Romain Guy06882f82009-06-10 13:36:04 -07004504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 public float getAnimationScale(int which) {
4506 switch (which) {
4507 case 0: return mWindowAnimationScale;
4508 case 1: return mTransitionAnimationScale;
4509 }
4510 return 0;
4511 }
Romain Guy06882f82009-06-10 13:36:04 -07004512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 public float[] getAnimationScales() {
4514 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4515 }
Romain Guy06882f82009-06-10 13:36:04 -07004516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 public int getSwitchState(int sw) {
4518 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4519 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004520 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004522 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 }
Romain Guy06882f82009-06-10 13:36:04 -07004524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 public int getSwitchStateForDevice(int devid, int sw) {
4526 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4527 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004528 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004530 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 }
Romain Guy06882f82009-06-10 13:36:04 -07004532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004533 public int getScancodeState(int sw) {
4534 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4535 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004536 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004537 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004538 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004539 }
Romain Guy06882f82009-06-10 13:36:04 -07004540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004541 public int getScancodeStateForDevice(int devid, int sw) {
4542 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4543 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004544 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004545 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004546 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 }
Romain Guy06882f82009-06-10 13:36:04 -07004548
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004549 public int getTrackballScancodeState(int sw) {
4550 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4551 "getTrackballScancodeState()")) {
4552 throw new SecurityException("Requires READ_INPUT_STATE permission");
4553 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004554 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004555 }
4556
4557 public int getDPadScancodeState(int sw) {
4558 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4559 "getDPadScancodeState()")) {
4560 throw new SecurityException("Requires READ_INPUT_STATE permission");
4561 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004562 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004563 }
4564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 public int getKeycodeState(int sw) {
4566 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4567 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004568 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004569 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004570 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 }
Romain Guy06882f82009-06-10 13:36:04 -07004572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 public int getKeycodeStateForDevice(int devid, int sw) {
4574 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4575 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004576 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004577 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004578 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 }
Romain Guy06882f82009-06-10 13:36:04 -07004580
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004581 public int getTrackballKeycodeState(int sw) {
4582 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4583 "getTrackballKeycodeState()")) {
4584 throw new SecurityException("Requires READ_INPUT_STATE permission");
4585 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004586 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004587 }
4588
4589 public int getDPadKeycodeState(int sw) {
4590 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4591 "getDPadKeycodeState()")) {
4592 throw new SecurityException("Requires READ_INPUT_STATE permission");
4593 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004594 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004595 }
Jeff Browna41ca772010-08-11 14:46:32 -07004596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004597 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004598 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004599 }
Romain Guy06882f82009-06-10 13:36:04 -07004600
Jeff Browna41ca772010-08-11 14:46:32 -07004601 public InputChannel monitorInput(String inputChannelName) {
4602 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4603 "monitorInput()")) {
4604 throw new SecurityException("Requires READ_INPUT_STATE permission");
4605 }
4606 return mInputManager.monitorInput(inputChannelName);
4607 }
4608
Jeff Brown0029c662011-03-30 02:25:18 -07004609 public void setInputFilter(InputFilter filter) {
4610 mInputManager.setInputFilter(filter);
4611 }
4612
Jeff Brown8d608662010-08-30 03:02:23 -07004613 public InputDevice getInputDevice(int deviceId) {
4614 return mInputManager.getInputDevice(deviceId);
4615 }
4616
4617 public int[] getInputDeviceIds() {
4618 return mInputManager.getInputDeviceIds();
4619 }
4620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 public void enableScreenAfterBoot() {
4622 synchronized(mWindowMap) {
4623 if (mSystemBooted) {
4624 return;
4625 }
4626 mSystemBooted = true;
4627 }
Romain Guy06882f82009-06-10 13:36:04 -07004628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004629 performEnableScreen();
4630 }
Romain Guy06882f82009-06-10 13:36:04 -07004631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632 public void enableScreenIfNeededLocked() {
4633 if (mDisplayEnabled) {
4634 return;
4635 }
4636 if (!mSystemBooted) {
4637 return;
4638 }
4639 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4640 }
Romain Guy06882f82009-06-10 13:36:04 -07004641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 public void performEnableScreen() {
4643 synchronized(mWindowMap) {
4644 if (mDisplayEnabled) {
4645 return;
4646 }
4647 if (!mSystemBooted) {
4648 return;
4649 }
Romain Guy06882f82009-06-10 13:36:04 -07004650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 // Don't enable the screen until all existing windows
4652 // have been drawn.
4653 final int N = mWindows.size();
4654 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004655 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004656 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 return;
4658 }
4659 }
Romain Guy06882f82009-06-10 13:36:04 -07004660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 mDisplayEnabled = true;
4662 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004663 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 StringWriter sw = new StringWriter();
4665 PrintWriter pw = new PrintWriter(sw);
4666 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004667 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004668 }
4669 try {
4670 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4671 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004672 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004673 Parcel data = Parcel.obtain();
4674 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4675 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4676 data, null, 0);
4677 data.recycle();
4678 }
4679 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004680 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 }
4682 }
Romain Guy06882f82009-06-10 13:36:04 -07004683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004687 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4688 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 }
Romain Guy06882f82009-06-10 13:36:04 -07004690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004691 public void setInTouchMode(boolean mode) {
4692 synchronized(mWindowMap) {
4693 mInTouchMode = mode;
4694 }
4695 }
4696
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004697 // TODO: more accounting of which pid(s) turned it on, keep count,
4698 // only allow disables from pids which have count on, etc.
4699 public void showStrictModeViolation(boolean on) {
4700 int pid = Binder.getCallingPid();
4701 synchronized(mWindowMap) {
4702 // Ignoring requests to enable the red border from clients
4703 // which aren't on screen. (e.g. Broadcast Receivers in
4704 // the background..)
4705 if (on) {
4706 boolean isVisible = false;
4707 for (WindowState ws : mWindows) {
4708 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4709 isVisible = true;
4710 break;
4711 }
4712 }
4713 if (!isVisible) {
4714 return;
4715 }
4716 }
4717
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004718 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004719 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004720 try {
4721 if (mStrictModeFlash == null) {
4722 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4723 }
4724 mStrictModeFlash.setVisibility(on);
4725 } finally {
4726 Surface.closeTransaction();
4727 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004728 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004729 }
4730 }
4731
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004732 public void setStrictModeVisualIndicatorPreference(String value) {
4733 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4734 }
4735
Jim Millere70d5062011-03-08 21:38:39 -08004736 /**
4737 * Takes a snapshot of the screen. In landscape mode this grabs the whole screen.
4738 * In portrait mode, it grabs the upper region of the screen based on the vertical dimension
4739 * of the target image.
4740 *
4741 * @param width the width of the target bitmap
4742 * @param height the height of the target bitmap
4743 */
4744 public Bitmap screenshotApplications(IBinder appToken, int width, int height) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004745 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4746 "screenshotApplications()")) {
4747 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
4748 }
4749
4750 Bitmap rawss;
4751
Dianne Hackbornd2835932010-12-13 16:28:46 -08004752 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004753 final Rect frame = new Rect();
4754
4755 float scale;
Jim Millere70d5062011-03-08 21:38:39 -08004756 int dw, dh;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004757 int rot;
4758
4759 synchronized(mWindowMap) {
4760 long ident = Binder.clearCallingIdentity();
4761
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07004762 dw = mCurDisplayWidth;
4763 dh = mCurDisplayHeight;
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004764
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004765 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
4766 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
4767 + TYPE_LAYER_OFFSET;
4768 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
4769
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004770 boolean isImeTarget = mInputMethodTarget != null
4771 && mInputMethodTarget.mAppToken != null
4772 && mInputMethodTarget.mAppToken.appToken != null
4773 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
4774
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004775 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004776 boolean including = false;
4777 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004778 WindowState ws = mWindows.get(i);
4779 if (ws.mSurface == null) {
4780 continue;
4781 }
4782 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08004783 continue;
4784 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004785 // When we will skip windows: when we are not including
4786 // ones behind a window we didn't skip, and we are actually
4787 // taking a screenshot of a specific app.
4788 if (!including && appToken != null) {
4789 // Also, we can possibly skip this window if it is not
4790 // an IME target or the application for the screenshot
4791 // is not the current IME target.
4792 if (!ws.mIsImWindow || !isImeTarget) {
4793 // And finally, this window is of no interest if it
4794 // is not associated with the screenshot app.
4795 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
4796 continue;
4797 }
4798 }
4799 }
4800
4801 // We keep on including windows until we go past a full-screen
4802 // window.
4803 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
4804
Dianne Hackbornd2835932010-12-13 16:28:46 -08004805 if (maxLayer < ws.mAnimLayer) {
4806 maxLayer = ws.mAnimLayer;
4807 }
Jim Miller2aded182011-03-08 15:32:42 -08004808
4809 // Don't include wallpaper in bounds calculation
4810 if (!ws.mIsWallpaper) {
4811 final Rect wf = ws.mFrame;
4812 final Rect cr = ws.mContentInsets;
4813 int left = wf.left + cr.left;
4814 int top = wf.top + cr.top;
4815 int right = wf.right - cr.right;
4816 int bottom = wf.bottom - cr.bottom;
4817 frame.union(left, top, right, bottom);
4818 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004819 }
4820 Binder.restoreCallingIdentity(ident);
4821
Dianne Hackborndd962ee2011-02-02 11:11:50 -08004822 // Constrain frame to the screen size.
4823 frame.intersect(0, 0, dw, dh);
Jim Millere70d5062011-03-08 21:38:39 -08004824
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004825 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004826 return null;
4827 }
4828
4829 // The screenshot API does not apply the current screen rotation.
4830 rot = mDisplay.getRotation();
4831 int fw = frame.width();
4832 int fh = frame.height();
4833
4834 // First try reducing to fit in x dimension.
Jim Millere70d5062011-03-08 21:38:39 -08004835 scale = width/(float)fw;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004836
4837 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004838 dw = (int)(dw*scale);
4839 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004840 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
4841 int tmp = dw;
4842 dw = dh;
4843 dh = tmp;
4844 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
4845 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08004846 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004847 }
4848
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004849 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08004850 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
4851 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004852 return null;
4853 }
Jim Millere70d5062011-03-08 21:38:39 -08004854
4855 Bitmap bm = Bitmap.createBitmap(width, height, rawss.getConfig());
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004856 Matrix matrix = new Matrix();
4857 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
4858 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
4859 Canvas canvas = new Canvas(bm);
4860 canvas.drawBitmap(rawss, matrix, null);
4861
4862 rawss.recycle();
4863 return bm;
4864 }
4865
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004866 public void freezeRotation() {
4867 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004868 "freezeRotation()")) {
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004869 throw new SecurityException("Requires SET_ORIENTATION permission");
4870 }
4871
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004872 if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation);
4873
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004874 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4875 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4876 }
4877
4878 public void thawRotation() {
4879 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004880 "thawRotation()")) {
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004881 throw new SecurityException("Requires SET_ORIENTATION permission");
4882 }
4883
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004884 if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation);
4885
4886 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 777); // rot not used
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004887 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4888 }
4889
Romain Guy06882f82009-06-10 13:36:04 -07004890 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004891 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004892 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004893 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004894 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 }
4896
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004897 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004898 }
Romain Guy06882f82009-06-10 13:36:04 -07004899
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004900 public void setRotationUnchecked(int rotation,
4901 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004902 if(DEBUG_ORIENTATION) Slog.v(TAG,
David 'Digit' Turner910a0682011-02-05 00:34:46 +01004903 "setRotationUnchecked(rotation=" + rotation +
4904 " alwaysSendConfiguration=" + alwaysSendConfiguration +
4905 " animFlags=" + animFlags);
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 Hackborn94cb2eb2011-01-13 21:09:44 -08004910 changed = setRotationUncheckedLocked(rotation, animFlags, false);
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 Hackborn94cb2eb2011-01-13 21:09:44 -08004928 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004929 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08004930 // Potential rotation during a drag. Don't do the rotation now, but make
4931 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004932 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
4933 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
4934 mDeferredRotation = rotation;
4935 mDeferredRotationAnimFlags = animFlags;
4936 }
Christopher Tateccd24de2011-01-12 15:02:55 -08004937 return false;
4938 }
4939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004940 boolean changed;
4941 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004942 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
4943 rotation = mDeferredRotation;
4944 mRequestedRotation = rotation;
4945 mLastRotationFlags = mDeferredRotationAnimFlags;
4946 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 rotation = mRequestedRotation;
4948 } else {
4949 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004950 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004951 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004952 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08004953 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004954 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004956 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004957 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004960 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004961 "Rotation changed to " + rotation
4962 + " from " + mRotation
4963 + " (forceApp=" + mForcedAppOrientation
4964 + ", req=" + mRequestedRotation + ")");
4965 mRotation = rotation;
4966 mWindowsFreezingScreen = true;
4967 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4968 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4969 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004970 mWaitingForConfig = true;
4971 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004972 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004973 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004974 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 if (mDisplayEnabled) {
David 'Digit' Turner910a0682011-02-05 00:34:46 +01004976 // NOTE: We disable the rotation in the emulator because
4977 // it doesn't support hardware OpenGL emulation yet.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08004978 if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
4979 && mScreenRotationAnimation.hasScreenshot()) {
Dianne Hackborna1111872010-11-23 20:55:11 -08004980 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004981 if (!inTransaction) {
4982 if (SHOW_TRANSACTIONS) Slog.i(TAG,
4983 ">>> OPEN TRANSACTION setRotationUnchecked");
4984 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08004985 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004986 try {
4987 if (mScreenRotationAnimation != null) {
4988 mScreenRotationAnimation.setRotation(rotation);
4989 }
4990 } finally {
4991 if (!inTransaction) {
4992 Surface.closeTransaction();
4993 if (SHOW_TRANSACTIONS) Slog.i(TAG,
4994 "<<< CLOSE TRANSACTION setRotationUnchecked");
4995 }
4996 }
Dianne Hackborna1111872010-11-23 20:55:11 -08004997 Surface.setOrientation(0, rotation, animFlags);
4998 Surface.unfreezeDisplay(0);
4999 } else {
5000 Surface.setOrientation(0, rotation, animFlags);
5001 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005002 }
5003 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005004 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005005 if (w.mSurface != null) {
5006 w.mOrientationChanging = true;
5007 }
5008 }
5009 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5010 try {
5011 mRotationWatchers.get(i).onRotationChanged(rotation);
5012 } catch (RemoteException e) {
5013 }
5014 }
5015 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005017 return changed;
5018 }
Romain Guy06882f82009-06-10 13:36:04 -07005019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005020 public int getRotation() {
5021 return mRotation;
5022 }
5023
5024 public int watchRotation(IRotationWatcher watcher) {
5025 final IBinder watcherBinder = watcher.asBinder();
5026 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5027 public void binderDied() {
5028 synchronized (mWindowMap) {
5029 for (int i=0; i<mRotationWatchers.size(); i++) {
5030 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005031 IRotationWatcher removed = mRotationWatchers.remove(i);
5032 if (removed != null) {
5033 removed.asBinder().unlinkToDeath(this, 0);
5034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 i--;
5036 }
5037 }
5038 }
5039 }
5040 };
Romain Guy06882f82009-06-10 13:36:04 -07005041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005042 synchronized (mWindowMap) {
5043 try {
5044 watcher.asBinder().linkToDeath(dr, 0);
5045 mRotationWatchers.add(watcher);
5046 } catch (RemoteException e) {
5047 // Client died, no cleanup needed.
5048 }
Romain Guy06882f82009-06-10 13:36:04 -07005049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005050 return mRotation;
5051 }
5052 }
5053
5054 /**
5055 * Starts the view server on the specified port.
5056 *
5057 * @param port The port to listener to.
5058 *
5059 * @return True if the server was successfully started, false otherwise.
5060 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005061 * @see com.android.server.wm.ViewServer
5062 * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005063 */
5064 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005065 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005066 return false;
5067 }
5068
5069 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5070 return false;
5071 }
5072
5073 if (port < 1024) {
5074 return false;
5075 }
5076
5077 if (mViewServer != null) {
5078 if (!mViewServer.isRunning()) {
5079 try {
5080 return mViewServer.start();
5081 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005082 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005083 }
5084 }
5085 return false;
5086 }
5087
5088 try {
5089 mViewServer = new ViewServer(this, port);
5090 return mViewServer.start();
5091 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005092 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005093 }
5094 return false;
5095 }
5096
Romain Guy06882f82009-06-10 13:36:04 -07005097 private boolean isSystemSecure() {
5098 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5099 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5100 }
5101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005102 /**
5103 * Stops the view server if it exists.
5104 *
5105 * @return True if the server stopped, false if it wasn't started or
5106 * couldn't be stopped.
5107 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005108 * @see com.android.server.wm.ViewServer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005109 */
5110 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005111 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005112 return false;
5113 }
5114
5115 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5116 return false;
5117 }
5118
5119 if (mViewServer != null) {
5120 return mViewServer.stop();
5121 }
5122 return false;
5123 }
5124
5125 /**
5126 * Indicates whether the view server is running.
5127 *
5128 * @return True if the server is running, false otherwise.
5129 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005130 * @see com.android.server.wm.ViewServer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005131 */
5132 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005133 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005134 return false;
5135 }
5136
5137 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5138 return false;
5139 }
5140
5141 return mViewServer != null && mViewServer.isRunning();
5142 }
5143
5144 /**
5145 * Lists all availble windows in the system. The listing is written in the
5146 * specified Socket's output stream with the following syntax:
5147 * windowHashCodeInHexadecimal windowName
5148 * Each line of the ouput represents a different window.
5149 *
5150 * @param client The remote client to send the listing to.
5151 * @return False if an error occured, true otherwise.
5152 */
5153 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005154 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005155 return false;
5156 }
5157
5158 boolean result = true;
5159
Jeff Browne33348b2010-07-15 23:54:05 -07005160 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005161 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005162 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005163 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005164 }
5165
5166 BufferedWriter out = null;
5167
5168 // Any uncaught exception will crash the system process
5169 try {
5170 OutputStream clientStream = client.getOutputStream();
5171 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5172
5173 final int count = windows.length;
5174 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005175 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005176 out.write(Integer.toHexString(System.identityHashCode(w)));
5177 out.write(' ');
5178 out.append(w.mAttrs.getTitle());
5179 out.write('\n');
5180 }
5181
5182 out.write("DONE.\n");
5183 out.flush();
5184 } catch (Exception e) {
5185 result = false;
5186 } finally {
5187 if (out != null) {
5188 try {
5189 out.close();
5190 } catch (IOException e) {
5191 result = false;
5192 }
5193 }
5194 }
5195
5196 return result;
5197 }
5198
5199 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005200 * Returns the focused window in the following format:
5201 * windowHashCodeInHexadecimal windowName
5202 *
5203 * @param client The remote client to send the listing to.
5204 * @return False if an error occurred, true otherwise.
5205 */
5206 boolean viewServerGetFocusedWindow(Socket client) {
5207 if (isSystemSecure()) {
5208 return false;
5209 }
5210
5211 boolean result = true;
5212
5213 WindowState focusedWindow = getFocusedWindow();
5214
5215 BufferedWriter out = null;
5216
5217 // Any uncaught exception will crash the system process
5218 try {
5219 OutputStream clientStream = client.getOutputStream();
5220 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5221
5222 if(focusedWindow != null) {
5223 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5224 out.write(' ');
5225 out.append(focusedWindow.mAttrs.getTitle());
5226 }
5227 out.write('\n');
5228 out.flush();
5229 } catch (Exception e) {
5230 result = false;
5231 } finally {
5232 if (out != null) {
5233 try {
5234 out.close();
5235 } catch (IOException e) {
5236 result = false;
5237 }
5238 }
5239 }
5240
5241 return result;
5242 }
5243
5244 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 * Sends a command to a target window. The result of the command, if any, will be
5246 * written in the output stream of the specified socket.
5247 *
5248 * The parameters must follow this syntax:
5249 * windowHashcode extra
5250 *
5251 * Where XX is the length in characeters of the windowTitle.
5252 *
5253 * The first parameter is the target window. The window with the specified hashcode
5254 * will be the target. If no target can be found, nothing happens. The extra parameters
5255 * will be delivered to the target window and as parameters to the command itself.
5256 *
5257 * @param client The remote client to sent the result, if any, to.
5258 * @param command The command to execute.
5259 * @param parameters The command parameters.
5260 *
5261 * @return True if the command was successfully delivered, false otherwise. This does
5262 * not indicate whether the command itself was successful.
5263 */
5264 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005265 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005266 return false;
5267 }
5268
5269 boolean success = true;
5270 Parcel data = null;
5271 Parcel reply = null;
5272
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005273 BufferedWriter out = null;
5274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005275 // Any uncaught exception will crash the system process
5276 try {
5277 // Find the hashcode of the window
5278 int index = parameters.indexOf(' ');
5279 if (index == -1) {
5280 index = parameters.length();
5281 }
5282 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005283 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284
5285 // Extract the command's parameter after the window description
5286 if (index < parameters.length()) {
5287 parameters = parameters.substring(index + 1);
5288 } else {
5289 parameters = "";
5290 }
5291
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005292 final WindowState window = findWindow(hashCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005293 if (window == null) {
5294 return false;
5295 }
5296
5297 data = Parcel.obtain();
5298 data.writeInterfaceToken("android.view.IWindow");
5299 data.writeString(command);
5300 data.writeString(parameters);
5301 data.writeInt(1);
5302 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5303
5304 reply = Parcel.obtain();
5305
5306 final IBinder binder = window.mClient.asBinder();
5307 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5308 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5309
5310 reply.readException();
5311
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005312 if (!client.isOutputShutdown()) {
5313 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5314 out.write("DONE\n");
5315 out.flush();
5316 }
5317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005318 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005319 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005320 success = false;
5321 } finally {
5322 if (data != null) {
5323 data.recycle();
5324 }
5325 if (reply != null) {
5326 reply.recycle();
5327 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005328 if (out != null) {
5329 try {
5330 out.close();
5331 } catch (IOException e) {
5332
5333 }
5334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005335 }
5336
5337 return success;
5338 }
5339
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005340 public void addWindowChangeListener(WindowChangeListener listener) {
5341 synchronized(mWindowMap) {
5342 mWindowChangeListeners.add(listener);
5343 }
5344 }
5345
5346 public void removeWindowChangeListener(WindowChangeListener listener) {
5347 synchronized(mWindowMap) {
5348 mWindowChangeListeners.remove(listener);
5349 }
5350 }
5351
5352 private void notifyWindowsChanged() {
5353 WindowChangeListener[] windowChangeListeners;
5354 synchronized(mWindowMap) {
5355 if(mWindowChangeListeners.isEmpty()) {
5356 return;
5357 }
5358 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5359 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5360 }
5361 int N = windowChangeListeners.length;
5362 for(int i = 0; i < N; i++) {
5363 windowChangeListeners[i].windowsChanged();
5364 }
5365 }
5366
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005367 private void notifyFocusChanged() {
5368 WindowChangeListener[] windowChangeListeners;
5369 synchronized(mWindowMap) {
5370 if(mWindowChangeListeners.isEmpty()) {
5371 return;
5372 }
5373 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5374 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5375 }
5376 int N = windowChangeListeners.length;
5377 for(int i = 0; i < N; i++) {
5378 windowChangeListeners[i].focusChanged();
5379 }
5380 }
5381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 private WindowState findWindow(int hashCode) {
5383 if (hashCode == -1) {
5384 return getFocusedWindow();
5385 }
5386
5387 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005388 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005389 final int count = windows.size();
5390
5391 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005392 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 if (System.identityHashCode(w) == hashCode) {
5394 return w;
5395 }
5396 }
5397 }
5398
5399 return null;
5400 }
5401
5402 /*
5403 * Instruct the Activity Manager to fetch the current configuration and broadcast
5404 * that to config-changed listeners if appropriate.
5405 */
5406 void sendNewConfiguration() {
5407 try {
5408 mActivityManager.updateConfiguration(null);
5409 } catch (RemoteException e) {
5410 }
5411 }
Romain Guy06882f82009-06-10 13:36:04 -07005412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005413 public Configuration computeNewConfiguration() {
5414 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005415 Configuration config = computeNewConfigurationLocked();
5416 if (config == null && mWaitingForConfig) {
5417 // Nothing changed but we are waiting for something... stop that!
5418 mWaitingForConfig = false;
5419 performLayoutAndPlaceSurfacesLocked();
5420 }
5421 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005422 }
5423 }
Romain Guy06882f82009-06-10 13:36:04 -07005424
Dianne Hackbornc485a602009-03-24 22:39:49 -07005425 Configuration computeNewConfigurationLocked() {
5426 Configuration config = new Configuration();
5427 if (!computeNewConfigurationLocked(config)) {
5428 return null;
5429 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005430 return config;
5431 }
Romain Guy06882f82009-06-10 13:36:04 -07005432
Dianne Hackbornc485a602009-03-24 22:39:49 -07005433 boolean computeNewConfigurationLocked(Configuration config) {
5434 if (mDisplay == null) {
5435 return false;
5436 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005437
5438 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005439
5440 // Use the effective "visual" dimensions based on current rotation
5441 final boolean rotated = (mRotation == Surface.ROTATION_90
5442 || mRotation == Surface.ROTATION_270);
5443 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5444 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5445
Dianne Hackbornc485a602009-03-24 22:39:49 -07005446 int orientation = Configuration.ORIENTATION_SQUARE;
5447 if (dw < dh) {
5448 orientation = Configuration.ORIENTATION_PORTRAIT;
5449 } else if (dw > dh) {
5450 orientation = Configuration.ORIENTATION_LANDSCAPE;
5451 }
5452 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005453
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005454 DisplayMetrics dm = new DisplayMetrics();
5455 mDisplay.getMetrics(dm);
5456 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5457
Dianne Hackborn3fc982f2011-03-30 16:20:26 -07005458 config.screenWidthDp = (int)(dm.widthPixels / dm.density);
5459 config.screenHeightDp = (int)(dm.heightPixels / dm.density);
5460
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005461 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005462 // Note we only do this once because at this point we don't
5463 // expect the screen to change in this way at runtime, and want
5464 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005465 int longSize = dw;
5466 int shortSize = dh;
5467 if (longSize < shortSize) {
5468 int tmp = longSize;
5469 longSize = shortSize;
5470 shortSize = tmp;
5471 }
5472 longSize = (int)(longSize/dm.density);
5473 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005474
Dianne Hackborn723738c2009-06-25 19:48:04 -07005475 // These semi-magic numbers define our compatibility modes for
Dianne Hackborncc1d9f72011-03-08 10:33:55 -08005476 // applications with different screens. These are guarantees to
5477 // app developers about the space they can expect for a particular
5478 // configuration. DO NOT CHANGE!
Dianne Hackborn723738c2009-06-25 19:48:04 -07005479 if (longSize < 470) {
5480 // This is shorter than an HVGA normal density screen (which
5481 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005482 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5483 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005484 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005485 // What size is this screen screen?
Dianne Hackborncc1d9f72011-03-08 10:33:55 -08005486 if (longSize >= 960 && shortSize >= 720) {
5487 // 1.5xVGA or larger screens at medium density are the point
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005488 // at which we consider it to be an extra large screen.
5489 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackborncc1d9f72011-03-08 10:33:55 -08005490 } else if (longSize >= 640 && shortSize >= 480) {
5491 // VGA or larger screens at medium density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005492 // at which we consider it to be a large screen.
5493 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5494 } else {
5495 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Dianne Hackborne97a12e2011-01-29 13:22:02 -08005496 }
5497
5498 // If this screen is wider than normal HVGA, or taller
5499 // than FWVGA, then for old apps we want to run in size
5500 // compatibility mode.
5501 if (shortSize > 321 || longSize > 570) {
5502 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005503 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005504
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005505 // Is this a long screen?
5506 if (((longSize*3)/5) >= (shortSize-1)) {
5507 // Anything wider than WVGA (5:3) is considering to be long.
5508 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5509 } else {
5510 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5511 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005512 }
5513 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005514 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005515
Jeff Brown597eec82011-01-31 17:12:25 -08005516 // Determine whether a hard keyboard is available and enabled.
Jeff Brown2992ea72011-01-28 22:04:14 -08005517 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5518 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5519 mHardKeyboardAvailable = hardKeyboardAvailable;
5520 mHardKeyboardEnabled = hardKeyboardAvailable;
5521
5522 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5523 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5524 }
5525 if (!mHardKeyboardEnabled) {
5526 config.keyboard = Configuration.KEYBOARD_NOKEYS;
Jeff Brown2992ea72011-01-28 22:04:14 -08005527 }
Jeff Brown597eec82011-01-31 17:12:25 -08005528
5529 // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
5530 // based on whether a hard or soft keyboard is present, whether navigation keys
5531 // are present and the lid switch state.
5532 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5533 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5534 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
5535 mPolicy.adjustConfigurationLw(config);
Dianne Hackbornc485a602009-03-24 22:39:49 -07005536 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005537 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005538
Jeff Brown2992ea72011-01-28 22:04:14 -08005539 public boolean isHardKeyboardAvailable() {
5540 synchronized (mWindowMap) {
5541 return mHardKeyboardAvailable;
5542 }
5543 }
5544
5545 public boolean isHardKeyboardEnabled() {
5546 synchronized (mWindowMap) {
5547 return mHardKeyboardEnabled;
5548 }
5549 }
5550
5551 public void setHardKeyboardEnabled(boolean enabled) {
5552 synchronized (mWindowMap) {
5553 if (mHardKeyboardEnabled != enabled) {
5554 mHardKeyboardEnabled = enabled;
5555 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5556 }
5557 }
5558 }
5559
5560 public void setOnHardKeyboardStatusChangeListener(
5561 OnHardKeyboardStatusChangeListener listener) {
5562 synchronized (mWindowMap) {
5563 mHardKeyboardStatusChangeListener = listener;
5564 }
5565 }
5566
5567 void notifyHardKeyboardStatusChange() {
5568 final boolean available, enabled;
5569 final OnHardKeyboardStatusChangeListener listener;
5570 synchronized (mWindowMap) {
5571 listener = mHardKeyboardStatusChangeListener;
5572 available = mHardKeyboardAvailable;
5573 enabled = mHardKeyboardEnabled;
5574 }
5575 if (listener != null) {
5576 listener.onHardKeyboardStatusChange(available, enabled);
5577 }
5578 }
5579
Christopher Tatea53146c2010-09-07 11:57:52 -07005580 // -------------------------------------------------------------
5581 // Drag and drop
5582 // -------------------------------------------------------------
5583
5584 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005585 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005586 if (DEBUG_DRAG) {
5587 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005588 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005589 + " asbinder=" + window.asBinder());
5590 }
5591
5592 final int callerPid = Binder.getCallingPid();
5593 final long origId = Binder.clearCallingIdentity();
5594 IBinder token = null;
5595
5596 try {
5597 synchronized (mWindowMap) {
5598 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005599 if (mDragState == null) {
5600 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5601 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
Dianne Hackbornac1471a2011-02-03 13:46:06 -08005602 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG "
5603 + surface + ": CREATE");
Christopher Tatea53146c2010-09-07 11:57:52 -07005604 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005605 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005606 token = new Binder();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005607 mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005608 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005609 token = mDragState.mToken = new Binder();
5610
5611 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005612 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5613 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005614 mH.sendMessageDelayed(msg, 5000);
5615 } else {
5616 Slog.w(TAG, "Drag already in progress");
5617 }
5618 } catch (Surface.OutOfResourcesException e) {
5619 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5620 if (mDragState != null) {
5621 mDragState.reset();
5622 mDragState = null;
5623 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005624 }
5625 }
5626 } finally {
5627 Binder.restoreCallingIdentity(origId);
5628 }
5629
5630 return token;
5631 }
5632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005633 // -------------------------------------------------------------
5634 // Input Events and Focus Management
5635 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005636
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005637 final InputMonitor mInputMonitor = new InputMonitor(this);
Jeff Brown349703e2010-06-22 01:27:15 -07005638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005639 public void pauseKeyDispatching(IBinder _token) {
5640 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5641 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005642 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005643 }
5644
5645 synchronized (mWindowMap) {
5646 WindowToken token = mTokenMap.get(_token);
5647 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005648 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005649 }
5650 }
5651 }
5652
5653 public void resumeKeyDispatching(IBinder _token) {
5654 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5655 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005656 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005657 }
5658
5659 synchronized (mWindowMap) {
5660 WindowToken token = mTokenMap.get(_token);
5661 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005662 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005663 }
5664 }
5665 }
5666
5667 public void setEventDispatching(boolean enabled) {
5668 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5669 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005670 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005671 }
5672
5673 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005674 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005675 }
5676 }
Romain Guy06882f82009-06-10 13:36:04 -07005677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005678 /**
5679 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005680 * Even when sync is false, this method may block while waiting for current
5681 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005682 *
5683 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005684 * {@link SystemClock#uptimeMillis()} as the timebase.)
5685 * @param sync If true, wait for the event to be completed before returning to the caller.
5686 * @return Returns true if event was dispatched, false if it was dropped for any reason
5687 */
5688 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5689 long downTime = ev.getDownTime();
5690 long eventTime = ev.getEventTime();
5691
5692 int action = ev.getAction();
5693 int code = ev.getKeyCode();
5694 int repeatCount = ev.getRepeatCount();
5695 int metaState = ev.getMetaState();
5696 int deviceId = ev.getDeviceId();
5697 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005698 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00005699 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005700
5701 if (source == InputDevice.SOURCE_UNKNOWN) {
5702 source = InputDevice.SOURCE_KEYBOARD;
5703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005704
5705 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5706 if (downTime == 0) downTime = eventTime;
5707
5708 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08005709 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005710
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005711 final int pid = Binder.getCallingPid();
5712 final int uid = Binder.getCallingUid();
5713 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005714
Jeff Brownbbda99d2010-07-28 15:48:59 -07005715 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5716 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5717 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5718 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005719
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005720 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005721 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005722 }
5723
5724 /**
5725 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005726 * Even when sync is false, this method may block while waiting for current
5727 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005728 *
5729 * @param ev A motion event describing the pointer (touch) action. (As noted in
5730 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005731 * {@link SystemClock#uptimeMillis()} as the timebase.)
5732 * @param sync If true, wait for the event to be completed before returning to the caller.
5733 * @return Returns true if event was dispatched, false if it was dropped for any reason
5734 */
5735 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005736 final int pid = Binder.getCallingPid();
5737 final int uid = Binder.getCallingUid();
5738 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005739
Jeff Brownc5ed5912010-07-14 18:48:53 -07005740 MotionEvent newEvent = MotionEvent.obtain(ev);
5741 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5742 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5743 }
5744
Jeff Brownbbda99d2010-07-28 15:48:59 -07005745 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5746 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5747 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5748 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005749
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005750 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005751 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005752 }
Romain Guy06882f82009-06-10 13:36:04 -07005753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005754 /**
5755 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005756 * Even when sync is false, this method may block while waiting for current
5757 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005758 *
5759 * @param ev A motion event describing the trackball action. (As noted in
5760 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005761 * {@link SystemClock#uptimeMillis()} as the timebase.)
5762 * @param sync If true, wait for the event to be completed before returning to the caller.
5763 * @return Returns true if event was dispatched, false if it was dropped for any reason
5764 */
5765 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005766 final int pid = Binder.getCallingPid();
5767 final int uid = Binder.getCallingUid();
5768 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005769
Jeff Brownc5ed5912010-07-14 18:48:53 -07005770 MotionEvent newEvent = MotionEvent.obtain(ev);
5771 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5772 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5773 }
5774
Jeff Brownbbda99d2010-07-28 15:48:59 -07005775 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5776 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5777 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5778 INJECTION_TIMEOUT_MILLIS);
5779
5780 Binder.restoreCallingIdentity(ident);
5781 return reportInjectionResult(result);
5782 }
5783
5784 /**
5785 * Inject an input event into the UI without waiting for dispatch to commence.
5786 * This variant is useful for fire-and-forget input event injection. It does not
5787 * block any longer than it takes to enqueue the input event.
5788 *
5789 * @param ev An input event. (Be sure to set the input source correctly.)
5790 * @return Returns true if event was dispatched, false if it was dropped for any reason
5791 */
5792 public boolean injectInputEventNoWait(InputEvent ev) {
5793 final int pid = Binder.getCallingPid();
5794 final int uid = Binder.getCallingUid();
5795 final long ident = Binder.clearCallingIdentity();
5796
5797 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5798 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5799 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005800
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005801 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005802 return reportInjectionResult(result);
5803 }
5804
5805 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005806 switch (result) {
5807 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5808 Slog.w(TAG, "Input event injection permission denied.");
5809 throw new SecurityException(
5810 "Injecting to another application requires INJECT_EVENTS permission");
5811 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005812 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005813 return true;
5814 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5815 Slog.w(TAG, "Input event injection timed out.");
5816 return false;
5817 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5818 default:
5819 Slog.w(TAG, "Input event injection failed.");
5820 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005821 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005822 }
Romain Guy06882f82009-06-10 13:36:04 -07005823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005824 private WindowState getFocusedWindow() {
5825 synchronized (mWindowMap) {
5826 return getFocusedWindowLocked();
5827 }
5828 }
5829
5830 private WindowState getFocusedWindowLocked() {
5831 return mCurrentFocus;
5832 }
Romain Guy06882f82009-06-10 13:36:04 -07005833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08005835 if (!mInputMonitor.waitForInputDevicesReady(
5836 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
5837 Slog.w(TAG, "Devices still not ready after waiting "
5838 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
5839 + " milliseconds before attempting to detect safe mode.");
5840 }
5841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005842 mSafeMode = mPolicy.detectSafeMode();
5843 return mSafeMode;
5844 }
Romain Guy06882f82009-06-10 13:36:04 -07005845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005846 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005847 synchronized(mWindowMap) {
5848 if (mDisplay != null) {
5849 throw new IllegalStateException("Display already initialized");
5850 }
5851 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5852 mDisplay = wm.getDefaultDisplay();
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07005853 mInitialDisplayWidth = mCurDisplayWidth = mDisplay.getRealWidth();
5854 mInitialDisplayHeight = mCurDisplayHeight = mDisplay.getRealHeight();
5855 mInputManager.setDisplaySize(0, mDisplay.getRawWidth(), mDisplay.getRawHeight());
Dianne Hackborn5132b372010-07-29 12:51:35 -07005856 }
5857
5858 try {
5859 mActivityManager.updateConfiguration(null);
5860 } catch (RemoteException e) {
5861 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005862
5863 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005864 }
5865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005866 // This is an animation that does nothing: it just immediately finishes
5867 // itself every time it is called. It is used as a stub animation in cases
5868 // where we want to synchronize multiple things that may be animating.
5869 static final class DummyAnimation extends Animation {
5870 public boolean getTransformation(long currentTime, Transformation outTransformation) {
5871 return false;
5872 }
5873 }
5874 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07005875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005876 // -------------------------------------------------------------
5877 // Async Handler
5878 // -------------------------------------------------------------
5879
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005880 final class H extends Handler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005881 public static final int REPORT_FOCUS_CHANGE = 2;
5882 public static final int REPORT_LOSING_FOCUS = 3;
5883 public static final int ANIMATE = 4;
5884 public static final int ADD_STARTING = 5;
5885 public static final int REMOVE_STARTING = 6;
5886 public static final int FINISHED_STARTING = 7;
5887 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005888 public static final int WINDOW_FREEZE_TIMEOUT = 11;
5889 public static final int HOLD_SCREEN_CHANGED = 12;
5890 public static final int APP_TRANSITION_TIMEOUT = 13;
5891 public static final int PERSIST_ANIMATION_SCALE = 14;
5892 public static final int FORCE_GC = 15;
5893 public static final int ENABLE_SCREEN = 16;
5894 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005895 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005896 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07005897 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07005898 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08005899 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07005900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005901 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07005902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005903 public H() {
5904 }
Romain Guy06882f82009-06-10 13:36:04 -07005905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005906 @Override
5907 public void handleMessage(Message msg) {
5908 switch (msg.what) {
5909 case REPORT_FOCUS_CHANGE: {
5910 WindowState lastFocus;
5911 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005913 synchronized(mWindowMap) {
5914 lastFocus = mLastFocus;
5915 newFocus = mCurrentFocus;
5916 if (lastFocus == newFocus) {
5917 // Focus is not changing, so nothing to do.
5918 return;
5919 }
5920 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005921 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005922 // + " to " + newFocus);
5923 if (newFocus != null && lastFocus != null
5924 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005925 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005926 mLosingFocus.add(lastFocus);
5927 lastFocus = null;
5928 }
5929 }
5930
5931 if (lastFocus != newFocus) {
5932 //System.out.println("Changing focus from " + lastFocus
5933 // + " to " + newFocus);
5934 if (newFocus != null) {
5935 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005936 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005937 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
5938 } catch (RemoteException e) {
5939 // Ignore if process has died.
5940 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07005941 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005942 }
5943
5944 if (lastFocus != null) {
5945 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005946 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005947 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
5948 } catch (RemoteException e) {
5949 // Ignore if process has died.
5950 }
5951 }
Joe Onorato664644d2011-01-23 17:53:23 -08005952
5953 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005954 }
5955 } break;
5956
5957 case REPORT_LOSING_FOCUS: {
5958 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07005959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005960 synchronized(mWindowMap) {
5961 losers = mLosingFocus;
5962 mLosingFocus = new ArrayList<WindowState>();
5963 }
5964
5965 final int N = losers.size();
5966 for (int i=0; i<N; i++) {
5967 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005968 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005969 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
5970 } catch (RemoteException e) {
5971 // Ignore if process has died.
5972 }
5973 }
5974 } break;
5975
5976 case ANIMATE: {
5977 synchronized(mWindowMap) {
5978 mAnimationPending = false;
5979 performLayoutAndPlaceSurfacesLocked();
5980 }
5981 } break;
5982
5983 case ADD_STARTING: {
5984 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
5985 final StartingData sd = wtoken.startingData;
5986
5987 if (sd == null) {
5988 // Animation has been canceled... do nothing.
5989 return;
5990 }
Romain Guy06882f82009-06-10 13:36:04 -07005991
Joe Onorato8a9b2202010-02-26 18:56:32 -08005992 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005993 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07005994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005995 View view = null;
5996 try {
5997 view = mPolicy.addStartingWindow(
5998 wtoken.token, sd.pkg,
5999 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08006000 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006002 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006003 }
6004
6005 if (view != null) {
6006 boolean abort = false;
6007
6008 synchronized(mWindowMap) {
6009 if (wtoken.removed || wtoken.startingData == null) {
6010 // If the window was successfully added, then
6011 // we need to remove it.
6012 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006013 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006014 "Aborted starting " + wtoken
6015 + ": removed=" + wtoken.removed
6016 + " startingData=" + wtoken.startingData);
6017 wtoken.startingWindow = null;
6018 wtoken.startingData = null;
6019 abort = true;
6020 }
6021 } else {
6022 wtoken.startingView = view;
6023 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006024 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006025 "Added starting " + wtoken
6026 + ": startingWindow="
6027 + wtoken.startingWindow + " startingView="
6028 + wtoken.startingView);
6029 }
6030
6031 if (abort) {
6032 try {
6033 mPolicy.removeStartingWindow(wtoken.token, view);
6034 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006035 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006036 }
6037 }
6038 }
6039 } break;
6040
6041 case REMOVE_STARTING: {
6042 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
6043 IBinder token = null;
6044 View view = null;
6045 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006046 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006047 + wtoken + ": startingWindow="
6048 + wtoken.startingWindow + " startingView="
6049 + wtoken.startingView);
6050 if (wtoken.startingWindow != null) {
6051 view = wtoken.startingView;
6052 token = wtoken.token;
6053 wtoken.startingData = null;
6054 wtoken.startingView = null;
6055 wtoken.startingWindow = null;
6056 }
6057 }
6058 if (view != null) {
6059 try {
6060 mPolicy.removeStartingWindow(token, view);
6061 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006062 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006063 }
6064 }
6065 } break;
6066
6067 case FINISHED_STARTING: {
6068 IBinder token = null;
6069 View view = null;
6070 while (true) {
6071 synchronized (mWindowMap) {
6072 final int N = mFinishedStarting.size();
6073 if (N <= 0) {
6074 break;
6075 }
6076 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
6077
Joe Onorato8a9b2202010-02-26 18:56:32 -08006078 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006079 "Finished starting " + wtoken
6080 + ": startingWindow=" + wtoken.startingWindow
6081 + " startingView=" + wtoken.startingView);
6082
6083 if (wtoken.startingWindow == null) {
6084 continue;
6085 }
6086
6087 view = wtoken.startingView;
6088 token = wtoken.token;
6089 wtoken.startingData = null;
6090 wtoken.startingView = null;
6091 wtoken.startingWindow = null;
6092 }
6093
6094 try {
6095 mPolicy.removeStartingWindow(token, view);
6096 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006097 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098 }
6099 }
6100 } break;
6101
6102 case REPORT_APPLICATION_TOKEN_WINDOWS: {
6103 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
6104
6105 boolean nowVisible = msg.arg1 != 0;
6106 boolean nowGone = msg.arg2 != 0;
6107
6108 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006109 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006110 TAG, "Reporting visible in " + wtoken
6111 + " visible=" + nowVisible
6112 + " gone=" + nowGone);
6113 if (nowVisible) {
6114 wtoken.appToken.windowsVisible();
6115 } else {
6116 wtoken.appToken.windowsGone();
6117 }
6118 } catch (RemoteException ex) {
6119 }
6120 } break;
Romain Guy06882f82009-06-10 13:36:04 -07006121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 case WINDOW_FREEZE_TIMEOUT: {
6123 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006124 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006125 int i = mWindows.size();
6126 while (i > 0) {
6127 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006128 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006129 if (w.mOrientationChanging) {
6130 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006131 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132 }
6133 }
6134 performLayoutAndPlaceSurfacesLocked();
6135 }
6136 break;
6137 }
Romain Guy06882f82009-06-10 13:36:04 -07006138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006139 case HOLD_SCREEN_CHANGED: {
6140 Session oldHold;
6141 Session newHold;
6142 synchronized (mWindowMap) {
6143 oldHold = mLastReportedHold;
6144 newHold = (Session)msg.obj;
6145 mLastReportedHold = newHold;
6146 }
Romain Guy06882f82009-06-10 13:36:04 -07006147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 if (oldHold != newHold) {
6149 try {
6150 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07006151 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006152 "window",
6153 BatteryStats.WAKE_TYPE_WINDOW);
6154 }
6155 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07006156 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006157 "window",
6158 BatteryStats.WAKE_TYPE_WINDOW);
6159 }
6160 } catch (RemoteException e) {
6161 }
6162 }
6163 break;
6164 }
Romain Guy06882f82009-06-10 13:36:04 -07006165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 case APP_TRANSITION_TIMEOUT: {
6167 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006168 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006169 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 "*** APP TRANSITION TIMEOUT");
6171 mAppTransitionReady = true;
6172 mAppTransitionTimeout = true;
6173 performLayoutAndPlaceSurfacesLocked();
6174 }
6175 }
6176 break;
6177 }
Romain Guy06882f82009-06-10 13:36:04 -07006178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006179 case PERSIST_ANIMATION_SCALE: {
6180 Settings.System.putFloat(mContext.getContentResolver(),
6181 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
6182 Settings.System.putFloat(mContext.getContentResolver(),
6183 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
6184 break;
6185 }
Romain Guy06882f82009-06-10 13:36:04 -07006186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 case FORCE_GC: {
6188 synchronized(mWindowMap) {
6189 if (mAnimationPending) {
6190 // If we are animating, don't do the gc now but
6191 // delay a bit so we don't interrupt the animation.
6192 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
6193 2000);
6194 return;
6195 }
6196 // If we are currently rotating the display, it will
6197 // schedule a new message when done.
6198 if (mDisplayFrozen) {
6199 return;
6200 }
6201 mFreezeGcPending = 0;
6202 }
6203 Runtime.getRuntime().gc();
6204 break;
6205 }
Romain Guy06882f82009-06-10 13:36:04 -07006206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006207 case ENABLE_SCREEN: {
6208 performEnableScreen();
6209 break;
6210 }
Romain Guy06882f82009-06-10 13:36:04 -07006211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006212 case APP_FREEZE_TIMEOUT: {
6213 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006214 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006215 int i = mAppTokens.size();
6216 while (i > 0) {
6217 i--;
6218 AppWindowToken tok = mAppTokens.get(i);
6219 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006220 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006221 unsetAppFreezingScreenLocked(tok, true, true);
6222 }
6223 }
6224 }
6225 break;
6226 }
Romain Guy06882f82009-06-10 13:36:04 -07006227
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006228 case SEND_NEW_CONFIGURATION: {
6229 removeMessages(SEND_NEW_CONFIGURATION);
6230 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006231 break;
6232 }
Romain Guy06882f82009-06-10 13:36:04 -07006233
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07006234 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006235 if (mWindowsChanged) {
6236 synchronized (mWindowMap) {
6237 mWindowsChanged = false;
6238 }
6239 notifyWindowsChanged();
6240 }
6241 break;
6242 }
6243
Christopher Tatea53146c2010-09-07 11:57:52 -07006244 case DRAG_START_TIMEOUT: {
6245 IBinder win = (IBinder)msg.obj;
6246 if (DEBUG_DRAG) {
6247 Slog.w(TAG, "Timeout starting drag by win " + win);
6248 }
6249 synchronized (mWindowMap) {
6250 // !!! TODO: ANR the app that has failed to start the drag in time
6251 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07006252 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08006253 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07006254 mDragState.reset();
6255 mDragState = null;
6256 }
6257 }
Chris Tated4533f12010-10-19 15:15:08 -07006258 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07006259 }
6260
Chris Tated4533f12010-10-19 15:15:08 -07006261 case DRAG_END_TIMEOUT: {
6262 IBinder win = (IBinder)msg.obj;
6263 if (DEBUG_DRAG) {
6264 Slog.w(TAG, "Timeout ending drag to win " + win);
6265 }
6266 synchronized (mWindowMap) {
6267 // !!! TODO: ANR the drag-receiving app
6268 mDragState.mDragResult = false;
6269 mDragState.endDragLw();
6270 }
6271 break;
6272 }
Jeff Brown2992ea72011-01-28 22:04:14 -08006273
6274 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
6275 notifyHardKeyboardStatusChange();
6276 break;
6277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 }
6279 }
6280 }
6281
6282 // -------------------------------------------------------------
6283 // IWindowManager API
6284 // -------------------------------------------------------------
6285
6286 public IWindowSession openSession(IInputMethodClient client,
6287 IInputContext inputContext) {
6288 if (client == null) throw new IllegalArgumentException("null client");
6289 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08006290 Session session = new Session(this, client, inputContext);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006291 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 }
6293
6294 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
6295 synchronized (mWindowMap) {
6296 // The focus for the client is the window immediately below
6297 // where we would place the input method window.
6298 int idx = findDesiredInputMethodWindowIndexLocked(false);
6299 WindowState imFocus;
6300 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07006301 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08006302 //Log.i(TAG, "Desired input method target: " + imFocus);
6303 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
6304 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08006306 // This may be a starting window, in which case we still want
6307 // to count it as okay.
6308 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
6309 && imFocus.mAppToken != null) {
6310 // The client has definitely started, so it really should
6311 // have a window in this app token. Let's look for it.
6312 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
6313 WindowState w = imFocus.mAppToken.windows.get(i);
6314 if (w != imFocus) {
6315 //Log.i(TAG, "Switching to real app window: " + w);
6316 imFocus = w;
6317 break;
6318 }
6319 }
6320 }
6321 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
6322 //if (imFocus.mSession.mClient != null) {
6323 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
6324 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
6325 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326 if (imFocus.mSession.mClient != null &&
6327 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
6328 return true;
6329 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08006330
6331 // Okay, how about this... what is the current focus?
6332 // It seems in some cases we may not have moved the IM
6333 // target window, such as when it was in a pop-up window,
6334 // so let's also look at the current focus. (An example:
6335 // go to Gmail, start searching so the keyboard goes up,
6336 // press home. Sometimes the IME won't go down.)
6337 // Would be nice to fix this more correctly, but it's
6338 // way at the end of a release, and this should be good enough.
6339 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
6340 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
6341 return true;
6342 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006343 }
6344 }
6345 }
6346 return false;
6347 }
Romain Guy06882f82009-06-10 13:36:04 -07006348
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07006349 public void getDisplaySize(Point size) {
6350 synchronized(mWindowMap) {
6351 size.x = mCurDisplayWidth;
6352 size.y = mCurDisplayHeight;
6353 }
6354 }
6355
6356 public int getMaximumSizeDimension() {
6357 synchronized(mWindowMap) {
6358 // Do this based on the raw screen size, until we are smarter.
6359 return mInitialDisplayWidth > mInitialDisplayHeight
6360 ? mInitialDisplayWidth : mInitialDisplayHeight;
6361 }
6362 }
6363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006364 // -------------------------------------------------------------
6365 // Internals
6366 // -------------------------------------------------------------
6367
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006368 final WindowState windowForClientLocked(Session session, IWindow client,
6369 boolean throwOnError) {
6370 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006371 }
Romain Guy06882f82009-06-10 13:36:04 -07006372
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006373 final WindowState windowForClientLocked(Session session, IBinder client,
6374 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006375 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006376 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006377 TAG, "Looking up client " + client + ": " + win);
6378 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006379 RuntimeException ex = new IllegalArgumentException(
6380 "Requested window " + client + " does not exist");
6381 if (throwOnError) {
6382 throw ex;
6383 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006384 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385 return null;
6386 }
6387 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006388 RuntimeException ex = new IllegalArgumentException(
6389 "Requested window " + client + " is in session " +
6390 win.mSession + ", not " + session);
6391 if (throwOnError) {
6392 throw ex;
6393 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006394 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006395 return null;
6396 }
6397
6398 return win;
6399 }
6400
Dianne Hackborna8f60182009-09-01 19:01:50 -07006401 final void rebuildAppWindowListLocked() {
6402 int NW = mWindows.size();
6403 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006404 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006405 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006406
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006407 if (mRebuildTmp.length < NW) {
6408 mRebuildTmp = new WindowState[NW+10];
6409 }
6410
Dianne Hackborna8f60182009-09-01 19:01:50 -07006411 // First remove all existing app windows.
6412 i=0;
6413 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07006414 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006415 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07006416 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006417 win.mRebuilding = true;
6418 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006419 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006420 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006421 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07006422 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006423 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07006424 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006425 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
6426 && lastWallpaper == i-1) {
6427 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07006428 }
6429 i++;
6430 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006431
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006432 // The wallpaper window(s) typically live at the bottom of the stack,
6433 // so skip them before adding app tokens.
6434 lastWallpaper++;
6435 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006436
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006437 // First add all of the exiting app tokens... these are no longer
6438 // in the main app list, but still have windows shown. We put them
6439 // in the back because now that the animation is over we no longer
6440 // will care about them.
6441 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07006442 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006443 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
6444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006445
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006446 // And add in the still active app tokens in Z order.
6447 NT = mAppTokens.size();
6448 for (int j=0; j<NT; j++) {
6449 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07006450 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006451
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006452 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006453 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006454 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006455 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006456 for (i=0; i<numRemoved; i++) {
6457 WindowState ws = mRebuildTmp[i];
6458 if (ws.mRebuilding) {
6459 StringWriter sw = new StringWriter();
6460 PrintWriter pw = new PrintWriter(sw);
6461 ws.dump(pw, "");
6462 pw.flush();
6463 Slog.w(TAG, "This window was lost: " + ws);
6464 Slog.w(TAG, sw.toString());
6465 }
6466 }
6467 Slog.w(TAG, "Current app token list:");
6468 dumpAppTokensLocked();
6469 Slog.w(TAG, "Final window list:");
6470 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006471 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07006472 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 private final void assignLayersLocked() {
6475 int N = mWindows.size();
6476 int curBaseLayer = 0;
6477 int curLayer = 0;
6478 int i;
Romain Guy06882f82009-06-10 13:36:04 -07006479
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006480 if (DEBUG_LAYERS) {
6481 RuntimeException here = new RuntimeException("here");
6482 here.fillInStackTrace();
6483 Log.v(TAG, "Assigning layers", here);
6484 }
6485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006487 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006488 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
6489 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 curLayer += WINDOW_LAYER_MULTIPLIER;
6491 w.mLayer = curLayer;
6492 } else {
6493 curBaseLayer = curLayer = w.mBaseLayer;
6494 w.mLayer = curLayer;
6495 }
6496 if (w.mTargetAppToken != null) {
6497 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
6498 } else if (w.mAppToken != null) {
6499 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
6500 } else {
6501 w.mAnimLayer = w.mLayer;
6502 }
6503 if (w.mIsImWindow) {
6504 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006505 } else if (w.mIsWallpaper) {
6506 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006507 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006508 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006509 + w.mAnimLayer);
6510 //System.out.println(
6511 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
6512 }
6513 }
6514
6515 private boolean mInLayout = false;
6516 private final void performLayoutAndPlaceSurfacesLocked() {
6517 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07006518 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 throw new RuntimeException("Recursive call!");
6520 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006521 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006522 return;
6523 }
6524
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006525 if (mWaitingForConfig) {
6526 // Our configuration has changed (most likely rotation), but we
6527 // don't yet have the complete configuration to report to
6528 // applications. Don't do any window layout until we have it.
6529 return;
6530 }
6531
Dianne Hackbornce2ef762010-09-20 11:39:14 -07006532 if (mDisplay == null) {
6533 // Not yet initialized, nothing to do.
6534 return;
6535 }
6536
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006537 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006538 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006539
6540 try {
6541 if (mForceRemoves != null) {
6542 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006543 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006544 for (int i=0; i<mForceRemoves.size(); i++) {
6545 WindowState ws = mForceRemoves.get(i);
6546 Slog.i(TAG, "Force removing: " + ws);
6547 removeWindowInnerLocked(ws.mSession, ws);
6548 }
6549 mForceRemoves = null;
6550 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
6551 Object tmp = new Object();
6552 synchronized (tmp) {
6553 try {
6554 tmp.wait(250);
6555 } catch (InterruptedException e) {
6556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006557 }
6558 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006559 } catch (RuntimeException e) {
6560 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 try {
6564 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07006565
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006566 int N = mPendingRemove.size();
6567 if (N > 0) {
6568 if (mPendingRemoveTmp.length < N) {
6569 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006571 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006572 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006573 for (int i=0; i<N; i++) {
6574 WindowState w = mPendingRemoveTmp[i];
6575 removeWindowInnerLocked(w.mSession, w);
6576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006577
6578 mInLayout = false;
6579 assignLayersLocked();
6580 mLayoutNeeded = true;
6581 performLayoutAndPlaceSurfacesLocked();
6582
6583 } else {
6584 mInLayout = false;
6585 if (mLayoutNeeded) {
6586 requestAnimationLocked(0);
6587 }
6588 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006589 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07006590 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
6591 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 } catch (RuntimeException e) {
6594 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006595 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006596 }
6597 }
6598
Jeff Brown3a22cd92011-01-21 13:59:04 -08006599 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006600 if (!mLayoutNeeded) {
6601 return 0;
6602 }
6603
6604 mLayoutNeeded = false;
6605
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07006606 final int dw = mCurDisplayWidth;
6607 final int dh = mCurDisplayHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006608
6609 final int N = mWindows.size();
6610 int i;
6611
Joe Onorato8a9b2202010-02-26 18:56:32 -08006612 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08006613 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
6614
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006615 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07006616
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006617 int seq = mLayoutSeq+1;
6618 if (seq < 0) seq = 0;
6619 mLayoutSeq = seq;
6620
6621 // First perform layout of any root windows (not attached
6622 // to another window).
6623 int topAttached = -1;
6624 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006625 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006627 // Don't do layout of a window if it is not visible, or
6628 // soon won't be visible, to avoid wasting time and funky
6629 // changes while a window is animating away.
6630 final AppWindowToken atoken = win.mAppToken;
6631 final boolean gone = win.mViewVisibility == View.GONE
6632 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08006633 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006634 || (atoken != null && atoken.hiddenRequested)
6635 || win.mAttachedHidden
6636 || win.mExiting || win.mDestroying;
6637
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006638 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
6639 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006640 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
6641 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006642 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006643 + win.mViewVisibility + " mRelayoutCalled="
6644 + win.mRelayoutCalled + " hidden="
6645 + win.mRootToken.hidden + " hiddenRequested="
6646 + (atoken != null && atoken.hiddenRequested)
6647 + " mAttachedHidden=" + win.mAttachedHidden);
6648 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006649
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006650 // If this view is GONE, then skip it -- keep the current
6651 // frame, and let the caller know so they can ignore it
6652 // if they want. (We do the normal layout for INVISIBLE
6653 // windows, since that means "perform layout as normal,
6654 // just don't display").
6655 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006656 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006657 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006658 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006659 win.mContentChanged = false;
6660 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006661 mPolicy.layoutWindowLw(win, win.mAttrs, null);
6662 win.mLayoutSeq = seq;
6663 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
6664 + win.mFrame + " mContainingFrame="
6665 + win.mContainingFrame + " mDisplayFrame="
6666 + win.mDisplayFrame);
6667 } else {
6668 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006669 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07006670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006672
6673 // Now perform layout of attached windows, which usually
6674 // depend on the position of the window they are attached to.
6675 // XXX does not deal with windows that are attached to windows
6676 // that are themselves attached.
6677 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006678 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006679
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006680 if (win.mLayoutAttached) {
6681 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
6682 + " mHaveFrame=" + win.mHaveFrame
6683 + " mViewVisibility=" + win.mViewVisibility
6684 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006685 // If this view is GONE, then skip it -- keep the current
6686 // frame, and let the caller know so they can ignore it
6687 // if they want. (We do the normal layout for INVISIBLE
6688 // windows, since that means "perform layout as normal,
6689 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006690 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
6691 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006692 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006693 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006694 win.mContentChanged = false;
6695 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006696 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
6697 win.mLayoutSeq = seq;
6698 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
6699 + win.mFrame + " mContainingFrame="
6700 + win.mContainingFrame + " mDisplayFrame="
6701 + win.mDisplayFrame);
6702 }
6703 }
6704 }
Jeff Brown349703e2010-06-22 01:27:15 -07006705
6706 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08006707 mInputMonitor.setUpdateInputWindowsNeededLw();
6708 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006709 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006710 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006711
6712 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006713 }
Romain Guy06882f82009-06-10 13:36:04 -07006714
Brad Fitzpatrick68044332010-11-22 18:19:48 -08006715 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 private final void performLayoutAndPlaceSurfacesLockedInner(
6717 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04006718 if (mDisplay == null) {
6719 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
6720 return;
6721 }
6722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006723 final long currentTime = SystemClock.uptimeMillis();
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07006724 final int dw = mCurDisplayWidth = mDisplay.getRealWidth();
6725 final int dh = mCurDisplayHeight = mDisplay.getRealHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006727 int i;
6728
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006729 if (mFocusMayChange) {
6730 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006731 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
6732 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006733 }
6734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006735 // Initialize state of exiting tokens.
6736 for (i=mExitingTokens.size()-1; i>=0; i--) {
6737 mExitingTokens.get(i).hasVisible = false;
6738 }
6739
6740 // Initialize state of exiting applications.
6741 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
6742 mExitingAppTokens.get(i).hasVisible = false;
6743 }
6744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 boolean orientationChangeComplete = true;
6746 Session holdScreen = null;
6747 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05006748 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 boolean focusDisplayed = false;
6750 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006751 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08006752 boolean updateRotation = false;
Dianne Hackborn50660e22011-02-02 17:12:25 -08006753 boolean screenRotationFinished = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006754
6755 if (mFxSession == null) {
6756 mFxSession = new SurfaceSession();
6757 createWatermark = true;
6758 }
6759
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006760 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006761
6762 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006763
6764 if (createWatermark) {
6765 createWatermark();
6766 }
6767 if (mWatermark != null) {
6768 mWatermark.positionSurface(dw, dh);
6769 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08006770 if (mStrictModeFlash != null) {
6771 mStrictModeFlash.positionSurface(dw, dh);
6772 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006774 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006775 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006776 int repeats = 0;
6777 int changes = 0;
6778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006779 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006780 repeats++;
6781 if (repeats > 6) {
6782 Slog.w(TAG, "Animation repeat aborted after too many iterations");
6783 mLayoutNeeded = false;
6784 break;
6785 }
6786
6787 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
6788 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
6789 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
6790 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
6791 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
6792 assignLayersLocked();
6793 mLayoutNeeded = true;
6794 }
6795 }
6796 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
6797 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006798 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006799 mLayoutNeeded = true;
6800 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
6801 }
6802 }
6803 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
6804 mLayoutNeeded = true;
6805 }
6806 }
6807
6808 // FIRST LOOP: Perform a layout, if needed.
6809 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006810 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006811 if (changes != 0) {
6812 continue;
6813 }
6814 } else {
6815 Slog.w(TAG, "Layout repeat skipped after too many iterations");
6816 changes = 0;
6817 }
6818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006819 final int transactionSequence = ++mTransactionSequence;
6820
6821 // Update animations of all applications, including those
6822 // associated with exiting/removed apps
6823 boolean tokensAnimating = false;
6824 final int NAT = mAppTokens.size();
6825 for (i=0; i<NAT; i++) {
6826 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
6827 tokensAnimating = true;
6828 }
6829 }
6830 final int NEAT = mExitingAppTokens.size();
6831 for (i=0; i<NEAT; i++) {
6832 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
6833 tokensAnimating = true;
6834 }
6835 }
6836
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006837 // SECOND LOOP: Execute animations and update visibility of windows.
6838
Joe Onorato8a9b2202010-02-26 18:56:32 -08006839 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006840 + transactionSequence + " tokensAnimating="
6841 + tokensAnimating);
6842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006844
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08006845 if (mScreenRotationAnimation != null) {
6846 if (mScreenRotationAnimation.isAnimating()) {
6847 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
6848 animating = true;
6849 } else {
Dianne Hackborn50660e22011-02-02 17:12:25 -08006850 screenRotationFinished = true;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08006851 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08006852 }
6853 }
6854 }
6855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006857 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006858 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006859 WindowState windowDetachedWallpaper = null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -08006860 WindowState windowAnimationBackground = null;
6861 int windowAnimationBackgroundColor = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862
6863 mPolicy.beginAnimationLw(dw, dh);
6864
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006865 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006868 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869
6870 final WindowManager.LayoutParams attrs = w.mAttrs;
6871
6872 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006873 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006874 if (w.commitFinishDrawingLocked(currentTime)) {
6875 if ((w.mAttrs.flags
6876 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006877 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006878 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006879 wallpaperMayChange = true;
6880 }
6881 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006882
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006883 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006884
6885 int animDw = dw;
6886 int animDh = dh;
6887
6888 // If the window has moved due to its containing
6889 // content frame changing, then we'd like to animate
6890 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08006891 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006892 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006893 // Frame has moved, containing content frame
6894 // has also moved, and we're not currently animating...
6895 // let's do something.
6896 Animation a = AnimationUtils.loadAnimation(mContext,
6897 com.android.internal.R.anim.window_move_from_decor);
6898 w.setAnimation(a);
6899 animDw = w.mLastFrame.left - w.mFrame.left;
6900 animDh = w.mLastFrame.top - w.mFrame.top;
6901 }
6902
6903 // Execute animation.
6904 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
6905 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006906
6907 // If this window is animating, make a note that we have
6908 // an animating window and take care of a request to run
6909 // a detached wallpaper animation.
6910 if (nowAnimating) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08006911 if (w.mAnimation != null) {
6912 if (w.mAnimation.getDetachWallpaper()) {
6913 windowDetachedWallpaper = w;
6914 }
6915 if (w.mAnimation.getBackgroundColor() != 0) {
6916 windowAnimationBackground = w;
6917 windowAnimationBackgroundColor =
6918 w.mAnimation.getBackgroundColor();
6919 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006923
6924 // If this window's app token is running a detached wallpaper
6925 // animation, make a note so we can ensure the wallpaper is
6926 // displayed behind it.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08006927 if (w.mAppToken != null && w.mAppToken.animation != null) {
6928 if (w.mAppToken.animation.getDetachWallpaper()) {
6929 windowDetachedWallpaper = w;
6930 }
6931 if (w.mAppToken.animation.getBackgroundColor() != 0) {
6932 windowAnimationBackground = w;
6933 windowAnimationBackgroundColor =
6934 w.mAppToken.animation.getBackgroundColor();
6935 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006936 }
6937
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006938 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
6939 wallpaperMayChange = true;
6940 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006941
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006942 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006943 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006944 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006945 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006946 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006947 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006948 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006949 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
6950 forceHiding = true;
6951 }
6952 } else if (mPolicy.canBeForceHidden(w, attrs)) {
6953 boolean changed;
6954 if (forceHiding) {
6955 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006956 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
6957 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006958 } else {
6959 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006960 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
6961 "Now policy shown: " + w);
6962 if (changed) {
6963 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006964 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006965 // Assume we will need to animate. If
6966 // we don't (because the wallpaper will
6967 // stay with the lock screen), then we will
6968 // clean up later.
6969 Animation a = mPolicy.createForceHideEnterAnimation();
6970 if (a != null) {
6971 w.setAnimation(a);
6972 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006973 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006974 if (mCurrentFocus == null ||
6975 mCurrentFocus.mLayer < w.mLayer) {
6976 // We are showing on to of the current
6977 // focus, so re-evaluate focus to make
6978 // sure it is correct.
6979 mFocusMayChange = true;
6980 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006981 }
6982 }
6983 if (changed && (attrs.flags
6984 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
6985 wallpaperMayChange = true;
6986 }
6987 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006989 mPolicy.animatingWindowLw(w, attrs);
6990 }
6991
6992 final AppWindowToken atoken = w.mAppToken;
6993 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
6994 if (atoken.lastTransactionSequence != transactionSequence) {
6995 atoken.lastTransactionSequence = transactionSequence;
6996 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
6997 atoken.startingDisplayed = false;
6998 }
6999 if ((w.isOnScreen() || w.mAttrs.type
7000 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
7001 && !w.mExiting && !w.mDestroying) {
7002 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007003 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007004 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007005 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007006 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007007 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 + " pv=" + w.mPolicyVisibility
7009 + " dp=" + w.mDrawPending
7010 + " cdp=" + w.mCommitDrawPending
7011 + " ah=" + w.mAttachedHidden
7012 + " th=" + atoken.hiddenRequested
7013 + " a=" + w.mAnimating);
7014 }
7015 }
7016 if (w != atoken.startingWindow) {
7017 if (!atoken.freezingScreen || !w.mAppFreezing) {
7018 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007019 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007020 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007021 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 "tokenMayBeDrawn: " + atoken
7023 + " freezingScreen=" + atoken.freezingScreen
7024 + " mAppFreezing=" + w.mAppFreezing);
7025 tokenMayBeDrawn = true;
7026 }
7027 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007028 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 atoken.startingDisplayed = true;
7030 }
7031 }
7032 } else if (w.mReadyToShow) {
7033 w.performShowLocked();
7034 }
7035 }
7036
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007037 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038
7039 if (tokenMayBeDrawn) {
7040 // See if any windows have been drawn, so they (and others
7041 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007042 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007043 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007044 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 if (wtoken.freezingScreen) {
7046 int numInteresting = wtoken.numInterestingWindows;
7047 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007048 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007049 "allDrawn: " + wtoken
7050 + " interesting=" + numInteresting
7051 + " drawn=" + wtoken.numDrawnWindows);
7052 wtoken.showAllWindowsLocked();
7053 unsetAppFreezingScreenLocked(wtoken, false, true);
7054 orientationChangeComplete = true;
7055 }
7056 } else if (!wtoken.allDrawn) {
7057 int numInteresting = wtoken.numInterestingWindows;
7058 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007059 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007060 "allDrawn: " + wtoken
7061 + " interesting=" + numInteresting
7062 + " drawn=" + wtoken.numDrawnWindows);
7063 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007064 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007065
7066 // We can now show all of the drawn windows!
7067 if (!mOpeningApps.contains(wtoken)) {
7068 wtoken.showAllWindowsLocked();
7069 }
7070 }
7071 }
7072 }
7073 }
7074
7075 // If we are ready to perform an app transition, check through
7076 // all of the app tokens to be shown and see if they are ready
7077 // to go.
7078 if (mAppTransitionReady) {
7079 int NN = mOpeningApps.size();
7080 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007081 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007082 "Checking " + NN + " opening apps (frozen="
7083 + mDisplayFrozen + " timeout="
7084 + mAppTransitionTimeout + ")...");
7085 if (!mDisplayFrozen && !mAppTransitionTimeout) {
7086 // If the display isn't frozen, wait to do anything until
7087 // all of the apps are ready. Otherwise just go because
7088 // we'll unfreeze the display when everyone is ready.
7089 for (i=0; i<NN && goodToGo; i++) {
7090 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007091 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007092 "Check opening app" + wtoken + ": allDrawn="
7093 + wtoken.allDrawn + " startingDisplayed="
7094 + wtoken.startingDisplayed);
7095 if (!wtoken.allDrawn && !wtoken.startingDisplayed
7096 && !wtoken.startingMoved) {
7097 goodToGo = false;
7098 }
7099 }
7100 }
7101 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007102 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 int transit = mNextAppTransition;
7104 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007105 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007107 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007109 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007110 mAppTransitionTimeout = false;
7111 mStartingIconInTransition = false;
7112 mSkipAppTransitionAnimation = false;
7113
7114 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
7115
Dianne Hackborna8f60182009-09-01 19:01:50 -07007116 // If there are applications waiting to come to the
7117 // top of the stack, now is the time to move their windows.
7118 // (Note that we don't do apps going to the bottom
7119 // here -- we want to keep their windows in the old
7120 // Z-order until the animation completes.)
7121 if (mToTopApps.size() > 0) {
7122 NN = mAppTokens.size();
7123 for (i=0; i<NN; i++) {
7124 AppWindowToken wtoken = mAppTokens.get(i);
7125 if (wtoken.sendingToTop) {
7126 wtoken.sendingToTop = false;
7127 moveAppWindowsLocked(wtoken, NN, false);
7128 }
7129 }
7130 mToTopApps.clear();
7131 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007132
Dianne Hackborn25994b42009-09-04 14:21:19 -07007133 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007134
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007135 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007136 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007137
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007138 // The top-most window will supply the layout params,
7139 // and we will determine it below.
7140 LayoutParams animLp = null;
7141 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007142 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007143
Joe Onorato8a9b2202010-02-26 18:56:32 -08007144 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007145 "New wallpaper target=" + mWallpaperTarget
7146 + ", lower target=" + mLowerWallpaperTarget
7147 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07007148 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007149 // Do a first pass through the tokens for two
7150 // things:
7151 // (1) Determine if both the closing and opening
7152 // app token sets are wallpaper targets, in which
7153 // case special animations are needed
7154 // (since the wallpaper needs to stay static
7155 // behind them).
7156 // (2) Find the layout params of the top-most
7157 // application window in the tokens, which is
7158 // what will control the animation theme.
7159 final int NC = mClosingApps.size();
7160 NN = NC + mOpeningApps.size();
7161 for (i=0; i<NN; i++) {
7162 AppWindowToken wtoken;
7163 int mode;
7164 if (i < NC) {
7165 wtoken = mClosingApps.get(i);
7166 mode = 1;
7167 } else {
7168 wtoken = mOpeningApps.get(i-NC);
7169 mode = 2;
7170 }
7171 if (mLowerWallpaperTarget != null) {
7172 if (mLowerWallpaperTarget.mAppToken == wtoken
7173 || mUpperWallpaperTarget.mAppToken == wtoken) {
7174 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007175 }
7176 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007177 if (wtoken.appFullscreen) {
7178 WindowState ws = wtoken.findMainWindow();
7179 if (ws != null) {
7180 // If this is a compatibility mode
7181 // window, we will always use its anim.
7182 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
7183 animLp = ws.mAttrs;
7184 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007185 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007186 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007187 bestAnimLayer = ws.mLayer;
7188 }
7189 fullscreenAnim = true;
7190 }
7191 } else if (!fullscreenAnim) {
7192 WindowState ws = wtoken.findMainWindow();
7193 if (ws != null) {
7194 if (ws.mLayer > bestAnimLayer) {
7195 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007196 bestAnimLayer = ws.mLayer;
7197 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07007198 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007199 }
7200 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007201
Dianne Hackborn25994b42009-09-04 14:21:19 -07007202 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007203 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007204 "Wallpaper animation!");
7205 switch (transit) {
7206 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
7207 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
7208 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
7209 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
7210 break;
7211 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
7212 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
7213 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
7214 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
7215 break;
7216 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007217 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007218 "New transit: " + transit);
7219 } else if (oldWallpaper != null) {
7220 // We are transitioning from an activity with
7221 // a wallpaper to one without.
7222 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007223 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007224 "New transit away from wallpaper: " + transit);
7225 } else if (mWallpaperTarget != null) {
7226 // We are transitioning from an activity without
7227 // a wallpaper to now showing the wallpaper
7228 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007229 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007230 "New transit into wallpaper: " + transit);
7231 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007232
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007233 // If all closing windows are obscured, then there is
7234 // no need to do an animation. This is the case, for
7235 // example, when this transition is being done behind
7236 // the lock screen.
7237 if (!mPolicy.allowAppAnimationsLw()) {
7238 animLp = null;
7239 }
7240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007241 NN = mOpeningApps.size();
7242 for (i=0; i<NN; i++) {
7243 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007244 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007245 "Now opening app" + wtoken);
7246 wtoken.reportedVisible = false;
7247 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07007248 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007249 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007250 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07007251 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 wtoken.showAllWindowsLocked();
7253 }
7254 NN = mClosingApps.size();
7255 for (i=0; i<NN; i++) {
7256 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007257 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007258 "Now closing app" + wtoken);
7259 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07007260 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007261 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07007263 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007264 // Force the allDrawn flag, because we want to start
7265 // this guy's animations regardless of whether it's
7266 // gotten drawn.
7267 wtoken.allDrawn = true;
7268 }
7269
Dianne Hackborn8b571a82009-09-25 16:09:43 -07007270 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007272 mOpeningApps.clear();
7273 mClosingApps.clear();
7274
7275 // This has changed the visibility of windows, so perform
7276 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007277 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
7278 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07007280 if (!moveInputMethodWindowsIfNeededLocked(true)) {
7281 assignLayersLocked();
7282 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08007283 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
7284 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007285 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007286 }
7287 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007288
Dianne Hackborn16064f92010-03-25 00:47:24 -07007289 int adjResult = 0;
7290
Dianne Hackborna8f60182009-09-01 19:01:50 -07007291 if (!animating && mAppTransitionRunning) {
7292 // We have finished the animation of an app transition. To do
7293 // this, we have delayed a lot of operations like showing and
7294 // hiding apps, moving apps in Z-order, etc. The app token list
7295 // reflects the correct Z-order, but the window list may now
7296 // be out of sync with it. So here we will just rebuild the
7297 // entire app window list. Fun!
7298 mAppTransitionRunning = false;
7299 // Clear information about apps that were moving.
7300 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007301
Dianne Hackborna8f60182009-09-01 19:01:50 -07007302 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007303 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007304 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007305 moveInputMethodWindowsIfNeededLocked(false);
7306 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08007307 // Since the window list has been rebuilt, focus might
7308 // have to be recomputed since the actual order of windows
7309 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007310 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007311 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007312
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007313 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007314 // At this point, there was a window with a wallpaper that
7315 // was force hiding other windows behind it, but now it
7316 // is going away. This may be simple -- just animate
7317 // away the wallpaper and its window -- or it may be
7318 // hard -- the wallpaper now needs to be shown behind
7319 // something that was hidden.
7320 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007321 if (mLowerWallpaperTarget != null
7322 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007323 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007324 "wallpaperForceHiding changed with lower="
7325 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007326 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007327 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
7328 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
7329 if (mLowerWallpaperTarget.mAppToken.hidden) {
7330 // The lower target has become hidden before we
7331 // actually started the animation... let's completely
7332 // re-evaluate everything.
7333 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007334 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007335 }
7336 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07007337 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007338 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007339 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007340 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007341 + " NEW: " + mWallpaperTarget
7342 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007343 if (mLowerWallpaperTarget == null) {
7344 // Whoops, we don't need a special wallpaper animation.
7345 // Clear them out.
7346 forceHiding = false;
7347 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07007348 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007349 if (w.mSurface != null) {
7350 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07007351 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007352 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007353 forceHiding = true;
7354 } else if (mPolicy.canBeForceHidden(w, attrs)) {
7355 if (!w.mAnimating) {
7356 // We set the animation above so it
7357 // is not yet running.
7358 w.clearAnimation();
7359 }
7360 }
7361 }
7362 }
7363 }
7364 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007365
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08007366 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
7367 if (DEBUG_WALLPAPER) Slog.v(TAG,
7368 "Detached wallpaper changed from " + mWindowDetachedWallpaper
7369 + windowDetachedWallpaper);
7370 mWindowDetachedWallpaper = windowDetachedWallpaper;
7371 wallpaperMayChange = true;
7372 }
7373
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007374 if (windowAnimationBackgroundColor != 0) {
7375 if (mWindowAnimationBackgroundSurface == null) {
7376 mWindowAnimationBackgroundSurface = new DimSurface(mFxSession);
7377 }
7378 mWindowAnimationBackgroundSurface.show(dw, dh,
7379 windowAnimationBackground.mAnimLayer - LAYER_OFFSET_DIM,
7380 windowAnimationBackgroundColor);
7381 } else if (mWindowAnimationBackgroundSurface != null) {
7382 mWindowAnimationBackgroundSurface.hide();
7383 }
7384
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007385 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007386 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007387 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07007388 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007389 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007390
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007391 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007392 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007393 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007394 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007395 assignLayersLocked();
7396 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007397 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007398 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007399 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007400 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007401
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007402 if (mFocusMayChange) {
7403 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08007404 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
7405 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007406 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007407 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007408 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007409 }
7410
7411 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007412 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007413 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007414
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007415 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
7416 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007417 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418
7419 // THIRD LOOP: Update the surfaces of all windows.
7420
7421 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
7422
7423 boolean obscured = false;
7424 boolean blurring = false;
7425 boolean dimming = false;
7426 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007427 boolean syswin = false;
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007428 boolean backgroundFillerWasShown = mBackgroundFillerTarget != null;
7429 mBackgroundFillerTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07007431 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07007434 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435
7436 boolean displayed = false;
7437 final WindowManager.LayoutParams attrs = w.mAttrs;
7438 final int attrFlags = attrs.flags;
7439
7440 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007441 // XXX NOTE: The logic here could be improved. We have
7442 // the decision about whether to resize a window separated
7443 // from whether to hide the surface. This can cause us to
7444 // resize a surface even if we are going to hide it. You
7445 // can see this by (1) holding device in landscape mode on
7446 // home screen; (2) tapping browser icon (device will rotate
7447 // to landscape; (3) tap home. The wallpaper will be resized
7448 // in step 2 but then immediately hidden, causing us to
7449 // have to resize and then redraw it again in step 3. It
7450 // would be nice to figure out how to avoid this, but it is
7451 // difficult because we do need to resize surfaces in some
7452 // cases while they are hidden such as when first showing a
7453 // window.
7454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007455 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08007456 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007457 TAG, "Placing surface #" + i + " " + w.mSurface
7458 + ": new=" + w.mShownFrame + ", old="
7459 + w.mLastShownFrame);
7460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 int width, height;
7462 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 // for a scaled surface, we just want to use
7464 // the requested size.
7465 width = w.mRequestedWidth;
7466 height = w.mRequestedHeight;
7467 w.mLastRequestedWidth = width;
7468 w.mLastRequestedHeight = height;
7469 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007471 width = w.mShownFrame.width();
7472 height = w.mShownFrame.height();
7473 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 }
7475
Jeff Brownfbae7222011-01-23 13:07:25 -08007476 if (w.mSurface != null) {
7477 if (w.mSurfaceX != w.mShownFrame.left
7478 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007479 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007480 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -08007481 "POS " + w.mShownFrame.left
7482 + ", " + w.mShownFrame.top, null);
7483 w.mSurfaceX = w.mShownFrame.left;
7484 w.mSurfaceY = w.mShownFrame.top;
7485 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
7486 } catch (RuntimeException e) {
7487 Slog.w(TAG, "Error positioning surface of " + w
7488 + " pos=(" + w.mShownFrame.left
7489 + "," + w.mShownFrame.top + ")", e);
7490 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007491 reclaimSomeSurfaceMemoryLocked(w, "position", true);
Jeff Brownfbae7222011-01-23 13:07:25 -08007492 }
7493 }
7494 }
7495
7496 if (width < 1) {
7497 width = 1;
7498 }
7499 if (height < 1) {
7500 height = 1;
7501 }
7502
7503 if (w.mSurfaceW != width || w.mSurfaceH != height) {
7504 try {
7505 if (SHOW_TRANSACTIONS) logSurface(w,
7506 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007507 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007508 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007509 w.mSurfaceW = width;
7510 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 } catch (RuntimeException e) {
7513 // If something goes wrong with the surface (such
7514 // as running out of memory), don't take down the
7515 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -08007516 Slog.e(TAG, "Error resizing surface of " + w
7517 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007518 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007519 reclaimSomeSurfaceMemoryLocked(w, "size", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 }
7521 }
7522 }
7523 }
Jeff Brownfbae7222011-01-23 13:07:25 -08007524
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007525 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 w.mContentInsetsChanged =
7527 !w.mLastContentInsets.equals(w.mContentInsets);
7528 w.mVisibleInsetsChanged =
7529 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007530 boolean configChanged =
7531 w.mConfiguration != mCurConfiguration
7532 && (w.mConfiguration == null
7533 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007534 if (DEBUG_CONFIGURATION && configChanged) {
7535 Slog.v(TAG, "Win " + w + " config changed: "
7536 + mCurConfiguration);
7537 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007538 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007539 + ": configChanged=" + configChanged
7540 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -08007541 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
7542 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007544 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007545 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007546 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -08007547 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
7548 Slog.v(TAG, "Resize reasons: "
7549 + "frameChanged=" + frameChanged
7550 + " contentInsetsChanged=" + w.mContentInsetsChanged
7551 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
7552 + " surfaceResized=" + w.mSurfaceResized
7553 + " configChanged=" + configChanged);
7554 }
7555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007556 w.mLastFrame.set(w.mFrame);
7557 w.mLastContentInsets.set(w.mContentInsets);
7558 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007559 // If the screen is currently frozen, then keep
7560 // it frozen until this window draws at its new
7561 // orientation.
7562 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007563 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007564 "Resizing while display frozen: " + w);
7565 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007566 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007567 mWindowsFreezingScreen = true;
7568 // XXX should probably keep timeout from
7569 // when we first froze the display.
7570 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
7571 mH.sendMessageDelayed(mH.obtainMessage(
7572 H.WINDOW_FREEZE_TIMEOUT), 2000);
7573 }
7574 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 // If the orientation is changing, then we need to
7576 // hold off on unfreezing the display until this
7577 // window has been redrawn; to do that, we need
7578 // to go through the process of getting informed
7579 // by the application when it has finished drawing.
7580 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007581 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 "Orientation start waiting for draw in "
7583 + w + ", surface " + w.mSurface);
7584 w.mDrawPending = true;
7585 w.mCommitDrawPending = false;
7586 w.mReadyToShow = false;
7587 if (w.mAppToken != null) {
7588 w.mAppToken.allDrawn = false;
7589 }
7590 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007591 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 "Resizing window " + w + " to " + w.mFrame);
7593 mResizingWindows.add(w);
7594 } else if (w.mOrientationChanging) {
7595 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007596 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 "Orientation not waiting for draw in "
7598 + w + ", surface " + w.mSurface);
7599 w.mOrientationChanging = false;
7600 }
7601 }
7602 }
7603
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007604 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 if (!w.mLastHidden) {
7606 //dump();
7607 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007608 if (SHOW_TRANSACTIONS) logSurface(w,
7609 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007610 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007611 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 try {
7613 w.mSurface.hide();
7614 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007615 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007616 }
7617 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 }
7619 // If we are waiting for this window to handle an
7620 // orientation change, well, it is hidden, so
7621 // doesn't really matter. Note that this does
7622 // introduce a potential glitch if the window
7623 // becomes unhidden before it has drawn for the
7624 // new orientation.
7625 if (w.mOrientationChanging) {
7626 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007627 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007628 "Orientation change skips hidden " + w);
7629 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007630 } else if (w.mLastLayer != w.mAnimLayer
7631 || w.mLastAlpha != w.mShownAlpha
7632 || w.mLastDsDx != w.mDsDx
7633 || w.mLastDtDx != w.mDtDx
7634 || w.mLastDsDy != w.mDsDy
7635 || w.mLastDtDy != w.mDtDy
7636 || w.mLastHScale != w.mHScale
7637 || w.mLastVScale != w.mVScale
7638 || w.mLastHidden) {
7639 displayed = true;
7640 w.mLastAlpha = w.mShownAlpha;
7641 w.mLastLayer = w.mAnimLayer;
7642 w.mLastDsDx = w.mDsDx;
7643 w.mLastDtDx = w.mDtDx;
7644 w.mLastDsDy = w.mDsDy;
7645 w.mLastDtDy = w.mDtDy;
7646 w.mLastHScale = w.mHScale;
7647 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007648 if (SHOW_TRANSACTIONS) logSurface(w,
7649 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007650 + " matrix=[" + (w.mDsDx*w.mHScale)
7651 + "," + (w.mDtDx*w.mVScale)
7652 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007653 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007654 if (w.mSurface != null) {
7655 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007656 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007657 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007658 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 w.mSurface.setLayer(w.mAnimLayer);
7660 w.mSurface.setMatrix(
7661 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
7662 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
7663 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007664 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007666 reclaimSomeSurfaceMemoryLocked(w, "update", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007667 }
7668 }
7669 }
7670
7671 if (w.mLastHidden && !w.mDrawPending
7672 && !w.mCommitDrawPending
7673 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007674 if (SHOW_TRANSACTIONS) logSurface(w,
7675 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007676 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007677 + " during relayout");
7678 if (showSurfaceRobustlyLocked(w)) {
7679 w.mHasDrawn = true;
7680 w.mLastHidden = false;
7681 } else {
7682 w.mOrientationChanging = false;
7683 }
7684 }
7685 if (w.mSurface != null) {
7686 w.mToken.hasVisible = true;
7687 }
7688 } else {
7689 displayed = true;
7690 }
7691
7692 if (displayed) {
7693 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08007694 if (attrs.width == LayoutParams.MATCH_PARENT
7695 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 covered = true;
7697 }
7698 }
7699 if (w.mOrientationChanging) {
7700 if (w.mDrawPending || w.mCommitDrawPending) {
7701 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007702 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007703 "Orientation continue waiting for draw in " + w);
7704 } else {
7705 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007706 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007707 "Orientation change complete in " + w);
7708 }
7709 }
7710 w.mToken.hasVisible = true;
7711 }
7712 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007713 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007714 "Orientation change skips hidden " + w);
7715 w.mOrientationChanging = false;
7716 }
7717
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007718 if (w.mContentChanged) {
7719 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
7720 w.mContentChanged = false;
7721 }
7722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007723 final boolean canBeSeen = w.isDisplayedLw();
7724
7725 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
7726 focusDisplayed = true;
7727 }
7728
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007729 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007730
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007731 if (mBackgroundFillerTarget != null) {
7732 if (w.isAnimating()) {
7733 // Background filler is below all other windows that
7734 // are animating.
7735 mBackgroundFillerTarget = w;
7736 } else if (w.mIsWallpaper) {
7737 mBackgroundFillerTarget = w;
7738 }
7739 }
7740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007741 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007742 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007743 if (w.mSurface != null) {
7744 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
7745 holdScreen = w.mSession;
7746 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007747 if (!syswin && w.mAttrs.screenBrightness >= 0
7748 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007749 screenBrightness = w.mAttrs.screenBrightness;
7750 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05007751 if (!syswin && w.mAttrs.buttonBrightness >= 0
7752 && buttonBrightness < 0) {
7753 buttonBrightness = w.mAttrs.buttonBrightness;
7754 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05007755 if (canBeSeen
7756 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
7757 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
7758 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007759 syswin = true;
7760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007762
Dianne Hackborn25994b42009-09-04 14:21:19 -07007763 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
7764 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 // This window completely covers everything behind it,
7766 // so we want to leave all of them as unblurred (for
7767 // performance reasons).
7768 obscured = true;
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007769 } else if (w.needsBackgroundFiller(dw, dh) && (canBeSeen || w.isAnimating())) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007770 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007771 obscured = true;
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007772 mBackgroundFillerTarget = w;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007773 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007775 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 + ": blurring=" + blurring
7777 + " obscured=" + obscured
7778 + " displayed=" + displayed);
7779 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
7780 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007781 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007782 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007783 if (mDimAnimator == null) {
7784 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007785 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007786 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007787 mDimAnimator.updateParameters(mContext.getResources(),
7788 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007789 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 }
7791 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
7792 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007793 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007794 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007795 if (mBlurSurface == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 try {
Romain Guy06882f82009-06-10 13:36:04 -07007797 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007798 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 -1, 16, 16,
7800 PixelFormat.OPAQUE,
7801 Surface.FX_SURFACE_BLUR);
7802 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007803 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007804 }
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007805 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7806 + mBlurSurface + ": CREATE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007808 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007809 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7810 + mBlurSurface + ": pos=(0,0) (" +
7811 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007812 mBlurSurface.setPosition(0, 0);
7813 mBlurSurface.setSize(dw, dh);
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007814 mBlurSurface.setLayer(w.mAnimLayer-LAYER_OFFSET_BLUR);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007815 if (!mBlurShown) {
7816 try {
7817 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7818 + mBlurSurface + ": SHOW");
7819 mBlurSurface.show();
7820 } catch (RuntimeException e) {
7821 Slog.w(TAG, "Failure showing blur surface", e);
7822 }
7823 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007824 }
7825 }
7826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007827 }
7828 }
7829 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007830
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007831 if (obscuredChanged && mWallpaperTarget == w) {
7832 // This is the wallpaper target and its obscured state
7833 // changed... make sure the current wallaper's visibility
7834 // has been updated accordingly.
7835 updateWallpaperVisibilityLocked();
7836 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007837 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007838
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007839 if (mBackgroundFillerTarget != null) {
7840 if (mBackgroundFillerSurface == null) {
7841 try {
7842 mBackgroundFillerSurface = new Surface(mFxSession, 0,
7843 "BackGroundFiller",
7844 0, dw, dh,
7845 PixelFormat.OPAQUE,
7846 Surface.FX_SURFACE_NORMAL);
7847 } catch (Exception e) {
7848 Slog.e(TAG, "Exception creating filler surface", e);
7849 }
7850 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7851 + mBackgroundFillerSurface + ": CREATE");
7852 }
7853 try {
7854 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7855 + mBackgroundFillerSurface + " SHOW: pos=(0,0) ("
7856 + dw + "x" + dh + ") layer="
7857 + (mBackgroundFillerTarget.mLayer - 1));
7858 mBackgroundFillerSurface.setPosition(0, 0);
7859 mBackgroundFillerSurface.setSize(dw, dh);
7860 // Using the same layer as Dim because they will never be shown at the
7861 // same time. NOTE: we do NOT use mAnimLayer, because we don't
7862 // want this surface dragged up in front of stuff that is animating.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007863 mBackgroundFillerSurface.setLayer(mBackgroundFillerTarget.mLayer
7864 - LAYER_OFFSET_DIM);
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007865 mBackgroundFillerSurface.show();
7866 } catch (RuntimeException e) {
7867 Slog.e(TAG, "Exception showing filler surface");
7868 }
7869 } else if (backgroundFillerWasShown) {
7870 mBackgroundFillerTarget = null;
7871 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7872 + mBackgroundFillerSurface + " HIDE");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007873 try {
7874 mBackgroundFillerSurface.hide();
7875 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007876 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007877 }
7878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007879
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007880 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007881 animating |= mDimAnimator.updateSurface(dimming, currentTime,
7882 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007883 }
Romain Guy06882f82009-06-10 13:36:04 -07007884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007886 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007887 + ": HIDE");
7888 try {
7889 mBlurSurface.hide();
7890 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007891 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007892 }
7893 mBlurShown = false;
7894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007896 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007897 }
7898
7899 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07007900
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007901 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
7902
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07007903 if (mWatermark != null) {
7904 mWatermark.drawIfNeeded();
7905 }
7906
Joe Onorato8a9b2202010-02-26 18:56:32 -08007907 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 "With display frozen, orientationChangeComplete="
7909 + orientationChangeComplete);
7910 if (orientationChangeComplete) {
7911 if (mWindowsFreezingScreen) {
7912 mWindowsFreezingScreen = false;
7913 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
7914 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007915 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 }
Romain Guy06882f82009-06-10 13:36:04 -07007917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007918 i = mResizingWindows.size();
7919 if (i > 0) {
7920 do {
7921 i--;
7922 WindowState win = mResizingWindows.get(i);
7923 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007924 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
7925 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007926 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007927 boolean configChanged =
7928 win.mConfiguration != mCurConfiguration
7929 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007930 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
7931 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
7932 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007933 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007934 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007935 + " / " + mCurConfiguration + " / 0x"
7936 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007937 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007938 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007939 win.mClient.resized(win.mFrame.width(),
7940 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007941 win.mLastVisibleInsets, win.mDrawPending,
7942 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007943 win.mContentInsetsChanged = false;
7944 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007945 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007946 } catch (RemoteException e) {
7947 win.mOrientationChanging = false;
7948 }
7949 } while (i > 0);
7950 mResizingWindows.clear();
7951 }
Romain Guy06882f82009-06-10 13:36:04 -07007952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007953 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007954 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007955 i = mDestroySurface.size();
7956 if (i > 0) {
7957 do {
7958 i--;
7959 WindowState win = mDestroySurface.get(i);
7960 win.mDestroying = false;
7961 if (mInputMethodWindow == win) {
7962 mInputMethodWindow = null;
7963 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007964 if (win == mWallpaperTarget) {
7965 wallpaperDestroyed = true;
7966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007967 win.destroySurfaceLocked();
7968 } while (i > 0);
7969 mDestroySurface.clear();
7970 }
7971
7972 // Time to remove any exiting tokens?
7973 for (i=mExitingTokens.size()-1; i>=0; i--) {
7974 WindowToken token = mExitingTokens.get(i);
7975 if (!token.hasVisible) {
7976 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007977 if (token.windowType == TYPE_WALLPAPER) {
7978 mWallpaperTokens.remove(token);
7979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 }
7981 }
7982
7983 // Time to remove any exiting applications?
7984 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
7985 AppWindowToken token = mExitingAppTokens.get(i);
7986 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07007987 // Make sure there is no animation running on this token,
7988 // so any windows associated with it will be removed as
7989 // soon as their animations are complete
7990 token.animation = null;
7991 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007992 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
7993 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007994 mAppTokens.remove(token);
7995 mExitingAppTokens.remove(i);
7996 }
7997 }
7998
Dianne Hackborna8f60182009-09-01 19:01:50 -07007999 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008000
Dianne Hackborna8f60182009-09-01 19:01:50 -07008001 if (!animating && mAppTransitionRunning) {
8002 // We have finished the animation of an app transition. To do
8003 // this, we have delayed a lot of operations like showing and
8004 // hiding apps, moving apps in Z-order, etc. The app token list
8005 // reflects the correct Z-order, but the window list may now
8006 // be out of sync with it. So here we will just rebuild the
8007 // entire app window list. Fun!
8008 mAppTransitionRunning = false;
8009 needRelayout = true;
8010 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008011 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008012 // Clear information about apps that were moving.
8013 mToBottomApps.clear();
8014 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 if (focusDisplayed) {
8017 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
8018 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008019 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008020 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008021 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008022 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008023 requestAnimationLocked(0);
8024 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
8026 }
Jeff Browneb857f12010-07-16 10:06:33 -07008027
Jeff Brown3a22cd92011-01-21 13:59:04 -08008028 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -08008029 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -07008030
Jeff Brown8e03b752010-06-13 19:16:55 -07008031 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -08008032 if (!mDisplayFrozen) {
8033 if (screenBrightness < 0 || screenBrightness > 1.0f) {
8034 mPowerManager.setScreenBrightnessOverride(-1);
8035 } else {
8036 mPowerManager.setScreenBrightnessOverride((int)
8037 (screenBrightness * Power.BRIGHTNESS_ON));
8038 }
8039 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
8040 mPowerManager.setButtonBrightnessOverride(-1);
8041 } else {
8042 mPowerManager.setButtonBrightnessOverride((int)
8043 (buttonBrightness * Power.BRIGHTNESS_ON));
8044 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 if (holdScreen != mHoldingScreenOn) {
8047 mHoldingScreenOn = holdScreen;
8048 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
8049 mH.sendMessage(m);
8050 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008051
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008052 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008053 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008054 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
8055 LocalPowerManager.BUTTON_EVENT, true);
8056 mTurnOnScreen = false;
8057 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008058
Dianne Hackborn50660e22011-02-02 17:12:25 -08008059 if (screenRotationFinished && mScreenRotationAnimation != null) {
8060 mScreenRotationAnimation.kill();
8061 mScreenRotationAnimation = null;
8062 }
8063
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008064 if (updateRotation) {
8065 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
8066 boolean changed = setRotationUncheckedLocked(
8067 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
8068 if (changed) {
Dianne Hackborn3e4f9d02011-02-04 14:05:55 -08008069 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008070 }
8071 }
8072
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008073 // Check to see if we are now in a state where the screen should
8074 // be enabled, because the window obscured flags have changed.
8075 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07008077
8078 /**
8079 * Must be called with the main window manager lock held.
8080 */
8081 void setHoldScreenLocked(boolean holding) {
8082 boolean state = mHoldingScreenWakeLock.isHeld();
8083 if (holding != state) {
8084 if (holding) {
8085 mHoldingScreenWakeLock.acquire();
8086 } else {
8087 mPolicy.screenOnStoppedLw();
8088 mHoldingScreenWakeLock.release();
8089 }
8090 }
8091 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008092
8093 void requestAnimationLocked(long delay) {
8094 if (!mAnimationPending) {
8095 mAnimationPending = true;
8096 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
8097 }
8098 }
Romain Guy06882f82009-06-10 13:36:04 -07008099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008100 /**
8101 * Have the surface flinger show a surface, robustly dealing with
8102 * error conditions. In particular, if there is not enough memory
8103 * to show the surface, then we will try to get rid of other surfaces
8104 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07008105 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008106 * @return Returns true if the surface was successfully shown.
8107 */
8108 boolean showSurfaceRobustlyLocked(WindowState win) {
8109 try {
8110 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07008111 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008112 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008113 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008114 if (DEBUG_VISIBILITY) Slog.v(TAG,
8115 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008116 win.mTurnOnScreen = false;
8117 mTurnOnScreen = true;
8118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008119 }
8120 return true;
8121 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008122 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008123 }
Romain Guy06882f82009-06-10 13:36:04 -07008124
Dianne Hackborn64825172011-03-02 21:32:58 -08008125 reclaimSomeSurfaceMemoryLocked(win, "show", true);
Romain Guy06882f82009-06-10 13:36:04 -07008126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008127 return false;
8128 }
Romain Guy06882f82009-06-10 13:36:04 -07008129
Dianne Hackborn64825172011-03-02 21:32:58 -08008130 boolean reclaimSomeSurfaceMemoryLocked(WindowState win, String operation, boolean secure) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008131 final Surface surface = win.mSurface;
Dianne Hackborn64825172011-03-02 21:32:58 -08008132 boolean leakedSurface = false;
8133 boolean killedApps = false;
Romain Guy06882f82009-06-10 13:36:04 -07008134
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008135 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008136 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07008137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008138 if (mForceRemoves == null) {
8139 mForceRemoves = new ArrayList<WindowState>();
8140 }
Romain Guy06882f82009-06-10 13:36:04 -07008141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008142 long callingIdentity = Binder.clearCallingIdentity();
8143 try {
8144 // There was some problem... first, do a sanity check of the
8145 // window list to make sure we haven't left any dangling surfaces
8146 // around.
8147 int N = mWindows.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08008148 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008149 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008150 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 if (ws.mSurface != null) {
8152 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008153 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008154 + ws + " surface=" + ws.mSurface
8155 + " token=" + win.mToken
8156 + " pid=" + ws.mSession.mPid
8157 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008158 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008159 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008160 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008161 ws.mSurface = null;
8162 mForceRemoves.add(ws);
8163 i--;
8164 N--;
8165 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008166 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008167 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008168 + ws + " surface=" + ws.mSurface
8169 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008170 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008171 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008172 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008173 ws.mSurface = null;
8174 leakedSurface = true;
8175 }
8176 }
8177 }
Romain Guy06882f82009-06-10 13:36:04 -07008178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008179 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008180 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008181 SparseIntArray pidCandidates = new SparseIntArray();
8182 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008183 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008184 if (ws.mSurface != null) {
8185 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
8186 }
8187 }
8188 if (pidCandidates.size() > 0) {
8189 int[] pids = new int[pidCandidates.size()];
8190 for (int i=0; i<pids.length; i++) {
8191 pids[i] = pidCandidates.keyAt(i);
8192 }
8193 try {
Dianne Hackborn64825172011-03-02 21:32:58 -08008194 if (mActivityManager.killPids(pids, "Free memory", secure)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008195 killedApps = true;
8196 }
8197 } catch (RemoteException e) {
8198 }
8199 }
8200 }
Romain Guy06882f82009-06-10 13:36:04 -07008201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008202 if (leakedSurface || killedApps) {
8203 // We managed to reclaim some memory, so get rid of the trouble
8204 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08008205 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008206 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008207 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008208 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008209 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008210 win.mSurface = null;
8211 }
Romain Guy06882f82009-06-10 13:36:04 -07008212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008213 try {
8214 win.mClient.dispatchGetNewSurface();
8215 } catch (RemoteException e) {
8216 }
8217 }
8218 } finally {
8219 Binder.restoreCallingIdentity(callingIdentity);
8220 }
Dianne Hackborn64825172011-03-02 21:32:58 -08008221
8222 return leakedSurface || killedApps;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008223 }
Romain Guy06882f82009-06-10 13:36:04 -07008224
Jeff Brown3a22cd92011-01-21 13:59:04 -08008225 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008226 WindowState newFocus = computeFocusedWindowLocked();
8227 if (mCurrentFocus != newFocus) {
8228 // This check makes sure that we don't already have the focus
8229 // change message pending.
8230 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
8231 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008232 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008233 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
8234 final WindowState oldFocus = mCurrentFocus;
8235 mCurrentFocus = newFocus;
8236 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07008237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 final WindowState imWindow = mInputMethodWindow;
8239 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008240 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008241 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008242 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
8243 mLayoutNeeded = true;
8244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008245 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08008246 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008247 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
8248 // Client will do the layout, but we need to assign layers
8249 // for handleNewWindowLocked() below.
8250 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008251 }
8252 }
Jeff Brown349703e2010-06-22 01:27:15 -07008253
8254 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
8255 // If we defer assigning layers, then the caller is responsible for
8256 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -08008257 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008259 return true;
8260 }
8261 return false;
8262 }
Jeff Brown349703e2010-06-22 01:27:15 -07008263
Jeff Brown3a22cd92011-01-21 13:59:04 -08008264 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
8265 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -07008266 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008267
8268 private WindowState computeFocusedWindowLocked() {
8269 WindowState result = null;
8270 WindowState win;
8271
8272 int i = mWindows.size() - 1;
8273 int nextAppIndex = mAppTokens.size()-1;
8274 WindowToken nextApp = nextAppIndex >= 0
8275 ? mAppTokens.get(nextAppIndex) : null;
8276
8277 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008278 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279
Joe Onorato8a9b2202010-02-26 18:56:32 -08008280 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008281 TAG, "Looking for focus: " + i
8282 + " = " + win
8283 + ", flags=" + win.mAttrs.flags
8284 + ", canReceive=" + win.canReceiveKeys());
8285
8286 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07008287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008288 // If this window's application has been removed, just skip it.
8289 if (thisApp != null && thisApp.removed) {
8290 i--;
8291 continue;
8292 }
Romain Guy06882f82009-06-10 13:36:04 -07008293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008294 // If there is a focused app, don't allow focus to go to any
8295 // windows below it. If this is an application window, step
8296 // through the app tokens until we find its app.
8297 if (thisApp != null && nextApp != null && thisApp != nextApp
8298 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
8299 int origAppIndex = nextAppIndex;
8300 while (nextAppIndex > 0) {
8301 if (nextApp == mFocusedApp) {
8302 // Whoops, we are below the focused app... no focus
8303 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08008304 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008305 TAG, "Reached focused app: " + mFocusedApp);
8306 return null;
8307 }
8308 nextAppIndex--;
8309 nextApp = mAppTokens.get(nextAppIndex);
8310 if (nextApp == thisApp) {
8311 break;
8312 }
8313 }
8314 if (thisApp != nextApp) {
8315 // Uh oh, the app token doesn't exist! This shouldn't
8316 // happen, but if it does we can get totally hosed...
8317 // so restart at the original app.
8318 nextAppIndex = origAppIndex;
8319 nextApp = mAppTokens.get(nextAppIndex);
8320 }
8321 }
8322
8323 // Dispatch to this window if it is wants key events.
8324 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008325 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008326 TAG, "Found focus @ " + i + " = " + win);
8327 result = win;
8328 break;
8329 }
8330
8331 i--;
8332 }
8333
8334 return result;
8335 }
8336
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008337 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008338 if (mDisplayFrozen) {
8339 return;
8340 }
Romain Guy06882f82009-06-10 13:36:04 -07008341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008342 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07008343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008344 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08008345 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008346 if (mFreezeGcPending != 0) {
8347 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008348 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008349 mH.removeMessages(H.FORCE_GC);
8350 Runtime.getRuntime().gc();
8351 mFreezeGcPending = now;
8352 }
8353 } else {
8354 mFreezeGcPending = now;
8355 }
Romain Guy06882f82009-06-10 13:36:04 -07008356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008357 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07008358
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008359 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07008360
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008361 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
8362 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008363 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008364 mAppTransitionReady = true;
8365 }
Romain Guy06882f82009-06-10 13:36:04 -07008366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008367 if (PROFILE_ORIENTATION) {
8368 File file = new File("/data/system/frozen");
8369 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
8370 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008371
8372 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08008373 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
8374 mScreenRotationAnimation.kill();
8375 mScreenRotationAnimation = null;
8376 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008377 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08008378 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008379 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -08008380 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008381 if (!mScreenRotationAnimation.hasScreenshot()) {
8382 Surface.freezeDisplay(0);
8383 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008384 } else {
8385 Surface.freezeDisplay(0);
8386 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008387 }
Romain Guy06882f82009-06-10 13:36:04 -07008388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008389 private void stopFreezingDisplayLocked() {
8390 if (!mDisplayFrozen) {
8391 return;
8392 }
Romain Guy06882f82009-06-10 13:36:04 -07008393
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008394 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
8395 return;
8396 }
8397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008398 mDisplayFrozen = false;
8399 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
8400 if (PROFILE_ORIENTATION) {
8401 Debug.stopMethodTracing();
8402 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008403
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008404 boolean updateRotation = false;
8405
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008406 if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
8407 && mScreenRotationAnimation.hasScreenshot()) {
8408 if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION,
8409 mTransitionAnimationScale)) {
8410 requestAnimationLocked(0);
8411 } else {
8412 mScreenRotationAnimation = null;
8413 updateRotation = true;
Dianne Hackborna1111872010-11-23 20:55:11 -08008414 }
8415 } else {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008416 if (mScreenRotationAnimation != null) {
8417 mScreenRotationAnimation.kill();
8418 mScreenRotationAnimation = null;
8419 }
8420 updateRotation = true;
Dianne Hackborna1111872010-11-23 20:55:11 -08008421 Surface.unfreezeDisplay(0);
8422 }
Romain Guy06882f82009-06-10 13:36:04 -07008423
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008424 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008425
Dianne Hackborn420829e2011-01-28 11:30:35 -08008426 boolean configChanged;
8427
Christopher Tateb696aee2010-04-02 19:08:30 -07008428 // While the display is frozen we don't re-compute the orientation
8429 // to avoid inconsistent states. However, something interesting
8430 // could have actually changed during that time so re-evaluate it
8431 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -08008432 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -07008433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008434 // A little kludge: a lot could have happened while the
8435 // display was frozen, so now that we are coming back we
8436 // do a gc so that any remote references the system
8437 // processes holds on others can be released if they are
8438 // no longer needed.
8439 mH.removeMessages(H.FORCE_GC);
8440 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8441 2000);
Romain Guy06882f82009-06-10 13:36:04 -07008442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008443 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008444
8445 if (updateRotation) {
8446 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -08008447 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008448 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -08008449 }
8450
8451 if (configChanged) {
8452 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008454 }
Romain Guy06882f82009-06-10 13:36:04 -07008455
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008456 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
8457 DisplayMetrics dm) {
8458 if (index < tokens.length) {
8459 String str = tokens[index];
8460 if (str != null && str.length() > 0) {
8461 try {
8462 int val = Integer.parseInt(str);
8463 return val;
8464 } catch (Exception e) {
8465 }
8466 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008467 }
8468 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
8469 return defDps;
8470 }
8471 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
8472 return val;
8473 }
8474
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008475 void createWatermark() {
8476 if (mWatermark != null) {
8477 return;
8478 }
8479
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008480 File file = new File("/system/etc/setup.conf");
8481 FileInputStream in = null;
8482 try {
8483 in = new FileInputStream(file);
8484 DataInputStream ind = new DataInputStream(in);
8485 String line = ind.readLine();
8486 if (line != null) {
8487 String[] toks = line.split("%");
8488 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -07008489 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008490 }
8491 }
8492 } catch (FileNotFoundException e) {
8493 } catch (IOException e) {
8494 } finally {
8495 if (in != null) {
8496 try {
8497 in.close();
8498 } catch (IOException e) {
8499 }
8500 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008501 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008502 }
8503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008504 @Override
Joe Onorato664644d2011-01-23 17:53:23 -08008505 public void statusBarVisibilityChanged(int visibility) {
Jeff Brown05dc66a2011-03-02 14:41:58 -08008506 mInputManager.setSystemUiVisibility(visibility);
Joe Onorato664644d2011-01-23 17:53:23 -08008507 synchronized (mWindowMap) {
8508 final int N = mWindows.size();
8509 for (int i = 0; i < N; i++) {
8510 WindowState ws = mWindows.get(i);
8511 try {
8512 if (ws.getAttrs().hasSystemUiListeners) {
8513 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
8514 }
8515 } catch (RemoteException e) {
8516 // so sorry
8517 }
8518 }
8519 }
8520 }
8521
8522 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
8524 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
8525 != PackageManager.PERMISSION_GRANTED) {
8526 pw.println("Permission Denial: can't dump WindowManager from from pid="
8527 + Binder.getCallingPid()
8528 + ", uid=" + Binder.getCallingUid());
8529 return;
8530 }
Romain Guy06882f82009-06-10 13:36:04 -07008531
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008532 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -08008533 pw.println(" ");
8534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 synchronized(mWindowMap) {
8536 pw.println("Current Window Manager state:");
8537 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008538 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008539 pw.print(" Window #"); pw.print(i); pw.print(' ');
8540 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541 w.dump(pw, " ");
8542 }
8543 if (mInputMethodDialogs.size() > 0) {
8544 pw.println(" ");
8545 pw.println(" Input method dialogs:");
8546 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
8547 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008548 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 }
8550 }
8551 if (mPendingRemove.size() > 0) {
8552 pw.println(" ");
8553 pw.println(" Remove pending for:");
8554 for (int i=mPendingRemove.size()-1; i>=0; i--) {
8555 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008556 pw.print(" Remove #"); pw.print(i); pw.print(' ');
8557 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558 w.dump(pw, " ");
8559 }
8560 }
8561 if (mForceRemoves != null && mForceRemoves.size() > 0) {
8562 pw.println(" ");
8563 pw.println(" Windows force removing:");
8564 for (int i=mForceRemoves.size()-1; i>=0; i--) {
8565 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008566 pw.print(" Removing #"); pw.print(i); pw.print(' ');
8567 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 w.dump(pw, " ");
8569 }
8570 }
8571 if (mDestroySurface.size() > 0) {
8572 pw.println(" ");
8573 pw.println(" Windows waiting to destroy their surface:");
8574 for (int i=mDestroySurface.size()-1; i>=0; i--) {
8575 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008576 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
8577 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008578 w.dump(pw, " ");
8579 }
8580 }
8581 if (mLosingFocus.size() > 0) {
8582 pw.println(" ");
8583 pw.println(" Windows losing focus:");
8584 for (int i=mLosingFocus.size()-1; i>=0; i--) {
8585 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008586 pw.print(" Losing #"); pw.print(i); pw.print(' ');
8587 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008588 w.dump(pw, " ");
8589 }
8590 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008591 if (mResizingWindows.size() > 0) {
8592 pw.println(" ");
8593 pw.println(" Windows waiting to resize:");
8594 for (int i=mResizingWindows.size()-1; i>=0; i--) {
8595 WindowState w = mResizingWindows.get(i);
8596 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
8597 pw.print(w); pw.println(":");
8598 w.dump(pw, " ");
8599 }
8600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008601 if (mSessions.size() > 0) {
8602 pw.println(" ");
8603 pw.println(" All active sessions:");
8604 Iterator<Session> it = mSessions.iterator();
8605 while (it.hasNext()) {
8606 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008607 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008608 s.dump(pw, " ");
8609 }
8610 }
8611 if (mTokenMap.size() > 0) {
8612 pw.println(" ");
8613 pw.println(" All tokens:");
8614 Iterator<WindowToken> it = mTokenMap.values().iterator();
8615 while (it.hasNext()) {
8616 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008617 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 token.dump(pw, " ");
8619 }
8620 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008621 if (mWallpaperTokens.size() > 0) {
8622 pw.println(" ");
8623 pw.println(" Wallpaper tokens:");
8624 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
8625 WindowToken token = mWallpaperTokens.get(i);
8626 pw.print(" Wallpaper #"); pw.print(i);
8627 pw.print(' '); pw.print(token); pw.println(':');
8628 token.dump(pw, " ");
8629 }
8630 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008631 if (mAppTokens.size() > 0) {
8632 pw.println(" ");
8633 pw.println(" Application tokens in Z order:");
8634 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008635 pw.print(" App #"); pw.print(i); pw.print(": ");
8636 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 }
8638 }
8639 if (mFinishedStarting.size() > 0) {
8640 pw.println(" ");
8641 pw.println(" Finishing start of application tokens:");
8642 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
8643 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008644 pw.print(" Finished Starting #"); pw.print(i);
8645 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008646 token.dump(pw, " ");
8647 }
8648 }
8649 if (mExitingTokens.size() > 0) {
8650 pw.println(" ");
8651 pw.println(" Exiting tokens:");
8652 for (int i=mExitingTokens.size()-1; i>=0; i--) {
8653 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008654 pw.print(" Exiting #"); pw.print(i);
8655 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008656 token.dump(pw, " ");
8657 }
8658 }
8659 if (mExitingAppTokens.size() > 0) {
8660 pw.println(" ");
8661 pw.println(" Exiting application tokens:");
8662 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
8663 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008664 pw.print(" Exiting App #"); pw.print(i);
8665 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008666 token.dump(pw, " ");
8667 }
8668 }
8669 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008670 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
8671 pw.print(" mLastFocus="); pw.println(mLastFocus);
8672 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
8673 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
8674 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -07008675 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -07008676 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
8677 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
8678 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
8679 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08008680 if (mWindowDetachedWallpaper != null) {
8681 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
8682 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008683 if (mWindowAnimationBackgroundSurface != null) {
8684 pw.println(" mWindowAnimationBackgroundSurface:");
8685 mWindowAnimationBackgroundSurface.printTo(" ", pw);
8686 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008687 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
8688 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
8689 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008690 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
8691 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
8692 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
8693 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008694 if (mDimAnimator != null) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008695 pw.println(" mDimAnimator:");
8696 mDimAnimator.printTo(" ", pw);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008697 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -08008698 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008699 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008700 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008701 pw.print(mInputMethodAnimLayerAdjustment);
8702 pw.print(" mWallpaperAnimLayerAdjustment=");
8703 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -07008704 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
8705 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008706 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
8707 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008708 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
8709 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008710 pw.print(" mRotation="); pw.print(mRotation);
8711 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
8712 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008713 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
8714 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008715 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
8716 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
8717 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
8718 pw.print(" mNextAppTransition=0x");
8719 pw.print(Integer.toHexString(mNextAppTransition));
8720 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008721 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008722 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008723 if (mNextAppTransitionPackage != null) {
8724 pw.print(" mNextAppTransitionPackage=");
8725 pw.print(mNextAppTransitionPackage);
8726 pw.print(", mNextAppTransitionEnter=0x");
8727 pw.print(Integer.toHexString(mNextAppTransitionEnter));
8728 pw.print(", mNextAppTransitionExit=0x");
8729 pw.print(Integer.toHexString(mNextAppTransitionExit));
8730 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008731 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
8732 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
8733 if (mOpeningApps.size() > 0) {
8734 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
8735 }
8736 if (mClosingApps.size() > 0) {
8737 pw.print(" mClosingApps="); pw.println(mClosingApps);
8738 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008739 if (mToTopApps.size() > 0) {
8740 pw.print(" mToTopApps="); pw.println(mToTopApps);
8741 }
8742 if (mToBottomApps.size() > 0) {
8743 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
8744 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -08008745 if (mDisplay != null) {
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07008746 pw.print(" Display: init="); pw.print(mInitialDisplayWidth); pw.print("x");
8747 pw.print(mInitialDisplayHeight); pw.print(" cur=");
8748 pw.print(mCurDisplayWidth); pw.print("x"); pw.print(mCurDisplayHeight);
8749 pw.print(" real="); pw.print(mDisplay.getRealWidth());
8750 pw.print("x"); pw.print(mDisplay.getRealHeight());
8751 pw.print(" raw="); pw.print(mDisplay.getRawWidth());
8752 pw.print("x"); pw.println(mDisplay.getRawHeight());
Dianne Hackborn87fc3082010-12-03 13:09:12 -08008753 } else {
8754 pw.println(" NO DISPLAY");
8755 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008756 pw.println(" Policy:");
8757 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008758 }
8759 }
8760
Jeff Brown349703e2010-06-22 01:27:15 -07008761 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008762 public void monitor() {
8763 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -05008764 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07008765 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008766
Jeff Brown2992ea72011-01-28 22:04:14 -08008767 public interface OnHardKeyboardStatusChangeListener {
8768 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
8769 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008770}