blob: b7a276f7657089b45a37b4a8797ab8321e067676 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
32import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070035import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37import com.android.internal.app.IBatteryStats;
38import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080039import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070040import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import com.android.internal.view.IInputContext;
42import com.android.internal.view.IInputMethodClient;
43import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080044import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import com.android.server.am.BatteryStatsService;
46
47import android.Manifest;
48import android.app.ActivityManagerNative;
49import android.app.IActivityManager;
Joe Onoratoac0ee892011-01-30 15:38:30 -080050import android.app.StatusBarManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070053import android.content.ClipData;
54import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070056import android.content.Intent;
57import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080062import android.content.res.Resources;
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;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070068import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.graphics.Rect;
70import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070071import android.graphics.Typeface;
72import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.BatteryStats;
74import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070075import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.Debug;
77import android.os.Handler;
78import android.os.IBinder;
79import android.os.LocalPowerManager;
80import android.os.Looper;
81import android.os.Message;
82import android.os.Parcel;
83import android.os.ParcelFileDescriptor;
84import android.os.Power;
85import android.os.PowerManager;
86import android.os.Process;
87import android.os.RemoteException;
88import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070089import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.os.SystemClock;
91import android.os.SystemProperties;
92import android.os.TokenWatcher;
93import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070094import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070096import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080097import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070099import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700101import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.Gravity;
103import android.view.IApplicationToken;
104import android.view.IOnKeyguardExitResult;
105import android.view.IRotationWatcher;
106import android.view.IWindow;
107import android.view.IWindowManager;
108import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700109import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700111import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700112import android.view.InputHandler;
113import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.KeyEvent;
115import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116import android.view.Surface;
117import android.view.SurfaceSession;
118import android.view.View;
119import android.view.ViewTreeObserver;
120import android.view.WindowManager;
121import android.view.WindowManagerImpl;
122import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700123import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700125import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import android.view.animation.Animation;
127import android.view.animation.AnimationUtils;
128import android.view.animation.Transformation;
129
130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800153 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 static final boolean DEBUG_FOCUS = false;
155 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800156 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800157 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 static final boolean DEBUG_LAYERS = false;
159 static final boolean DEBUG_INPUT = false;
160 static final boolean DEBUG_INPUT_METHOD = false;
161 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700162 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800163 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700165 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 static final boolean DEBUG_APP_TRANSITIONS = false;
167 static final boolean DEBUG_STARTING_WINDOW = false;
168 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700169 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800170 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700172 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 static final boolean PROFILE_ORIENTATION = false;
175 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700176 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to multiply the policy's type layer, to reserve room
179 * for multiple windows of the same type and Z-ordering adjustment
180 * with TYPE_LAYER_OFFSET. */
181 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
184 * or below others in the same layer. */
185 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 /** How much to increment the layer for each window, to reserve room
188 * for effect surfaces between them.
189 */
190 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 /** The maximum length we will accept for a loaded animation duration:
193 * this is 10 seconds.
194 */
195 static final int MAX_ANIMATION_DURATION = 10*1000;
196
197 /** Amount of time (in milliseconds) to animate the dim surface from one
198 * value to another, when no window animation is driving it.
199 */
200 static final int DEFAULT_DIM_DURATION = 200;
201
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700202 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
203 * compatible windows.
204 */
205 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
206
Dianne Hackborna1111872010-11-23 20:55:11 -0800207 /**
208 * If true, the window manager will do its own custom freezing and general
209 * management of the screen during rotation.
210 */
211 static final boolean CUSTOM_SCREEN_ROTATION = true;
212
Jeff Brown7fbdc842010-06-17 20:52:56 -0700213 // Maximum number of milliseconds to wait for input event injection.
214 // FIXME is this value reasonable?
215 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800216
217 // Maximum number of milliseconds to wait for input devices to be enumerated before
218 // proceding with safe mode detection.
219 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700220
221 // Default input dispatching timeout in nanoseconds.
222 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 static final int UPDATE_FOCUS_NORMAL = 0;
225 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
226 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
227 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700230 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
232 /**
233 * Condition waited on by {@link #reenableKeyguard} to know the call to
234 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500235 * This is set to true only if mKeyguardTokenWatcher.acquired() has
236 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500238 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239
Jim Miller284b62e2010-06-08 14:27:42 -0700240 private static final int ALLOW_DISABLE_YES = 1;
241 private static final int ALLOW_DISABLE_NO = 0;
242 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
243 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
244
Mike Lockwood983ee092009-11-22 01:42:24 -0500245 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
246 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700248 if (shouldAllowDisableKeyguard()) {
249 mPolicy.enableKeyguard(false);
250 mKeyguardDisabled = true;
251 } else {
252 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
255 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700256 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500257 synchronized (mKeyguardTokenWatcher) {
258 mKeyguardDisabled = false;
259 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 }
261 }
262 };
263
Jim Miller284b62e2010-06-08 14:27:42 -0700264 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
265 @Override
266 public void onReceive(Context context, Intent intent) {
267 mPolicy.enableKeyguard(true);
268 synchronized(mKeyguardTokenWatcher) {
269 // lazily evaluate this next time we're asked to disable keyguard
270 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
271 mKeyguardDisabled = false;
272 }
273 }
274 };
275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 final Context mContext;
277
278 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
283
284 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700287
David 'Digit' Turner910a0682011-02-05 00:34:46 +0100288 private static final boolean mInEmulator = SystemProperties.get("ro.kernel.qemu").equals("1");
289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 /**
291 * All currently active sessions with clients.
292 */
293 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 /**
296 * Mapping from an IWindow IBinder to the server's Window object.
297 * This is also used as the lock for all of our state.
298 */
299 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
300
301 /**
302 * Mapping from a token IBinder to a WindowToken object.
303 */
304 final HashMap<IBinder, WindowToken> mTokenMap =
305 new HashMap<IBinder, WindowToken>();
306
307 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 * Window tokens that are in the process of exiting, but still
309 * on screen for animations.
310 */
311 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
312
313 /**
314 * Z-ordered (bottom-most first) list of all application tokens, for
315 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800316 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 */
318 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
319
320 /**
321 * Application tokens that are in the process of exiting, but still
322 * on screen for animations.
323 */
324 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
325
326 /**
327 * List of window tokens that have finished starting their application,
328 * and now need to have the policy remove their windows.
329 */
330 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
331
332 /**
333 * Z-ordered (bottom-most first) list of all Window objects.
334 */
Jeff Browne33348b2010-07-15 23:54:05 -0700335 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
337 /**
338 * Windows that are being resized. Used so we can tell the client about
339 * the resize after closing the transaction in which we resized the
340 * underlying surface.
341 */
342 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
343
344 /**
345 * Windows whose animations have ended and now must be removed.
346 */
347 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
348
349 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800350 * Used when processing mPendingRemove to avoid working on the original array.
351 */
352 WindowState[] mPendingRemoveTmp = new WindowState[20];
353
354 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 * Windows whose surface should be destroyed.
356 */
357 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
358
359 /**
360 * Windows that have lost input focus and are waiting for the new
361 * focus window to be displayed before they are told about this.
362 */
363 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
364
365 /**
366 * This is set when we have run out of memory, and will either be an empty
367 * list or contain windows that need to be force removed.
368 */
369 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700370
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800371 /**
372 * Used when rebuilding window list to keep track of windows that have
373 * been removed.
374 */
375 WindowState[] mRebuildTmp = new WindowState[20];
376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700380 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 Surface mBlurSurface;
382 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700383 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800384 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800385 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 final float[] mTmpFloats = new float[9];
390
391 boolean mSafeMode;
392 boolean mDisplayEnabled = false;
393 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700394 int mInitialDisplayWidth = 0;
395 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 int mRotation = 0;
397 int mRequestedRotation = 0;
398 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700399 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 ArrayList<IRotationWatcher> mRotationWatchers
401 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800402 int mDeferredRotation;
403 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 boolean mLayoutNeeded = true;
406 boolean mAnimationPending = false;
407 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800408 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 boolean mWindowsFreezingScreen = false;
410 long mFreezeGcPending = 0;
411 int mAppsFreezingScreen = 0;
412
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800413 int mLayoutSeq = 0;
414
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800415 // State while inside of layoutAndPlaceSurfacesLocked().
416 boolean mFocusMayChange;
417
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800418 Configuration mCurConfiguration = new Configuration();
419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 // This is held as long as we have the screen frozen, to give us time to
421 // perform a rotation animation when turning off shows the lock screen which
422 // changes the orientation.
423 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 // State management of app transitions. When we are preparing for a
426 // transition, mNextAppTransition will be the kind of transition to
427 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
428 // mOpeningApps and mClosingApps are the lists of tokens that will be
429 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700430 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700431 String mNextAppTransitionPackage;
432 int mNextAppTransitionEnter;
433 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700435 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 boolean mAppTransitionTimeout = false;
437 boolean mStartingIconInTransition = false;
438 boolean mSkipAppTransitionAnimation = false;
439 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
440 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700441 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
442 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 H mH = new H();
447
448 WindowState mCurrentFocus = null;
449 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 // This just indicates the window the input method is on top of, not
452 // necessarily the window its input is going to.
453 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 boolean mInputMethodTargetWaitingAnim;
455 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 WindowState mInputMethodWindow = null;
458 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
459
Jeff Brown2992ea72011-01-28 22:04:14 -0800460 boolean mHardKeyboardAvailable;
461 boolean mHardKeyboardEnabled;
462 OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
463
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700464 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800465
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700466 // If non-null, this is the currently visible window that is associated
467 // with the wallpaper.
468 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700469 // If non-null, we are in the middle of animating from one wallpaper target
470 // to another, and this is the lower one in Z-order.
471 WindowState mLowerWallpaperTarget = null;
472 // If non-null, we are in the middle of animating from one wallpaper target
473 // to another, and this is the higher one in Z-order.
474 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800475 // Window currently running an animation that has requested it be detached
476 // from the wallpaper. This means we need to ensure the wallpaper is
477 // visible behind it in case it animates in a way that would allow it to be
478 // seen.
479 WindowState mWindowDetachedWallpaper = 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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700511 * Drag/drop state
512 */
513 class DragState {
514 IBinder mToken;
515 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800516 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700517 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700518 ClipData mData;
519 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700520 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700521 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700522 float mThumbOffsetX, mThumbOffsetY;
523 InputChannel mServerChannel, mClientChannel;
524 WindowState mTargetWindow;
525 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700526 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700527
Jeff Brownfbf09772011-01-16 14:06:57 -0800528 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700529
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800530 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700531 mToken = token;
532 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800533 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700534 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700535 mNotifiedWindows = new ArrayList<WindowState>();
536 }
537
538 void reset() {
539 if (mSurface != null) {
540 mSurface.destroy();
541 }
542 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800543 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700544 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700545 mToken = null;
546 mData = null;
547 mThumbOffsetX = mThumbOffsetY = 0;
548 mNotifiedWindows = null;
549 }
550
551 void register() {
552 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
553 if (mClientChannel != null) {
554 Slog.e(TAG, "Duplicate register of drag input channel");
555 } else {
556 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
557 mServerChannel = channels[0];
558 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800559 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700560 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
561 mH.getLooper().getQueue());
562 }
563 }
564
565 void unregister() {
566 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
567 if (mClientChannel == null) {
568 Slog.e(TAG, "Unregister of nonexistent drag input channel");
569 } else {
570 mInputManager.unregisterInputChannel(mServerChannel);
571 InputQueue.unregisterInputChannel(mClientChannel);
572 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700573 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700574 mClientChannel = null;
575 mServerChannel = null;
576 }
577 }
578
Chris Tatea32dcf72010-10-14 12:13:50 -0700579 int getDragLayerLw() {
580 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
581 * TYPE_LAYER_MULTIPLIER
582 + TYPE_LAYER_OFFSET;
583 }
584
Christopher Tatea53146c2010-09-07 11:57:52 -0700585 /* call out to each visible window/session informing it about the drag
586 */
Chris Tateb8203e92010-10-12 14:23:21 -0700587 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 // Cache a base-class instance of the clip metadata so that parceling
589 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800590 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700591 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700592 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700593
594 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700595 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700596 }
597
Christopher Tate2c095f32010-10-04 14:13:40 -0700598 final int N = mWindows.size();
599 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700600 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700601 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700602 }
603
604 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
605 * designated window is potentially a drop recipient. There are race situations
606 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
607 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700608 *
609 * This method clones the 'event' parameter if it's being delivered to the same
610 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700611 */
Chris Tateb478f462010-10-15 16:02:26 -0700612 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
613 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700614 // Don't actually send the event if the drag is supposed to be pinned
615 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800616 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700617 final IBinder winBinder = newWin.mClient.asBinder();
618 if (winBinder != mLocalWin) {
619 if (DEBUG_DRAG) {
620 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
621 }
622 return;
623 }
624 }
625
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700626 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700627 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
628 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800629 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700630 try {
631 newWin.mClient.dispatchDragEvent(event);
632 // track each window that we've notified that the drag is starting
633 mNotifiedWindows.add(newWin);
634 } catch (RemoteException e) {
635 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700636 } finally {
637 // if the callee was local, the dispatch has already recycled the event
638 if (Process.myPid() != newWin.mSession.mPid) {
639 event.recycle();
640 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700641 }
642 }
643 }
644
645 /* helper - construct and send a DRAG_STARTED event only if the window has not
646 * previously been notified, i.e. it became visible after the drag operation
647 * was begun. This is a rare case.
648 */
649 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700650 if (mDragInProgress) {
651 // If we have sent the drag-started, we needn't do so again
652 for (WindowState ws : mNotifiedWindows) {
653 if (ws == newWin) {
654 return;
655 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700656 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700657 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700658 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700659 }
Chris Tateb478f462010-10-15 16:02:26 -0700660 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700661 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700662 }
663
Chris Tated4533f142010-10-19 15:15:08 -0700664 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700665 if (DEBUG_DRAG) {
666 Slog.d(TAG, "broadcasting DRAG_ENDED");
667 }
Chris Tated4533f142010-10-19 15:15:08 -0700668 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800669 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700670 for (WindowState ws: mNotifiedWindows) {
671 try {
672 ws.mClient.dispatchDragEvent(evt);
673 } catch (RemoteException e) {
674 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700675 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700676 }
Chris Tated4533f142010-10-19 15:15:08 -0700677 mNotifiedWindows.clear();
678 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700679 evt.recycle();
680 }
681
Chris Tated4533f142010-10-19 15:15:08 -0700682 void endDragLw() {
683 mDragState.broadcastDragEndedLw();
684
685 // stop intercepting input
686 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -0800687 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tated4533f142010-10-19 15:15:08 -0700688
689 // free our resources and drop all the object references
690 mDragState.reset();
691 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800692
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800693 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
694 boolean changed = setRotationUncheckedLocked(
695 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
696 if (changed) {
Dianne Hackborn3e4f9d042011-02-04 14:05:55 -0800697 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Christopher Tateccd24de2011-01-12 15:02:55 -0800698 }
Chris Tated4533f142010-10-19 15:15:08 -0700699 }
700
Christopher Tatea53146c2010-09-07 11:57:52 -0700701 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700702 final int myPid = Process.myPid();
703
704 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800705 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800706 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800707 try {
708 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
Dianne Hackbornac1471a2011-02-03 13:46:06 -0800709 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG "
710 + mSurface + ": pos=(" +
711 (int)(x - mThumbOffsetX) + "," + (int)(y - mThumbOffsetY) + ")");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800712 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800713 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800714 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
715 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700716
717 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700718 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800719 if (touchedWin == null) {
720 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
721 return;
722 }
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800723 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700724 final IBinder touchedBinder = touchedWin.mClient.asBinder();
725 if (touchedBinder != mLocalWin) {
726 // This drag is pinned only to the originating window, but the drag
727 // point is outside that window. Pretend it's over empty space.
728 touchedWin = null;
729 }
730 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700731 try {
732 // have we dragged over a new window?
733 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
734 if (DEBUG_DRAG) {
735 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
736 }
737 // force DRAG_EXITED_EVENT if appropriate
738 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700739 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800740 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700741 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700742 if (myPid != mTargetWindow.mSession.mPid) {
743 evt.recycle();
744 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700745 }
746 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700747 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700748 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
749 }
750 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700751 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800752 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700753 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700754 if (myPid != touchedWin.mSession.mPid) {
755 evt.recycle();
756 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700757 }
758 } catch (RemoteException e) {
759 Slog.w(TAG, "can't send drag notification to windows");
760 }
761 mTargetWindow = touchedWin;
762 }
763
Chris Tated4533f142010-10-19 15:15:08 -0700764 // Tell the drop target about the data. Returns 'true' if we can immediately
765 // dispatch the global drag-ended message, 'false' if we need to wait for a
766 // result from the recipient.
767 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700768 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700769 if (touchedWin == null) {
770 // "drop" outside a valid window -- no recipient to apply a
771 // timeout to, and we can send the drag-ended message immediately.
772 mDragResult = false;
773 return true;
774 }
775
776 if (DEBUG_DRAG) {
777 Slog.d(TAG, "sending DROP to " + touchedWin);
778 }
779 final int myPid = Process.myPid();
780 final IBinder token = touchedWin.mClient.asBinder();
781 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
782 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800783 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700784 try {
785 touchedWin.mClient.dispatchDragEvent(evt);
786
787 // 5 second timeout for this window to respond to the drop
788 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
789 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
790 mH.sendMessageDelayed(msg, 5000);
791 } catch (RemoteException e) {
792 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
793 return true;
794 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700795 if (myPid != touchedWin.mSession.mPid) {
796 evt.recycle();
797 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700798 }
Chris Tated4533f142010-10-19 15:15:08 -0700799 mToken = token;
800 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700801 }
802
803 // Find the visible, touch-deliverable window under the given point
804 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
805 WindowState touchedWin = null;
806 final int x = (int) xf;
807 final int y = (int) yf;
808 final ArrayList<WindowState> windows = mWindows;
809 final int N = windows.size();
810 for (int i = N - 1; i >= 0; i--) {
811 WindowState child = windows.get(i);
812 final int flags = child.mAttrs.flags;
813 if (!child.isVisibleLw()) {
814 // not visible == don't tell about drags
815 continue;
816 }
817 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
818 // not touchable == don't tell about drags
819 continue;
820 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800821
822 child.getTouchableRegion(mTmpRegion);
823
Christopher Tatea53146c2010-09-07 11:57:52 -0700824 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800825 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
826 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
827 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700828 // Found it
829 touchedWin = child;
830 break;
831 }
832 }
833
834 return touchedWin;
835 }
836 }
837
838 DragState mDragState = null;
839 private final InputHandler mDragInputHandler = new BaseInputHandler() {
840 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700841 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
842 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700843 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700844 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
845 && mDragState != null) {
846 boolean endDrag = false;
847 final float newX = event.getRawX();
848 final float newY = event.getRawY();
849
Christopher Tatea53146c2010-09-07 11:57:52 -0700850 switch (event.getAction()) {
851 case MotionEvent.ACTION_DOWN: {
852 if (DEBUG_DRAG) {
853 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
854 }
855 } break;
856
857 case MotionEvent.ACTION_MOVE: {
858 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700859 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700860 mDragState.notifyMoveLw(newX, newY);
861 }
862 } break;
863
864 case MotionEvent.ACTION_UP: {
865 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
866 + newX + "," + newY);
867 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700868 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700869 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700870 } break;
871
872 case MotionEvent.ACTION_CANCEL: {
873 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
874 endDrag = true;
875 } break;
876 }
877
878 if (endDrag) {
879 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
880 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700881 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700882 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700883 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700884 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700885
886 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700887 }
888 } catch (Exception e) {
889 Slog.e(TAG, "Exception caught by drag handleMotion", e);
890 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700891 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700892 }
893 }
894 };
895
896 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 * Whether the UI is currently running in touch mode (not showing
898 * navigational focus because the user is directly pressing the screen).
899 */
900 boolean mInTouchMode = false;
901
902 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700903 private ArrayList<WindowChangeListener> mWindowChangeListeners =
904 new ArrayList<WindowChangeListener>();
905 private boolean mWindowsChanged = false;
906
907 public interface WindowChangeListener {
908 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700909 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700910 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911
Dianne Hackbornc485a602009-03-24 22:39:49 -0700912 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700913 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700914
915 // The frame use to limit the size of the app running in compatibility mode.
916 Rect mCompatibleScreenFrame = new Rect();
917 // The surface used to fill the outer rim of the app running in compatibility mode.
918 Surface mBackgroundFillerSurface = null;
Dianne Hackbornac1471a2011-02-03 13:46:06 -0800919 WindowState mBackgroundFillerTarget = null;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 public static WindowManagerService main(Context context,
922 PowerManagerService pm, boolean haveInputMethods) {
923 WMThread thr = new WMThread(context, pm, haveInputMethods);
924 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 synchronized (thr) {
927 while (thr.mService == null) {
928 try {
929 thr.wait();
930 } catch (InterruptedException e) {
931 }
932 }
Jozef BABJAK06e57b52011-01-20 08:09:25 +0100933 return thr.mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 }
Romain Guy06882f82009-06-10 13:36:04 -0700936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 static class WMThread extends Thread {
938 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 private final Context mContext;
941 private final PowerManagerService mPM;
942 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 public WMThread(Context context, PowerManagerService pm,
945 boolean haveInputMethods) {
946 super("WindowManager");
947 mContext = context;
948 mPM = pm;
949 mHaveInputMethods = haveInputMethods;
950 }
Romain Guy06882f82009-06-10 13:36:04 -0700951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 public void run() {
953 Looper.prepare();
954 WindowManagerService s = new WindowManagerService(mContext, mPM,
955 mHaveInputMethods);
956 android.os.Process.setThreadPriority(
957 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700958 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 synchronized (this) {
961 mService = s;
962 notifyAll();
963 }
Romain Guy06882f82009-06-10 13:36:04 -0700964
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700965 // For debug builds, log event loop stalls to dropbox for analysis.
966 if (StrictMode.conditionallyEnableDebugLogging()) {
967 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
968 }
969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 Looper.loop();
971 }
972 }
973
974 static class PolicyThread extends Thread {
975 private final WindowManagerPolicy mPolicy;
976 private final WindowManagerService mService;
977 private final Context mContext;
978 private final PowerManagerService mPM;
979 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 public PolicyThread(WindowManagerPolicy policy,
982 WindowManagerService service, Context context,
983 PowerManagerService pm) {
984 super("WindowManagerPolicy");
985 mPolicy = policy;
986 mService = service;
987 mContext = context;
988 mPM = pm;
989 }
Romain Guy06882f82009-06-10 13:36:04 -0700990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 public void run() {
992 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800993 WindowManagerPolicyThread.set(this, Looper.myLooper());
994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800996 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 android.os.Process.setThreadPriority(
998 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700999 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -07001001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 synchronized (this) {
1003 mRunning = true;
1004 notifyAll();
1005 }
Romain Guy06882f82009-06-10 13:36:04 -07001006
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001007 // For debug builds, log event loop stalls to dropbox for analysis.
1008 if (StrictMode.conditionallyEnableDebugLogging()) {
1009 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1010 }
1011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 Looper.loop();
1013 }
1014 }
1015
1016 private WindowManagerService(Context context, PowerManagerService pm,
1017 boolean haveInputMethods) {
1018 mContext = context;
1019 mHaveInputMethods = haveInputMethods;
1020 mLimitedAlphaCompositing = context.getResources().getBoolean(
1021 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 mPowerManager = pm;
1024 mPowerManager.setPolicy(mPolicy);
1025 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1026 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1027 "SCREEN_FROZEN");
1028 mScreenFrozenLock.setReferenceCounted(false);
1029
1030 mActivityManager = ActivityManagerNative.getDefault();
1031 mBatteryStats = BatteryStatsService.getService();
1032
1033 // Get persisted window scale setting
1034 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1035 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1036 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1037 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001038
Jim Miller284b62e2010-06-08 14:27:42 -07001039 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1040 IntentFilter filter = new IntentFilter();
1041 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1042 mContext.registerReceiver(mBroadcastReceiver, filter);
1043
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001044 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1045 "KEEP_SCREEN_ON_FLAG");
1046 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047
Jeff Browne33348b2010-07-15 23:54:05 -07001048 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1051 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 synchronized (thr) {
1054 while (!thr.mRunning) {
1055 try {
1056 thr.wait();
1057 } catch (InterruptedException e) {
1058 }
1059 }
1060 }
Romain Guy06882f82009-06-10 13:36:04 -07001061
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001062 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 // Add ourself to the Watchdog monitors.
1065 Watchdog.getInstance().addMonitor(this);
1066 }
1067
1068 @Override
1069 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1070 throws RemoteException {
1071 try {
1072 return super.onTransact(code, data, reply, flags);
1073 } catch (RuntimeException e) {
1074 // The window manager only throws security exceptions, so let's
1075 // log all others.
1076 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001077 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 }
1079 throw e;
1080 }
1081 }
1082
Jeff Browne33348b2010-07-15 23:54:05 -07001083 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001085 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 TAG, "Adding window " + window + " at "
1087 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1088 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001089 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 }
1091
Jeff Browne33348b2010-07-15 23:54:05 -07001092 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001094 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 TAG, "Adding window " + window + " at "
1096 + i + " of " + mWindows.size() + " (before " + pos + ")");
1097 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001098 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 }
1100
1101 //This method finds out the index of a window that has the same app token as
1102 //win. used for z ordering the windows in mWindows
1103 private int findIdxBasedOnAppTokens(WindowState win) {
1104 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001105 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 int jmax = localmWindows.size();
1107 if(jmax == 0) {
1108 return -1;
1109 }
1110 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001111 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 if(wentry.mAppToken == win.mAppToken) {
1113 return j;
1114 }
1115 }
1116 return -1;
1117 }
Romain Guy06882f82009-06-10 13:36:04 -07001118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1120 final IWindow client = win.mClient;
1121 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001122 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 final int N = localmWindows.size();
1125 final WindowState attached = win.mAttachedWindow;
1126 int i;
1127 if (attached == null) {
1128 int tokenWindowsPos = token.windows.size();
1129 if (token.appWindowToken != null) {
1130 int index = tokenWindowsPos-1;
1131 if (index >= 0) {
1132 // If this application has existing windows, we
1133 // simply place the new window on top of them... but
1134 // keep the starting window on top.
1135 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1136 // Base windows go behind everything else.
1137 placeWindowBefore(token.windows.get(0), win);
1138 tokenWindowsPos = 0;
1139 } else {
1140 AppWindowToken atoken = win.mAppToken;
1141 if (atoken != null &&
1142 token.windows.get(index) == atoken.startingWindow) {
1143 placeWindowBefore(token.windows.get(index), win);
1144 tokenWindowsPos--;
1145 } else {
1146 int newIdx = findIdxBasedOnAppTokens(win);
1147 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001148 //there is a window above this one associated with the same
1149 //apptoken note that the window could be a floating window
1150 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001152 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1153 Slog.v(TAG, "Adding window " + win + " at "
1154 + (newIdx+1) + " of " + N);
1155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001157 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 }
1160 }
1161 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001162 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 TAG, "Figuring out where to add app window "
1164 + client.asBinder() + " (token=" + token + ")");
1165 // Figure out where the window should go, based on the
1166 // order of applications.
1167 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001168 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 for (i=NA-1; i>=0; i--) {
1170 AppWindowToken t = mAppTokens.get(i);
1171 if (t == token) {
1172 i--;
1173 break;
1174 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001175
Dianne Hackborna8f60182009-09-01 19:01:50 -07001176 // We haven't reached the token yet; if this token
1177 // is not going to the bottom and has windows, we can
1178 // use it as an anchor for when we do reach the token.
1179 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 pos = t.windows.get(0);
1181 }
1182 }
1183 // We now know the index into the apps. If we found
1184 // an app window above, that gives us the position; else
1185 // we need to look some more.
1186 if (pos != null) {
1187 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001188 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 if (atoken != null) {
1190 final int NC = atoken.windows.size();
1191 if (NC > 0) {
1192 WindowState bottom = atoken.windows.get(0);
1193 if (bottom.mSubLayer < 0) {
1194 pos = bottom;
1195 }
1196 }
1197 }
1198 placeWindowBefore(pos, win);
1199 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001200 // Continue looking down until we find the first
1201 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 while (i >= 0) {
1203 AppWindowToken t = mAppTokens.get(i);
1204 final int NW = t.windows.size();
1205 if (NW > 0) {
1206 pos = t.windows.get(NW-1);
1207 break;
1208 }
1209 i--;
1210 }
1211 if (pos != null) {
1212 // Move in front of any windows attached to this
1213 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001214 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 if (atoken != null) {
1216 final int NC = atoken.windows.size();
1217 if (NC > 0) {
1218 WindowState top = atoken.windows.get(NC-1);
1219 if (top.mSubLayer >= 0) {
1220 pos = top;
1221 }
1222 }
1223 }
1224 placeWindowAfter(pos, win);
1225 } else {
1226 // Just search for the start of this layer.
1227 final int myLayer = win.mBaseLayer;
1228 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001229 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 if (w.mBaseLayer > myLayer) {
1231 break;
1232 }
1233 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001234 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1235 Slog.v(TAG, "Adding window " + win + " at "
1236 + i + " of " + N);
1237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001239 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 }
1241 }
1242 }
1243 } else {
1244 // Figure out where window should go, based on layer.
1245 final int myLayer = win.mBaseLayer;
1246 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001247 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 i++;
1249 break;
1250 }
1251 }
1252 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001253 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001254 TAG, "Adding window " + win + " at "
1255 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001257 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 }
1259 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001260 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 token.windows.add(tokenWindowsPos, win);
1262 }
1263
1264 } else {
1265 // Figure out this window's ordering relative to the window
1266 // it is attached to.
1267 final int NA = token.windows.size();
1268 final int sublayer = win.mSubLayer;
1269 int largestSublayer = Integer.MIN_VALUE;
1270 WindowState windowWithLargestSublayer = null;
1271 for (i=0; i<NA; i++) {
1272 WindowState w = token.windows.get(i);
1273 final int wSublayer = w.mSubLayer;
1274 if (wSublayer >= largestSublayer) {
1275 largestSublayer = wSublayer;
1276 windowWithLargestSublayer = w;
1277 }
1278 if (sublayer < 0) {
1279 // For negative sublayers, we go below all windows
1280 // in the same sublayer.
1281 if (wSublayer >= sublayer) {
1282 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001283 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 token.windows.add(i, win);
1285 }
1286 placeWindowBefore(
1287 wSublayer >= 0 ? attached : w, win);
1288 break;
1289 }
1290 } else {
1291 // For positive sublayers, we go above all windows
1292 // in the same sublayer.
1293 if (wSublayer > sublayer) {
1294 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001295 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 token.windows.add(i, win);
1297 }
1298 placeWindowBefore(w, win);
1299 break;
1300 }
1301 }
1302 }
1303 if (i >= NA) {
1304 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001305 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 token.windows.add(win);
1307 }
1308 if (sublayer < 0) {
1309 placeWindowBefore(attached, win);
1310 } else {
1311 placeWindowAfter(largestSublayer >= 0
1312 ? windowWithLargestSublayer
1313 : attached,
1314 win);
1315 }
1316 }
1317 }
Romain Guy06882f82009-06-10 13:36:04 -07001318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 if (win.mAppToken != null && addToToken) {
1320 win.mAppToken.allAppWindows.add(win);
1321 }
1322 }
Romain Guy06882f82009-06-10 13:36:04 -07001323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 static boolean canBeImeTarget(WindowState w) {
1325 final int fl = w.mAttrs.flags
1326 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001327 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
1328 || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
1329 if (DEBUG_INPUT_METHOD) {
1330 Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1331 if (!w.isVisibleOrAdding()) {
1332 Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface
1333 + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
1334 + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
1335 + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
1336 if (w.mAppToken != null) {
1337 Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1338 }
1339 }
1340 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 return w.isVisibleOrAdding();
1342 }
1343 return false;
1344 }
Romain Guy06882f82009-06-10 13:36:04 -07001345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001347 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 final int N = localmWindows.size();
1349 WindowState w = null;
1350 int i = N;
1351 while (i > 0) {
1352 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001353 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001354
Dianne Hackborne75d8722011-01-27 19:37:40 -08001355 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
1356 + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001357 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001358 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 // Yet more tricksyness! If this window is a "starting"
1361 // window, we do actually want to be on top of it, but
1362 // it is not -really- where input will go. So if the caller
1363 // is not actually looking to move the IME, look down below
1364 // for a real window to target...
1365 if (!willMove
1366 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1367 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001368 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1370 i--;
1371 w = wb;
1372 }
1373 }
1374 break;
1375 }
1376 }
Romain Guy06882f82009-06-10 13:36:04 -07001377
Dianne Hackborne75d8722011-01-27 19:37:40 -08001378 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
1379
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001380 // Now, a special case -- if the last target's window is in the
1381 // process of exiting, and is above the new target, keep on the
1382 // last target to avoid flicker. Consider for example a Dialog with
1383 // the IME shown: when the Dialog is dismissed, we want to keep
1384 // the IME above it until it is completely gone so it doesn't drop
1385 // behind the dialog or its full-screen scrim.
1386 if (mInputMethodTarget != null && w != null
1387 && mInputMethodTarget.isDisplayedLw()
1388 && mInputMethodTarget.mExiting) {
1389 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1390 w = mInputMethodTarget;
1391 i = localmWindows.indexOf(w);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001392 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w);
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001393 }
1394 }
Romain Guy06882f82009-06-10 13:36:04 -07001395
Joe Onorato8a9b2202010-02-26 18:56:32 -08001396 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 if (willMove && w != null) {
1400 final WindowState curTarget = mInputMethodTarget;
1401 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001403 // Now some fun for dealing with window animations that
1404 // modify the Z order. We need to look at all windows below
1405 // the current target that are in this app, finding the highest
1406 // visible one in layering.
1407 AppWindowToken token = curTarget.mAppToken;
1408 WindowState highestTarget = null;
1409 int highestPos = 0;
1410 if (token.animating || token.animation != null) {
1411 int pos = 0;
1412 pos = localmWindows.indexOf(curTarget);
1413 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001414 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 if (win.mAppToken != token) {
1416 break;
1417 }
1418 if (!win.mRemoved) {
1419 if (highestTarget == null || win.mAnimLayer >
1420 highestTarget.mAnimLayer) {
1421 highestTarget = win;
1422 highestPos = pos;
1423 }
1424 }
1425 pos--;
1426 }
1427 }
Romain Guy06882f82009-06-10 13:36:04 -07001428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001430 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 + mNextAppTransition + " " + highestTarget
1432 + " animating=" + highestTarget.isAnimating()
1433 + " layer=" + highestTarget.mAnimLayer
1434 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001435
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001436 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 // If we are currently setting up for an animation,
1438 // hold everything until we can find out what will happen.
1439 mInputMethodTargetWaitingAnim = true;
1440 mInputMethodTarget = highestTarget;
1441 return highestPos + 1;
1442 } else if (highestTarget.isAnimating() &&
1443 highestTarget.mAnimLayer > w.mAnimLayer) {
1444 // If the window we are currently targeting is involved
1445 // with an animation, and it is on top of the next target
1446 // we will be over, then hold off on moving until
1447 // that is done.
Dianne Hackborne75d8722011-01-27 19:37:40 -08001448 mInputMethodTargetWaitingAnim = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 mInputMethodTarget = highestTarget;
1450 return highestPos + 1;
1451 }
1452 }
1453 }
1454 }
Romain Guy06882f82009-06-10 13:36:04 -07001455
Joe Onorato8a9b2202010-02-26 18:56:32 -08001456 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 if (w != null) {
1458 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001459 if (DEBUG_INPUT_METHOD) {
1460 RuntimeException e = null;
1461 if (!HIDE_STACK_CRAWLS) {
1462 e = new RuntimeException();
1463 e.fillInStackTrace();
1464 }
1465 Slog.w(TAG, "Moving IM target from "
1466 + mInputMethodTarget + " to " + w, e);
1467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 mInputMethodTarget = w;
Dianne Hackborne75d8722011-01-27 19:37:40 -08001469 mInputMethodTargetWaitingAnim = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 if (w.mAppToken != null) {
1471 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1472 } else {
1473 setInputMethodAnimLayerAdjustment(0);
1474 }
1475 }
1476 return i+1;
1477 }
1478 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001479 if (DEBUG_INPUT_METHOD) {
1480 RuntimeException e = null;
1481 if (!HIDE_STACK_CRAWLS) {
1482 e = new RuntimeException();
1483 e.fillInStackTrace();
1484 }
1485 Slog.w(TAG, "Moving IM target from "
1486 + mInputMethodTarget + " to null", e);
1487 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 mInputMethodTarget = null;
1489 setInputMethodAnimLayerAdjustment(0);
1490 }
1491 return -1;
1492 }
Romain Guy06882f82009-06-10 13:36:04 -07001493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 void addInputMethodWindowToListLocked(WindowState win) {
1495 int pos = findDesiredInputMethodWindowIndexLocked(true);
1496 if (pos >= 0) {
1497 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001498 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001499 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001501 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 moveInputMethodDialogsLocked(pos+1);
1503 return;
1504 }
1505 win.mTargetAppToken = null;
1506 addWindowToListInOrderLocked(win, true);
1507 moveInputMethodDialogsLocked(pos);
1508 }
Romain Guy06882f82009-06-10 13:36:04 -07001509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001511 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 mInputMethodAnimLayerAdjustment = adj;
1513 WindowState imw = mInputMethodWindow;
1514 if (imw != null) {
1515 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001516 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 + " anim layer: " + imw.mAnimLayer);
1518 int wi = imw.mChildWindows.size();
1519 while (wi > 0) {
1520 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001521 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001523 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 + " anim layer: " + cw.mAnimLayer);
1525 }
1526 }
1527 int di = mInputMethodDialogs.size();
1528 while (di > 0) {
1529 di --;
1530 imw = mInputMethodDialogs.get(di);
1531 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001532 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 + " anim layer: " + imw.mAnimLayer);
1534 }
1535 }
Romain Guy06882f82009-06-10 13:36:04 -07001536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1538 int wpos = mWindows.indexOf(win);
1539 if (wpos >= 0) {
1540 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001541 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001543 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 int NC = win.mChildWindows.size();
1545 while (NC > 0) {
1546 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001547 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 int cpos = mWindows.indexOf(cw);
1549 if (cpos >= 0) {
1550 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001551 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001552 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 mWindows.remove(cpos);
1554 }
1555 }
1556 }
1557 return interestingPos;
1558 }
Romain Guy06882f82009-06-10 13:36:04 -07001559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 private void reAddWindowToListInOrderLocked(WindowState win) {
1561 addWindowToListInOrderLocked(win, false);
1562 // This is a hack to get all of the child windows added as well
1563 // at the right position. Child windows should be rare and
1564 // this case should be rare, so it shouldn't be that big a deal.
1565 int wpos = mWindows.indexOf(win);
1566 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001568 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001570 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 reAddWindowLocked(wpos, win);
1572 }
1573 }
Romain Guy06882f82009-06-10 13:36:04 -07001574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 void logWindowList(String prefix) {
1576 int N = mWindows.size();
1577 while (N > 0) {
1578 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001579 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 }
1581 }
Romain Guy06882f82009-06-10 13:36:04 -07001582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 void moveInputMethodDialogsLocked(int pos) {
1584 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001587 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 for (int i=0; i<N; i++) {
1589 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1590 }
1591 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001592 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593 logWindowList(" ");
1594 }
Romain Guy06882f82009-06-10 13:36:04 -07001595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 if (pos >= 0) {
1597 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1598 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001599 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 if (wp == mInputMethodWindow) {
1601 pos++;
1602 }
1603 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001604 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 for (int i=0; i<N; i++) {
1606 WindowState win = dialogs.get(i);
1607 win.mTargetAppToken = targetAppToken;
1608 pos = reAddWindowLocked(pos, win);
1609 }
1610 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001611 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 logWindowList(" ");
1613 }
1614 return;
1615 }
1616 for (int i=0; i<N; i++) {
1617 WindowState win = dialogs.get(i);
1618 win.mTargetAppToken = null;
1619 reAddWindowToListInOrderLocked(win);
1620 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001621 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622 logWindowList(" ");
1623 }
1624 }
1625 }
Romain Guy06882f82009-06-10 13:36:04 -07001626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1628 final WindowState imWin = mInputMethodWindow;
1629 final int DN = mInputMethodDialogs.size();
1630 if (imWin == null && DN == 0) {
1631 return false;
1632 }
Romain Guy06882f82009-06-10 13:36:04 -07001633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1635 if (imPos >= 0) {
1636 // In this case, the input method windows are to be placed
1637 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 // First check to see if the input method windows are already
1640 // located here, and contiguous.
1641 final int N = mWindows.size();
1642 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001643 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 // Figure out the actual input method window that should be
1646 // at the bottom of their stack.
1647 WindowState baseImWin = imWin != null
1648 ? imWin : mInputMethodDialogs.get(0);
1649 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001650 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 if (cw.mSubLayer < 0) baseImWin = cw;
1652 }
Romain Guy06882f82009-06-10 13:36:04 -07001653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 if (firstImWin == baseImWin) {
1655 // The windows haven't moved... but are they still contiguous?
1656 // First find the top IM window.
1657 int pos = imPos+1;
1658 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001659 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 break;
1661 }
1662 pos++;
1663 }
1664 pos++;
1665 // Now there should be no more input method windows above.
1666 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001667 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 break;
1669 }
1670 pos++;
1671 }
1672 if (pos >= N) {
1673 // All is good!
1674 return false;
1675 }
1676 }
Romain Guy06882f82009-06-10 13:36:04 -07001677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 if (imWin != null) {
1679 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001680 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 logWindowList(" ");
1682 }
1683 imPos = tmpRemoveWindowLocked(imPos, imWin);
1684 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001685 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686 logWindowList(" ");
1687 }
1688 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1689 reAddWindowLocked(imPos, imWin);
1690 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001691 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 logWindowList(" ");
1693 }
1694 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1695 } else {
1696 moveInputMethodDialogsLocked(imPos);
1697 }
Romain Guy06882f82009-06-10 13:36:04 -07001698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 } else {
1700 // In this case, the input method windows go in a fixed layer,
1701 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001704 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 tmpRemoveWindowLocked(0, imWin);
1706 imWin.mTargetAppToken = null;
1707 reAddWindowToListInOrderLocked(imWin);
1708 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001709 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 logWindowList(" ");
1711 }
1712 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1713 } else {
1714 moveInputMethodDialogsLocked(-1);;
1715 }
Romain Guy06882f82009-06-10 13:36:04 -07001716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 }
Romain Guy06882f82009-06-10 13:36:04 -07001718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 if (needAssignLayers) {
1720 assignLayersLocked();
1721 }
Romain Guy06882f82009-06-10 13:36:04 -07001722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001723 return true;
1724 }
Romain Guy06882f82009-06-10 13:36:04 -07001725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 void adjustInputMethodDialogsLocked() {
1727 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1728 }
Romain Guy06882f82009-06-10 13:36:04 -07001729
Dianne Hackborn25994b42009-09-04 14:21:19 -07001730 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001731 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001732 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1733 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1734 ? wallpaperTarget.mAppToken.animation : null)
1735 + " upper=" + mUpperWallpaperTarget
1736 + " lower=" + mLowerWallpaperTarget);
1737 return (wallpaperTarget != null
1738 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1739 && wallpaperTarget.mAppToken.animation != null)))
1740 || mUpperWallpaperTarget != null
1741 || mLowerWallpaperTarget != null;
1742 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001743
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001744 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1745 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001746
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001747 int adjustWallpaperWindowsLocked() {
1748 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001749
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001750 final int dw = mDisplay.getWidth();
1751 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001752
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001753 // First find top-most window that has asked to be on top of the
1754 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001755 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001756 int N = localmWindows.size();
1757 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001758 WindowState foundW = null;
1759 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001760 WindowState topCurW = null;
1761 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001762 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001763 int i = N;
1764 while (i > 0) {
1765 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001766 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001767 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1768 if (topCurW == null) {
1769 topCurW = w;
1770 topCurI = i;
1771 }
1772 continue;
1773 }
1774 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001775 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001776 // If this window's app token is hidden and not animating,
1777 // it is of no interest to us.
1778 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001779 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001780 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001781 continue;
1782 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001783 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001784 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001785 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1786 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001787 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001788 && (mWallpaperTarget == w
1789 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001790 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001791 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001792 foundW = w;
1793 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001794 if (w == mWallpaperTarget && ((w.mAppToken != null
1795 && w.mAppToken.animation != null)
1796 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 // The current wallpaper target is animating, so we'll
1798 // look behind it for another possible target and figure
1799 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001800 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001802 continue;
1803 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001804 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001805 } else if (w == mWindowDetachedWallpaper) {
1806 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001807 }
1808 }
1809
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001810 if (foundW == null && windowDetachedI >= 0) {
1811 if (DEBUG_WALLPAPER) Slog.v(TAG,
1812 "Found animating detached wallpaper activity: #" + i + "=" + w);
1813 foundW = w;
1814 foundI = windowDetachedI;
1815 }
1816
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001817 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001818 // If we are currently waiting for an app transition, and either
1819 // the current target or the next target are involved with it,
1820 // then hold off on doing anything with the wallpaper.
1821 // Note that we are checking here for just whether the target
1822 // is part of an app token... which is potentially overly aggressive
1823 // (the app token may not be involved in the transition), but good
1824 // enough (we'll just wait until whatever transition is pending
1825 // executes).
1826 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001827 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001828 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001829 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001830 }
1831 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001833 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001834 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001835 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001836 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001837
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001838 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001839 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001840 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001841 + " oldTarget: " + mWallpaperTarget);
1842 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001843
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001844 mLowerWallpaperTarget = null;
1845 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001846
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001847 WindowState oldW = mWallpaperTarget;
1848 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001849
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001850 // Now what is happening... if the current and new targets are
1851 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001852 if (foundW != null && oldW != null) {
1853 boolean oldAnim = oldW.mAnimation != null
1854 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1855 boolean foundAnim = foundW.mAnimation != null
1856 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001857 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001858 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001859 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001860 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001861 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001862 int oldI = localmWindows.indexOf(oldW);
1863 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001864 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001865 }
1866 if (oldI >= 0) {
1867 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001869 + "=" + oldW + "; new#" + foundI
1870 + "=" + foundW);
1871 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001872
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001873 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001874 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001875 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001876 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001877 }
1878 mWallpaperTarget = oldW;
1879 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001880
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001881 // Now set the upper and lower wallpaper targets
1882 // correctly, and make sure that we are positioning
1883 // the wallpaper below the lower.
1884 if (foundI > oldI) {
1885 // The new target is on top of the old one.
1886 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001887 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001888 }
1889 mUpperWallpaperTarget = foundW;
1890 mLowerWallpaperTarget = oldW;
1891 foundW = oldW;
1892 foundI = oldI;
1893 } else {
1894 // The new target is below the old one.
1895 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001896 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001897 }
1898 mUpperWallpaperTarget = oldW;
1899 mLowerWallpaperTarget = foundW;
1900 }
1901 }
1902 }
1903 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001904
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001905 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001906 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001907 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1908 || (mLowerWallpaperTarget.mAppToken != null
1909 && mLowerWallpaperTarget.mAppToken.animation != null);
1910 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1911 || (mUpperWallpaperTarget.mAppToken != null
1912 && mUpperWallpaperTarget.mAppToken.animation != null);
1913 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001914 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001915 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001916 }
1917 mLowerWallpaperTarget = null;
1918 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001919 }
1920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001921
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001922 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001923 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001924 // The window is visible to the compositor... but is it visible
1925 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001926 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001927 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001928
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001929 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001930 // its layer adjustment. Only do this if we are not transfering
1931 // between two wallpaper targets.
1932 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001933 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001934 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001935
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001936 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1937 * TYPE_LAYER_MULTIPLIER
1938 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001939
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001940 // Now w is the window we are supposed to be behind... but we
1941 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001942 // AND any starting window associated with it, AND below the
1943 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001944 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001945 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001946 if (wb.mBaseLayer < maxLayer &&
1947 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001948 (foundW.mAttachedWindow == null ||
1949 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001950 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001951 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001952 // This window is not related to the previous one in any
1953 // interesting way, so stop here.
1954 break;
1955 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001956 foundW = wb;
1957 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001958 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001959 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001960 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001961 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001962
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001963 if (foundW == null && topCurW != null) {
1964 // There is no wallpaper target, so it goes at the bottom.
1965 // We will assume it is the same place as last time, if known.
1966 foundW = topCurW;
1967 foundI = topCurI+1;
1968 } else {
1969 // Okay i is the position immediately above the wallpaper. Look at
1970 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001971 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001972 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001973
Dianne Hackborn284ac932009-08-28 10:34:25 -07001974 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001975 if (mWallpaperTarget.mWallpaperX >= 0) {
1976 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001977 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001978 }
1979 if (mWallpaperTarget.mWallpaperY >= 0) {
1980 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001981 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001982 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001983 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001984
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001985 // Start stepping backwards from here, ensuring that our wallpaper windows
1986 // are correctly placed.
1987 int curTokenIndex = mWallpaperTokens.size();
1988 while (curTokenIndex > 0) {
1989 curTokenIndex--;
1990 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001991 if (token.hidden == visible) {
1992 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1993 token.hidden = !visible;
1994 // Need to do a layout to ensure the wallpaper now has the
1995 // correct size.
1996 mLayoutNeeded = true;
1997 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001998
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001999 int curWallpaperIndex = token.windows.size();
2000 while (curWallpaperIndex > 0) {
2001 curWallpaperIndex--;
2002 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002003
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002004 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002005 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002006 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002007
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002008 // First, make sure the client has the current visibility
2009 // state.
2010 if (wallpaper.mWallpaperVisible != visible) {
2011 wallpaper.mWallpaperVisible = visible;
2012 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002014 "Setting visibility of wallpaper " + wallpaper
2015 + ": " + visible);
2016 wallpaper.mClient.dispatchAppVisibility(visible);
2017 } catch (RemoteException e) {
2018 }
2019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002020
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002021 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002022 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002023 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002024
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002025 // First, if this window is at the current index, then all
2026 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002027 if (wallpaper == foundW) {
2028 foundI--;
2029 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002030 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002031 continue;
2032 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002033
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002034 // The window didn't match... the current wallpaper window,
2035 // wherever it is, is in the wrong place, so make sure it is
2036 // not in the list.
2037 int oldIndex = localmWindows.indexOf(wallpaper);
2038 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002039 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002040 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002041 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002042 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002043 if (oldIndex < foundI) {
2044 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002045 }
2046 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002047
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002048 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002049 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2050 Slog.v(TAG, "Moving wallpaper " + wallpaper
2051 + " from " + oldIndex + " to " + foundI);
2052 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002053
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002054 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002055 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002056 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002057 }
2058 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002059
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002060 return changed;
2061 }
2062
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002063 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002064 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002065 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002066 mWallpaperAnimLayerAdjustment = adj;
2067 int curTokenIndex = mWallpaperTokens.size();
2068 while (curTokenIndex > 0) {
2069 curTokenIndex--;
2070 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2071 int curWallpaperIndex = token.windows.size();
2072 while (curWallpaperIndex > 0) {
2073 curWallpaperIndex--;
2074 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2075 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002076 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002077 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002078 }
2079 }
2080 }
2081
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002082 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2083 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002084 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002085 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002086 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002087 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2089 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2090 changed = wallpaperWin.mXOffset != offset;
2091 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002092 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002093 + wallpaperWin + " x: " + offset);
2094 wallpaperWin.mXOffset = offset;
2095 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002096 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002097 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002098 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002099 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002101
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002102 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002103 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002104 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2105 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2106 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002107 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002108 + wallpaperWin + " y: " + offset);
2109 changed = true;
2110 wallpaperWin.mYOffset = offset;
2111 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002112 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002113 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002114 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002115 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002116 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002117
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002118 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002119 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002120 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002121 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2122 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002123 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002124 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002125 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002126 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002127 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2128 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002129 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002130 if (mWaitingOnWallpaper != null) {
2131 long start = SystemClock.uptimeMillis();
2132 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2133 < start) {
2134 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002135 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002136 "Waiting for offset complete...");
2137 mWindowMap.wait(WALLPAPER_TIMEOUT);
2138 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002139 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002140 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002141 if ((start+WALLPAPER_TIMEOUT)
2142 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002143 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002144 + wallpaperWin);
2145 mLastWallpaperTimeoutTime = start;
2146 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002147 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002148 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002149 }
2150 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002151 } catch (RemoteException e) {
2152 }
2153 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002154
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002155 return changed;
2156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002157
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002158 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002159 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002160 if (mWaitingOnWallpaper != null &&
2161 mWaitingOnWallpaper.mClient.asBinder() == window) {
2162 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002163 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002164 }
2165 }
2166 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002167
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002168 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002169 final int dw = mDisplay.getWidth();
2170 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002171
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002172 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002173
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002174 WindowState target = mWallpaperTarget;
2175 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002176 if (target.mWallpaperX >= 0) {
2177 mLastWallpaperX = target.mWallpaperX;
2178 } else if (changingTarget.mWallpaperX >= 0) {
2179 mLastWallpaperX = changingTarget.mWallpaperX;
2180 }
2181 if (target.mWallpaperY >= 0) {
2182 mLastWallpaperY = target.mWallpaperY;
2183 } else if (changingTarget.mWallpaperY >= 0) {
2184 mLastWallpaperY = changingTarget.mWallpaperY;
2185 }
2186 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002187
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002188 int curTokenIndex = mWallpaperTokens.size();
2189 while (curTokenIndex > 0) {
2190 curTokenIndex--;
2191 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2192 int curWallpaperIndex = token.windows.size();
2193 while (curWallpaperIndex > 0) {
2194 curWallpaperIndex--;
2195 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2196 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2197 wallpaper.computeShownFrameLocked();
2198 changed = true;
2199 // We only want to be synchronous with one wallpaper.
2200 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002201 }
2202 }
2203 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002204
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002205 return changed;
2206 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002207
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002208 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002209 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002210 final int dw = mDisplay.getWidth();
2211 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002212
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002213 int curTokenIndex = mWallpaperTokens.size();
2214 while (curTokenIndex > 0) {
2215 curTokenIndex--;
2216 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002217 if (token.hidden == visible) {
2218 token.hidden = !visible;
2219 // Need to do a layout to ensure the wallpaper now has the
2220 // correct size.
2221 mLayoutNeeded = true;
2222 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002223
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002224 int curWallpaperIndex = token.windows.size();
2225 while (curWallpaperIndex > 0) {
2226 curWallpaperIndex--;
2227 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2228 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002229 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002230 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002231
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002232 if (wallpaper.mWallpaperVisible != visible) {
2233 wallpaper.mWallpaperVisible = visible;
2234 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002235 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002236 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002237 + ": " + visible);
2238 wallpaper.mClient.dispatchAppVisibility(visible);
2239 } catch (RemoteException e) {
2240 }
2241 }
2242 }
2243 }
2244 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 public int addWindow(Session session, IWindow client,
2247 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002248 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 int res = mPolicy.checkAddPermission(attrs);
2250 if (res != WindowManagerImpl.ADD_OKAY) {
2251 return res;
2252 }
Romain Guy06882f82009-06-10 13:36:04 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 boolean reportNewConfig = false;
2255 WindowState attachedWindow = null;
2256 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002257 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002261 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 }
Romain Guy06882f82009-06-10 13:36:04 -07002263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002265 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2267 }
2268
2269 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002270 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002272 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 + attrs.token + ". Aborting.");
2274 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2275 }
2276 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2277 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002278 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 + attrs.token + ". Aborting.");
2280 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2281 }
2282 }
2283
2284 boolean addToken = false;
2285 WindowToken token = mTokenMap.get(attrs.token);
2286 if (token == null) {
2287 if (attrs.type >= FIRST_APPLICATION_WINDOW
2288 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002289 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 + attrs.token + ". Aborting.");
2291 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2292 }
2293 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002294 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 + attrs.token + ". Aborting.");
2296 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2297 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002298 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002299 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002300 + attrs.token + ". Aborting.");
2301 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2302 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 token = new WindowToken(attrs.token, -1, false);
2304 addToken = true;
2305 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2306 && attrs.type <= LAST_APPLICATION_WINDOW) {
2307 AppWindowToken atoken = token.appWindowToken;
2308 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002309 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 + token + ". Aborting.");
2311 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2312 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002313 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 + token + ". Aborting.");
2315 return WindowManagerImpl.ADD_APP_EXITING;
2316 }
2317 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2318 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002319 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2321 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2322 }
2323 } else if (attrs.type == TYPE_INPUT_METHOD) {
2324 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002325 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 + attrs.token + ". Aborting.");
2327 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2328 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002329 } else if (attrs.type == TYPE_WALLPAPER) {
2330 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002331 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002332 + attrs.token + ". Aborting.");
2333 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 }
2336
2337 win = new WindowState(session, client, token,
2338 attachedWindow, attrs, viewVisibility);
2339 if (win.mDeathRecipient == null) {
2340 // Client has apparently died, so there is no reason to
2341 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002342 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 + " that is dead, aborting.");
2344 return WindowManagerImpl.ADD_APP_EXITING;
2345 }
2346
2347 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 res = mPolicy.prepareAddWindowLw(win, attrs);
2350 if (res != WindowManagerImpl.ADD_OKAY) {
2351 return res;
2352 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002353
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002354 if (outInputChannel != null) {
2355 String name = win.makeInputChannelName();
2356 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2357 win.mInputChannel = inputChannels[0];
2358 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2359
Jeff Brown928e0542011-01-10 11:17:36 -08002360 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362
2363 // From now on, no exceptions or errors allowed!
2364
2365 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002366
Dianne Hackborn5132b372010-07-29 12:51:35 -07002367 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 if (addToken) {
2370 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 }
2372 win.attach();
2373 mWindowMap.put(client.asBinder(), win);
2374
2375 if (attrs.type == TYPE_APPLICATION_STARTING &&
2376 token.appWindowToken != null) {
2377 token.appWindowToken.startingWindow = win;
2378 }
2379
2380 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 if (attrs.type == TYPE_INPUT_METHOD) {
2383 mInputMethodWindow = win;
2384 addInputMethodWindowToListLocked(win);
2385 imMayMove = false;
2386 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2387 mInputMethodDialogs.add(win);
2388 addWindowToListInOrderLocked(win, true);
2389 adjustInputMethodDialogsLocked();
2390 imMayMove = false;
2391 } else {
2392 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002393 if (attrs.type == TYPE_WALLPAPER) {
2394 mLastWallpaperTimeoutTime = 0;
2395 adjustWallpaperWindowsLocked();
2396 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002397 adjustWallpaperWindowsLocked();
2398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 }
Romain Guy06882f82009-06-10 13:36:04 -07002400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 if (mInTouchMode) {
2406 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2407 }
2408 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2409 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2410 }
Romain Guy06882f82009-06-10 13:36:04 -07002411
Jeff Brown2e44b072011-01-24 15:21:56 -08002412 mInputMonitor.setUpdateInputWindowsNeededLw();
2413
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002414 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002416 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2417 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002418 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 imMayMove = false;
2420 }
2421 }
Romain Guy06882f82009-06-10 13:36:04 -07002422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002424 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 }
Romain Guy06882f82009-06-10 13:36:04 -07002426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 assignLayersLocked();
2428 // Don't do layout here, the window must call
2429 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 //dump();
2432
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002433 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002434 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002435 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002436 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002437
Joe Onorato8a9b2202010-02-26 18:56:32 -08002438 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 TAG, "New client " + client.asBinder()
2440 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002441
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002442 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002443 reportNewConfig = true;
2444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 }
2446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 if (reportNewConfig) {
2448 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 return res;
2454 }
Romain Guy06882f82009-06-10 13:36:04 -07002455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 public void removeWindow(Session session, IWindow client) {
2457 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002458 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 if (win == null) {
2460 return;
2461 }
2462 removeWindowLocked(session, win);
2463 }
2464 }
Romain Guy06882f82009-06-10 13:36:04 -07002465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 public void removeWindowLocked(Session session, WindowState win) {
2467
Joe Onorato8a9b2202010-02-26 18:56:32 -08002468 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 TAG, "Remove " + win + " client="
2470 + Integer.toHexString(System.identityHashCode(
2471 win.mClient.asBinder()))
2472 + ", surface=" + win.mSurface);
2473
2474 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002475
2476 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002477
Joe Onorato8a9b2202010-02-26 18:56:32 -08002478 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2480 + " mExiting=" + win.mExiting
2481 + " isAnimating=" + win.isAnimating()
2482 + " app-animation="
2483 + (win.mAppToken != null ? win.mAppToken.animation : null)
2484 + " inPendingTransaction="
2485 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2486 + " mDisplayFrozen=" + mDisplayFrozen);
2487 // Visibility of the removed window. Will be used later to update orientation later on.
2488 boolean wasVisible = false;
2489 // First, see if we need to run an animation. If we do, we have
2490 // to hold off on removing the window until the animation is done.
2491 // If the display is frozen, just remove immediately, since the
2492 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002493 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 // If we are not currently running the exit animation, we
2495 // need to see about starting one.
2496 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2499 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2500 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2501 }
2502 // Try starting an animation.
2503 if (applyAnimationLocked(win, transit, false)) {
2504 win.mExiting = true;
2505 }
2506 }
2507 if (win.mExiting || win.isAnimating()) {
2508 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002509 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 win.mExiting = true;
2511 win.mRemoveOnExit = true;
2512 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002513 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2514 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002516 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 if (win.mAppToken != null) {
2518 win.mAppToken.updateReportedVisibilityLocked();
2519 }
2520 //dump();
2521 Binder.restoreCallingIdentity(origId);
2522 return;
2523 }
2524 }
2525
2526 removeWindowInnerLocked(session, win);
2527 // Removing a visible window will effect the computed orientation
2528 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002529 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002530 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002531 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002532 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002534 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 Binder.restoreCallingIdentity(origId);
2536 }
Romain Guy06882f82009-06-10 13:36:04 -07002537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002539 if (win.mRemoved) {
2540 // Nothing to do.
2541 return;
2542 }
2543
2544 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2545 WindowState cwin = win.mChildWindows.get(i);
2546 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2547 + win);
2548 removeWindowInnerLocked(cwin.mSession, cwin);
2549 }
2550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 if (mInputMethodTarget == win) {
2554 moveInputMethodWindowsIfNeededLocked(false);
2555 }
Romain Guy06882f82009-06-10 13:36:04 -07002556
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002557 if (false) {
2558 RuntimeException e = new RuntimeException("here");
2559 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002560 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002561 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 mPolicy.removeWindowLw(win);
2564 win.removeLocked();
2565
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002566 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 mWindowMap.remove(win.mClient.asBinder());
2568 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002569 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002570 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002571 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572
2573 if (mInputMethodWindow == win) {
2574 mInputMethodWindow = null;
2575 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2576 mInputMethodDialogs.remove(win);
2577 }
Romain Guy06882f82009-06-10 13:36:04 -07002578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 final WindowToken token = win.mToken;
2580 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002581 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 token.windows.remove(win);
2583 if (atoken != null) {
2584 atoken.allAppWindows.remove(win);
2585 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002586 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 TAG, "**** Removing window " + win + ": count="
2588 + token.windows.size());
2589 if (token.windows.size() == 0) {
2590 if (!token.explicit) {
2591 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592 } else if (atoken != null) {
2593 atoken.firstWindowDrawn = false;
2594 }
2595 }
2596
2597 if (atoken != null) {
2598 if (atoken.startingWindow == win) {
2599 atoken.startingWindow = null;
2600 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2601 // If this is the last window and we had requested a starting
2602 // transition window, well there is no point now.
2603 atoken.startingData = null;
2604 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2605 // If this is the last window except for a starting transition
2606 // window, we need to get rid of the starting transition.
2607 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002608 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 + ": no more real windows");
2610 }
2611 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2612 mH.sendMessage(m);
2613 }
2614 }
Romain Guy06882f82009-06-10 13:36:04 -07002615
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002616 if (win.mAttrs.type == TYPE_WALLPAPER) {
2617 mLastWallpaperTimeoutTime = 0;
2618 adjustWallpaperWindowsLocked();
2619 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002620 adjustWallpaperWindowsLocked();
2621 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 if (!mInLayout) {
2624 assignLayersLocked();
2625 mLayoutNeeded = true;
2626 performLayoutAndPlaceSurfacesLocked();
2627 if (win.mAppToken != null) {
2628 win.mAppToken.updateReportedVisibilityLocked();
2629 }
2630 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002631
Jeff Brown2e44b072011-01-24 15:21:56 -08002632 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 }
2634
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002635 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2636 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2637 + ": " + msg + " / " + w.mAttrs.getTitle();
2638 if (where != null) {
2639 Slog.i(TAG, str, where);
2640 } else {
2641 Slog.i(TAG, str);
2642 }
2643 }
2644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2646 long origId = Binder.clearCallingIdentity();
2647 try {
2648 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002649 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002650 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002651 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2652 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 Surface.openTransaction();
2654 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002655 if (SHOW_TRANSACTIONS) logSurface(w,
2656 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 w.mSurface.setTransparentRegionHint(region);
2658 } finally {
2659 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002660 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2661 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002662 }
2663 }
2664 }
2665 } finally {
2666 Binder.restoreCallingIdentity(origId);
2667 }
2668 }
2669
2670 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002671 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002672 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002673 long origId = Binder.clearCallingIdentity();
2674 try {
2675 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002676 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 if (w != null) {
2678 w.mGivenInsetsPending = false;
2679 w.mGivenContentInsets.set(contentInsets);
2680 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002681 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 w.mTouchableInsets = touchableInsets;
2683 mLayoutNeeded = true;
2684 performLayoutAndPlaceSurfacesLocked();
2685 }
2686 }
2687 } finally {
2688 Binder.restoreCallingIdentity(origId);
2689 }
2690 }
Romain Guy06882f82009-06-10 13:36:04 -07002691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 public void getWindowDisplayFrame(Session session, IWindow client,
2693 Rect outDisplayFrame) {
2694 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002695 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 if (win == null) {
2697 outDisplayFrame.setEmpty();
2698 return;
2699 }
2700 outDisplayFrame.set(win.mDisplayFrame);
2701 }
2702 }
2703
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002704 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2705 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002706 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2707 window.mWallpaperX = x;
2708 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002709 window.mWallpaperXStep = xStep;
2710 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002711 if (updateWallpaperOffsetLocked(window, true)) {
2712 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002713 }
2714 }
2715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002716
Dianne Hackborn75804932009-10-20 20:15:20 -07002717 void wallpaperCommandComplete(IBinder window, Bundle result) {
2718 synchronized (mWindowMap) {
2719 if (mWaitingOnWallpaper != null &&
2720 mWaitingOnWallpaper.mClient.asBinder() == window) {
2721 mWaitingOnWallpaper = null;
2722 mWindowMap.notifyAll();
2723 }
2724 }
2725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002726
Dianne Hackborn75804932009-10-20 20:15:20 -07002727 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2728 String action, int x, int y, int z, Bundle extras, boolean sync) {
2729 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2730 || window == mUpperWallpaperTarget) {
2731 boolean doWait = sync;
2732 int curTokenIndex = mWallpaperTokens.size();
2733 while (curTokenIndex > 0) {
2734 curTokenIndex--;
2735 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2736 int curWallpaperIndex = token.windows.size();
2737 while (curWallpaperIndex > 0) {
2738 curWallpaperIndex--;
2739 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2740 try {
2741 wallpaper.mClient.dispatchWallpaperCommand(action,
2742 x, y, z, extras, sync);
2743 // We only want to be synchronous with one wallpaper.
2744 sync = false;
2745 } catch (RemoteException e) {
2746 }
2747 }
2748 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002749
Dianne Hackborn75804932009-10-20 20:15:20 -07002750 if (doWait) {
2751 // XXX Need to wait for result.
2752 }
2753 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002754
Dianne Hackborn75804932009-10-20 20:15:20 -07002755 return null;
2756 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002758 public int relayoutWindow(Session session, IWindow client,
2759 WindowManager.LayoutParams attrs, int requestedWidth,
2760 int requestedHeight, int viewVisibility, boolean insetsPending,
2761 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002762 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 boolean displayed = false;
2764 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002765 boolean configChanged;
Joe Onoratoac0ee892011-01-30 15:38:30 -08002766
2767 // if they don't have this permission, mask out the status bar bits
2768 if (attrs != null) {
2769 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
2770 != PackageManager.PERMISSION_GRANTED) {
2771 attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2772 attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2773 }
2774 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002778 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779 if (win == null) {
2780 return 0;
2781 }
2782 win.mRequestedWidth = requestedWidth;
2783 win.mRequestedHeight = requestedHeight;
2784
2785 if (attrs != null) {
2786 mPolicy.adjustWindowParamsLw(attrs);
2787 }
Romain Guy06882f82009-06-10 13:36:04 -07002788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 int attrChanges = 0;
2790 int flagChanges = 0;
2791 if (attrs != null) {
2792 flagChanges = win.mAttrs.flags ^= attrs.flags;
2793 attrChanges = win.mAttrs.copyFrom(attrs);
2794 }
2795
Joe Onorato8a9b2202010-02-26 18:56:32 -08002796 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797
2798 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2799 win.mAlpha = attrs.alpha;
2800 }
2801
2802 final boolean scaledWindow =
2803 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2804
2805 if (scaledWindow) {
2806 // requested{Width|Height} Surface's physical size
2807 // attrs.{width|height} Size on screen
2808 win.mHScale = (attrs.width != requestedWidth) ?
2809 (attrs.width / (float)requestedWidth) : 1.0f;
2810 win.mVScale = (attrs.height != requestedHeight) ?
2811 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002812 } else {
2813 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 }
2815
2816 boolean imMayMove = (flagChanges&(
2817 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2818 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 boolean focusMayChange = win.mViewVisibility != viewVisibility
2821 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2822 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002823
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002824 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2825 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 win.mRelayoutCalled = true;
2828 final int oldVisibility = win.mViewVisibility;
2829 win.mViewVisibility = viewVisibility;
2830 if (viewVisibility == View.VISIBLE &&
2831 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2832 displayed = !win.isVisibleLw();
2833 if (win.mExiting) {
2834 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002835 if (win.mAnimation != null) {
2836 win.mAnimation.cancel();
2837 win.mAnimation = null;
2838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 }
2840 if (win.mDestroying) {
2841 win.mDestroying = false;
2842 mDestroySurface.remove(win);
2843 }
2844 if (oldVisibility == View.GONE) {
2845 win.mEnterAnimationPending = true;
2846 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002847 if (displayed) {
2848 if (win.mSurface != null && !win.mDrawPending
2849 && !win.mCommitDrawPending && !mDisplayFrozen
2850 && mPolicy.isScreenOn()) {
2851 applyEnterAnimationLocked(win);
2852 }
2853 if ((win.mAttrs.flags
2854 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2855 if (DEBUG_VISIBILITY) Slog.v(TAG,
2856 "Relayout window turning screen on: " + win);
2857 win.mTurnOnScreen = true;
2858 }
2859 int diff = 0;
2860 if (win.mConfiguration != mCurConfiguration
2861 && (win.mConfiguration == null
2862 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2863 win.mConfiguration = mCurConfiguration;
2864 if (DEBUG_CONFIGURATION) {
2865 Slog.i(TAG, "Window " + win + " visible with new config: "
2866 + win.mConfiguration + " / 0x"
2867 + Integer.toHexString(diff));
2868 }
2869 outConfig.setTo(mCurConfiguration);
2870 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2873 // To change the format, we need to re-build the surface.
2874 win.destroySurfaceLocked();
2875 displayed = true;
2876 }
2877 try {
2878 Surface surface = win.createSurfaceLocked();
2879 if (surface != null) {
2880 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002881 win.mReportDestroySurface = false;
2882 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002883 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002884 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002886 // For some reason there isn't a surface. Clear the
2887 // caller's object so they see the same state.
2888 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 }
2890 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002891 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002892
Joe Onorato8a9b2202010-02-26 18:56:32 -08002893 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002894 + client + " (" + win.mAttrs.getTitle() + ")",
2895 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 Binder.restoreCallingIdentity(origId);
2897 return 0;
2898 }
2899 if (displayed) {
2900 focusMayChange = true;
2901 }
2902 if (win.mAttrs.type == TYPE_INPUT_METHOD
2903 && mInputMethodWindow == null) {
2904 mInputMethodWindow = win;
2905 imMayMove = true;
2906 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002907 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2908 && win.mAppToken != null
2909 && win.mAppToken.startingWindow != null) {
2910 // Special handling of starting window over the base
2911 // window of the app: propagate lock screen flags to it,
2912 // to provide the correct semantics while starting.
2913 final int mask =
2914 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002915 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2916 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002917 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2918 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 } else {
2921 win.mEnterAnimationPending = false;
2922 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002923 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002924 + ": mExiting=" + win.mExiting
2925 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 // If we are not currently running the exit animation, we
2927 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002928 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 // Try starting an animation; if there isn't one, we
2930 // can destroy the surface right away.
2931 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2932 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2933 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2934 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002935 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002936 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002937 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 } else if (win.isAnimating()) {
2940 // Currently in a hide animation... turn this into
2941 // an exit.
2942 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002943 } else if (win == mWallpaperTarget) {
2944 // If the wallpaper is currently behind this
2945 // window, we need to change both of them inside
2946 // of a transaction to avoid artifacts.
2947 win.mExiting = true;
2948 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 } else {
2950 if (mInputMethodWindow == win) {
2951 mInputMethodWindow = null;
2952 }
2953 win.destroySurfaceLocked();
2954 }
2955 }
2956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002957
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002958 if (win.mSurface == null || (win.getAttrs().flags
2959 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2960 || win.mSurfacePendingDestroy) {
2961 // We are being called from a local process, which
2962 // means outSurface holds its current surface. Ensure the
2963 // surface object is cleared, but we don't want it actually
2964 // destroyed at this point.
2965 win.mSurfacePendingDestroy = false;
2966 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002967 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002968 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002969 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002970 "Keeping surface, will report destroy: " + win);
2971 win.mReportDestroySurface = true;
2972 outSurface.copyFrom(win.mSurface);
2973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 }
2975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 if (focusMayChange) {
2977 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002978 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2979 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 imMayMove = false;
2981 }
2982 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2983 }
Romain Guy06882f82009-06-10 13:36:04 -07002984
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002985 // updateFocusedWindowLocked() already assigned layers so we only need to
2986 // reassign them at this point if the IM window state gets shuffled
2987 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002990 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2991 // Little hack here -- we -should- be able to rely on the
2992 // function to return true if the IME has moved and needs
2993 // its layer recomputed. However, if the IME was hidden
2994 // and isn't actually moved in the list, its layer may be
2995 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 assignLayers = true;
2997 }
2998 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002999 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07003000 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003001 assignLayers = true;
3002 }
3003 }
Romain Guy06882f82009-06-10 13:36:04 -07003004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 mLayoutNeeded = true;
3006 win.mGivenInsetsPending = insetsPending;
3007 if (assignLayers) {
3008 assignLayersLocked();
3009 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003010 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07003012 if (displayed && win.mIsWallpaper) {
3013 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07003014 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07003015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 if (win.mAppToken != null) {
3017 win.mAppToken.updateReportedVisibilityLocked();
3018 }
3019 outFrame.set(win.mFrame);
3020 outContentInsets.set(win.mContentInsets);
3021 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003022 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07003024 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 + ", requestedHeight=" + requestedHeight
3026 + ", viewVisibility=" + viewVisibility
3027 + "\nRelayout returning frame=" + outFrame
3028 + ", surface=" + outSurface);
3029
Joe Onorato8a9b2202010-02-26 18:56:32 -08003030 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003031 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3032
3033 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003034
Jeff Brown2e44b072011-01-24 15:21:56 -08003035 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 }
3037
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003038 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 sendNewConfiguration();
3040 }
Romain Guy06882f82009-06-10 13:36:04 -07003041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003044 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3045 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3046 }
3047
3048 public void finishDrawingWindow(Session session, IWindow client) {
3049 final long origId = Binder.clearCallingIdentity();
3050 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003051 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003052 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003053 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3054 adjustWallpaperWindowsLocked();
3055 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 mLayoutNeeded = true;
3057 performLayoutAndPlaceSurfacesLocked();
3058 }
3059 }
3060 Binder.restoreCallingIdentity(origId);
3061 }
3062
3063 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003064 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003065 + (lp != null ? lp.packageName : null)
3066 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3067 if (lp != null && lp.windowAnimations != 0) {
3068 // If this is a system resource, don't try to load it from the
3069 // application resources. It is nice to avoid loading application
3070 // resources if we can.
3071 String packageName = lp.packageName != null ? lp.packageName : "android";
3072 int resId = lp.windowAnimations;
3073 if ((resId&0xFF000000) == 0x01000000) {
3074 packageName = "android";
3075 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003076 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 + packageName);
3078 return AttributeCache.instance().get(packageName, resId,
3079 com.android.internal.R.styleable.WindowAnimation);
3080 }
3081 return null;
3082 }
Romain Guy06882f82009-06-10 13:36:04 -07003083
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003084 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003085 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003086 + packageName + " resId=0x" + Integer.toHexString(resId));
3087 if (packageName != null) {
3088 if ((resId&0xFF000000) == 0x01000000) {
3089 packageName = "android";
3090 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003091 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003092 + packageName);
3093 return AttributeCache.instance().get(packageName, resId,
3094 com.android.internal.R.styleable.WindowAnimation);
3095 }
3096 return null;
3097 }
3098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 private void applyEnterAnimationLocked(WindowState win) {
3100 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3101 if (win.mEnterAnimationPending) {
3102 win.mEnterAnimationPending = false;
3103 transit = WindowManagerPolicy.TRANSIT_ENTER;
3104 }
3105
3106 applyAnimationLocked(win, transit, true);
3107 }
3108
3109 private boolean applyAnimationLocked(WindowState win,
3110 int transit, boolean isEntrance) {
3111 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3112 // If we are trying to apply an animation, but already running
3113 // an animation of the same type, then just leave that one alone.
3114 return true;
3115 }
Romain Guy06882f82009-06-10 13:36:04 -07003116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 // Only apply an animation if the display isn't frozen. If it is
3118 // frozen, there is no reason to animate and it can cause strange
3119 // artifacts when we unfreeze the display if some different animation
3120 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003121 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 int anim = mPolicy.selectAnimationLw(win, transit);
3123 int attr = -1;
3124 Animation a = null;
3125 if (anim != 0) {
3126 a = AnimationUtils.loadAnimation(mContext, anim);
3127 } else {
3128 switch (transit) {
3129 case WindowManagerPolicy.TRANSIT_ENTER:
3130 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3131 break;
3132 case WindowManagerPolicy.TRANSIT_EXIT:
3133 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3134 break;
3135 case WindowManagerPolicy.TRANSIT_SHOW:
3136 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3137 break;
3138 case WindowManagerPolicy.TRANSIT_HIDE:
3139 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3140 break;
3141 }
3142 if (attr >= 0) {
3143 a = loadAnimation(win.mAttrs, attr);
3144 }
3145 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003146 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3148 + " mAnimation=" + win.mAnimation
3149 + " isEntrance=" + isEntrance);
3150 if (a != null) {
3151 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003152 RuntimeException e = null;
3153 if (!HIDE_STACK_CRAWLS) {
3154 e = new RuntimeException();
3155 e.fillInStackTrace();
3156 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003157 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 }
3159 win.setAnimation(a);
3160 win.mAnimationIsEntrance = isEntrance;
3161 }
3162 } else {
3163 win.clearAnimation();
3164 }
3165
3166 return win.mAnimation != null;
3167 }
3168
3169 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3170 int anim = 0;
3171 Context context = mContext;
3172 if (animAttr >= 0) {
3173 AttributeCache.Entry ent = getCachedAnimations(lp);
3174 if (ent != null) {
3175 context = ent.context;
3176 anim = ent.array.getResourceId(animAttr, 0);
3177 }
3178 }
3179 if (anim != 0) {
3180 return AnimationUtils.loadAnimation(context, anim);
3181 }
3182 return null;
3183 }
Romain Guy06882f82009-06-10 13:36:04 -07003184
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003185 private Animation loadAnimation(String packageName, int resId) {
3186 int anim = 0;
3187 Context context = mContext;
3188 if (resId >= 0) {
3189 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3190 if (ent != null) {
3191 context = ent.context;
3192 anim = resId;
3193 }
3194 }
3195 if (anim != 0) {
3196 return AnimationUtils.loadAnimation(context, anim);
3197 }
3198 return null;
3199 }
3200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201 private boolean applyAnimationLocked(AppWindowToken wtoken,
3202 WindowManager.LayoutParams lp, int transit, boolean enter) {
3203 // Only apply an animation if the display isn't frozen. If it is
3204 // frozen, there is no reason to animate and it can cause strange
3205 // artifacts when we unfreeze the display if some different animation
3206 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003207 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003208 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003209 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003210 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003211 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003212 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003213 } else if (mNextAppTransitionPackage != null) {
3214 a = loadAnimation(mNextAppTransitionPackage, enter ?
3215 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003216 } else {
3217 int animAttr = 0;
3218 switch (transit) {
3219 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3220 animAttr = enter
3221 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3222 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3223 break;
3224 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3225 animAttr = enter
3226 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3227 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3228 break;
3229 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3230 animAttr = enter
3231 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3232 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3233 break;
3234 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3235 animAttr = enter
3236 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3237 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3238 break;
3239 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3240 animAttr = enter
3241 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3242 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3243 break;
3244 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3245 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003246 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003247 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3248 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003249 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003250 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003251 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3252 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003253 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003254 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003255 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003256 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3257 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3258 break;
3259 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3260 animAttr = enter
3261 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3262 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3263 break;
3264 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3265 animAttr = enter
3266 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3267 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003268 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003269 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003270 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003271 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003272 + " anim=" + a
3273 + " animAttr=0x" + Integer.toHexString(animAttr)
3274 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 if (a != null) {
3277 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003278 RuntimeException e = null;
3279 if (!HIDE_STACK_CRAWLS) {
3280 e = new RuntimeException();
3281 e.fillInStackTrace();
3282 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003283 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 }
3285 wtoken.setAnimation(a);
3286 }
3287 } else {
3288 wtoken.clearAnimation();
3289 }
3290
3291 return wtoken.animation != null;
3292 }
3293
3294 // -------------------------------------------------------------
3295 // Application Window Tokens
3296 // -------------------------------------------------------------
3297
3298 public void validateAppTokens(List tokens) {
3299 int v = tokens.size()-1;
3300 int m = mAppTokens.size()-1;
3301 while (v >= 0 && m >= 0) {
3302 AppWindowToken wtoken = mAppTokens.get(m);
3303 if (wtoken.removed) {
3304 m--;
3305 continue;
3306 }
3307 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003308 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3310 }
3311 v--;
3312 m--;
3313 }
3314 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003315 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 v--;
3317 }
3318 while (m >= 0) {
3319 AppWindowToken wtoken = mAppTokens.get(m);
3320 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003321 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 }
3323 m--;
3324 }
3325 }
3326
3327 boolean checkCallingPermission(String permission, String func) {
3328 // Quick check: if the calling permission is me, it's all okay.
3329 if (Binder.getCallingPid() == Process.myPid()) {
3330 return true;
3331 }
Romain Guy06882f82009-06-10 13:36:04 -07003332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 if (mContext.checkCallingPermission(permission)
3334 == PackageManager.PERMISSION_GRANTED) {
3335 return true;
3336 }
3337 String msg = "Permission Denial: " + func + " from pid="
3338 + Binder.getCallingPid()
3339 + ", uid=" + Binder.getCallingUid()
3340 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003341 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 return false;
3343 }
Romain Guy06882f82009-06-10 13:36:04 -07003344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 AppWindowToken findAppWindowToken(IBinder token) {
3346 WindowToken wtoken = mTokenMap.get(token);
3347 if (wtoken == null) {
3348 return null;
3349 }
3350 return wtoken.appWindowToken;
3351 }
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 public void addWindowToken(IBinder token, int type) {
3354 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3355 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003356 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 }
Romain Guy06882f82009-06-10 13:36:04 -07003358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 synchronized(mWindowMap) {
3360 WindowToken wtoken = mTokenMap.get(token);
3361 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003362 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 return;
3364 }
3365 wtoken = new WindowToken(token, type, true);
3366 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003367 if (type == TYPE_WALLPAPER) {
3368 mWallpaperTokens.add(wtoken);
3369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 }
3371 }
Romain Guy06882f82009-06-10 13:36:04 -07003372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 public void removeWindowToken(IBinder token) {
3374 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3375 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003376 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 }
3378
3379 final long origId = Binder.clearCallingIdentity();
3380 synchronized(mWindowMap) {
3381 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 if (wtoken != null) {
3383 boolean delayed = false;
3384 if (!wtoken.hidden) {
3385 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 final int N = wtoken.windows.size();
3388 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 for (int i=0; i<N; i++) {
3391 WindowState win = wtoken.windows.get(i);
3392
3393 if (win.isAnimating()) {
3394 delayed = true;
3395 }
Romain Guy06882f82009-06-10 13:36:04 -07003396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 if (win.isVisibleNow()) {
3398 applyAnimationLocked(win,
3399 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 changed = true;
3401 }
3402 }
3403
3404 if (changed) {
3405 mLayoutNeeded = true;
3406 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003407 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3408 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 }
Romain Guy06882f82009-06-10 13:36:04 -07003410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 if (delayed) {
3412 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003413 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3414 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 }
3416 }
Romain Guy06882f82009-06-10 13:36:04 -07003417
Jeff Brown2e44b072011-01-24 15:21:56 -08003418 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003420 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 }
3422 }
3423 Binder.restoreCallingIdentity(origId);
3424 }
3425
3426 public void addAppToken(int addPos, IApplicationToken token,
3427 int groupId, int requestedOrientation, boolean fullscreen) {
3428 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3429 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003430 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 }
Jeff Brown349703e2010-06-22 01:27:15 -07003432
3433 // Get the dispatching timeout here while we are not holding any locks so that it
3434 // can be cached by the AppWindowToken. The timeout value is used later by the
3435 // input dispatcher in code that does hold locks. If we did not cache the value
3436 // here we would run the chance of introducing a deadlock between the window manager
3437 // (which holds locks while updating the input dispatcher state) and the activity manager
3438 // (which holds locks while querying the application token).
3439 long inputDispatchingTimeoutNanos;
3440 try {
3441 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3442 } catch (RemoteException ex) {
3443 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3444 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3445 }
Romain Guy06882f82009-06-10 13:36:04 -07003446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 synchronized(mWindowMap) {
3448 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3449 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003450 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003451 return;
3452 }
3453 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003454 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003455 wtoken.groupId = groupId;
3456 wtoken.appFullscreen = fullscreen;
3457 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003458 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003459 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003462 // Application tokens start out hidden.
3463 wtoken.hidden = true;
3464 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 //dump();
3467 }
3468 }
Romain Guy06882f82009-06-10 13:36:04 -07003469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 public void setAppGroupId(IBinder token, int groupId) {
3471 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3472 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003473 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 }
3475
3476 synchronized(mWindowMap) {
3477 AppWindowToken wtoken = findAppWindowToken(token);
3478 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003479 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 return;
3481 }
3482 wtoken.groupId = groupId;
3483 }
3484 }
Romain Guy06882f82009-06-10 13:36:04 -07003485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 public int getOrientationFromWindowsLocked() {
3487 int pos = mWindows.size() - 1;
3488 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003489 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 pos--;
3491 if (wtoken.mAppToken != null) {
3492 // We hit an application window. so the orientation will be determined by the
3493 // app window. No point in continuing further.
3494 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3495 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003496 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003497 continue;
3498 }
3499 int req = wtoken.mAttrs.screenOrientation;
3500 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3501 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3502 continue;
3503 } else {
3504 return req;
3505 }
3506 }
3507 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3508 }
Romain Guy06882f82009-06-10 13:36:04 -07003509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003511 int pos = mAppTokens.size() - 1;
3512 int curGroup = 0;
3513 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3514 boolean findingBehind = false;
3515 boolean haveGroup = false;
3516 boolean lastFullscreen = false;
3517 while (pos >= 0) {
3518 AppWindowToken wtoken = mAppTokens.get(pos);
3519 pos--;
3520 // if we're about to tear down this window and not seek for
3521 // the behind activity, don't use it for orientation
3522 if (!findingBehind
3523 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3524 continue;
3525 }
3526
3527 if (!haveGroup) {
3528 // We ignore any hidden applications on the top.
3529 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003530 continue;
3531 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003532 haveGroup = true;
3533 curGroup = wtoken.groupId;
3534 lastOrientation = wtoken.requestedOrientation;
3535 } else if (curGroup != wtoken.groupId) {
3536 // If we have hit a new application group, and the bottom
3537 // of the previous group didn't explicitly say to use
3538 // the orientation behind it, and the last app was
3539 // full screen, then we'll stick with the
3540 // user's orientation.
3541 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3542 && lastFullscreen) {
3543 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003546 int or = wtoken.requestedOrientation;
3547 // If this application is fullscreen, and didn't explicitly say
3548 // to use the orientation behind it, then just take whatever
3549 // orientation it has and ignores whatever is under it.
3550 lastFullscreen = wtoken.appFullscreen;
3551 if (lastFullscreen
3552 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3553 return or;
3554 }
3555 // If this application has requested an explicit orientation,
3556 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003557 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3558 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003559 return or;
3560 }
3561 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3562 }
3563 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 }
Romain Guy06882f82009-06-10 13:36:04 -07003565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003567 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003568 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3569 "updateOrientationFromAppTokens()")) {
3570 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3571 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003572
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003573 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003575
3576 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003577 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003578 if (freezeThisOneIfNeeded != null) {
3579 AppWindowToken wtoken = findAppWindowToken(
3580 freezeThisOneIfNeeded);
3581 if (wtoken != null) {
3582 startAppFreezingScreenLocked(wtoken,
3583 ActivityInfo.CONFIG_ORIENTATION);
3584 }
3585 }
3586 config = computeNewConfigurationLocked();
3587
3588 } else if (currentConfig != null) {
3589 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003590 // state mismatches the activity manager's, update it,
3591 // disregarding font scale, which should remain set to
3592 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003593 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003594 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003595 if (computeNewConfigurationLocked(mTempConfiguration)) {
3596 if (currentConfig.diff(mTempConfiguration) != 0) {
3597 mWaitingForConfig = true;
3598 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003599 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003600 config = new Configuration(mTempConfiguration);
3601 }
3602 }
3603 }
3604 }
3605
Dianne Hackborncfaef692009-06-15 14:24:44 -07003606 Binder.restoreCallingIdentity(ident);
3607 return config;
3608 }
3609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003611 * Determine the new desired orientation of the display, returning
3612 * a non-null new Configuration if it has changed from the current
3613 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3614 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3615 * SCREEN. This will typically be done for you if you call
3616 * sendNewConfiguration().
3617 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 * The orientation is computed from non-application windows first. If none of
3619 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003620 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3622 * android.os.IBinder)
3623 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003624 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3625 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003626 // If the display is frozen, some activities may be in the middle
3627 // of restarting, and thus have removed their old window. If the
3628 // window has the flag to hide the lock screen, then the lock screen
3629 // can re-appear and inflict its own orientation on us. Keep the
3630 // orientation stable until this all settles down.
3631 return false;
3632 }
3633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 long ident = Binder.clearCallingIdentity();
3636 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003637 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 mForcedAppOrientation = req;
3641 //send a message to Policy indicating orientation change to take
3642 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003643 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003644 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003645 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3646 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003647 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 }
3649 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003650
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003651 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003652 } finally {
3653 Binder.restoreCallingIdentity(ident);
3654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 }
Romain Guy06882f82009-06-10 13:36:04 -07003656
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003657 int computeForcedAppOrientationLocked() {
3658 int req = getOrientationFromWindowsLocked();
3659 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3660 req = getOrientationFromAppTokensLocked();
3661 }
3662 return req;
3663 }
Romain Guy06882f82009-06-10 13:36:04 -07003664
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003665 public void setNewConfiguration(Configuration config) {
3666 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3667 "setNewConfiguration()")) {
3668 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3669 }
3670
3671 synchronized(mWindowMap) {
3672 mCurConfiguration = new Configuration(config);
3673 mWaitingForConfig = false;
3674 performLayoutAndPlaceSurfacesLocked();
3675 }
3676 }
3677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3679 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3680 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003681 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 }
Romain Guy06882f82009-06-10 13:36:04 -07003683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 synchronized(mWindowMap) {
3685 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3686 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003687 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 return;
3689 }
Romain Guy06882f82009-06-10 13:36:04 -07003690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 wtoken.requestedOrientation = requestedOrientation;
3692 }
3693 }
Romain Guy06882f82009-06-10 13:36:04 -07003694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 public int getAppOrientation(IApplicationToken token) {
3696 synchronized(mWindowMap) {
3697 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3698 if (wtoken == null) {
3699 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3700 }
Romain Guy06882f82009-06-10 13:36:04 -07003701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 return wtoken.requestedOrientation;
3703 }
3704 }
Romain Guy06882f82009-06-10 13:36:04 -07003705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3707 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3708 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003709 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 }
3711
3712 synchronized(mWindowMap) {
3713 boolean changed = false;
3714 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003715 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003716 changed = mFocusedApp != null;
3717 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003718 if (changed) {
3719 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 } else {
3722 AppWindowToken newFocus = findAppWindowToken(token);
3723 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003724 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 return;
3726 }
3727 changed = mFocusedApp != newFocus;
3728 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003729 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003730 if (changed) {
3731 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003732 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 }
3734
3735 if (moveFocusNow && changed) {
3736 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003737 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 Binder.restoreCallingIdentity(origId);
3739 }
3740 }
3741 }
3742
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003743 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3745 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003746 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 }
Romain Guy06882f82009-06-10 13:36:04 -07003748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003750 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 TAG, "Prepare app transition: transit=" + transit
3752 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003753 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003754 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3755 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003757 } else if (!alwaysKeepCurrent) {
3758 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3759 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3760 // Opening a new task always supersedes a close for the anim.
3761 mNextAppTransition = transit;
3762 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3763 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3764 // Opening a new activity always supersedes a close for the anim.
3765 mNextAppTransition = transit;
3766 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 }
3768 mAppTransitionReady = false;
3769 mAppTransitionTimeout = false;
3770 mStartingIconInTransition = false;
3771 mSkipAppTransitionAnimation = false;
3772 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3773 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3774 5000);
3775 }
3776 }
3777 }
3778
3779 public int getPendingAppTransition() {
3780 return mNextAppTransition;
3781 }
Romain Guy06882f82009-06-10 13:36:04 -07003782
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003783 public void overridePendingAppTransition(String packageName,
3784 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003785 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003786 mNextAppTransitionPackage = packageName;
3787 mNextAppTransitionEnter = enterAnim;
3788 mNextAppTransitionExit = exitAnim;
3789 }
3790 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 public void executeAppTransition() {
3793 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3794 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003795 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 }
Romain Guy06882f82009-06-10 13:36:04 -07003797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003799 if (DEBUG_APP_TRANSITIONS) {
3800 RuntimeException e = new RuntimeException("here");
3801 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003802 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003803 + mNextAppTransition, e);
3804 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003805 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 mAppTransitionReady = true;
3807 final long origId = Binder.clearCallingIdentity();
3808 performLayoutAndPlaceSurfacesLocked();
3809 Binder.restoreCallingIdentity(origId);
3810 }
3811 }
3812 }
3813
3814 public void setAppStartingWindow(IBinder token, String pkg,
3815 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003816 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003817 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3818 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003819 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 }
3821
3822 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003823 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3825 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003827 AppWindowToken wtoken = findAppWindowToken(token);
3828 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003829 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 return;
3831 }
3832
3833 // If the display is frozen, we won't do anything until the
3834 // actual window is displayed so there is no reason to put in
3835 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003836 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003837 return;
3838 }
Romain Guy06882f82009-06-10 13:36:04 -07003839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 if (wtoken.startingData != null) {
3841 return;
3842 }
Romain Guy06882f82009-06-10 13:36:04 -07003843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 if (transferFrom != null) {
3845 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3846 if (ttoken != null) {
3847 WindowState startingWindow = ttoken.startingWindow;
3848 if (startingWindow != null) {
3849 if (mStartingIconInTransition) {
3850 // In this case, the starting icon has already
3851 // been displayed, so start letting windows get
3852 // shown immediately without any more transitions.
3853 mSkipAppTransitionAnimation = true;
3854 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003855 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 "Moving existing starting from " + ttoken
3857 + " to " + wtoken);
3858 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 // Transfer the starting window over to the new
3861 // token.
3862 wtoken.startingData = ttoken.startingData;
3863 wtoken.startingView = ttoken.startingView;
3864 wtoken.startingWindow = startingWindow;
3865 ttoken.startingData = null;
3866 ttoken.startingView = null;
3867 ttoken.startingWindow = null;
3868 ttoken.startingMoved = true;
3869 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003870 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003871 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003872 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003873 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003875 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003876 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3877 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 ttoken.windows.remove(startingWindow);
3879 ttoken.allAppWindows.remove(startingWindow);
3880 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 // Propagate other interesting state between the
3883 // tokens. If the old token is displayed, we should
3884 // immediately force the new one to be displayed. If
3885 // it is animating, we need to move that animation to
3886 // the new one.
3887 if (ttoken.allDrawn) {
3888 wtoken.allDrawn = true;
3889 }
3890 if (ttoken.firstWindowDrawn) {
3891 wtoken.firstWindowDrawn = true;
3892 }
3893 if (!ttoken.hidden) {
3894 wtoken.hidden = false;
3895 wtoken.hiddenRequested = false;
3896 wtoken.willBeHidden = false;
3897 }
3898 if (wtoken.clientHidden != ttoken.clientHidden) {
3899 wtoken.clientHidden = ttoken.clientHidden;
3900 wtoken.sendAppVisibilityToClients();
3901 }
3902 if (ttoken.animation != null) {
3903 wtoken.animation = ttoken.animation;
3904 wtoken.animating = ttoken.animating;
3905 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3906 ttoken.animation = null;
3907 ttoken.animLayerAdjustment = 0;
3908 wtoken.updateLayers();
3909 ttoken.updateLayers();
3910 }
Romain Guy06882f82009-06-10 13:36:04 -07003911
Jeff Brown3a22cd92011-01-21 13:59:04 -08003912 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3913 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 mLayoutNeeded = true;
3915 performLayoutAndPlaceSurfacesLocked();
3916 Binder.restoreCallingIdentity(origId);
3917 return;
3918 } else if (ttoken.startingData != null) {
3919 // The previous app was getting ready to show a
3920 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003921 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922 "Moving pending starting from " + ttoken
3923 + " to " + wtoken);
3924 wtoken.startingData = ttoken.startingData;
3925 ttoken.startingData = null;
3926 ttoken.startingMoved = true;
3927 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3928 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3929 // want to process the message ASAP, before any other queued
3930 // messages.
3931 mH.sendMessageAtFrontOfQueue(m);
3932 return;
3933 }
3934 }
3935 }
3936
3937 // There is no existing starting window, and the caller doesn't
3938 // want us to create one, so that's it!
3939 if (!createIfNeeded) {
3940 return;
3941 }
Romain Guy06882f82009-06-10 13:36:04 -07003942
Dianne Hackborn284ac932009-08-28 10:34:25 -07003943 // If this is a translucent or wallpaper window, then don't
3944 // show a starting window -- the current effect (a full-screen
3945 // opaque starting window that fades away to the real contents
3946 // when it is ready) does not work for this.
3947 if (theme != 0) {
3948 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3949 com.android.internal.R.styleable.Window);
3950 if (ent.array.getBoolean(
3951 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3952 return;
3953 }
3954 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003955 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3956 return;
3957 }
3958 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003959 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3960 return;
3961 }
3962 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 mStartingIconInTransition = true;
3965 wtoken.startingData = new StartingData(
3966 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003967 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003968 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3969 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3970 // want to process the message ASAP, before any other queued
3971 // messages.
3972 mH.sendMessageAtFrontOfQueue(m);
3973 }
3974 }
3975
3976 public void setAppWillBeHidden(IBinder token) {
3977 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3978 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003979 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 }
3981
3982 AppWindowToken wtoken;
3983
3984 synchronized(mWindowMap) {
3985 wtoken = findAppWindowToken(token);
3986 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003987 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 -08003988 return;
3989 }
3990 wtoken.willBeHidden = true;
3991 }
3992 }
Romain Guy06882f82009-06-10 13:36:04 -07003993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3995 boolean visible, int transit, boolean performLayout) {
3996 boolean delayed = false;
3997
3998 if (wtoken.clientHidden == visible) {
3999 wtoken.clientHidden = !visible;
4000 wtoken.sendAppVisibilityToClients();
4001 }
Romain Guy06882f82009-06-10 13:36:04 -07004002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 wtoken.willBeHidden = false;
4004 if (wtoken.hidden == visible) {
4005 final int N = wtoken.allAppWindows.size();
4006 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08004007 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
4009 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07004010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07004012
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004013 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 if (wtoken.animation == sDummyAnimation) {
4015 wtoken.animation = null;
4016 }
4017 applyAnimationLocked(wtoken, lp, transit, visible);
4018 changed = true;
4019 if (wtoken.animation != null) {
4020 delayed = runningAppAnimation = true;
4021 }
4022 }
Romain Guy06882f82009-06-10 13:36:04 -07004023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 for (int i=0; i<N; i++) {
4025 WindowState win = wtoken.allAppWindows.get(i);
4026 if (win == wtoken.startingWindow) {
4027 continue;
4028 }
4029
4030 if (win.isAnimating()) {
4031 delayed = true;
4032 }
Romain Guy06882f82009-06-10 13:36:04 -07004033
Joe Onorato8a9b2202010-02-26 18:56:32 -08004034 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 //win.dump(" ");
4036 if (visible) {
4037 if (!win.isVisibleNow()) {
4038 if (!runningAppAnimation) {
4039 applyAnimationLocked(win,
4040 WindowManagerPolicy.TRANSIT_ENTER, true);
4041 }
4042 changed = true;
4043 }
4044 } else if (win.isVisibleNow()) {
4045 if (!runningAppAnimation) {
4046 applyAnimationLocked(win,
4047 WindowManagerPolicy.TRANSIT_EXIT, false);
4048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004049 changed = true;
4050 }
4051 }
4052
4053 wtoken.hidden = wtoken.hiddenRequested = !visible;
4054 if (!visible) {
4055 unsetAppFreezingScreenLocked(wtoken, true, true);
4056 } else {
4057 // If we are being set visible, and the starting window is
4058 // not yet displayed, then make sure it doesn't get displayed.
4059 WindowState swin = wtoken.startingWindow;
4060 if (swin != null && (swin.mDrawPending
4061 || swin.mCommitDrawPending)) {
4062 swin.mPolicyVisibility = false;
4063 swin.mPolicyVisibilityAfterAnim = false;
4064 }
4065 }
Romain Guy06882f82009-06-10 13:36:04 -07004066
Joe Onorato8a9b2202010-02-26 18:56:32 -08004067 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4069 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004070
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004071 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004072 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004073 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004074 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004075 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4076 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004077 performLayoutAndPlaceSurfacesLocked();
4078 }
Jeff Brown2e44b072011-01-24 15:21:56 -08004079 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004080 }
4081 }
4082
4083 if (wtoken.animation != null) {
4084 delayed = true;
4085 }
Romain Guy06882f82009-06-10 13:36:04 -07004086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004087 return delayed;
4088 }
4089
4090 public void setAppVisibility(IBinder token, boolean visible) {
4091 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4092 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004093 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004094 }
4095
4096 AppWindowToken wtoken;
4097
4098 synchronized(mWindowMap) {
4099 wtoken = findAppWindowToken(token);
4100 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004101 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 return;
4103 }
4104
4105 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004106 RuntimeException e = null;
4107 if (!HIDE_STACK_CRAWLS) {
4108 e = new RuntimeException();
4109 e.fillInStackTrace();
4110 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004111 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 + "): mNextAppTransition=" + mNextAppTransition
4113 + " hidden=" + wtoken.hidden
4114 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4115 }
Romain Guy06882f82009-06-10 13:36:04 -07004116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 // If we are preparing an app transition, then delay changing
4118 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004119 if (!mDisplayFrozen && mPolicy.isScreenOn()
4120 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004121 // Already in requested state, don't do anything more.
4122 if (wtoken.hiddenRequested != visible) {
4123 return;
4124 }
4125 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004126
Joe Onorato8a9b2202010-02-26 18:56:32 -08004127 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004128 TAG, "Setting dummy animation on: " + wtoken);
4129 wtoken.setDummyAnimation();
4130 mOpeningApps.remove(wtoken);
4131 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004132 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 wtoken.inPendingTransaction = true;
4134 if (visible) {
4135 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 wtoken.startingDisplayed = false;
4137 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004138
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004139 // If the token is currently hidden (should be the
4140 // common case), then we need to set up to wait for
4141 // its windows to be ready.
4142 if (wtoken.hidden) {
4143 wtoken.allDrawn = false;
4144 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004145
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004146 if (wtoken.clientHidden) {
4147 // In the case where we are making an app visible
4148 // but holding off for a transition, we still need
4149 // to tell the client to make its windows visible so
4150 // they get drawn. Otherwise, we will wait on
4151 // performing the transition until all windows have
4152 // been drawn, they never will be, and we are sad.
4153 wtoken.clientHidden = false;
4154 wtoken.sendAppVisibilityToClients();
4155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004156 }
4157 } else {
4158 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004159
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004160 // If the token is currently visible (should be the
4161 // common case), then set up to wait for it to be hidden.
4162 if (!wtoken.hidden) {
4163 wtoken.waitingToHide = true;
4164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 }
4166 return;
4167 }
Romain Guy06882f82009-06-10 13:36:04 -07004168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004170 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 wtoken.updateReportedVisibilityLocked();
4172 Binder.restoreCallingIdentity(origId);
4173 }
4174 }
4175
4176 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4177 boolean unfreezeSurfaceNow, boolean force) {
4178 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004179 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 + " force=" + force);
4181 final int N = wtoken.allAppWindows.size();
4182 boolean unfrozeWindows = false;
4183 for (int i=0; i<N; i++) {
4184 WindowState w = wtoken.allAppWindows.get(i);
4185 if (w.mAppFreezing) {
4186 w.mAppFreezing = false;
4187 if (w.mSurface != null && !w.mOrientationChanging) {
4188 w.mOrientationChanging = true;
4189 }
4190 unfrozeWindows = true;
4191 }
4192 }
4193 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004194 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004195 wtoken.freezingScreen = false;
4196 mAppsFreezingScreen--;
4197 }
4198 if (unfreezeSurfaceNow) {
4199 if (unfrozeWindows) {
4200 mLayoutNeeded = true;
4201 performLayoutAndPlaceSurfacesLocked();
4202 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004203 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 }
4205 }
4206 }
Romain Guy06882f82009-06-10 13:36:04 -07004207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4209 int configChanges) {
4210 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004211 RuntimeException e = null;
4212 if (!HIDE_STACK_CRAWLS) {
4213 e = new RuntimeException();
4214 e.fillInStackTrace();
4215 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004216 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004217 + ": hidden=" + wtoken.hidden + " freezing="
4218 + wtoken.freezingScreen, e);
4219 }
4220 if (!wtoken.hiddenRequested) {
4221 if (!wtoken.freezingScreen) {
4222 wtoken.freezingScreen = true;
4223 mAppsFreezingScreen++;
4224 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004225 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4227 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4228 5000);
4229 }
4230 }
4231 final int N = wtoken.allAppWindows.size();
4232 for (int i=0; i<N; i++) {
4233 WindowState w = wtoken.allAppWindows.get(i);
4234 w.mAppFreezing = true;
4235 }
4236 }
4237 }
Romain Guy06882f82009-06-10 13:36:04 -07004238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 public void startAppFreezingScreen(IBinder token, int configChanges) {
4240 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4241 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004242 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004243 }
4244
4245 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004246 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004247 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 return;
4249 }
Romain Guy06882f82009-06-10 13:36:04 -07004250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 AppWindowToken wtoken = findAppWindowToken(token);
4252 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004253 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 return;
4255 }
4256 final long origId = Binder.clearCallingIdentity();
4257 startAppFreezingScreenLocked(wtoken, configChanges);
4258 Binder.restoreCallingIdentity(origId);
4259 }
4260 }
Romain Guy06882f82009-06-10 13:36:04 -07004261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 public void stopAppFreezingScreen(IBinder token, boolean force) {
4263 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4264 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004265 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 }
4267
4268 synchronized(mWindowMap) {
4269 AppWindowToken wtoken = findAppWindowToken(token);
4270 if (wtoken == null || wtoken.appToken == null) {
4271 return;
4272 }
4273 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004274 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4276 unsetAppFreezingScreenLocked(wtoken, true, force);
4277 Binder.restoreCallingIdentity(origId);
4278 }
4279 }
Romain Guy06882f82009-06-10 13:36:04 -07004280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 public void removeAppToken(IBinder token) {
4282 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4283 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004284 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 }
4286
4287 AppWindowToken wtoken = null;
4288 AppWindowToken startingToken = null;
4289 boolean delayed = false;
4290
4291 final long origId = Binder.clearCallingIdentity();
4292 synchronized(mWindowMap) {
4293 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004295 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004296 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 wtoken.inPendingTransaction = false;
4298 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004299 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 if (mClosingApps.contains(wtoken)) {
4301 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004302 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004304 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 delayed = true;
4306 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004307 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 TAG, "Removing app " + wtoken + " delayed=" + delayed
4309 + " animation=" + wtoken.animation
4310 + " animating=" + wtoken.animating);
4311 if (delayed) {
4312 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004313 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4314 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004316 } else {
4317 // Make sure there is no animation running on this token,
4318 // so any windows associated with it will be removed as
4319 // soon as their animations are complete
4320 wtoken.animation = null;
4321 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004323 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4324 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 mAppTokens.remove(wtoken);
4326 wtoken.removed = true;
4327 if (wtoken.startingData != null) {
4328 startingToken = wtoken;
4329 }
4330 unsetAppFreezingScreenLocked(wtoken, true, true);
4331 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004332 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004334 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004335 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004336 }
4337 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004338 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 }
Romain Guy06882f82009-06-10 13:36:04 -07004340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004341 if (!delayed && wtoken != null) {
4342 wtoken.updateReportedVisibilityLocked();
4343 }
4344 }
4345 Binder.restoreCallingIdentity(origId);
4346
4347 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004348 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 + startingToken + ": app token removed");
4350 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4351 mH.sendMessage(m);
4352 }
4353 }
4354
4355 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4356 final int NW = token.windows.size();
4357 for (int i=0; i<NW; i++) {
4358 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004359 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004361 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 int j = win.mChildWindows.size();
4363 while (j > 0) {
4364 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004365 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004366 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004367 "Tmp removing child window " + cwin);
4368 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 }
4370 }
4371 return NW > 0;
4372 }
4373
4374 void dumpAppTokensLocked() {
4375 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004376 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004377 }
4378 }
Romain Guy06882f82009-06-10 13:36:04 -07004379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004380 void dumpWindowsLocked() {
4381 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004382 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 }
4384 }
Romain Guy06882f82009-06-10 13:36:04 -07004385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 private int findWindowOffsetLocked(int tokenPos) {
4387 final int NW = mWindows.size();
4388
4389 if (tokenPos >= mAppTokens.size()) {
4390 int i = NW;
4391 while (i > 0) {
4392 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004393 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 if (win.getAppToken() != null) {
4395 return i+1;
4396 }
4397 }
4398 }
4399
4400 while (tokenPos > 0) {
4401 // Find the first app token below the new position that has
4402 // a window displayed.
4403 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004404 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004405 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004406 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004407 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004408 "Skipping token -- currently sending to bottom");
4409 tokenPos--;
4410 continue;
4411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004412 int i = wtoken.windows.size();
4413 while (i > 0) {
4414 i--;
4415 WindowState win = wtoken.windows.get(i);
4416 int j = win.mChildWindows.size();
4417 while (j > 0) {
4418 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004419 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004420 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004421 for (int pos=NW-1; pos>=0; pos--) {
4422 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004423 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 "Found child win @" + (pos+1));
4425 return pos+1;
4426 }
4427 }
4428 }
4429 }
4430 for (int pos=NW-1; pos>=0; pos--) {
4431 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004432 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 return pos+1;
4434 }
4435 }
4436 }
4437 tokenPos--;
4438 }
4439
4440 return 0;
4441 }
4442
4443 private final int reAddWindowLocked(int index, WindowState win) {
4444 final int NCW = win.mChildWindows.size();
4445 boolean added = false;
4446 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004447 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004449 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004450 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004451 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452 mWindows.add(index, win);
4453 index++;
4454 added = true;
4455 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004456 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004457 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004458 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 mWindows.add(index, cwin);
4460 index++;
4461 }
4462 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004463 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004464 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004465 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 mWindows.add(index, win);
4467 index++;
4468 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004469 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 return index;
4471 }
Romain Guy06882f82009-06-10 13:36:04 -07004472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4474 final int NW = token.windows.size();
4475 for (int i=0; i<NW; i++) {
4476 index = reAddWindowLocked(index, token.windows.get(i));
4477 }
4478 return index;
4479 }
4480
4481 public void moveAppToken(int index, IBinder token) {
4482 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4483 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004484 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 }
4486
4487 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004488 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 if (DEBUG_REORDER) dumpAppTokensLocked();
4490 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004491 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4492 "Start moving token " + wtoken + " initially at "
4493 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004495 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004496 + token + " (" + wtoken + ")");
4497 return;
4498 }
4499 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004500 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004501 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004504 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004505 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004506 if (DEBUG_REORDER) dumpWindowsLocked();
4507 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004508 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509 if (DEBUG_REORDER) dumpWindowsLocked();
4510 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004511 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004513 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4514 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004516 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004518 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 }
4520 Binder.restoreCallingIdentity(origId);
4521 }
4522 }
4523
4524 private void removeAppTokensLocked(List<IBinder> tokens) {
4525 // XXX This should be done more efficiently!
4526 // (take advantage of the fact that both lists should be
4527 // ordered in the same way.)
4528 int N = tokens.size();
4529 for (int i=0; i<N; i++) {
4530 IBinder token = tokens.get(i);
4531 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004532 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4533 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004534 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004535 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004536 + token + " (" + wtoken + ")");
4537 i--;
4538 N--;
4539 }
4540 }
4541 }
4542
Dianne Hackborna8f60182009-09-01 19:01:50 -07004543 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4544 boolean updateFocusAndLayout) {
4545 // First remove all of the windows from the list.
4546 tmpRemoveAppWindowsLocked(wtoken);
4547
4548 // Where to start adding?
4549 int pos = findWindowOffsetLocked(tokenPos);
4550
4551 // And now add them back at the correct place.
4552 pos = reAddAppWindowsLocked(pos, wtoken);
4553
4554 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004555 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004556 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4557 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004558 assignLayersLocked();
4559 }
4560 mLayoutNeeded = true;
4561 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004562 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004563 }
4564 }
4565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004566 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4567 // First remove all of the windows from the list.
4568 final int N = tokens.size();
4569 int i;
4570 for (i=0; i<N; i++) {
4571 WindowToken token = mTokenMap.get(tokens.get(i));
4572 if (token != null) {
4573 tmpRemoveAppWindowsLocked(token);
4574 }
4575 }
4576
4577 // Where to start adding?
4578 int pos = findWindowOffsetLocked(tokenPos);
4579
4580 // And now add them back at the correct place.
4581 for (i=0; i<N; i++) {
4582 WindowToken token = mTokenMap.get(tokens.get(i));
4583 if (token != null) {
4584 pos = reAddAppWindowsLocked(pos, token);
4585 }
4586 }
4587
Jeff Brown2e44b072011-01-24 15:21:56 -08004588 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004589 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4590 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004591 assignLayersLocked();
4592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 mLayoutNeeded = true;
4594 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004595 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596
4597 //dump();
4598 }
4599
4600 public void moveAppTokensToTop(List<IBinder> tokens) {
4601 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4602 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004603 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004604 }
4605
4606 final long origId = Binder.clearCallingIdentity();
4607 synchronized(mWindowMap) {
4608 removeAppTokensLocked(tokens);
4609 final int N = tokens.size();
4610 for (int i=0; i<N; i++) {
4611 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4612 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004613 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4614 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004615 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004616 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004617 mToTopApps.remove(wt);
4618 mToBottomApps.remove(wt);
4619 mToTopApps.add(wt);
4620 wt.sendingToBottom = false;
4621 wt.sendingToTop = true;
4622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 }
4624 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004625
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004626 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004627 moveAppWindowsLocked(tokens, mAppTokens.size());
4628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004629 }
4630 Binder.restoreCallingIdentity(origId);
4631 }
4632
4633 public void moveAppTokensToBottom(List<IBinder> tokens) {
4634 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4635 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004636 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004637 }
4638
4639 final long origId = Binder.clearCallingIdentity();
4640 synchronized(mWindowMap) {
4641 removeAppTokensLocked(tokens);
4642 final int N = tokens.size();
4643 int pos = 0;
4644 for (int i=0; i<N; i++) {
4645 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4646 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004647 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4648 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004649 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004650 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004651 mToTopApps.remove(wt);
4652 mToBottomApps.remove(wt);
4653 mToBottomApps.add(i, wt);
4654 wt.sendingToTop = false;
4655 wt.sendingToBottom = true;
4656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 pos++;
4658 }
4659 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004660
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004661 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004662 moveAppWindowsLocked(tokens, 0);
4663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 }
4665 Binder.restoreCallingIdentity(origId);
4666 }
4667
4668 // -------------------------------------------------------------
4669 // Misc IWindowSession methods
4670 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004671
Jim Miller284b62e2010-06-08 14:27:42 -07004672 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004673 {
Jim Miller284b62e2010-06-08 14:27:42 -07004674 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4675 // called before DevicePolicyManagerService has started.
4676 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4677 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4678 Context.DEVICE_POLICY_SERVICE);
4679 if (dpm != null) {
4680 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4681 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4682 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4683 }
Jim Millerd6b57052010-06-07 17:52:42 -07004684 }
Jim Miller284b62e2010-06-08 14:27:42 -07004685 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004686 }
4687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004689 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004690 != PackageManager.PERMISSION_GRANTED) {
4691 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4692 }
Jim Millerd6b57052010-06-07 17:52:42 -07004693
Jim Miller284b62e2010-06-08 14:27:42 -07004694 synchronized (mKeyguardTokenWatcher) {
4695 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004696 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 }
4698
4699 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004700 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004701 != PackageManager.PERMISSION_GRANTED) {
4702 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004704
Jim Miller284b62e2010-06-08 14:27:42 -07004705 synchronized (mKeyguardTokenWatcher) {
4706 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004707
Jim Miller284b62e2010-06-08 14:27:42 -07004708 if (!mKeyguardTokenWatcher.isAcquired()) {
4709 // If we are the last one to reenable the keyguard wait until
4710 // we have actually finished reenabling until returning.
4711 // It is possible that reenableKeyguard() can be called before
4712 // the previous disableKeyguard() is handled, in which case
4713 // neither mKeyguardTokenWatcher.acquired() or released() would
4714 // be called. In that case mKeyguardDisabled will be false here
4715 // and we have nothing to wait for.
4716 while (mKeyguardDisabled) {
4717 try {
4718 mKeyguardTokenWatcher.wait();
4719 } catch (InterruptedException e) {
4720 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004721 }
4722 }
4723 }
4724 }
4725 }
4726
4727 /**
4728 * @see android.app.KeyguardManager#exitKeyguardSecurely
4729 */
4730 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004731 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 != PackageManager.PERMISSION_GRANTED) {
4733 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4734 }
4735 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4736 public void onKeyguardExitResult(boolean success) {
4737 try {
4738 callback.onKeyguardExitResult(success);
4739 } catch (RemoteException e) {
4740 // Client has died, we don't care.
4741 }
4742 }
4743 });
4744 }
4745
4746 public boolean inKeyguardRestrictedInputMode() {
4747 return mPolicy.inKeyguardRestrictedKeyInputMode();
4748 }
Romain Guy06882f82009-06-10 13:36:04 -07004749
Dianne Hackbornffa42482009-09-23 22:20:11 -07004750 public void closeSystemDialogs(String reason) {
4751 synchronized(mWindowMap) {
4752 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004753 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004754 if (w.mSurface != null) {
4755 try {
4756 w.mClient.closeSystemDialogs(reason);
4757 } catch (RemoteException e) {
4758 }
4759 }
4760 }
4761 }
4762 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764 static float fixScale(float scale) {
4765 if (scale < 0) scale = 0;
4766 else if (scale > 20) scale = 20;
4767 return Math.abs(scale);
4768 }
Romain Guy06882f82009-06-10 13:36:04 -07004769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 public void setAnimationScale(int which, float scale) {
4771 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4772 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004773 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004774 }
4775
4776 if (scale < 0) scale = 0;
4777 else if (scale > 20) scale = 20;
4778 scale = Math.abs(scale);
4779 switch (which) {
4780 case 0: mWindowAnimationScale = fixScale(scale); break;
4781 case 1: mTransitionAnimationScale = fixScale(scale); break;
4782 }
Romain Guy06882f82009-06-10 13:36:04 -07004783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004784 // Persist setting
4785 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4786 }
Romain Guy06882f82009-06-10 13:36:04 -07004787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 public void setAnimationScales(float[] scales) {
4789 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4790 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004791 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004792 }
4793
4794 if (scales != null) {
4795 if (scales.length >= 1) {
4796 mWindowAnimationScale = fixScale(scales[0]);
4797 }
4798 if (scales.length >= 2) {
4799 mTransitionAnimationScale = fixScale(scales[1]);
4800 }
4801 }
Romain Guy06882f82009-06-10 13:36:04 -07004802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004803 // Persist setting
4804 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4805 }
Romain Guy06882f82009-06-10 13:36:04 -07004806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 public float getAnimationScale(int which) {
4808 switch (which) {
4809 case 0: return mWindowAnimationScale;
4810 case 1: return mTransitionAnimationScale;
4811 }
4812 return 0;
4813 }
Romain Guy06882f82009-06-10 13:36:04 -07004814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815 public float[] getAnimationScales() {
4816 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4817 }
Romain Guy06882f82009-06-10 13:36:04 -07004818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004819 public int getSwitchState(int sw) {
4820 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4821 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004822 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004824 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 }
Romain Guy06882f82009-06-10 13:36:04 -07004826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 public int getSwitchStateForDevice(int devid, int sw) {
4828 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4829 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004830 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004832 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004833 }
Romain Guy06882f82009-06-10 13:36:04 -07004834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 public int getScancodeState(int sw) {
4836 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4837 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004838 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004840 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004841 }
Romain Guy06882f82009-06-10 13:36:04 -07004842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 public int getScancodeStateForDevice(int devid, int sw) {
4844 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4845 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004846 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004847 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004848 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004849 }
Romain Guy06882f82009-06-10 13:36:04 -07004850
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004851 public int getTrackballScancodeState(int sw) {
4852 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4853 "getTrackballScancodeState()")) {
4854 throw new SecurityException("Requires READ_INPUT_STATE permission");
4855 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004856 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004857 }
4858
4859 public int getDPadScancodeState(int sw) {
4860 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4861 "getDPadScancodeState()")) {
4862 throw new SecurityException("Requires READ_INPUT_STATE permission");
4863 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004864 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004865 }
4866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 public int getKeycodeState(int sw) {
4868 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4869 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004870 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004872 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 }
Romain Guy06882f82009-06-10 13:36:04 -07004874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004875 public int getKeycodeStateForDevice(int devid, int sw) {
4876 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4877 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004878 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004879 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004880 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 }
Romain Guy06882f82009-06-10 13:36:04 -07004882
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004883 public int getTrackballKeycodeState(int sw) {
4884 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4885 "getTrackballKeycodeState()")) {
4886 throw new SecurityException("Requires READ_INPUT_STATE permission");
4887 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004888 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004889 }
4890
4891 public int getDPadKeycodeState(int sw) {
4892 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4893 "getDPadKeycodeState()")) {
4894 throw new SecurityException("Requires READ_INPUT_STATE permission");
4895 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004896 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004897 }
Jeff Browna41ca772010-08-11 14:46:32 -07004898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004899 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004900 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004901 }
Romain Guy06882f82009-06-10 13:36:04 -07004902
Jeff Browna41ca772010-08-11 14:46:32 -07004903 public InputChannel monitorInput(String inputChannelName) {
4904 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4905 "monitorInput()")) {
4906 throw new SecurityException("Requires READ_INPUT_STATE permission");
4907 }
4908 return mInputManager.monitorInput(inputChannelName);
4909 }
4910
Jeff Brown8d608662010-08-30 03:02:23 -07004911 public InputDevice getInputDevice(int deviceId) {
4912 return mInputManager.getInputDevice(deviceId);
4913 }
4914
4915 public int[] getInputDeviceIds() {
4916 return mInputManager.getInputDeviceIds();
4917 }
4918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 public void enableScreenAfterBoot() {
4920 synchronized(mWindowMap) {
4921 if (mSystemBooted) {
4922 return;
4923 }
4924 mSystemBooted = true;
4925 }
Romain Guy06882f82009-06-10 13:36:04 -07004926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004927 performEnableScreen();
4928 }
Romain Guy06882f82009-06-10 13:36:04 -07004929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 public void enableScreenIfNeededLocked() {
4931 if (mDisplayEnabled) {
4932 return;
4933 }
4934 if (!mSystemBooted) {
4935 return;
4936 }
4937 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4938 }
Romain Guy06882f82009-06-10 13:36:04 -07004939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004940 public void performEnableScreen() {
4941 synchronized(mWindowMap) {
4942 if (mDisplayEnabled) {
4943 return;
4944 }
4945 if (!mSystemBooted) {
4946 return;
4947 }
Romain Guy06882f82009-06-10 13:36:04 -07004948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 // Don't enable the screen until all existing windows
4950 // have been drawn.
4951 final int N = mWindows.size();
4952 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004953 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004954 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 return;
4956 }
4957 }
Romain Guy06882f82009-06-10 13:36:04 -07004958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 mDisplayEnabled = true;
4960 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004961 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 StringWriter sw = new StringWriter();
4963 PrintWriter pw = new PrintWriter(sw);
4964 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004965 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004966 }
4967 try {
4968 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4969 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004970 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004971 Parcel data = Parcel.obtain();
4972 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4973 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4974 data, null, 0);
4975 data.recycle();
4976 }
4977 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004978 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004979 }
4980 }
Romain Guy06882f82009-06-10 13:36:04 -07004981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004984 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004985 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4986 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004987 }
Romain Guy06882f82009-06-10 13:36:04 -07004988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004989 public void setInTouchMode(boolean mode) {
4990 synchronized(mWindowMap) {
4991 mInTouchMode = mode;
4992 }
4993 }
4994
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004995 // TODO: more accounting of which pid(s) turned it on, keep count,
4996 // only allow disables from pids which have count on, etc.
4997 public void showStrictModeViolation(boolean on) {
4998 int pid = Binder.getCallingPid();
4999 synchronized(mWindowMap) {
5000 // Ignoring requests to enable the red border from clients
5001 // which aren't on screen. (e.g. Broadcast Receivers in
5002 // the background..)
5003 if (on) {
5004 boolean isVisible = false;
5005 for (WindowState ws : mWindows) {
5006 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
5007 isVisible = true;
5008 break;
5009 }
5010 }
5011 if (!isVisible) {
5012 return;
5013 }
5014 }
5015
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005016 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005017 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005018 try {
5019 if (mStrictModeFlash == null) {
5020 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
5021 }
5022 mStrictModeFlash.setVisibility(on);
5023 } finally {
5024 Surface.closeTransaction();
5025 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005026 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005027 }
5028 }
5029
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08005030 public void setStrictModeVisualIndicatorPreference(String value) {
5031 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
5032 }
5033
Dianne Hackbornd2835932010-12-13 16:28:46 -08005034 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005035 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5036 "screenshotApplications()")) {
5037 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5038 }
5039
5040 Bitmap rawss;
5041
Dianne Hackbornd2835932010-12-13 16:28:46 -08005042 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005043 final Rect frame = new Rect();
5044
5045 float scale;
5046 int sw, sh, dw, dh;
5047 int rot;
5048
5049 synchronized(mWindowMap) {
5050 long ident = Binder.clearCallingIdentity();
5051
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005052 dw = mDisplay.getWidth();
5053 dh = mDisplay.getHeight();
5054
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005055 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5056 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5057 + TYPE_LAYER_OFFSET;
5058 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5059
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005060 boolean isImeTarget = mInputMethodTarget != null
5061 && mInputMethodTarget.mAppToken != null
5062 && mInputMethodTarget.mAppToken.appToken != null
5063 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
5064
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005065 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005066 boolean including = false;
5067 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005068 WindowState ws = mWindows.get(i);
5069 if (ws.mSurface == null) {
5070 continue;
5071 }
5072 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08005073 continue;
5074 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005075 // When we will skip windows: when we are not including
5076 // ones behind a window we didn't skip, and we are actually
5077 // taking a screenshot of a specific app.
5078 if (!including && appToken != null) {
5079 // Also, we can possibly skip this window if it is not
5080 // an IME target or the application for the screenshot
5081 // is not the current IME target.
5082 if (!ws.mIsImWindow || !isImeTarget) {
5083 // And finally, this window is of no interest if it
5084 // is not associated with the screenshot app.
5085 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
5086 continue;
5087 }
5088 }
5089 }
5090
5091 // We keep on including windows until we go past a full-screen
5092 // window.
5093 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
5094
Dianne Hackbornd2835932010-12-13 16:28:46 -08005095 if (maxLayer < ws.mAnimLayer) {
5096 maxLayer = ws.mAnimLayer;
5097 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005098 final Rect wf = ws.mFrame;
5099 final Rect cr = ws.mContentInsets;
5100 int left = wf.left + cr.left;
5101 int top = wf.top + cr.top;
5102 int right = wf.right - cr.right;
5103 int bottom = wf.bottom - cr.bottom;
5104 frame.union(left, top, right, bottom);
5105 }
5106 Binder.restoreCallingIdentity(ident);
5107
Dianne Hackborndd962ee2011-02-02 11:11:50 -08005108 // Constrain frame to the screen size.
5109 frame.intersect(0, 0, dw, dh);
5110
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005111 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005112 return null;
5113 }
5114
5115 // The screenshot API does not apply the current screen rotation.
5116 rot = mDisplay.getRotation();
5117 int fw = frame.width();
5118 int fh = frame.height();
5119
5120 // First try reducing to fit in x dimension.
5121 scale = maxWidth/(float)fw;
5122 sw = maxWidth;
5123 sh = (int)(fh*scale);
5124 if (sh > maxHeight) {
5125 // y dimension became too long; constrain by that.
5126 scale = maxHeight/(float)fh;
5127 sw = (int)(fw*scale);
5128 sh = maxHeight;
5129 }
5130
5131 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005132 dw = (int)(dw*scale);
5133 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005134 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5135 int tmp = dw;
5136 dw = dh;
5137 dh = tmp;
5138 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5139 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005140 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005141 }
5142
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005143 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005144 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5145 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005146 return null;
5147 }
5148
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005149 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5150 Matrix matrix = new Matrix();
5151 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5152 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5153 Canvas canvas = new Canvas(bm);
5154 canvas.drawBitmap(rawss, matrix, null);
5155
5156 rawss.recycle();
5157 return bm;
5158 }
5159
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005160 public void freezeRotation() {
5161 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5162 "setRotation()")) {
5163 throw new SecurityException("Requires SET_ORIENTATION permission");
5164 }
5165
5166 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5167 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5168 }
5169
5170 public void thawRotation() {
5171 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5172 "setRotation()")) {
5173 throw new SecurityException("Requires SET_ORIENTATION permission");
5174 }
5175
5176 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5177 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5178 }
5179
Romain Guy06882f82009-06-10 13:36:04 -07005180 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005181 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005182 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005183 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005184 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005185 }
5186
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005187 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005188 }
Romain Guy06882f82009-06-10 13:36:04 -07005189
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005190 public void setRotationUnchecked(int rotation,
5191 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005192 if(DEBUG_ORIENTATION) Slog.v(TAG,
David 'Digit' Turner910a0682011-02-05 00:34:46 +01005193 "setRotationUnchecked(rotation=" + rotation +
5194 " alwaysSendConfiguration=" + alwaysSendConfiguration +
5195 " animFlags=" + animFlags);
Romain Guy06882f82009-06-10 13:36:04 -07005196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005197 long origId = Binder.clearCallingIdentity();
5198 boolean changed;
5199 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005200 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005201 }
Romain Guy06882f82009-06-10 13:36:04 -07005202
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005203 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005204 sendNewConfiguration();
5205 }
Romain Guy06882f82009-06-10 13:36:04 -07005206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005207 Binder.restoreCallingIdentity(origId);
5208 }
Romain Guy06882f82009-06-10 13:36:04 -07005209
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005210 /**
5211 * Apply a new rotation to the screen, respecting the requests of
5212 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5213 * re-evaluate the desired rotation.
5214 *
5215 * Returns null if the rotation has been changed. In this case YOU
5216 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5217 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005218 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005219 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005220 // Potential rotation during a drag. Don't do the rotation now, but make
5221 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005222 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5223 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5224 mDeferredRotation = rotation;
5225 mDeferredRotationAnimFlags = animFlags;
5226 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005227 return false;
5228 }
5229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005230 boolean changed;
5231 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005232 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5233 rotation = mDeferredRotation;
5234 mRequestedRotation = rotation;
5235 mLastRotationFlags = mDeferredRotationAnimFlags;
5236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005237 rotation = mRequestedRotation;
5238 } else {
5239 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005240 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005242 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005243 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005244 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005246 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005249 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005250 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 "Rotation changed to " + rotation
5252 + " from " + mRotation
5253 + " (forceApp=" + mForcedAppOrientation
5254 + ", req=" + mRequestedRotation + ")");
5255 mRotation = rotation;
5256 mWindowsFreezingScreen = true;
5257 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5258 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5259 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005260 mWaitingForConfig = true;
5261 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005262 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005263 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005264 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005265 if (mDisplayEnabled) {
David 'Digit' Turner910a0682011-02-05 00:34:46 +01005266 // NOTE: We disable the rotation in the emulator because
5267 // it doesn't support hardware OpenGL emulation yet.
5268 if (CUSTOM_SCREEN_ROTATION && !mInEmulator) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005269 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005270 if (!inTransaction) {
5271 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5272 ">>> OPEN TRANSACTION setRotationUnchecked");
5273 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005274 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005275 try {
5276 if (mScreenRotationAnimation != null) {
5277 mScreenRotationAnimation.setRotation(rotation);
5278 }
5279 } finally {
5280 if (!inTransaction) {
5281 Surface.closeTransaction();
5282 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5283 "<<< CLOSE TRANSACTION setRotationUnchecked");
5284 }
5285 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005286 Surface.setOrientation(0, rotation, animFlags);
5287 Surface.unfreezeDisplay(0);
5288 } else {
5289 Surface.setOrientation(0, rotation, animFlags);
5290 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291 }
5292 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005293 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005294 if (w.mSurface != null) {
5295 w.mOrientationChanging = true;
5296 }
5297 }
5298 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5299 try {
5300 mRotationWatchers.get(i).onRotationChanged(rotation);
5301 } catch (RemoteException e) {
5302 }
5303 }
5304 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005306 return changed;
5307 }
Romain Guy06882f82009-06-10 13:36:04 -07005308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005309 public int getRotation() {
5310 return mRotation;
5311 }
5312
5313 public int watchRotation(IRotationWatcher watcher) {
5314 final IBinder watcherBinder = watcher.asBinder();
5315 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5316 public void binderDied() {
5317 synchronized (mWindowMap) {
5318 for (int i=0; i<mRotationWatchers.size(); i++) {
5319 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005320 IRotationWatcher removed = mRotationWatchers.remove(i);
5321 if (removed != null) {
5322 removed.asBinder().unlinkToDeath(this, 0);
5323 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005324 i--;
5325 }
5326 }
5327 }
5328 }
5329 };
Romain Guy06882f82009-06-10 13:36:04 -07005330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005331 synchronized (mWindowMap) {
5332 try {
5333 watcher.asBinder().linkToDeath(dr, 0);
5334 mRotationWatchers.add(watcher);
5335 } catch (RemoteException e) {
5336 // Client died, no cleanup needed.
5337 }
Romain Guy06882f82009-06-10 13:36:04 -07005338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005339 return mRotation;
5340 }
5341 }
5342
5343 /**
5344 * Starts the view server on the specified port.
5345 *
5346 * @param port The port to listener to.
5347 *
5348 * @return True if the server was successfully started, false otherwise.
5349 *
5350 * @see com.android.server.ViewServer
5351 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5352 */
5353 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005354 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005355 return false;
5356 }
5357
5358 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5359 return false;
5360 }
5361
5362 if (port < 1024) {
5363 return false;
5364 }
5365
5366 if (mViewServer != null) {
5367 if (!mViewServer.isRunning()) {
5368 try {
5369 return mViewServer.start();
5370 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005371 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005372 }
5373 }
5374 return false;
5375 }
5376
5377 try {
5378 mViewServer = new ViewServer(this, port);
5379 return mViewServer.start();
5380 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005381 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 }
5383 return false;
5384 }
5385
Romain Guy06882f82009-06-10 13:36:04 -07005386 private boolean isSystemSecure() {
5387 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5388 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5389 }
5390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005391 /**
5392 * Stops the view server if it exists.
5393 *
5394 * @return True if the server stopped, false if it wasn't started or
5395 * couldn't be stopped.
5396 *
5397 * @see com.android.server.ViewServer
5398 */
5399 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005400 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005401 return false;
5402 }
5403
5404 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5405 return false;
5406 }
5407
5408 if (mViewServer != null) {
5409 return mViewServer.stop();
5410 }
5411 return false;
5412 }
5413
5414 /**
5415 * Indicates whether the view server is running.
5416 *
5417 * @return True if the server is running, false otherwise.
5418 *
5419 * @see com.android.server.ViewServer
5420 */
5421 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005422 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005423 return false;
5424 }
5425
5426 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5427 return false;
5428 }
5429
5430 return mViewServer != null && mViewServer.isRunning();
5431 }
5432
5433 /**
5434 * Lists all availble windows in the system. The listing is written in the
5435 * specified Socket's output stream with the following syntax:
5436 * windowHashCodeInHexadecimal windowName
5437 * Each line of the ouput represents a different window.
5438 *
5439 * @param client The remote client to send the listing to.
5440 * @return False if an error occured, true otherwise.
5441 */
5442 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005443 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005444 return false;
5445 }
5446
5447 boolean result = true;
5448
Jeff Browne33348b2010-07-15 23:54:05 -07005449 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005450 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005451 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005452 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005453 }
5454
5455 BufferedWriter out = null;
5456
5457 // Any uncaught exception will crash the system process
5458 try {
5459 OutputStream clientStream = client.getOutputStream();
5460 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5461
5462 final int count = windows.length;
5463 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005464 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005465 out.write(Integer.toHexString(System.identityHashCode(w)));
5466 out.write(' ');
5467 out.append(w.mAttrs.getTitle());
5468 out.write('\n');
5469 }
5470
5471 out.write("DONE.\n");
5472 out.flush();
5473 } catch (Exception e) {
5474 result = false;
5475 } finally {
5476 if (out != null) {
5477 try {
5478 out.close();
5479 } catch (IOException e) {
5480 result = false;
5481 }
5482 }
5483 }
5484
5485 return result;
5486 }
5487
5488 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005489 * Returns the focused window in the following format:
5490 * windowHashCodeInHexadecimal windowName
5491 *
5492 * @param client The remote client to send the listing to.
5493 * @return False if an error occurred, true otherwise.
5494 */
5495 boolean viewServerGetFocusedWindow(Socket client) {
5496 if (isSystemSecure()) {
5497 return false;
5498 }
5499
5500 boolean result = true;
5501
5502 WindowState focusedWindow = getFocusedWindow();
5503
5504 BufferedWriter out = null;
5505
5506 // Any uncaught exception will crash the system process
5507 try {
5508 OutputStream clientStream = client.getOutputStream();
5509 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5510
5511 if(focusedWindow != null) {
5512 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5513 out.write(' ');
5514 out.append(focusedWindow.mAttrs.getTitle());
5515 }
5516 out.write('\n');
5517 out.flush();
5518 } catch (Exception e) {
5519 result = false;
5520 } finally {
5521 if (out != null) {
5522 try {
5523 out.close();
5524 } catch (IOException e) {
5525 result = false;
5526 }
5527 }
5528 }
5529
5530 return result;
5531 }
5532
5533 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005534 * Sends a command to a target window. The result of the command, if any, will be
5535 * written in the output stream of the specified socket.
5536 *
5537 * The parameters must follow this syntax:
5538 * windowHashcode extra
5539 *
5540 * Where XX is the length in characeters of the windowTitle.
5541 *
5542 * The first parameter is the target window. The window with the specified hashcode
5543 * will be the target. If no target can be found, nothing happens. The extra parameters
5544 * will be delivered to the target window and as parameters to the command itself.
5545 *
5546 * @param client The remote client to sent the result, if any, to.
5547 * @param command The command to execute.
5548 * @param parameters The command parameters.
5549 *
5550 * @return True if the command was successfully delivered, false otherwise. This does
5551 * not indicate whether the command itself was successful.
5552 */
5553 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005554 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005555 return false;
5556 }
5557
5558 boolean success = true;
5559 Parcel data = null;
5560 Parcel reply = null;
5561
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005562 BufferedWriter out = null;
5563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005564 // Any uncaught exception will crash the system process
5565 try {
5566 // Find the hashcode of the window
5567 int index = parameters.indexOf(' ');
5568 if (index == -1) {
5569 index = parameters.length();
5570 }
5571 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005572 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005573
5574 // Extract the command's parameter after the window description
5575 if (index < parameters.length()) {
5576 parameters = parameters.substring(index + 1);
5577 } else {
5578 parameters = "";
5579 }
5580
5581 final WindowManagerService.WindowState window = findWindow(hashCode);
5582 if (window == null) {
5583 return false;
5584 }
5585
5586 data = Parcel.obtain();
5587 data.writeInterfaceToken("android.view.IWindow");
5588 data.writeString(command);
5589 data.writeString(parameters);
5590 data.writeInt(1);
5591 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5592
5593 reply = Parcel.obtain();
5594
5595 final IBinder binder = window.mClient.asBinder();
5596 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5597 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5598
5599 reply.readException();
5600
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005601 if (!client.isOutputShutdown()) {
5602 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5603 out.write("DONE\n");
5604 out.flush();
5605 }
5606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005607 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005608 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005609 success = false;
5610 } finally {
5611 if (data != null) {
5612 data.recycle();
5613 }
5614 if (reply != null) {
5615 reply.recycle();
5616 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005617 if (out != null) {
5618 try {
5619 out.close();
5620 } catch (IOException e) {
5621
5622 }
5623 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005624 }
5625
5626 return success;
5627 }
5628
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005629 public void addWindowChangeListener(WindowChangeListener listener) {
5630 synchronized(mWindowMap) {
5631 mWindowChangeListeners.add(listener);
5632 }
5633 }
5634
5635 public void removeWindowChangeListener(WindowChangeListener listener) {
5636 synchronized(mWindowMap) {
5637 mWindowChangeListeners.remove(listener);
5638 }
5639 }
5640
5641 private void notifyWindowsChanged() {
5642 WindowChangeListener[] windowChangeListeners;
5643 synchronized(mWindowMap) {
5644 if(mWindowChangeListeners.isEmpty()) {
5645 return;
5646 }
5647 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5648 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5649 }
5650 int N = windowChangeListeners.length;
5651 for(int i = 0; i < N; i++) {
5652 windowChangeListeners[i].windowsChanged();
5653 }
5654 }
5655
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005656 private void notifyFocusChanged() {
5657 WindowChangeListener[] windowChangeListeners;
5658 synchronized(mWindowMap) {
5659 if(mWindowChangeListeners.isEmpty()) {
5660 return;
5661 }
5662 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5663 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5664 }
5665 int N = windowChangeListeners.length;
5666 for(int i = 0; i < N; i++) {
5667 windowChangeListeners[i].focusChanged();
5668 }
5669 }
5670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005671 private WindowState findWindow(int hashCode) {
5672 if (hashCode == -1) {
5673 return getFocusedWindow();
5674 }
5675
5676 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005677 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005678 final int count = windows.size();
5679
5680 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005681 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 if (System.identityHashCode(w) == hashCode) {
5683 return w;
5684 }
5685 }
5686 }
5687
5688 return null;
5689 }
5690
5691 /*
5692 * Instruct the Activity Manager to fetch the current configuration and broadcast
5693 * that to config-changed listeners if appropriate.
5694 */
5695 void sendNewConfiguration() {
5696 try {
5697 mActivityManager.updateConfiguration(null);
5698 } catch (RemoteException e) {
5699 }
5700 }
Romain Guy06882f82009-06-10 13:36:04 -07005701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005702 public Configuration computeNewConfiguration() {
5703 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005704 Configuration config = computeNewConfigurationLocked();
5705 if (config == null && mWaitingForConfig) {
5706 // Nothing changed but we are waiting for something... stop that!
5707 mWaitingForConfig = false;
5708 performLayoutAndPlaceSurfacesLocked();
5709 }
5710 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005711 }
5712 }
Romain Guy06882f82009-06-10 13:36:04 -07005713
Dianne Hackbornc485a602009-03-24 22:39:49 -07005714 Configuration computeNewConfigurationLocked() {
5715 Configuration config = new Configuration();
5716 if (!computeNewConfigurationLocked(config)) {
5717 return null;
5718 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005719 return config;
5720 }
Romain Guy06882f82009-06-10 13:36:04 -07005721
Dianne Hackbornc485a602009-03-24 22:39:49 -07005722 boolean computeNewConfigurationLocked(Configuration config) {
5723 if (mDisplay == null) {
5724 return false;
5725 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005726
5727 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005728
5729 // Use the effective "visual" dimensions based on current rotation
5730 final boolean rotated = (mRotation == Surface.ROTATION_90
5731 || mRotation == Surface.ROTATION_270);
5732 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5733 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5734
Dianne Hackbornc485a602009-03-24 22:39:49 -07005735 int orientation = Configuration.ORIENTATION_SQUARE;
5736 if (dw < dh) {
5737 orientation = Configuration.ORIENTATION_PORTRAIT;
5738 } else if (dw > dh) {
5739 orientation = Configuration.ORIENTATION_LANDSCAPE;
5740 }
5741 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005742
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005743 DisplayMetrics dm = new DisplayMetrics();
5744 mDisplay.getMetrics(dm);
5745 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5746
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005747 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005748 // Note we only do this once because at this point we don't
5749 // expect the screen to change in this way at runtime, and want
5750 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005751 int longSize = dw;
5752 int shortSize = dh;
5753 if (longSize < shortSize) {
5754 int tmp = longSize;
5755 longSize = shortSize;
5756 shortSize = tmp;
5757 }
5758 longSize = (int)(longSize/dm.density);
5759 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005760
Dianne Hackborn723738c2009-06-25 19:48:04 -07005761 // These semi-magic numbers define our compatibility modes for
5762 // applications with different screens. Don't change unless you
5763 // make sure to test lots and lots of apps!
5764 if (longSize < 470) {
5765 // This is shorter than an HVGA normal density screen (which
5766 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005767 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5768 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005769 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005770 // What size is this screen screen?
5771 if (longSize >= 800 && shortSize >= 600) {
5772 // SVGA or larger screens at medium density are the point
5773 // at which we consider it to be an extra large screen.
5774 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005775 } else if (longSize >= 530 && shortSize >= 400) {
5776 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005777 // at which we consider it to be a large screen.
5778 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5779 } else {
5780 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Dianne Hackborne97a12e2011-01-29 13:22:02 -08005781 }
5782
5783 // If this screen is wider than normal HVGA, or taller
5784 // than FWVGA, then for old apps we want to run in size
5785 // compatibility mode.
5786 if (shortSize > 321 || longSize > 570) {
5787 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005788 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005789
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005790 // Is this a long screen?
5791 if (((longSize*3)/5) >= (shortSize-1)) {
5792 // Anything wider than WVGA (5:3) is considering to be long.
5793 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5794 } else {
5795 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5796 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005797 }
5798 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005799 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005800
Jeff Brown597eec82011-01-31 17:12:25 -08005801 // Determine whether a hard keyboard is available and enabled.
Jeff Brown2992ea72011-01-28 22:04:14 -08005802 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5803 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5804 mHardKeyboardAvailable = hardKeyboardAvailable;
5805 mHardKeyboardEnabled = hardKeyboardAvailable;
5806
5807 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5808 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5809 }
5810 if (!mHardKeyboardEnabled) {
5811 config.keyboard = Configuration.KEYBOARD_NOKEYS;
Jeff Brown2992ea72011-01-28 22:04:14 -08005812 }
Jeff Brown597eec82011-01-31 17:12:25 -08005813
5814 // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
5815 // based on whether a hard or soft keyboard is present, whether navigation keys
5816 // are present and the lid switch state.
5817 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5818 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5819 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
5820 mPolicy.adjustConfigurationLw(config);
Dianne Hackbornc485a602009-03-24 22:39:49 -07005821 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005822 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005823
Jeff Brown2992ea72011-01-28 22:04:14 -08005824 public boolean isHardKeyboardAvailable() {
5825 synchronized (mWindowMap) {
5826 return mHardKeyboardAvailable;
5827 }
5828 }
5829
5830 public boolean isHardKeyboardEnabled() {
5831 synchronized (mWindowMap) {
5832 return mHardKeyboardEnabled;
5833 }
5834 }
5835
5836 public void setHardKeyboardEnabled(boolean enabled) {
5837 synchronized (mWindowMap) {
5838 if (mHardKeyboardEnabled != enabled) {
5839 mHardKeyboardEnabled = enabled;
5840 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5841 }
5842 }
5843 }
5844
5845 public void setOnHardKeyboardStatusChangeListener(
5846 OnHardKeyboardStatusChangeListener listener) {
5847 synchronized (mWindowMap) {
5848 mHardKeyboardStatusChangeListener = listener;
5849 }
5850 }
5851
5852 void notifyHardKeyboardStatusChange() {
5853 final boolean available, enabled;
5854 final OnHardKeyboardStatusChangeListener listener;
5855 synchronized (mWindowMap) {
5856 listener = mHardKeyboardStatusChangeListener;
5857 available = mHardKeyboardAvailable;
5858 enabled = mHardKeyboardEnabled;
5859 }
5860 if (listener != null) {
5861 listener.onHardKeyboardStatusChange(available, enabled);
5862 }
5863 }
5864
Christopher Tatea53146c2010-09-07 11:57:52 -07005865 // -------------------------------------------------------------
5866 // Drag and drop
5867 // -------------------------------------------------------------
5868
5869 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005870 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005871 if (DEBUG_DRAG) {
5872 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005873 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005874 + " asbinder=" + window.asBinder());
5875 }
5876
5877 final int callerPid = Binder.getCallingPid();
5878 final long origId = Binder.clearCallingIdentity();
5879 IBinder token = null;
5880
5881 try {
5882 synchronized (mWindowMap) {
5883 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005884 if (mDragState == null) {
5885 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5886 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
Dianne Hackbornac1471a2011-02-03 13:46:06 -08005887 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG "
5888 + surface + ": CREATE");
Christopher Tatea53146c2010-09-07 11:57:52 -07005889 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005890 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005891 token = new Binder();
Christopher Tate251602f2011-01-28 17:54:12 -08005892 mDragState = new DragState(token, surface, flags, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005893 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005894 token = mDragState.mToken = new Binder();
5895
5896 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005897 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5898 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005899 mH.sendMessageDelayed(msg, 5000);
5900 } else {
5901 Slog.w(TAG, "Drag already in progress");
5902 }
5903 } catch (Surface.OutOfResourcesException e) {
5904 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5905 if (mDragState != null) {
5906 mDragState.reset();
5907 mDragState = null;
5908 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005909 }
5910 }
5911 } finally {
5912 Binder.restoreCallingIdentity(origId);
5913 }
5914
5915 return token;
5916 }
5917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005918 // -------------------------------------------------------------
5919 // Input Events and Focus Management
5920 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005921
Jeff Brown349703e2010-06-22 01:27:15 -07005922 InputMonitor mInputMonitor = new InputMonitor();
5923
5924 /* Tracks the progress of input dispatch and ensures that input dispatch state
5925 * is kept in sync with changes in window focus, visibility, registration, and
5926 * other relevant Window Manager state transitions. */
5927 final class InputMonitor {
5928 // Current window with input focus for keys and other non-touch events. May be null.
5929 private WindowState mInputFocus;
5930
5931 // When true, prevents input dispatch from proceeding until set to false again.
5932 private boolean mInputDispatchFrozen;
5933
5934 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5935 private boolean mInputDispatchEnabled = true;
5936
Jeff Brown3a22cd92011-01-21 13:59:04 -08005937 // When true, need to call updateInputWindowsLw().
5938 private boolean mUpdateInputWindowsNeeded = true;
5939
Jeff Brown349703e2010-06-22 01:27:15 -07005940 // Temporary list of windows information to provide to the input dispatcher.
5941 private InputWindowList mTempInputWindows = new InputWindowList();
5942
5943 // Temporary input application object to provide to the input dispatcher.
5944 private InputApplication mTempInputApplication = new InputApplication();
5945
Jeff Brownb09abc12011-01-13 21:08:27 -08005946 // Set to true when the first input device configuration change notification
5947 // is received to indicate that the input devices are ready.
5948 private final Object mInputDevicesReadyMonitor = new Object();
5949 private boolean mInputDevicesReady;
5950
Jeff Brown349703e2010-06-22 01:27:15 -07005951 /* Notifies the window manager about a broken input channel.
5952 *
5953 * Called by the InputManager.
5954 */
Jeff Brown928e0542011-01-10 11:17:36 -08005955 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5956 if (inputWindowHandle == null) {
5957 return;
5958 }
5959
Jeff Brown349703e2010-06-22 01:27:15 -07005960 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005961 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005962 Slog.i(TAG, "WINDOW DIED " + windowState);
5963 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005964 }
5965 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005966
Jeff Brown519e0242010-09-15 15:18:56 -07005967 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005968 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005969 *
5970 * Called by the InputManager.
5971 */
Jeff Brown928e0542011-01-10 11:17:36 -08005972 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5973 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005974 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005975 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005976 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005977 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005978 if (windowState != null) {
5979 Slog.i(TAG, "Input event dispatching timed out sending to "
5980 + windowState.mAttrs.getTitle());
5981 appWindowToken = windowState.mAppToken;
5982 }
Jeff Brown349703e2010-06-22 01:27:15 -07005983 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005984 }
5985
Jeff Brown928e0542011-01-10 11:17:36 -08005986 if (appWindowToken == null && inputApplicationHandle != null) {
5987 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005988 Slog.i(TAG, "Input event dispatching timed out sending to application "
5989 + appWindowToken.stringName);
5990 }
Jeff Brown349703e2010-06-22 01:27:15 -07005991
Jeff Brown519e0242010-09-15 15:18:56 -07005992 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005993 try {
5994 // Notify the activity manager about the timeout and let it decide whether
5995 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005996 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005997 if (! abort) {
5998 // The activity manager declined to abort dispatching.
5999 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07006000 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07006001 }
Jeff Brown349703e2010-06-22 01:27:15 -07006002 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07006003 }
6004 }
Jeff Brownb88102f2010-09-08 11:49:43 -07006005 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07006006 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006007
Chris Tatea32dcf72010-10-14 12:13:50 -07006008 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07006009 final InputWindow inputWindow = windowList.add();
6010 inputWindow.inputChannel = mDragState.mServerChannel;
6011 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08006012 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07006013 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
6014 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6015 inputWindow.visible = true;
6016 inputWindow.canReceiveKeys = false;
6017 inputWindow.hasFocus = true;
6018 inputWindow.hasWallpaper = false;
6019 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07006020 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07006021 inputWindow.ownerPid = Process.myPid();
6022 inputWindow.ownerUid = Process.myUid();
6023
6024 // The drag window covers the entire display
6025 inputWindow.frameLeft = 0;
6026 inputWindow.frameTop = 0;
6027 inputWindow.frameRight = mDisplay.getWidth();
6028 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07006029
Jeff Brownfbf09772011-01-16 14:06:57 -08006030 // The drag window cannot receive new touches.
6031 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07006032 }
6033
Jeff Brown3a22cd92011-01-21 13:59:04 -08006034 public void setUpdateInputWindowsNeededLw() {
6035 mUpdateInputWindowsNeeded = true;
6036 }
6037
Jeff Brown349703e2010-06-22 01:27:15 -07006038 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08006039 public void updateInputWindowsLw(boolean force) {
6040 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006041 return;
6042 }
6043 mUpdateInputWindowsNeeded = false;
6044
Jeff Brown349703e2010-06-22 01:27:15 -07006045 // Populate the input window list with information about all of the windows that
6046 // could potentially receive input.
6047 // As an optimization, we could try to prune the list of windows but this turns
6048 // out to be difficult because only the native code knows for sure which window
6049 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07006050 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07006051
6052 // If there's a drag in flight, provide a pseudowindow to catch drag input
6053 final boolean inDrag = (mDragState != null);
6054 if (inDrag) {
6055 if (DEBUG_DRAG) {
6056 Log.d(TAG, "Inserting drag window");
6057 }
Chris Tatea32dcf72010-10-14 12:13:50 -07006058 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07006059 }
6060
Jeff Brown7fbdc842010-06-17 20:52:56 -07006061 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07006062 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006063 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07006064 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07006065 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07006066 continue;
6067 }
6068
Jeff Brown349703e2010-06-22 01:27:15 -07006069 final int flags = child.mAttrs.flags;
6070 final int type = child.mAttrs.type;
6071
6072 final boolean hasFocus = (child == mInputFocus);
6073 final boolean isVisible = child.isVisibleLw();
6074 final boolean hasWallpaper = (child == mWallpaperTarget)
6075 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07006076
6077 // If there's a drag in progress and 'child' is a potential drop target,
6078 // make sure it's been told about the drag
6079 if (inDrag && isVisible) {
6080 mDragState.sendDragStartedIfNeededLw(child);
6081 }
6082
Jeff Brown349703e2010-06-22 01:27:15 -07006083 // Add a window to our list of input windows.
6084 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08006085 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006086 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07006087 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07006088 inputWindow.layoutParamsFlags = flags;
6089 inputWindow.layoutParamsType = type;
6090 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
6091 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07006092 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07006093 inputWindow.hasFocus = hasFocus;
6094 inputWindow.hasWallpaper = hasWallpaper;
6095 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07006096 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07006097 inputWindow.ownerPid = child.mSession.mPid;
6098 inputWindow.ownerUid = child.mSession.mUid;
6099
6100 final Rect frame = child.mFrame;
6101 inputWindow.frameLeft = frame.left;
6102 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006103 inputWindow.frameRight = frame.right;
6104 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006105
6106 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006107 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006108
Jeff Brown349703e2010-06-22 01:27:15 -07006109 // Send windows to native code.
6110 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006111
Jeff Brown349703e2010-06-22 01:27:15 -07006112 // Clear the list in preparation for the next round.
6113 // Also avoids keeping InputChannel objects referenced unnecessarily.
6114 mTempInputWindows.clear();
6115 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006116
6117 /* Notifies that the input device configuration has changed. */
6118 public void notifyConfigurationChanged() {
6119 sendNewConfiguration();
6120
6121 synchronized (mInputDevicesReadyMonitor) {
6122 if (!mInputDevicesReady) {
6123 mInputDevicesReady = true;
6124 mInputDevicesReadyMonitor.notifyAll();
6125 }
6126 }
6127 }
6128
6129 /* Waits until the built-in input devices have been configured. */
6130 public boolean waitForInputDevicesReady(long timeoutMillis) {
6131 synchronized (mInputDevicesReadyMonitor) {
6132 if (!mInputDevicesReady) {
6133 try {
6134 mInputDevicesReadyMonitor.wait(timeoutMillis);
6135 } catch (InterruptedException ex) {
6136 }
6137 }
6138 return mInputDevicesReady;
6139 }
6140 }
6141
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006142 /* Notifies that the lid switch changed state. */
6143 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6144 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6145 }
6146
Jeff Brown349703e2010-06-22 01:27:15 -07006147 /* Provides an opportunity for the window manager policy to intercept early key
6148 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006149 public int interceptKeyBeforeQueueing(
6150 KeyEvent event, int policyFlags, boolean isScreenOn) {
6151 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006152 }
6153
6154 /* Provides an opportunity for the window manager policy to process a key before
6155 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006156 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006157 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006158 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006159 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006160 }
6161
Jeff Brown3915bb82010-11-05 15:02:16 -07006162 /* Provides an opportunity for the window manager policy to process a key that
6163 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006164 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006165 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006166 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006167 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006168 }
6169
Jeff Brown349703e2010-06-22 01:27:15 -07006170 /* Called when the current input focus changes.
6171 * Layer assignment is assumed to be complete by the time this is called.
6172 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006173 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006174 if (DEBUG_INPUT) {
6175 Slog.d(TAG, "Input focus has changed to " + newWindow);
6176 }
6177
6178 if (newWindow != mInputFocus) {
6179 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006180 // Displaying a window implicitly causes dispatching to be unpaused.
6181 // This is to protect against bugs if someone pauses dispatching but
6182 // forgets to resume.
6183 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006184 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006185
Jeff Brown349703e2010-06-22 01:27:15 -07006186 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006187 setUpdateInputWindowsNeededLw();
6188
6189 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006190 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006191 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006192 }
6193 }
6194
Jeff Brown349703e2010-06-22 01:27:15 -07006195 public void setFocusedAppLw(AppWindowToken newApp) {
6196 // Focused app has changed.
6197 if (newApp == null) {
6198 mInputManager.setFocusedApplication(null);
6199 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006200 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006201 mTempInputApplication.name = newApp.toString();
6202 mTempInputApplication.dispatchingTimeoutNanos =
6203 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006204
Jeff Brown349703e2010-06-22 01:27:15 -07006205 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006206
6207 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006208 }
6209 }
6210
Jeff Brown349703e2010-06-22 01:27:15 -07006211 public void pauseDispatchingLw(WindowToken window) {
6212 if (! window.paused) {
6213 if (DEBUG_INPUT) {
6214 Slog.v(TAG, "Pausing WindowToken " + window);
6215 }
6216
6217 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006218 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006219 }
6220 }
6221
6222 public void resumeDispatchingLw(WindowToken window) {
6223 if (window.paused) {
6224 if (DEBUG_INPUT) {
6225 Slog.v(TAG, "Resuming WindowToken " + window);
6226 }
6227
6228 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006229 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006230 }
6231 }
6232
6233 public void freezeInputDispatchingLw() {
6234 if (! mInputDispatchFrozen) {
6235 if (DEBUG_INPUT) {
6236 Slog.v(TAG, "Freezing input dispatching");
6237 }
6238
6239 mInputDispatchFrozen = true;
6240 updateInputDispatchModeLw();
6241 }
6242 }
6243
6244 public void thawInputDispatchingLw() {
6245 if (mInputDispatchFrozen) {
6246 if (DEBUG_INPUT) {
6247 Slog.v(TAG, "Thawing input dispatching");
6248 }
6249
6250 mInputDispatchFrozen = false;
6251 updateInputDispatchModeLw();
6252 }
6253 }
6254
6255 public void setEventDispatchingLw(boolean enabled) {
6256 if (mInputDispatchEnabled != enabled) {
6257 if (DEBUG_INPUT) {
6258 Slog.v(TAG, "Setting event dispatching to " + enabled);
6259 }
6260
6261 mInputDispatchEnabled = enabled;
6262 updateInputDispatchModeLw();
6263 }
6264 }
6265
6266 private void updateInputDispatchModeLw() {
6267 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6268 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006271 public void pauseKeyDispatching(IBinder _token) {
6272 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6273 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006274 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006275 }
6276
6277 synchronized (mWindowMap) {
6278 WindowToken token = mTokenMap.get(_token);
6279 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006280 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 }
6282 }
6283 }
6284
6285 public void resumeKeyDispatching(IBinder _token) {
6286 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6287 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006288 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006289 }
6290
6291 synchronized (mWindowMap) {
6292 WindowToken token = mTokenMap.get(_token);
6293 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006294 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295 }
6296 }
6297 }
6298
6299 public void setEventDispatching(boolean enabled) {
6300 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6301 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006302 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006303 }
6304
6305 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006306 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006307 }
6308 }
Romain Guy06882f82009-06-10 13:36:04 -07006309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006310 /**
6311 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006312 * Even when sync is false, this method may block while waiting for current
6313 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006314 *
6315 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006316 * {@link SystemClock#uptimeMillis()} as the timebase.)
6317 * @param sync If true, wait for the event to be completed before returning to the caller.
6318 * @return Returns true if event was dispatched, false if it was dropped for any reason
6319 */
6320 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6321 long downTime = ev.getDownTime();
6322 long eventTime = ev.getEventTime();
6323
6324 int action = ev.getAction();
6325 int code = ev.getKeyCode();
6326 int repeatCount = ev.getRepeatCount();
6327 int metaState = ev.getMetaState();
6328 int deviceId = ev.getDeviceId();
6329 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006330 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006331 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006332
6333 if (source == InputDevice.SOURCE_UNKNOWN) {
6334 source = InputDevice.SOURCE_KEYBOARD;
6335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336
6337 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6338 if (downTime == 0) downTime = eventTime;
6339
6340 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006341 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006343 final int pid = Binder.getCallingPid();
6344 final int uid = Binder.getCallingUid();
6345 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006346
Jeff Brownbbda99d2010-07-28 15:48:59 -07006347 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6348 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6349 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6350 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006351
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006352 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006353 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 }
6355
6356 /**
6357 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006358 * Even when sync is false, this method may block while waiting for current
6359 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006360 *
6361 * @param ev A motion event describing the pointer (touch) action. (As noted in
6362 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006363 * {@link SystemClock#uptimeMillis()} as the timebase.)
6364 * @param sync If true, wait for the event to be completed before returning to the caller.
6365 * @return Returns true if event was dispatched, false if it was dropped for any reason
6366 */
6367 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006368 final int pid = Binder.getCallingPid();
6369 final int uid = Binder.getCallingUid();
6370 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006371
Jeff Brownc5ed5912010-07-14 18:48:53 -07006372 MotionEvent newEvent = MotionEvent.obtain(ev);
6373 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6374 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6375 }
6376
Jeff Brownbbda99d2010-07-28 15:48:59 -07006377 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6378 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6379 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6380 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006381
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006382 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006383 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006384 }
Romain Guy06882f82009-06-10 13:36:04 -07006385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 /**
6387 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006388 * Even when sync is false, this method may block while waiting for current
6389 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006390 *
6391 * @param ev A motion event describing the trackball action. (As noted in
6392 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006393 * {@link SystemClock#uptimeMillis()} as the timebase.)
6394 * @param sync If true, wait for the event to be completed before returning to the caller.
6395 * @return Returns true if event was dispatched, false if it was dropped for any reason
6396 */
6397 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006398 final int pid = Binder.getCallingPid();
6399 final int uid = Binder.getCallingUid();
6400 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006401
Jeff Brownc5ed5912010-07-14 18:48:53 -07006402 MotionEvent newEvent = MotionEvent.obtain(ev);
6403 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6404 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6405 }
6406
Jeff Brownbbda99d2010-07-28 15:48:59 -07006407 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6408 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6409 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6410 INJECTION_TIMEOUT_MILLIS);
6411
6412 Binder.restoreCallingIdentity(ident);
6413 return reportInjectionResult(result);
6414 }
6415
6416 /**
6417 * Inject an input event into the UI without waiting for dispatch to commence.
6418 * This variant is useful for fire-and-forget input event injection. It does not
6419 * block any longer than it takes to enqueue the input event.
6420 *
6421 * @param ev An input event. (Be sure to set the input source correctly.)
6422 * @return Returns true if event was dispatched, false if it was dropped for any reason
6423 */
6424 public boolean injectInputEventNoWait(InputEvent ev) {
6425 final int pid = Binder.getCallingPid();
6426 final int uid = Binder.getCallingUid();
6427 final long ident = Binder.clearCallingIdentity();
6428
6429 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6430 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6431 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006432
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006433 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006434 return reportInjectionResult(result);
6435 }
6436
6437 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006438 switch (result) {
6439 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6440 Slog.w(TAG, "Input event injection permission denied.");
6441 throw new SecurityException(
6442 "Injecting to another application requires INJECT_EVENTS permission");
6443 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006444 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006445 return true;
6446 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6447 Slog.w(TAG, "Input event injection timed out.");
6448 return false;
6449 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6450 default:
6451 Slog.w(TAG, "Input event injection failed.");
6452 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 }
Romain Guy06882f82009-06-10 13:36:04 -07006455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 private WindowState getFocusedWindow() {
6457 synchronized (mWindowMap) {
6458 return getFocusedWindowLocked();
6459 }
6460 }
6461
6462 private WindowState getFocusedWindowLocked() {
6463 return mCurrentFocus;
6464 }
Romain Guy06882f82009-06-10 13:36:04 -07006465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006467 if (!mInputMonitor.waitForInputDevicesReady(
6468 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6469 Slog.w(TAG, "Devices still not ready after waiting "
6470 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6471 + " milliseconds before attempting to detect safe mode.");
6472 }
6473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 mSafeMode = mPolicy.detectSafeMode();
6475 return mSafeMode;
6476 }
Romain Guy06882f82009-06-10 13:36:04 -07006477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006478 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006479 synchronized(mWindowMap) {
6480 if (mDisplay != null) {
6481 throw new IllegalStateException("Display already initialized");
6482 }
6483 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6484 mDisplay = wm.getDefaultDisplay();
6485 mInitialDisplayWidth = mDisplay.getWidth();
6486 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006487 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6488 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006489 }
6490
6491 try {
6492 mActivityManager.updateConfiguration(null);
6493 } catch (RemoteException e) {
6494 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006495
6496 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006497 }
6498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006499 // -------------------------------------------------------------
6500 // Client Session State
6501 // -------------------------------------------------------------
6502
6503 private final class Session extends IWindowSession.Stub
6504 implements IBinder.DeathRecipient {
6505 final IInputMethodClient mClient;
6506 final IInputContext mInputContext;
6507 final int mUid;
6508 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006509 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 SurfaceSession mSurfaceSession;
6511 int mNumWindow = 0;
6512 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006514 public Session(IInputMethodClient client, IInputContext inputContext) {
6515 mClient = client;
6516 mInputContext = inputContext;
6517 mUid = Binder.getCallingUid();
6518 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006519 StringBuilder sb = new StringBuilder();
6520 sb.append("Session{");
6521 sb.append(Integer.toHexString(System.identityHashCode(this)));
6522 sb.append(" uid ");
6523 sb.append(mUid);
6524 sb.append("}");
6525 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006527 synchronized (mWindowMap) {
6528 if (mInputMethodManager == null && mHaveInputMethods) {
6529 IBinder b = ServiceManager.getService(
6530 Context.INPUT_METHOD_SERVICE);
6531 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6532 }
6533 }
6534 long ident = Binder.clearCallingIdentity();
6535 try {
6536 // Note: it is safe to call in to the input method manager
6537 // here because we are not holding our lock.
6538 if (mInputMethodManager != null) {
6539 mInputMethodManager.addClient(client, inputContext,
6540 mUid, mPid);
6541 } else {
6542 client.setUsingInputMethod(false);
6543 }
6544 client.asBinder().linkToDeath(this, 0);
6545 } catch (RemoteException e) {
6546 // The caller has died, so we can just forget about this.
6547 try {
6548 if (mInputMethodManager != null) {
6549 mInputMethodManager.removeClient(client);
6550 }
6551 } catch (RemoteException ee) {
6552 }
6553 } finally {
6554 Binder.restoreCallingIdentity(ident);
6555 }
6556 }
Romain Guy06882f82009-06-10 13:36:04 -07006557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 @Override
6559 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6560 throws RemoteException {
6561 try {
6562 return super.onTransact(code, data, reply, flags);
6563 } catch (RuntimeException e) {
6564 // Log all 'real' exceptions thrown to the caller
6565 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006566 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 }
6568 throw e;
6569 }
6570 }
6571
6572 public void binderDied() {
6573 // Note: it is safe to call in to the input method manager
6574 // here because we are not holding our lock.
6575 try {
6576 if (mInputMethodManager != null) {
6577 mInputMethodManager.removeClient(mClient);
6578 }
6579 } catch (RemoteException e) {
6580 }
6581 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006582 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006583 mClientDead = true;
6584 killSessionLocked();
6585 }
6586 }
6587
6588 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006589 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6590 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6591 outInputChannel);
6592 }
6593
6594 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006595 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006596 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 }
Romain Guy06882f82009-06-10 13:36:04 -07006598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006599 public void remove(IWindow window) {
6600 removeWindow(this, window);
6601 }
Romain Guy06882f82009-06-10 13:36:04 -07006602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6604 int requestedWidth, int requestedHeight, int viewFlags,
6605 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006606 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006607 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6608 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006610 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006611 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6612 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 }
Romain Guy06882f82009-06-10 13:36:04 -07006614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 public void setTransparentRegion(IWindow window, Region region) {
6616 setTransparentRegionWindow(this, window, region);
6617 }
Romain Guy06882f82009-06-10 13:36:04 -07006618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006620 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006621 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006622 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006623 }
Romain Guy06882f82009-06-10 13:36:04 -07006624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006625 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6626 getWindowDisplayFrame(this, window, outDisplayFrame);
6627 }
Romain Guy06882f82009-06-10 13:36:04 -07006628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006630 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006631 TAG, "IWindow finishDrawing called for " + window);
6632 finishDrawingWindow(this, window);
6633 }
6634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 public void setInTouchMode(boolean mode) {
6636 synchronized(mWindowMap) {
6637 mInTouchMode = mode;
6638 }
6639 }
6640
6641 public boolean getInTouchMode() {
6642 synchronized(mWindowMap) {
6643 return mInTouchMode;
6644 }
6645 }
6646
6647 public boolean performHapticFeedback(IWindow window, int effectId,
6648 boolean always) {
6649 synchronized(mWindowMap) {
6650 long ident = Binder.clearCallingIdentity();
6651 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006652 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006653 windowForClientLocked(this, window, true),
6654 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 } finally {
6656 Binder.restoreCallingIdentity(ident);
6657 }
6658 }
6659 }
Romain Guy06882f82009-06-10 13:36:04 -07006660
Christopher Tatea53146c2010-09-07 11:57:52 -07006661 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006662 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006663 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006664 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006665 width, height, outSurface);
6666 }
6667
6668 public boolean performDrag(IWindow window, IBinder dragToken,
6669 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6670 ClipData data) {
6671 if (DEBUG_DRAG) {
6672 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6673 }
6674
6675 synchronized (mWindowMap) {
6676 if (mDragState == null) {
6677 Slog.w(TAG, "No drag prepared");
6678 throw new IllegalStateException("performDrag() without prepareDrag()");
6679 }
6680
6681 if (dragToken != mDragState.mToken) {
6682 Slog.w(TAG, "Performing mismatched drag");
6683 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6684 }
6685
6686 WindowState callingWin = windowForClientLocked(null, window, false);
6687 if (callingWin == null) {
6688 Slog.w(TAG, "Bad requesting window " + window);
6689 return false; // !!! TODO: throw here?
6690 }
6691
6692 // !!! TODO: if input is not still focused on the initiating window, fail
6693 // the drag initiation (e.g. an alarm window popped up just as the application
6694 // called performDrag()
6695
6696 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6697
Christopher Tate2c095f32010-10-04 14:13:40 -07006698 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6699 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006700
Chris Tateb478f462010-10-15 16:02:26 -07006701 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6702 // the actual drag event dispatch stuff in the dragstate
6703
Christopher Tatea53146c2010-09-07 11:57:52 -07006704 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006705 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006706 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6707 mDragState.mServerChannel)) {
6708 Slog.e(TAG, "Unable to transfer touch focus");
6709 mDragState.unregister();
6710 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006711 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006712 return false;
6713 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006714
6715 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006716 mDragState.mCurrentX = touchX;
6717 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006718 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006719
6720 // remember the thumb offsets for later
6721 mDragState.mThumbOffsetX = thumbCenterX;
6722 mDragState.mThumbOffsetY = thumbCenterY;
6723
6724 // Make the surface visible at the proper location
6725 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006726 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006727 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006728 try {
6729 surface.setPosition((int)(touchX - thumbCenterX),
6730 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006731 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006732 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006733 surface.show();
6734 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006735 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006736 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006737 }
6738 }
6739
6740 return true; // success!
6741 }
6742
Chris Tated4533f142010-10-19 15:15:08 -07006743 public void reportDropResult(IWindow window, boolean consumed) {
6744 IBinder token = window.asBinder();
6745 if (DEBUG_DRAG) {
6746 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6747 }
6748
6749 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006750 long ident = Binder.clearCallingIdentity();
6751 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006752 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006753 Slog.w(TAG, "Invalid drop-result claim by " + window);
6754 throw new IllegalStateException("reportDropResult() by non-recipient");
6755 }
6756
6757 // The right window has responded, even if it's no longer around,
6758 // so be sure to halt the timeout even if the later WindowState
6759 // lookup fails.
6760 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6761 WindowState callingWin = windowForClientLocked(null, window, false);
6762 if (callingWin == null) {
6763 Slog.w(TAG, "Bad result-reporting window " + window);
6764 return; // !!! TODO: throw here?
6765 }
6766
6767 mDragState.mDragResult = consumed;
6768 mDragState.endDragLw();
6769 } finally {
6770 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006771 }
Chris Tated4533f142010-10-19 15:15:08 -07006772 }
6773 }
6774
Christopher Tatea53146c2010-09-07 11:57:52 -07006775 public void dragRecipientEntered(IWindow window) {
6776 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006777 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006778 }
6779 }
6780
6781 public void dragRecipientExited(IWindow window) {
6782 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006783 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006784 }
6785 }
6786
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006787 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006788 synchronized(mWindowMap) {
6789 long ident = Binder.clearCallingIdentity();
6790 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006791 setWindowWallpaperPositionLocked(
6792 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006793 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006794 } finally {
6795 Binder.restoreCallingIdentity(ident);
6796 }
6797 }
6798 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006799
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006800 public void wallpaperOffsetsComplete(IBinder window) {
6801 WindowManagerService.this.wallpaperOffsetsComplete(window);
6802 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006803
Dianne Hackborn75804932009-10-20 20:15:20 -07006804 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6805 int z, Bundle extras, boolean sync) {
6806 synchronized(mWindowMap) {
6807 long ident = Binder.clearCallingIdentity();
6808 try {
6809 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006810 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006811 action, x, y, z, extras, sync);
6812 } finally {
6813 Binder.restoreCallingIdentity(ident);
6814 }
6815 }
6816 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006817
Dianne Hackborn75804932009-10-20 20:15:20 -07006818 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6819 WindowManagerService.this.wallpaperCommandComplete(window, result);
6820 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006822 void windowAddedLocked() {
6823 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006824 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 TAG, "First window added to " + this + ", creating SurfaceSession");
6826 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006827 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006828 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006829 mSessions.add(this);
6830 }
6831 mNumWindow++;
6832 }
6833
6834 void windowRemovedLocked() {
6835 mNumWindow--;
6836 killSessionLocked();
6837 }
Romain Guy06882f82009-06-10 13:36:04 -07006838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006839 void killSessionLocked() {
6840 if (mNumWindow <= 0 && mClientDead) {
6841 mSessions.remove(this);
6842 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006843 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006844 TAG, "Last window removed from " + this
6845 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006846 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006847 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006848 try {
6849 mSurfaceSession.kill();
6850 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006851 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 + mSurfaceSession + " in session " + this
6853 + ": " + e.toString());
6854 }
6855 mSurfaceSession = null;
6856 }
6857 }
6858 }
Romain Guy06882f82009-06-10 13:36:04 -07006859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006861 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6862 pw.print(" mClientDead="); pw.print(mClientDead);
6863 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 }
6865
6866 @Override
6867 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006868 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 }
6870 }
6871
6872 // -------------------------------------------------------------
6873 // Client Window State
6874 // -------------------------------------------------------------
6875
6876 private final class WindowState implements WindowManagerPolicy.WindowState {
6877 final Session mSession;
6878 final IWindow mClient;
6879 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006880 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006881 AppWindowToken mAppToken;
6882 AppWindowToken mTargetAppToken;
6883 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6884 final DeathRecipient mDeathRecipient;
6885 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006886 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 final int mBaseLayer;
6888 final int mSubLayer;
6889 final boolean mLayoutAttached;
6890 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006891 final boolean mIsWallpaper;
6892 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 int mViewVisibility;
6894 boolean mPolicyVisibility = true;
6895 boolean mPolicyVisibilityAfterAnim = true;
6896 boolean mAppFreezing;
6897 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006898 boolean mReportDestroySurface;
6899 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006900 boolean mAttachedHidden; // is our parent window hidden?
6901 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006902 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 int mRequestedWidth;
6904 int mRequestedHeight;
6905 int mLastRequestedWidth;
6906 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006907 int mLayer;
6908 int mAnimLayer;
6909 int mLastLayer;
6910 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006911 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006912 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006913
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006914 int mLayoutSeq = -1;
6915
6916 Configuration mConfiguration = null;
6917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006918 // Actual frame shown on-screen (may be modified by animation)
6919 final Rect mShownFrame = new Rect();
6920 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006923 * Set when we have changed the size of the surface, to know that
6924 * we must tell them application to resize (and thus redraw itself).
6925 */
6926 boolean mSurfaceResized;
6927
6928 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006929 * Insets that determine the actually visible area
6930 */
6931 final Rect mVisibleInsets = new Rect();
6932 final Rect mLastVisibleInsets = new Rect();
6933 boolean mVisibleInsetsChanged;
6934
6935 /**
6936 * Insets that are covered by system windows
6937 */
6938 final Rect mContentInsets = new Rect();
6939 final Rect mLastContentInsets = new Rect();
6940 boolean mContentInsetsChanged;
6941
6942 /**
6943 * Set to true if we are waiting for this window to receive its
6944 * given internal insets before laying out other windows based on it.
6945 */
6946 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 /**
6949 * These are the content insets that were given during layout for
6950 * this window, to be applied to windows behind it.
6951 */
6952 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006954 /**
6955 * These are the visible insets that were given during layout for
6956 * this window, to be applied to windows behind it.
6957 */
6958 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006960 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006961 * This is the given touchable area relative to the window frame, or null if none.
6962 */
6963 final Region mGivenTouchableRegion = new Region();
6964
6965 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006966 * Flag indicating whether the touchable region should be adjusted by
6967 * the visible insets; if false the area outside the visible insets is
6968 * NOT touchable, so we must use those to adjust the frame during hit
6969 * tests.
6970 */
6971 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006973 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006974 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6976 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6977 float mHScale=1, mVScale=1;
6978 float mLastHScale=1, mLastVScale=1;
6979 final Matrix mTmpMatrix = new Matrix();
6980
6981 // "Real" frame that the application sees.
6982 final Rect mFrame = new Rect();
6983 final Rect mLastFrame = new Rect();
6984
6985 final Rect mContainingFrame = new Rect();
6986 final Rect mDisplayFrame = new Rect();
6987 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006988 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006989 final Rect mVisibleFrame = new Rect();
6990
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006991 boolean mContentChanged;
6992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006993 float mShownAlpha = 1;
6994 float mAlpha = 1;
6995 float mLastAlpha = 1;
6996
6997 // Set to true if, when the window gets displayed, it should perform
6998 // an enter animation.
6999 boolean mEnterAnimationPending;
7000
7001 // Currently running animation.
7002 boolean mAnimating;
7003 boolean mLocalAnimating;
7004 Animation mAnimation;
7005 boolean mAnimationIsEntrance;
7006 boolean mHasTransformation;
7007 boolean mHasLocalTransformation;
7008 final Transformation mTransformation = new Transformation();
7009
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007010 // If a window showing a wallpaper: the requested offset for the
7011 // wallpaper; if a wallpaper window: the currently applied offset.
7012 float mWallpaperX = -1;
7013 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007014
7015 // If a window showing a wallpaper: what fraction of the offset
7016 // range corresponds to a full virtual screen.
7017 float mWallpaperXStep = -1;
7018 float mWallpaperYStep = -1;
7019
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007020 // Wallpaper windows: pixels offset based on above variables.
7021 int mXOffset;
7022 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007024 // This is set after IWindowSession.relayout() has been called at
7025 // least once for the window. It allows us to detect the situation
7026 // where we don't yet have a surface, but should have one soon, so
7027 // we can give the window focus before waiting for the relayout.
7028 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 // This is set after the Surface has been created but before the
7031 // window has been drawn. During this time the surface is hidden.
7032 boolean mDrawPending;
7033
7034 // This is set after the window has finished drawing for the first
7035 // time but before its surface is shown. The surface will be
7036 // displayed when the next layout is run.
7037 boolean mCommitDrawPending;
7038
7039 // This is set during the time after the window's drawing has been
7040 // committed, and before its surface is actually shown. It is used
7041 // to delay showing the surface until all windows in a token are ready
7042 // to be shown.
7043 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 // Set when the window has been shown in the screen the first time.
7046 boolean mHasDrawn;
7047
7048 // Currently running an exit animation?
7049 boolean mExiting;
7050
7051 // Currently on the mDestroySurface list?
7052 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 // Completely remove from window manager after exit animation?
7055 boolean mRemoveOnExit;
7056
7057 // Set when the orientation is changing and this window has not yet
7058 // been updated for the new orientation.
7059 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 // Is this window now (or just being) removed?
7062 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007063
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007064 // Temp for keeping track of windows that have been removed when
7065 // rebuilding window list.
7066 boolean mRebuilding;
7067
Dianne Hackborn16064f92010-03-25 00:47:24 -07007068 // For debugging, this is the last information given to the surface flinger.
7069 boolean mSurfaceShown;
7070 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7071 int mSurfaceLayer;
7072 float mSurfaceAlpha;
7073
Jeff Brown928e0542011-01-10 11:17:36 -08007074 // Input channel and input window handle used by the input dispatcher.
7075 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007076 InputChannel mInputChannel;
7077
Mattias Petersson1622eee2010-12-21 10:15:11 +01007078 // Used to improve performance of toString()
7079 String mStringNameCache;
7080 CharSequence mLastTitle;
7081 boolean mWasPaused;
7082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 WindowState(Session s, IWindow c, WindowToken token,
7084 WindowState attachedWindow, WindowManager.LayoutParams a,
7085 int viewVisibility) {
7086 mSession = s;
7087 mClient = c;
7088 mToken = token;
7089 mAttrs.copyFrom(a);
7090 mViewVisibility = viewVisibility;
7091 DeathRecipient deathRecipient = new DeathRecipient();
7092 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007093 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 TAG, "Window " + this + " client=" + c.asBinder()
7095 + " token=" + token + " (" + mAttrs.token + ")");
7096 try {
7097 c.asBinder().linkToDeath(deathRecipient, 0);
7098 } catch (RemoteException e) {
7099 mDeathRecipient = null;
7100 mAttachedWindow = null;
7101 mLayoutAttached = false;
7102 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007103 mIsWallpaper = false;
7104 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007105 mBaseLayer = 0;
7106 mSubLayer = 0;
7107 return;
7108 }
7109 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7112 mAttrs.type <= LAST_SUB_WINDOW)) {
7113 // The multiplier here is to reserve space for multiple
7114 // windows in the same type layer.
7115 mBaseLayer = mPolicy.windowTypeToLayerLw(
7116 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7117 + TYPE_LAYER_OFFSET;
7118 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7119 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007120 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007121 mAttachedWindow.mChildWindows.add(this);
7122 mLayoutAttached = mAttrs.type !=
7123 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7124 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7125 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007126 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7127 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007128 } else {
7129 // The multiplier here is to reserve space for multiple
7130 // windows in the same type layer.
7131 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7132 * TYPE_LAYER_MULTIPLIER
7133 + TYPE_LAYER_OFFSET;
7134 mSubLayer = 0;
7135 mAttachedWindow = null;
7136 mLayoutAttached = false;
7137 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7138 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007139 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7140 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007141 }
7142
7143 WindowState appWin = this;
7144 while (appWin.mAttachedWindow != null) {
7145 appWin = mAttachedWindow;
7146 }
7147 WindowToken appToken = appWin.mToken;
7148 while (appToken.appWindowToken == null) {
7149 WindowToken parent = mTokenMap.get(appToken.token);
7150 if (parent == null || appToken == parent) {
7151 break;
7152 }
7153 appToken = parent;
7154 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007155 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007156 mAppToken = appToken.appWindowToken;
7157
7158 mSurface = null;
7159 mRequestedWidth = 0;
7160 mRequestedHeight = 0;
7161 mLastRequestedWidth = 0;
7162 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007163 mXOffset = 0;
7164 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 mLayer = 0;
7166 mAnimLayer = 0;
7167 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007168 mInputWindowHandle = new InputWindowHandle(
7169 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007170 }
7171
7172 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007173 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007174 TAG, "Attaching " + this + " token=" + mToken
7175 + ", list=" + mToken.windows);
7176 mSession.windowAddedLocked();
7177 }
7178
7179 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7180 mHaveFrame = true;
7181
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007182 final Rect container = mContainingFrame;
7183 container.set(pf);
7184
7185 final Rect display = mDisplayFrame;
7186 display.set(df);
7187
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007188 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007189 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007190 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7191 display.intersect(mCompatibleScreenFrame);
7192 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007193 }
7194
7195 final int pw = container.right - container.left;
7196 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007197
7198 int w,h;
7199 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7200 w = mAttrs.width < 0 ? pw : mAttrs.width;
7201 h = mAttrs.height< 0 ? ph : mAttrs.height;
7202 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007203 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7204 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 }
Romain Guy06882f82009-06-10 13:36:04 -07007206
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007207 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007208 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7209 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007210 mParentFrame.set(pf);
7211 mContentChanged = true;
7212 }
7213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007214 final Rect content = mContentFrame;
7215 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007217 final Rect visible = mVisibleFrame;
7218 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007220 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007221 final int fw = frame.width();
7222 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007224 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7225 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7226
7227 Gravity.apply(mAttrs.gravity, w, h, container,
7228 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7229 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7230
7231 //System.out.println("Out: " + mFrame);
7232
7233 // Now make sure the window fits in the overall display.
7234 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007236 // Make sure the content and visible frames are inside of the
7237 // final window frame.
7238 if (content.left < frame.left) content.left = frame.left;
7239 if (content.top < frame.top) content.top = frame.top;
7240 if (content.right > frame.right) content.right = frame.right;
7241 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7242 if (visible.left < frame.left) visible.left = frame.left;
7243 if (visible.top < frame.top) visible.top = frame.top;
7244 if (visible.right > frame.right) visible.right = frame.right;
7245 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007247 final Rect contentInsets = mContentInsets;
7248 contentInsets.left = content.left-frame.left;
7249 contentInsets.top = content.top-frame.top;
7250 contentInsets.right = frame.right-content.right;
7251 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007253 final Rect visibleInsets = mVisibleInsets;
7254 visibleInsets.left = visible.left-frame.left;
7255 visibleInsets.top = visible.top-frame.top;
7256 visibleInsets.right = frame.right-visible.right;
7257 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007258
Dianne Hackborn284ac932009-08-28 10:34:25 -07007259 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7260 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007261 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007262 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007264 if (localLOGV) {
7265 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7266 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007267 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 + mRequestedWidth + ", mRequestedheight="
7269 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7270 + "): frame=" + mFrame.toShortString()
7271 + " ci=" + contentInsets.toShortString()
7272 + " vi=" + visibleInsets.toShortString());
7273 //}
7274 }
7275 }
Romain Guy06882f82009-06-10 13:36:04 -07007276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007277 public Rect getFrameLw() {
7278 return mFrame;
7279 }
7280
7281 public Rect getShownFrameLw() {
7282 return mShownFrame;
7283 }
7284
7285 public Rect getDisplayFrameLw() {
7286 return mDisplayFrame;
7287 }
7288
7289 public Rect getContentFrameLw() {
7290 return mContentFrame;
7291 }
7292
7293 public Rect getVisibleFrameLw() {
7294 return mVisibleFrame;
7295 }
7296
7297 public boolean getGivenInsetsPendingLw() {
7298 return mGivenInsetsPending;
7299 }
7300
7301 public Rect getGivenContentInsetsLw() {
7302 return mGivenContentInsets;
7303 }
Romain Guy06882f82009-06-10 13:36:04 -07007304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 public Rect getGivenVisibleInsetsLw() {
7306 return mGivenVisibleInsets;
7307 }
Romain Guy06882f82009-06-10 13:36:04 -07007308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007309 public WindowManager.LayoutParams getAttrs() {
7310 return mAttrs;
7311 }
7312
7313 public int getSurfaceLayer() {
7314 return mLayer;
7315 }
Romain Guy06882f82009-06-10 13:36:04 -07007316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 public IApplicationToken getAppToken() {
7318 return mAppToken != null ? mAppToken.appToken : null;
7319 }
Jeff Brown349703e2010-06-22 01:27:15 -07007320
7321 public long getInputDispatchingTimeoutNanos() {
7322 return mAppToken != null
7323 ? mAppToken.inputDispatchingTimeoutNanos
7324 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007326
7327 public boolean hasAppShownWindows() {
7328 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7329 }
7330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007332 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007333 TAG, "Setting animation in " + this + ": " + anim);
7334 mAnimating = false;
7335 mLocalAnimating = false;
7336 mAnimation = anim;
7337 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7338 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7339 }
7340
7341 public void clearAnimation() {
7342 if (mAnimation != null) {
7343 mAnimating = true;
7344 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007345 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 mAnimation = null;
7347 }
7348 }
Romain Guy06882f82009-06-10 13:36:04 -07007349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 Surface createSurfaceLocked() {
7351 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007352 mReportDestroySurface = false;
7353 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 mDrawPending = true;
7355 mCommitDrawPending = false;
7356 mReadyToShow = false;
7357 if (mAppToken != null) {
7358 mAppToken.allDrawn = false;
7359 }
7360
7361 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362
7363 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7364 flags |= Surface.SECURE;
7365 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007366 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007367 TAG, "Creating surface in session "
7368 + mSession.mSurfaceSession + " window " + this
7369 + " w=" + mFrame.width()
7370 + " h=" + mFrame.height() + " format="
7371 + mAttrs.format + " flags=" + flags);
7372
7373 int w = mFrame.width();
7374 int h = mFrame.height();
7375 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7376 // for a scaled surface, we always want the requested
7377 // size.
7378 w = mRequestedWidth;
7379 h = mRequestedHeight;
7380 }
7381
Romain Guy9825ec62009-10-01 00:58:09 -07007382 // Something is wrong and SurfaceFlinger will not like this,
7383 // try to revert to sane values
7384 if (w <= 0) w = 1;
7385 if (h <= 0) h = 1;
7386
Dianne Hackborn16064f92010-03-25 00:47:24 -07007387 mSurfaceShown = false;
7388 mSurfaceLayer = 0;
7389 mSurfaceAlpha = 1;
7390 mSurfaceX = 0;
7391 mSurfaceY = 0;
7392 mSurfaceW = w;
7393 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007394 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007395 final boolean isHwAccelerated = (mAttrs.flags &
7396 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7397 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7398 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7399 flags |= Surface.OPAQUE;
7400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007402 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007403 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007404 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007405 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007406 + mSurface + " IN SESSION "
7407 + mSession.mSurfaceSession
7408 + ": pid=" + mSession.mPid + " format="
7409 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007410 + Integer.toHexString(flags)
7411 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007413 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007414 reclaimSomeSurfaceMemoryLocked(this, "create");
7415 return null;
7416 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007417 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 return null;
7419 }
Romain Guy06882f82009-06-10 13:36:04 -07007420
Joe Onorato8a9b2202010-02-26 18:56:32 -08007421 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 TAG, "Got surface: " + mSurface
7423 + ", set left=" + mFrame.left + " top=" + mFrame.top
7424 + ", animLayer=" + mAnimLayer);
7425 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007426 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7427 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007428 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7429 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 }
7431 Surface.openTransaction();
7432 try {
7433 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007434 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007435 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007436 mSurface.setPosition(mSurfaceX, mSurfaceY);
7437 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007439 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 mSurface.hide();
7441 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007442 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 mSurface.setFlags(Surface.SURFACE_DITHER,
7444 Surface.SURFACE_DITHER);
7445 }
7446 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007447 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7449 }
7450 mLastHidden = true;
7451 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007453 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007455 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 TAG, "Created surface " + this);
7457 }
7458 return mSurface;
7459 }
Romain Guy06882f82009-06-10 13:36:04 -07007460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007462 if (mAppToken != null && this == mAppToken.startingWindow) {
7463 mAppToken.startingDisplayed = false;
7464 }
Romain Guy06882f82009-06-10 13:36:04 -07007465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007466 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007467 mDrawPending = false;
7468 mCommitDrawPending = false;
7469 mReadyToShow = false;
7470
7471 int i = mChildWindows.size();
7472 while (i > 0) {
7473 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007474 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007475 c.mAttachedHidden = true;
7476 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007477
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007478 if (mReportDestroySurface) {
7479 mReportDestroySurface = false;
7480 mSurfacePendingDestroy = true;
7481 try {
7482 mClient.dispatchGetNewSurface();
7483 // We'll really destroy on the next time around.
7484 return;
7485 } catch (RemoteException e) {
7486 }
7487 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007489 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007490 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007491 RuntimeException e = null;
7492 if (!HIDE_STACK_CRAWLS) {
7493 e = new RuntimeException();
7494 e.fillInStackTrace();
7495 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007496 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007497 + mSurface + ", session " + mSession, e);
7498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007500 RuntimeException e = null;
7501 if (!HIDE_STACK_CRAWLS) {
7502 e = new RuntimeException();
7503 e.fillInStackTrace();
7504 }
7505 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007506 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007507 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007508 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007509 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 + " surface " + mSurface + " session " + mSession
7511 + ": " + e.toString());
7512 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007513
Dianne Hackborn16064f92010-03-25 00:47:24 -07007514 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007515 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 }
7517 }
7518
7519 boolean finishDrawingLocked() {
7520 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007521 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 TAG, "finishDrawingLocked: " + mSurface);
7523 mCommitDrawPending = true;
7524 mDrawPending = false;
7525 return true;
7526 }
7527 return false;
7528 }
7529
7530 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007531 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007532 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007533 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007534 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007535 }
7536 mCommitDrawPending = false;
7537 mReadyToShow = true;
7538 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7539 final AppWindowToken atoken = mAppToken;
7540 if (atoken == null || atoken.allDrawn || starting) {
7541 performShowLocked();
7542 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007543 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007544 }
7545
7546 // This must be called while inside a transaction.
7547 boolean performShowLocked() {
7548 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007549 RuntimeException e = null;
7550 if (!HIDE_STACK_CRAWLS) {
7551 e = new RuntimeException();
7552 e.fillInStackTrace();
7553 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007554 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007555 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7556 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7557 }
7558 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007559 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7560 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007561 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 + " during animation: policyVis=" + mPolicyVisibility
7563 + " attHidden=" + mAttachedHidden
7564 + " tok.hiddenRequested="
7565 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007566 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007567 + (mAppToken != null ? mAppToken.hidden : false)
7568 + " animating=" + mAnimating
7569 + " tok animating="
7570 + (mAppToken != null ? mAppToken.animating : false));
7571 if (!showSurfaceRobustlyLocked(this)) {
7572 return false;
7573 }
7574 mLastAlpha = -1;
7575 mHasDrawn = true;
7576 mLastHidden = false;
7577 mReadyToShow = false;
7578 enableScreenIfNeededLocked();
7579
7580 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 int i = mChildWindows.size();
7583 while (i > 0) {
7584 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007585 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007586 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007588 if (c.mSurface != null) {
7589 c.performShowLocked();
7590 // It hadn't been shown, which means layout not
7591 // performed on it, so now we want to make sure to
7592 // do a layout. If called from within the transaction
7593 // loop, this will cause it to restart with a new
7594 // layout.
7595 mLayoutNeeded = true;
7596 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 }
7598 }
Romain Guy06882f82009-06-10 13:36:04 -07007599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007600 if (mAttrs.type != TYPE_APPLICATION_STARTING
7601 && mAppToken != null) {
7602 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007603
Dianne Hackborn248b1882009-09-16 16:46:44 -07007604 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007605 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007606 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007608 // If this initial window is animating, stop it -- we
7609 // will do an animation to reveal it from behind the
7610 // starting window, so there is no need for it to also
7611 // be doing its own stuff.
7612 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007613 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007614 mAnimation = null;
7615 // Make sure we clean up the animation.
7616 mAnimating = true;
7617 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 mFinishedStarting.add(mAppToken);
7619 mH.sendEmptyMessage(H.FINISHED_STARTING);
7620 }
7621 mAppToken.updateReportedVisibilityLocked();
7622 }
7623 }
7624 return true;
7625 }
Romain Guy06882f82009-06-10 13:36:04 -07007626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 // This must be called while inside a transaction. Returns true if
7628 // there is more animation to run.
7629 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007630 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007631 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007633 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7634 mHasTransformation = true;
7635 mHasLocalTransformation = true;
7636 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007637 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 TAG, "Starting animation in " + this +
7639 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7640 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7641 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7642 mAnimation.setStartTime(currentTime);
7643 mLocalAnimating = true;
7644 mAnimating = true;
7645 }
7646 mTransformation.clear();
7647 final boolean more = mAnimation.getTransformation(
7648 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007649 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007650 TAG, "Stepped animation in " + this +
7651 ": more=" + more + ", xform=" + mTransformation);
7652 if (more) {
7653 // we're not done!
7654 return true;
7655 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007656 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007657 TAG, "Finished animation in " + this +
7658 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007659
7660 if (mAnimation != null) {
7661 mAnimation.cancel();
7662 mAnimation = null;
7663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007664 //WindowManagerService.this.dump();
7665 }
7666 mHasLocalTransformation = false;
7667 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007668 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007669 // When our app token is animating, we kind-of pretend like
7670 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7671 // part of this check means that we will only do this if
7672 // our window is not currently exiting, or it is not
7673 // locally animating itself. The idea being that one that
7674 // is exiting and doing a local animation should be removed
7675 // once that animation is done.
7676 mAnimating = true;
7677 mHasTransformation = true;
7678 mTransformation.clear();
7679 return false;
7680 } else if (mHasTransformation) {
7681 // Little trick to get through the path below to act like
7682 // we have finished an animation.
7683 mAnimating = true;
7684 } else if (isAnimating()) {
7685 mAnimating = true;
7686 }
7687 } else if (mAnimation != null) {
7688 // If the display is frozen, and there is a pending animation,
7689 // clear it and make sure we run the cleanup code.
7690 mAnimating = true;
7691 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007692 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007693 mAnimation = null;
7694 }
Romain Guy06882f82009-06-10 13:36:04 -07007695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 if (!mAnimating && !mLocalAnimating) {
7697 return false;
7698 }
7699
Joe Onorato8a9b2202010-02-26 18:56:32 -08007700 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007701 TAG, "Animation done in " + this + ": exiting=" + mExiting
7702 + ", reportedVisible="
7703 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007705 mAnimating = false;
7706 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007707 if (mAnimation != null) {
7708 mAnimation.cancel();
7709 mAnimation = null;
7710 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007711 mAnimLayer = mLayer;
7712 if (mIsImWindow) {
7713 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007714 } else if (mIsWallpaper) {
7715 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007716 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007717 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007718 + " anim layer: " + mAnimLayer);
7719 mHasTransformation = false;
7720 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007721 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7722 if (DEBUG_VISIBILITY) {
7723 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7724 + mPolicyVisibilityAfterAnim);
7725 }
7726 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7727 if (!mPolicyVisibility) {
7728 if (mCurrentFocus == this) {
7729 mFocusMayChange = true;
7730 }
7731 // Window is no longer visible -- make sure if we were waiting
7732 // for it to be displayed before enabling the display, that
7733 // we allow the display to be enabled now.
7734 enableScreenIfNeededLocked();
7735 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007736 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 mTransformation.clear();
7738 if (mHasDrawn
7739 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7740 && mAppToken != null
7741 && mAppToken.firstWindowDrawn
7742 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007743 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007744 + mToken + ": first real window done animating");
7745 mFinishedStarting.add(mAppToken);
7746 mH.sendEmptyMessage(H.FINISHED_STARTING);
7747 }
Romain Guy06882f82009-06-10 13:36:04 -07007748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007749 finishExit();
7750
7751 if (mAppToken != null) {
7752 mAppToken.updateReportedVisibilityLocked();
7753 }
7754
7755 return false;
7756 }
7757
7758 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007759 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007760 TAG, "finishExit in " + this
7761 + ": exiting=" + mExiting
7762 + " remove=" + mRemoveOnExit
7763 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 final int N = mChildWindows.size();
7766 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007767 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007768 }
Romain Guy06882f82009-06-10 13:36:04 -07007769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 if (!mExiting) {
7771 return;
7772 }
Romain Guy06882f82009-06-10 13:36:04 -07007773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 if (isWindowAnimating()) {
7775 return;
7776 }
7777
Joe Onorato8a9b2202010-02-26 18:56:32 -08007778 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007779 TAG, "Exit animation finished in " + this
7780 + ": remove=" + mRemoveOnExit);
7781 if (mSurface != null) {
7782 mDestroySurface.add(this);
7783 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007784 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007785 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007786 try {
7787 mSurface.hide();
7788 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007789 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 }
7791 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007792 }
7793 mExiting = false;
7794 if (mRemoveOnExit) {
7795 mPendingRemove.add(this);
7796 mRemoveOnExit = false;
7797 }
7798 }
Romain Guy06882f82009-06-10 13:36:04 -07007799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007800 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7801 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7802 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7803 if (dtdx < -.000001f || dtdx > .000001f) return false;
7804 if (dsdy < -.000001f || dsdy > .000001f) return false;
7805 return true;
7806 }
Romain Guy06882f82009-06-10 13:36:04 -07007807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007808 void computeShownFrameLocked() {
7809 final boolean selfTransformation = mHasLocalTransformation;
7810 Transformation attachedTransformation =
7811 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7812 ? mAttachedWindow.mTransformation : null;
7813 Transformation appTransformation =
7814 (mAppToken != null && mAppToken.hasTransformation)
7815 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007816
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007817 // Wallpapers are animated based on the "real" window they
7818 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007819 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007820 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007821 if (mWallpaperTarget.mHasLocalTransformation &&
7822 mWallpaperTarget.mAnimation != null &&
7823 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007824 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007825 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007826 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007827 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007828 }
7829 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007830 mWallpaperTarget.mAppToken.hasTransformation &&
7831 mWallpaperTarget.mAppToken.animation != null &&
7832 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007833 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007834 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007835 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007836 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007837 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007838 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007839
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007840 final boolean screenAnimation = mScreenRotationAnimation != null
7841 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007843 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007844 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 final Rect frame = mFrame;
7846 final float tmpFloats[] = mTmpFloats;
7847 final Matrix tmpMatrix = mTmpMatrix;
7848
7849 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007850 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007851 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007852 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007853 }
Dianne Hackborn50660e22011-02-02 17:12:25 -08007854 tmpMatrix.postTranslate(frame.left + mXOffset, frame.top + mYOffset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007856 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007857 }
7858 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007859 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007860 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007861 if (screenAnimation) {
7862 tmpMatrix.postConcat(
7863 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7864 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007865
7866 // "convert" it into SurfaceFlinger's format
7867 // (a 2x2 matrix + an offset)
7868 // Here we must not transform the position of the surface
7869 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007870 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007871
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007872 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007873 tmpMatrix.getValues(tmpFloats);
7874 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007875 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7876 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007877 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackborn50660e22011-02-02 17:12:25 -08007878 int x = (int)tmpFloats[Matrix.MTRANS_X];
7879 int y = (int)tmpFloats[Matrix.MTRANS_Y];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 int w = frame.width();
7881 int h = frame.height();
7882 mShownFrame.set(x, y, x+w, y+h);
7883
7884 // Now set the alpha... but because our current hardware
7885 // can't do alpha transformation on a non-opaque surface,
7886 // turn it off if we are running an animation that is also
7887 // transforming since it is more important to have that
7888 // animation be smooth.
7889 mShownAlpha = mAlpha;
7890 if (!mLimitedAlphaCompositing
7891 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7892 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7893 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007894 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 if (selfTransformation) {
7896 mShownAlpha *= mTransformation.getAlpha();
7897 }
7898 if (attachedTransformation != null) {
7899 mShownAlpha *= attachedTransformation.getAlpha();
7900 }
7901 if (appTransformation != null) {
7902 mShownAlpha *= appTransformation.getAlpha();
7903 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007904 if (screenAnimation) {
7905 mShownAlpha *=
7906 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007909 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007910 }
Romain Guy06882f82009-06-10 13:36:04 -07007911
Joe Onorato8a9b2202010-02-26 18:56:32 -08007912 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 TAG, "Continuing animation in " + this +
7914 ": " + mShownFrame +
7915 ", alpha=" + mTransformation.getAlpha());
7916 return;
7917 }
Romain Guy06882f82009-06-10 13:36:04 -07007918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007920 if (mXOffset != 0 || mYOffset != 0) {
7921 mShownFrame.offset(mXOffset, mYOffset);
7922 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007923 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007924 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 mDsDx = 1;
7926 mDtDx = 0;
7927 mDsDy = 0;
7928 mDtDy = 1;
7929 }
Romain Guy06882f82009-06-10 13:36:04 -07007930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007931 /**
7932 * Is this window visible? It is not visible if there is no
7933 * surface, or we are in the process of running an exit animation
7934 * that will remove the surface, or its app token has been hidden.
7935 */
7936 public boolean isVisibleLw() {
7937 final AppWindowToken atoken = mAppToken;
7938 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7939 && (atoken == null || !atoken.hiddenRequested)
7940 && !mExiting && !mDestroying;
7941 }
7942
7943 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007944 * Like {@link #isVisibleLw}, but also counts a window that is currently
7945 * "hidden" behind the keyguard as visible. This allows us to apply
7946 * things like window flags that impact the keyguard.
7947 * XXX I am starting to think we need to have ANOTHER visibility flag
7948 * for this "hidden behind keyguard" state rather than overloading
7949 * mPolicyVisibility. Ungh.
7950 */
7951 public boolean isVisibleOrBehindKeyguardLw() {
7952 final AppWindowToken atoken = mAppToken;
7953 return mSurface != null && !mAttachedHidden
7954 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007955 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007956 && !mExiting && !mDestroying;
7957 }
7958
7959 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007960 * Is this window visible, ignoring its app token? It is not visible
7961 * if there is no surface, or we are in the process of running an exit animation
7962 * that will remove the surface.
7963 */
7964 public boolean isWinVisibleLw() {
7965 final AppWindowToken atoken = mAppToken;
7966 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7967 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7968 && !mExiting && !mDestroying;
7969 }
7970
7971 /**
7972 * The same as isVisible(), but follows the current hidden state of
7973 * the associated app token, not the pending requested hidden state.
7974 */
7975 boolean isVisibleNow() {
7976 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007977 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007978 }
7979
7980 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007981 * Can this window possibly be a drag/drop target? The test here is
7982 * a combination of the above "visible now" with the check that the
7983 * Input Manager uses when discarding windows from input consideration.
7984 */
7985 boolean isPotentialDragTarget() {
7986 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7987 }
7988
7989 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007990 * Same as isVisible(), but we also count it as visible between the
7991 * call to IWindowSession.add() and the first relayout().
7992 */
7993 boolean isVisibleOrAdding() {
7994 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007995 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007996 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7997 && mPolicyVisibility && !mAttachedHidden
7998 && (atoken == null || !atoken.hiddenRequested)
7999 && !mExiting && !mDestroying;
8000 }
8001
8002 /**
8003 * Is this window currently on-screen? It is on-screen either if it
8004 * is visible or it is currently running an animation before no longer
8005 * being visible.
8006 */
8007 boolean isOnScreen() {
8008 final AppWindowToken atoken = mAppToken;
8009 if (atoken != null) {
8010 return mSurface != null && mPolicyVisibility && !mDestroying
8011 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008012 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008013 } else {
8014 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008015 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 }
8017 }
Romain Guy06882f82009-06-10 13:36:04 -07008018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008019 /**
8020 * Like isOnScreen(), but we don't return true if the window is part
8021 * of a transition that has not yet been started.
8022 */
8023 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008024 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008025 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008026 return false;
8027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008028 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008029 final boolean animating = atoken != null
8030 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008031 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008032 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8033 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008034 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 }
8036
8037 /** Is the window or its container currently animating? */
8038 boolean isAnimating() {
8039 final WindowState attached = mAttachedWindow;
8040 final AppWindowToken atoken = mAppToken;
8041 return mAnimation != null
8042 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008043 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008044 (atoken.animation != null
8045 || atoken.inPendingTransaction));
8046 }
8047
8048 /** Is this window currently animating? */
8049 boolean isWindowAnimating() {
8050 return mAnimation != null;
8051 }
8052
8053 /**
8054 * Like isOnScreen, but returns false if the surface hasn't yet
8055 * been drawn.
8056 */
8057 public boolean isDisplayedLw() {
8058 final AppWindowToken atoken = mAppToken;
8059 return mSurface != null && mPolicyVisibility && !mDestroying
8060 && !mDrawPending && !mCommitDrawPending
8061 && ((!mAttachedHidden &&
8062 (atoken == null || !atoken.hiddenRequested))
8063 || mAnimating);
8064 }
8065
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008066 /**
8067 * Returns true if the window has a surface that it has drawn a
8068 * complete UI in to.
8069 */
8070 public boolean isDrawnLw() {
8071 final AppWindowToken atoken = mAppToken;
8072 return mSurface != null && !mDestroying
8073 && !mDrawPending && !mCommitDrawPending;
8074 }
8075
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008076 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008077 * Return true if the window is opaque and fully drawn. This indicates
8078 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008079 */
8080 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008081 return (mAttrs.format == PixelFormat.OPAQUE
8082 || mAttrs.type == TYPE_WALLPAPER)
8083 && mSurface != null && mAnimation == null
8084 && (mAppToken == null || mAppToken.animation == null)
8085 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008086 }
8087
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008088 /**
8089 * Return whether this window is wanting to have a translation
8090 * animation applied to it for an in-progress move. (Only makes
8091 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
8092 */
8093 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008094 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008095 && (mFrame.top != mLastFrame.top
8096 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008097 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008098 && mPolicy.isScreenOn();
8099 }
8100
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008101 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8102 return
8103 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008104 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8105 // only if it's visible
8106 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008107 // and only if the application fills the compatible screen
8108 mFrame.left <= mCompatibleScreenFrame.left &&
8109 mFrame.top <= mCompatibleScreenFrame.top &&
8110 mFrame.right >= mCompatibleScreenFrame.right &&
Dianne Hackbornac1471a2011-02-03 13:46:06 -08008111 mFrame.bottom >= mCompatibleScreenFrame.bottom;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008112 }
8113
8114 boolean isFullscreen(int screenWidth, int screenHeight) {
8115 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008116 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008117 }
8118
8119 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008120 disposeInputChannel();
8121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008122 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008123 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008124 mAttachedWindow.mChildWindows.remove(this);
8125 }
8126 destroySurfaceLocked();
8127 mSession.windowRemovedLocked();
8128 try {
8129 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8130 } catch (RuntimeException e) {
8131 // Ignore if it has already been removed (usually because
8132 // we are doing this as part of processing a death note.)
8133 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008134 }
8135
8136 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008137 if (mInputChannel != null) {
8138 mInputManager.unregisterInputChannel(mInputChannel);
8139
8140 mInputChannel.dispose();
8141 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008143 }
8144
8145 private class DeathRecipient implements IBinder.DeathRecipient {
8146 public void binderDied() {
8147 try {
8148 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008149 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008150 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 if (win != null) {
8152 removeWindowLocked(mSession, win);
8153 }
8154 }
8155 } catch (IllegalArgumentException ex) {
8156 // This will happen if the window has already been
8157 // removed.
8158 }
8159 }
8160 }
8161
8162 /** Returns true if this window desires key events. */
8163 public final boolean canReceiveKeys() {
8164 return isVisibleOrAdding()
8165 && (mViewVisibility == View.VISIBLE)
8166 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8167 }
8168
8169 public boolean hasDrawnLw() {
8170 return mHasDrawn;
8171 }
8172
8173 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008174 return showLw(doAnimation, true);
8175 }
8176
8177 boolean showLw(boolean doAnimation, boolean requestAnim) {
8178 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8179 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008180 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008181 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008182 if (doAnimation) {
8183 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8184 + mPolicyVisibility + " mAnimation=" + mAnimation);
8185 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8186 doAnimation = false;
8187 } else if (mPolicyVisibility && mAnimation == null) {
8188 // Check for the case where we are currently visible and
8189 // not animating; we do not want to do animation at such a
8190 // point to become visible when we already are.
8191 doAnimation = false;
8192 }
8193 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008194 mPolicyVisibility = true;
8195 mPolicyVisibilityAfterAnim = true;
8196 if (doAnimation) {
8197 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8198 }
8199 if (requestAnim) {
8200 requestAnimationLocked(0);
8201 }
8202 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008203 }
8204
8205 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008206 return hideLw(doAnimation, true);
8207 }
8208
8209 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008210 if (doAnimation) {
8211 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8212 doAnimation = false;
8213 }
8214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008215 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8216 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008217 if (!current) {
8218 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008219 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008220 if (doAnimation) {
8221 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8222 if (mAnimation == null) {
8223 doAnimation = false;
8224 }
8225 }
8226 if (doAnimation) {
8227 mPolicyVisibilityAfterAnim = false;
8228 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008229 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008230 mPolicyVisibilityAfterAnim = false;
8231 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008232 // Window is no longer visible -- make sure if we were waiting
8233 // for it to be displayed before enabling the display, that
8234 // we allow the display to be enabled now.
8235 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008236 if (mCurrentFocus == this) {
8237 mFocusMayChange = true;
8238 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008239 }
8240 if (requestAnim) {
8241 requestAnimationLocked(0);
8242 }
8243 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008244 }
8245
Jeff Brownfbf09772011-01-16 14:06:57 -08008246 public void getTouchableRegion(Region outRegion) {
8247 final Rect frame = mFrame;
8248 switch (mTouchableInsets) {
8249 default:
8250 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8251 outRegion.set(frame);
8252 break;
8253 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8254 final Rect inset = mGivenContentInsets;
8255 outRegion.set(
8256 frame.left + inset.left, frame.top + inset.top,
8257 frame.right - inset.right, frame.bottom - inset.bottom);
8258 break;
8259 }
8260 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8261 final Rect inset = mGivenVisibleInsets;
8262 outRegion.set(
8263 frame.left + inset.left, frame.top + inset.top,
8264 frame.right - inset.right, frame.bottom - inset.bottom);
8265 break;
8266 }
8267 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8268 final Region givenTouchableRegion = mGivenTouchableRegion;
8269 outRegion.set(givenTouchableRegion);
8270 outRegion.translate(frame.left, frame.top);
8271 break;
8272 }
8273 }
8274 }
8275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008276 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008277 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8278 pw.print(" mClient="); pw.println(mClient.asBinder());
8279 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8280 if (mAttachedWindow != null || mLayoutAttached) {
8281 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8282 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8283 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008284 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8285 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8286 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008287 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8288 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008289 }
8290 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8291 pw.print(" mSubLayer="); pw.print(mSubLayer);
8292 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8293 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8294 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8295 pw.print("="); pw.print(mAnimLayer);
8296 pw.print(" mLastLayer="); pw.println(mLastLayer);
8297 if (mSurface != null) {
8298 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008299 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8300 pw.print(" layer="); pw.print(mSurfaceLayer);
8301 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8302 pw.print(" rect=("); pw.print(mSurfaceX);
8303 pw.print(","); pw.print(mSurfaceY);
8304 pw.print(") "); pw.print(mSurfaceW);
8305 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008306 }
8307 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8308 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8309 if (mAppToken != null) {
8310 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8311 }
8312 if (mTargetAppToken != null) {
8313 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8314 }
8315 pw.print(prefix); pw.print("mViewVisibility=0x");
8316 pw.print(Integer.toHexString(mViewVisibility));
8317 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008318 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8319 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008320 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8321 pw.print(prefix); pw.print("mPolicyVisibility=");
8322 pw.print(mPolicyVisibility);
8323 pw.print(" mPolicyVisibilityAfterAnim=");
8324 pw.print(mPolicyVisibilityAfterAnim);
8325 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8326 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008327 if (!mRelayoutCalled) {
8328 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8329 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008330 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008331 pw.print(" h="); pw.print(mRequestedHeight);
8332 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008333 if (mXOffset != 0 || mYOffset != 0) {
8334 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8335 pw.print(" y="); pw.println(mYOffset);
8336 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008337 pw.print(prefix); pw.print("mGivenContentInsets=");
8338 mGivenContentInsets.printShortString(pw);
8339 pw.print(" mGivenVisibleInsets=");
8340 mGivenVisibleInsets.printShortString(pw);
8341 pw.println();
8342 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8343 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8344 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8345 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008346 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008347 pw.print(prefix); pw.print("mShownFrame=");
8348 mShownFrame.printShortString(pw);
8349 pw.print(" last="); mLastShownFrame.printShortString(pw);
8350 pw.println();
8351 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8352 pw.print(" last="); mLastFrame.printShortString(pw);
8353 pw.println();
8354 pw.print(prefix); pw.print("mContainingFrame=");
8355 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008356 pw.print(" mParentFrame=");
8357 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008358 pw.print(" mDisplayFrame=");
8359 mDisplayFrame.printShortString(pw);
8360 pw.println();
8361 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8362 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8363 pw.println();
8364 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8365 pw.print(" last="); mLastContentInsets.printShortString(pw);
8366 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8367 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8368 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008369 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8370 || mAnimation != null) {
8371 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8372 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8373 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8374 pw.print(" mAnimation="); pw.println(mAnimation);
8375 }
8376 if (mHasTransformation || mHasLocalTransformation) {
8377 pw.print(prefix); pw.print("XForm: has=");
8378 pw.print(mHasTransformation);
8379 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8380 pw.print(" "); mTransformation.printShortString(pw);
8381 pw.println();
8382 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008383 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8384 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8385 pw.print(" mAlpha="); pw.print(mAlpha);
8386 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8387 }
8388 if (mHaveMatrix) {
8389 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8390 pw.print(" mDtDx="); pw.print(mDtDx);
8391 pw.print(" mDsDy="); pw.print(mDsDy);
8392 pw.print(" mDtDy="); pw.println(mDtDy);
8393 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008394 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8395 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8396 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8397 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8398 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8399 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8400 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8401 pw.print(" mDestroying="); pw.print(mDestroying);
8402 pw.print(" mRemoved="); pw.println(mRemoved);
8403 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008404 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008405 pw.print(prefix); pw.print("mOrientationChanging=");
8406 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008407 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8408 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008409 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008410 if (mHScale != 1 || mVScale != 1) {
8411 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8412 pw.print(" mVScale="); pw.println(mVScale);
8413 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008414 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008415 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8416 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8417 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008418 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8419 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8420 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008422 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008423
8424 String makeInputChannelName() {
8425 return Integer.toHexString(System.identityHashCode(this))
8426 + " " + mAttrs.getTitle();
8427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008428
8429 @Override
8430 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008431 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8432 || mWasPaused != mToken.paused) {
8433 mLastTitle = mAttrs.getTitle();
8434 mWasPaused = mToken.paused;
8435 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8436 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8437 }
8438 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008439 }
8440 }
Romain Guy06882f82009-06-10 13:36:04 -07008441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008442 // -------------------------------------------------------------
8443 // Window Token State
8444 // -------------------------------------------------------------
8445
8446 class WindowToken {
8447 // The actual token.
8448 final IBinder token;
8449
8450 // The type of window this token is for, as per WindowManager.LayoutParams.
8451 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453 // Set if this token was explicitly added by a client, so should
8454 // not be removed when all windows are removed.
8455 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008456
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008457 // For printing.
8458 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008460 // If this is an AppWindowToken, this is non-null.
8461 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008463 // All of the windows associated with this token.
8464 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8465
8466 // Is key dispatching paused for this token?
8467 boolean paused = false;
8468
8469 // Should this token's windows be hidden?
8470 boolean hidden;
8471
8472 // Temporary for finding which tokens no longer have visible windows.
8473 boolean hasVisible;
8474
Dianne Hackborna8f60182009-09-01 19:01:50 -07008475 // Set to true when this token is in a pending transaction where it
8476 // will be shown.
8477 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008478
Dianne Hackborna8f60182009-09-01 19:01:50 -07008479 // Set to true when this token is in a pending transaction where it
8480 // will be hidden.
8481 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008482
Dianne Hackborna8f60182009-09-01 19:01:50 -07008483 // Set to true when this token is in a pending transaction where its
8484 // windows will be put to the bottom of the list.
8485 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008486
Dianne Hackborna8f60182009-09-01 19:01:50 -07008487 // Set to true when this token is in a pending transaction where its
8488 // windows will be put to the top of the list.
8489 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 WindowToken(IBinder _token, int type, boolean _explicit) {
8492 token = _token;
8493 windowType = type;
8494 explicit = _explicit;
8495 }
8496
8497 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008498 pw.print(prefix); pw.print("token="); pw.println(token);
8499 pw.print(prefix); pw.print("windows="); pw.println(windows);
8500 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8501 pw.print(" hidden="); pw.print(hidden);
8502 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008503 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8504 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8505 pw.print(" waitingToHide="); pw.print(waitingToHide);
8506 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8507 pw.print(" sendingToTop="); pw.println(sendingToTop);
8508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008509 }
8510
8511 @Override
8512 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008513 if (stringName == null) {
8514 StringBuilder sb = new StringBuilder();
8515 sb.append("WindowToken{");
8516 sb.append(Integer.toHexString(System.identityHashCode(this)));
8517 sb.append(" token="); sb.append(token); sb.append('}');
8518 stringName = sb.toString();
8519 }
8520 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008521 }
8522 };
8523
8524 class AppWindowToken extends WindowToken {
8525 // Non-null only for application tokens.
8526 final IApplicationToken appToken;
8527
8528 // All of the windows and child windows that are included in this
8529 // application token. Note this list is NOT sorted!
8530 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8531
8532 int groupId = -1;
8533 boolean appFullscreen;
8534 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008535
8536 // The input dispatching timeout for this application token in nanoseconds.
8537 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 // These are used for determining when all windows associated with
8540 // an activity have been drawn, so they can be made visible together
8541 // at the same time.
8542 int lastTransactionSequence = mTransactionSequence-1;
8543 int numInterestingWindows;
8544 int numDrawnWindows;
8545 boolean inPendingTransaction;
8546 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 // Is this token going to be hidden in a little while? If so, it
8549 // won't be taken into account for setting the screen orientation.
8550 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 // Is this window's surface needed? This is almost like hidden, except
8553 // it will sometimes be true a little earlier: when the token has
8554 // been shown, but is still waiting for its app transition to execute
8555 // before making its windows shown.
8556 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558 // Have we told the window clients to hide themselves?
8559 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 // Last visibility state we reported to the app token.
8562 boolean reportedVisible;
8563
8564 // Set to true when the token has been removed from the window mgr.
8565 boolean removed;
8566
8567 // Have we been asked to have this token keep the screen frozen?
8568 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 boolean animating;
8571 Animation animation;
8572 boolean hasTransformation;
8573 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008575 // Offset to the window of all layers in the token, for use by
8576 // AppWindowToken animations.
8577 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008579 // Information about an application starting window if displayed.
8580 StartingData startingData;
8581 WindowState startingWindow;
8582 View startingView;
8583 boolean startingDisplayed;
8584 boolean startingMoved;
8585 boolean firstWindowDrawn;
8586
Jeff Brown928e0542011-01-10 11:17:36 -08008587 // Input application handle used by the input dispatcher.
8588 InputApplicationHandle mInputApplicationHandle;
8589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 AppWindowToken(IApplicationToken _token) {
8591 super(_token.asBinder(),
8592 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8593 appWindowToken = this;
8594 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008595 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 }
Romain Guy06882f82009-06-10 13:36:04 -07008597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008598 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008599 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008600 TAG, "Setting animation in " + this + ": " + anim);
8601 animation = anim;
8602 animating = false;
8603 anim.restrictDuration(MAX_ANIMATION_DURATION);
8604 anim.scaleCurrentDuration(mTransitionAnimationScale);
8605 int zorder = anim.getZAdjustment();
8606 int adj = 0;
8607 if (zorder == Animation.ZORDER_TOP) {
8608 adj = TYPE_LAYER_OFFSET;
8609 } else if (zorder == Animation.ZORDER_BOTTOM) {
8610 adj = -TYPE_LAYER_OFFSET;
8611 }
Romain Guy06882f82009-06-10 13:36:04 -07008612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008613 if (animLayerAdjustment != adj) {
8614 animLayerAdjustment = adj;
8615 updateLayers();
8616 }
8617 }
Romain Guy06882f82009-06-10 13:36:04 -07008618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 public void setDummyAnimation() {
8620 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008621 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008622 TAG, "Setting dummy animation in " + this);
8623 animation = sDummyAnimation;
8624 }
8625 }
8626
8627 public void clearAnimation() {
8628 if (animation != null) {
8629 animation = null;
8630 animating = true;
8631 }
8632 }
Romain Guy06882f82009-06-10 13:36:04 -07008633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008634 void updateLayers() {
8635 final int N = allAppWindows.size();
8636 final int adj = animLayerAdjustment;
8637 for (int i=0; i<N; i++) {
8638 WindowState w = allAppWindows.get(i);
8639 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008640 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 + w.mAnimLayer);
Dianne Hackborne75d8722011-01-27 19:37:40 -08008642 if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008643 setInputMethodAnimLayerAdjustment(adj);
8644 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008645 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008646 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 }
8649 }
Romain Guy06882f82009-06-10 13:36:04 -07008650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008651 void sendAppVisibilityToClients() {
8652 final int N = allAppWindows.size();
8653 for (int i=0; i<N; i++) {
8654 WindowState win = allAppWindows.get(i);
8655 if (win == startingWindow && clientHidden) {
8656 // Don't hide the starting window.
8657 continue;
8658 }
8659 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008660 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008661 "Setting visibility of " + win + ": " + (!clientHidden));
8662 win.mClient.dispatchAppVisibility(!clientHidden);
8663 } catch (RemoteException e) {
8664 }
8665 }
8666 }
Romain Guy06882f82009-06-10 13:36:04 -07008667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 void showAllWindowsLocked() {
8669 final int NW = allAppWindows.size();
8670 for (int i=0; i<NW; i++) {
8671 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008672 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 "performing show on: " + w);
8674 w.performShowLocked();
8675 }
8676 }
Romain Guy06882f82009-06-10 13:36:04 -07008677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008678 // This must be called while inside a transaction.
8679 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008680 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 if (animation == sDummyAnimation) {
8684 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008685 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 // when it is really time to animate, this will be set to
8687 // a real animation and the next call will execute normally.
8688 return false;
8689 }
Romain Guy06882f82009-06-10 13:36:04 -07008690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008691 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8692 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008693 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008694 TAG, "Starting animation in " + this +
8695 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8696 + " scale=" + mTransitionAnimationScale
8697 + " allDrawn=" + allDrawn + " animating=" + animating);
8698 animation.initialize(dw, dh, dw, dh);
8699 animation.setStartTime(currentTime);
8700 animating = true;
8701 }
8702 transformation.clear();
8703 final boolean more = animation.getTransformation(
8704 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008705 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008706 TAG, "Stepped animation in " + this +
8707 ": more=" + more + ", xform=" + transformation);
8708 if (more) {
8709 // we're done!
8710 hasTransformation = true;
8711 return true;
8712 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008713 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008714 TAG, "Finished animation in " + this +
8715 " @ " + currentTime);
8716 animation = null;
8717 }
8718 } else if (animation != null) {
8719 // If the display is frozen, and there is a pending animation,
8720 // clear it and make sure we run the cleanup code.
8721 animating = true;
8722 animation = null;
8723 }
8724
8725 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008727 if (!animating) {
8728 return false;
8729 }
8730
8731 clearAnimation();
8732 animating = false;
Dianne Hackborne75d8722011-01-27 19:37:40 -08008733 if (animLayerAdjustment != 0) {
8734 animLayerAdjustment = 0;
8735 updateLayers();
8736 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8738 moveInputMethodWindowsIfNeededLocked(true);
8739 }
Romain Guy06882f82009-06-10 13:36:04 -07008740
Joe Onorato8a9b2202010-02-26 18:56:32 -08008741 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008742 TAG, "Animation done in " + this
8743 + ": reportedVisible=" + reportedVisible);
8744
8745 transformation.clear();
Romain Guy06882f82009-06-10 13:36:04 -07008746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008747 final int N = windows.size();
8748 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008749 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008750 }
8751 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008753 return false;
8754 }
8755
8756 void updateReportedVisibilityLocked() {
8757 if (appToken == null) {
8758 return;
8759 }
Romain Guy06882f82009-06-10 13:36:04 -07008760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008761 int numInteresting = 0;
8762 int numVisible = 0;
8763 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008764
Joe Onorato8a9b2202010-02-26 18:56:32 -08008765 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008766 final int N = allAppWindows.size();
8767 for (int i=0; i<N; i++) {
8768 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008769 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008770 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008771 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8772 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008773 continue;
8774 }
8775 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008776 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008777 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008778 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008779 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008780 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008781 + " pv=" + win.mPolicyVisibility
8782 + " dp=" + win.mDrawPending
8783 + " cdp=" + win.mCommitDrawPending
8784 + " ah=" + win.mAttachedHidden
8785 + " th="
8786 + (win.mAppToken != null
8787 ? win.mAppToken.hiddenRequested : false)
8788 + " a=" + win.mAnimating);
8789 }
8790 }
8791 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008792 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008793 if (!win.isAnimating()) {
8794 numVisible++;
8795 }
8796 nowGone = false;
8797 } else if (win.isAnimating()) {
8798 nowGone = false;
8799 }
8800 }
Romain Guy06882f82009-06-10 13:36:04 -07008801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008802 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008803 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 + numInteresting + " visible=" + numVisible);
8805 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008806 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008807 TAG, "Visibility changed in " + this
8808 + ": vis=" + nowVisible);
8809 reportedVisible = nowVisible;
8810 Message m = mH.obtainMessage(
8811 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8812 nowVisible ? 1 : 0,
8813 nowGone ? 1 : 0,
8814 this);
8815 mH.sendMessage(m);
8816 }
8817 }
Romain Guy06882f82009-06-10 13:36:04 -07008818
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008819 WindowState findMainWindow() {
8820 int j = windows.size();
8821 while (j > 0) {
8822 j--;
8823 WindowState win = windows.get(j);
8824 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8825 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8826 return win;
8827 }
8828 }
8829 return null;
8830 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008832 void dump(PrintWriter pw, String prefix) {
8833 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008834 if (appToken != null) {
8835 pw.print(prefix); pw.println("app=true");
8836 }
8837 if (allAppWindows.size() > 0) {
8838 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8839 }
8840 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008841 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008842 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8843 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8844 pw.print(" clientHidden="); pw.print(clientHidden);
8845 pw.print(" willBeHidden="); pw.print(willBeHidden);
8846 pw.print(" reportedVisible="); pw.println(reportedVisible);
8847 if (paused || freezingScreen) {
8848 pw.print(prefix); pw.print("paused="); pw.print(paused);
8849 pw.print(" freezingScreen="); pw.println(freezingScreen);
8850 }
8851 if (numInterestingWindows != 0 || numDrawnWindows != 0
8852 || inPendingTransaction || allDrawn) {
8853 pw.print(prefix); pw.print("numInterestingWindows=");
8854 pw.print(numInterestingWindows);
8855 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8856 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8857 pw.print(" allDrawn="); pw.println(allDrawn);
8858 }
8859 if (animating || animation != null) {
8860 pw.print(prefix); pw.print("animating="); pw.print(animating);
8861 pw.print(" animation="); pw.println(animation);
8862 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008863 if (hasTransformation) {
8864 pw.print(prefix); pw.print("XForm: ");
8865 transformation.printShortString(pw);
8866 pw.println();
8867 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008868 if (animLayerAdjustment != 0) {
8869 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8870 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008871 if (startingData != null || removed || firstWindowDrawn) {
8872 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8873 pw.print(" removed="); pw.print(removed);
8874 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8875 }
8876 if (startingWindow != null || startingView != null
8877 || startingDisplayed || startingMoved) {
8878 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8879 pw.print(" startingView="); pw.print(startingView);
8880 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8881 pw.print(" startingMoved"); pw.println(startingMoved);
8882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008883 }
8884
8885 @Override
8886 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008887 if (stringName == null) {
8888 StringBuilder sb = new StringBuilder();
8889 sb.append("AppWindowToken{");
8890 sb.append(Integer.toHexString(System.identityHashCode(this)));
8891 sb.append(" token="); sb.append(token); sb.append('}');
8892 stringName = sb.toString();
8893 }
8894 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008895 }
8896 }
Romain Guy06882f82009-06-10 13:36:04 -07008897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008898 // -------------------------------------------------------------
8899 // DummyAnimation
8900 // -------------------------------------------------------------
8901
8902 // This is an animation that does nothing: it just immediately finishes
8903 // itself every time it is called. It is used as a stub animation in cases
8904 // where we want to synchronize multiple things that may be animating.
8905 static final class DummyAnimation extends Animation {
8906 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8907 return false;
8908 }
8909 }
8910 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008912 // -------------------------------------------------------------
8913 // Async Handler
8914 // -------------------------------------------------------------
8915
8916 static final class StartingData {
8917 final String pkg;
8918 final int theme;
8919 final CharSequence nonLocalizedLabel;
8920 final int labelRes;
8921 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008922 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008924 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008925 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008926 pkg = _pkg;
8927 theme = _theme;
8928 nonLocalizedLabel = _nonLocalizedLabel;
8929 labelRes = _labelRes;
8930 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008931 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 }
8933 }
8934
8935 private final class H extends Handler {
8936 public static final int REPORT_FOCUS_CHANGE = 2;
8937 public static final int REPORT_LOSING_FOCUS = 3;
8938 public static final int ANIMATE = 4;
8939 public static final int ADD_STARTING = 5;
8940 public static final int REMOVE_STARTING = 6;
8941 public static final int FINISHED_STARTING = 7;
8942 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8944 public static final int HOLD_SCREEN_CHANGED = 12;
8945 public static final int APP_TRANSITION_TIMEOUT = 13;
8946 public static final int PERSIST_ANIMATION_SCALE = 14;
8947 public static final int FORCE_GC = 15;
8948 public static final int ENABLE_SCREEN = 16;
8949 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008950 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008951 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008952 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008953 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08008954 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07008955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008956 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008958 public H() {
8959 }
Romain Guy06882f82009-06-10 13:36:04 -07008960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008961 @Override
8962 public void handleMessage(Message msg) {
8963 switch (msg.what) {
8964 case REPORT_FOCUS_CHANGE: {
8965 WindowState lastFocus;
8966 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008968 synchronized(mWindowMap) {
8969 lastFocus = mLastFocus;
8970 newFocus = mCurrentFocus;
8971 if (lastFocus == newFocus) {
8972 // Focus is not changing, so nothing to do.
8973 return;
8974 }
8975 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008976 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008977 // + " to " + newFocus);
8978 if (newFocus != null && lastFocus != null
8979 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008980 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008981 mLosingFocus.add(lastFocus);
8982 lastFocus = null;
8983 }
8984 }
8985
8986 if (lastFocus != newFocus) {
8987 //System.out.println("Changing focus from " + lastFocus
8988 // + " to " + newFocus);
8989 if (newFocus != null) {
8990 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008991 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008992 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8993 } catch (RemoteException e) {
8994 // Ignore if process has died.
8995 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008996 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 }
8998
8999 if (lastFocus != null) {
9000 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009001 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009002 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
9003 } catch (RemoteException e) {
9004 // Ignore if process has died.
9005 }
9006 }
Joe Onorato664644d2011-01-23 17:53:23 -08009007
9008 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009009 }
9010 } break;
9011
9012 case REPORT_LOSING_FOCUS: {
9013 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07009014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009015 synchronized(mWindowMap) {
9016 losers = mLosingFocus;
9017 mLosingFocus = new ArrayList<WindowState>();
9018 }
9019
9020 final int N = losers.size();
9021 for (int i=0; i<N; i++) {
9022 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009023 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009024 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
9025 } catch (RemoteException e) {
9026 // Ignore if process has died.
9027 }
9028 }
9029 } break;
9030
9031 case ANIMATE: {
9032 synchronized(mWindowMap) {
9033 mAnimationPending = false;
9034 performLayoutAndPlaceSurfacesLocked();
9035 }
9036 } break;
9037
9038 case ADD_STARTING: {
9039 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9040 final StartingData sd = wtoken.startingData;
9041
9042 if (sd == null) {
9043 // Animation has been canceled... do nothing.
9044 return;
9045 }
Romain Guy06882f82009-06-10 13:36:04 -07009046
Joe Onorato8a9b2202010-02-26 18:56:32 -08009047 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009048 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07009049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009050 View view = null;
9051 try {
9052 view = mPolicy.addStartingWindow(
9053 wtoken.token, sd.pkg,
9054 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08009055 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009056 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009057 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009058 }
9059
9060 if (view != null) {
9061 boolean abort = false;
9062
9063 synchronized(mWindowMap) {
9064 if (wtoken.removed || wtoken.startingData == null) {
9065 // If the window was successfully added, then
9066 // we need to remove it.
9067 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009068 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009069 "Aborted starting " + wtoken
9070 + ": removed=" + wtoken.removed
9071 + " startingData=" + wtoken.startingData);
9072 wtoken.startingWindow = null;
9073 wtoken.startingData = null;
9074 abort = true;
9075 }
9076 } else {
9077 wtoken.startingView = view;
9078 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009079 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009080 "Added starting " + wtoken
9081 + ": startingWindow="
9082 + wtoken.startingWindow + " startingView="
9083 + wtoken.startingView);
9084 }
9085
9086 if (abort) {
9087 try {
9088 mPolicy.removeStartingWindow(wtoken.token, view);
9089 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009090 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009091 }
9092 }
9093 }
9094 } break;
9095
9096 case REMOVE_STARTING: {
9097 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9098 IBinder token = null;
9099 View view = null;
9100 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009101 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009102 + wtoken + ": startingWindow="
9103 + wtoken.startingWindow + " startingView="
9104 + wtoken.startingView);
9105 if (wtoken.startingWindow != null) {
9106 view = wtoken.startingView;
9107 token = wtoken.token;
9108 wtoken.startingData = null;
9109 wtoken.startingView = null;
9110 wtoken.startingWindow = null;
9111 }
9112 }
9113 if (view != null) {
9114 try {
9115 mPolicy.removeStartingWindow(token, view);
9116 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009117 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 }
9119 }
9120 } break;
9121
9122 case FINISHED_STARTING: {
9123 IBinder token = null;
9124 View view = null;
9125 while (true) {
9126 synchronized (mWindowMap) {
9127 final int N = mFinishedStarting.size();
9128 if (N <= 0) {
9129 break;
9130 }
9131 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9132
Joe Onorato8a9b2202010-02-26 18:56:32 -08009133 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009134 "Finished starting " + wtoken
9135 + ": startingWindow=" + wtoken.startingWindow
9136 + " startingView=" + wtoken.startingView);
9137
9138 if (wtoken.startingWindow == null) {
9139 continue;
9140 }
9141
9142 view = wtoken.startingView;
9143 token = wtoken.token;
9144 wtoken.startingData = null;
9145 wtoken.startingView = null;
9146 wtoken.startingWindow = null;
9147 }
9148
9149 try {
9150 mPolicy.removeStartingWindow(token, view);
9151 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009152 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009153 }
9154 }
9155 } break;
9156
9157 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9158 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9159
9160 boolean nowVisible = msg.arg1 != 0;
9161 boolean nowGone = msg.arg2 != 0;
9162
9163 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009164 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009165 TAG, "Reporting visible in " + wtoken
9166 + " visible=" + nowVisible
9167 + " gone=" + nowGone);
9168 if (nowVisible) {
9169 wtoken.appToken.windowsVisible();
9170 } else {
9171 wtoken.appToken.windowsGone();
9172 }
9173 } catch (RemoteException ex) {
9174 }
9175 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009177 case WINDOW_FREEZE_TIMEOUT: {
9178 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009179 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009180 int i = mWindows.size();
9181 while (i > 0) {
9182 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009183 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 if (w.mOrientationChanging) {
9185 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009186 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009187 }
9188 }
9189 performLayoutAndPlaceSurfacesLocked();
9190 }
9191 break;
9192 }
Romain Guy06882f82009-06-10 13:36:04 -07009193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009194 case HOLD_SCREEN_CHANGED: {
9195 Session oldHold;
9196 Session newHold;
9197 synchronized (mWindowMap) {
9198 oldHold = mLastReportedHold;
9199 newHold = (Session)msg.obj;
9200 mLastReportedHold = newHold;
9201 }
Romain Guy06882f82009-06-10 13:36:04 -07009202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009203 if (oldHold != newHold) {
9204 try {
9205 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009206 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009207 "window",
9208 BatteryStats.WAKE_TYPE_WINDOW);
9209 }
9210 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009211 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009212 "window",
9213 BatteryStats.WAKE_TYPE_WINDOW);
9214 }
9215 } catch (RemoteException e) {
9216 }
9217 }
9218 break;
9219 }
Romain Guy06882f82009-06-10 13:36:04 -07009220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009221 case APP_TRANSITION_TIMEOUT: {
9222 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009223 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009224 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009225 "*** APP TRANSITION TIMEOUT");
9226 mAppTransitionReady = true;
9227 mAppTransitionTimeout = true;
9228 performLayoutAndPlaceSurfacesLocked();
9229 }
9230 }
9231 break;
9232 }
Romain Guy06882f82009-06-10 13:36:04 -07009233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009234 case PERSIST_ANIMATION_SCALE: {
9235 Settings.System.putFloat(mContext.getContentResolver(),
9236 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9237 Settings.System.putFloat(mContext.getContentResolver(),
9238 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9239 break;
9240 }
Romain Guy06882f82009-06-10 13:36:04 -07009241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 case FORCE_GC: {
9243 synchronized(mWindowMap) {
9244 if (mAnimationPending) {
9245 // If we are animating, don't do the gc now but
9246 // delay a bit so we don't interrupt the animation.
9247 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9248 2000);
9249 return;
9250 }
9251 // If we are currently rotating the display, it will
9252 // schedule a new message when done.
9253 if (mDisplayFrozen) {
9254 return;
9255 }
9256 mFreezeGcPending = 0;
9257 }
9258 Runtime.getRuntime().gc();
9259 break;
9260 }
Romain Guy06882f82009-06-10 13:36:04 -07009261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 case ENABLE_SCREEN: {
9263 performEnableScreen();
9264 break;
9265 }
Romain Guy06882f82009-06-10 13:36:04 -07009266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009267 case APP_FREEZE_TIMEOUT: {
9268 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009269 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 int i = mAppTokens.size();
9271 while (i > 0) {
9272 i--;
9273 AppWindowToken tok = mAppTokens.get(i);
9274 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009275 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009276 unsetAppFreezingScreenLocked(tok, true, true);
9277 }
9278 }
9279 }
9280 break;
9281 }
Romain Guy06882f82009-06-10 13:36:04 -07009282
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009283 case SEND_NEW_CONFIGURATION: {
9284 removeMessages(SEND_NEW_CONFIGURATION);
9285 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009286 break;
9287 }
Romain Guy06882f82009-06-10 13:36:04 -07009288
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009289 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009290 if (mWindowsChanged) {
9291 synchronized (mWindowMap) {
9292 mWindowsChanged = false;
9293 }
9294 notifyWindowsChanged();
9295 }
9296 break;
9297 }
9298
Christopher Tatea53146c2010-09-07 11:57:52 -07009299 case DRAG_START_TIMEOUT: {
9300 IBinder win = (IBinder)msg.obj;
9301 if (DEBUG_DRAG) {
9302 Slog.w(TAG, "Timeout starting drag by win " + win);
9303 }
9304 synchronized (mWindowMap) {
9305 // !!! TODO: ANR the app that has failed to start the drag in time
9306 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009307 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009308 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009309 mDragState.reset();
9310 mDragState = null;
9311 }
9312 }
Chris Tated4533f142010-10-19 15:15:08 -07009313 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009314 }
9315
Chris Tated4533f142010-10-19 15:15:08 -07009316 case DRAG_END_TIMEOUT: {
9317 IBinder win = (IBinder)msg.obj;
9318 if (DEBUG_DRAG) {
9319 Slog.w(TAG, "Timeout ending drag to win " + win);
9320 }
9321 synchronized (mWindowMap) {
9322 // !!! TODO: ANR the drag-receiving app
9323 mDragState.mDragResult = false;
9324 mDragState.endDragLw();
9325 }
9326 break;
9327 }
Jeff Brown2992ea72011-01-28 22:04:14 -08009328
9329 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
9330 notifyHardKeyboardStatusChange();
9331 break;
9332 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 }
9334 }
9335 }
9336
9337 // -------------------------------------------------------------
9338 // IWindowManager API
9339 // -------------------------------------------------------------
9340
9341 public IWindowSession openSession(IInputMethodClient client,
9342 IInputContext inputContext) {
9343 if (client == null) throw new IllegalArgumentException("null client");
9344 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009345 Session session = new Session(client, inputContext);
9346 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 }
9348
9349 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9350 synchronized (mWindowMap) {
9351 // The focus for the client is the window immediately below
9352 // where we would place the input method window.
9353 int idx = findDesiredInputMethodWindowIndexLocked(false);
9354 WindowState imFocus;
9355 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009356 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08009357 //Log.i(TAG, "Desired input method target: " + imFocus);
9358 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
9359 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009360 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08009361 // This may be a starting window, in which case we still want
9362 // to count it as okay.
9363 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
9364 && imFocus.mAppToken != null) {
9365 // The client has definitely started, so it really should
9366 // have a window in this app token. Let's look for it.
9367 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
9368 WindowState w = imFocus.mAppToken.windows.get(i);
9369 if (w != imFocus) {
9370 //Log.i(TAG, "Switching to real app window: " + w);
9371 imFocus = w;
9372 break;
9373 }
9374 }
9375 }
9376 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
9377 //if (imFocus.mSession.mClient != null) {
9378 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
9379 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
9380 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009381 if (imFocus.mSession.mClient != null &&
9382 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9383 return true;
9384 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08009385
9386 // Okay, how about this... what is the current focus?
9387 // It seems in some cases we may not have moved the IM
9388 // target window, such as when it was in a pop-up window,
9389 // so let's also look at the current focus. (An example:
9390 // go to Gmail, start searching so the keyboard goes up,
9391 // press home. Sometimes the IME won't go down.)
9392 // Would be nice to fix this more correctly, but it's
9393 // way at the end of a release, and this should be good enough.
9394 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
9395 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
9396 return true;
9397 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 }
9399 }
9400 }
9401 return false;
9402 }
Romain Guy06882f82009-06-10 13:36:04 -07009403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 // -------------------------------------------------------------
9405 // Internals
9406 // -------------------------------------------------------------
9407
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009408 final WindowState windowForClientLocked(Session session, IWindow client,
9409 boolean throwOnError) {
9410 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 }
Romain Guy06882f82009-06-10 13:36:04 -07009412
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009413 final WindowState windowForClientLocked(Session session, IBinder client,
9414 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009415 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009416 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 TAG, "Looking up client " + client + ": " + win);
9418 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009419 RuntimeException ex = new IllegalArgumentException(
9420 "Requested window " + client + " does not exist");
9421 if (throwOnError) {
9422 throw ex;
9423 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009424 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009425 return null;
9426 }
9427 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009428 RuntimeException ex = new IllegalArgumentException(
9429 "Requested window " + client + " is in session " +
9430 win.mSession + ", not " + session);
9431 if (throwOnError) {
9432 throw ex;
9433 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009434 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009435 return null;
9436 }
9437
9438 return win;
9439 }
9440
Dianne Hackborna8f60182009-09-01 19:01:50 -07009441 final void rebuildAppWindowListLocked() {
9442 int NW = mWindows.size();
9443 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009444 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009445 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009446
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009447 if (mRebuildTmp.length < NW) {
9448 mRebuildTmp = new WindowState[NW+10];
9449 }
9450
Dianne Hackborna8f60182009-09-01 19:01:50 -07009451 // First remove all existing app windows.
9452 i=0;
9453 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009454 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009455 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009456 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009457 win.mRebuilding = true;
9458 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009459 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009460 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009461 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009462 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009463 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009464 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009465 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9466 && lastWallpaper == i-1) {
9467 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009468 }
9469 i++;
9470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009471
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009472 // The wallpaper window(s) typically live at the bottom of the stack,
9473 // so skip them before adding app tokens.
9474 lastWallpaper++;
9475 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009476
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009477 // First add all of the exiting app tokens... these are no longer
9478 // in the main app list, but still have windows shown. We put them
9479 // in the back because now that the animation is over we no longer
9480 // will care about them.
9481 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009482 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009483 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9484 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009485
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009486 // And add in the still active app tokens in Z order.
9487 NT = mAppTokens.size();
9488 for (int j=0; j<NT; j++) {
9489 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009490 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009491
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009492 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009493 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009494 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009495 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009496 for (i=0; i<numRemoved; i++) {
9497 WindowState ws = mRebuildTmp[i];
9498 if (ws.mRebuilding) {
9499 StringWriter sw = new StringWriter();
9500 PrintWriter pw = new PrintWriter(sw);
9501 ws.dump(pw, "");
9502 pw.flush();
9503 Slog.w(TAG, "This window was lost: " + ws);
9504 Slog.w(TAG, sw.toString());
9505 }
9506 }
9507 Slog.w(TAG, "Current app token list:");
9508 dumpAppTokensLocked();
9509 Slog.w(TAG, "Final window list:");
9510 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009511 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009512 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514 private final void assignLayersLocked() {
9515 int N = mWindows.size();
9516 int curBaseLayer = 0;
9517 int curLayer = 0;
9518 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009519
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009520 if (DEBUG_LAYERS) {
9521 RuntimeException here = new RuntimeException("here");
9522 here.fillInStackTrace();
9523 Log.v(TAG, "Assigning layers", here);
9524 }
9525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009526 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009527 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009528 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9529 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009530 curLayer += WINDOW_LAYER_MULTIPLIER;
9531 w.mLayer = curLayer;
9532 } else {
9533 curBaseLayer = curLayer = w.mBaseLayer;
9534 w.mLayer = curLayer;
9535 }
9536 if (w.mTargetAppToken != null) {
9537 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9538 } else if (w.mAppToken != null) {
9539 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9540 } else {
9541 w.mAnimLayer = w.mLayer;
9542 }
9543 if (w.mIsImWindow) {
9544 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009545 } else if (w.mIsWallpaper) {
9546 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009547 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009548 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009549 + w.mAnimLayer);
9550 //System.out.println(
9551 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9552 }
9553 }
9554
9555 private boolean mInLayout = false;
9556 private final void performLayoutAndPlaceSurfacesLocked() {
9557 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009558 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009559 throw new RuntimeException("Recursive call!");
9560 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009561 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009562 return;
9563 }
9564
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009565 if (mWaitingForConfig) {
9566 // Our configuration has changed (most likely rotation), but we
9567 // don't yet have the complete configuration to report to
9568 // applications. Don't do any window layout until we have it.
9569 return;
9570 }
9571
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009572 if (mDisplay == null) {
9573 // Not yet initialized, nothing to do.
9574 return;
9575 }
9576
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009577 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009578 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009579
9580 try {
9581 if (mForceRemoves != null) {
9582 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009583 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009584 for (int i=0; i<mForceRemoves.size(); i++) {
9585 WindowState ws = mForceRemoves.get(i);
9586 Slog.i(TAG, "Force removing: " + ws);
9587 removeWindowInnerLocked(ws.mSession, ws);
9588 }
9589 mForceRemoves = null;
9590 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9591 Object tmp = new Object();
9592 synchronized (tmp) {
9593 try {
9594 tmp.wait(250);
9595 } catch (InterruptedException e) {
9596 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009597 }
9598 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009599 } catch (RuntimeException e) {
9600 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009601 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 try {
9604 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009605
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009606 int N = mPendingRemove.size();
9607 if (N > 0) {
9608 if (mPendingRemoveTmp.length < N) {
9609 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009610 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009611 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009612 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009613 for (int i=0; i<N; i++) {
9614 WindowState w = mPendingRemoveTmp[i];
9615 removeWindowInnerLocked(w.mSession, w);
9616 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009617
9618 mInLayout = false;
9619 assignLayersLocked();
9620 mLayoutNeeded = true;
9621 performLayoutAndPlaceSurfacesLocked();
9622
9623 } else {
9624 mInLayout = false;
9625 if (mLayoutNeeded) {
9626 requestAnimationLocked(0);
9627 }
9628 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009629 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009630 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9631 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633 } catch (RuntimeException e) {
9634 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009635 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009636 }
9637 }
9638
Jeff Brown3a22cd92011-01-21 13:59:04 -08009639 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009640 if (!mLayoutNeeded) {
9641 return 0;
9642 }
9643
9644 mLayoutNeeded = false;
9645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009646 final int dw = mDisplay.getWidth();
9647 final int dh = mDisplay.getHeight();
9648
9649 final int N = mWindows.size();
9650 int i;
9651
Joe Onorato8a9b2202010-02-26 18:56:32 -08009652 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009653 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9654
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009655 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009656
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009657 int seq = mLayoutSeq+1;
9658 if (seq < 0) seq = 0;
9659 mLayoutSeq = seq;
9660
9661 // First perform layout of any root windows (not attached
9662 // to another window).
9663 int topAttached = -1;
9664 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009665 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009666
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009667 // Don't do layout of a window if it is not visible, or
9668 // soon won't be visible, to avoid wasting time and funky
9669 // changes while a window is animating away.
9670 final AppWindowToken atoken = win.mAppToken;
9671 final boolean gone = win.mViewVisibility == View.GONE
9672 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009673 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009674 || (atoken != null && atoken.hiddenRequested)
9675 || win.mAttachedHidden
9676 || win.mExiting || win.mDestroying;
9677
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009678 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9679 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009680 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9681 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009682 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009683 + win.mViewVisibility + " mRelayoutCalled="
9684 + win.mRelayoutCalled + " hidden="
9685 + win.mRootToken.hidden + " hiddenRequested="
9686 + (atoken != null && atoken.hiddenRequested)
9687 + " mAttachedHidden=" + win.mAttachedHidden);
9688 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009689
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009690 // If this view is GONE, then skip it -- keep the current
9691 // frame, and let the caller know so they can ignore it
9692 // if they want. (We do the normal layout for INVISIBLE
9693 // windows, since that means "perform layout as normal,
9694 // just don't display").
9695 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009696 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009697 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009698 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009699 win.mContentChanged = false;
9700 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009701 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9702 win.mLayoutSeq = seq;
9703 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9704 + win.mFrame + " mContainingFrame="
9705 + win.mContainingFrame + " mDisplayFrame="
9706 + win.mDisplayFrame);
9707 } else {
9708 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009709 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009710 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009711 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009712
9713 // Now perform layout of attached windows, which usually
9714 // depend on the position of the window they are attached to.
9715 // XXX does not deal with windows that are attached to windows
9716 // that are themselves attached.
9717 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009718 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009719
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009720 if (win.mLayoutAttached) {
9721 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9722 + " mHaveFrame=" + win.mHaveFrame
9723 + " mViewVisibility=" + win.mViewVisibility
9724 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009725 // If this view is GONE, then skip it -- keep the current
9726 // frame, and let the caller know so they can ignore it
9727 // if they want. (We do the normal layout for INVISIBLE
9728 // windows, since that means "perform layout as normal,
9729 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009730 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9731 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009732 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009733 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009734 win.mContentChanged = false;
9735 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009736 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9737 win.mLayoutSeq = seq;
9738 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9739 + win.mFrame + " mContainingFrame="
9740 + win.mContainingFrame + " mDisplayFrame="
9741 + win.mDisplayFrame);
9742 }
9743 }
9744 }
Jeff Brown349703e2010-06-22 01:27:15 -07009745
9746 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009747 mInputMonitor.setUpdateInputWindowsNeededLw();
9748 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009749 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009750 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009751
9752 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753 }
Romain Guy06882f82009-06-10 13:36:04 -07009754
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009755 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009756 private final void performLayoutAndPlaceSurfacesLockedInner(
9757 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009758 if (mDisplay == null) {
9759 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9760 return;
9761 }
9762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009763 final long currentTime = SystemClock.uptimeMillis();
9764 final int dw = mDisplay.getWidth();
9765 final int dh = mDisplay.getHeight();
9766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 int i;
9768
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009769 if (mFocusMayChange) {
9770 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009771 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9772 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009773 }
9774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 // Initialize state of exiting tokens.
9776 for (i=mExitingTokens.size()-1; i>=0; i--) {
9777 mExitingTokens.get(i).hasVisible = false;
9778 }
9779
9780 // Initialize state of exiting applications.
9781 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9782 mExitingAppTokens.get(i).hasVisible = false;
9783 }
9784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009785 boolean orientationChangeComplete = true;
9786 Session holdScreen = null;
9787 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009788 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009789 boolean focusDisplayed = false;
9790 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009791 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009792 boolean updateRotation = false;
Dianne Hackborn50660e22011-02-02 17:12:25 -08009793 boolean screenRotationFinished = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009794
9795 if (mFxSession == null) {
9796 mFxSession = new SurfaceSession();
9797 createWatermark = true;
9798 }
9799
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009800 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801
9802 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009803
9804 if (createWatermark) {
9805 createWatermark();
9806 }
9807 if (mWatermark != null) {
9808 mWatermark.positionSurface(dw, dh);
9809 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009810 if (mStrictModeFlash != null) {
9811 mStrictModeFlash.positionSurface(dw, dh);
9812 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009814 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009815 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009816 int repeats = 0;
9817 int changes = 0;
9818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009819 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009820 repeats++;
9821 if (repeats > 6) {
9822 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9823 mLayoutNeeded = false;
9824 break;
9825 }
9826
9827 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9828 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9829 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9830 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9831 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9832 assignLayersLocked();
9833 mLayoutNeeded = true;
9834 }
9835 }
9836 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9837 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009838 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009839 mLayoutNeeded = true;
9840 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9841 }
9842 }
9843 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9844 mLayoutNeeded = true;
9845 }
9846 }
9847
9848 // FIRST LOOP: Perform a layout, if needed.
9849 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009850 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009851 if (changes != 0) {
9852 continue;
9853 }
9854 } else {
9855 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9856 changes = 0;
9857 }
9858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859 final int transactionSequence = ++mTransactionSequence;
9860
9861 // Update animations of all applications, including those
9862 // associated with exiting/removed apps
9863 boolean tokensAnimating = false;
9864 final int NAT = mAppTokens.size();
9865 for (i=0; i<NAT; i++) {
9866 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9867 tokensAnimating = true;
9868 }
9869 }
9870 final int NEAT = mExitingAppTokens.size();
9871 for (i=0; i<NEAT; i++) {
9872 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9873 tokensAnimating = true;
9874 }
9875 }
9876
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009877 // SECOND LOOP: Execute animations and update visibility of windows.
9878
Joe Onorato8a9b2202010-02-26 18:56:32 -08009879 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009880 + transactionSequence + " tokensAnimating="
9881 + tokensAnimating);
9882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009884
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009885 if (mScreenRotationAnimation != null) {
9886 if (mScreenRotationAnimation.isAnimating()) {
9887 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9888 animating = true;
9889 } else {
Dianne Hackborn50660e22011-02-02 17:12:25 -08009890 screenRotationFinished = true;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009891 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009892 }
9893 }
9894 }
9895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009897 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009898 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009899 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900
9901 mPolicy.beginAnimationLw(dw, dh);
9902
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009903 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009906 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009907
9908 final WindowManager.LayoutParams attrs = w.mAttrs;
9909
9910 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009911 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009912 if (w.commitFinishDrawingLocked(currentTime)) {
9913 if ((w.mAttrs.flags
9914 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009915 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009916 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009917 wallpaperMayChange = true;
9918 }
9919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009920
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009921 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009922
9923 int animDw = dw;
9924 int animDh = dh;
9925
9926 // If the window has moved due to its containing
9927 // content frame changing, then we'd like to animate
9928 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009929 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009930 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009931 // Frame has moved, containing content frame
9932 // has also moved, and we're not currently animating...
9933 // let's do something.
9934 Animation a = AnimationUtils.loadAnimation(mContext,
9935 com.android.internal.R.anim.window_move_from_decor);
9936 w.setAnimation(a);
9937 animDw = w.mLastFrame.left - w.mFrame.left;
9938 animDh = w.mLastFrame.top - w.mFrame.top;
9939 }
9940
9941 // Execute animation.
9942 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9943 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009944
9945 // If this window is animating, make a note that we have
9946 // an animating window and take care of a request to run
9947 // a detached wallpaper animation.
9948 if (nowAnimating) {
9949 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9950 windowDetachedWallpaper = w;
9951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009952 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009953 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009954
9955 // If this window's app token is running a detached wallpaper
9956 // animation, make a note so we can ensure the wallpaper is
9957 // displayed behind it.
9958 if (w.mAppToken != null && w.mAppToken.animation != null
9959 && w.mAppToken.animation.getDetachWallpaper()) {
9960 windowDetachedWallpaper = w;
9961 }
9962
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009963 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9964 wallpaperMayChange = true;
9965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009966
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009967 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009968 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009969 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009970 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009971 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009972 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009973 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009974 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9975 forceHiding = true;
9976 }
9977 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9978 boolean changed;
9979 if (forceHiding) {
9980 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009981 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9982 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009983 } else {
9984 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009985 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9986 "Now policy shown: " + w);
9987 if (changed) {
9988 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009989 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009990 // Assume we will need to animate. If
9991 // we don't (because the wallpaper will
9992 // stay with the lock screen), then we will
9993 // clean up later.
9994 Animation a = mPolicy.createForceHideEnterAnimation();
9995 if (a != null) {
9996 w.setAnimation(a);
9997 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009998 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009999 if (mCurrentFocus == null ||
10000 mCurrentFocus.mLayer < w.mLayer) {
10001 // We are showing on to of the current
10002 // focus, so re-evaluate focus to make
10003 // sure it is correct.
10004 mFocusMayChange = true;
10005 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010006 }
10007 }
10008 if (changed && (attrs.flags
10009 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
10010 wallpaperMayChange = true;
10011 }
10012 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010014 mPolicy.animatingWindowLw(w, attrs);
10015 }
10016
10017 final AppWindowToken atoken = w.mAppToken;
10018 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
10019 if (atoken.lastTransactionSequence != transactionSequence) {
10020 atoken.lastTransactionSequence = transactionSequence;
10021 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
10022 atoken.startingDisplayed = false;
10023 }
10024 if ((w.isOnScreen() || w.mAttrs.type
10025 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
10026 && !w.mExiting && !w.mDestroying) {
10027 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010028 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010029 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010031 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010032 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 + " pv=" + w.mPolicyVisibility
10034 + " dp=" + w.mDrawPending
10035 + " cdp=" + w.mCommitDrawPending
10036 + " ah=" + w.mAttachedHidden
10037 + " th=" + atoken.hiddenRequested
10038 + " a=" + w.mAnimating);
10039 }
10040 }
10041 if (w != atoken.startingWindow) {
10042 if (!atoken.freezingScreen || !w.mAppFreezing) {
10043 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010044 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010045 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010046 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010047 "tokenMayBeDrawn: " + atoken
10048 + " freezingScreen=" + atoken.freezingScreen
10049 + " mAppFreezing=" + w.mAppFreezing);
10050 tokenMayBeDrawn = true;
10051 }
10052 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010053 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 atoken.startingDisplayed = true;
10055 }
10056 }
10057 } else if (w.mReadyToShow) {
10058 w.performShowLocked();
10059 }
10060 }
10061
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010062 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063
10064 if (tokenMayBeDrawn) {
10065 // See if any windows have been drawn, so they (and others
10066 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010067 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010068 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010069 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010070 if (wtoken.freezingScreen) {
10071 int numInteresting = wtoken.numInterestingWindows;
10072 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010073 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010074 "allDrawn: " + wtoken
10075 + " interesting=" + numInteresting
10076 + " drawn=" + wtoken.numDrawnWindows);
10077 wtoken.showAllWindowsLocked();
10078 unsetAppFreezingScreenLocked(wtoken, false, true);
10079 orientationChangeComplete = true;
10080 }
10081 } else if (!wtoken.allDrawn) {
10082 int numInteresting = wtoken.numInterestingWindows;
10083 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010084 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010085 "allDrawn: " + wtoken
10086 + " interesting=" + numInteresting
10087 + " drawn=" + wtoken.numDrawnWindows);
10088 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010089 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010090
10091 // We can now show all of the drawn windows!
10092 if (!mOpeningApps.contains(wtoken)) {
10093 wtoken.showAllWindowsLocked();
10094 }
10095 }
10096 }
10097 }
10098 }
10099
10100 // If we are ready to perform an app transition, check through
10101 // all of the app tokens to be shown and see if they are ready
10102 // to go.
10103 if (mAppTransitionReady) {
10104 int NN = mOpeningApps.size();
10105 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010106 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010107 "Checking " + NN + " opening apps (frozen="
10108 + mDisplayFrozen + " timeout="
10109 + mAppTransitionTimeout + ")...");
10110 if (!mDisplayFrozen && !mAppTransitionTimeout) {
10111 // If the display isn't frozen, wait to do anything until
10112 // all of the apps are ready. Otherwise just go because
10113 // we'll unfreeze the display when everyone is ready.
10114 for (i=0; i<NN && goodToGo; i++) {
10115 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010116 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 "Check opening app" + wtoken + ": allDrawn="
10118 + wtoken.allDrawn + " startingDisplayed="
10119 + wtoken.startingDisplayed);
10120 if (!wtoken.allDrawn && !wtoken.startingDisplayed
10121 && !wtoken.startingMoved) {
10122 goodToGo = false;
10123 }
10124 }
10125 }
10126 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010127 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010128 int transit = mNextAppTransition;
10129 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010130 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010131 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010132 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010133 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010134 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010135 mAppTransitionTimeout = false;
10136 mStartingIconInTransition = false;
10137 mSkipAppTransitionAnimation = false;
10138
10139 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
10140
Dianne Hackborna8f60182009-09-01 19:01:50 -070010141 // If there are applications waiting to come to the
10142 // top of the stack, now is the time to move their windows.
10143 // (Note that we don't do apps going to the bottom
10144 // here -- we want to keep their windows in the old
10145 // Z-order until the animation completes.)
10146 if (mToTopApps.size() > 0) {
10147 NN = mAppTokens.size();
10148 for (i=0; i<NN; i++) {
10149 AppWindowToken wtoken = mAppTokens.get(i);
10150 if (wtoken.sendingToTop) {
10151 wtoken.sendingToTop = false;
10152 moveAppWindowsLocked(wtoken, NN, false);
10153 }
10154 }
10155 mToTopApps.clear();
10156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010157
Dianne Hackborn25994b42009-09-04 14:21:19 -070010158 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010159
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010160 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010161 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010162
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010163 // The top-most window will supply the layout params,
10164 // and we will determine it below.
10165 LayoutParams animLp = null;
10166 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010167 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010168
Joe Onorato8a9b2202010-02-26 18:56:32 -080010169 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010170 "New wallpaper target=" + mWallpaperTarget
10171 + ", lower target=" + mLowerWallpaperTarget
10172 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010173 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010174 // Do a first pass through the tokens for two
10175 // things:
10176 // (1) Determine if both the closing and opening
10177 // app token sets are wallpaper targets, in which
10178 // case special animations are needed
10179 // (since the wallpaper needs to stay static
10180 // behind them).
10181 // (2) Find the layout params of the top-most
10182 // application window in the tokens, which is
10183 // what will control the animation theme.
10184 final int NC = mClosingApps.size();
10185 NN = NC + mOpeningApps.size();
10186 for (i=0; i<NN; i++) {
10187 AppWindowToken wtoken;
10188 int mode;
10189 if (i < NC) {
10190 wtoken = mClosingApps.get(i);
10191 mode = 1;
10192 } else {
10193 wtoken = mOpeningApps.get(i-NC);
10194 mode = 2;
10195 }
10196 if (mLowerWallpaperTarget != null) {
10197 if (mLowerWallpaperTarget.mAppToken == wtoken
10198 || mUpperWallpaperTarget.mAppToken == wtoken) {
10199 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010200 }
10201 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010202 if (wtoken.appFullscreen) {
10203 WindowState ws = wtoken.findMainWindow();
10204 if (ws != null) {
10205 // If this is a compatibility mode
10206 // window, we will always use its anim.
10207 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10208 animLp = ws.mAttrs;
10209 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010210 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010211 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010212 bestAnimLayer = ws.mLayer;
10213 }
10214 fullscreenAnim = true;
10215 }
10216 } else if (!fullscreenAnim) {
10217 WindowState ws = wtoken.findMainWindow();
10218 if (ws != null) {
10219 if (ws.mLayer > bestAnimLayer) {
10220 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010221 bestAnimLayer = ws.mLayer;
10222 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010223 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010224 }
10225 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010226
Dianne Hackborn25994b42009-09-04 14:21:19 -070010227 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010228 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010229 "Wallpaper animation!");
10230 switch (transit) {
10231 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10232 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10233 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10234 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10235 break;
10236 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10237 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10238 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10239 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10240 break;
10241 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010242 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010243 "New transit: " + transit);
10244 } else if (oldWallpaper != null) {
10245 // We are transitioning from an activity with
10246 // a wallpaper to one without.
10247 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010248 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010249 "New transit away from wallpaper: " + transit);
10250 } else if (mWallpaperTarget != null) {
10251 // We are transitioning from an activity without
10252 // a wallpaper to now showing the wallpaper
10253 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010254 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010255 "New transit into wallpaper: " + transit);
10256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010257
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010258 // If all closing windows are obscured, then there is
10259 // no need to do an animation. This is the case, for
10260 // example, when this transition is being done behind
10261 // the lock screen.
10262 if (!mPolicy.allowAppAnimationsLw()) {
10263 animLp = null;
10264 }
10265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 NN = mOpeningApps.size();
10267 for (i=0; i<NN; i++) {
10268 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010269 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010270 "Now opening app" + wtoken);
10271 wtoken.reportedVisible = false;
10272 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010273 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010274 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010275 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010276 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 wtoken.showAllWindowsLocked();
10278 }
10279 NN = mClosingApps.size();
10280 for (i=0; i<NN; i++) {
10281 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010282 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283 "Now closing app" + wtoken);
10284 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010285 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010286 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010287 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010288 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 // Force the allDrawn flag, because we want to start
10290 // this guy's animations regardless of whether it's
10291 // gotten drawn.
10292 wtoken.allDrawn = true;
10293 }
10294
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010295 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 mOpeningApps.clear();
10298 mClosingApps.clear();
10299
10300 // This has changed the visibility of windows, so perform
10301 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010302 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10303 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010305 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10306 assignLayersLocked();
10307 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010308 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10309 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010310 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 }
10312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010313
Dianne Hackborn16064f92010-03-25 00:47:24 -070010314 int adjResult = 0;
10315
Dianne Hackborna8f60182009-09-01 19:01:50 -070010316 if (!animating && mAppTransitionRunning) {
10317 // We have finished the animation of an app transition. To do
10318 // this, we have delayed a lot of operations like showing and
10319 // hiding apps, moving apps in Z-order, etc. The app token list
10320 // reflects the correct Z-order, but the window list may now
10321 // be out of sync with it. So here we will just rebuild the
10322 // entire app window list. Fun!
10323 mAppTransitionRunning = false;
10324 // Clear information about apps that were moving.
10325 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010326
Dianne Hackborna8f60182009-09-01 19:01:50 -070010327 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010328 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010329 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010330 moveInputMethodWindowsIfNeededLocked(false);
10331 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010332 // Since the window list has been rebuilt, focus might
10333 // have to be recomputed since the actual order of windows
10334 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010335 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010336 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010337
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010338 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010339 // At this point, there was a window with a wallpaper that
10340 // was force hiding other windows behind it, but now it
10341 // is going away. This may be simple -- just animate
10342 // away the wallpaper and its window -- or it may be
10343 // hard -- the wallpaper now needs to be shown behind
10344 // something that was hidden.
10345 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010346 if (mLowerWallpaperTarget != null
10347 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010348 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010349 "wallpaperForceHiding changed with lower="
10350 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010351 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010352 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10353 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10354 if (mLowerWallpaperTarget.mAppToken.hidden) {
10355 // The lower target has become hidden before we
10356 // actually started the animation... let's completely
10357 // re-evaluate everything.
10358 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010359 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010360 }
10361 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010362 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010363 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010364 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010365 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010366 + " NEW: " + mWallpaperTarget
10367 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010368 if (mLowerWallpaperTarget == null) {
10369 // Whoops, we don't need a special wallpaper animation.
10370 // Clear them out.
10371 forceHiding = false;
10372 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010373 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010374 if (w.mSurface != null) {
10375 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010376 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010377 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010378 forceHiding = true;
10379 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10380 if (!w.mAnimating) {
10381 // We set the animation above so it
10382 // is not yet running.
10383 w.clearAnimation();
10384 }
10385 }
10386 }
10387 }
10388 }
10389 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010390
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010391 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10392 if (DEBUG_WALLPAPER) Slog.v(TAG,
10393 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10394 + windowDetachedWallpaper);
10395 mWindowDetachedWallpaper = windowDetachedWallpaper;
10396 wallpaperMayChange = true;
10397 }
10398
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010399 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010400 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010401 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010402 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010404
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010405 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010406 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010407 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010408 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010409 assignLayersLocked();
10410 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010411 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010412 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010413 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010414 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010415
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010416 if (mFocusMayChange) {
10417 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010418 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10419 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010420 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010421 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010422 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010423 }
10424
10425 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010426 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010427 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010428
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010429 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10430 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010431 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432
10433 // THIRD LOOP: Update the surfaces of all windows.
10434
10435 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10436
10437 boolean obscured = false;
10438 boolean blurring = false;
10439 boolean dimming = false;
10440 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010441 boolean syswin = false;
Dianne Hackbornac1471a2011-02-03 13:46:06 -080010442 boolean backgroundFillerWasShown = mBackgroundFillerTarget != null;
10443 mBackgroundFillerTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010444
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010445 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010447 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010448 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010449
10450 boolean displayed = false;
10451 final WindowManager.LayoutParams attrs = w.mAttrs;
10452 final int attrFlags = attrs.flags;
10453
10454 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010455 // XXX NOTE: The logic here could be improved. We have
10456 // the decision about whether to resize a window separated
10457 // from whether to hide the surface. This can cause us to
10458 // resize a surface even if we are going to hide it. You
10459 // can see this by (1) holding device in landscape mode on
10460 // home screen; (2) tapping browser icon (device will rotate
10461 // to landscape; (3) tap home. The wallpaper will be resized
10462 // in step 2 but then immediately hidden, causing us to
10463 // have to resize and then redraw it again in step 3. It
10464 // would be nice to figure out how to avoid this, but it is
10465 // difficult because we do need to resize surfaces in some
10466 // cases while they are hidden such as when first showing a
10467 // window.
10468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010469 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010470 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010471 TAG, "Placing surface #" + i + " " + w.mSurface
10472 + ": new=" + w.mShownFrame + ", old="
10473 + w.mLastShownFrame);
10474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 int width, height;
10476 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 // for a scaled surface, we just want to use
10478 // the requested size.
10479 width = w.mRequestedWidth;
10480 height = w.mRequestedHeight;
10481 w.mLastRequestedWidth = width;
10482 w.mLastRequestedHeight = height;
10483 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010484 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010485 width = w.mShownFrame.width();
10486 height = w.mShownFrame.height();
10487 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010488 }
10489
Jeff Brownfbae7222011-01-23 13:07:25 -080010490 if (w.mSurface != null) {
10491 if (w.mSurfaceX != w.mShownFrame.left
10492 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010494 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010495 "POS " + w.mShownFrame.left
10496 + ", " + w.mShownFrame.top, null);
10497 w.mSurfaceX = w.mShownFrame.left;
10498 w.mSurfaceY = w.mShownFrame.top;
10499 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10500 } catch (RuntimeException e) {
10501 Slog.w(TAG, "Error positioning surface of " + w
10502 + " pos=(" + w.mShownFrame.left
10503 + "," + w.mShownFrame.top + ")", e);
10504 if (!recoveringMemory) {
10505 reclaimSomeSurfaceMemoryLocked(w, "position");
10506 }
10507 }
10508 }
10509
10510 if (width < 1) {
10511 width = 1;
10512 }
10513 if (height < 1) {
10514 height = 1;
10515 }
10516
10517 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10518 try {
10519 if (SHOW_TRANSACTIONS) logSurface(w,
10520 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010521 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010522 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010523 w.mSurfaceW = width;
10524 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010526 } catch (RuntimeException e) {
10527 // If something goes wrong with the surface (such
10528 // as running out of memory), don't take down the
10529 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010530 Slog.e(TAG, "Error resizing surface of " + w
10531 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 if (!recoveringMemory) {
10533 reclaimSomeSurfaceMemoryLocked(w, "size");
10534 }
10535 }
10536 }
10537 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010538
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010539 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010540 w.mContentInsetsChanged =
10541 !w.mLastContentInsets.equals(w.mContentInsets);
10542 w.mVisibleInsetsChanged =
10543 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010544 boolean configChanged =
10545 w.mConfiguration != mCurConfiguration
10546 && (w.mConfiguration == null
10547 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010548 if (DEBUG_CONFIGURATION && configChanged) {
10549 Slog.v(TAG, "Win " + w + " config changed: "
10550 + mCurConfiguration);
10551 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010552 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010553 + ": configChanged=" + configChanged
10554 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010555 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10556 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010557 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010558 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010559 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010560 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010561 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10562 Slog.v(TAG, "Resize reasons: "
10563 + "frameChanged=" + frameChanged
10564 + " contentInsetsChanged=" + w.mContentInsetsChanged
10565 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10566 + " surfaceResized=" + w.mSurfaceResized
10567 + " configChanged=" + configChanged);
10568 }
10569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010570 w.mLastFrame.set(w.mFrame);
10571 w.mLastContentInsets.set(w.mContentInsets);
10572 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010573 // If the screen is currently frozen, then keep
10574 // it frozen until this window draws at its new
10575 // orientation.
10576 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010577 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010578 "Resizing while display frozen: " + w);
10579 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010580 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010581 mWindowsFreezingScreen = true;
10582 // XXX should probably keep timeout from
10583 // when we first froze the display.
10584 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10585 mH.sendMessageDelayed(mH.obtainMessage(
10586 H.WINDOW_FREEZE_TIMEOUT), 2000);
10587 }
10588 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010589 // If the orientation is changing, then we need to
10590 // hold off on unfreezing the display until this
10591 // window has been redrawn; to do that, we need
10592 // to go through the process of getting informed
10593 // by the application when it has finished drawing.
10594 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010595 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010596 "Orientation start waiting for draw in "
10597 + w + ", surface " + w.mSurface);
10598 w.mDrawPending = true;
10599 w.mCommitDrawPending = false;
10600 w.mReadyToShow = false;
10601 if (w.mAppToken != null) {
10602 w.mAppToken.allDrawn = false;
10603 }
10604 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010605 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010606 "Resizing window " + w + " to " + w.mFrame);
10607 mResizingWindows.add(w);
10608 } else if (w.mOrientationChanging) {
10609 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010610 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 "Orientation not waiting for draw in "
10612 + w + ", surface " + w.mSurface);
10613 w.mOrientationChanging = false;
10614 }
10615 }
10616 }
10617
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010618 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010619 if (!w.mLastHidden) {
10620 //dump();
10621 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010622 if (SHOW_TRANSACTIONS) logSurface(w,
10623 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010624 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010625 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010626 try {
10627 w.mSurface.hide();
10628 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010629 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010630 }
10631 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 }
10633 // If we are waiting for this window to handle an
10634 // orientation change, well, it is hidden, so
10635 // doesn't really matter. Note that this does
10636 // introduce a potential glitch if the window
10637 // becomes unhidden before it has drawn for the
10638 // new orientation.
10639 if (w.mOrientationChanging) {
10640 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010641 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010642 "Orientation change skips hidden " + w);
10643 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010644 } else if (w.mLastLayer != w.mAnimLayer
10645 || w.mLastAlpha != w.mShownAlpha
10646 || w.mLastDsDx != w.mDsDx
10647 || w.mLastDtDx != w.mDtDx
10648 || w.mLastDsDy != w.mDsDy
10649 || w.mLastDtDy != w.mDtDy
10650 || w.mLastHScale != w.mHScale
10651 || w.mLastVScale != w.mVScale
10652 || w.mLastHidden) {
10653 displayed = true;
10654 w.mLastAlpha = w.mShownAlpha;
10655 w.mLastLayer = w.mAnimLayer;
10656 w.mLastDsDx = w.mDsDx;
10657 w.mLastDtDx = w.mDtDx;
10658 w.mLastDsDy = w.mDsDy;
10659 w.mLastDtDy = w.mDtDy;
10660 w.mLastHScale = w.mHScale;
10661 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010662 if (SHOW_TRANSACTIONS) logSurface(w,
10663 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010664 + " matrix=[" + (w.mDsDx*w.mHScale)
10665 + "," + (w.mDtDx*w.mVScale)
10666 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010667 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010668 if (w.mSurface != null) {
10669 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010670 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010671 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010672 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010673 w.mSurface.setLayer(w.mAnimLayer);
10674 w.mSurface.setMatrix(
10675 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10676 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10677 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010678 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010679 if (!recoveringMemory) {
10680 reclaimSomeSurfaceMemoryLocked(w, "update");
10681 }
10682 }
10683 }
10684
10685 if (w.mLastHidden && !w.mDrawPending
10686 && !w.mCommitDrawPending
10687 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010688 if (SHOW_TRANSACTIONS) logSurface(w,
10689 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010690 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010691 + " during relayout");
10692 if (showSurfaceRobustlyLocked(w)) {
10693 w.mHasDrawn = true;
10694 w.mLastHidden = false;
10695 } else {
10696 w.mOrientationChanging = false;
10697 }
10698 }
10699 if (w.mSurface != null) {
10700 w.mToken.hasVisible = true;
10701 }
10702 } else {
10703 displayed = true;
10704 }
10705
10706 if (displayed) {
10707 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010708 if (attrs.width == LayoutParams.MATCH_PARENT
10709 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010710 covered = true;
10711 }
10712 }
10713 if (w.mOrientationChanging) {
10714 if (w.mDrawPending || w.mCommitDrawPending) {
10715 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010716 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010717 "Orientation continue waiting for draw in " + w);
10718 } else {
10719 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010720 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010721 "Orientation change complete in " + w);
10722 }
10723 }
10724 w.mToken.hasVisible = true;
10725 }
10726 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010727 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010728 "Orientation change skips hidden " + w);
10729 w.mOrientationChanging = false;
10730 }
10731
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010732 if (w.mContentChanged) {
10733 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10734 w.mContentChanged = false;
10735 }
10736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010737 final boolean canBeSeen = w.isDisplayedLw();
10738
10739 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10740 focusDisplayed = true;
10741 }
10742
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010743 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010744
Dianne Hackbornac1471a2011-02-03 13:46:06 -080010745 if (mBackgroundFillerTarget != null) {
10746 if (w.isAnimating()) {
10747 // Background filler is below all other windows that
10748 // are animating.
10749 mBackgroundFillerTarget = w;
10750 } else if (w.mIsWallpaper) {
10751 mBackgroundFillerTarget = w;
10752 }
10753 }
10754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010755 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010756 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010757 if (w.mSurface != null) {
10758 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10759 holdScreen = w.mSession;
10760 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010761 if (!syswin && w.mAttrs.screenBrightness >= 0
10762 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010763 screenBrightness = w.mAttrs.screenBrightness;
10764 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010765 if (!syswin && w.mAttrs.buttonBrightness >= 0
10766 && buttonBrightness < 0) {
10767 buttonBrightness = w.mAttrs.buttonBrightness;
10768 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010769 if (canBeSeen
10770 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10771 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10772 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010773 syswin = true;
10774 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010775 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010776
Dianne Hackborn25994b42009-09-04 14:21:19 -070010777 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10778 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 // This window completely covers everything behind it,
10780 // so we want to leave all of them as unblurred (for
10781 // performance reasons).
10782 obscured = true;
Dianne Hackbornac1471a2011-02-03 13:46:06 -080010783 } else if (w.needsBackgroundFiller(dw, dh) && (canBeSeen || w.isAnimating())) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010784 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010785 obscured = true;
Dianne Hackbornac1471a2011-02-03 13:46:06 -080010786 mBackgroundFillerTarget = w;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010787 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010788 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010789 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010790 + ": blurring=" + blurring
10791 + " obscured=" + obscured
10792 + " displayed=" + displayed);
10793 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10794 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010795 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010797 if (mDimAnimator == null) {
10798 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010799 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010800 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010801 mDimAnimator.updateParameters(mContext.getResources(),
10802 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010803 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010804 }
10805 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10806 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010807 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010808 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010809 if (mBlurSurface == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 try {
Romain Guy06882f82009-06-10 13:36:04 -070010811 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010812 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010813 -1, 16, 16,
10814 PixelFormat.OPAQUE,
10815 Surface.FX_SURFACE_BLUR);
10816 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010817 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010818 }
Dianne Hackbornac1471a2011-02-03 13:46:06 -080010819 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10820 + mBlurSurface + ": CREATE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010821 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010822 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010823 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10824 + mBlurSurface + ": pos=(0,0) (" +
10825 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010826 mBlurSurface.setPosition(0, 0);
10827 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010828 mBlurSurface.setLayer(w.mAnimLayer-2);
10829 if (!mBlurShown) {
10830 try {
10831 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10832 + mBlurSurface + ": SHOW");
10833 mBlurSurface.show();
10834 } catch (RuntimeException e) {
10835 Slog.w(TAG, "Failure showing blur surface", e);
10836 }
10837 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010838 }
10839 }
10840 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010841 }
10842 }
10843 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010844
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010845 if (obscuredChanged && mWallpaperTarget == w) {
10846 // This is the wallpaper target and its obscured state
10847 // changed... make sure the current wallaper's visibility
10848 // has been updated accordingly.
10849 updateWallpaperVisibilityLocked();
10850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010851 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010852
Dianne Hackbornac1471a2011-02-03 13:46:06 -080010853 if (mBackgroundFillerTarget != null) {
10854 if (mBackgroundFillerSurface == null) {
10855 try {
10856 mBackgroundFillerSurface = new Surface(mFxSession, 0,
10857 "BackGroundFiller",
10858 0, dw, dh,
10859 PixelFormat.OPAQUE,
10860 Surface.FX_SURFACE_NORMAL);
10861 } catch (Exception e) {
10862 Slog.e(TAG, "Exception creating filler surface", e);
10863 }
10864 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
10865 + mBackgroundFillerSurface + ": CREATE");
10866 }
10867 try {
10868 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
10869 + mBackgroundFillerSurface + " SHOW: pos=(0,0) ("
10870 + dw + "x" + dh + ") layer="
10871 + (mBackgroundFillerTarget.mLayer - 1));
10872 mBackgroundFillerSurface.setPosition(0, 0);
10873 mBackgroundFillerSurface.setSize(dw, dh);
10874 // Using the same layer as Dim because they will never be shown at the
10875 // same time. NOTE: we do NOT use mAnimLayer, because we don't
10876 // want this surface dragged up in front of stuff that is animating.
10877 mBackgroundFillerSurface.setLayer(mBackgroundFillerTarget.mLayer - 1);
10878 mBackgroundFillerSurface.show();
10879 } catch (RuntimeException e) {
10880 Slog.e(TAG, "Exception showing filler surface");
10881 }
10882 } else if (backgroundFillerWasShown) {
10883 mBackgroundFillerTarget = null;
10884 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER "
10885 + mBackgroundFillerSurface + " HIDE");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010886 try {
10887 mBackgroundFillerSurface.hide();
10888 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010889 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010890 }
10891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010892
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010893 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010894 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10895 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010896 }
Romain Guy06882f82009-06-10 13:36:04 -070010897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010899 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010900 + ": HIDE");
10901 try {
10902 mBlurSurface.hide();
10903 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010904 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010905 }
10906 mBlurShown = false;
10907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010908 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010909 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010910 }
10911
10912 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010913
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010914 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10915
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010916 if (mWatermark != null) {
10917 mWatermark.drawIfNeeded();
10918 }
10919
Joe Onorato8a9b2202010-02-26 18:56:32 -080010920 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010921 "With display frozen, orientationChangeComplete="
10922 + orientationChangeComplete);
10923 if (orientationChangeComplete) {
10924 if (mWindowsFreezingScreen) {
10925 mWindowsFreezingScreen = false;
10926 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10927 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010928 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010929 }
Romain Guy06882f82009-06-10 13:36:04 -070010930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010931 i = mResizingWindows.size();
10932 if (i > 0) {
10933 do {
10934 i--;
10935 WindowState win = mResizingWindows.get(i);
10936 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010937 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10938 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010939 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010940 boolean configChanged =
10941 win.mConfiguration != mCurConfiguration
10942 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010943 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10944 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10945 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010946 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010947 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010948 + " / " + mCurConfiguration + " / 0x"
10949 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010950 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010951 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010952 win.mClient.resized(win.mFrame.width(),
10953 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010954 win.mLastVisibleInsets, win.mDrawPending,
10955 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010956 win.mContentInsetsChanged = false;
10957 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010958 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010959 } catch (RemoteException e) {
10960 win.mOrientationChanging = false;
10961 }
10962 } while (i > 0);
10963 mResizingWindows.clear();
10964 }
Romain Guy06882f82009-06-10 13:36:04 -070010965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010966 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010967 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010968 i = mDestroySurface.size();
10969 if (i > 0) {
10970 do {
10971 i--;
10972 WindowState win = mDestroySurface.get(i);
10973 win.mDestroying = false;
10974 if (mInputMethodWindow == win) {
10975 mInputMethodWindow = null;
10976 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010977 if (win == mWallpaperTarget) {
10978 wallpaperDestroyed = true;
10979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 win.destroySurfaceLocked();
10981 } while (i > 0);
10982 mDestroySurface.clear();
10983 }
10984
10985 // Time to remove any exiting tokens?
10986 for (i=mExitingTokens.size()-1; i>=0; i--) {
10987 WindowToken token = mExitingTokens.get(i);
10988 if (!token.hasVisible) {
10989 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010990 if (token.windowType == TYPE_WALLPAPER) {
10991 mWallpaperTokens.remove(token);
10992 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010993 }
10994 }
10995
10996 // Time to remove any exiting applications?
10997 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10998 AppWindowToken token = mExitingAppTokens.get(i);
10999 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070011000 // Make sure there is no animation running on this token,
11001 // so any windows associated with it will be removed as
11002 // soon as their animations are complete
11003 token.animation = null;
11004 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011005 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
11006 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 mAppTokens.remove(token);
11008 mExitingAppTokens.remove(i);
11009 }
11010 }
11011
Dianne Hackborna8f60182009-09-01 19:01:50 -070011012 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011013
Dianne Hackborna8f60182009-09-01 19:01:50 -070011014 if (!animating && mAppTransitionRunning) {
11015 // We have finished the animation of an app transition. To do
11016 // this, we have delayed a lot of operations like showing and
11017 // hiding apps, moving apps in Z-order, etc. The app token list
11018 // reflects the correct Z-order, but the window list may now
11019 // be out of sync with it. So here we will just rebuild the
11020 // entire app window list. Fun!
11021 mAppTransitionRunning = false;
11022 needRelayout = true;
11023 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011024 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070011025 // Clear information about apps that were moving.
11026 mToBottomApps.clear();
11027 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011029 if (focusDisplayed) {
11030 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
11031 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011032 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011033 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011034 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011035 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011036 requestAnimationLocked(0);
11037 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011038 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
11039 }
Jeff Browneb857f12010-07-16 10:06:33 -070011040
Jeff Brown3a22cd92011-01-21 13:59:04 -080011041 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080011042 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070011043
Jeff Brown8e03b752010-06-13 19:16:55 -070011044 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080011045 if (!mDisplayFrozen) {
11046 if (screenBrightness < 0 || screenBrightness > 1.0f) {
11047 mPowerManager.setScreenBrightnessOverride(-1);
11048 } else {
11049 mPowerManager.setScreenBrightnessOverride((int)
11050 (screenBrightness * Power.BRIGHTNESS_ON));
11051 }
11052 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
11053 mPowerManager.setButtonBrightnessOverride(-1);
11054 } else {
11055 mPowerManager.setButtonBrightnessOverride((int)
11056 (buttonBrightness * Power.BRIGHTNESS_ON));
11057 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050011058 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011059 if (holdScreen != mHoldingScreenOn) {
11060 mHoldingScreenOn = holdScreen;
11061 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
11062 mH.sendMessage(m);
11063 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011064
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011065 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011066 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011067 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
11068 LocalPowerManager.BUTTON_EVENT, true);
11069 mTurnOnScreen = false;
11070 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011071
Dianne Hackborn50660e22011-02-02 17:12:25 -080011072 if (screenRotationFinished && mScreenRotationAnimation != null) {
11073 mScreenRotationAnimation.kill();
11074 mScreenRotationAnimation = null;
11075 }
11076
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011077 if (updateRotation) {
11078 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11079 boolean changed = setRotationUncheckedLocked(
11080 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11081 if (changed) {
Dianne Hackborn3e4f9d042011-02-04 14:05:55 -080011082 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011083 }
11084 }
11085
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011086 // Check to see if we are now in a state where the screen should
11087 // be enabled, because the window obscured flags have changed.
11088 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011089 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070011090
11091 /**
11092 * Must be called with the main window manager lock held.
11093 */
11094 void setHoldScreenLocked(boolean holding) {
11095 boolean state = mHoldingScreenWakeLock.isHeld();
11096 if (holding != state) {
11097 if (holding) {
11098 mHoldingScreenWakeLock.acquire();
11099 } else {
11100 mPolicy.screenOnStoppedLw();
11101 mHoldingScreenWakeLock.release();
11102 }
11103 }
11104 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011105
11106 void requestAnimationLocked(long delay) {
11107 if (!mAnimationPending) {
11108 mAnimationPending = true;
11109 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
11110 }
11111 }
Romain Guy06882f82009-06-10 13:36:04 -070011112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011113 /**
11114 * Have the surface flinger show a surface, robustly dealing with
11115 * error conditions. In particular, if there is not enough memory
11116 * to show the surface, then we will try to get rid of other surfaces
11117 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070011118 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011119 * @return Returns true if the surface was successfully shown.
11120 */
11121 boolean showSurfaceRobustlyLocked(WindowState win) {
11122 try {
11123 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011124 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011125 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011126 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011127 if (DEBUG_VISIBILITY) Slog.v(TAG,
11128 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011129 win.mTurnOnScreen = false;
11130 mTurnOnScreen = true;
11131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011132 }
11133 return true;
11134 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011135 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011136 }
Romain Guy06882f82009-06-10 13:36:04 -070011137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011138 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070011139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011140 return false;
11141 }
Romain Guy06882f82009-06-10 13:36:04 -070011142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011143 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
11144 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070011145
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011146 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011147 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070011148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011149 if (mForceRemoves == null) {
11150 mForceRemoves = new ArrayList<WindowState>();
11151 }
Romain Guy06882f82009-06-10 13:36:04 -070011152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011153 long callingIdentity = Binder.clearCallingIdentity();
11154 try {
11155 // There was some problem... first, do a sanity check of the
11156 // window list to make sure we haven't left any dangling surfaces
11157 // around.
11158 int N = mWindows.size();
11159 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011160 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011161 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011162 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011163 if (ws.mSurface != null) {
11164 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011165 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011166 + ws + " surface=" + ws.mSurface
11167 + " token=" + win.mToken
11168 + " pid=" + ws.mSession.mPid
11169 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011170 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011171 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011172 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011173 ws.mSurface = null;
11174 mForceRemoves.add(ws);
11175 i--;
11176 N--;
11177 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011178 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011179 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011180 + ws + " surface=" + ws.mSurface
11181 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011182 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011183 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011184 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011185 ws.mSurface = null;
11186 leakedSurface = true;
11187 }
11188 }
11189 }
Romain Guy06882f82009-06-10 13:36:04 -070011190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011191 boolean killedApps = false;
11192 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011193 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011194 SparseIntArray pidCandidates = new SparseIntArray();
11195 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011196 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011197 if (ws.mSurface != null) {
11198 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11199 }
11200 }
11201 if (pidCandidates.size() > 0) {
11202 int[] pids = new int[pidCandidates.size()];
11203 for (int i=0; i<pids.length; i++) {
11204 pids[i] = pidCandidates.keyAt(i);
11205 }
11206 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011207 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011208 killedApps = true;
11209 }
11210 } catch (RemoteException e) {
11211 }
11212 }
11213 }
Romain Guy06882f82009-06-10 13:36:04 -070011214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011215 if (leakedSurface || killedApps) {
11216 // We managed to reclaim some memory, so get rid of the trouble
11217 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011218 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011219 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011220 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011221 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011222 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011223 win.mSurface = null;
11224 }
Romain Guy06882f82009-06-10 13:36:04 -070011225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011226 try {
11227 win.mClient.dispatchGetNewSurface();
11228 } catch (RemoteException e) {
11229 }
11230 }
11231 } finally {
11232 Binder.restoreCallingIdentity(callingIdentity);
11233 }
11234 }
Romain Guy06882f82009-06-10 13:36:04 -070011235
Jeff Brown3a22cd92011-01-21 13:59:04 -080011236 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011237 WindowState newFocus = computeFocusedWindowLocked();
11238 if (mCurrentFocus != newFocus) {
11239 // This check makes sure that we don't already have the focus
11240 // change message pending.
11241 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11242 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011243 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011244 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11245 final WindowState oldFocus = mCurrentFocus;
11246 mCurrentFocus = newFocus;
11247 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011249 final WindowState imWindow = mInputMethodWindow;
11250 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011251 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011252 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011253 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11254 mLayoutNeeded = true;
11255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011256 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011257 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011258 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11259 // Client will do the layout, but we need to assign layers
11260 // for handleNewWindowLocked() below.
11261 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011262 }
11263 }
Jeff Brown349703e2010-06-22 01:27:15 -070011264
11265 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11266 // If we defer assigning layers, then the caller is responsible for
11267 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011268 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011270 return true;
11271 }
11272 return false;
11273 }
Jeff Brown349703e2010-06-22 01:27:15 -070011274
Jeff Brown3a22cd92011-01-21 13:59:04 -080011275 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11276 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011278
11279 private WindowState computeFocusedWindowLocked() {
11280 WindowState result = null;
11281 WindowState win;
11282
11283 int i = mWindows.size() - 1;
11284 int nextAppIndex = mAppTokens.size()-1;
11285 WindowToken nextApp = nextAppIndex >= 0
11286 ? mAppTokens.get(nextAppIndex) : null;
11287
11288 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011289 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011290
Joe Onorato8a9b2202010-02-26 18:56:32 -080011291 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011292 TAG, "Looking for focus: " + i
11293 + " = " + win
11294 + ", flags=" + win.mAttrs.flags
11295 + ", canReceive=" + win.canReceiveKeys());
11296
11297 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011299 // If this window's application has been removed, just skip it.
11300 if (thisApp != null && thisApp.removed) {
11301 i--;
11302 continue;
11303 }
Romain Guy06882f82009-06-10 13:36:04 -070011304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011305 // If there is a focused app, don't allow focus to go to any
11306 // windows below it. If this is an application window, step
11307 // through the app tokens until we find its app.
11308 if (thisApp != null && nextApp != null && thisApp != nextApp
11309 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11310 int origAppIndex = nextAppIndex;
11311 while (nextAppIndex > 0) {
11312 if (nextApp == mFocusedApp) {
11313 // Whoops, we are below the focused app... no focus
11314 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011315 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011316 TAG, "Reached focused app: " + mFocusedApp);
11317 return null;
11318 }
11319 nextAppIndex--;
11320 nextApp = mAppTokens.get(nextAppIndex);
11321 if (nextApp == thisApp) {
11322 break;
11323 }
11324 }
11325 if (thisApp != nextApp) {
11326 // Uh oh, the app token doesn't exist! This shouldn't
11327 // happen, but if it does we can get totally hosed...
11328 // so restart at the original app.
11329 nextAppIndex = origAppIndex;
11330 nextApp = mAppTokens.get(nextAppIndex);
11331 }
11332 }
11333
11334 // Dispatch to this window if it is wants key events.
11335 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011336 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011337 TAG, "Found focus @ " + i + " = " + win);
11338 result = win;
11339 break;
11340 }
11341
11342 i--;
11343 }
11344
11345 return result;
11346 }
11347
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011348 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011349 if (mDisplayFrozen) {
11350 return;
11351 }
Romain Guy06882f82009-06-10 13:36:04 -070011352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011353 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011355 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011356 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011357 if (mFreezeGcPending != 0) {
11358 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011359 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011360 mH.removeMessages(H.FORCE_GC);
11361 Runtime.getRuntime().gc();
11362 mFreezeGcPending = now;
11363 }
11364 } else {
11365 mFreezeGcPending = now;
11366 }
Romain Guy06882f82009-06-10 13:36:04 -070011367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011368 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011369
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011370 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011371
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011372 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11373 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011374 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011375 mAppTransitionReady = true;
11376 }
Romain Guy06882f82009-06-10 13:36:04 -070011377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011378 if (PROFILE_ORIENTATION) {
11379 File file = new File("/data/system/frozen");
11380 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11381 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011382
11383 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011384 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11385 mScreenRotationAnimation.kill();
11386 mScreenRotationAnimation = null;
11387 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011388 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011389 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011390 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011391 }
11392 } else {
11393 Surface.freezeDisplay(0);
11394 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011395 }
Romain Guy06882f82009-06-10 13:36:04 -070011396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011397 private void stopFreezingDisplayLocked() {
11398 if (!mDisplayFrozen) {
11399 return;
11400 }
Romain Guy06882f82009-06-10 13:36:04 -070011401
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011402 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11403 return;
11404 }
11405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011406 mDisplayFrozen = false;
11407 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11408 if (PROFILE_ORIENTATION) {
11409 Debug.stopMethodTracing();
11410 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011411
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011412 boolean updateRotation = false;
11413
Dianne Hackborna1111872010-11-23 20:55:11 -080011414 if (CUSTOM_SCREEN_ROTATION) {
11415 if (mScreenRotationAnimation != null) {
Dianne Hackborn50660e22011-02-02 17:12:25 -080011416 if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011417 mTransitionAnimationScale)) {
11418 requestAnimationLocked(0);
11419 } else {
11420 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011421 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011422 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011423 }
11424 } else {
11425 Surface.unfreezeDisplay(0);
11426 }
Romain Guy06882f82009-06-10 13:36:04 -070011427
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011428 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011429
Dianne Hackborn420829e2011-01-28 11:30:35 -080011430 boolean configChanged;
11431
Christopher Tateb696aee2010-04-02 19:08:30 -070011432 // While the display is frozen we don't re-compute the orientation
11433 // to avoid inconsistent states. However, something interesting
11434 // could have actually changed during that time so re-evaluate it
11435 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -080011436 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -070011437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011438 // A little kludge: a lot could have happened while the
11439 // display was frozen, so now that we are coming back we
11440 // do a gc so that any remote references the system
11441 // processes holds on others can be released if they are
11442 // no longer needed.
11443 mH.removeMessages(H.FORCE_GC);
11444 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11445 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011447 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011448
11449 if (updateRotation) {
11450 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -080011451 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011452 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -080011453 }
11454
11455 if (configChanged) {
11456 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011458 }
Romain Guy06882f82009-06-10 13:36:04 -070011459
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011460 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11461 DisplayMetrics dm) {
11462 if (index < tokens.length) {
11463 String str = tokens[index];
11464 if (str != null && str.length() > 0) {
11465 try {
11466 int val = Integer.parseInt(str);
11467 return val;
11468 } catch (Exception e) {
11469 }
11470 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011471 }
11472 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11473 return defDps;
11474 }
11475 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11476 return val;
11477 }
11478
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011479 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011480 final String[] mTokens;
11481 final String mText;
11482 final Paint mTextPaint;
11483 final int mTextWidth;
11484 final int mTextHeight;
11485 final int mTextAscent;
11486 final int mTextDescent;
11487 final int mDeltaX;
11488 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011489
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011490 Surface mSurface;
11491 int mLastDW;
11492 int mLastDH;
11493 boolean mDrawNeeded;
11494
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011495 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011496 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011497 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011498
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011499 if (false) {
11500 Log.i(TAG, "*********************** WATERMARK");
11501 for (int i=0; i<tokens.length; i++) {
11502 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11503 }
11504 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011505
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011506 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011507
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011508 StringBuilder builder = new StringBuilder(32);
11509 int len = mTokens[0].length();
11510 len = len & ~1;
11511 for (int i=0; i<len; i+=2) {
11512 int c1 = mTokens[0].charAt(i);
11513 int c2 = mTokens[0].charAt(i+1);
11514 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11515 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11516 else c1 -= '0';
11517 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11518 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11519 else c2 -= '0';
11520 builder.append((char)(255-((c1*16)+c2)));
11521 }
11522 mText = builder.toString();
11523 if (false) {
11524 Log.i(TAG, "Final text: " + mText);
11525 }
11526
11527 int fontSize = getPropertyInt(tokens, 1,
11528 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11529
11530 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11531 mTextPaint.setTextSize(fontSize);
11532 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11533
11534 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11535 mTextWidth = (int)mTextPaint.measureText(mText);
11536 mTextAscent = fm.ascent;
11537 mTextDescent = fm.descent;
11538 mTextHeight = fm.descent - fm.ascent;
11539
11540 mDeltaX = getPropertyInt(tokens, 2,
11541 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11542 mDeltaY = getPropertyInt(tokens, 3,
11543 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11544 int shadowColor = getPropertyInt(tokens, 4,
11545 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11546 int color = getPropertyInt(tokens, 5,
11547 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11548 int shadowRadius = getPropertyInt(tokens, 6,
11549 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11550 int shadowDx = getPropertyInt(tokens, 8,
11551 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11552 int shadowDy = getPropertyInt(tokens, 9,
11553 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11554
11555 mTextPaint.setColor(color);
11556 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011557
11558 try {
11559 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011560 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011561 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011562 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011563 mSurface.show();
11564 } catch (OutOfResourcesException e) {
11565 }
11566 }
11567
11568 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011569 if (mLastDW != dw || mLastDH != dh) {
11570 mLastDW = dw;
11571 mLastDH = dh;
11572 mSurface.setSize(dw, dh);
11573 mDrawNeeded = true;
11574 }
11575 }
11576
11577 void drawIfNeeded() {
11578 if (mDrawNeeded) {
11579 final int dw = mLastDW;
11580 final int dh = mLastDH;
11581
11582 mDrawNeeded = false;
11583 Rect dirty = new Rect(0, 0, dw, dh);
11584 Canvas c = null;
11585 try {
11586 c = mSurface.lockCanvas(dirty);
11587 } catch (IllegalArgumentException e) {
11588 } catch (OutOfResourcesException e) {
11589 }
11590 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011591 c.drawColor(0, PorterDuff.Mode.CLEAR);
11592
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011593 int deltaX = mDeltaX;
11594 int deltaY = mDeltaY;
11595
11596 // deltaX shouldn't be close to a round fraction of our
11597 // x step, or else things will line up too much.
11598 int div = (dw+mTextWidth)/deltaX;
11599 int rem = (dw+mTextWidth) - (div*deltaX);
11600 int qdelta = deltaX/4;
11601 if (rem < qdelta || rem > (deltaX-qdelta)) {
11602 deltaX += deltaX/3;
11603 }
11604
11605 int y = -mTextHeight;
11606 int x = -mTextWidth;
11607 while (y < (dh+mTextHeight)) {
11608 c.drawText(mText, x, y, mTextPaint);
11609 x += deltaX;
11610 if (x >= dw) {
11611 x -= (dw+mTextWidth);
11612 y += deltaY;
11613 }
11614 }
11615 mSurface.unlockCanvasAndPost(c);
11616 }
11617 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011618 }
11619 }
11620
11621 void createWatermark() {
11622 if (mWatermark != null) {
11623 return;
11624 }
11625
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011626 File file = new File("/system/etc/setup.conf");
11627 FileInputStream in = null;
11628 try {
11629 in = new FileInputStream(file);
11630 DataInputStream ind = new DataInputStream(in);
11631 String line = ind.readLine();
11632 if (line != null) {
11633 String[] toks = line.split("%");
11634 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011635 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011636 }
11637 }
11638 } catch (FileNotFoundException e) {
11639 } catch (IOException e) {
11640 } finally {
11641 if (in != null) {
11642 try {
11643 in.close();
11644 } catch (IOException e) {
11645 }
11646 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011647 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011648 }
11649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011650 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011651 public void statusBarVisibilityChanged(int visibility) {
11652 synchronized (mWindowMap) {
11653 final int N = mWindows.size();
11654 for (int i = 0; i < N; i++) {
11655 WindowState ws = mWindows.get(i);
11656 try {
11657 if (ws.getAttrs().hasSystemUiListeners) {
11658 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11659 }
11660 } catch (RemoteException e) {
11661 // so sorry
11662 }
11663 }
11664 }
11665 }
11666
11667 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011668 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11669 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11670 != PackageManager.PERMISSION_GRANTED) {
11671 pw.println("Permission Denial: can't dump WindowManager from from pid="
11672 + Binder.getCallingPid()
11673 + ", uid=" + Binder.getCallingUid());
11674 return;
11675 }
Romain Guy06882f82009-06-10 13:36:04 -070011676
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011677 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011678 pw.println(" ");
11679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011680 synchronized(mWindowMap) {
11681 pw.println("Current Window Manager state:");
11682 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011683 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011684 pw.print(" Window #"); pw.print(i); pw.print(' ');
11685 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011686 w.dump(pw, " ");
11687 }
11688 if (mInputMethodDialogs.size() > 0) {
11689 pw.println(" ");
11690 pw.println(" Input method dialogs:");
11691 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11692 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011693 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011694 }
11695 }
11696 if (mPendingRemove.size() > 0) {
11697 pw.println(" ");
11698 pw.println(" Remove pending for:");
11699 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11700 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011701 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11702 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011703 w.dump(pw, " ");
11704 }
11705 }
11706 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11707 pw.println(" ");
11708 pw.println(" Windows force removing:");
11709 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11710 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011711 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11712 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011713 w.dump(pw, " ");
11714 }
11715 }
11716 if (mDestroySurface.size() > 0) {
11717 pw.println(" ");
11718 pw.println(" Windows waiting to destroy their surface:");
11719 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11720 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011721 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11722 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011723 w.dump(pw, " ");
11724 }
11725 }
11726 if (mLosingFocus.size() > 0) {
11727 pw.println(" ");
11728 pw.println(" Windows losing focus:");
11729 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11730 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011731 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11732 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011733 w.dump(pw, " ");
11734 }
11735 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011736 if (mResizingWindows.size() > 0) {
11737 pw.println(" ");
11738 pw.println(" Windows waiting to resize:");
11739 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11740 WindowState w = mResizingWindows.get(i);
11741 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11742 pw.print(w); pw.println(":");
11743 w.dump(pw, " ");
11744 }
11745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011746 if (mSessions.size() > 0) {
11747 pw.println(" ");
11748 pw.println(" All active sessions:");
11749 Iterator<Session> it = mSessions.iterator();
11750 while (it.hasNext()) {
11751 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011752 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011753 s.dump(pw, " ");
11754 }
11755 }
11756 if (mTokenMap.size() > 0) {
11757 pw.println(" ");
11758 pw.println(" All tokens:");
11759 Iterator<WindowToken> it = mTokenMap.values().iterator();
11760 while (it.hasNext()) {
11761 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011762 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011763 token.dump(pw, " ");
11764 }
11765 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011766 if (mWallpaperTokens.size() > 0) {
11767 pw.println(" ");
11768 pw.println(" Wallpaper tokens:");
11769 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11770 WindowToken token = mWallpaperTokens.get(i);
11771 pw.print(" Wallpaper #"); pw.print(i);
11772 pw.print(' '); pw.print(token); pw.println(':');
11773 token.dump(pw, " ");
11774 }
11775 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011776 if (mAppTokens.size() > 0) {
11777 pw.println(" ");
11778 pw.println(" Application tokens in Z order:");
11779 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011780 pw.print(" App #"); pw.print(i); pw.print(": ");
11781 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011782 }
11783 }
11784 if (mFinishedStarting.size() > 0) {
11785 pw.println(" ");
11786 pw.println(" Finishing start of application tokens:");
11787 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11788 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011789 pw.print(" Finished Starting #"); pw.print(i);
11790 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011791 token.dump(pw, " ");
11792 }
11793 }
11794 if (mExitingTokens.size() > 0) {
11795 pw.println(" ");
11796 pw.println(" Exiting tokens:");
11797 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11798 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011799 pw.print(" Exiting #"); pw.print(i);
11800 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011801 token.dump(pw, " ");
11802 }
11803 }
11804 if (mExitingAppTokens.size() > 0) {
11805 pw.println(" ");
11806 pw.println(" Exiting application tokens:");
11807 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11808 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011809 pw.print(" Exiting App #"); pw.print(i);
11810 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011811 token.dump(pw, " ");
11812 }
11813 }
11814 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011815 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11816 pw.print(" mLastFocus="); pw.println(mLastFocus);
11817 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11818 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11819 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011820 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011821 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11822 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11823 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11824 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011825 if (mWindowDetachedWallpaper != null) {
11826 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11827 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011828 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11829 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11830 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011831 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11832 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11833 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11834 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011835 if (mDimAnimator != null) {
11836 mDimAnimator.printTo(pw);
11837 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011838 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011839 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011840 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011841 pw.print(mInputMethodAnimLayerAdjustment);
11842 pw.print(" mWallpaperAnimLayerAdjustment=");
11843 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011844 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11845 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011846 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11847 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011848 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11849 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011850 pw.print(" mRotation="); pw.print(mRotation);
11851 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11852 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011853 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11854 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011855 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11856 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11857 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11858 pw.print(" mNextAppTransition=0x");
11859 pw.print(Integer.toHexString(mNextAppTransition));
11860 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011861 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011862 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011863 if (mNextAppTransitionPackage != null) {
11864 pw.print(" mNextAppTransitionPackage=");
11865 pw.print(mNextAppTransitionPackage);
11866 pw.print(", mNextAppTransitionEnter=0x");
11867 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11868 pw.print(", mNextAppTransitionExit=0x");
11869 pw.print(Integer.toHexString(mNextAppTransitionExit));
11870 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011871 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11872 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11873 if (mOpeningApps.size() > 0) {
11874 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11875 }
11876 if (mClosingApps.size() > 0) {
11877 pw.print(" mClosingApps="); pw.println(mClosingApps);
11878 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011879 if (mToTopApps.size() > 0) {
11880 pw.print(" mToTopApps="); pw.println(mToTopApps);
11881 }
11882 if (mToBottomApps.size() > 0) {
11883 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11884 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011885 if (mDisplay != null) {
11886 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11887 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11888 } else {
11889 pw.println(" NO DISPLAY");
11890 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011891 pw.println(" Policy:");
11892 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011893 }
11894 }
11895
Jeff Brown349703e2010-06-22 01:27:15 -070011896 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011897 public void monitor() {
11898 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011899 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011900 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011901
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011902 /**
11903 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011904 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011905 */
11906 private static class DimAnimator {
11907 Surface mDimSurface;
11908 boolean mDimShown = false;
11909 float mDimCurrentAlpha;
11910 float mDimTargetAlpha;
11911 float mDimDeltaPerMs;
11912 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011913
11914 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011915
11916 DimAnimator (SurfaceSession session) {
11917 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011918 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011919 + mDimSurface + ": CREATE");
11920 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011921 mDimSurface = new Surface(session, 0,
11922 "DimSurface",
11923 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011924 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011925 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011926 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011927 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011928 }
11929 }
11930 }
11931
11932 /**
11933 * Show the dim surface.
11934 */
11935 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011936 if (!mDimShown) {
11937 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11938 dw + "x" + dh + ")");
11939 mDimShown = true;
11940 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011941 mLastDimWidth = dw;
11942 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011943 mDimSurface.setPosition(0, 0);
11944 mDimSurface.setSize(dw, dh);
11945 mDimSurface.show();
11946 } catch (RuntimeException e) {
11947 Slog.w(TAG, "Failure showing dim surface", e);
11948 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011949 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11950 mLastDimWidth = dw;
11951 mLastDimHeight = dh;
11952 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011953 }
11954 }
11955
11956 /**
11957 * Set's the dim surface's layer and update dim parameters that will be used in
11958 * {@link updateSurface} after all windows are examined.
11959 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011960 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011961 mDimSurface.setLayer(w.mAnimLayer-1);
11962
11963 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011964 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011965 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011966 if (mDimTargetAlpha != target) {
11967 // If the desired dim level has changed, then
11968 // start an animation to it.
11969 mLastDimAnimTime = currentTime;
11970 long duration = (w.mAnimating && w.mAnimation != null)
11971 ? w.mAnimation.computeDurationHint()
11972 : DEFAULT_DIM_DURATION;
11973 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011974 TypedValue tv = new TypedValue();
11975 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11976 tv, true);
11977 if (tv.type == TypedValue.TYPE_FRACTION) {
11978 duration = (long)tv.getFraction((float)duration, (float)duration);
11979 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11980 && tv.type <= TypedValue.TYPE_LAST_INT) {
11981 duration = tv.data;
11982 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011983 }
11984 if (duration < 1) {
11985 // Don't divide by zero
11986 duration = 1;
11987 }
11988 mDimTargetAlpha = target;
11989 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11990 }
11991 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011992
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011993 /**
11994 * Updating the surface's alpha. Returns true if the animation continues, or returns
11995 * false when the animation is finished and the dim surface is hidden.
11996 */
11997 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11998 if (!dimming) {
11999 if (mDimTargetAlpha != 0) {
12000 mLastDimAnimTime = currentTime;
12001 mDimTargetAlpha = 0;
12002 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
12003 }
12004 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080012005
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012006 boolean animating = false;
12007 if (mLastDimAnimTime != 0) {
12008 mDimCurrentAlpha += mDimDeltaPerMs
12009 * (currentTime-mLastDimAnimTime);
12010 boolean more = true;
12011 if (displayFrozen) {
12012 // If the display is frozen, there is no reason to animate.
12013 more = false;
12014 } else if (mDimDeltaPerMs > 0) {
12015 if (mDimCurrentAlpha > mDimTargetAlpha) {
12016 more = false;
12017 }
12018 } else if (mDimDeltaPerMs < 0) {
12019 if (mDimCurrentAlpha < mDimTargetAlpha) {
12020 more = false;
12021 }
12022 } else {
12023 more = false;
12024 }
12025
12026 // Do we need to continue animating?
12027 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012028 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012029 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
12030 mLastDimAnimTime = currentTime;
12031 mDimSurface.setAlpha(mDimCurrentAlpha);
12032 animating = true;
12033 } else {
12034 mDimCurrentAlpha = mDimTargetAlpha;
12035 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080012036 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012037 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
12038 mDimSurface.setAlpha(mDimCurrentAlpha);
12039 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012040 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012041 + ": HIDE");
12042 try {
12043 mDimSurface.hide();
12044 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012045 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012046 }
12047 mDimShown = false;
12048 }
12049 }
12050 }
12051 return animating;
12052 }
12053
12054 public void printTo(PrintWriter pw) {
12055 pw.print(" mDimShown="); pw.print(mDimShown);
12056 pw.print(" current="); pw.print(mDimCurrentAlpha);
12057 pw.print(" target="); pw.print(mDimTargetAlpha);
12058 pw.print(" delta="); pw.print(mDimDeltaPerMs);
12059 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
12060 }
12061 }
12062
12063 /**
12064 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
12065 * This is used for opening/closing transition for apps in compatible mode.
12066 */
12067 private static class FadeInOutAnimation extends Animation {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012068 boolean mFadeIn;
12069
12070 public FadeInOutAnimation(boolean fadeIn) {
12071 setInterpolator(new AccelerateInterpolator());
12072 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
12073 mFadeIn = fadeIn;
12074 }
12075
12076 @Override
12077 protected void applyTransformation(float interpolatedTime, Transformation t) {
12078 float x = interpolatedTime;
12079 if (!mFadeIn) {
12080 x = 1.0f - x; // reverse the interpolation for fade out
12081 }
Dianne Hackbornac1471a2011-02-03 13:46:06 -080012082 t.setAlpha(x);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012083 }
12084 }
Jeff Brown2992ea72011-01-28 22:04:14 -080012085
12086 public interface OnHardKeyboardStatusChangeListener {
12087 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
12088 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012089}