blob: e2874f816dc888347a3c180e3cea1ba1f986722e [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;
67import android.graphics.Rect;
68import android.graphics.Region;
69import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
75import android.os.LocalPowerManager;
76import android.os.Looper;
77import android.os.Message;
78import android.os.Parcel;
79import android.os.ParcelFileDescriptor;
80import android.os.Power;
81import android.os.PowerManager;
82import android.os.Process;
83import android.os.RemoteException;
84import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070085import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086import android.os.SystemClock;
87import android.os.SystemProperties;
88import android.os.TokenWatcher;
89import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070090import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070092import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080093import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070095import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.view.Display;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.view.IApplicationToken;
98import android.view.IOnKeyguardExitResult;
99import android.view.IRotationWatcher;
100import android.view.IWindow;
101import android.view.IWindowManager;
102import android.view.IWindowSession;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700103import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700104import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700105import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700106import android.view.InputHandler;
107import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.KeyEvent;
109import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110import android.view.Surface;
111import android.view.SurfaceSession;
112import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.WindowManager;
114import android.view.WindowManagerImpl;
115import android.view.WindowManagerPolicy;
116import android.view.WindowManager.LayoutParams;
117import android.view.animation.Animation;
118import android.view.animation.AnimationUtils;
119import android.view.animation.Transformation;
120
121import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700122import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import java.io.File;
124import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700125import java.io.FileInputStream;
126import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127import java.io.IOException;
128import java.io.OutputStream;
129import java.io.OutputStreamWriter;
130import java.io.PrintWriter;
131import java.io.StringWriter;
132import java.net.Socket;
133import java.util.ArrayList;
134import java.util.HashMap;
135import java.util.HashSet;
136import java.util.Iterator;
137import java.util.List;
138
139/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700140public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700141 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 static final String TAG = "WindowManager";
143 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800144 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 static final boolean DEBUG_FOCUS = false;
146 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800147 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800148 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 static final boolean DEBUG_LAYERS = false;
150 static final boolean DEBUG_INPUT = false;
151 static final boolean DEBUG_INPUT_METHOD = false;
152 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700153 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800154 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700156 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_APP_TRANSITIONS = false;
158 static final boolean DEBUG_STARTING_WINDOW = false;
159 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700160 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800161 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700163 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean PROFILE_ORIENTATION = false;
166 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700167 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** How much to multiply the policy's type layer, to reserve room
170 * for multiple windows of the same type and Z-ordering adjustment
171 * with TYPE_LAYER_OFFSET. */
172 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
175 * or below others in the same layer. */
176 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to increment the layer for each window, to reserve room
179 * for effect surfaces between them.
180 */
181 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700182
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800183 /**
184 * Dim surface layer is immediately below target window.
185 */
186 static final int LAYER_OFFSET_DIM = 1;
187
188 /**
189 * Blur surface layer is immediately below dim layer.
190 */
191 static final int LAYER_OFFSET_BLUR = 2;
192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 /** The maximum length we will accept for a loaded animation duration:
194 * this is 10 seconds.
195 */
196 static final int MAX_ANIMATION_DURATION = 10*1000;
197
198 /** Amount of time (in milliseconds) to animate the dim surface from one
199 * value to another, when no window animation is driving it.
200 */
201 static final int DEFAULT_DIM_DURATION = 200;
202
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700203 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
204 * compatible windows.
205 */
206 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
207
Dianne Hackborna1111872010-11-23 20:55:11 -0800208 /**
209 * If true, the window manager will do its own custom freezing and general
210 * management of the screen during rotation.
211 */
212 static final boolean CUSTOM_SCREEN_ROTATION = true;
213
Jeff Brown7fbdc842010-06-17 20:52:56 -0700214 // Maximum number of milliseconds to wait for input event injection.
215 // FIXME is this value reasonable?
216 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800217
218 // Maximum number of milliseconds to wait for input devices to be enumerated before
219 // proceding with safe mode detection.
220 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700221
222 // Default input dispatching timeout in nanoseconds.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 static final int UPDATE_FOCUS_NORMAL = 0;
226 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
227 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
228 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700231 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232
233 /**
234 * Condition waited on by {@link #reenableKeyguard} to know the call to
235 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500236 * This is set to true only if mKeyguardTokenWatcher.acquired() has
237 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500239 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240
Jim Miller284b62e2010-06-08 14:27:42 -0700241 private static final int ALLOW_DISABLE_YES = 1;
242 private static final int ALLOW_DISABLE_NO = 0;
243 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
244 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
245
Mike Lockwood983ee092009-11-22 01:42:24 -0500246 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
247 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700249 if (shouldAllowDisableKeyguard()) {
250 mPolicy.enableKeyguard(false);
251 mKeyguardDisabled = true;
252 } else {
253 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 }
256 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700257 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500258 synchronized (mKeyguardTokenWatcher) {
259 mKeyguardDisabled = false;
260 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 }
262 }
263 };
264
Jim Miller284b62e2010-06-08 14:27:42 -0700265 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
266 @Override
267 public void onReceive(Context context, Intent intent) {
268 mPolicy.enableKeyguard(true);
269 synchronized(mKeyguardTokenWatcher) {
270 // lazily evaluate this next time we're asked to disable keyguard
271 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
272 mKeyguardDisabled = false;
273 }
274 }
275 };
276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 final Context mContext;
278
279 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
284
285 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 /**
290 * All currently active sessions with clients.
291 */
292 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 /**
295 * Mapping from an IWindow IBinder to the server's Window object.
296 * This is also used as the lock for all of our state.
297 */
298 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
299
300 /**
301 * Mapping from a token IBinder to a WindowToken object.
302 */
303 final HashMap<IBinder, WindowToken> mTokenMap =
304 new HashMap<IBinder, WindowToken>();
305
306 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 * Window tokens that are in the process of exiting, but still
308 * on screen for animations.
309 */
310 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
311
312 /**
313 * Z-ordered (bottom-most first) list of all application tokens, for
314 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800315 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 */
317 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
318
319 /**
320 * Application tokens that are in the process of exiting, but still
321 * on screen for animations.
322 */
323 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
324
325 /**
326 * List of window tokens that have finished starting their application,
327 * and now need to have the policy remove their windows.
328 */
329 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
330
331 /**
332 * Z-ordered (bottom-most first) list of all Window objects.
333 */
Jeff Browne33348b2010-07-15 23:54:05 -0700334 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335
336 /**
337 * Windows that are being resized. Used so we can tell the client about
338 * the resize after closing the transaction in which we resized the
339 * underlying surface.
340 */
341 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
342
343 /**
344 * Windows whose animations have ended and now must be removed.
345 */
346 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
347
348 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800349 * Used when processing mPendingRemove to avoid working on the original array.
350 */
351 WindowState[] mPendingRemoveTmp = new WindowState[20];
352
353 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 * Windows whose surface should be destroyed.
355 */
356 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
357
358 /**
359 * Windows that have lost input focus and are waiting for the new
360 * focus window to be displayed before they are told about this.
361 */
362 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
363
364 /**
365 * This is set when we have run out of memory, and will either be an empty
366 * list or contain windows that need to be force removed.
367 */
368 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700369
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800370 /**
371 * Used when rebuilding window list to keep track of windows that have
372 * been removed.
373 */
374 WindowState[] mRebuildTmp = new WindowState[20];
375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700379 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 Surface mBlurSurface;
381 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700382 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800383 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800384 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 final float[] mTmpFloats = new float[9];
389
390 boolean mSafeMode;
391 boolean mDisplayEnabled = false;
392 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700393 int mInitialDisplayWidth = 0;
394 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 int mRotation = 0;
396 int mRequestedRotation = 0;
397 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700398 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 ArrayList<IRotationWatcher> mRotationWatchers
400 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800401 int mDeferredRotation;
402 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 boolean mLayoutNeeded = true;
405 boolean mAnimationPending = false;
406 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800407 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 boolean mWindowsFreezingScreen = false;
409 long mFreezeGcPending = 0;
410 int mAppsFreezingScreen = 0;
411
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800412 int mLayoutSeq = 0;
413
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800414 // State while inside of layoutAndPlaceSurfacesLocked().
415 boolean mFocusMayChange;
416
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800417 Configuration mCurConfiguration = new Configuration();
418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 // This is held as long as we have the screen frozen, to give us time to
420 // perform a rotation animation when turning off shows the lock screen which
421 // changes the orientation.
422 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 // State management of app transitions. When we are preparing for a
425 // transition, mNextAppTransition will be the kind of transition to
426 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
427 // mOpeningApps and mClosingApps are the lists of tokens that will be
428 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700429 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700430 String mNextAppTransitionPackage;
431 int mNextAppTransitionEnter;
432 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700434 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 boolean mAppTransitionTimeout = false;
436 boolean mStartingIconInTransition = false;
437 boolean mSkipAppTransitionAnimation = false;
438 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
439 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700440 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
441 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 H mH = new H();
446
447 WindowState mCurrentFocus = null;
448 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 // This just indicates the window the input method is on top of, not
451 // necessarily the window its input is going to.
452 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 boolean mInputMethodTargetWaitingAnim;
454 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 WindowState mInputMethodWindow = null;
457 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
458
Jeff Brown2992ea72011-01-28 22:04:14 -0800459 boolean mHardKeyboardAvailable;
460 boolean mHardKeyboardEnabled;
461 OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
462
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700463 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800464
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700465 // If non-null, this is the currently visible window that is associated
466 // with the wallpaper.
467 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700468 // If non-null, we are in the middle of animating from one wallpaper target
469 // to another, and this is the lower one in Z-order.
470 WindowState mLowerWallpaperTarget = null;
471 // If non-null, we are in the middle of animating from one wallpaper target
472 // to another, and this is the higher one in Z-order.
473 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800474 // Window currently running an animation that has requested it be detached
475 // from the wallpaper. This means we need to ensure the wallpaper is
476 // visible behind it in case it animates in a way that would allow it to be
477 // seen.
478 WindowState mWindowDetachedWallpaper = null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800479 DimSurface mWindowAnimationBackgroundSurface = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700480 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700481 float mLastWallpaperX = -1;
482 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800483 float mLastWallpaperXStep = -1;
484 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700485 // This is set when we are waiting for a wallpaper to tell us it is done
486 // changing its scroll position.
487 WindowState mWaitingOnWallpaper;
488 // The last time we had a timeout when waiting for a wallpaper.
489 long mLastWallpaperTimeoutTime;
490 // We give a wallpaper up to 150ms to finish scrolling.
491 static final long WALLPAPER_TIMEOUT = 150;
492 // Time we wait after a timeout before trying to wait again.
493 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 AppWindowToken mFocusedApp = null;
496
497 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 float mWindowAnimationScale = 1.0f;
500 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700501
Jeff Brown46b9ac02010-04-22 18:58:52 -0700502 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503
504 // Who is holding the screen on.
505 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700506 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700507
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700508 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800509
Christopher Tatea53146c2010-09-07 11:57:52 -0700510 DragState mDragState = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800511 final InputHandler mDragInputHandler = new BaseInputHandler() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700512 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700513 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
514 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700516 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
517 && mDragState != null) {
518 boolean endDrag = false;
519 final float newX = event.getRawX();
520 final float newY = event.getRawY();
521
Christopher Tatea53146c2010-09-07 11:57:52 -0700522 switch (event.getAction()) {
523 case MotionEvent.ACTION_DOWN: {
524 if (DEBUG_DRAG) {
525 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
526 }
527 } break;
528
529 case MotionEvent.ACTION_MOVE: {
530 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700531 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700532 mDragState.notifyMoveLw(newX, newY);
533 }
534 } break;
535
536 case MotionEvent.ACTION_UP: {
537 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
538 + newX + "," + newY);
539 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700540 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700541 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700542 } break;
543
544 case MotionEvent.ACTION_CANCEL: {
545 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
546 endDrag = true;
547 } break;
548 }
549
550 if (endDrag) {
551 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
552 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700553 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700554 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700555 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700556 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700557
558 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700559 }
560 } catch (Exception e) {
561 Slog.e(TAG, "Exception caught by drag handleMotion", e);
562 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700563 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700564 }
565 }
566 };
567
568 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 * Whether the UI is currently running in touch mode (not showing
570 * navigational focus because the user is directly pressing the screen).
571 */
572 boolean mInTouchMode = false;
573
574 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700575 private ArrayList<WindowChangeListener> mWindowChangeListeners =
576 new ArrayList<WindowChangeListener>();
577 private boolean mWindowsChanged = false;
578
579 public interface WindowChangeListener {
580 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700581 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700582 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583
Dianne Hackbornc485a602009-03-24 22:39:49 -0700584 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700585 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700586
587 // The frame use to limit the size of the app running in compatibility mode.
588 Rect mCompatibleScreenFrame = new Rect();
589 // The surface used to fill the outer rim of the app running in compatibility mode.
590 Surface mBackgroundFillerSurface = null;
Dianne Hackbornac1471a2011-02-03 13:46:06 -0800591 WindowState mBackgroundFillerTarget = null;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 public static WindowManagerService main(Context context,
594 PowerManagerService pm, boolean haveInputMethods) {
595 WMThread thr = new WMThread(context, pm, haveInputMethods);
596 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 synchronized (thr) {
599 while (thr.mService == null) {
600 try {
601 thr.wait();
602 } catch (InterruptedException e) {
603 }
604 }
Jozef BABJAK06e57b52011-01-20 08:09:25 +0100605 return thr.mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 }
Romain Guy06882f82009-06-10 13:36:04 -0700608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 static class WMThread extends Thread {
610 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 private final Context mContext;
613 private final PowerManagerService mPM;
614 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 public WMThread(Context context, PowerManagerService pm,
617 boolean haveInputMethods) {
618 super("WindowManager");
619 mContext = context;
620 mPM = pm;
621 mHaveInputMethods = haveInputMethods;
622 }
Romain Guy06882f82009-06-10 13:36:04 -0700623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 public void run() {
625 Looper.prepare();
626 WindowManagerService s = new WindowManagerService(mContext, mPM,
627 mHaveInputMethods);
628 android.os.Process.setThreadPriority(
629 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700630 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 synchronized (this) {
633 mService = s;
634 notifyAll();
635 }
Romain Guy06882f82009-06-10 13:36:04 -0700636
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700637 // For debug builds, log event loop stalls to dropbox for analysis.
638 if (StrictMode.conditionallyEnableDebugLogging()) {
639 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
640 }
641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 Looper.loop();
643 }
644 }
645
646 static class PolicyThread extends Thread {
647 private final WindowManagerPolicy mPolicy;
648 private final WindowManagerService mService;
649 private final Context mContext;
650 private final PowerManagerService mPM;
651 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 public PolicyThread(WindowManagerPolicy policy,
654 WindowManagerService service, Context context,
655 PowerManagerService pm) {
656 super("WindowManagerPolicy");
657 mPolicy = policy;
658 mService = service;
659 mContext = context;
660 mPM = pm;
661 }
Romain Guy06882f82009-06-10 13:36:04 -0700662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 public void run() {
664 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800665 WindowManagerPolicyThread.set(this, Looper.myLooper());
666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800668 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 android.os.Process.setThreadPriority(
670 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700671 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 synchronized (this) {
675 mRunning = true;
676 notifyAll();
677 }
Romain Guy06882f82009-06-10 13:36:04 -0700678
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700679 // For debug builds, log event loop stalls to dropbox for analysis.
680 if (StrictMode.conditionallyEnableDebugLogging()) {
681 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
682 }
683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 Looper.loop();
685 }
686 }
687
688 private WindowManagerService(Context context, PowerManagerService pm,
689 boolean haveInputMethods) {
690 mContext = context;
691 mHaveInputMethods = haveInputMethods;
692 mLimitedAlphaCompositing = context.getResources().getBoolean(
693 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 mPowerManager = pm;
696 mPowerManager.setPolicy(mPolicy);
697 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
698 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
699 "SCREEN_FROZEN");
700 mScreenFrozenLock.setReferenceCounted(false);
701
702 mActivityManager = ActivityManagerNative.getDefault();
703 mBatteryStats = BatteryStatsService.getService();
704
705 // Get persisted window scale setting
706 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
707 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
708 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
709 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700710
Jim Miller284b62e2010-06-08 14:27:42 -0700711 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
712 IntentFilter filter = new IntentFilter();
713 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
714 mContext.registerReceiver(mBroadcastReceiver, filter);
715
Jeff Brown46b9ac02010-04-22 18:58:52 -0700716 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
717 "KEEP_SCREEN_ON_FLAG");
718 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719
Jeff Browne33348b2010-07-15 23:54:05 -0700720 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
723 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 synchronized (thr) {
726 while (!thr.mRunning) {
727 try {
728 thr.wait();
729 } catch (InterruptedException e) {
730 }
731 }
732 }
Romain Guy06882f82009-06-10 13:36:04 -0700733
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700734 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 // Add ourself to the Watchdog monitors.
737 Watchdog.getInstance().addMonitor(this);
738 }
739
740 @Override
741 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
742 throws RemoteException {
743 try {
744 return super.onTransact(code, data, reply, flags);
745 } catch (RuntimeException e) {
746 // The window manager only throws security exceptions, so let's
747 // log all others.
748 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800749 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 }
751 throw e;
752 }
753 }
754
Jeff Browne33348b2010-07-15 23:54:05 -0700755 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800757 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 TAG, "Adding window " + window + " at "
759 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
760 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700761 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 }
763
Jeff Browne33348b2010-07-15 23:54:05 -0700764 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800766 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 TAG, "Adding window " + window + " at "
768 + i + " of " + mWindows.size() + " (before " + pos + ")");
769 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700770 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 }
772
773 //This method finds out the index of a window that has the same app token as
774 //win. used for z ordering the windows in mWindows
775 private int findIdxBasedOnAppTokens(WindowState win) {
776 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700777 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 int jmax = localmWindows.size();
779 if(jmax == 0) {
780 return -1;
781 }
782 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700783 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 if(wentry.mAppToken == win.mAppToken) {
785 return j;
786 }
787 }
788 return -1;
789 }
Romain Guy06882f82009-06-10 13:36:04 -0700790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
792 final IWindow client = win.mClient;
793 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700794 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 final int N = localmWindows.size();
797 final WindowState attached = win.mAttachedWindow;
798 int i;
799 if (attached == null) {
800 int tokenWindowsPos = token.windows.size();
801 if (token.appWindowToken != null) {
802 int index = tokenWindowsPos-1;
803 if (index >= 0) {
804 // If this application has existing windows, we
805 // simply place the new window on top of them... but
806 // keep the starting window on top.
807 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
808 // Base windows go behind everything else.
809 placeWindowBefore(token.windows.get(0), win);
810 tokenWindowsPos = 0;
811 } else {
812 AppWindowToken atoken = win.mAppToken;
813 if (atoken != null &&
814 token.windows.get(index) == atoken.startingWindow) {
815 placeWindowBefore(token.windows.get(index), win);
816 tokenWindowsPos--;
817 } else {
818 int newIdx = findIdxBasedOnAppTokens(win);
819 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700820 //there is a window above this one associated with the same
821 //apptoken note that the window could be a floating window
822 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800824 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
825 Slog.v(TAG, "Adding window " + win + " at "
826 + (newIdx+1) + " of " + N);
827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700829 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 }
832 }
833 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800834 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 TAG, "Figuring out where to add app window "
836 + client.asBinder() + " (token=" + token + ")");
837 // Figure out where the window should go, based on the
838 // order of applications.
839 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700840 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 for (i=NA-1; i>=0; i--) {
842 AppWindowToken t = mAppTokens.get(i);
843 if (t == token) {
844 i--;
845 break;
846 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800847
Dianne Hackborna8f60182009-09-01 19:01:50 -0700848 // We haven't reached the token yet; if this token
849 // is not going to the bottom and has windows, we can
850 // use it as an anchor for when we do reach the token.
851 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 pos = t.windows.get(0);
853 }
854 }
855 // We now know the index into the apps. If we found
856 // an app window above, that gives us the position; else
857 // we need to look some more.
858 if (pos != null) {
859 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700860 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 if (atoken != null) {
862 final int NC = atoken.windows.size();
863 if (NC > 0) {
864 WindowState bottom = atoken.windows.get(0);
865 if (bottom.mSubLayer < 0) {
866 pos = bottom;
867 }
868 }
869 }
870 placeWindowBefore(pos, win);
871 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700872 // Continue looking down until we find the first
873 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 while (i >= 0) {
875 AppWindowToken t = mAppTokens.get(i);
876 final int NW = t.windows.size();
877 if (NW > 0) {
878 pos = t.windows.get(NW-1);
879 break;
880 }
881 i--;
882 }
883 if (pos != null) {
884 // Move in front of any windows attached to this
885 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700886 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 if (atoken != null) {
888 final int NC = atoken.windows.size();
889 if (NC > 0) {
890 WindowState top = atoken.windows.get(NC-1);
891 if (top.mSubLayer >= 0) {
892 pos = top;
893 }
894 }
895 }
896 placeWindowAfter(pos, win);
897 } else {
898 // Just search for the start of this layer.
899 final int myLayer = win.mBaseLayer;
900 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700901 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 if (w.mBaseLayer > myLayer) {
903 break;
904 }
905 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800906 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
907 Slog.v(TAG, "Adding window " + win + " at "
908 + i + " of " + N);
909 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700911 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 }
913 }
914 }
915 } else {
916 // Figure out where window should go, based on layer.
917 final int myLayer = win.mBaseLayer;
918 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700919 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 i++;
921 break;
922 }
923 }
924 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800925 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700926 TAG, "Adding window " + win + " at "
927 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700929 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 }
931 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800932 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 token.windows.add(tokenWindowsPos, win);
934 }
935
936 } else {
937 // Figure out this window's ordering relative to the window
938 // it is attached to.
939 final int NA = token.windows.size();
940 final int sublayer = win.mSubLayer;
941 int largestSublayer = Integer.MIN_VALUE;
942 WindowState windowWithLargestSublayer = null;
943 for (i=0; i<NA; i++) {
944 WindowState w = token.windows.get(i);
945 final int wSublayer = w.mSubLayer;
946 if (wSublayer >= largestSublayer) {
947 largestSublayer = wSublayer;
948 windowWithLargestSublayer = w;
949 }
950 if (sublayer < 0) {
951 // For negative sublayers, we go below all windows
952 // in the same sublayer.
953 if (wSublayer >= sublayer) {
954 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800955 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 token.windows.add(i, win);
957 }
958 placeWindowBefore(
959 wSublayer >= 0 ? attached : w, win);
960 break;
961 }
962 } else {
963 // For positive sublayers, we go above all windows
964 // in the same sublayer.
965 if (wSublayer > sublayer) {
966 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800967 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 token.windows.add(i, win);
969 }
970 placeWindowBefore(w, win);
971 break;
972 }
973 }
974 }
975 if (i >= NA) {
976 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800977 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 token.windows.add(win);
979 }
980 if (sublayer < 0) {
981 placeWindowBefore(attached, win);
982 } else {
983 placeWindowAfter(largestSublayer >= 0
984 ? windowWithLargestSublayer
985 : attached,
986 win);
987 }
988 }
989 }
Romain Guy06882f82009-06-10 13:36:04 -0700990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 if (win.mAppToken != null && addToToken) {
992 win.mAppToken.allAppWindows.add(win);
993 }
994 }
Romain Guy06882f82009-06-10 13:36:04 -0700995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 static boolean canBeImeTarget(WindowState w) {
997 final int fl = w.mAttrs.flags
998 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborne75d8722011-01-27 19:37:40 -0800999 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
1000 || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
1001 if (DEBUG_INPUT_METHOD) {
1002 Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1003 if (!w.isVisibleOrAdding()) {
1004 Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface
1005 + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
1006 + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
1007 + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
1008 if (w.mAppToken != null) {
1009 Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1010 }
1011 }
1012 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 return w.isVisibleOrAdding();
1014 }
1015 return false;
1016 }
Romain Guy06882f82009-06-10 13:36:04 -07001017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001019 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 final int N = localmWindows.size();
1021 WindowState w = null;
1022 int i = N;
1023 while (i > 0) {
1024 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001025 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001026
Dianne Hackborne75d8722011-01-27 19:37:40 -08001027 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
1028 + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001030 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 // Yet more tricksyness! If this window is a "starting"
1033 // window, we do actually want to be on top of it, but
1034 // it is not -really- where input will go. So if the caller
1035 // is not actually looking to move the IME, look down below
1036 // for a real window to target...
1037 if (!willMove
1038 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1039 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001040 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1042 i--;
1043 w = wb;
1044 }
1045 }
1046 break;
1047 }
1048 }
Romain Guy06882f82009-06-10 13:36:04 -07001049
Dianne Hackborne75d8722011-01-27 19:37:40 -08001050 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
1051
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001052 // Now, a special case -- if the last target's window is in the
1053 // process of exiting, and is above the new target, keep on the
1054 // last target to avoid flicker. Consider for example a Dialog with
1055 // the IME shown: when the Dialog is dismissed, we want to keep
1056 // the IME above it until it is completely gone so it doesn't drop
1057 // behind the dialog or its full-screen scrim.
1058 if (mInputMethodTarget != null && w != null
1059 && mInputMethodTarget.isDisplayedLw()
1060 && mInputMethodTarget.mExiting) {
1061 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1062 w = mInputMethodTarget;
1063 i = localmWindows.indexOf(w);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001064 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w);
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001065 }
1066 }
Romain Guy06882f82009-06-10 13:36:04 -07001067
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 if (willMove && w != null) {
1072 final WindowState curTarget = mInputMethodTarget;
1073 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 // Now some fun for dealing with window animations that
1076 // modify the Z order. We need to look at all windows below
1077 // the current target that are in this app, finding the highest
1078 // visible one in layering.
1079 AppWindowToken token = curTarget.mAppToken;
1080 WindowState highestTarget = null;
1081 int highestPos = 0;
1082 if (token.animating || token.animation != null) {
1083 int pos = 0;
1084 pos = localmWindows.indexOf(curTarget);
1085 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001086 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 if (win.mAppToken != token) {
1088 break;
1089 }
1090 if (!win.mRemoved) {
1091 if (highestTarget == null || win.mAnimLayer >
1092 highestTarget.mAnimLayer) {
1093 highestTarget = win;
1094 highestPos = pos;
1095 }
1096 }
1097 pos--;
1098 }
1099 }
Romain Guy06882f82009-06-10 13:36:04 -07001100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001102 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 + mNextAppTransition + " " + highestTarget
1104 + " animating=" + highestTarget.isAnimating()
1105 + " layer=" + highestTarget.mAnimLayer
1106 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001107
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001108 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 // If we are currently setting up for an animation,
1110 // hold everything until we can find out what will happen.
1111 mInputMethodTargetWaitingAnim = true;
1112 mInputMethodTarget = highestTarget;
1113 return highestPos + 1;
1114 } else if (highestTarget.isAnimating() &&
1115 highestTarget.mAnimLayer > w.mAnimLayer) {
1116 // If the window we are currently targeting is involved
1117 // with an animation, and it is on top of the next target
1118 // we will be over, then hold off on moving until
1119 // that is done.
Dianne Hackborne75d8722011-01-27 19:37:40 -08001120 mInputMethodTargetWaitingAnim = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 mInputMethodTarget = highestTarget;
1122 return highestPos + 1;
1123 }
1124 }
1125 }
1126 }
Romain Guy06882f82009-06-10 13:36:04 -07001127
Joe Onorato8a9b2202010-02-26 18:56:32 -08001128 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 if (w != null) {
1130 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001131 if (DEBUG_INPUT_METHOD) {
1132 RuntimeException e = null;
1133 if (!HIDE_STACK_CRAWLS) {
1134 e = new RuntimeException();
1135 e.fillInStackTrace();
1136 }
1137 Slog.w(TAG, "Moving IM target from "
1138 + mInputMethodTarget + " to " + w, e);
1139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 mInputMethodTarget = w;
Dianne Hackborne75d8722011-01-27 19:37:40 -08001141 mInputMethodTargetWaitingAnim = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 if (w.mAppToken != null) {
1143 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1144 } else {
1145 setInputMethodAnimLayerAdjustment(0);
1146 }
1147 }
1148 return i+1;
1149 }
1150 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001151 if (DEBUG_INPUT_METHOD) {
1152 RuntimeException e = null;
1153 if (!HIDE_STACK_CRAWLS) {
1154 e = new RuntimeException();
1155 e.fillInStackTrace();
1156 }
1157 Slog.w(TAG, "Moving IM target from "
1158 + mInputMethodTarget + " to null", e);
1159 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 mInputMethodTarget = null;
1161 setInputMethodAnimLayerAdjustment(0);
1162 }
1163 return -1;
1164 }
Romain Guy06882f82009-06-10 13:36:04 -07001165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 void addInputMethodWindowToListLocked(WindowState win) {
1167 int pos = findDesiredInputMethodWindowIndexLocked(true);
1168 if (pos >= 0) {
1169 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001170 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001171 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001173 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 moveInputMethodDialogsLocked(pos+1);
1175 return;
1176 }
1177 win.mTargetAppToken = null;
1178 addWindowToListInOrderLocked(win, true);
1179 moveInputMethodDialogsLocked(pos);
1180 }
Romain Guy06882f82009-06-10 13:36:04 -07001181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001183 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 mInputMethodAnimLayerAdjustment = adj;
1185 WindowState imw = mInputMethodWindow;
1186 if (imw != null) {
1187 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001188 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 + " anim layer: " + imw.mAnimLayer);
1190 int wi = imw.mChildWindows.size();
1191 while (wi > 0) {
1192 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001193 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001195 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 + " anim layer: " + cw.mAnimLayer);
1197 }
1198 }
1199 int di = mInputMethodDialogs.size();
1200 while (di > 0) {
1201 di --;
1202 imw = mInputMethodDialogs.get(di);
1203 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001204 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 + " anim layer: " + imw.mAnimLayer);
1206 }
1207 }
Romain Guy06882f82009-06-10 13:36:04 -07001208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1210 int wpos = mWindows.indexOf(win);
1211 if (wpos >= 0) {
1212 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001213 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001215 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 int NC = win.mChildWindows.size();
1217 while (NC > 0) {
1218 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001219 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 int cpos = mWindows.indexOf(cw);
1221 if (cpos >= 0) {
1222 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001223 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001224 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 mWindows.remove(cpos);
1226 }
1227 }
1228 }
1229 return interestingPos;
1230 }
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 private void reAddWindowToListInOrderLocked(WindowState win) {
1233 addWindowToListInOrderLocked(win, false);
1234 // This is a hack to get all of the child windows added as well
1235 // at the right position. Child windows should be rare and
1236 // this case should be rare, so it shouldn't be that big a deal.
1237 int wpos = mWindows.indexOf(win);
1238 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001239 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001240 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001242 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 reAddWindowLocked(wpos, win);
1244 }
1245 }
Romain Guy06882f82009-06-10 13:36:04 -07001246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 void logWindowList(String prefix) {
1248 int N = mWindows.size();
1249 while (N > 0) {
1250 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001251 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 }
1253 }
Romain Guy06882f82009-06-10 13:36:04 -07001254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 void moveInputMethodDialogsLocked(int pos) {
1256 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001259 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 for (int i=0; i<N; i++) {
1261 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1262 }
1263 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001264 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 logWindowList(" ");
1266 }
Romain Guy06882f82009-06-10 13:36:04 -07001267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 if (pos >= 0) {
1269 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1270 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001271 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 if (wp == mInputMethodWindow) {
1273 pos++;
1274 }
1275 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001276 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 for (int i=0; i<N; i++) {
1278 WindowState win = dialogs.get(i);
1279 win.mTargetAppToken = targetAppToken;
1280 pos = reAddWindowLocked(pos, win);
1281 }
1282 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001283 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 logWindowList(" ");
1285 }
1286 return;
1287 }
1288 for (int i=0; i<N; i++) {
1289 WindowState win = dialogs.get(i);
1290 win.mTargetAppToken = null;
1291 reAddWindowToListInOrderLocked(win);
1292 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001293 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 logWindowList(" ");
1295 }
1296 }
1297 }
Romain Guy06882f82009-06-10 13:36:04 -07001298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1300 final WindowState imWin = mInputMethodWindow;
1301 final int DN = mInputMethodDialogs.size();
1302 if (imWin == null && DN == 0) {
1303 return false;
1304 }
Romain Guy06882f82009-06-10 13:36:04 -07001305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1307 if (imPos >= 0) {
1308 // In this case, the input method windows are to be placed
1309 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 // First check to see if the input method windows are already
1312 // located here, and contiguous.
1313 final int N = mWindows.size();
1314 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001315 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 // Figure out the actual input method window that should be
1318 // at the bottom of their stack.
1319 WindowState baseImWin = imWin != null
1320 ? imWin : mInputMethodDialogs.get(0);
1321 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001322 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 if (cw.mSubLayer < 0) baseImWin = cw;
1324 }
Romain Guy06882f82009-06-10 13:36:04 -07001325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 if (firstImWin == baseImWin) {
1327 // The windows haven't moved... but are they still contiguous?
1328 // First find the top IM window.
1329 int pos = imPos+1;
1330 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001331 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 break;
1333 }
1334 pos++;
1335 }
1336 pos++;
1337 // Now there should be no more input method windows above.
1338 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001339 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 break;
1341 }
1342 pos++;
1343 }
1344 if (pos >= N) {
1345 // All is good!
1346 return false;
1347 }
1348 }
Romain Guy06882f82009-06-10 13:36:04 -07001349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 if (imWin != null) {
1351 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001352 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 logWindowList(" ");
1354 }
1355 imPos = tmpRemoveWindowLocked(imPos, imWin);
1356 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001357 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 logWindowList(" ");
1359 }
1360 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1361 reAddWindowLocked(imPos, imWin);
1362 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001363 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 logWindowList(" ");
1365 }
1366 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1367 } else {
1368 moveInputMethodDialogsLocked(imPos);
1369 }
Romain Guy06882f82009-06-10 13:36:04 -07001370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 } else {
1372 // In this case, the input method windows go in a fixed layer,
1373 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001376 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 tmpRemoveWindowLocked(0, imWin);
1378 imWin.mTargetAppToken = null;
1379 reAddWindowToListInOrderLocked(imWin);
1380 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001381 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 logWindowList(" ");
1383 }
1384 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1385 } else {
1386 moveInputMethodDialogsLocked(-1);;
1387 }
Romain Guy06882f82009-06-10 13:36:04 -07001388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 }
Romain Guy06882f82009-06-10 13:36:04 -07001390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 if (needAssignLayers) {
1392 assignLayersLocked();
1393 }
Romain Guy06882f82009-06-10 13:36:04 -07001394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 return true;
1396 }
Romain Guy06882f82009-06-10 13:36:04 -07001397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 void adjustInputMethodDialogsLocked() {
1399 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1400 }
Romain Guy06882f82009-06-10 13:36:04 -07001401
Dianne Hackborn25994b42009-09-04 14:21:19 -07001402 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001403 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001404 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1405 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1406 ? wallpaperTarget.mAppToken.animation : null)
1407 + " upper=" + mUpperWallpaperTarget
1408 + " lower=" + mLowerWallpaperTarget);
1409 return (wallpaperTarget != null
1410 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1411 && wallpaperTarget.mAppToken.animation != null)))
1412 || mUpperWallpaperTarget != null
1413 || mLowerWallpaperTarget != null;
1414 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001415
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001416 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1417 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001418
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001419 int adjustWallpaperWindowsLocked() {
1420 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001421
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001422 final int dw = mDisplay.getWidth();
1423 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001424
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001425 // First find top-most window that has asked to be on top of the
1426 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001427 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001428 int N = localmWindows.size();
1429 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001430 WindowState foundW = null;
1431 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001432 WindowState topCurW = null;
1433 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001434 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001435 int i = N;
1436 while (i > 0) {
1437 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001438 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001439 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1440 if (topCurW == null) {
1441 topCurW = w;
1442 topCurI = i;
1443 }
1444 continue;
1445 }
1446 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001447 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001448 // If this window's app token is hidden and not animating,
1449 // it is of no interest to us.
1450 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001452 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001453 continue;
1454 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001455 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001456 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001457 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1458 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001459 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001460 && (mWallpaperTarget == w
1461 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001463 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001464 foundW = w;
1465 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001466 if (w == mWallpaperTarget && ((w.mAppToken != null
1467 && w.mAppToken.animation != null)
1468 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001469 // The current wallpaper target is animating, so we'll
1470 // look behind it for another possible target and figure
1471 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001472 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001473 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001474 continue;
1475 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001476 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001477 } else if (w == mWindowDetachedWallpaper) {
1478 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001479 }
1480 }
1481
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001482 if (foundW == null && windowDetachedI >= 0) {
1483 if (DEBUG_WALLPAPER) Slog.v(TAG,
1484 "Found animating detached wallpaper activity: #" + i + "=" + w);
1485 foundW = w;
1486 foundI = windowDetachedI;
1487 }
1488
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001489 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001490 // If we are currently waiting for an app transition, and either
1491 // the current target or the next target are involved with it,
1492 // then hold off on doing anything with the wallpaper.
1493 // Note that we are checking here for just whether the target
1494 // is part of an app token... which is potentially overly aggressive
1495 // (the app token may not be involved in the transition), but good
1496 // enough (we'll just wait until whatever transition is pending
1497 // executes).
1498 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001499 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001500 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001501 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001502 }
1503 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001504 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001505 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001506 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001507 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001509
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001510 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001511 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001512 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001513 + " oldTarget: " + mWallpaperTarget);
1514 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001515
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001516 mLowerWallpaperTarget = null;
1517 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001518
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001519 WindowState oldW = mWallpaperTarget;
1520 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001521
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001522 // Now what is happening... if the current and new targets are
1523 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001524 if (foundW != null && oldW != null) {
1525 boolean oldAnim = oldW.mAnimation != null
1526 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1527 boolean foundAnim = foundW.mAnimation != null
1528 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001529 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001530 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001531 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001532 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001533 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001534 int oldI = localmWindows.indexOf(oldW);
1535 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001536 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001537 }
1538 if (oldI >= 0) {
1539 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001540 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001541 + "=" + oldW + "; new#" + foundI
1542 + "=" + foundW);
1543 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001544
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001545 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001546 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001547 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001548 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001549 }
1550 mWallpaperTarget = oldW;
1551 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001552
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001553 // Now set the upper and lower wallpaper targets
1554 // correctly, and make sure that we are positioning
1555 // the wallpaper below the lower.
1556 if (foundI > oldI) {
1557 // The new target is on top of the old one.
1558 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001559 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001560 }
1561 mUpperWallpaperTarget = foundW;
1562 mLowerWallpaperTarget = oldW;
1563 foundW = oldW;
1564 foundI = oldI;
1565 } else {
1566 // The new target is below the old one.
1567 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001568 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001569 }
1570 mUpperWallpaperTarget = oldW;
1571 mLowerWallpaperTarget = foundW;
1572 }
1573 }
1574 }
1575 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001576
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001577 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001578 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001579 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1580 || (mLowerWallpaperTarget.mAppToken != null
1581 && mLowerWallpaperTarget.mAppToken.animation != null);
1582 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1583 || (mUpperWallpaperTarget.mAppToken != null
1584 && mUpperWallpaperTarget.mAppToken.animation != null);
1585 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001586 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001587 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001588 }
1589 mLowerWallpaperTarget = null;
1590 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001591 }
1592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001593
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001594 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001595 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001596 // The window is visible to the compositor... but is it visible
1597 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001598 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001599 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001600
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001601 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001602 // its layer adjustment. Only do this if we are not transfering
1603 // between two wallpaper targets.
1604 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001605 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001606 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001607
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001608 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1609 * TYPE_LAYER_MULTIPLIER
1610 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001611
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001612 // Now w is the window we are supposed to be behind... but we
1613 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001614 // AND any starting window associated with it, AND below the
1615 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001616 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001617 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001618 if (wb.mBaseLayer < maxLayer &&
1619 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001620 (foundW.mAttachedWindow == null ||
1621 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001622 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001623 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001624 // This window is not related to the previous one in any
1625 // interesting way, so stop here.
1626 break;
1627 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001628 foundW = wb;
1629 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001630 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001631 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001632 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001633 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001634
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001635 if (foundW == null && topCurW != null) {
1636 // There is no wallpaper target, so it goes at the bottom.
1637 // We will assume it is the same place as last time, if known.
1638 foundW = topCurW;
1639 foundI = topCurI+1;
1640 } else {
1641 // Okay i is the position immediately above the wallpaper. Look at
1642 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001643 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001644 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001645
Dianne Hackborn284ac932009-08-28 10:34:25 -07001646 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001647 if (mWallpaperTarget.mWallpaperX >= 0) {
1648 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001649 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 }
1651 if (mWallpaperTarget.mWallpaperY >= 0) {
1652 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001653 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001654 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001655 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001656
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001657 // Start stepping backwards from here, ensuring that our wallpaper windows
1658 // are correctly placed.
1659 int curTokenIndex = mWallpaperTokens.size();
1660 while (curTokenIndex > 0) {
1661 curTokenIndex--;
1662 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001663 if (token.hidden == visible) {
1664 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1665 token.hidden = !visible;
1666 // Need to do a layout to ensure the wallpaper now has the
1667 // correct size.
1668 mLayoutNeeded = true;
1669 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001670
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001671 int curWallpaperIndex = token.windows.size();
1672 while (curWallpaperIndex > 0) {
1673 curWallpaperIndex--;
1674 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001675
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001676 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001677 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001678 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001679
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001680 // First, make sure the client has the current visibility
1681 // state.
1682 if (wallpaper.mWallpaperVisible != visible) {
1683 wallpaper.mWallpaperVisible = visible;
1684 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001685 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001686 "Setting visibility of wallpaper " + wallpaper
1687 + ": " + visible);
1688 wallpaper.mClient.dispatchAppVisibility(visible);
1689 } catch (RemoteException e) {
1690 }
1691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001693 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001694 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001695 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001696
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001697 // First, if this window is at the current index, then all
1698 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001699 if (wallpaper == foundW) {
1700 foundI--;
1701 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001702 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001703 continue;
1704 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001706 // The window didn't match... the current wallpaper window,
1707 // wherever it is, is in the wrong place, so make sure it is
1708 // not in the list.
1709 int oldIndex = localmWindows.indexOf(wallpaper);
1710 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001711 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001712 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001713 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001714 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001715 if (oldIndex < foundI) {
1716 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001717 }
1718 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001719
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001720 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001721 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1722 Slog.v(TAG, "Moving wallpaper " + wallpaper
1723 + " from " + oldIndex + " to " + foundI);
1724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001725
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001726 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001727 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001728 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001729 }
1730 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001731
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001732 return changed;
1733 }
1734
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001735 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001736 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001737 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001738 mWallpaperAnimLayerAdjustment = adj;
1739 int curTokenIndex = mWallpaperTokens.size();
1740 while (curTokenIndex > 0) {
1741 curTokenIndex--;
1742 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1743 int curWallpaperIndex = token.windows.size();
1744 while (curWallpaperIndex > 0) {
1745 curWallpaperIndex--;
1746 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1747 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001748 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001749 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001750 }
1751 }
1752 }
1753
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001754 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1755 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001756 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001757 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001758 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001759 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001760 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1761 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1762 changed = wallpaperWin.mXOffset != offset;
1763 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001764 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001765 + wallpaperWin + " x: " + offset);
1766 wallpaperWin.mXOffset = offset;
1767 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001768 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001769 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001770 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001771 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001772 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001773
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001774 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001775 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001776 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1777 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1778 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001779 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001780 + wallpaperWin + " y: " + offset);
1781 changed = true;
1782 wallpaperWin.mYOffset = offset;
1783 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001784 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001785 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001786 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001787 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001788 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001789
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001790 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001791 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001792 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001793 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1794 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001795 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001796 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001797 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001798 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001799 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1800 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001801 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001802 if (mWaitingOnWallpaper != null) {
1803 long start = SystemClock.uptimeMillis();
1804 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1805 < start) {
1806 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001807 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001808 "Waiting for offset complete...");
1809 mWindowMap.wait(WALLPAPER_TIMEOUT);
1810 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001811 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001812 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001813 if ((start+WALLPAPER_TIMEOUT)
1814 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001816 + wallpaperWin);
1817 mLastWallpaperTimeoutTime = start;
1818 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001819 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001820 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001821 }
1822 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001823 } catch (RemoteException e) {
1824 }
1825 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001826
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001827 return changed;
1828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001829
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001830 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001831 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001832 if (mWaitingOnWallpaper != null &&
1833 mWaitingOnWallpaper.mClient.asBinder() == window) {
1834 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001835 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001836 }
1837 }
1838 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001839
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001840 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001841 final int dw = mDisplay.getWidth();
1842 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001843
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001844 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001845
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001846 WindowState target = mWallpaperTarget;
1847 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001848 if (target.mWallpaperX >= 0) {
1849 mLastWallpaperX = target.mWallpaperX;
1850 } else if (changingTarget.mWallpaperX >= 0) {
1851 mLastWallpaperX = changingTarget.mWallpaperX;
1852 }
1853 if (target.mWallpaperY >= 0) {
1854 mLastWallpaperY = target.mWallpaperY;
1855 } else if (changingTarget.mWallpaperY >= 0) {
1856 mLastWallpaperY = changingTarget.mWallpaperY;
1857 }
1858 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001859
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001860 int curTokenIndex = mWallpaperTokens.size();
1861 while (curTokenIndex > 0) {
1862 curTokenIndex--;
1863 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1864 int curWallpaperIndex = token.windows.size();
1865 while (curWallpaperIndex > 0) {
1866 curWallpaperIndex--;
1867 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1868 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1869 wallpaper.computeShownFrameLocked();
1870 changed = true;
1871 // We only want to be synchronous with one wallpaper.
1872 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001873 }
1874 }
1875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001876
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001877 return changed;
1878 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001879
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001880 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001881 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001882 final int dw = mDisplay.getWidth();
1883 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001884
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001885 int curTokenIndex = mWallpaperTokens.size();
1886 while (curTokenIndex > 0) {
1887 curTokenIndex--;
1888 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001889 if (token.hidden == visible) {
1890 token.hidden = !visible;
1891 // Need to do a layout to ensure the wallpaper now has the
1892 // correct size.
1893 mLayoutNeeded = true;
1894 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001895
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001896 int curWallpaperIndex = token.windows.size();
1897 while (curWallpaperIndex > 0) {
1898 curWallpaperIndex--;
1899 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1900 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001901 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001902 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001903
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001904 if (wallpaper.mWallpaperVisible != visible) {
1905 wallpaper.mWallpaperVisible = visible;
1906 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001907 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001908 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001909 + ": " + visible);
1910 wallpaper.mClient.dispatchAppVisibility(visible);
1911 } catch (RemoteException e) {
1912 }
1913 }
1914 }
1915 }
1916 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 public int addWindow(Session session, IWindow client,
1919 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001920 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 int res = mPolicy.checkAddPermission(attrs);
1922 if (res != WindowManagerImpl.ADD_OKAY) {
1923 return res;
1924 }
Romain Guy06882f82009-06-10 13:36:04 -07001925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 boolean reportNewConfig = false;
1927 WindowState attachedWindow = null;
1928 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07001929 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07001930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07001933 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 }
Romain Guy06882f82009-06-10 13:36:04 -07001935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001936 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001937 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1939 }
1940
1941 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001942 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001944 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 + attrs.token + ". Aborting.");
1946 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1947 }
1948 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1949 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001950 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 + attrs.token + ". Aborting.");
1952 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1953 }
1954 }
1955
1956 boolean addToken = false;
1957 WindowToken token = mTokenMap.get(attrs.token);
1958 if (token == null) {
1959 if (attrs.type >= FIRST_APPLICATION_WINDOW
1960 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001961 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 + attrs.token + ". Aborting.");
1963 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1964 }
1965 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001966 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 + attrs.token + ". Aborting.");
1968 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1969 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001970 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001971 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001972 + attrs.token + ". Aborting.");
1973 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1974 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001975 token = new WindowToken(this, attrs.token, -1, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001976 addToken = true;
1977 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1978 && attrs.type <= LAST_APPLICATION_WINDOW) {
1979 AppWindowToken atoken = token.appWindowToken;
1980 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001981 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 + token + ". Aborting.");
1983 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1984 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001985 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 + token + ". Aborting.");
1987 return WindowManagerImpl.ADD_APP_EXITING;
1988 }
1989 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1990 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001991 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1993 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1994 }
1995 } else if (attrs.type == TYPE_INPUT_METHOD) {
1996 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001997 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 + attrs.token + ". Aborting.");
1999 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2000 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002001 } else if (attrs.type == TYPE_WALLPAPER) {
2002 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002003 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002004 + attrs.token + ". Aborting.");
2005 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002007 }
2008
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002009 win = new WindowState(this, session, client, token,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 attachedWindow, attrs, viewVisibility);
2011 if (win.mDeathRecipient == null) {
2012 // Client has apparently died, so there is no reason to
2013 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002014 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002015 + " that is dead, aborting.");
2016 return WindowManagerImpl.ADD_APP_EXITING;
2017 }
2018
2019 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 res = mPolicy.prepareAddWindowLw(win, attrs);
2022 if (res != WindowManagerImpl.ADD_OKAY) {
2023 return res;
2024 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002025
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002026 if (outInputChannel != null) {
2027 String name = win.makeInputChannelName();
2028 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2029 win.mInputChannel = inputChannels[0];
2030 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2031
Jeff Brown928e0542011-01-10 11:17:36 -08002032 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034
2035 // From now on, no exceptions or errors allowed!
2036
2037 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002038
Dianne Hackborn5132b372010-07-29 12:51:35 -07002039 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 if (addToken) {
2042 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 }
2044 win.attach();
2045 mWindowMap.put(client.asBinder(), win);
2046
2047 if (attrs.type == TYPE_APPLICATION_STARTING &&
2048 token.appWindowToken != null) {
2049 token.appWindowToken.startingWindow = win;
2050 }
2051
2052 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002054 if (attrs.type == TYPE_INPUT_METHOD) {
2055 mInputMethodWindow = win;
2056 addInputMethodWindowToListLocked(win);
2057 imMayMove = false;
2058 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2059 mInputMethodDialogs.add(win);
2060 addWindowToListInOrderLocked(win, true);
2061 adjustInputMethodDialogsLocked();
2062 imMayMove = false;
2063 } else {
2064 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002065 if (attrs.type == TYPE_WALLPAPER) {
2066 mLastWallpaperTimeoutTime = 0;
2067 adjustWallpaperWindowsLocked();
2068 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002069 adjustWallpaperWindowsLocked();
2070 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 }
Romain Guy06882f82009-06-10 13:36:04 -07002072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002077 if (mInTouchMode) {
2078 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2079 }
2080 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2081 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2082 }
Romain Guy06882f82009-06-10 13:36:04 -07002083
Jeff Brown2e44b072011-01-24 15:21:56 -08002084 mInputMonitor.setUpdateInputWindowsNeededLw();
2085
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002086 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002088 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2089 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002090 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 imMayMove = false;
2092 }
2093 }
Romain Guy06882f82009-06-10 13:36:04 -07002094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002096 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002097 }
Romain Guy06882f82009-06-10 13:36:04 -07002098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002099 assignLayersLocked();
2100 // Don't do layout here, the window must call
2101 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002103 //dump();
2104
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002105 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002106 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002107 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002108 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002109
Joe Onorato8a9b2202010-02-26 18:56:32 -08002110 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002111 TAG, "New client " + client.asBinder()
2112 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002113
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002114 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002115 reportNewConfig = true;
2116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 }
2118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002119 if (reportNewConfig) {
2120 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002121 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002123 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 return res;
2126 }
Romain Guy06882f82009-06-10 13:36:04 -07002127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 public void removeWindow(Session session, IWindow client) {
2129 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002130 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 if (win == null) {
2132 return;
2133 }
2134 removeWindowLocked(session, win);
2135 }
2136 }
Romain Guy06882f82009-06-10 13:36:04 -07002137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 public void removeWindowLocked(Session session, WindowState win) {
2139
Joe Onorato8a9b2202010-02-26 18:56:32 -08002140 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141 TAG, "Remove " + win + " client="
2142 + Integer.toHexString(System.identityHashCode(
2143 win.mClient.asBinder()))
2144 + ", surface=" + win.mSurface);
2145
2146 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002147
2148 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002149
Joe Onorato8a9b2202010-02-26 18:56:32 -08002150 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002151 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2152 + " mExiting=" + win.mExiting
2153 + " isAnimating=" + win.isAnimating()
2154 + " app-animation="
2155 + (win.mAppToken != null ? win.mAppToken.animation : null)
2156 + " inPendingTransaction="
2157 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2158 + " mDisplayFrozen=" + mDisplayFrozen);
2159 // Visibility of the removed window. Will be used later to update orientation later on.
2160 boolean wasVisible = false;
2161 // First, see if we need to run an animation. If we do, we have
2162 // to hold off on removing the window until the animation is done.
2163 // If the display is frozen, just remove immediately, since the
2164 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002165 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 // If we are not currently running the exit animation, we
2167 // need to see about starting one.
2168 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2171 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2172 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2173 }
2174 // Try starting an animation.
2175 if (applyAnimationLocked(win, transit, false)) {
2176 win.mExiting = true;
2177 }
2178 }
2179 if (win.mExiting || win.isAnimating()) {
2180 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002181 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 win.mExiting = true;
2183 win.mRemoveOnExit = true;
2184 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002185 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2186 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002188 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 if (win.mAppToken != null) {
2190 win.mAppToken.updateReportedVisibilityLocked();
2191 }
2192 //dump();
2193 Binder.restoreCallingIdentity(origId);
2194 return;
2195 }
2196 }
2197
2198 removeWindowInnerLocked(session, win);
2199 // Removing a visible window will effect the computed orientation
2200 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002201 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002202 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002203 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002204 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002206 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 Binder.restoreCallingIdentity(origId);
2208 }
Romain Guy06882f82009-06-10 13:36:04 -07002209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002211 if (win.mRemoved) {
2212 // Nothing to do.
2213 return;
2214 }
2215
2216 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2217 WindowState cwin = win.mChildWindows.get(i);
2218 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2219 + win);
2220 removeWindowInnerLocked(cwin.mSession, cwin);
2221 }
2222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 if (mInputMethodTarget == win) {
2226 moveInputMethodWindowsIfNeededLocked(false);
2227 }
Romain Guy06882f82009-06-10 13:36:04 -07002228
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002229 if (false) {
2230 RuntimeException e = new RuntimeException("here");
2231 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002232 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002233 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 mPolicy.removeWindowLw(win);
2236 win.removeLocked();
2237
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002238 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 mWindowMap.remove(win.mClient.asBinder());
2240 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002241 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002242 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002243 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244
2245 if (mInputMethodWindow == win) {
2246 mInputMethodWindow = null;
2247 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2248 mInputMethodDialogs.remove(win);
2249 }
Romain Guy06882f82009-06-10 13:36:04 -07002250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 final WindowToken token = win.mToken;
2252 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002253 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 token.windows.remove(win);
2255 if (atoken != null) {
2256 atoken.allAppWindows.remove(win);
2257 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002258 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 TAG, "**** Removing window " + win + ": count="
2260 + token.windows.size());
2261 if (token.windows.size() == 0) {
2262 if (!token.explicit) {
2263 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 } else if (atoken != null) {
2265 atoken.firstWindowDrawn = false;
2266 }
2267 }
2268
2269 if (atoken != null) {
2270 if (atoken.startingWindow == win) {
2271 atoken.startingWindow = null;
2272 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2273 // If this is the last window and we had requested a starting
2274 // transition window, well there is no point now.
2275 atoken.startingData = null;
2276 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2277 // If this is the last window except for a starting transition
2278 // window, we need to get rid of the starting transition.
2279 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002280 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 + ": no more real windows");
2282 }
2283 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2284 mH.sendMessage(m);
2285 }
2286 }
Romain Guy06882f82009-06-10 13:36:04 -07002287
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002288 if (win.mAttrs.type == TYPE_WALLPAPER) {
2289 mLastWallpaperTimeoutTime = 0;
2290 adjustWallpaperWindowsLocked();
2291 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002292 adjustWallpaperWindowsLocked();
2293 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 if (!mInLayout) {
2296 assignLayersLocked();
2297 mLayoutNeeded = true;
2298 performLayoutAndPlaceSurfacesLocked();
2299 if (win.mAppToken != null) {
2300 win.mAppToken.updateReportedVisibilityLocked();
2301 }
2302 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002303
Jeff Brown2e44b072011-01-24 15:21:56 -08002304 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 }
2306
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002307 static void logSurface(WindowState w, String msg, RuntimeException where) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002308 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2309 + ": " + msg + " / " + w.mAttrs.getTitle();
2310 if (where != null) {
2311 Slog.i(TAG, str, where);
2312 } else {
2313 Slog.i(TAG, str);
2314 }
2315 }
2316
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002317 void setTransparentRegionWindow(Session session, IWindow client, Region region) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 long origId = Binder.clearCallingIdentity();
2319 try {
2320 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002321 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002323 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2324 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 Surface.openTransaction();
2326 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002327 if (SHOW_TRANSACTIONS) logSurface(w,
2328 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 w.mSurface.setTransparentRegionHint(region);
2330 } finally {
2331 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002332 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2333 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 }
2335 }
2336 }
2337 } finally {
2338 Binder.restoreCallingIdentity(origId);
2339 }
2340 }
2341
2342 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002343 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002344 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 long origId = Binder.clearCallingIdentity();
2346 try {
2347 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002348 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 if (w != null) {
2350 w.mGivenInsetsPending = false;
2351 w.mGivenContentInsets.set(contentInsets);
2352 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002353 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 w.mTouchableInsets = touchableInsets;
2355 mLayoutNeeded = true;
2356 performLayoutAndPlaceSurfacesLocked();
2357 }
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(origId);
2361 }
2362 }
Romain Guy06882f82009-06-10 13:36:04 -07002363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 public void getWindowDisplayFrame(Session session, IWindow client,
2365 Rect outDisplayFrame) {
2366 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002367 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 if (win == null) {
2369 outDisplayFrame.setEmpty();
2370 return;
2371 }
2372 outDisplayFrame.set(win.mDisplayFrame);
2373 }
2374 }
2375
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002376 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2377 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002378 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2379 window.mWallpaperX = x;
2380 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002381 window.mWallpaperXStep = xStep;
2382 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002383 if (updateWallpaperOffsetLocked(window, true)) {
2384 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002385 }
2386 }
2387 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002388
Dianne Hackborn75804932009-10-20 20:15:20 -07002389 void wallpaperCommandComplete(IBinder window, Bundle result) {
2390 synchronized (mWindowMap) {
2391 if (mWaitingOnWallpaper != null &&
2392 mWaitingOnWallpaper.mClient.asBinder() == window) {
2393 mWaitingOnWallpaper = null;
2394 mWindowMap.notifyAll();
2395 }
2396 }
2397 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002398
Dianne Hackborn75804932009-10-20 20:15:20 -07002399 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2400 String action, int x, int y, int z, Bundle extras, boolean sync) {
2401 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2402 || window == mUpperWallpaperTarget) {
2403 boolean doWait = sync;
2404 int curTokenIndex = mWallpaperTokens.size();
2405 while (curTokenIndex > 0) {
2406 curTokenIndex--;
2407 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2408 int curWallpaperIndex = token.windows.size();
2409 while (curWallpaperIndex > 0) {
2410 curWallpaperIndex--;
2411 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2412 try {
2413 wallpaper.mClient.dispatchWallpaperCommand(action,
2414 x, y, z, extras, sync);
2415 // We only want to be synchronous with one wallpaper.
2416 sync = false;
2417 } catch (RemoteException e) {
2418 }
2419 }
2420 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002421
Dianne Hackborn75804932009-10-20 20:15:20 -07002422 if (doWait) {
2423 // XXX Need to wait for result.
2424 }
2425 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002426
Dianne Hackborn75804932009-10-20 20:15:20 -07002427 return null;
2428 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 public int relayoutWindow(Session session, IWindow client,
2431 WindowManager.LayoutParams attrs, int requestedWidth,
2432 int requestedHeight, int viewVisibility, boolean insetsPending,
2433 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002434 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 boolean displayed = false;
2436 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002437 boolean configChanged;
Joe Onoratoac0ee892011-01-30 15:38:30 -08002438
2439 // if they don't have this permission, mask out the status bar bits
2440 if (attrs != null) {
2441 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
2442 != PackageManager.PERMISSION_GRANTED) {
2443 attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2444 attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2445 }
2446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002450 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 if (win == null) {
2452 return 0;
2453 }
2454 win.mRequestedWidth = requestedWidth;
2455 win.mRequestedHeight = requestedHeight;
2456
2457 if (attrs != null) {
2458 mPolicy.adjustWindowParamsLw(attrs);
2459 }
Romain Guy06882f82009-06-10 13:36:04 -07002460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 int attrChanges = 0;
2462 int flagChanges = 0;
2463 if (attrs != null) {
2464 flagChanges = win.mAttrs.flags ^= attrs.flags;
2465 attrChanges = win.mAttrs.copyFrom(attrs);
2466 }
2467
Joe Onorato8a9b2202010-02-26 18:56:32 -08002468 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469
2470 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2471 win.mAlpha = attrs.alpha;
2472 }
2473
2474 final boolean scaledWindow =
2475 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2476
2477 if (scaledWindow) {
2478 // requested{Width|Height} Surface's physical size
2479 // attrs.{width|height} Size on screen
2480 win.mHScale = (attrs.width != requestedWidth) ?
2481 (attrs.width / (float)requestedWidth) : 1.0f;
2482 win.mVScale = (attrs.height != requestedHeight) ?
2483 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002484 } else {
2485 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 }
2487
2488 boolean imMayMove = (flagChanges&(
2489 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2490 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 boolean focusMayChange = win.mViewVisibility != viewVisibility
2493 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2494 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002495
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002496 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2497 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 win.mRelayoutCalled = true;
2500 final int oldVisibility = win.mViewVisibility;
2501 win.mViewVisibility = viewVisibility;
2502 if (viewVisibility == View.VISIBLE &&
2503 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2504 displayed = !win.isVisibleLw();
2505 if (win.mExiting) {
2506 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002507 if (win.mAnimation != null) {
2508 win.mAnimation.cancel();
2509 win.mAnimation = null;
2510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 }
2512 if (win.mDestroying) {
2513 win.mDestroying = false;
2514 mDestroySurface.remove(win);
2515 }
2516 if (oldVisibility == View.GONE) {
2517 win.mEnterAnimationPending = true;
2518 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002519 if (displayed) {
2520 if (win.mSurface != null && !win.mDrawPending
2521 && !win.mCommitDrawPending && !mDisplayFrozen
2522 && mPolicy.isScreenOn()) {
2523 applyEnterAnimationLocked(win);
2524 }
2525 if ((win.mAttrs.flags
2526 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2527 if (DEBUG_VISIBILITY) Slog.v(TAG,
2528 "Relayout window turning screen on: " + win);
2529 win.mTurnOnScreen = true;
2530 }
2531 int diff = 0;
2532 if (win.mConfiguration != mCurConfiguration
2533 && (win.mConfiguration == null
2534 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2535 win.mConfiguration = mCurConfiguration;
2536 if (DEBUG_CONFIGURATION) {
2537 Slog.i(TAG, "Window " + win + " visible with new config: "
2538 + win.mConfiguration + " / 0x"
2539 + Integer.toHexString(diff));
2540 }
2541 outConfig.setTo(mCurConfiguration);
2542 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002543 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2545 // To change the format, we need to re-build the surface.
2546 win.destroySurfaceLocked();
2547 displayed = true;
2548 }
2549 try {
2550 Surface surface = win.createSurfaceLocked();
2551 if (surface != null) {
2552 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002553 win.mReportDestroySurface = false;
2554 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002555 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002556 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002558 // For some reason there isn't a surface. Clear the
2559 // caller's object so they see the same state.
2560 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 }
2562 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002563 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002564
Joe Onorato8a9b2202010-02-26 18:56:32 -08002565 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002566 + client + " (" + win.mAttrs.getTitle() + ")",
2567 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 Binder.restoreCallingIdentity(origId);
2569 return 0;
2570 }
2571 if (displayed) {
2572 focusMayChange = true;
2573 }
2574 if (win.mAttrs.type == TYPE_INPUT_METHOD
2575 && mInputMethodWindow == null) {
2576 mInputMethodWindow = win;
2577 imMayMove = true;
2578 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002579 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2580 && win.mAppToken != null
2581 && win.mAppToken.startingWindow != null) {
2582 // Special handling of starting window over the base
2583 // window of the app: propagate lock screen flags to it,
2584 // to provide the correct semantics while starting.
2585 final int mask =
2586 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002587 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2588 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002589 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2590 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592 } else {
2593 win.mEnterAnimationPending = false;
2594 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002595 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002596 + ": mExiting=" + win.mExiting
2597 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 // If we are not currently running the exit animation, we
2599 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002600 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 // Try starting an animation; if there isn't one, we
2602 // can destroy the surface right away.
2603 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2604 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2605 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2606 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002607 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002609 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 } else if (win.isAnimating()) {
2612 // Currently in a hide animation... turn this into
2613 // an exit.
2614 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002615 } else if (win == mWallpaperTarget) {
2616 // If the wallpaper is currently behind this
2617 // window, we need to change both of them inside
2618 // of a transaction to avoid artifacts.
2619 win.mExiting = true;
2620 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 } else {
2622 if (mInputMethodWindow == win) {
2623 mInputMethodWindow = null;
2624 }
2625 win.destroySurfaceLocked();
2626 }
2627 }
2628 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002629
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002630 if (win.mSurface == null || (win.getAttrs().flags
2631 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2632 || win.mSurfacePendingDestroy) {
2633 // We are being called from a local process, which
2634 // means outSurface holds its current surface. Ensure the
2635 // surface object is cleared, but we don't want it actually
2636 // destroyed at this point.
2637 win.mSurfacePendingDestroy = false;
2638 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002639 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002640 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002641 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002642 "Keeping surface, will report destroy: " + win);
2643 win.mReportDestroySurface = true;
2644 outSurface.copyFrom(win.mSurface);
2645 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 }
2647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 if (focusMayChange) {
2649 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002650 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2651 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 imMayMove = false;
2653 }
2654 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2655 }
Romain Guy06882f82009-06-10 13:36:04 -07002656
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002657 // updateFocusedWindowLocked() already assigned layers so we only need to
2658 // reassign them at this point if the IM window state gets shuffled
2659 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002662 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2663 // Little hack here -- we -should- be able to rely on the
2664 // function to return true if the IME has moved and needs
2665 // its layer recomputed. However, if the IME was hidden
2666 // and isn't actually moved in the list, its layer may be
2667 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 assignLayers = true;
2669 }
2670 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002671 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002672 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002673 assignLayers = true;
2674 }
2675 }
Romain Guy06882f82009-06-10 13:36:04 -07002676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 mLayoutNeeded = true;
2678 win.mGivenInsetsPending = insetsPending;
2679 if (assignLayers) {
2680 assignLayersLocked();
2681 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002682 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002684 if (displayed && win.mIsWallpaper) {
2685 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002686 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002687 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 if (win.mAppToken != null) {
2689 win.mAppToken.updateReportedVisibilityLocked();
2690 }
2691 outFrame.set(win.mFrame);
2692 outContentInsets.set(win.mContentInsets);
2693 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002694 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002696 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 + ", requestedHeight=" + requestedHeight
2698 + ", viewVisibility=" + viewVisibility
2699 + "\nRelayout returning frame=" + outFrame
2700 + ", surface=" + outSurface);
2701
Joe Onorato8a9b2202010-02-26 18:56:32 -08002702 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002703 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2704
2705 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002706
Jeff Brown2e44b072011-01-24 15:21:56 -08002707 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708 }
2709
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002710 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 sendNewConfiguration();
2712 }
Romain Guy06882f82009-06-10 13:36:04 -07002713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2717 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2718 }
2719
Dianne Hackborn64825172011-03-02 21:32:58 -08002720 public boolean outOfMemoryWindow(Session session, IWindow client) {
2721 long origId = Binder.clearCallingIdentity();
2722
2723 try {
2724 synchronized(mWindowMap) {
2725 WindowState win = windowForClientLocked(session, client, false);
2726 if (win == null) {
2727 return false;
2728 }
2729 return reclaimSomeSurfaceMemoryLocked(win, "from-client", false);
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(origId);
2733 }
2734 }
2735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002736 public void finishDrawingWindow(Session session, IWindow client) {
2737 final long origId = Binder.clearCallingIdentity();
2738 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002739 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002741 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2742 adjustWallpaperWindowsLocked();
2743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002744 mLayoutNeeded = true;
2745 performLayoutAndPlaceSurfacesLocked();
2746 }
2747 }
2748 Binder.restoreCallingIdentity(origId);
2749 }
2750
2751 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08002752 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 + (lp != null ? lp.packageName : null)
2754 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2755 if (lp != null && lp.windowAnimations != 0) {
2756 // If this is a system resource, don't try to load it from the
2757 // application resources. It is nice to avoid loading application
2758 // resources if we can.
2759 String packageName = lp.packageName != null ? lp.packageName : "android";
2760 int resId = lp.windowAnimations;
2761 if ((resId&0xFF000000) == 0x01000000) {
2762 packageName = "android";
2763 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002764 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 + packageName);
2766 return AttributeCache.instance().get(packageName, resId,
2767 com.android.internal.R.styleable.WindowAnimation);
2768 }
2769 return null;
2770 }
Romain Guy06882f82009-06-10 13:36:04 -07002771
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002772 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08002773 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002774 + packageName + " resId=0x" + Integer.toHexString(resId));
2775 if (packageName != null) {
2776 if ((resId&0xFF000000) == 0x01000000) {
2777 packageName = "android";
2778 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002779 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002780 + packageName);
2781 return AttributeCache.instance().get(packageName, resId,
2782 com.android.internal.R.styleable.WindowAnimation);
2783 }
2784 return null;
2785 }
2786
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002787 void applyEnterAnimationLocked(WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2789 if (win.mEnterAnimationPending) {
2790 win.mEnterAnimationPending = false;
2791 transit = WindowManagerPolicy.TRANSIT_ENTER;
2792 }
2793
2794 applyAnimationLocked(win, transit, true);
2795 }
2796
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002797 boolean applyAnimationLocked(WindowState win,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 int transit, boolean isEntrance) {
2799 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2800 // If we are trying to apply an animation, but already running
2801 // an animation of the same type, then just leave that one alone.
2802 return true;
2803 }
Romain Guy06882f82009-06-10 13:36:04 -07002804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 // Only apply an animation if the display isn't frozen. If it is
2806 // frozen, there is no reason to animate and it can cause strange
2807 // artifacts when we unfreeze the display if some different animation
2808 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002809 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 int anim = mPolicy.selectAnimationLw(win, transit);
2811 int attr = -1;
2812 Animation a = null;
2813 if (anim != 0) {
2814 a = AnimationUtils.loadAnimation(mContext, anim);
2815 } else {
2816 switch (transit) {
2817 case WindowManagerPolicy.TRANSIT_ENTER:
2818 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2819 break;
2820 case WindowManagerPolicy.TRANSIT_EXIT:
2821 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2822 break;
2823 case WindowManagerPolicy.TRANSIT_SHOW:
2824 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2825 break;
2826 case WindowManagerPolicy.TRANSIT_HIDE:
2827 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2828 break;
2829 }
2830 if (attr >= 0) {
2831 a = loadAnimation(win.mAttrs, attr);
2832 }
2833 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002834 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2836 + " mAnimation=" + win.mAnimation
2837 + " isEntrance=" + isEntrance);
2838 if (a != null) {
2839 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002840 RuntimeException e = null;
2841 if (!HIDE_STACK_CRAWLS) {
2842 e = new RuntimeException();
2843 e.fillInStackTrace();
2844 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002845 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 }
2847 win.setAnimation(a);
2848 win.mAnimationIsEntrance = isEntrance;
2849 }
2850 } else {
2851 win.clearAnimation();
2852 }
2853
2854 return win.mAnimation != null;
2855 }
2856
2857 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2858 int anim = 0;
2859 Context context = mContext;
2860 if (animAttr >= 0) {
2861 AttributeCache.Entry ent = getCachedAnimations(lp);
2862 if (ent != null) {
2863 context = ent.context;
2864 anim = ent.array.getResourceId(animAttr, 0);
2865 }
2866 }
2867 if (anim != 0) {
2868 return AnimationUtils.loadAnimation(context, anim);
2869 }
2870 return null;
2871 }
Romain Guy06882f82009-06-10 13:36:04 -07002872
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002873 private Animation loadAnimation(String packageName, int resId) {
2874 int anim = 0;
2875 Context context = mContext;
2876 if (resId >= 0) {
2877 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2878 if (ent != null) {
2879 context = ent.context;
2880 anim = resId;
2881 }
2882 }
2883 if (anim != 0) {
2884 return AnimationUtils.loadAnimation(context, anim);
2885 }
2886 return null;
2887 }
2888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 private boolean applyAnimationLocked(AppWindowToken wtoken,
2890 WindowManager.LayoutParams lp, int transit, boolean enter) {
2891 // Only apply an animation if the display isn't frozen. If it is
2892 // frozen, there is no reason to animate and it can cause strange
2893 // artifacts when we unfreeze the display if some different animation
2894 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002895 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002896 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002897 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002898 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002899 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002900 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002901 } else if (mNextAppTransitionPackage != null) {
2902 a = loadAnimation(mNextAppTransitionPackage, enter ?
2903 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002904 } else {
2905 int animAttr = 0;
2906 switch (transit) {
2907 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2908 animAttr = enter
2909 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2910 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2911 break;
2912 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2913 animAttr = enter
2914 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2915 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2916 break;
2917 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2918 animAttr = enter
2919 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2920 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2921 break;
2922 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2923 animAttr = enter
2924 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2925 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2926 break;
2927 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2928 animAttr = enter
2929 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2930 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2931 break;
2932 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2933 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002934 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002935 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2936 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002937 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002938 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002939 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2940 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002941 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002942 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002943 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002944 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2945 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2946 break;
2947 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2948 animAttr = enter
2949 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2950 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2951 break;
2952 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2953 animAttr = enter
2954 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2955 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002956 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002957 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002958 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002959 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002960 + " anim=" + a
2961 + " animAttr=0x" + Integer.toHexString(animAttr)
2962 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 if (a != null) {
2965 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002966 RuntimeException e = null;
2967 if (!HIDE_STACK_CRAWLS) {
2968 e = new RuntimeException();
2969 e.fillInStackTrace();
2970 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 }
2973 wtoken.setAnimation(a);
2974 }
2975 } else {
2976 wtoken.clearAnimation();
2977 }
2978
2979 return wtoken.animation != null;
2980 }
2981
2982 // -------------------------------------------------------------
2983 // Application Window Tokens
2984 // -------------------------------------------------------------
2985
2986 public void validateAppTokens(List tokens) {
2987 int v = tokens.size()-1;
2988 int m = mAppTokens.size()-1;
2989 while (v >= 0 && m >= 0) {
2990 AppWindowToken wtoken = mAppTokens.get(m);
2991 if (wtoken.removed) {
2992 m--;
2993 continue;
2994 }
2995 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002996 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2998 }
2999 v--;
3000 m--;
3001 }
3002 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003003 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003004 v--;
3005 }
3006 while (m >= 0) {
3007 AppWindowToken wtoken = mAppTokens.get(m);
3008 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003009 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 }
3011 m--;
3012 }
3013 }
3014
3015 boolean checkCallingPermission(String permission, String func) {
3016 // Quick check: if the calling permission is me, it's all okay.
3017 if (Binder.getCallingPid() == Process.myPid()) {
3018 return true;
3019 }
Romain Guy06882f82009-06-10 13:36:04 -07003020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 if (mContext.checkCallingPermission(permission)
3022 == PackageManager.PERMISSION_GRANTED) {
3023 return true;
3024 }
3025 String msg = "Permission Denial: " + func + " from pid="
3026 + Binder.getCallingPid()
3027 + ", uid=" + Binder.getCallingUid()
3028 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003029 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 return false;
3031 }
Romain Guy06882f82009-06-10 13:36:04 -07003032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003033 AppWindowToken findAppWindowToken(IBinder token) {
3034 WindowToken wtoken = mTokenMap.get(token);
3035 if (wtoken == null) {
3036 return null;
3037 }
3038 return wtoken.appWindowToken;
3039 }
Romain Guy06882f82009-06-10 13:36:04 -07003040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041 public void addWindowToken(IBinder token, int type) {
3042 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3043 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003044 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003045 }
Romain Guy06882f82009-06-10 13:36:04 -07003046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 synchronized(mWindowMap) {
3048 WindowToken wtoken = mTokenMap.get(token);
3049 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003050 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051 return;
3052 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003053 wtoken = new WindowToken(this, token, type, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003054 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003055 if (type == TYPE_WALLPAPER) {
3056 mWallpaperTokens.add(wtoken);
3057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
3059 }
Romain Guy06882f82009-06-10 13:36:04 -07003060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 public void removeWindowToken(IBinder token) {
3062 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3063 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003064 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003065 }
3066
3067 final long origId = Binder.clearCallingIdentity();
3068 synchronized(mWindowMap) {
3069 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 if (wtoken != null) {
3071 boolean delayed = false;
3072 if (!wtoken.hidden) {
3073 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003075 final int N = wtoken.windows.size();
3076 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 for (int i=0; i<N; i++) {
3079 WindowState win = wtoken.windows.get(i);
3080
3081 if (win.isAnimating()) {
3082 delayed = true;
3083 }
Romain Guy06882f82009-06-10 13:36:04 -07003084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003085 if (win.isVisibleNow()) {
3086 applyAnimationLocked(win,
3087 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003088 changed = true;
3089 }
3090 }
3091
3092 if (changed) {
3093 mLayoutNeeded = true;
3094 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003095 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3096 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003097 }
Romain Guy06882f82009-06-10 13:36:04 -07003098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 if (delayed) {
3100 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003101 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3102 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003103 }
3104 }
Romain Guy06882f82009-06-10 13:36:04 -07003105
Jeff Brown2e44b072011-01-24 15:21:56 -08003106 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003107 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003108 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 }
3110 }
3111 Binder.restoreCallingIdentity(origId);
3112 }
3113
3114 public void addAppToken(int addPos, IApplicationToken token,
3115 int groupId, int requestedOrientation, boolean fullscreen) {
3116 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3117 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003118 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119 }
Jeff Brown349703e2010-06-22 01:27:15 -07003120
3121 // Get the dispatching timeout here while we are not holding any locks so that it
3122 // can be cached by the AppWindowToken. The timeout value is used later by the
3123 // input dispatcher in code that does hold locks. If we did not cache the value
3124 // here we would run the chance of introducing a deadlock between the window manager
3125 // (which holds locks while updating the input dispatcher state) and the activity manager
3126 // (which holds locks while querying the application token).
3127 long inputDispatchingTimeoutNanos;
3128 try {
3129 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3130 } catch (RemoteException ex) {
3131 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3132 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3133 }
Romain Guy06882f82009-06-10 13:36:04 -07003134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 synchronized(mWindowMap) {
3136 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3137 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003138 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 return;
3140 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003141 wtoken = new AppWindowToken(this, token);
Jeff Brown349703e2010-06-22 01:27:15 -07003142 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 wtoken.groupId = groupId;
3144 wtoken.appFullscreen = fullscreen;
3145 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003146 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 // Application tokens start out hidden.
3151 wtoken.hidden = true;
3152 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 //dump();
3155 }
3156 }
Romain Guy06882f82009-06-10 13:36:04 -07003157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 public void setAppGroupId(IBinder token, int groupId) {
3159 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3160 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003161 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 }
3163
3164 synchronized(mWindowMap) {
3165 AppWindowToken wtoken = findAppWindowToken(token);
3166 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003167 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168 return;
3169 }
3170 wtoken.groupId = groupId;
3171 }
3172 }
Romain Guy06882f82009-06-10 13:36:04 -07003173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 public int getOrientationFromWindowsLocked() {
3175 int pos = mWindows.size() - 1;
3176 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003177 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178 pos--;
3179 if (wtoken.mAppToken != null) {
3180 // We hit an application window. so the orientation will be determined by the
3181 // app window. No point in continuing further.
3182 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3183 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003184 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 continue;
3186 }
3187 int req = wtoken.mAttrs.screenOrientation;
3188 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3189 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3190 continue;
3191 } else {
3192 return req;
3193 }
3194 }
3195 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3196 }
Romain Guy06882f82009-06-10 13:36:04 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003199 int pos = mAppTokens.size() - 1;
3200 int curGroup = 0;
3201 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3202 boolean findingBehind = false;
3203 boolean haveGroup = false;
3204 boolean lastFullscreen = false;
3205 while (pos >= 0) {
3206 AppWindowToken wtoken = mAppTokens.get(pos);
3207 pos--;
3208 // if we're about to tear down this window and not seek for
3209 // the behind activity, don't use it for orientation
3210 if (!findingBehind
3211 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3212 continue;
3213 }
3214
3215 if (!haveGroup) {
3216 // We ignore any hidden applications on the top.
3217 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003218 continue;
3219 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003220 haveGroup = true;
3221 curGroup = wtoken.groupId;
3222 lastOrientation = wtoken.requestedOrientation;
3223 } else if (curGroup != wtoken.groupId) {
3224 // If we have hit a new application group, and the bottom
3225 // of the previous group didn't explicitly say to use
3226 // the orientation behind it, and the last app was
3227 // full screen, then we'll stick with the
3228 // user's orientation.
3229 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3230 && lastFullscreen) {
3231 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003234 int or = wtoken.requestedOrientation;
3235 // If this application is fullscreen, and didn't explicitly say
3236 // to use the orientation behind it, then just take whatever
3237 // orientation it has and ignores whatever is under it.
3238 lastFullscreen = wtoken.appFullscreen;
3239 if (lastFullscreen
3240 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3241 return or;
3242 }
3243 // If this application has requested an explicit orientation,
3244 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003245 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3246 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003247 return or;
3248 }
3249 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3250 }
3251 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 }
Romain Guy06882f82009-06-10 13:36:04 -07003253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003255 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003256 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3257 "updateOrientationFromAppTokens()")) {
3258 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3259 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003260
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003261 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003263
3264 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003265 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003266 if (freezeThisOneIfNeeded != null) {
3267 AppWindowToken wtoken = findAppWindowToken(
3268 freezeThisOneIfNeeded);
3269 if (wtoken != null) {
3270 startAppFreezingScreenLocked(wtoken,
3271 ActivityInfo.CONFIG_ORIENTATION);
3272 }
3273 }
3274 config = computeNewConfigurationLocked();
3275
3276 } else if (currentConfig != null) {
3277 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003278 // state mismatches the activity manager's, update it,
3279 // disregarding font scale, which should remain set to
3280 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003281 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003282 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003283 if (computeNewConfigurationLocked(mTempConfiguration)) {
3284 if (currentConfig.diff(mTempConfiguration) != 0) {
3285 mWaitingForConfig = true;
3286 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003287 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003288 config = new Configuration(mTempConfiguration);
3289 }
3290 }
3291 }
3292 }
3293
Dianne Hackborncfaef692009-06-15 14:24:44 -07003294 Binder.restoreCallingIdentity(ident);
3295 return config;
3296 }
3297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003299 * Determine the new desired orientation of the display, returning
3300 * a non-null new Configuration if it has changed from the current
3301 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3302 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3303 * SCREEN. This will typically be done for you if you call
3304 * sendNewConfiguration().
3305 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 * The orientation is computed from non-application windows first. If none of
3307 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003308 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3310 * android.os.IBinder)
3311 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003312 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3313 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003314 // If the display is frozen, some activities may be in the middle
3315 // of restarting, and thus have removed their old window. If the
3316 // window has the flag to hide the lock screen, then the lock screen
3317 // can re-appear and inflict its own orientation on us. Keep the
3318 // orientation stable until this all settles down.
3319 return false;
3320 }
3321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 long ident = Binder.clearCallingIdentity();
3324 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003325 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 mForcedAppOrientation = req;
3329 //send a message to Policy indicating orientation change to take
3330 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003331 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003332 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003333 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3334 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003335 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 }
3337 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003338
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003339 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 } finally {
3341 Binder.restoreCallingIdentity(ident);
3342 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 }
Romain Guy06882f82009-06-10 13:36:04 -07003344
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003345 int computeForcedAppOrientationLocked() {
3346 int req = getOrientationFromWindowsLocked();
3347 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3348 req = getOrientationFromAppTokensLocked();
3349 }
3350 return req;
3351 }
Romain Guy06882f82009-06-10 13:36:04 -07003352
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003353 public void setNewConfiguration(Configuration config) {
3354 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3355 "setNewConfiguration()")) {
3356 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3357 }
3358
3359 synchronized(mWindowMap) {
3360 mCurConfiguration = new Configuration(config);
3361 mWaitingForConfig = false;
3362 performLayoutAndPlaceSurfacesLocked();
3363 }
3364 }
3365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3367 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3368 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003369 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 }
Romain Guy06882f82009-06-10 13:36:04 -07003371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 synchronized(mWindowMap) {
3373 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3374 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003375 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 return;
3377 }
Romain Guy06882f82009-06-10 13:36:04 -07003378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 wtoken.requestedOrientation = requestedOrientation;
3380 }
3381 }
Romain Guy06882f82009-06-10 13:36:04 -07003382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 public int getAppOrientation(IApplicationToken token) {
3384 synchronized(mWindowMap) {
3385 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3386 if (wtoken == null) {
3387 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3388 }
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 return wtoken.requestedOrientation;
3391 }
3392 }
Romain Guy06882f82009-06-10 13:36:04 -07003393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003394 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3395 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3396 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003397 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 }
3399
3400 synchronized(mWindowMap) {
3401 boolean changed = false;
3402 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003403 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 changed = mFocusedApp != null;
3405 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003406 if (changed) {
3407 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 } else {
3410 AppWindowToken newFocus = findAppWindowToken(token);
3411 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003412 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 return;
3414 }
3415 changed = mFocusedApp != newFocus;
3416 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003417 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003418 if (changed) {
3419 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003420 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 }
3422
3423 if (moveFocusNow && changed) {
3424 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003425 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 Binder.restoreCallingIdentity(origId);
3427 }
3428 }
3429 }
3430
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003431 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003432 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3433 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003434 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 }
Romain Guy06882f82009-06-10 13:36:04 -07003436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003438 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 TAG, "Prepare app transition: transit=" + transit
3440 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003441 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003442 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3443 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003445 } else if (!alwaysKeepCurrent) {
3446 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3447 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3448 // Opening a new task always supersedes a close for the anim.
3449 mNextAppTransition = transit;
3450 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3451 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3452 // Opening a new activity always supersedes a close for the anim.
3453 mNextAppTransition = transit;
3454 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003455 }
3456 mAppTransitionReady = false;
3457 mAppTransitionTimeout = false;
3458 mStartingIconInTransition = false;
3459 mSkipAppTransitionAnimation = false;
3460 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3461 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3462 5000);
3463 }
3464 }
3465 }
3466
3467 public int getPendingAppTransition() {
3468 return mNextAppTransition;
3469 }
Romain Guy06882f82009-06-10 13:36:04 -07003470
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003471 public void overridePendingAppTransition(String packageName,
3472 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003473 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003474 mNextAppTransitionPackage = packageName;
3475 mNextAppTransitionEnter = enterAnim;
3476 mNextAppTransitionExit = exitAnim;
3477 }
3478 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 public void executeAppTransition() {
3481 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3482 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003483 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003484 }
Romain Guy06882f82009-06-10 13:36:04 -07003485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003487 if (DEBUG_APP_TRANSITIONS) {
3488 RuntimeException e = new RuntimeException("here");
3489 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003490 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003491 + mNextAppTransition, e);
3492 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003493 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003494 mAppTransitionReady = true;
3495 final long origId = Binder.clearCallingIdentity();
3496 performLayoutAndPlaceSurfacesLocked();
3497 Binder.restoreCallingIdentity(origId);
3498 }
3499 }
3500 }
3501
3502 public void setAppStartingWindow(IBinder token, String pkg,
3503 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003504 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003505 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3506 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003507 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 }
3509
3510 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003511 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3513 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 AppWindowToken wtoken = findAppWindowToken(token);
3516 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003517 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 return;
3519 }
3520
3521 // If the display is frozen, we won't do anything until the
3522 // actual window is displayed so there is no reason to put in
3523 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003524 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003525 return;
3526 }
Romain Guy06882f82009-06-10 13:36:04 -07003527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 if (wtoken.startingData != null) {
3529 return;
3530 }
Romain Guy06882f82009-06-10 13:36:04 -07003531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 if (transferFrom != null) {
3533 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3534 if (ttoken != null) {
3535 WindowState startingWindow = ttoken.startingWindow;
3536 if (startingWindow != null) {
3537 if (mStartingIconInTransition) {
3538 // In this case, the starting icon has already
3539 // been displayed, so start letting windows get
3540 // shown immediately without any more transitions.
3541 mSkipAppTransitionAnimation = true;
3542 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003543 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 "Moving existing starting from " + ttoken
3545 + " to " + wtoken);
3546 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 // Transfer the starting window over to the new
3549 // token.
3550 wtoken.startingData = ttoken.startingData;
3551 wtoken.startingView = ttoken.startingView;
3552 wtoken.startingWindow = startingWindow;
3553 ttoken.startingData = null;
3554 ttoken.startingView = null;
3555 ttoken.startingWindow = null;
3556 ttoken.startingMoved = true;
3557 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003558 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003560 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003561 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003563 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003564 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3565 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 ttoken.windows.remove(startingWindow);
3567 ttoken.allAppWindows.remove(startingWindow);
3568 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 // Propagate other interesting state between the
3571 // tokens. If the old token is displayed, we should
3572 // immediately force the new one to be displayed. If
3573 // it is animating, we need to move that animation to
3574 // the new one.
3575 if (ttoken.allDrawn) {
3576 wtoken.allDrawn = true;
3577 }
3578 if (ttoken.firstWindowDrawn) {
3579 wtoken.firstWindowDrawn = true;
3580 }
3581 if (!ttoken.hidden) {
3582 wtoken.hidden = false;
3583 wtoken.hiddenRequested = false;
3584 wtoken.willBeHidden = false;
3585 }
3586 if (wtoken.clientHidden != ttoken.clientHidden) {
3587 wtoken.clientHidden = ttoken.clientHidden;
3588 wtoken.sendAppVisibilityToClients();
3589 }
3590 if (ttoken.animation != null) {
3591 wtoken.animation = ttoken.animation;
3592 wtoken.animating = ttoken.animating;
3593 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3594 ttoken.animation = null;
3595 ttoken.animLayerAdjustment = 0;
3596 wtoken.updateLayers();
3597 ttoken.updateLayers();
3598 }
Romain Guy06882f82009-06-10 13:36:04 -07003599
Jeff Brown3a22cd92011-01-21 13:59:04 -08003600 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3601 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 mLayoutNeeded = true;
3603 performLayoutAndPlaceSurfacesLocked();
3604 Binder.restoreCallingIdentity(origId);
3605 return;
3606 } else if (ttoken.startingData != null) {
3607 // The previous app was getting ready to show a
3608 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003609 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 "Moving pending starting from " + ttoken
3611 + " to " + wtoken);
3612 wtoken.startingData = ttoken.startingData;
3613 ttoken.startingData = null;
3614 ttoken.startingMoved = true;
3615 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3616 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3617 // want to process the message ASAP, before any other queued
3618 // messages.
3619 mH.sendMessageAtFrontOfQueue(m);
3620 return;
3621 }
3622 }
3623 }
3624
3625 // There is no existing starting window, and the caller doesn't
3626 // want us to create one, so that's it!
3627 if (!createIfNeeded) {
3628 return;
3629 }
Romain Guy06882f82009-06-10 13:36:04 -07003630
Dianne Hackborn284ac932009-08-28 10:34:25 -07003631 // If this is a translucent or wallpaper window, then don't
3632 // show a starting window -- the current effect (a full-screen
3633 // opaque starting window that fades away to the real contents
3634 // when it is ready) does not work for this.
3635 if (theme != 0) {
3636 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3637 com.android.internal.R.styleable.Window);
3638 if (ent.array.getBoolean(
3639 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3640 return;
3641 }
3642 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003643 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3644 return;
3645 }
3646 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003647 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3648 return;
3649 }
3650 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003652 mStartingIconInTransition = true;
3653 wtoken.startingData = new StartingData(
3654 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003655 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3657 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3658 // want to process the message ASAP, before any other queued
3659 // messages.
3660 mH.sendMessageAtFrontOfQueue(m);
3661 }
3662 }
3663
3664 public void setAppWillBeHidden(IBinder token) {
3665 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3666 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003667 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 }
3669
3670 AppWindowToken wtoken;
3671
3672 synchronized(mWindowMap) {
3673 wtoken = findAppWindowToken(token);
3674 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003675 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 -08003676 return;
3677 }
3678 wtoken.willBeHidden = true;
3679 }
3680 }
Romain Guy06882f82009-06-10 13:36:04 -07003681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3683 boolean visible, int transit, boolean performLayout) {
3684 boolean delayed = false;
3685
3686 if (wtoken.clientHidden == visible) {
3687 wtoken.clientHidden = !visible;
3688 wtoken.sendAppVisibilityToClients();
3689 }
Romain Guy06882f82009-06-10 13:36:04 -07003690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 wtoken.willBeHidden = false;
3692 if (wtoken.hidden == visible) {
3693 final int N = wtoken.allAppWindows.size();
3694 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003695 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3697 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003700
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003701 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 if (wtoken.animation == sDummyAnimation) {
3703 wtoken.animation = null;
3704 }
3705 applyAnimationLocked(wtoken, lp, transit, visible);
3706 changed = true;
3707 if (wtoken.animation != null) {
3708 delayed = runningAppAnimation = true;
3709 }
3710 }
Romain Guy06882f82009-06-10 13:36:04 -07003711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 for (int i=0; i<N; i++) {
3713 WindowState win = wtoken.allAppWindows.get(i);
3714 if (win == wtoken.startingWindow) {
3715 continue;
3716 }
3717
3718 if (win.isAnimating()) {
3719 delayed = true;
3720 }
Romain Guy06882f82009-06-10 13:36:04 -07003721
Joe Onorato8a9b2202010-02-26 18:56:32 -08003722 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 //win.dump(" ");
3724 if (visible) {
3725 if (!win.isVisibleNow()) {
3726 if (!runningAppAnimation) {
3727 applyAnimationLocked(win,
3728 WindowManagerPolicy.TRANSIT_ENTER, true);
3729 }
3730 changed = true;
3731 }
3732 } else if (win.isVisibleNow()) {
3733 if (!runningAppAnimation) {
3734 applyAnimationLocked(win,
3735 WindowManagerPolicy.TRANSIT_EXIT, false);
3736 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 changed = true;
3738 }
3739 }
3740
3741 wtoken.hidden = wtoken.hiddenRequested = !visible;
3742 if (!visible) {
3743 unsetAppFreezingScreenLocked(wtoken, true, true);
3744 } else {
3745 // If we are being set visible, and the starting window is
3746 // not yet displayed, then make sure it doesn't get displayed.
3747 WindowState swin = wtoken.startingWindow;
3748 if (swin != null && (swin.mDrawPending
3749 || swin.mCommitDrawPending)) {
3750 swin.mPolicyVisibility = false;
3751 swin.mPolicyVisibilityAfterAnim = false;
3752 }
3753 }
Romain Guy06882f82009-06-10 13:36:04 -07003754
Joe Onorato8a9b2202010-02-26 18:56:32 -08003755 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3757 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003758
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003759 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08003761 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003762 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08003763 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3764 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003765 performLayoutAndPlaceSurfacesLocked();
3766 }
Jeff Brown2e44b072011-01-24 15:21:56 -08003767 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 }
3769 }
3770
3771 if (wtoken.animation != null) {
3772 delayed = true;
3773 }
Romain Guy06882f82009-06-10 13:36:04 -07003774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 return delayed;
3776 }
3777
3778 public void setAppVisibility(IBinder token, boolean visible) {
3779 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3780 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003781 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 }
3783
3784 AppWindowToken wtoken;
3785
3786 synchronized(mWindowMap) {
3787 wtoken = findAppWindowToken(token);
3788 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003789 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 return;
3791 }
3792
3793 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003794 RuntimeException e = null;
3795 if (!HIDE_STACK_CRAWLS) {
3796 e = new RuntimeException();
3797 e.fillInStackTrace();
3798 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003799 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 + "): mNextAppTransition=" + mNextAppTransition
3801 + " hidden=" + wtoken.hidden
3802 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3803 }
Romain Guy06882f82009-06-10 13:36:04 -07003804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 // If we are preparing an app transition, then delay changing
3806 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003807 if (!mDisplayFrozen && mPolicy.isScreenOn()
3808 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 // Already in requested state, don't do anything more.
3810 if (wtoken.hiddenRequested != visible) {
3811 return;
3812 }
3813 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003814
Joe Onorato8a9b2202010-02-26 18:56:32 -08003815 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 TAG, "Setting dummy animation on: " + wtoken);
3817 wtoken.setDummyAnimation();
3818 mOpeningApps.remove(wtoken);
3819 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003820 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 wtoken.inPendingTransaction = true;
3822 if (visible) {
3823 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 wtoken.startingDisplayed = false;
3825 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003826
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003827 // If the token is currently hidden (should be the
3828 // common case), then we need to set up to wait for
3829 // its windows to be ready.
3830 if (wtoken.hidden) {
3831 wtoken.allDrawn = false;
3832 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003833
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003834 if (wtoken.clientHidden) {
3835 // In the case where we are making an app visible
3836 // but holding off for a transition, we still need
3837 // to tell the client to make its windows visible so
3838 // they get drawn. Otherwise, we will wait on
3839 // performing the transition until all windows have
3840 // been drawn, they never will be, and we are sad.
3841 wtoken.clientHidden = false;
3842 wtoken.sendAppVisibilityToClients();
3843 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 }
3845 } else {
3846 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003847
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003848 // If the token is currently visible (should be the
3849 // common case), then set up to wait for it to be hidden.
3850 if (!wtoken.hidden) {
3851 wtoken.waitingToHide = true;
3852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 }
3854 return;
3855 }
Romain Guy06882f82009-06-10 13:36:04 -07003856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003858 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 wtoken.updateReportedVisibilityLocked();
3860 Binder.restoreCallingIdentity(origId);
3861 }
3862 }
3863
3864 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3865 boolean unfreezeSurfaceNow, boolean force) {
3866 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003867 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 + " force=" + force);
3869 final int N = wtoken.allAppWindows.size();
3870 boolean unfrozeWindows = false;
3871 for (int i=0; i<N; i++) {
3872 WindowState w = wtoken.allAppWindows.get(i);
3873 if (w.mAppFreezing) {
3874 w.mAppFreezing = false;
3875 if (w.mSurface != null && !w.mOrientationChanging) {
3876 w.mOrientationChanging = true;
3877 }
3878 unfrozeWindows = true;
3879 }
3880 }
3881 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003882 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 wtoken.freezingScreen = false;
3884 mAppsFreezingScreen--;
3885 }
3886 if (unfreezeSurfaceNow) {
3887 if (unfrozeWindows) {
3888 mLayoutNeeded = true;
3889 performLayoutAndPlaceSurfacesLocked();
3890 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003891 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003892 }
3893 }
3894 }
Romain Guy06882f82009-06-10 13:36:04 -07003895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3897 int configChanges) {
3898 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003899 RuntimeException e = null;
3900 if (!HIDE_STACK_CRAWLS) {
3901 e = new RuntimeException();
3902 e.fillInStackTrace();
3903 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003904 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003905 + ": hidden=" + wtoken.hidden + " freezing="
3906 + wtoken.freezingScreen, e);
3907 }
3908 if (!wtoken.hiddenRequested) {
3909 if (!wtoken.freezingScreen) {
3910 wtoken.freezingScreen = true;
3911 mAppsFreezingScreen++;
3912 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003913 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3915 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3916 5000);
3917 }
3918 }
3919 final int N = wtoken.allAppWindows.size();
3920 for (int i=0; i<N; i++) {
3921 WindowState w = wtoken.allAppWindows.get(i);
3922 w.mAppFreezing = true;
3923 }
3924 }
3925 }
Romain Guy06882f82009-06-10 13:36:04 -07003926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 public void startAppFreezingScreen(IBinder token, int configChanges) {
3928 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3929 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003930 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 }
3932
3933 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003934 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003935 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003936 return;
3937 }
Romain Guy06882f82009-06-10 13:36:04 -07003938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 AppWindowToken wtoken = findAppWindowToken(token);
3940 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003941 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003942 return;
3943 }
3944 final long origId = Binder.clearCallingIdentity();
3945 startAppFreezingScreenLocked(wtoken, configChanges);
3946 Binder.restoreCallingIdentity(origId);
3947 }
3948 }
Romain Guy06882f82009-06-10 13:36:04 -07003949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 public void stopAppFreezingScreen(IBinder token, boolean force) {
3951 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3952 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003953 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 }
3955
3956 synchronized(mWindowMap) {
3957 AppWindowToken wtoken = findAppWindowToken(token);
3958 if (wtoken == null || wtoken.appToken == null) {
3959 return;
3960 }
3961 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003962 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003963 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3964 unsetAppFreezingScreenLocked(wtoken, true, force);
3965 Binder.restoreCallingIdentity(origId);
3966 }
3967 }
Romain Guy06882f82009-06-10 13:36:04 -07003968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003969 public void removeAppToken(IBinder token) {
3970 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3971 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003972 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 }
3974
3975 AppWindowToken wtoken = null;
3976 AppWindowToken startingToken = null;
3977 boolean delayed = false;
3978
3979 final long origId = Binder.clearCallingIdentity();
3980 synchronized(mWindowMap) {
3981 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003983 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003984 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 wtoken.inPendingTransaction = false;
3986 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003987 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 if (mClosingApps.contains(wtoken)) {
3989 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003990 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003991 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003992 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 delayed = true;
3994 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003995 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 TAG, "Removing app " + wtoken + " delayed=" + delayed
3997 + " animation=" + wtoken.animation
3998 + " animating=" + wtoken.animating);
3999 if (delayed) {
4000 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004001 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4002 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004004 } else {
4005 // Make sure there is no animation running on this token,
4006 // so any windows associated with it will be removed as
4007 // soon as their animations are complete
4008 wtoken.animation = null;
4009 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004011 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4012 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 mAppTokens.remove(wtoken);
4014 wtoken.removed = true;
4015 if (wtoken.startingData != null) {
4016 startingToken = wtoken;
4017 }
4018 unsetAppFreezingScreenLocked(wtoken, true, true);
4019 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004020 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004021 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004022 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004023 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 }
4025 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004026 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004027 }
Romain Guy06882f82009-06-10 13:36:04 -07004028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 if (!delayed && wtoken != null) {
4030 wtoken.updateReportedVisibilityLocked();
4031 }
4032 }
4033 Binder.restoreCallingIdentity(origId);
4034
4035 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004036 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004037 + startingToken + ": app token removed");
4038 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4039 mH.sendMessage(m);
4040 }
4041 }
4042
4043 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4044 final int NW = token.windows.size();
4045 for (int i=0; i<NW; i++) {
4046 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004047 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004048 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004049 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050 int j = win.mChildWindows.size();
4051 while (j > 0) {
4052 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004053 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004054 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004055 "Tmp removing child window " + cwin);
4056 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004057 }
4058 }
4059 return NW > 0;
4060 }
4061
4062 void dumpAppTokensLocked() {
4063 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004064 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004065 }
4066 }
Romain Guy06882f82009-06-10 13:36:04 -07004067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 void dumpWindowsLocked() {
4069 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004070 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004071 }
4072 }
Romain Guy06882f82009-06-10 13:36:04 -07004073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004074 private int findWindowOffsetLocked(int tokenPos) {
4075 final int NW = mWindows.size();
4076
4077 if (tokenPos >= mAppTokens.size()) {
4078 int i = NW;
4079 while (i > 0) {
4080 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004081 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 if (win.getAppToken() != null) {
4083 return i+1;
4084 }
4085 }
4086 }
4087
4088 while (tokenPos > 0) {
4089 // Find the first app token below the new position that has
4090 // a window displayed.
4091 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004092 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004094 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004095 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004096 "Skipping token -- currently sending to bottom");
4097 tokenPos--;
4098 continue;
4099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 int i = wtoken.windows.size();
4101 while (i > 0) {
4102 i--;
4103 WindowState win = wtoken.windows.get(i);
4104 int j = win.mChildWindows.size();
4105 while (j > 0) {
4106 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004107 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004108 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004109 for (int pos=NW-1; pos>=0; pos--) {
4110 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004111 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 "Found child win @" + (pos+1));
4113 return pos+1;
4114 }
4115 }
4116 }
4117 }
4118 for (int pos=NW-1; pos>=0; pos--) {
4119 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004120 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004121 return pos+1;
4122 }
4123 }
4124 }
4125 tokenPos--;
4126 }
4127
4128 return 0;
4129 }
4130
4131 private final int reAddWindowLocked(int index, WindowState win) {
4132 final int NCW = win.mChildWindows.size();
4133 boolean added = false;
4134 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004135 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004137 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004138 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004139 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 mWindows.add(index, win);
4141 index++;
4142 added = true;
4143 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004144 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004145 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004146 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147 mWindows.add(index, cwin);
4148 index++;
4149 }
4150 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004151 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004152 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004153 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004154 mWindows.add(index, win);
4155 index++;
4156 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004157 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 return index;
4159 }
Romain Guy06882f82009-06-10 13:36:04 -07004160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4162 final int NW = token.windows.size();
4163 for (int i=0; i<NW; i++) {
4164 index = reAddWindowLocked(index, token.windows.get(i));
4165 }
4166 return index;
4167 }
4168
4169 public void moveAppToken(int index, IBinder token) {
4170 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4171 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004172 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 }
4174
4175 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004176 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 if (DEBUG_REORDER) dumpAppTokensLocked();
4178 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004179 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4180 "Start moving token " + wtoken + " initially at "
4181 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004183 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 + token + " (" + wtoken + ")");
4185 return;
4186 }
4187 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004188 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004189 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004193 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 if (DEBUG_REORDER) dumpWindowsLocked();
4195 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004196 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 if (DEBUG_REORDER) dumpWindowsLocked();
4198 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004199 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004201 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4202 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004203 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004204 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004206 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 }
4208 Binder.restoreCallingIdentity(origId);
4209 }
4210 }
4211
4212 private void removeAppTokensLocked(List<IBinder> tokens) {
4213 // XXX This should be done more efficiently!
4214 // (take advantage of the fact that both lists should be
4215 // ordered in the same way.)
4216 int N = tokens.size();
4217 for (int i=0; i<N; i++) {
4218 IBinder token = tokens.get(i);
4219 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004220 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4221 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004223 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004224 + token + " (" + wtoken + ")");
4225 i--;
4226 N--;
4227 }
4228 }
4229 }
4230
Dianne Hackborna8f60182009-09-01 19:01:50 -07004231 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4232 boolean updateFocusAndLayout) {
4233 // First remove all of the windows from the list.
4234 tmpRemoveAppWindowsLocked(wtoken);
4235
4236 // Where to start adding?
4237 int pos = findWindowOffsetLocked(tokenPos);
4238
4239 // And now add them back at the correct place.
4240 pos = reAddAppWindowsLocked(pos, wtoken);
4241
4242 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004243 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004244 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4245 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004246 assignLayersLocked();
4247 }
4248 mLayoutNeeded = true;
4249 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004250 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004251 }
4252 }
4253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4255 // First remove all of the windows from the list.
4256 final int N = tokens.size();
4257 int i;
4258 for (i=0; i<N; i++) {
4259 WindowToken token = mTokenMap.get(tokens.get(i));
4260 if (token != null) {
4261 tmpRemoveAppWindowsLocked(token);
4262 }
4263 }
4264
4265 // Where to start adding?
4266 int pos = findWindowOffsetLocked(tokenPos);
4267
4268 // And now add them back at the correct place.
4269 for (i=0; i<N; i++) {
4270 WindowToken token = mTokenMap.get(tokens.get(i));
4271 if (token != null) {
4272 pos = reAddAppWindowsLocked(pos, token);
4273 }
4274 }
4275
Jeff Brown2e44b072011-01-24 15:21:56 -08004276 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004277 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4278 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004279 assignLayersLocked();
4280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 mLayoutNeeded = true;
4282 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004283 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284
4285 //dump();
4286 }
4287
4288 public void moveAppTokensToTop(List<IBinder> tokens) {
4289 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4290 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004291 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 }
4293
4294 final long origId = Binder.clearCallingIdentity();
4295 synchronized(mWindowMap) {
4296 removeAppTokensLocked(tokens);
4297 final int N = tokens.size();
4298 for (int i=0; i<N; i++) {
4299 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4300 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004301 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4302 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004304 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004305 mToTopApps.remove(wt);
4306 mToBottomApps.remove(wt);
4307 mToTopApps.add(wt);
4308 wt.sendingToBottom = false;
4309 wt.sendingToTop = true;
4310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 }
4312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004313
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004314 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004315 moveAppWindowsLocked(tokens, mAppTokens.size());
4316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
4318 Binder.restoreCallingIdentity(origId);
4319 }
4320
4321 public void moveAppTokensToBottom(List<IBinder> tokens) {
4322 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4323 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004324 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
4326
4327 final long origId = Binder.clearCallingIdentity();
4328 synchronized(mWindowMap) {
4329 removeAppTokensLocked(tokens);
4330 final int N = tokens.size();
4331 int pos = 0;
4332 for (int i=0; i<N; i++) {
4333 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4334 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004335 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4336 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004338 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004339 mToTopApps.remove(wt);
4340 mToBottomApps.remove(wt);
4341 mToBottomApps.add(i, wt);
4342 wt.sendingToTop = false;
4343 wt.sendingToBottom = true;
4344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 pos++;
4346 }
4347 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004348
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004349 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004350 moveAppWindowsLocked(tokens, 0);
4351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 }
4353 Binder.restoreCallingIdentity(origId);
4354 }
4355
4356 // -------------------------------------------------------------
4357 // Misc IWindowSession methods
4358 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004359
Jim Miller284b62e2010-06-08 14:27:42 -07004360 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004361 {
Jim Miller284b62e2010-06-08 14:27:42 -07004362 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4363 // called before DevicePolicyManagerService has started.
4364 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4365 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4366 Context.DEVICE_POLICY_SERVICE);
4367 if (dpm != null) {
4368 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4369 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4370 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4371 }
Jim Millerd6b57052010-06-07 17:52:42 -07004372 }
Jim Miller284b62e2010-06-08 14:27:42 -07004373 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004374 }
4375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004377 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 != PackageManager.PERMISSION_GRANTED) {
4379 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4380 }
Jim Millerd6b57052010-06-07 17:52:42 -07004381
Jim Miller284b62e2010-06-08 14:27:42 -07004382 synchronized (mKeyguardTokenWatcher) {
4383 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 }
4386
4387 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004388 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 != PackageManager.PERMISSION_GRANTED) {
4390 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004392
Jim Miller284b62e2010-06-08 14:27:42 -07004393 synchronized (mKeyguardTokenWatcher) {
4394 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004395
Jim Miller284b62e2010-06-08 14:27:42 -07004396 if (!mKeyguardTokenWatcher.isAcquired()) {
4397 // If we are the last one to reenable the keyguard wait until
4398 // we have actually finished reenabling until returning.
4399 // It is possible that reenableKeyguard() can be called before
4400 // the previous disableKeyguard() is handled, in which case
4401 // neither mKeyguardTokenWatcher.acquired() or released() would
4402 // be called. In that case mKeyguardDisabled will be false here
4403 // and we have nothing to wait for.
4404 while (mKeyguardDisabled) {
4405 try {
4406 mKeyguardTokenWatcher.wait();
4407 } catch (InterruptedException e) {
4408 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 }
4410 }
4411 }
4412 }
4413 }
4414
4415 /**
4416 * @see android.app.KeyguardManager#exitKeyguardSecurely
4417 */
4418 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004419 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 != PackageManager.PERMISSION_GRANTED) {
4421 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4422 }
4423 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4424 public void onKeyguardExitResult(boolean success) {
4425 try {
4426 callback.onKeyguardExitResult(success);
4427 } catch (RemoteException e) {
4428 // Client has died, we don't care.
4429 }
4430 }
4431 });
4432 }
4433
4434 public boolean inKeyguardRestrictedInputMode() {
4435 return mPolicy.inKeyguardRestrictedKeyInputMode();
4436 }
Romain Guy06882f82009-06-10 13:36:04 -07004437
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004438 public boolean isKeyguardLocked() {
4439 return mPolicy.isKeyguardLocked();
4440 }
4441
4442 public boolean isKeyguardSecure() {
4443 return mPolicy.isKeyguardSecure();
4444 }
4445
Dianne Hackbornffa42482009-09-23 22:20:11 -07004446 public void closeSystemDialogs(String reason) {
4447 synchronized(mWindowMap) {
4448 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004449 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004450 if (w.mSurface != null) {
4451 try {
4452 w.mClient.closeSystemDialogs(reason);
4453 } catch (RemoteException e) {
4454 }
4455 }
4456 }
4457 }
4458 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004460 static float fixScale(float scale) {
4461 if (scale < 0) scale = 0;
4462 else if (scale > 20) scale = 20;
4463 return Math.abs(scale);
4464 }
Romain Guy06882f82009-06-10 13:36:04 -07004465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 public void setAnimationScale(int which, float scale) {
4467 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4468 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004469 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 }
4471
4472 if (scale < 0) scale = 0;
4473 else if (scale > 20) scale = 20;
4474 scale = Math.abs(scale);
4475 switch (which) {
4476 case 0: mWindowAnimationScale = fixScale(scale); break;
4477 case 1: mTransitionAnimationScale = fixScale(scale); break;
4478 }
Romain Guy06882f82009-06-10 13:36:04 -07004479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 // Persist setting
4481 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4482 }
Romain Guy06882f82009-06-10 13:36:04 -07004483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 public void setAnimationScales(float[] scales) {
4485 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4486 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004487 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 }
4489
4490 if (scales != null) {
4491 if (scales.length >= 1) {
4492 mWindowAnimationScale = fixScale(scales[0]);
4493 }
4494 if (scales.length >= 2) {
4495 mTransitionAnimationScale = fixScale(scales[1]);
4496 }
4497 }
Romain Guy06882f82009-06-10 13:36:04 -07004498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 // Persist setting
4500 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4501 }
Romain Guy06882f82009-06-10 13:36:04 -07004502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004503 public float getAnimationScale(int which) {
4504 switch (which) {
4505 case 0: return mWindowAnimationScale;
4506 case 1: return mTransitionAnimationScale;
4507 }
4508 return 0;
4509 }
Romain Guy06882f82009-06-10 13:36:04 -07004510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 public float[] getAnimationScales() {
4512 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4513 }
Romain Guy06882f82009-06-10 13:36:04 -07004514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 public int getSwitchState(int sw) {
4516 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4517 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004518 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004520 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 }
Romain Guy06882f82009-06-10 13:36:04 -07004522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 public int getSwitchStateForDevice(int devid, int sw) {
4524 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4525 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004526 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004528 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 }
Romain Guy06882f82009-06-10 13:36:04 -07004530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 public int getScancodeState(int sw) {
4532 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4533 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004534 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004536 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004537 }
Romain Guy06882f82009-06-10 13:36:04 -07004538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004539 public int getScancodeStateForDevice(int devid, int sw) {
4540 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4541 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004542 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004544 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004545 }
Romain Guy06882f82009-06-10 13:36:04 -07004546
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004547 public int getTrackballScancodeState(int sw) {
4548 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4549 "getTrackballScancodeState()")) {
4550 throw new SecurityException("Requires READ_INPUT_STATE permission");
4551 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004552 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004553 }
4554
4555 public int getDPadScancodeState(int sw) {
4556 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4557 "getDPadScancodeState()")) {
4558 throw new SecurityException("Requires READ_INPUT_STATE permission");
4559 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004560 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004561 }
4562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004563 public int getKeycodeState(int sw) {
4564 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4565 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004566 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004567 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004568 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004569 }
Romain Guy06882f82009-06-10 13:36:04 -07004570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 public int getKeycodeStateForDevice(int devid, int sw) {
4572 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4573 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004574 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004575 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004576 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004577 }
Romain Guy06882f82009-06-10 13:36:04 -07004578
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004579 public int getTrackballKeycodeState(int sw) {
4580 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4581 "getTrackballKeycodeState()")) {
4582 throw new SecurityException("Requires READ_INPUT_STATE permission");
4583 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004584 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004585 }
4586
4587 public int getDPadKeycodeState(int sw) {
4588 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4589 "getDPadKeycodeState()")) {
4590 throw new SecurityException("Requires READ_INPUT_STATE permission");
4591 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004592 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004593 }
Jeff Browna41ca772010-08-11 14:46:32 -07004594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004595 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004596 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004597 }
Romain Guy06882f82009-06-10 13:36:04 -07004598
Jeff Browna41ca772010-08-11 14:46:32 -07004599 public InputChannel monitorInput(String inputChannelName) {
4600 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4601 "monitorInput()")) {
4602 throw new SecurityException("Requires READ_INPUT_STATE permission");
4603 }
4604 return mInputManager.monitorInput(inputChannelName);
4605 }
4606
Jeff Brown0029c662011-03-30 02:25:18 -07004607 public void setInputFilter(InputFilter filter) {
4608 mInputManager.setInputFilter(filter);
4609 }
4610
Jeff Brown8d608662010-08-30 03:02:23 -07004611 public InputDevice getInputDevice(int deviceId) {
4612 return mInputManager.getInputDevice(deviceId);
4613 }
4614
4615 public int[] getInputDeviceIds() {
4616 return mInputManager.getInputDeviceIds();
4617 }
4618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004619 public void enableScreenAfterBoot() {
4620 synchronized(mWindowMap) {
4621 if (mSystemBooted) {
4622 return;
4623 }
4624 mSystemBooted = true;
4625 }
Romain Guy06882f82009-06-10 13:36:04 -07004626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004627 performEnableScreen();
4628 }
Romain Guy06882f82009-06-10 13:36:04 -07004629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 public void enableScreenIfNeededLocked() {
4631 if (mDisplayEnabled) {
4632 return;
4633 }
4634 if (!mSystemBooted) {
4635 return;
4636 }
4637 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4638 }
Romain Guy06882f82009-06-10 13:36:04 -07004639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 public void performEnableScreen() {
4641 synchronized(mWindowMap) {
4642 if (mDisplayEnabled) {
4643 return;
4644 }
4645 if (!mSystemBooted) {
4646 return;
4647 }
Romain Guy06882f82009-06-10 13:36:04 -07004648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004649 // Don't enable the screen until all existing windows
4650 // have been drawn.
4651 final int N = mWindows.size();
4652 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004653 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004654 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004655 return;
4656 }
4657 }
Romain Guy06882f82009-06-10 13:36:04 -07004658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 mDisplayEnabled = true;
4660 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004661 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662 StringWriter sw = new StringWriter();
4663 PrintWriter pw = new PrintWriter(sw);
4664 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004665 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 }
4667 try {
4668 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4669 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004670 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004671 Parcel data = Parcel.obtain();
4672 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4673 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4674 data, null, 0);
4675 data.recycle();
4676 }
4677 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004678 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679 }
4680 }
Romain Guy06882f82009-06-10 13:36:04 -07004681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004685 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4686 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004687 }
Romain Guy06882f82009-06-10 13:36:04 -07004688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 public void setInTouchMode(boolean mode) {
4690 synchronized(mWindowMap) {
4691 mInTouchMode = mode;
4692 }
4693 }
4694
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004695 // TODO: more accounting of which pid(s) turned it on, keep count,
4696 // only allow disables from pids which have count on, etc.
4697 public void showStrictModeViolation(boolean on) {
4698 int pid = Binder.getCallingPid();
4699 synchronized(mWindowMap) {
4700 // Ignoring requests to enable the red border from clients
4701 // which aren't on screen. (e.g. Broadcast Receivers in
4702 // the background..)
4703 if (on) {
4704 boolean isVisible = false;
4705 for (WindowState ws : mWindows) {
4706 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4707 isVisible = true;
4708 break;
4709 }
4710 }
4711 if (!isVisible) {
4712 return;
4713 }
4714 }
4715
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004716 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004717 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004718 try {
4719 if (mStrictModeFlash == null) {
4720 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4721 }
4722 mStrictModeFlash.setVisibility(on);
4723 } finally {
4724 Surface.closeTransaction();
4725 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004726 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004727 }
4728 }
4729
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004730 public void setStrictModeVisualIndicatorPreference(String value) {
4731 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4732 }
4733
Jim Millere70d5062011-03-08 21:38:39 -08004734 /**
4735 * Takes a snapshot of the screen. In landscape mode this grabs the whole screen.
4736 * In portrait mode, it grabs the upper region of the screen based on the vertical dimension
4737 * of the target image.
4738 *
4739 * @param width the width of the target bitmap
4740 * @param height the height of the target bitmap
4741 */
4742 public Bitmap screenshotApplications(IBinder appToken, int width, int height) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004743 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4744 "screenshotApplications()")) {
4745 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
4746 }
4747
4748 Bitmap rawss;
4749
Dianne Hackbornd2835932010-12-13 16:28:46 -08004750 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004751 final Rect frame = new Rect();
4752
4753 float scale;
Jim Millere70d5062011-03-08 21:38:39 -08004754 int dw, dh;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004755 int rot;
4756
4757 synchronized(mWindowMap) {
4758 long ident = Binder.clearCallingIdentity();
4759
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004760 dw = mDisplay.getWidth();
4761 dh = mDisplay.getHeight();
4762
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004763 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
4764 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
4765 + TYPE_LAYER_OFFSET;
4766 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
4767
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004768 boolean isImeTarget = mInputMethodTarget != null
4769 && mInputMethodTarget.mAppToken != null
4770 && mInputMethodTarget.mAppToken.appToken != null
4771 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
4772
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004773 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004774 boolean including = false;
4775 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004776 WindowState ws = mWindows.get(i);
4777 if (ws.mSurface == null) {
4778 continue;
4779 }
4780 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08004781 continue;
4782 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004783 // When we will skip windows: when we are not including
4784 // ones behind a window we didn't skip, and we are actually
4785 // taking a screenshot of a specific app.
4786 if (!including && appToken != null) {
4787 // Also, we can possibly skip this window if it is not
4788 // an IME target or the application for the screenshot
4789 // is not the current IME target.
4790 if (!ws.mIsImWindow || !isImeTarget) {
4791 // And finally, this window is of no interest if it
4792 // is not associated with the screenshot app.
4793 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
4794 continue;
4795 }
4796 }
4797 }
4798
4799 // We keep on including windows until we go past a full-screen
4800 // window.
4801 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
4802
Dianne Hackbornd2835932010-12-13 16:28:46 -08004803 if (maxLayer < ws.mAnimLayer) {
4804 maxLayer = ws.mAnimLayer;
4805 }
Jim Miller2aded182011-03-08 15:32:42 -08004806
4807 // Don't include wallpaper in bounds calculation
4808 if (!ws.mIsWallpaper) {
4809 final Rect wf = ws.mFrame;
4810 final Rect cr = ws.mContentInsets;
4811 int left = wf.left + cr.left;
4812 int top = wf.top + cr.top;
4813 int right = wf.right - cr.right;
4814 int bottom = wf.bottom - cr.bottom;
4815 frame.union(left, top, right, bottom);
4816 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004817 }
4818 Binder.restoreCallingIdentity(ident);
4819
Dianne Hackborndd962ee2011-02-02 11:11:50 -08004820 // Constrain frame to the screen size.
4821 frame.intersect(0, 0, dw, dh);
Jim Millere70d5062011-03-08 21:38:39 -08004822
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004823 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004824 return null;
4825 }
4826
4827 // The screenshot API does not apply the current screen rotation.
4828 rot = mDisplay.getRotation();
4829 int fw = frame.width();
4830 int fh = frame.height();
4831
4832 // First try reducing to fit in x dimension.
Jim Millere70d5062011-03-08 21:38:39 -08004833 scale = width/(float)fw;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004834
4835 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08004836 dw = (int)(dw*scale);
4837 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004838 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
4839 int tmp = dw;
4840 dw = dh;
4841 dh = tmp;
4842 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
4843 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08004844 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004845 }
4846
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004847 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08004848 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
4849 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004850 return null;
4851 }
Jim Millere70d5062011-03-08 21:38:39 -08004852
4853 Bitmap bm = Bitmap.createBitmap(width, height, rawss.getConfig());
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004854 Matrix matrix = new Matrix();
4855 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
4856 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
4857 Canvas canvas = new Canvas(bm);
4858 canvas.drawBitmap(rawss, matrix, null);
4859
4860 rawss.recycle();
4861 return bm;
4862 }
4863
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004864 public void freezeRotation() {
4865 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004866 "freezeRotation()")) {
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004867 throw new SecurityException("Requires SET_ORIENTATION permission");
4868 }
4869
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004870 if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation);
4871
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004872 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4873 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4874 }
4875
4876 public void thawRotation() {
4877 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004878 "thawRotation()")) {
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004879 throw new SecurityException("Requires SET_ORIENTATION permission");
4880 }
4881
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004882 if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation);
4883
4884 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 777); // rot not used
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004885 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4886 }
4887
Romain Guy06882f82009-06-10 13:36:04 -07004888 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004889 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004890 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004891 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004892 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004893 }
4894
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004895 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004896 }
Romain Guy06882f82009-06-10 13:36:04 -07004897
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004898 public void setRotationUnchecked(int rotation,
4899 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004900 if(DEBUG_ORIENTATION) Slog.v(TAG,
David 'Digit' Turner910a0682011-02-05 00:34:46 +01004901 "setRotationUnchecked(rotation=" + rotation +
4902 " alwaysSendConfiguration=" + alwaysSendConfiguration +
4903 " animFlags=" + animFlags);
Romain Guy06882f82009-06-10 13:36:04 -07004904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004905 long origId = Binder.clearCallingIdentity();
4906 boolean changed;
4907 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004908 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004909 }
Romain Guy06882f82009-06-10 13:36:04 -07004910
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004911 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004912 sendNewConfiguration();
4913 }
Romain Guy06882f82009-06-10 13:36:04 -07004914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 Binder.restoreCallingIdentity(origId);
4916 }
Romain Guy06882f82009-06-10 13:36:04 -07004917
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004918 /**
4919 * Apply a new rotation to the screen, respecting the requests of
4920 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4921 * re-evaluate the desired rotation.
4922 *
4923 * Returns null if the rotation has been changed. In this case YOU
4924 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4925 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004926 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004927 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08004928 // Potential rotation during a drag. Don't do the rotation now, but make
4929 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004930 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
4931 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
4932 mDeferredRotation = rotation;
4933 mDeferredRotationAnimFlags = animFlags;
4934 }
Christopher Tateccd24de2011-01-12 15:02:55 -08004935 return false;
4936 }
4937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004938 boolean changed;
4939 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004940 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
4941 rotation = mDeferredRotation;
4942 mRequestedRotation = rotation;
4943 mLastRotationFlags = mDeferredRotationAnimFlags;
4944 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 rotation = mRequestedRotation;
4946 } else {
4947 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004948 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08004950 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08004951 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004952 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004954 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004957 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004958 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 "Rotation changed to " + rotation
4960 + " from " + mRotation
4961 + " (forceApp=" + mForcedAppOrientation
4962 + ", req=" + mRequestedRotation + ")");
4963 mRotation = rotation;
4964 mWindowsFreezingScreen = true;
4965 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4966 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4967 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004968 mWaitingForConfig = true;
4969 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004970 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004971 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004972 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004973 if (mDisplayEnabled) {
David 'Digit' Turner910a0682011-02-05 00:34:46 +01004974 // NOTE: We disable the rotation in the emulator because
4975 // it doesn't support hardware OpenGL emulation yet.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08004976 if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
4977 && mScreenRotationAnimation.hasScreenshot()) {
Dianne Hackborna1111872010-11-23 20:55:11 -08004978 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004979 if (!inTransaction) {
4980 if (SHOW_TRANSACTIONS) Slog.i(TAG,
4981 ">>> OPEN TRANSACTION setRotationUnchecked");
4982 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08004983 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004984 try {
4985 if (mScreenRotationAnimation != null) {
4986 mScreenRotationAnimation.setRotation(rotation);
4987 }
4988 } finally {
4989 if (!inTransaction) {
4990 Surface.closeTransaction();
4991 if (SHOW_TRANSACTIONS) Slog.i(TAG,
4992 "<<< CLOSE TRANSACTION setRotationUnchecked");
4993 }
4994 }
Dianne Hackborna1111872010-11-23 20:55:11 -08004995 Surface.setOrientation(0, rotation, animFlags);
4996 Surface.unfreezeDisplay(0);
4997 } else {
4998 Surface.setOrientation(0, rotation, animFlags);
4999 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005000 }
5001 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005002 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005003 if (w.mSurface != null) {
5004 w.mOrientationChanging = true;
5005 }
5006 }
5007 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5008 try {
5009 mRotationWatchers.get(i).onRotationChanged(rotation);
5010 } catch (RemoteException e) {
5011 }
5012 }
5013 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005015 return changed;
5016 }
Romain Guy06882f82009-06-10 13:36:04 -07005017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005018 public int getRotation() {
5019 return mRotation;
5020 }
5021
5022 public int watchRotation(IRotationWatcher watcher) {
5023 final IBinder watcherBinder = watcher.asBinder();
5024 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5025 public void binderDied() {
5026 synchronized (mWindowMap) {
5027 for (int i=0; i<mRotationWatchers.size(); i++) {
5028 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005029 IRotationWatcher removed = mRotationWatchers.remove(i);
5030 if (removed != null) {
5031 removed.asBinder().unlinkToDeath(this, 0);
5032 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 i--;
5034 }
5035 }
5036 }
5037 }
5038 };
Romain Guy06882f82009-06-10 13:36:04 -07005039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005040 synchronized (mWindowMap) {
5041 try {
5042 watcher.asBinder().linkToDeath(dr, 0);
5043 mRotationWatchers.add(watcher);
5044 } catch (RemoteException e) {
5045 // Client died, no cleanup needed.
5046 }
Romain Guy06882f82009-06-10 13:36:04 -07005047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005048 return mRotation;
5049 }
5050 }
5051
5052 /**
5053 * Starts the view server on the specified port.
5054 *
5055 * @param port The port to listener to.
5056 *
5057 * @return True if the server was successfully started, false otherwise.
5058 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005059 * @see com.android.server.wm.ViewServer
5060 * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005061 */
5062 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005063 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005064 return false;
5065 }
5066
5067 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5068 return false;
5069 }
5070
5071 if (port < 1024) {
5072 return false;
5073 }
5074
5075 if (mViewServer != null) {
5076 if (!mViewServer.isRunning()) {
5077 try {
5078 return mViewServer.start();
5079 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005080 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005081 }
5082 }
5083 return false;
5084 }
5085
5086 try {
5087 mViewServer = new ViewServer(this, port);
5088 return mViewServer.start();
5089 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005090 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005091 }
5092 return false;
5093 }
5094
Romain Guy06882f82009-06-10 13:36:04 -07005095 private boolean isSystemSecure() {
5096 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5097 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5098 }
5099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005100 /**
5101 * Stops the view server if it exists.
5102 *
5103 * @return True if the server stopped, false if it wasn't started or
5104 * couldn't be stopped.
5105 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005106 * @see com.android.server.wm.ViewServer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005107 */
5108 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005109 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005110 return false;
5111 }
5112
5113 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5114 return false;
5115 }
5116
5117 if (mViewServer != null) {
5118 return mViewServer.stop();
5119 }
5120 return false;
5121 }
5122
5123 /**
5124 * Indicates whether the view server is running.
5125 *
5126 * @return True if the server is running, false otherwise.
5127 *
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08005128 * @see com.android.server.wm.ViewServer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005129 */
5130 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005131 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005132 return false;
5133 }
5134
5135 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5136 return false;
5137 }
5138
5139 return mViewServer != null && mViewServer.isRunning();
5140 }
5141
5142 /**
5143 * Lists all availble windows in the system. The listing is written in the
5144 * specified Socket's output stream with the following syntax:
5145 * windowHashCodeInHexadecimal windowName
5146 * Each line of the ouput represents a different window.
5147 *
5148 * @param client The remote client to send the listing to.
5149 * @return False if an error occured, true otherwise.
5150 */
5151 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005152 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005153 return false;
5154 }
5155
5156 boolean result = true;
5157
Jeff Browne33348b2010-07-15 23:54:05 -07005158 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005159 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005160 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005161 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005162 }
5163
5164 BufferedWriter out = null;
5165
5166 // Any uncaught exception will crash the system process
5167 try {
5168 OutputStream clientStream = client.getOutputStream();
5169 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5170
5171 final int count = windows.length;
5172 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005173 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005174 out.write(Integer.toHexString(System.identityHashCode(w)));
5175 out.write(' ');
5176 out.append(w.mAttrs.getTitle());
5177 out.write('\n');
5178 }
5179
5180 out.write("DONE.\n");
5181 out.flush();
5182 } catch (Exception e) {
5183 result = false;
5184 } finally {
5185 if (out != null) {
5186 try {
5187 out.close();
5188 } catch (IOException e) {
5189 result = false;
5190 }
5191 }
5192 }
5193
5194 return result;
5195 }
5196
5197 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005198 * Returns the focused window in the following format:
5199 * windowHashCodeInHexadecimal windowName
5200 *
5201 * @param client The remote client to send the listing to.
5202 * @return False if an error occurred, true otherwise.
5203 */
5204 boolean viewServerGetFocusedWindow(Socket client) {
5205 if (isSystemSecure()) {
5206 return false;
5207 }
5208
5209 boolean result = true;
5210
5211 WindowState focusedWindow = getFocusedWindow();
5212
5213 BufferedWriter out = null;
5214
5215 // Any uncaught exception will crash the system process
5216 try {
5217 OutputStream clientStream = client.getOutputStream();
5218 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5219
5220 if(focusedWindow != null) {
5221 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5222 out.write(' ');
5223 out.append(focusedWindow.mAttrs.getTitle());
5224 }
5225 out.write('\n');
5226 out.flush();
5227 } catch (Exception e) {
5228 result = false;
5229 } finally {
5230 if (out != null) {
5231 try {
5232 out.close();
5233 } catch (IOException e) {
5234 result = false;
5235 }
5236 }
5237 }
5238
5239 return result;
5240 }
5241
5242 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005243 * Sends a command to a target window. The result of the command, if any, will be
5244 * written in the output stream of the specified socket.
5245 *
5246 * The parameters must follow this syntax:
5247 * windowHashcode extra
5248 *
5249 * Where XX is the length in characeters of the windowTitle.
5250 *
5251 * The first parameter is the target window. The window with the specified hashcode
5252 * will be the target. If no target can be found, nothing happens. The extra parameters
5253 * will be delivered to the target window and as parameters to the command itself.
5254 *
5255 * @param client The remote client to sent the result, if any, to.
5256 * @param command The command to execute.
5257 * @param parameters The command parameters.
5258 *
5259 * @return True if the command was successfully delivered, false otherwise. This does
5260 * not indicate whether the command itself was successful.
5261 */
5262 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005263 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005264 return false;
5265 }
5266
5267 boolean success = true;
5268 Parcel data = null;
5269 Parcel reply = null;
5270
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005271 BufferedWriter out = null;
5272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005273 // Any uncaught exception will crash the system process
5274 try {
5275 // Find the hashcode of the window
5276 int index = parameters.indexOf(' ');
5277 if (index == -1) {
5278 index = parameters.length();
5279 }
5280 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005281 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005282
5283 // Extract the command's parameter after the window description
5284 if (index < parameters.length()) {
5285 parameters = parameters.substring(index + 1);
5286 } else {
5287 parameters = "";
5288 }
5289
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005290 final WindowState window = findWindow(hashCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291 if (window == null) {
5292 return false;
5293 }
5294
5295 data = Parcel.obtain();
5296 data.writeInterfaceToken("android.view.IWindow");
5297 data.writeString(command);
5298 data.writeString(parameters);
5299 data.writeInt(1);
5300 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5301
5302 reply = Parcel.obtain();
5303
5304 final IBinder binder = window.mClient.asBinder();
5305 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5306 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5307
5308 reply.readException();
5309
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005310 if (!client.isOutputShutdown()) {
5311 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5312 out.write("DONE\n");
5313 out.flush();
5314 }
5315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005316 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005317 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005318 success = false;
5319 } finally {
5320 if (data != null) {
5321 data.recycle();
5322 }
5323 if (reply != null) {
5324 reply.recycle();
5325 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005326 if (out != null) {
5327 try {
5328 out.close();
5329 } catch (IOException e) {
5330
5331 }
5332 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005333 }
5334
5335 return success;
5336 }
5337
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005338 public void addWindowChangeListener(WindowChangeListener listener) {
5339 synchronized(mWindowMap) {
5340 mWindowChangeListeners.add(listener);
5341 }
5342 }
5343
5344 public void removeWindowChangeListener(WindowChangeListener listener) {
5345 synchronized(mWindowMap) {
5346 mWindowChangeListeners.remove(listener);
5347 }
5348 }
5349
5350 private void notifyWindowsChanged() {
5351 WindowChangeListener[] windowChangeListeners;
5352 synchronized(mWindowMap) {
5353 if(mWindowChangeListeners.isEmpty()) {
5354 return;
5355 }
5356 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5357 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5358 }
5359 int N = windowChangeListeners.length;
5360 for(int i = 0; i < N; i++) {
5361 windowChangeListeners[i].windowsChanged();
5362 }
5363 }
5364
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005365 private void notifyFocusChanged() {
5366 WindowChangeListener[] windowChangeListeners;
5367 synchronized(mWindowMap) {
5368 if(mWindowChangeListeners.isEmpty()) {
5369 return;
5370 }
5371 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5372 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5373 }
5374 int N = windowChangeListeners.length;
5375 for(int i = 0; i < N; i++) {
5376 windowChangeListeners[i].focusChanged();
5377 }
5378 }
5379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 private WindowState findWindow(int hashCode) {
5381 if (hashCode == -1) {
5382 return getFocusedWindow();
5383 }
5384
5385 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005386 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005387 final int count = windows.size();
5388
5389 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005390 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005391 if (System.identityHashCode(w) == hashCode) {
5392 return w;
5393 }
5394 }
5395 }
5396
5397 return null;
5398 }
5399
5400 /*
5401 * Instruct the Activity Manager to fetch the current configuration and broadcast
5402 * that to config-changed listeners if appropriate.
5403 */
5404 void sendNewConfiguration() {
5405 try {
5406 mActivityManager.updateConfiguration(null);
5407 } catch (RemoteException e) {
5408 }
5409 }
Romain Guy06882f82009-06-10 13:36:04 -07005410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005411 public Configuration computeNewConfiguration() {
5412 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005413 Configuration config = computeNewConfigurationLocked();
5414 if (config == null && mWaitingForConfig) {
5415 // Nothing changed but we are waiting for something... stop that!
5416 mWaitingForConfig = false;
5417 performLayoutAndPlaceSurfacesLocked();
5418 }
5419 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005420 }
5421 }
Romain Guy06882f82009-06-10 13:36:04 -07005422
Dianne Hackbornc485a602009-03-24 22:39:49 -07005423 Configuration computeNewConfigurationLocked() {
5424 Configuration config = new Configuration();
5425 if (!computeNewConfigurationLocked(config)) {
5426 return null;
5427 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005428 return config;
5429 }
Romain Guy06882f82009-06-10 13:36:04 -07005430
Dianne Hackbornc485a602009-03-24 22:39:49 -07005431 boolean computeNewConfigurationLocked(Configuration config) {
5432 if (mDisplay == null) {
5433 return false;
5434 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005435
5436 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005437
5438 // Use the effective "visual" dimensions based on current rotation
5439 final boolean rotated = (mRotation == Surface.ROTATION_90
5440 || mRotation == Surface.ROTATION_270);
5441 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5442 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5443
Dianne Hackbornc485a602009-03-24 22:39:49 -07005444 int orientation = Configuration.ORIENTATION_SQUARE;
5445 if (dw < dh) {
5446 orientation = Configuration.ORIENTATION_PORTRAIT;
5447 } else if (dw > dh) {
5448 orientation = Configuration.ORIENTATION_LANDSCAPE;
5449 }
5450 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005451
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005452 DisplayMetrics dm = new DisplayMetrics();
5453 mDisplay.getMetrics(dm);
5454 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5455
Dianne Hackborn3fc982f2011-03-30 16:20:26 -07005456 config.screenWidthDp = (int)(dm.widthPixels / dm.density);
5457 config.screenHeightDp = (int)(dm.heightPixels / dm.density);
5458
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005459 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005460 // Note we only do this once because at this point we don't
5461 // expect the screen to change in this way at runtime, and want
5462 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005463 int longSize = dw;
5464 int shortSize = dh;
5465 if (longSize < shortSize) {
5466 int tmp = longSize;
5467 longSize = shortSize;
5468 shortSize = tmp;
5469 }
5470 longSize = (int)(longSize/dm.density);
5471 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005472
Dianne Hackborn723738c2009-06-25 19:48:04 -07005473 // These semi-magic numbers define our compatibility modes for
Dianne Hackborncc1d9f72011-03-08 10:33:55 -08005474 // applications with different screens. These are guarantees to
5475 // app developers about the space they can expect for a particular
5476 // configuration. DO NOT CHANGE!
Dianne Hackborn723738c2009-06-25 19:48:04 -07005477 if (longSize < 470) {
5478 // This is shorter than an HVGA normal density screen (which
5479 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005480 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5481 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005482 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005483 // What size is this screen screen?
Dianne Hackborncc1d9f72011-03-08 10:33:55 -08005484 if (longSize >= 960 && shortSize >= 720) {
5485 // 1.5xVGA or larger screens at medium density are the point
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005486 // at which we consider it to be an extra large screen.
5487 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackborncc1d9f72011-03-08 10:33:55 -08005488 } else if (longSize >= 640 && shortSize >= 480) {
5489 // VGA or larger screens at medium density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005490 // at which we consider it to be a large screen.
5491 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5492 } else {
5493 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Dianne Hackborne97a12e2011-01-29 13:22:02 -08005494 }
5495
5496 // If this screen is wider than normal HVGA, or taller
5497 // than FWVGA, then for old apps we want to run in size
5498 // compatibility mode.
5499 if (shortSize > 321 || longSize > 570) {
5500 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005501 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005502
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005503 // Is this a long screen?
5504 if (((longSize*3)/5) >= (shortSize-1)) {
5505 // Anything wider than WVGA (5:3) is considering to be long.
5506 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5507 } else {
5508 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5509 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005510 }
5511 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005512 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005513
Jeff Brown597eec82011-01-31 17:12:25 -08005514 // Determine whether a hard keyboard is available and enabled.
Jeff Brown2992ea72011-01-28 22:04:14 -08005515 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5516 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5517 mHardKeyboardAvailable = hardKeyboardAvailable;
5518 mHardKeyboardEnabled = hardKeyboardAvailable;
5519
5520 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5521 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5522 }
5523 if (!mHardKeyboardEnabled) {
5524 config.keyboard = Configuration.KEYBOARD_NOKEYS;
Jeff Brown2992ea72011-01-28 22:04:14 -08005525 }
Jeff Brown597eec82011-01-31 17:12:25 -08005526
5527 // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
5528 // based on whether a hard or soft keyboard is present, whether navigation keys
5529 // are present and the lid switch state.
5530 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5531 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5532 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
5533 mPolicy.adjustConfigurationLw(config);
Dianne Hackbornc485a602009-03-24 22:39:49 -07005534 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005535 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005536
Jeff Brown2992ea72011-01-28 22:04:14 -08005537 public boolean isHardKeyboardAvailable() {
5538 synchronized (mWindowMap) {
5539 return mHardKeyboardAvailable;
5540 }
5541 }
5542
5543 public boolean isHardKeyboardEnabled() {
5544 synchronized (mWindowMap) {
5545 return mHardKeyboardEnabled;
5546 }
5547 }
5548
5549 public void setHardKeyboardEnabled(boolean enabled) {
5550 synchronized (mWindowMap) {
5551 if (mHardKeyboardEnabled != enabled) {
5552 mHardKeyboardEnabled = enabled;
5553 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5554 }
5555 }
5556 }
5557
5558 public void setOnHardKeyboardStatusChangeListener(
5559 OnHardKeyboardStatusChangeListener listener) {
5560 synchronized (mWindowMap) {
5561 mHardKeyboardStatusChangeListener = listener;
5562 }
5563 }
5564
5565 void notifyHardKeyboardStatusChange() {
5566 final boolean available, enabled;
5567 final OnHardKeyboardStatusChangeListener listener;
5568 synchronized (mWindowMap) {
5569 listener = mHardKeyboardStatusChangeListener;
5570 available = mHardKeyboardAvailable;
5571 enabled = mHardKeyboardEnabled;
5572 }
5573 if (listener != null) {
5574 listener.onHardKeyboardStatusChange(available, enabled);
5575 }
5576 }
5577
Christopher Tatea53146c2010-09-07 11:57:52 -07005578 // -------------------------------------------------------------
5579 // Drag and drop
5580 // -------------------------------------------------------------
5581
5582 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005583 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005584 if (DEBUG_DRAG) {
5585 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005586 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005587 + " asbinder=" + window.asBinder());
5588 }
5589
5590 final int callerPid = Binder.getCallingPid();
5591 final long origId = Binder.clearCallingIdentity();
5592 IBinder token = null;
5593
5594 try {
5595 synchronized (mWindowMap) {
5596 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005597 if (mDragState == null) {
5598 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5599 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
Dianne Hackbornac1471a2011-02-03 13:46:06 -08005600 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG "
5601 + surface + ": CREATE");
Christopher Tatea53146c2010-09-07 11:57:52 -07005602 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005603 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005604 token = new Binder();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005605 mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005606 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005607 token = mDragState.mToken = new Binder();
5608
5609 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005610 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5611 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005612 mH.sendMessageDelayed(msg, 5000);
5613 } else {
5614 Slog.w(TAG, "Drag already in progress");
5615 }
5616 } catch (Surface.OutOfResourcesException e) {
5617 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5618 if (mDragState != null) {
5619 mDragState.reset();
5620 mDragState = null;
5621 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005622 }
5623 }
5624 } finally {
5625 Binder.restoreCallingIdentity(origId);
5626 }
5627
5628 return token;
5629 }
5630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005631 // -------------------------------------------------------------
5632 // Input Events and Focus Management
5633 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005634
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005635 final InputMonitor mInputMonitor = new InputMonitor(this);
Jeff Brown349703e2010-06-22 01:27:15 -07005636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005637 public void pauseKeyDispatching(IBinder _token) {
5638 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5639 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005640 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005641 }
5642
5643 synchronized (mWindowMap) {
5644 WindowToken token = mTokenMap.get(_token);
5645 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005646 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005647 }
5648 }
5649 }
5650
5651 public void resumeKeyDispatching(IBinder _token) {
5652 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5653 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005654 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005655 }
5656
5657 synchronized (mWindowMap) {
5658 WindowToken token = mTokenMap.get(_token);
5659 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005660 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005661 }
5662 }
5663 }
5664
5665 public void setEventDispatching(boolean enabled) {
5666 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5667 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005668 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005669 }
5670
5671 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005672 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005673 }
5674 }
Romain Guy06882f82009-06-10 13:36:04 -07005675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005676 /**
5677 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005678 * Even when sync is false, this method may block while waiting for current
5679 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005680 *
5681 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 * {@link SystemClock#uptimeMillis()} as the timebase.)
5683 * @param sync If true, wait for the event to be completed before returning to the caller.
5684 * @return Returns true if event was dispatched, false if it was dropped for any reason
5685 */
5686 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5687 long downTime = ev.getDownTime();
5688 long eventTime = ev.getEventTime();
5689
5690 int action = ev.getAction();
5691 int code = ev.getKeyCode();
5692 int repeatCount = ev.getRepeatCount();
5693 int metaState = ev.getMetaState();
5694 int deviceId = ev.getDeviceId();
5695 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005696 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00005697 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005698
5699 if (source == InputDevice.SOURCE_UNKNOWN) {
5700 source = InputDevice.SOURCE_KEYBOARD;
5701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005702
5703 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5704 if (downTime == 0) downTime = eventTime;
5705
5706 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08005707 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005708
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005709 final int pid = Binder.getCallingPid();
5710 final int uid = Binder.getCallingUid();
5711 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005712
Jeff Brownbbda99d2010-07-28 15:48:59 -07005713 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5714 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5715 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5716 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005717
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005718 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005719 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005720 }
5721
5722 /**
5723 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005724 * Even when sync is false, this method may block while waiting for current
5725 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005726 *
5727 * @param ev A motion event describing the pointer (touch) action. (As noted in
5728 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005729 * {@link SystemClock#uptimeMillis()} as the timebase.)
5730 * @param sync If true, wait for the event to be completed before returning to the caller.
5731 * @return Returns true if event was dispatched, false if it was dropped for any reason
5732 */
5733 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005734 final int pid = Binder.getCallingPid();
5735 final int uid = Binder.getCallingUid();
5736 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005737
Jeff Brownc5ed5912010-07-14 18:48:53 -07005738 MotionEvent newEvent = MotionEvent.obtain(ev);
5739 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5740 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5741 }
5742
Jeff Brownbbda99d2010-07-28 15:48:59 -07005743 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5744 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5745 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5746 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005747
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005748 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005749 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005750 }
Romain Guy06882f82009-06-10 13:36:04 -07005751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005752 /**
5753 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005754 * Even when sync is false, this method may block while waiting for current
5755 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005756 *
5757 * @param ev A motion event describing the trackball action. (As noted in
5758 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005759 * {@link SystemClock#uptimeMillis()} as the timebase.)
5760 * @param sync If true, wait for the event to be completed before returning to the caller.
5761 * @return Returns true if event was dispatched, false if it was dropped for any reason
5762 */
5763 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005764 final int pid = Binder.getCallingPid();
5765 final int uid = Binder.getCallingUid();
5766 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005767
Jeff Brownc5ed5912010-07-14 18:48:53 -07005768 MotionEvent newEvent = MotionEvent.obtain(ev);
5769 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5770 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5771 }
5772
Jeff Brownbbda99d2010-07-28 15:48:59 -07005773 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5774 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5775 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5776 INJECTION_TIMEOUT_MILLIS);
5777
5778 Binder.restoreCallingIdentity(ident);
5779 return reportInjectionResult(result);
5780 }
5781
5782 /**
5783 * Inject an input event into the UI without waiting for dispatch to commence.
5784 * This variant is useful for fire-and-forget input event injection. It does not
5785 * block any longer than it takes to enqueue the input event.
5786 *
5787 * @param ev An input event. (Be sure to set the input source correctly.)
5788 * @return Returns true if event was dispatched, false if it was dropped for any reason
5789 */
5790 public boolean injectInputEventNoWait(InputEvent ev) {
5791 final int pid = Binder.getCallingPid();
5792 final int uid = Binder.getCallingUid();
5793 final long ident = Binder.clearCallingIdentity();
5794
5795 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5796 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5797 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005798
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005799 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005800 return reportInjectionResult(result);
5801 }
5802
5803 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005804 switch (result) {
5805 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5806 Slog.w(TAG, "Input event injection permission denied.");
5807 throw new SecurityException(
5808 "Injecting to another application requires INJECT_EVENTS permission");
5809 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005810 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005811 return true;
5812 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5813 Slog.w(TAG, "Input event injection timed out.");
5814 return false;
5815 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5816 default:
5817 Slog.w(TAG, "Input event injection failed.");
5818 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005819 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005820 }
Romain Guy06882f82009-06-10 13:36:04 -07005821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005822 private WindowState getFocusedWindow() {
5823 synchronized (mWindowMap) {
5824 return getFocusedWindowLocked();
5825 }
5826 }
5827
5828 private WindowState getFocusedWindowLocked() {
5829 return mCurrentFocus;
5830 }
Romain Guy06882f82009-06-10 13:36:04 -07005831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005832 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08005833 if (!mInputMonitor.waitForInputDevicesReady(
5834 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
5835 Slog.w(TAG, "Devices still not ready after waiting "
5836 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
5837 + " milliseconds before attempting to detect safe mode.");
5838 }
5839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 mSafeMode = mPolicy.detectSafeMode();
5841 return mSafeMode;
5842 }
Romain Guy06882f82009-06-10 13:36:04 -07005843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005845 synchronized(mWindowMap) {
5846 if (mDisplay != null) {
5847 throw new IllegalStateException("Display already initialized");
5848 }
5849 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5850 mDisplay = wm.getDefaultDisplay();
5851 mInitialDisplayWidth = mDisplay.getWidth();
5852 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn99aac7b2011-02-25 17:33:02 -08005853 mInputManager.setDisplaySize(0, mDisplay.getRealWidth(), mDisplay.getRealHeight());
Dianne Hackborn5132b372010-07-29 12:51:35 -07005854 }
5855
5856 try {
5857 mActivityManager.updateConfiguration(null);
5858 } catch (RemoteException e) {
5859 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005860
5861 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005862 }
5863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005864 // This is an animation that does nothing: it just immediately finishes
5865 // itself every time it is called. It is used as a stub animation in cases
5866 // where we want to synchronize multiple things that may be animating.
5867 static final class DummyAnimation extends Animation {
5868 public boolean getTransformation(long currentTime, Transformation outTransformation) {
5869 return false;
5870 }
5871 }
5872 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07005873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005874 // -------------------------------------------------------------
5875 // Async Handler
5876 // -------------------------------------------------------------
5877
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08005878 final class H extends Handler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005879 public static final int REPORT_FOCUS_CHANGE = 2;
5880 public static final int REPORT_LOSING_FOCUS = 3;
5881 public static final int ANIMATE = 4;
5882 public static final int ADD_STARTING = 5;
5883 public static final int REMOVE_STARTING = 6;
5884 public static final int FINISHED_STARTING = 7;
5885 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 public static final int WINDOW_FREEZE_TIMEOUT = 11;
5887 public static final int HOLD_SCREEN_CHANGED = 12;
5888 public static final int APP_TRANSITION_TIMEOUT = 13;
5889 public static final int PERSIST_ANIMATION_SCALE = 14;
5890 public static final int FORCE_GC = 15;
5891 public static final int ENABLE_SCREEN = 16;
5892 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005893 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005894 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07005895 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07005896 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08005897 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07005898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005899 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07005900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005901 public H() {
5902 }
Romain Guy06882f82009-06-10 13:36:04 -07005903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005904 @Override
5905 public void handleMessage(Message msg) {
5906 switch (msg.what) {
5907 case REPORT_FOCUS_CHANGE: {
5908 WindowState lastFocus;
5909 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 synchronized(mWindowMap) {
5912 lastFocus = mLastFocus;
5913 newFocus = mCurrentFocus;
5914 if (lastFocus == newFocus) {
5915 // Focus is not changing, so nothing to do.
5916 return;
5917 }
5918 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005919 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005920 // + " to " + newFocus);
5921 if (newFocus != null && lastFocus != null
5922 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005923 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005924 mLosingFocus.add(lastFocus);
5925 lastFocus = null;
5926 }
5927 }
5928
5929 if (lastFocus != newFocus) {
5930 //System.out.println("Changing focus from " + lastFocus
5931 // + " to " + newFocus);
5932 if (newFocus != null) {
5933 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005934 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005935 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
5936 } catch (RemoteException e) {
5937 // Ignore if process has died.
5938 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07005939 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005940 }
5941
5942 if (lastFocus != null) {
5943 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005944 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005945 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
5946 } catch (RemoteException e) {
5947 // Ignore if process has died.
5948 }
5949 }
Joe Onorato664644d2011-01-23 17:53:23 -08005950
5951 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005952 }
5953 } break;
5954
5955 case REPORT_LOSING_FOCUS: {
5956 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07005957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005958 synchronized(mWindowMap) {
5959 losers = mLosingFocus;
5960 mLosingFocus = new ArrayList<WindowState>();
5961 }
5962
5963 final int N = losers.size();
5964 for (int i=0; i<N; i++) {
5965 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005966 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005967 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
5968 } catch (RemoteException e) {
5969 // Ignore if process has died.
5970 }
5971 }
5972 } break;
5973
5974 case ANIMATE: {
5975 synchronized(mWindowMap) {
5976 mAnimationPending = false;
5977 performLayoutAndPlaceSurfacesLocked();
5978 }
5979 } break;
5980
5981 case ADD_STARTING: {
5982 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
5983 final StartingData sd = wtoken.startingData;
5984
5985 if (sd == null) {
5986 // Animation has been canceled... do nothing.
5987 return;
5988 }
Romain Guy06882f82009-06-10 13:36:04 -07005989
Joe Onorato8a9b2202010-02-26 18:56:32 -08005990 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005991 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07005992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005993 View view = null;
5994 try {
5995 view = mPolicy.addStartingWindow(
5996 wtoken.token, sd.pkg,
5997 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08005998 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005999 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006000 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001 }
6002
6003 if (view != null) {
6004 boolean abort = false;
6005
6006 synchronized(mWindowMap) {
6007 if (wtoken.removed || wtoken.startingData == null) {
6008 // If the window was successfully added, then
6009 // we need to remove it.
6010 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006011 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006012 "Aborted starting " + wtoken
6013 + ": removed=" + wtoken.removed
6014 + " startingData=" + wtoken.startingData);
6015 wtoken.startingWindow = null;
6016 wtoken.startingData = null;
6017 abort = true;
6018 }
6019 } else {
6020 wtoken.startingView = view;
6021 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006022 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006023 "Added starting " + wtoken
6024 + ": startingWindow="
6025 + wtoken.startingWindow + " startingView="
6026 + wtoken.startingView);
6027 }
6028
6029 if (abort) {
6030 try {
6031 mPolicy.removeStartingWindow(wtoken.token, view);
6032 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006033 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006034 }
6035 }
6036 }
6037 } break;
6038
6039 case REMOVE_STARTING: {
6040 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
6041 IBinder token = null;
6042 View view = null;
6043 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006044 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 + wtoken + ": startingWindow="
6046 + wtoken.startingWindow + " startingView="
6047 + wtoken.startingView);
6048 if (wtoken.startingWindow != null) {
6049 view = wtoken.startingView;
6050 token = wtoken.token;
6051 wtoken.startingData = null;
6052 wtoken.startingView = null;
6053 wtoken.startingWindow = null;
6054 }
6055 }
6056 if (view != null) {
6057 try {
6058 mPolicy.removeStartingWindow(token, view);
6059 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006060 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006061 }
6062 }
6063 } break;
6064
6065 case FINISHED_STARTING: {
6066 IBinder token = null;
6067 View view = null;
6068 while (true) {
6069 synchronized (mWindowMap) {
6070 final int N = mFinishedStarting.size();
6071 if (N <= 0) {
6072 break;
6073 }
6074 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
6075
Joe Onorato8a9b2202010-02-26 18:56:32 -08006076 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006077 "Finished starting " + wtoken
6078 + ": startingWindow=" + wtoken.startingWindow
6079 + " startingView=" + wtoken.startingView);
6080
6081 if (wtoken.startingWindow == null) {
6082 continue;
6083 }
6084
6085 view = wtoken.startingView;
6086 token = wtoken.token;
6087 wtoken.startingData = null;
6088 wtoken.startingView = null;
6089 wtoken.startingWindow = null;
6090 }
6091
6092 try {
6093 mPolicy.removeStartingWindow(token, view);
6094 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006095 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006096 }
6097 }
6098 } break;
6099
6100 case REPORT_APPLICATION_TOKEN_WINDOWS: {
6101 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
6102
6103 boolean nowVisible = msg.arg1 != 0;
6104 boolean nowGone = msg.arg2 != 0;
6105
6106 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006107 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006108 TAG, "Reporting visible in " + wtoken
6109 + " visible=" + nowVisible
6110 + " gone=" + nowGone);
6111 if (nowVisible) {
6112 wtoken.appToken.windowsVisible();
6113 } else {
6114 wtoken.appToken.windowsGone();
6115 }
6116 } catch (RemoteException ex) {
6117 }
6118 } break;
Romain Guy06882f82009-06-10 13:36:04 -07006119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006120 case WINDOW_FREEZE_TIMEOUT: {
6121 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006122 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123 int i = mWindows.size();
6124 while (i > 0) {
6125 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006126 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006127 if (w.mOrientationChanging) {
6128 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006129 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006130 }
6131 }
6132 performLayoutAndPlaceSurfacesLocked();
6133 }
6134 break;
6135 }
Romain Guy06882f82009-06-10 13:36:04 -07006136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006137 case HOLD_SCREEN_CHANGED: {
6138 Session oldHold;
6139 Session newHold;
6140 synchronized (mWindowMap) {
6141 oldHold = mLastReportedHold;
6142 newHold = (Session)msg.obj;
6143 mLastReportedHold = newHold;
6144 }
Romain Guy06882f82009-06-10 13:36:04 -07006145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 if (oldHold != newHold) {
6147 try {
6148 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07006149 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 "window",
6151 BatteryStats.WAKE_TYPE_WINDOW);
6152 }
6153 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07006154 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155 "window",
6156 BatteryStats.WAKE_TYPE_WINDOW);
6157 }
6158 } catch (RemoteException e) {
6159 }
6160 }
6161 break;
6162 }
Romain Guy06882f82009-06-10 13:36:04 -07006163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 case APP_TRANSITION_TIMEOUT: {
6165 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006166 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006167 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 "*** APP TRANSITION TIMEOUT");
6169 mAppTransitionReady = true;
6170 mAppTransitionTimeout = true;
6171 performLayoutAndPlaceSurfacesLocked();
6172 }
6173 }
6174 break;
6175 }
Romain Guy06882f82009-06-10 13:36:04 -07006176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006177 case PERSIST_ANIMATION_SCALE: {
6178 Settings.System.putFloat(mContext.getContentResolver(),
6179 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
6180 Settings.System.putFloat(mContext.getContentResolver(),
6181 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
6182 break;
6183 }
Romain Guy06882f82009-06-10 13:36:04 -07006184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006185 case FORCE_GC: {
6186 synchronized(mWindowMap) {
6187 if (mAnimationPending) {
6188 // If we are animating, don't do the gc now but
6189 // delay a bit so we don't interrupt the animation.
6190 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
6191 2000);
6192 return;
6193 }
6194 // If we are currently rotating the display, it will
6195 // schedule a new message when done.
6196 if (mDisplayFrozen) {
6197 return;
6198 }
6199 mFreezeGcPending = 0;
6200 }
6201 Runtime.getRuntime().gc();
6202 break;
6203 }
Romain Guy06882f82009-06-10 13:36:04 -07006204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006205 case ENABLE_SCREEN: {
6206 performEnableScreen();
6207 break;
6208 }
Romain Guy06882f82009-06-10 13:36:04 -07006209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006210 case APP_FREEZE_TIMEOUT: {
6211 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006212 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006213 int i = mAppTokens.size();
6214 while (i > 0) {
6215 i--;
6216 AppWindowToken tok = mAppTokens.get(i);
6217 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006218 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006219 unsetAppFreezingScreenLocked(tok, true, true);
6220 }
6221 }
6222 }
6223 break;
6224 }
Romain Guy06882f82009-06-10 13:36:04 -07006225
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006226 case SEND_NEW_CONFIGURATION: {
6227 removeMessages(SEND_NEW_CONFIGURATION);
6228 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006229 break;
6230 }
Romain Guy06882f82009-06-10 13:36:04 -07006231
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07006232 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006233 if (mWindowsChanged) {
6234 synchronized (mWindowMap) {
6235 mWindowsChanged = false;
6236 }
6237 notifyWindowsChanged();
6238 }
6239 break;
6240 }
6241
Christopher Tatea53146c2010-09-07 11:57:52 -07006242 case DRAG_START_TIMEOUT: {
6243 IBinder win = (IBinder)msg.obj;
6244 if (DEBUG_DRAG) {
6245 Slog.w(TAG, "Timeout starting drag by win " + win);
6246 }
6247 synchronized (mWindowMap) {
6248 // !!! TODO: ANR the app that has failed to start the drag in time
6249 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07006250 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08006251 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07006252 mDragState.reset();
6253 mDragState = null;
6254 }
6255 }
Chris Tated4533f12010-10-19 15:15:08 -07006256 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07006257 }
6258
Chris Tated4533f12010-10-19 15:15:08 -07006259 case DRAG_END_TIMEOUT: {
6260 IBinder win = (IBinder)msg.obj;
6261 if (DEBUG_DRAG) {
6262 Slog.w(TAG, "Timeout ending drag to win " + win);
6263 }
6264 synchronized (mWindowMap) {
6265 // !!! TODO: ANR the drag-receiving app
6266 mDragState.mDragResult = false;
6267 mDragState.endDragLw();
6268 }
6269 break;
6270 }
Jeff Brown2992ea72011-01-28 22:04:14 -08006271
6272 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
6273 notifyHardKeyboardStatusChange();
6274 break;
6275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006276 }
6277 }
6278 }
6279
6280 // -------------------------------------------------------------
6281 // IWindowManager API
6282 // -------------------------------------------------------------
6283
6284 public IWindowSession openSession(IInputMethodClient client,
6285 IInputContext inputContext) {
6286 if (client == null) throw new IllegalArgumentException("null client");
6287 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08006288 Session session = new Session(this, client, inputContext);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006289 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006290 }
6291
6292 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
6293 synchronized (mWindowMap) {
6294 // The focus for the client is the window immediately below
6295 // where we would place the input method window.
6296 int idx = findDesiredInputMethodWindowIndexLocked(false);
6297 WindowState imFocus;
6298 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07006299 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08006300 //Log.i(TAG, "Desired input method target: " + imFocus);
6301 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
6302 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006303 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08006304 // This may be a starting window, in which case we still want
6305 // to count it as okay.
6306 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
6307 && imFocus.mAppToken != null) {
6308 // The client has definitely started, so it really should
6309 // have a window in this app token. Let's look for it.
6310 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
6311 WindowState w = imFocus.mAppToken.windows.get(i);
6312 if (w != imFocus) {
6313 //Log.i(TAG, "Switching to real app window: " + w);
6314 imFocus = w;
6315 break;
6316 }
6317 }
6318 }
6319 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
6320 //if (imFocus.mSession.mClient != null) {
6321 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
6322 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
6323 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 if (imFocus.mSession.mClient != null &&
6325 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
6326 return true;
6327 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08006328
6329 // Okay, how about this... what is the current focus?
6330 // It seems in some cases we may not have moved the IM
6331 // target window, such as when it was in a pop-up window,
6332 // so let's also look at the current focus. (An example:
6333 // go to Gmail, start searching so the keyboard goes up,
6334 // press home. Sometimes the IME won't go down.)
6335 // Would be nice to fix this more correctly, but it's
6336 // way at the end of a release, and this should be good enough.
6337 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
6338 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
6339 return true;
6340 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006341 }
6342 }
6343 }
6344 return false;
6345 }
Romain Guy06882f82009-06-10 13:36:04 -07006346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006347 // -------------------------------------------------------------
6348 // Internals
6349 // -------------------------------------------------------------
6350
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006351 final WindowState windowForClientLocked(Session session, IWindow client,
6352 boolean throwOnError) {
6353 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 }
Romain Guy06882f82009-06-10 13:36:04 -07006355
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006356 final WindowState windowForClientLocked(Session session, IBinder client,
6357 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006358 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006359 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 TAG, "Looking up client " + client + ": " + win);
6361 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006362 RuntimeException ex = new IllegalArgumentException(
6363 "Requested window " + client + " does not exist");
6364 if (throwOnError) {
6365 throw ex;
6366 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006367 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 return null;
6369 }
6370 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006371 RuntimeException ex = new IllegalArgumentException(
6372 "Requested window " + client + " is in session " +
6373 win.mSession + ", not " + session);
6374 if (throwOnError) {
6375 throw ex;
6376 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006377 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006378 return null;
6379 }
6380
6381 return win;
6382 }
6383
Dianne Hackborna8f60182009-09-01 19:01:50 -07006384 final void rebuildAppWindowListLocked() {
6385 int NW = mWindows.size();
6386 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006387 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006388 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006389
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006390 if (mRebuildTmp.length < NW) {
6391 mRebuildTmp = new WindowState[NW+10];
6392 }
6393
Dianne Hackborna8f60182009-09-01 19:01:50 -07006394 // First remove all existing app windows.
6395 i=0;
6396 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07006397 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006398 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07006399 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006400 win.mRebuilding = true;
6401 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006402 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006403 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006404 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07006405 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006406 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07006407 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006408 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
6409 && lastWallpaper == i-1) {
6410 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07006411 }
6412 i++;
6413 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006414
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006415 // The wallpaper window(s) typically live at the bottom of the stack,
6416 // so skip them before adding app tokens.
6417 lastWallpaper++;
6418 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006419
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006420 // First add all of the exiting app tokens... these are no longer
6421 // in the main app list, but still have windows shown. We put them
6422 // in the back because now that the animation is over we no longer
6423 // will care about them.
6424 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07006425 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006426 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
6427 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006428
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006429 // And add in the still active app tokens in Z order.
6430 NT = mAppTokens.size();
6431 for (int j=0; j<NT; j++) {
6432 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07006433 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006434
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006435 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006436 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006437 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006438 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006439 for (i=0; i<numRemoved; i++) {
6440 WindowState ws = mRebuildTmp[i];
6441 if (ws.mRebuilding) {
6442 StringWriter sw = new StringWriter();
6443 PrintWriter pw = new PrintWriter(sw);
6444 ws.dump(pw, "");
6445 pw.flush();
6446 Slog.w(TAG, "This window was lost: " + ws);
6447 Slog.w(TAG, sw.toString());
6448 }
6449 }
6450 Slog.w(TAG, "Current app token list:");
6451 dumpAppTokensLocked();
6452 Slog.w(TAG, "Final window list:");
6453 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006454 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07006455 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006457 private final void assignLayersLocked() {
6458 int N = mWindows.size();
6459 int curBaseLayer = 0;
6460 int curLayer = 0;
6461 int i;
Romain Guy06882f82009-06-10 13:36:04 -07006462
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006463 if (DEBUG_LAYERS) {
6464 RuntimeException here = new RuntimeException("here");
6465 here.fillInStackTrace();
6466 Log.v(TAG, "Assigning layers", here);
6467 }
6468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006470 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006471 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
6472 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006473 curLayer += WINDOW_LAYER_MULTIPLIER;
6474 w.mLayer = curLayer;
6475 } else {
6476 curBaseLayer = curLayer = w.mBaseLayer;
6477 w.mLayer = curLayer;
6478 }
6479 if (w.mTargetAppToken != null) {
6480 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
6481 } else if (w.mAppToken != null) {
6482 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
6483 } else {
6484 w.mAnimLayer = w.mLayer;
6485 }
6486 if (w.mIsImWindow) {
6487 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006488 } else if (w.mIsWallpaper) {
6489 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006491 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 + w.mAnimLayer);
6493 //System.out.println(
6494 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
6495 }
6496 }
6497
6498 private boolean mInLayout = false;
6499 private final void performLayoutAndPlaceSurfacesLocked() {
6500 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07006501 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 throw new RuntimeException("Recursive call!");
6503 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006504 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 return;
6506 }
6507
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006508 if (mWaitingForConfig) {
6509 // Our configuration has changed (most likely rotation), but we
6510 // don't yet have the complete configuration to report to
6511 // applications. Don't do any window layout until we have it.
6512 return;
6513 }
6514
Dianne Hackbornce2ef762010-09-20 11:39:14 -07006515 if (mDisplay == null) {
6516 // Not yet initialized, nothing to do.
6517 return;
6518 }
6519
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006520 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006521 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006522
6523 try {
6524 if (mForceRemoves != null) {
6525 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006526 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006527 for (int i=0; i<mForceRemoves.size(); i++) {
6528 WindowState ws = mForceRemoves.get(i);
6529 Slog.i(TAG, "Force removing: " + ws);
6530 removeWindowInnerLocked(ws.mSession, ws);
6531 }
6532 mForceRemoves = null;
6533 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
6534 Object tmp = new Object();
6535 synchronized (tmp) {
6536 try {
6537 tmp.wait(250);
6538 } catch (InterruptedException e) {
6539 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006540 }
6541 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006542 } catch (RuntimeException e) {
6543 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006544 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08006545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006546 try {
6547 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07006548
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006549 int N = mPendingRemove.size();
6550 if (N > 0) {
6551 if (mPendingRemoveTmp.length < N) {
6552 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006554 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006555 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006556 for (int i=0; i<N; i++) {
6557 WindowState w = mPendingRemoveTmp[i];
6558 removeWindowInnerLocked(w.mSession, w);
6559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006560
6561 mInLayout = false;
6562 assignLayersLocked();
6563 mLayoutNeeded = true;
6564 performLayoutAndPlaceSurfacesLocked();
6565
6566 } else {
6567 mInLayout = false;
6568 if (mLayoutNeeded) {
6569 requestAnimationLocked(0);
6570 }
6571 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006572 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07006573 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
6574 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07006575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006576 } catch (RuntimeException e) {
6577 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006578 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006579 }
6580 }
6581
Jeff Brown3a22cd92011-01-21 13:59:04 -08006582 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006583 if (!mLayoutNeeded) {
6584 return 0;
6585 }
6586
6587 mLayoutNeeded = false;
6588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006589 final int dw = mDisplay.getWidth();
6590 final int dh = mDisplay.getHeight();
6591
6592 final int N = mWindows.size();
6593 int i;
6594
Joe Onorato8a9b2202010-02-26 18:56:32 -08006595 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08006596 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
6597
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006598 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07006599
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006600 int seq = mLayoutSeq+1;
6601 if (seq < 0) seq = 0;
6602 mLayoutSeq = seq;
6603
6604 // First perform layout of any root windows (not attached
6605 // to another window).
6606 int topAttached = -1;
6607 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006608 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006610 // Don't do layout of a window if it is not visible, or
6611 // soon won't be visible, to avoid wasting time and funky
6612 // changes while a window is animating away.
6613 final AppWindowToken atoken = win.mAppToken;
6614 final boolean gone = win.mViewVisibility == View.GONE
6615 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08006616 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006617 || (atoken != null && atoken.hiddenRequested)
6618 || win.mAttachedHidden
6619 || win.mExiting || win.mDestroying;
6620
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006621 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
6622 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006623 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
6624 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006625 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006626 + win.mViewVisibility + " mRelayoutCalled="
6627 + win.mRelayoutCalled + " hidden="
6628 + win.mRootToken.hidden + " hiddenRequested="
6629 + (atoken != null && atoken.hiddenRequested)
6630 + " mAttachedHidden=" + win.mAttachedHidden);
6631 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006632
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006633 // If this view is GONE, then skip it -- keep the current
6634 // frame, and let the caller know so they can ignore it
6635 // if they want. (We do the normal layout for INVISIBLE
6636 // windows, since that means "perform layout as normal,
6637 // just don't display").
6638 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006639 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006640 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006641 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006642 win.mContentChanged = false;
6643 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006644 mPolicy.layoutWindowLw(win, win.mAttrs, null);
6645 win.mLayoutSeq = seq;
6646 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
6647 + win.mFrame + " mContainingFrame="
6648 + win.mContainingFrame + " mDisplayFrame="
6649 + win.mDisplayFrame);
6650 } else {
6651 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07006652 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07006653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006655
6656 // Now perform layout of attached windows, which usually
6657 // depend on the position of the window they are attached to.
6658 // XXX does not deal with windows that are attached to windows
6659 // that are themselves attached.
6660 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006661 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006662
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006663 if (win.mLayoutAttached) {
6664 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
6665 + " mHaveFrame=" + win.mHaveFrame
6666 + " mViewVisibility=" + win.mViewVisibility
6667 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006668 // If this view is GONE, then skip it -- keep the current
6669 // frame, and let the caller know so they can ignore it
6670 // if they want. (We do the normal layout for INVISIBLE
6671 // windows, since that means "perform layout as normal,
6672 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006673 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
6674 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006675 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006676 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006677 win.mContentChanged = false;
6678 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006679 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
6680 win.mLayoutSeq = seq;
6681 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
6682 + win.mFrame + " mContainingFrame="
6683 + win.mContainingFrame + " mDisplayFrame="
6684 + win.mDisplayFrame);
6685 }
6686 }
6687 }
Jeff Brown349703e2010-06-22 01:27:15 -07006688
6689 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08006690 mInputMonitor.setUpdateInputWindowsNeededLw();
6691 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006692 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006693 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006694
6695 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006696 }
Romain Guy06882f82009-06-10 13:36:04 -07006697
Brad Fitzpatrick68044332010-11-22 18:19:48 -08006698 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 private final void performLayoutAndPlaceSurfacesLockedInner(
6700 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04006701 if (mDisplay == null) {
6702 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
6703 return;
6704 }
6705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 final long currentTime = SystemClock.uptimeMillis();
6707 final int dw = mDisplay.getWidth();
6708 final int dh = mDisplay.getHeight();
6709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006710 int i;
6711
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006712 if (mFocusMayChange) {
6713 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006714 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
6715 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006716 }
6717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006718 // Initialize state of exiting tokens.
6719 for (i=mExitingTokens.size()-1; i>=0; i--) {
6720 mExitingTokens.get(i).hasVisible = false;
6721 }
6722
6723 // Initialize state of exiting applications.
6724 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
6725 mExitingAppTokens.get(i).hasVisible = false;
6726 }
6727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 boolean orientationChangeComplete = true;
6729 Session holdScreen = null;
6730 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05006731 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 boolean focusDisplayed = false;
6733 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006734 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08006735 boolean updateRotation = false;
Dianne Hackborn50660e22011-02-02 17:12:25 -08006736 boolean screenRotationFinished = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006737
6738 if (mFxSession == null) {
6739 mFxSession = new SurfaceSession();
6740 createWatermark = true;
6741 }
6742
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006743 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006744
6745 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006746
6747 if (createWatermark) {
6748 createWatermark();
6749 }
6750 if (mWatermark != null) {
6751 mWatermark.positionSurface(dw, dh);
6752 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08006753 if (mStrictModeFlash != null) {
6754 mStrictModeFlash.positionSurface(dw, dh);
6755 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07006756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006757 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006758 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006759 int repeats = 0;
6760 int changes = 0;
6761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006763 repeats++;
6764 if (repeats > 6) {
6765 Slog.w(TAG, "Animation repeat aborted after too many iterations");
6766 mLayoutNeeded = false;
6767 break;
6768 }
6769
6770 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
6771 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
6772 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
6773 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
6774 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
6775 assignLayersLocked();
6776 mLayoutNeeded = true;
6777 }
6778 }
6779 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
6780 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006781 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006782 mLayoutNeeded = true;
6783 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
6784 }
6785 }
6786 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
6787 mLayoutNeeded = true;
6788 }
6789 }
6790
6791 // FIRST LOOP: Perform a layout, if needed.
6792 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006793 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006794 if (changes != 0) {
6795 continue;
6796 }
6797 } else {
6798 Slog.w(TAG, "Layout repeat skipped after too many iterations");
6799 changes = 0;
6800 }
6801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006802 final int transactionSequence = ++mTransactionSequence;
6803
6804 // Update animations of all applications, including those
6805 // associated with exiting/removed apps
6806 boolean tokensAnimating = false;
6807 final int NAT = mAppTokens.size();
6808 for (i=0; i<NAT; i++) {
6809 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
6810 tokensAnimating = true;
6811 }
6812 }
6813 final int NEAT = mExitingAppTokens.size();
6814 for (i=0; i<NEAT; i++) {
6815 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
6816 tokensAnimating = true;
6817 }
6818 }
6819
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006820 // SECOND LOOP: Execute animations and update visibility of windows.
6821
Joe Onorato8a9b2202010-02-26 18:56:32 -08006822 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006823 + transactionSequence + " tokensAnimating="
6824 + tokensAnimating);
6825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006826 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08006828 if (mScreenRotationAnimation != null) {
6829 if (mScreenRotationAnimation.isAnimating()) {
6830 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
6831 animating = true;
6832 } else {
Dianne Hackborn50660e22011-02-02 17:12:25 -08006833 screenRotationFinished = true;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08006834 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08006835 }
6836 }
6837 }
6838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006839 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006840 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006841 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006842 WindowState windowDetachedWallpaper = null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -08006843 WindowState windowAnimationBackground = null;
6844 int windowAnimationBackgroundColor = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845
6846 mPolicy.beginAnimationLw(dw, dh);
6847
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07006848 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006850 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006851 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852
6853 final WindowManager.LayoutParams attrs = w.mAttrs;
6854
6855 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006856 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006857 if (w.commitFinishDrawingLocked(currentTime)) {
6858 if ((w.mAttrs.flags
6859 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006860 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006861 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006862 wallpaperMayChange = true;
6863 }
6864 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006865
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006866 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006867
6868 int animDw = dw;
6869 int animDh = dh;
6870
6871 // If the window has moved due to its containing
6872 // content frame changing, then we'd like to animate
6873 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08006874 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006875 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006876 // Frame has moved, containing content frame
6877 // has also moved, and we're not currently animating...
6878 // let's do something.
6879 Animation a = AnimationUtils.loadAnimation(mContext,
6880 com.android.internal.R.anim.window_move_from_decor);
6881 w.setAnimation(a);
6882 animDw = w.mLastFrame.left - w.mFrame.left;
6883 animDh = w.mLastFrame.top - w.mFrame.top;
6884 }
6885
6886 // Execute animation.
6887 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
6888 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006889
6890 // If this window is animating, make a note that we have
6891 // an animating window and take care of a request to run
6892 // a detached wallpaper animation.
6893 if (nowAnimating) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08006894 if (w.mAnimation != null) {
6895 if (w.mAnimation.getDetachWallpaper()) {
6896 windowDetachedWallpaper = w;
6897 }
6898 if (w.mAnimation.getBackgroundColor() != 0) {
6899 windowAnimationBackground = w;
6900 windowAnimationBackgroundColor =
6901 w.mAnimation.getBackgroundColor();
6902 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006904 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006906
6907 // If this window's app token is running a detached wallpaper
6908 // animation, make a note so we can ensure the wallpaper is
6909 // displayed behind it.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08006910 if (w.mAppToken != null && w.mAppToken.animation != null) {
6911 if (w.mAppToken.animation.getDetachWallpaper()) {
6912 windowDetachedWallpaper = w;
6913 }
6914 if (w.mAppToken.animation.getBackgroundColor() != 0) {
6915 windowAnimationBackground = w;
6916 windowAnimationBackgroundColor =
6917 w.mAppToken.animation.getBackgroundColor();
6918 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006919 }
6920
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006921 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
6922 wallpaperMayChange = true;
6923 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006924
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006925 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006926 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006927 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08006928 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006929 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006930 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006931 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006932 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
6933 forceHiding = true;
6934 }
6935 } else if (mPolicy.canBeForceHidden(w, attrs)) {
6936 boolean changed;
6937 if (forceHiding) {
6938 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006939 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
6940 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006941 } else {
6942 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006943 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
6944 "Now policy shown: " + w);
6945 if (changed) {
6946 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006947 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006948 // Assume we will need to animate. If
6949 // we don't (because the wallpaper will
6950 // stay with the lock screen), then we will
6951 // clean up later.
6952 Animation a = mPolicy.createForceHideEnterAnimation();
6953 if (a != null) {
6954 w.setAnimation(a);
6955 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006956 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08006957 if (mCurrentFocus == null ||
6958 mCurrentFocus.mLayer < w.mLayer) {
6959 // We are showing on to of the current
6960 // focus, so re-evaluate focus to make
6961 // sure it is correct.
6962 mFocusMayChange = true;
6963 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006964 }
6965 }
6966 if (changed && (attrs.flags
6967 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
6968 wallpaperMayChange = true;
6969 }
6970 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006972 mPolicy.animatingWindowLw(w, attrs);
6973 }
6974
6975 final AppWindowToken atoken = w.mAppToken;
6976 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
6977 if (atoken.lastTransactionSequence != transactionSequence) {
6978 atoken.lastTransactionSequence = transactionSequence;
6979 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
6980 atoken.startingDisplayed = false;
6981 }
6982 if ((w.isOnScreen() || w.mAttrs.type
6983 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
6984 && !w.mExiting && !w.mDestroying) {
6985 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006986 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006987 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006988 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006989 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006990 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006991 + " pv=" + w.mPolicyVisibility
6992 + " dp=" + w.mDrawPending
6993 + " cdp=" + w.mCommitDrawPending
6994 + " ah=" + w.mAttachedHidden
6995 + " th=" + atoken.hiddenRequested
6996 + " a=" + w.mAnimating);
6997 }
6998 }
6999 if (w != atoken.startingWindow) {
7000 if (!atoken.freezingScreen || !w.mAppFreezing) {
7001 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007002 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007004 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007005 "tokenMayBeDrawn: " + atoken
7006 + " freezingScreen=" + atoken.freezingScreen
7007 + " mAppFreezing=" + w.mAppFreezing);
7008 tokenMayBeDrawn = true;
7009 }
7010 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007011 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 atoken.startingDisplayed = true;
7013 }
7014 }
7015 } else if (w.mReadyToShow) {
7016 w.performShowLocked();
7017 }
7018 }
7019
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007020 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007021
7022 if (tokenMayBeDrawn) {
7023 // See if any windows have been drawn, so they (and others
7024 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007025 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007026 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007027 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007028 if (wtoken.freezingScreen) {
7029 int numInteresting = wtoken.numInterestingWindows;
7030 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007031 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007032 "allDrawn: " + wtoken
7033 + " interesting=" + numInteresting
7034 + " drawn=" + wtoken.numDrawnWindows);
7035 wtoken.showAllWindowsLocked();
7036 unsetAppFreezingScreenLocked(wtoken, false, true);
7037 orientationChangeComplete = true;
7038 }
7039 } else if (!wtoken.allDrawn) {
7040 int numInteresting = wtoken.numInterestingWindows;
7041 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007042 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007043 "allDrawn: " + wtoken
7044 + " interesting=" + numInteresting
7045 + " drawn=" + wtoken.numDrawnWindows);
7046 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007047 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007048
7049 // We can now show all of the drawn windows!
7050 if (!mOpeningApps.contains(wtoken)) {
7051 wtoken.showAllWindowsLocked();
7052 }
7053 }
7054 }
7055 }
7056 }
7057
7058 // If we are ready to perform an app transition, check through
7059 // all of the app tokens to be shown and see if they are ready
7060 // to go.
7061 if (mAppTransitionReady) {
7062 int NN = mOpeningApps.size();
7063 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007064 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007065 "Checking " + NN + " opening apps (frozen="
7066 + mDisplayFrozen + " timeout="
7067 + mAppTransitionTimeout + ")...");
7068 if (!mDisplayFrozen && !mAppTransitionTimeout) {
7069 // If the display isn't frozen, wait to do anything until
7070 // all of the apps are ready. Otherwise just go because
7071 // we'll unfreeze the display when everyone is ready.
7072 for (i=0; i<NN && goodToGo; i++) {
7073 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007074 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007075 "Check opening app" + wtoken + ": allDrawn="
7076 + wtoken.allDrawn + " startingDisplayed="
7077 + wtoken.startingDisplayed);
7078 if (!wtoken.allDrawn && !wtoken.startingDisplayed
7079 && !wtoken.startingMoved) {
7080 goodToGo = false;
7081 }
7082 }
7083 }
7084 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007085 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 int transit = mNextAppTransition;
7087 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007088 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007089 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007090 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007092 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007093 mAppTransitionTimeout = false;
7094 mStartingIconInTransition = false;
7095 mSkipAppTransitionAnimation = false;
7096
7097 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
7098
Dianne Hackborna8f60182009-09-01 19:01:50 -07007099 // If there are applications waiting to come to the
7100 // top of the stack, now is the time to move their windows.
7101 // (Note that we don't do apps going to the bottom
7102 // here -- we want to keep their windows in the old
7103 // Z-order until the animation completes.)
7104 if (mToTopApps.size() > 0) {
7105 NN = mAppTokens.size();
7106 for (i=0; i<NN; i++) {
7107 AppWindowToken wtoken = mAppTokens.get(i);
7108 if (wtoken.sendingToTop) {
7109 wtoken.sendingToTop = false;
7110 moveAppWindowsLocked(wtoken, NN, false);
7111 }
7112 }
7113 mToTopApps.clear();
7114 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007115
Dianne Hackborn25994b42009-09-04 14:21:19 -07007116 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007117
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007118 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007119 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007120
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007121 // The top-most window will supply the layout params,
7122 // and we will determine it below.
7123 LayoutParams animLp = null;
7124 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007125 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007126
Joe Onorato8a9b2202010-02-26 18:56:32 -08007127 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007128 "New wallpaper target=" + mWallpaperTarget
7129 + ", lower target=" + mLowerWallpaperTarget
7130 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07007131 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007132 // Do a first pass through the tokens for two
7133 // things:
7134 // (1) Determine if both the closing and opening
7135 // app token sets are wallpaper targets, in which
7136 // case special animations are needed
7137 // (since the wallpaper needs to stay static
7138 // behind them).
7139 // (2) Find the layout params of the top-most
7140 // application window in the tokens, which is
7141 // what will control the animation theme.
7142 final int NC = mClosingApps.size();
7143 NN = NC + mOpeningApps.size();
7144 for (i=0; i<NN; i++) {
7145 AppWindowToken wtoken;
7146 int mode;
7147 if (i < NC) {
7148 wtoken = mClosingApps.get(i);
7149 mode = 1;
7150 } else {
7151 wtoken = mOpeningApps.get(i-NC);
7152 mode = 2;
7153 }
7154 if (mLowerWallpaperTarget != null) {
7155 if (mLowerWallpaperTarget.mAppToken == wtoken
7156 || mUpperWallpaperTarget.mAppToken == wtoken) {
7157 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007158 }
7159 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007160 if (wtoken.appFullscreen) {
7161 WindowState ws = wtoken.findMainWindow();
7162 if (ws != null) {
7163 // If this is a compatibility mode
7164 // window, we will always use its anim.
7165 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
7166 animLp = ws.mAttrs;
7167 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007168 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007169 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08007170 bestAnimLayer = ws.mLayer;
7171 }
7172 fullscreenAnim = true;
7173 }
7174 } else if (!fullscreenAnim) {
7175 WindowState ws = wtoken.findMainWindow();
7176 if (ws != null) {
7177 if (ws.mLayer > bestAnimLayer) {
7178 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007179 bestAnimLayer = ws.mLayer;
7180 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07007181 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007182 }
7183 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007184
Dianne Hackborn25994b42009-09-04 14:21:19 -07007185 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007186 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007187 "Wallpaper animation!");
7188 switch (transit) {
7189 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
7190 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
7191 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
7192 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
7193 break;
7194 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
7195 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
7196 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
7197 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
7198 break;
7199 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007200 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007201 "New transit: " + transit);
7202 } else if (oldWallpaper != null) {
7203 // We are transitioning from an activity with
7204 // a wallpaper to one without.
7205 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007206 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007207 "New transit away from wallpaper: " + transit);
7208 } else if (mWallpaperTarget != null) {
7209 // We are transitioning from an activity without
7210 // a wallpaper to now showing the wallpaper
7211 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007212 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07007213 "New transit into wallpaper: " + transit);
7214 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007215
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007216 // If all closing windows are obscured, then there is
7217 // no need to do an animation. This is the case, for
7218 // example, when this transition is being done behind
7219 // the lock screen.
7220 if (!mPolicy.allowAppAnimationsLw()) {
7221 animLp = null;
7222 }
7223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007224 NN = mOpeningApps.size();
7225 for (i=0; i<NN; i++) {
7226 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007227 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228 "Now opening app" + wtoken);
7229 wtoken.reportedVisible = false;
7230 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07007231 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007232 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007233 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07007234 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007235 wtoken.showAllWindowsLocked();
7236 }
7237 NN = mClosingApps.size();
7238 for (i=0; i<NN; i++) {
7239 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007240 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007241 "Now closing app" + wtoken);
7242 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07007243 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007244 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007245 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07007246 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007247 // Force the allDrawn flag, because we want to start
7248 // this guy's animations regardless of whether it's
7249 // gotten drawn.
7250 wtoken.allDrawn = true;
7251 }
7252
Dianne Hackborn8b571a82009-09-25 16:09:43 -07007253 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 mOpeningApps.clear();
7256 mClosingApps.clear();
7257
7258 // This has changed the visibility of windows, so perform
7259 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007260 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
7261 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07007263 if (!moveInputMethodWindowsIfNeededLocked(true)) {
7264 assignLayersLocked();
7265 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08007266 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
7267 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007268 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007269 }
7270 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007271
Dianne Hackborn16064f92010-03-25 00:47:24 -07007272 int adjResult = 0;
7273
Dianne Hackborna8f60182009-09-01 19:01:50 -07007274 if (!animating && mAppTransitionRunning) {
7275 // We have finished the animation of an app transition. To do
7276 // this, we have delayed a lot of operations like showing and
7277 // hiding apps, moving apps in Z-order, etc. The app token list
7278 // reflects the correct Z-order, but the window list may now
7279 // be out of sync with it. So here we will just rebuild the
7280 // entire app window list. Fun!
7281 mAppTransitionRunning = false;
7282 // Clear information about apps that were moving.
7283 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007284
Dianne Hackborna8f60182009-09-01 19:01:50 -07007285 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007286 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007287 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007288 moveInputMethodWindowsIfNeededLocked(false);
7289 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08007290 // Since the window list has been rebuilt, focus might
7291 // have to be recomputed since the actual order of windows
7292 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007293 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07007294 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007295
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007296 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007297 // At this point, there was a window with a wallpaper that
7298 // was force hiding other windows behind it, but now it
7299 // is going away. This may be simple -- just animate
7300 // away the wallpaper and its window -- or it may be
7301 // hard -- the wallpaper now needs to be shown behind
7302 // something that was hidden.
7303 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007304 if (mLowerWallpaperTarget != null
7305 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007306 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007307 "wallpaperForceHiding changed with lower="
7308 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007309 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007310 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
7311 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
7312 if (mLowerWallpaperTarget.mAppToken.hidden) {
7313 // The lower target has become hidden before we
7314 // actually started the animation... let's completely
7315 // re-evaluate everything.
7316 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007317 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007318 }
7319 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07007320 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007321 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007322 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007323 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007324 + " NEW: " + mWallpaperTarget
7325 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007326 if (mLowerWallpaperTarget == null) {
7327 // Whoops, we don't need a special wallpaper animation.
7328 // Clear them out.
7329 forceHiding = false;
7330 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07007331 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007332 if (w.mSurface != null) {
7333 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07007334 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007335 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007336 forceHiding = true;
7337 } else if (mPolicy.canBeForceHidden(w, attrs)) {
7338 if (!w.mAnimating) {
7339 // We set the animation above so it
7340 // is not yet running.
7341 w.clearAnimation();
7342 }
7343 }
7344 }
7345 }
7346 }
7347 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007348
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08007349 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
7350 if (DEBUG_WALLPAPER) Slog.v(TAG,
7351 "Detached wallpaper changed from " + mWindowDetachedWallpaper
7352 + windowDetachedWallpaper);
7353 mWindowDetachedWallpaper = windowDetachedWallpaper;
7354 wallpaperMayChange = true;
7355 }
7356
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007357 if (windowAnimationBackgroundColor != 0) {
7358 if (mWindowAnimationBackgroundSurface == null) {
7359 mWindowAnimationBackgroundSurface = new DimSurface(mFxSession);
7360 }
7361 mWindowAnimationBackgroundSurface.show(dw, dh,
7362 windowAnimationBackground.mAnimLayer - LAYER_OFFSET_DIM,
7363 windowAnimationBackgroundColor);
7364 } else if (mWindowAnimationBackgroundSurface != null) {
7365 mWindowAnimationBackgroundSurface.hide();
7366 }
7367
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007368 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007369 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007370 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07007371 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007372 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007373
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007374 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007375 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007376 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007377 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007378 assignLayersLocked();
7379 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007380 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007381 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007382 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007383 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007384
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007385 if (mFocusMayChange) {
7386 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08007387 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
7388 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007389 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007390 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007391 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007392 }
7393
7394 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007395 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007396 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007397
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007398 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
7399 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007400 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401
7402 // THIRD LOOP: Update the surfaces of all windows.
7403
7404 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
7405
7406 boolean obscured = false;
7407 boolean blurring = false;
7408 boolean dimming = false;
7409 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007410 boolean syswin = false;
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007411 boolean backgroundFillerWasShown = mBackgroundFillerTarget != null;
7412 mBackgroundFillerTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07007414 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007416 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07007417 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418
7419 boolean displayed = false;
7420 final WindowManager.LayoutParams attrs = w.mAttrs;
7421 final int attrFlags = attrs.flags;
7422
7423 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007424 // XXX NOTE: The logic here could be improved. We have
7425 // the decision about whether to resize a window separated
7426 // from whether to hide the surface. This can cause us to
7427 // resize a surface even if we are going to hide it. You
7428 // can see this by (1) holding device in landscape mode on
7429 // home screen; (2) tapping browser icon (device will rotate
7430 // to landscape; (3) tap home. The wallpaper will be resized
7431 // in step 2 but then immediately hidden, causing us to
7432 // have to resize and then redraw it again in step 3. It
7433 // would be nice to figure out how to avoid this, but it is
7434 // difficult because we do need to resize surfaces in some
7435 // cases while they are hidden such as when first showing a
7436 // window.
7437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08007439 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 TAG, "Placing surface #" + i + " " + w.mSurface
7441 + ": new=" + w.mShownFrame + ", old="
7442 + w.mLastShownFrame);
7443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 int width, height;
7445 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 // for a scaled surface, we just want to use
7447 // the requested size.
7448 width = w.mRequestedWidth;
7449 height = w.mRequestedHeight;
7450 w.mLastRequestedWidth = width;
7451 w.mLastRequestedHeight = height;
7452 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 width = w.mShownFrame.width();
7455 height = w.mShownFrame.height();
7456 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007457 }
7458
Jeff Brownfbae7222011-01-23 13:07:25 -08007459 if (w.mSurface != null) {
7460 if (w.mSurfaceX != w.mShownFrame.left
7461 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007462 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007463 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -08007464 "POS " + w.mShownFrame.left
7465 + ", " + w.mShownFrame.top, null);
7466 w.mSurfaceX = w.mShownFrame.left;
7467 w.mSurfaceY = w.mShownFrame.top;
7468 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
7469 } catch (RuntimeException e) {
7470 Slog.w(TAG, "Error positioning surface of " + w
7471 + " pos=(" + w.mShownFrame.left
7472 + "," + w.mShownFrame.top + ")", e);
7473 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007474 reclaimSomeSurfaceMemoryLocked(w, "position", true);
Jeff Brownfbae7222011-01-23 13:07:25 -08007475 }
7476 }
7477 }
7478
7479 if (width < 1) {
7480 width = 1;
7481 }
7482 if (height < 1) {
7483 height = 1;
7484 }
7485
7486 if (w.mSurfaceW != width || w.mSurfaceH != height) {
7487 try {
7488 if (SHOW_TRANSACTIONS) logSurface(w,
7489 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007490 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007491 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007492 w.mSurfaceW = width;
7493 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 } catch (RuntimeException e) {
7496 // If something goes wrong with the surface (such
7497 // as running out of memory), don't take down the
7498 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -08007499 Slog.e(TAG, "Error resizing surface of " + w
7500 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007502 reclaimSomeSurfaceMemoryLocked(w, "size", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 }
7504 }
7505 }
7506 }
Jeff Brownfbae7222011-01-23 13:07:25 -08007507
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007508 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007509 w.mContentInsetsChanged =
7510 !w.mLastContentInsets.equals(w.mContentInsets);
7511 w.mVisibleInsetsChanged =
7512 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007513 boolean configChanged =
7514 w.mConfiguration != mCurConfiguration
7515 && (w.mConfiguration == null
7516 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007517 if (DEBUG_CONFIGURATION && configChanged) {
7518 Slog.v(TAG, "Win " + w + " config changed: "
7519 + mCurConfiguration);
7520 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007521 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007522 + ": configChanged=" + configChanged
7523 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -08007524 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
7525 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007527 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007528 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007529 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -08007530 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
7531 Slog.v(TAG, "Resize reasons: "
7532 + "frameChanged=" + frameChanged
7533 + " contentInsetsChanged=" + w.mContentInsetsChanged
7534 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
7535 + " surfaceResized=" + w.mSurfaceResized
7536 + " configChanged=" + configChanged);
7537 }
7538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007539 w.mLastFrame.set(w.mFrame);
7540 w.mLastContentInsets.set(w.mContentInsets);
7541 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007542 // If the screen is currently frozen, then keep
7543 // it frozen until this window draws at its new
7544 // orientation.
7545 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007546 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007547 "Resizing while display frozen: " + w);
7548 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007549 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007550 mWindowsFreezingScreen = true;
7551 // XXX should probably keep timeout from
7552 // when we first froze the display.
7553 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
7554 mH.sendMessageDelayed(mH.obtainMessage(
7555 H.WINDOW_FREEZE_TIMEOUT), 2000);
7556 }
7557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 // If the orientation is changing, then we need to
7559 // hold off on unfreezing the display until this
7560 // window has been redrawn; to do that, we need
7561 // to go through the process of getting informed
7562 // by the application when it has finished drawing.
7563 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007564 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 "Orientation start waiting for draw in "
7566 + w + ", surface " + w.mSurface);
7567 w.mDrawPending = true;
7568 w.mCommitDrawPending = false;
7569 w.mReadyToShow = false;
7570 if (w.mAppToken != null) {
7571 w.mAppToken.allDrawn = false;
7572 }
7573 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007574 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 "Resizing window " + w + " to " + w.mFrame);
7576 mResizingWindows.add(w);
7577 } else if (w.mOrientationChanging) {
7578 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007579 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 "Orientation not waiting for draw in "
7581 + w + ", surface " + w.mSurface);
7582 w.mOrientationChanging = false;
7583 }
7584 }
7585 }
7586
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007587 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 if (!w.mLastHidden) {
7589 //dump();
7590 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007591 if (SHOW_TRANSACTIONS) logSurface(w,
7592 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007594 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007595 try {
7596 w.mSurface.hide();
7597 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007598 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 }
7600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007601 }
7602 // If we are waiting for this window to handle an
7603 // orientation change, well, it is hidden, so
7604 // doesn't really matter. Note that this does
7605 // introduce a potential glitch if the window
7606 // becomes unhidden before it has drawn for the
7607 // new orientation.
7608 if (w.mOrientationChanging) {
7609 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007610 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 "Orientation change skips hidden " + w);
7612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007613 } else if (w.mLastLayer != w.mAnimLayer
7614 || w.mLastAlpha != w.mShownAlpha
7615 || w.mLastDsDx != w.mDsDx
7616 || w.mLastDtDx != w.mDtDx
7617 || w.mLastDsDy != w.mDsDy
7618 || w.mLastDtDy != w.mDtDy
7619 || w.mLastHScale != w.mHScale
7620 || w.mLastVScale != w.mVScale
7621 || w.mLastHidden) {
7622 displayed = true;
7623 w.mLastAlpha = w.mShownAlpha;
7624 w.mLastLayer = w.mAnimLayer;
7625 w.mLastDsDx = w.mDsDx;
7626 w.mLastDtDx = w.mDtDx;
7627 w.mLastDsDy = w.mDsDy;
7628 w.mLastDtDy = w.mDtDy;
7629 w.mLastHScale = w.mHScale;
7630 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007631 if (SHOW_TRANSACTIONS) logSurface(w,
7632 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007633 + " matrix=[" + (w.mDsDx*w.mHScale)
7634 + "," + (w.mDtDx*w.mVScale)
7635 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007636 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007637 if (w.mSurface != null) {
7638 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007639 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007641 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007642 w.mSurface.setLayer(w.mAnimLayer);
7643 w.mSurface.setMatrix(
7644 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
7645 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
7646 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007647 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007648 if (!recoveringMemory) {
Dianne Hackborn64825172011-03-02 21:32:58 -08007649 reclaimSomeSurfaceMemoryLocked(w, "update", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007650 }
7651 }
7652 }
7653
7654 if (w.mLastHidden && !w.mDrawPending
7655 && !w.mCommitDrawPending
7656 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007657 if (SHOW_TRANSACTIONS) logSurface(w,
7658 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007659 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007660 + " during relayout");
7661 if (showSurfaceRobustlyLocked(w)) {
7662 w.mHasDrawn = true;
7663 w.mLastHidden = false;
7664 } else {
7665 w.mOrientationChanging = false;
7666 }
7667 }
7668 if (w.mSurface != null) {
7669 w.mToken.hasVisible = true;
7670 }
7671 } else {
7672 displayed = true;
7673 }
7674
7675 if (displayed) {
7676 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08007677 if (attrs.width == LayoutParams.MATCH_PARENT
7678 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007679 covered = true;
7680 }
7681 }
7682 if (w.mOrientationChanging) {
7683 if (w.mDrawPending || w.mCommitDrawPending) {
7684 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007685 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 "Orientation continue waiting for draw in " + w);
7687 } else {
7688 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007689 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 "Orientation change complete in " + w);
7691 }
7692 }
7693 w.mToken.hasVisible = true;
7694 }
7695 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007696 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007697 "Orientation change skips hidden " + w);
7698 w.mOrientationChanging = false;
7699 }
7700
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007701 if (w.mContentChanged) {
7702 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
7703 w.mContentChanged = false;
7704 }
7705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 final boolean canBeSeen = w.isDisplayedLw();
7707
7708 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
7709 focusDisplayed = true;
7710 }
7711
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007712 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007713
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007714 if (mBackgroundFillerTarget != null) {
7715 if (w.isAnimating()) {
7716 // Background filler is below all other windows that
7717 // are animating.
7718 mBackgroundFillerTarget = w;
7719 } else if (w.mIsWallpaper) {
7720 mBackgroundFillerTarget = w;
7721 }
7722 }
7723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007725 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007726 if (w.mSurface != null) {
7727 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
7728 holdScreen = w.mSession;
7729 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007730 if (!syswin && w.mAttrs.screenBrightness >= 0
7731 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007732 screenBrightness = w.mAttrs.screenBrightness;
7733 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05007734 if (!syswin && w.mAttrs.buttonBrightness >= 0
7735 && buttonBrightness < 0) {
7736 buttonBrightness = w.mAttrs.buttonBrightness;
7737 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05007738 if (canBeSeen
7739 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
7740 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
7741 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07007742 syswin = true;
7743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007744 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007745
Dianne Hackborn25994b42009-09-04 14:21:19 -07007746 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
7747 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007748 // This window completely covers everything behind it,
7749 // so we want to leave all of them as unblurred (for
7750 // performance reasons).
7751 obscured = true;
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007752 } else if (w.needsBackgroundFiller(dw, dh) && (canBeSeen || w.isAnimating())) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007753 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007754 obscured = true;
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007755 mBackgroundFillerTarget = w;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007756 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007757 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007758 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 + ": blurring=" + blurring
7760 + " obscured=" + obscured
7761 + " displayed=" + displayed);
7762 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
7763 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007764 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007766 if (mDimAnimator == null) {
7767 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007768 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007769 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007770 mDimAnimator.updateParameters(mContext.getResources(),
7771 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007772 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007773 }
7774 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
7775 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007776 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007778 if (mBlurSurface == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007779 try {
Romain Guy06882f82009-06-10 13:36:04 -07007780 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007781 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007782 -1, 16, 16,
7783 PixelFormat.OPAQUE,
7784 Surface.FX_SURFACE_BLUR);
7785 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007786 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007787 }
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007788 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7789 + mBlurSurface + ": CREATE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007791 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007792 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7793 + mBlurSurface + ": pos=(0,0) (" +
7794 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007795 mBlurSurface.setPosition(0, 0);
7796 mBlurSurface.setSize(dw, dh);
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007797 mBlurSurface.setLayer(w.mAnimLayer-LAYER_OFFSET_BLUR);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007798 if (!mBlurShown) {
7799 try {
7800 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
7801 + mBlurSurface + ": SHOW");
7802 mBlurSurface.show();
7803 } catch (RuntimeException e) {
7804 Slog.w(TAG, "Failure showing blur surface", e);
7805 }
7806 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 }
7808 }
7809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007810 }
7811 }
7812 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007813
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007814 if (obscuredChanged && mWallpaperTarget == w) {
7815 // This is the wallpaper target and its obscured state
7816 // changed... make sure the current wallaper's visibility
7817 // has been updated accordingly.
7818 updateWallpaperVisibilityLocked();
7819 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007820 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007821
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007822 if (mBackgroundFillerTarget != null) {
7823 if (mBackgroundFillerSurface == null) {
7824 try {
7825 mBackgroundFillerSurface = new Surface(mFxSession, 0,
7826 "BackGroundFiller",
7827 0, dw, dh,
7828 PixelFormat.OPAQUE,
7829 Surface.FX_SURFACE_NORMAL);
7830 } catch (Exception e) {
7831 Slog.e(TAG, "Exception creating filler surface", e);
7832 }
7833 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7834 + mBackgroundFillerSurface + ": CREATE");
7835 }
7836 try {
7837 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7838 + mBackgroundFillerSurface + " SHOW: pos=(0,0) ("
7839 + dw + "x" + dh + ") layer="
7840 + (mBackgroundFillerTarget.mLayer - 1));
7841 mBackgroundFillerSurface.setPosition(0, 0);
7842 mBackgroundFillerSurface.setSize(dw, dh);
7843 // Using the same layer as Dim because they will never be shown at the
7844 // same time. NOTE: we do NOT use mAnimLayer, because we don't
7845 // want this surface dragged up in front of stuff that is animating.
Dianne Hackbornde75cb42011-03-02 17:11:21 -08007846 mBackgroundFillerSurface.setLayer(mBackgroundFillerTarget.mLayer
7847 - LAYER_OFFSET_DIM);
Dianne Hackbornac1471a2011-02-03 13:46:06 -08007848 mBackgroundFillerSurface.show();
7849 } catch (RuntimeException e) {
7850 Slog.e(TAG, "Exception showing filler surface");
7851 }
7852 } else if (backgroundFillerWasShown) {
7853 mBackgroundFillerTarget = null;
7854 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
7855 + mBackgroundFillerSurface + " HIDE");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007856 try {
7857 mBackgroundFillerSurface.hide();
7858 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007859 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007860 }
7861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007863 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007864 animating |= mDimAnimator.updateSurface(dimming, currentTime,
7865 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 }
Romain Guy06882f82009-06-10 13:36:04 -07007867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007869 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 + ": HIDE");
7871 try {
7872 mBlurSurface.hide();
7873 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007874 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007875 }
7876 mBlurShown = false;
7877 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007878 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007879 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 }
7881
7882 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07007883
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007884 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
7885
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07007886 if (mWatermark != null) {
7887 mWatermark.drawIfNeeded();
7888 }
7889
Joe Onorato8a9b2202010-02-26 18:56:32 -08007890 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007891 "With display frozen, orientationChangeComplete="
7892 + orientationChangeComplete);
7893 if (orientationChangeComplete) {
7894 if (mWindowsFreezingScreen) {
7895 mWindowsFreezingScreen = false;
7896 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
7897 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007898 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007899 }
Romain Guy06882f82009-06-10 13:36:04 -07007900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 i = mResizingWindows.size();
7902 if (i > 0) {
7903 do {
7904 i--;
7905 WindowState win = mResizingWindows.get(i);
7906 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007907 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
7908 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007909 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007910 boolean configChanged =
7911 win.mConfiguration != mCurConfiguration
7912 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007913 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
7914 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
7915 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007916 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007917 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007918 + " / " + mCurConfiguration + " / 0x"
7919 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007920 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07007921 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007922 win.mClient.resized(win.mFrame.width(),
7923 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007924 win.mLastVisibleInsets, win.mDrawPending,
7925 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007926 win.mContentInsetsChanged = false;
7927 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08007928 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 } catch (RemoteException e) {
7930 win.mOrientationChanging = false;
7931 }
7932 } while (i > 0);
7933 mResizingWindows.clear();
7934 }
Romain Guy06882f82009-06-10 13:36:04 -07007935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007937 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007938 i = mDestroySurface.size();
7939 if (i > 0) {
7940 do {
7941 i--;
7942 WindowState win = mDestroySurface.get(i);
7943 win.mDestroying = false;
7944 if (mInputMethodWindow == win) {
7945 mInputMethodWindow = null;
7946 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007947 if (win == mWallpaperTarget) {
7948 wallpaperDestroyed = true;
7949 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007950 win.destroySurfaceLocked();
7951 } while (i > 0);
7952 mDestroySurface.clear();
7953 }
7954
7955 // Time to remove any exiting tokens?
7956 for (i=mExitingTokens.size()-1; i>=0; i--) {
7957 WindowToken token = mExitingTokens.get(i);
7958 if (!token.hasVisible) {
7959 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007960 if (token.windowType == TYPE_WALLPAPER) {
7961 mWallpaperTokens.remove(token);
7962 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007963 }
7964 }
7965
7966 // Time to remove any exiting applications?
7967 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
7968 AppWindowToken token = mExitingAppTokens.get(i);
7969 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07007970 // Make sure there is no animation running on this token,
7971 // so any windows associated with it will be removed as
7972 // soon as their animations are complete
7973 token.animation = null;
7974 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007975 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
7976 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 mAppTokens.remove(token);
7978 mExitingAppTokens.remove(i);
7979 }
7980 }
7981
Dianne Hackborna8f60182009-09-01 19:01:50 -07007982 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007983
Dianne Hackborna8f60182009-09-01 19:01:50 -07007984 if (!animating && mAppTransitionRunning) {
7985 // We have finished the animation of an app transition. To do
7986 // this, we have delayed a lot of operations like showing and
7987 // hiding apps, moving apps in Z-order, etc. The app token list
7988 // reflects the correct Z-order, but the window list may now
7989 // be out of sync with it. So here we will just rebuild the
7990 // entire app window list. Fun!
7991 mAppTransitionRunning = false;
7992 needRelayout = true;
7993 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07007994 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07007995 // Clear information about apps that were moving.
7996 mToBottomApps.clear();
7997 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007999 if (focusDisplayed) {
8000 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
8001 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008002 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008003 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008004 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008005 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008006 requestAnimationLocked(0);
8007 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008008 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
8009 }
Jeff Browneb857f12010-07-16 10:06:33 -07008010
Jeff Brown3a22cd92011-01-21 13:59:04 -08008011 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -08008012 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -07008013
Jeff Brown8e03b752010-06-13 19:16:55 -07008014 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -08008015 if (!mDisplayFrozen) {
8016 if (screenBrightness < 0 || screenBrightness > 1.0f) {
8017 mPowerManager.setScreenBrightnessOverride(-1);
8018 } else {
8019 mPowerManager.setScreenBrightnessOverride((int)
8020 (screenBrightness * Power.BRIGHTNESS_ON));
8021 }
8022 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
8023 mPowerManager.setButtonBrightnessOverride(-1);
8024 } else {
8025 mPowerManager.setButtonBrightnessOverride((int)
8026 (buttonBrightness * Power.BRIGHTNESS_ON));
8027 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008028 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008029 if (holdScreen != mHoldingScreenOn) {
8030 mHoldingScreenOn = holdScreen;
8031 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
8032 mH.sendMessage(m);
8033 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008034
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008035 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008036 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008037 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
8038 LocalPowerManager.BUTTON_EVENT, true);
8039 mTurnOnScreen = false;
8040 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008041
Dianne Hackborn50660e22011-02-02 17:12:25 -08008042 if (screenRotationFinished && mScreenRotationAnimation != null) {
8043 mScreenRotationAnimation.kill();
8044 mScreenRotationAnimation = null;
8045 }
8046
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008047 if (updateRotation) {
8048 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
8049 boolean changed = setRotationUncheckedLocked(
8050 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
8051 if (changed) {
Dianne Hackborn3e4f9d02011-02-04 14:05:55 -08008052 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008053 }
8054 }
8055
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008056 // Check to see if we are now in a state where the screen should
8057 // be enabled, because the window obscured flags have changed.
8058 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008059 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07008060
8061 /**
8062 * Must be called with the main window manager lock held.
8063 */
8064 void setHoldScreenLocked(boolean holding) {
8065 boolean state = mHoldingScreenWakeLock.isHeld();
8066 if (holding != state) {
8067 if (holding) {
8068 mHoldingScreenWakeLock.acquire();
8069 } else {
8070 mPolicy.screenOnStoppedLw();
8071 mHoldingScreenWakeLock.release();
8072 }
8073 }
8074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008075
8076 void requestAnimationLocked(long delay) {
8077 if (!mAnimationPending) {
8078 mAnimationPending = true;
8079 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
8080 }
8081 }
Romain Guy06882f82009-06-10 13:36:04 -07008082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008083 /**
8084 * Have the surface flinger show a surface, robustly dealing with
8085 * error conditions. In particular, if there is not enough memory
8086 * to show the surface, then we will try to get rid of other surfaces
8087 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07008088 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 * @return Returns true if the surface was successfully shown.
8090 */
8091 boolean showSurfaceRobustlyLocked(WindowState win) {
8092 try {
8093 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07008094 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008095 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008096 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008097 if (DEBUG_VISIBILITY) Slog.v(TAG,
8098 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008099 win.mTurnOnScreen = false;
8100 mTurnOnScreen = true;
8101 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008102 }
8103 return true;
8104 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008105 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008106 }
Romain Guy06882f82009-06-10 13:36:04 -07008107
Dianne Hackborn64825172011-03-02 21:32:58 -08008108 reclaimSomeSurfaceMemoryLocked(win, "show", true);
Romain Guy06882f82009-06-10 13:36:04 -07008109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008110 return false;
8111 }
Romain Guy06882f82009-06-10 13:36:04 -07008112
Dianne Hackborn64825172011-03-02 21:32:58 -08008113 boolean reclaimSomeSurfaceMemoryLocked(WindowState win, String operation, boolean secure) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008114 final Surface surface = win.mSurface;
Dianne Hackborn64825172011-03-02 21:32:58 -08008115 boolean leakedSurface = false;
8116 boolean killedApps = false;
Romain Guy06882f82009-06-10 13:36:04 -07008117
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008118 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008119 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07008120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 if (mForceRemoves == null) {
8122 mForceRemoves = new ArrayList<WindowState>();
8123 }
Romain Guy06882f82009-06-10 13:36:04 -07008124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 long callingIdentity = Binder.clearCallingIdentity();
8126 try {
8127 // There was some problem... first, do a sanity check of the
8128 // window list to make sure we haven't left any dangling surfaces
8129 // around.
8130 int N = mWindows.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08008131 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008132 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008133 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 if (ws.mSurface != null) {
8135 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008136 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 + ws + " surface=" + ws.mSurface
8138 + " token=" + win.mToken
8139 + " pid=" + ws.mSession.mPid
8140 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008141 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008142 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008143 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008144 ws.mSurface = null;
8145 mForceRemoves.add(ws);
8146 i--;
8147 N--;
8148 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008149 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008150 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 + ws + " surface=" + ws.mSurface
8152 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008153 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008154 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008155 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008156 ws.mSurface = null;
8157 leakedSurface = true;
8158 }
8159 }
8160 }
Romain Guy06882f82009-06-10 13:36:04 -07008161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008163 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008164 SparseIntArray pidCandidates = new SparseIntArray();
8165 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008166 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008167 if (ws.mSurface != null) {
8168 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
8169 }
8170 }
8171 if (pidCandidates.size() > 0) {
8172 int[] pids = new int[pidCandidates.size()];
8173 for (int i=0; i<pids.length; i++) {
8174 pids[i] = pidCandidates.keyAt(i);
8175 }
8176 try {
Dianne Hackborn64825172011-03-02 21:32:58 -08008177 if (mActivityManager.killPids(pids, "Free memory", secure)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008178 killedApps = true;
8179 }
8180 } catch (RemoteException e) {
8181 }
8182 }
8183 }
Romain Guy06882f82009-06-10 13:36:04 -07008184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008185 if (leakedSurface || killedApps) {
8186 // We managed to reclaim some memory, so get rid of the trouble
8187 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08008188 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008190 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008191 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07008192 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008193 win.mSurface = null;
8194 }
Romain Guy06882f82009-06-10 13:36:04 -07008195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008196 try {
8197 win.mClient.dispatchGetNewSurface();
8198 } catch (RemoteException e) {
8199 }
8200 }
8201 } finally {
8202 Binder.restoreCallingIdentity(callingIdentity);
8203 }
Dianne Hackborn64825172011-03-02 21:32:58 -08008204
8205 return leakedSurface || killedApps;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008206 }
Romain Guy06882f82009-06-10 13:36:04 -07008207
Jeff Brown3a22cd92011-01-21 13:59:04 -08008208 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008209 WindowState newFocus = computeFocusedWindowLocked();
8210 if (mCurrentFocus != newFocus) {
8211 // This check makes sure that we don't already have the focus
8212 // change message pending.
8213 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
8214 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008215 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008216 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
8217 final WindowState oldFocus = mCurrentFocus;
8218 mCurrentFocus = newFocus;
8219 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07008220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008221 final WindowState imWindow = mInputMethodWindow;
8222 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008223 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008224 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008225 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
8226 mLayoutNeeded = true;
8227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008228 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08008229 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008230 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
8231 // Client will do the layout, but we need to assign layers
8232 // for handleNewWindowLocked() below.
8233 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008234 }
8235 }
Jeff Brown349703e2010-06-22 01:27:15 -07008236
8237 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
8238 // If we defer assigning layers, then the caller is responsible for
8239 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -08008240 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08008241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008242 return true;
8243 }
8244 return false;
8245 }
Jeff Brown349703e2010-06-22 01:27:15 -07008246
Jeff Brown3a22cd92011-01-21 13:59:04 -08008247 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
8248 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -07008249 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250
8251 private WindowState computeFocusedWindowLocked() {
8252 WindowState result = null;
8253 WindowState win;
8254
8255 int i = mWindows.size() - 1;
8256 int nextAppIndex = mAppTokens.size()-1;
8257 WindowToken nextApp = nextAppIndex >= 0
8258 ? mAppTokens.get(nextAppIndex) : null;
8259
8260 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008261 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008262
Joe Onorato8a9b2202010-02-26 18:56:32 -08008263 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008264 TAG, "Looking for focus: " + i
8265 + " = " + win
8266 + ", flags=" + win.mAttrs.flags
8267 + ", canReceive=" + win.canReceiveKeys());
8268
8269 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07008270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008271 // If this window's application has been removed, just skip it.
8272 if (thisApp != null && thisApp.removed) {
8273 i--;
8274 continue;
8275 }
Romain Guy06882f82009-06-10 13:36:04 -07008276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008277 // If there is a focused app, don't allow focus to go to any
8278 // windows below it. If this is an application window, step
8279 // through the app tokens until we find its app.
8280 if (thisApp != null && nextApp != null && thisApp != nextApp
8281 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
8282 int origAppIndex = nextAppIndex;
8283 while (nextAppIndex > 0) {
8284 if (nextApp == mFocusedApp) {
8285 // Whoops, we are below the focused app... no focus
8286 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08008287 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008288 TAG, "Reached focused app: " + mFocusedApp);
8289 return null;
8290 }
8291 nextAppIndex--;
8292 nextApp = mAppTokens.get(nextAppIndex);
8293 if (nextApp == thisApp) {
8294 break;
8295 }
8296 }
8297 if (thisApp != nextApp) {
8298 // Uh oh, the app token doesn't exist! This shouldn't
8299 // happen, but if it does we can get totally hosed...
8300 // so restart at the original app.
8301 nextAppIndex = origAppIndex;
8302 nextApp = mAppTokens.get(nextAppIndex);
8303 }
8304 }
8305
8306 // Dispatch to this window if it is wants key events.
8307 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008308 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008309 TAG, "Found focus @ " + i + " = " + win);
8310 result = win;
8311 break;
8312 }
8313
8314 i--;
8315 }
8316
8317 return result;
8318 }
8319
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008320 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 if (mDisplayFrozen) {
8322 return;
8323 }
Romain Guy06882f82009-06-10 13:36:04 -07008324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008325 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07008326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008327 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08008328 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008329 if (mFreezeGcPending != 0) {
8330 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008331 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008332 mH.removeMessages(H.FORCE_GC);
8333 Runtime.getRuntime().gc();
8334 mFreezeGcPending = now;
8335 }
8336 } else {
8337 mFreezeGcPending = now;
8338 }
Romain Guy06882f82009-06-10 13:36:04 -07008339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07008341
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008342 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07008343
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008344 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
8345 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008346 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008347 mAppTransitionReady = true;
8348 }
Romain Guy06882f82009-06-10 13:36:04 -07008349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008350 if (PROFILE_ORIENTATION) {
8351 File file = new File("/data/system/frozen");
8352 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
8353 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008354
8355 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08008356 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
8357 mScreenRotationAnimation.kill();
8358 mScreenRotationAnimation = null;
8359 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008360 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08008361 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08008362 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -08008363 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008364 if (!mScreenRotationAnimation.hasScreenshot()) {
8365 Surface.freezeDisplay(0);
8366 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008367 } else {
8368 Surface.freezeDisplay(0);
8369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008370 }
Romain Guy06882f82009-06-10 13:36:04 -07008371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008372 private void stopFreezingDisplayLocked() {
8373 if (!mDisplayFrozen) {
8374 return;
8375 }
Romain Guy06882f82009-06-10 13:36:04 -07008376
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008377 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
8378 return;
8379 }
8380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008381 mDisplayFrozen = false;
8382 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
8383 if (PROFILE_ORIENTATION) {
8384 Debug.stopMethodTracing();
8385 }
Dianne Hackborna1111872010-11-23 20:55:11 -08008386
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008387 boolean updateRotation = false;
8388
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008389 if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
8390 && mScreenRotationAnimation.hasScreenshot()) {
8391 if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION,
8392 mTransitionAnimationScale)) {
8393 requestAnimationLocked(0);
8394 } else {
8395 mScreenRotationAnimation = null;
8396 updateRotation = true;
Dianne Hackborna1111872010-11-23 20:55:11 -08008397 }
8398 } else {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008399 if (mScreenRotationAnimation != null) {
8400 mScreenRotationAnimation.kill();
8401 mScreenRotationAnimation = null;
8402 }
8403 updateRotation = true;
Dianne Hackborna1111872010-11-23 20:55:11 -08008404 Surface.unfreezeDisplay(0);
8405 }
Romain Guy06882f82009-06-10 13:36:04 -07008406
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008407 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008408
Dianne Hackborn420829e2011-01-28 11:30:35 -08008409 boolean configChanged;
8410
Christopher Tateb696aee2010-04-02 19:08:30 -07008411 // While the display is frozen we don't re-compute the orientation
8412 // to avoid inconsistent states. However, something interesting
8413 // could have actually changed during that time so re-evaluate it
8414 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -08008415 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -07008416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417 // A little kludge: a lot could have happened while the
8418 // display was frozen, so now that we are coming back we
8419 // do a gc so that any remote references the system
8420 // processes holds on others can be released if they are
8421 // no longer needed.
8422 mH.removeMessages(H.FORCE_GC);
8423 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8424 2000);
Romain Guy06882f82009-06-10 13:36:04 -07008425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008426 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008427
8428 if (updateRotation) {
8429 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -08008430 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008431 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -08008432 }
8433
8434 if (configChanged) {
8435 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008436 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 }
Romain Guy06882f82009-06-10 13:36:04 -07008438
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008439 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
8440 DisplayMetrics dm) {
8441 if (index < tokens.length) {
8442 String str = tokens[index];
8443 if (str != null && str.length() > 0) {
8444 try {
8445 int val = Integer.parseInt(str);
8446 return val;
8447 } catch (Exception e) {
8448 }
8449 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008450 }
8451 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
8452 return defDps;
8453 }
8454 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
8455 return val;
8456 }
8457
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008458 void createWatermark() {
8459 if (mWatermark != null) {
8460 return;
8461 }
8462
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008463 File file = new File("/system/etc/setup.conf");
8464 FileInputStream in = null;
8465 try {
8466 in = new FileInputStream(file);
8467 DataInputStream ind = new DataInputStream(in);
8468 String line = ind.readLine();
8469 if (line != null) {
8470 String[] toks = line.split("%");
8471 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -07008472 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07008473 }
8474 }
8475 } catch (FileNotFoundException e) {
8476 } catch (IOException e) {
8477 } finally {
8478 if (in != null) {
8479 try {
8480 in.close();
8481 } catch (IOException e) {
8482 }
8483 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008484 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008485 }
8486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008487 @Override
Joe Onorato664644d2011-01-23 17:53:23 -08008488 public void statusBarVisibilityChanged(int visibility) {
Jeff Brown05dc66a2011-03-02 14:41:58 -08008489 mInputManager.setSystemUiVisibility(visibility);
Joe Onorato664644d2011-01-23 17:53:23 -08008490 synchronized (mWindowMap) {
8491 final int N = mWindows.size();
8492 for (int i = 0; i < N; i++) {
8493 WindowState ws = mWindows.get(i);
8494 try {
8495 if (ws.getAttrs().hasSystemUiListeners) {
8496 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
8497 }
8498 } catch (RemoteException e) {
8499 // so sorry
8500 }
8501 }
8502 }
8503 }
8504
8505 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
8507 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
8508 != PackageManager.PERMISSION_GRANTED) {
8509 pw.println("Permission Denial: can't dump WindowManager from from pid="
8510 + Binder.getCallingPid()
8511 + ", uid=" + Binder.getCallingUid());
8512 return;
8513 }
Romain Guy06882f82009-06-10 13:36:04 -07008514
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008515 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -08008516 pw.println(" ");
8517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 synchronized(mWindowMap) {
8519 pw.println("Current Window Manager state:");
8520 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008521 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008522 pw.print(" Window #"); pw.print(i); pw.print(' ');
8523 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008524 w.dump(pw, " ");
8525 }
8526 if (mInputMethodDialogs.size() > 0) {
8527 pw.println(" ");
8528 pw.println(" Input method dialogs:");
8529 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
8530 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008531 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008532 }
8533 }
8534 if (mPendingRemove.size() > 0) {
8535 pw.println(" ");
8536 pw.println(" Remove pending for:");
8537 for (int i=mPendingRemove.size()-1; i>=0; i--) {
8538 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008539 pw.print(" Remove #"); 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 }
8544 if (mForceRemoves != null && mForceRemoves.size() > 0) {
8545 pw.println(" ");
8546 pw.println(" Windows force removing:");
8547 for (int i=mForceRemoves.size()-1; i>=0; i--) {
8548 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008549 pw.print(" Removing #"); pw.print(i); pw.print(' ');
8550 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008551 w.dump(pw, " ");
8552 }
8553 }
8554 if (mDestroySurface.size() > 0) {
8555 pw.println(" ");
8556 pw.println(" Windows waiting to destroy their surface:");
8557 for (int i=mDestroySurface.size()-1; i>=0; i--) {
8558 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008559 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
8560 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 w.dump(pw, " ");
8562 }
8563 }
8564 if (mLosingFocus.size() > 0) {
8565 pw.println(" ");
8566 pw.println(" Windows losing focus:");
8567 for (int i=mLosingFocus.size()-1; i>=0; i--) {
8568 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008569 pw.print(" Losing #"); pw.print(i); pw.print(' ');
8570 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008571 w.dump(pw, " ");
8572 }
8573 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008574 if (mResizingWindows.size() > 0) {
8575 pw.println(" ");
8576 pw.println(" Windows waiting to resize:");
8577 for (int i=mResizingWindows.size()-1; i>=0; i--) {
8578 WindowState w = mResizingWindows.get(i);
8579 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
8580 pw.print(w); pw.println(":");
8581 w.dump(pw, " ");
8582 }
8583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008584 if (mSessions.size() > 0) {
8585 pw.println(" ");
8586 pw.println(" All active sessions:");
8587 Iterator<Session> it = mSessions.iterator();
8588 while (it.hasNext()) {
8589 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008590 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008591 s.dump(pw, " ");
8592 }
8593 }
8594 if (mTokenMap.size() > 0) {
8595 pw.println(" ");
8596 pw.println(" All tokens:");
8597 Iterator<WindowToken> it = mTokenMap.values().iterator();
8598 while (it.hasNext()) {
8599 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008600 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008601 token.dump(pw, " ");
8602 }
8603 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008604 if (mWallpaperTokens.size() > 0) {
8605 pw.println(" ");
8606 pw.println(" Wallpaper tokens:");
8607 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
8608 WindowToken token = mWallpaperTokens.get(i);
8609 pw.print(" Wallpaper #"); pw.print(i);
8610 pw.print(' '); pw.print(token); pw.println(':');
8611 token.dump(pw, " ");
8612 }
8613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008614 if (mAppTokens.size() > 0) {
8615 pw.println(" ");
8616 pw.println(" Application tokens in Z order:");
8617 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008618 pw.print(" App #"); pw.print(i); pw.print(": ");
8619 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 }
8621 }
8622 if (mFinishedStarting.size() > 0) {
8623 pw.println(" ");
8624 pw.println(" Finishing start of application tokens:");
8625 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
8626 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008627 pw.print(" Finished Starting #"); pw.print(i);
8628 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 token.dump(pw, " ");
8630 }
8631 }
8632 if (mExitingTokens.size() > 0) {
8633 pw.println(" ");
8634 pw.println(" Exiting tokens:");
8635 for (int i=mExitingTokens.size()-1; i>=0; i--) {
8636 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008637 pw.print(" Exiting #"); pw.print(i);
8638 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008639 token.dump(pw, " ");
8640 }
8641 }
8642 if (mExitingAppTokens.size() > 0) {
8643 pw.println(" ");
8644 pw.println(" Exiting application tokens:");
8645 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
8646 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008647 pw.print(" Exiting App #"); pw.print(i);
8648 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008649 token.dump(pw, " ");
8650 }
8651 }
8652 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008653 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
8654 pw.print(" mLastFocus="); pw.println(mLastFocus);
8655 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
8656 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
8657 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -07008658 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -07008659 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
8660 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
8661 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
8662 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08008663 if (mWindowDetachedWallpaper != null) {
8664 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
8665 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008666 if (mWindowAnimationBackgroundSurface != null) {
8667 pw.println(" mWindowAnimationBackgroundSurface:");
8668 mWindowAnimationBackgroundSurface.printTo(" ", pw);
8669 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008670 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
8671 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
8672 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008673 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
8674 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
8675 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
8676 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008677 if (mDimAnimator != null) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -08008678 pw.println(" mDimAnimator:");
8679 mDimAnimator.printTo(" ", pw);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008680 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -08008681 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008682 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008683 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008684 pw.print(mInputMethodAnimLayerAdjustment);
8685 pw.print(" mWallpaperAnimLayerAdjustment=");
8686 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -07008687 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
8688 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008689 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
8690 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008691 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
8692 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008693 pw.print(" mRotation="); pw.print(mRotation);
8694 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
8695 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -08008696 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
8697 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008698 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
8699 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
8700 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
8701 pw.print(" mNextAppTransition=0x");
8702 pw.print(Integer.toHexString(mNextAppTransition));
8703 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008704 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008705 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008706 if (mNextAppTransitionPackage != null) {
8707 pw.print(" mNextAppTransitionPackage=");
8708 pw.print(mNextAppTransitionPackage);
8709 pw.print(", mNextAppTransitionEnter=0x");
8710 pw.print(Integer.toHexString(mNextAppTransitionEnter));
8711 pw.print(", mNextAppTransitionExit=0x");
8712 pw.print(Integer.toHexString(mNextAppTransitionExit));
8713 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008714 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
8715 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
8716 if (mOpeningApps.size() > 0) {
8717 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
8718 }
8719 if (mClosingApps.size() > 0) {
8720 pw.print(" mClosingApps="); pw.println(mClosingApps);
8721 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008722 if (mToTopApps.size() > 0) {
8723 pw.print(" mToTopApps="); pw.println(mToTopApps);
8724 }
8725 if (mToBottomApps.size() > 0) {
8726 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
8727 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -08008728 if (mDisplay != null) {
8729 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
8730 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
8731 } else {
8732 pw.println(" NO DISPLAY");
8733 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008734 pw.println(" Policy:");
8735 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008736 }
8737 }
8738
Jeff Brown349703e2010-06-22 01:27:15 -07008739 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 public void monitor() {
8741 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -05008742 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07008743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008744
Jeff Brown2992ea72011-01-28 22:04:14 -08008745 public interface OnHardKeyboardStatusChangeListener {
8746 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
8747 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008748}