blob: 169c6d87d063e66fdd7ec86041270526b98d17df [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 /**
289 * All currently active sessions with clients.
290 */
291 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 /**
294 * Mapping from an IWindow IBinder to the server's Window object.
295 * This is also used as the lock for all of our state.
296 */
297 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
298
299 /**
300 * Mapping from a token IBinder to a WindowToken object.
301 */
302 final HashMap<IBinder, WindowToken> mTokenMap =
303 new HashMap<IBinder, WindowToken>();
304
305 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 * Window tokens that are in the process of exiting, but still
307 * on screen for animations.
308 */
309 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
310
311 /**
312 * Z-ordered (bottom-most first) list of all application tokens, for
313 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800314 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 */
316 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
317
318 /**
319 * Application tokens that are in the process of exiting, but still
320 * on screen for animations.
321 */
322 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
323
324 /**
325 * List of window tokens that have finished starting their application,
326 * and now need to have the policy remove their windows.
327 */
328 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
329
330 /**
331 * Z-ordered (bottom-most first) list of all Window objects.
332 */
Jeff Browne33348b2010-07-15 23:54:05 -0700333 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334
335 /**
336 * Windows that are being resized. Used so we can tell the client about
337 * the resize after closing the transaction in which we resized the
338 * underlying surface.
339 */
340 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
341
342 /**
343 * Windows whose animations have ended and now must be removed.
344 */
345 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
346
347 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800348 * Used when processing mPendingRemove to avoid working on the original array.
349 */
350 WindowState[] mPendingRemoveTmp = new WindowState[20];
351
352 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 * Windows whose surface should be destroyed.
354 */
355 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
356
357 /**
358 * Windows that have lost input focus and are waiting for the new
359 * focus window to be displayed before they are told about this.
360 */
361 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
362
363 /**
364 * This is set when we have run out of memory, and will either be an empty
365 * list or contain windows that need to be force removed.
366 */
367 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700368
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800369 /**
370 * Used when rebuilding window list to keep track of windows that have
371 * been removed.
372 */
373 WindowState[] mRebuildTmp = new WindowState[20];
374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700378 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 Surface mBlurSurface;
380 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700381 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800382 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800383 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 final float[] mTmpFloats = new float[9];
388
389 boolean mSafeMode;
390 boolean mDisplayEnabled = false;
391 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700392 int mInitialDisplayWidth = 0;
393 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 int mRotation = 0;
395 int mRequestedRotation = 0;
396 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700397 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 ArrayList<IRotationWatcher> mRotationWatchers
399 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800400 int mDeferredRotation;
401 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 boolean mLayoutNeeded = true;
404 boolean mAnimationPending = false;
405 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800406 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 boolean mWindowsFreezingScreen = false;
408 long mFreezeGcPending = 0;
409 int mAppsFreezingScreen = 0;
410
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800411 int mLayoutSeq = 0;
412
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800413 // State while inside of layoutAndPlaceSurfacesLocked().
414 boolean mFocusMayChange;
415
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800416 Configuration mCurConfiguration = new Configuration();
417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 // This is held as long as we have the screen frozen, to give us time to
419 // perform a rotation animation when turning off shows the lock screen which
420 // changes the orientation.
421 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 // State management of app transitions. When we are preparing for a
424 // transition, mNextAppTransition will be the kind of transition to
425 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
426 // mOpeningApps and mClosingApps are the lists of tokens that will be
427 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700428 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700429 String mNextAppTransitionPackage;
430 int mNextAppTransitionEnter;
431 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700433 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 boolean mAppTransitionTimeout = false;
435 boolean mStartingIconInTransition = false;
436 boolean mSkipAppTransitionAnimation = false;
437 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
438 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700439 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
440 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 H mH = new H();
445
446 WindowState mCurrentFocus = null;
447 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 // This just indicates the window the input method is on top of, not
450 // necessarily the window its input is going to.
451 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 boolean mInputMethodTargetWaitingAnim;
453 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 WindowState mInputMethodWindow = null;
456 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
457
Jeff Brown2992ea72011-01-28 22:04:14 -0800458 boolean mHardKeyboardAvailable;
459 boolean mHardKeyboardEnabled;
460 OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
461
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700462 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800463
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700464 // If non-null, this is the currently visible window that is associated
465 // with the wallpaper.
466 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700467 // If non-null, we are in the middle of animating from one wallpaper target
468 // to another, and this is the lower one in Z-order.
469 WindowState mLowerWallpaperTarget = null;
470 // If non-null, we are in the middle of animating from one wallpaper target
471 // to another, and this is the higher one in Z-order.
472 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800473 // Window currently running an animation that has requested it be detached
474 // from the wallpaper. This means we need to ensure the wallpaper is
475 // visible behind it in case it animates in a way that would allow it to be
476 // seen.
477 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700478 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700479 float mLastWallpaperX = -1;
480 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800481 float mLastWallpaperXStep = -1;
482 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700483 // This is set when we are waiting for a wallpaper to tell us it is done
484 // changing its scroll position.
485 WindowState mWaitingOnWallpaper;
486 // The last time we had a timeout when waiting for a wallpaper.
487 long mLastWallpaperTimeoutTime;
488 // We give a wallpaper up to 150ms to finish scrolling.
489 static final long WALLPAPER_TIMEOUT = 150;
490 // Time we wait after a timeout before trying to wait again.
491 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 AppWindowToken mFocusedApp = null;
494
495 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 float mWindowAnimationScale = 1.0f;
498 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700499
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700500 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501
502 // Who is holding the screen on.
503 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700504 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700505
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700506 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 * Drag/drop state
510 */
511 class DragState {
512 IBinder mToken;
513 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800514 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700515 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700516 ClipData mData;
517 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700518 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700519 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700520 float mThumbOffsetX, mThumbOffsetY;
521 InputChannel mServerChannel, mClientChannel;
522 WindowState mTargetWindow;
523 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700524 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700525
Jeff Brownfbf09772011-01-16 14:06:57 -0800526 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700527
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800528 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700529 mToken = token;
530 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800531 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700532 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700533 mNotifiedWindows = new ArrayList<WindowState>();
534 }
535
536 void reset() {
537 if (mSurface != null) {
538 mSurface.destroy();
539 }
540 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800541 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700542 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700543 mToken = null;
544 mData = null;
545 mThumbOffsetX = mThumbOffsetY = 0;
546 mNotifiedWindows = null;
547 }
548
549 void register() {
550 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
551 if (mClientChannel != null) {
552 Slog.e(TAG, "Duplicate register of drag input channel");
553 } else {
554 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
555 mServerChannel = channels[0];
556 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800557 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700558 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
559 mH.getLooper().getQueue());
560 }
561 }
562
563 void unregister() {
564 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
565 if (mClientChannel == null) {
566 Slog.e(TAG, "Unregister of nonexistent drag input channel");
567 } else {
568 mInputManager.unregisterInputChannel(mServerChannel);
569 InputQueue.unregisterInputChannel(mClientChannel);
570 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700571 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700572 mClientChannel = null;
573 mServerChannel = null;
574 }
575 }
576
Chris Tatea32dcf72010-10-14 12:13:50 -0700577 int getDragLayerLw() {
578 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
579 * TYPE_LAYER_MULTIPLIER
580 + TYPE_LAYER_OFFSET;
581 }
582
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 /* call out to each visible window/session informing it about the drag
584 */
Chris Tateb8203e92010-10-12 14:23:21 -0700585 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700586 // Cache a base-class instance of the clip metadata so that parceling
587 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800588 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700590 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700591
592 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700593 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700594 }
595
Christopher Tate2c095f32010-10-04 14:13:40 -0700596 final int N = mWindows.size();
597 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700598 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700599 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700600 }
601
602 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
603 * designated window is potentially a drop recipient. There are race situations
604 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
605 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700606 *
607 * This method clones the 'event' parameter if it's being delivered to the same
608 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700609 */
Chris Tateb478f462010-10-15 16:02:26 -0700610 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
611 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700612 // Don't actually send the event if the drag is supposed to be pinned
613 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800614 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700615 final IBinder winBinder = newWin.mClient.asBinder();
616 if (winBinder != mLocalWin) {
617 if (DEBUG_DRAG) {
618 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
619 }
620 return;
621 }
622 }
623
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700624 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700625 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
626 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800627 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700628 try {
629 newWin.mClient.dispatchDragEvent(event);
630 // track each window that we've notified that the drag is starting
631 mNotifiedWindows.add(newWin);
632 } catch (RemoteException e) {
633 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700634 } finally {
635 // if the callee was local, the dispatch has already recycled the event
636 if (Process.myPid() != newWin.mSession.mPid) {
637 event.recycle();
638 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700639 }
640 }
641 }
642
643 /* helper - construct and send a DRAG_STARTED event only if the window has not
644 * previously been notified, i.e. it became visible after the drag operation
645 * was begun. This is a rare case.
646 */
647 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700648 if (mDragInProgress) {
649 // If we have sent the drag-started, we needn't do so again
650 for (WindowState ws : mNotifiedWindows) {
651 if (ws == newWin) {
652 return;
653 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700654 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700655 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700656 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700657 }
Chris Tateb478f462010-10-15 16:02:26 -0700658 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700659 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700660 }
661
Chris Tated4533f142010-10-19 15:15:08 -0700662 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 if (DEBUG_DRAG) {
664 Slog.d(TAG, "broadcasting DRAG_ENDED");
665 }
Chris Tated4533f142010-10-19 15:15:08 -0700666 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800667 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700668 for (WindowState ws: mNotifiedWindows) {
669 try {
670 ws.mClient.dispatchDragEvent(evt);
671 } catch (RemoteException e) {
672 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700673 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700674 }
Chris Tated4533f142010-10-19 15:15:08 -0700675 mNotifiedWindows.clear();
676 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700677 evt.recycle();
678 }
679
Chris Tated4533f142010-10-19 15:15:08 -0700680 void endDragLw() {
681 mDragState.broadcastDragEndedLw();
682
683 // stop intercepting input
684 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -0800685 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tated4533f142010-10-19 15:15:08 -0700686
687 // free our resources and drop all the object references
688 mDragState.reset();
689 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800690
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800691 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
692 boolean changed = setRotationUncheckedLocked(
693 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
694 if (changed) {
695 sendNewConfiguration();
Christopher Tateccd24de2011-01-12 15:02:55 -0800696 }
Chris Tated4533f142010-10-19 15:15:08 -0700697 }
698
Christopher Tatea53146c2010-09-07 11:57:52 -0700699 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700700 final int myPid = Process.myPid();
701
702 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800703 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800704 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800705 try {
706 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
707 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800708 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800709 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
710 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700711
712 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700713 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800714 if (touchedWin == null) {
715 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
716 return;
717 }
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800718 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700719 final IBinder touchedBinder = touchedWin.mClient.asBinder();
720 if (touchedBinder != mLocalWin) {
721 // This drag is pinned only to the originating window, but the drag
722 // point is outside that window. Pretend it's over empty space.
723 touchedWin = null;
724 }
725 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700726 try {
727 // have we dragged over a new window?
728 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
729 if (DEBUG_DRAG) {
730 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
731 }
732 // force DRAG_EXITED_EVENT if appropriate
733 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700734 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800735 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700736 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700737 if (myPid != mTargetWindow.mSession.mPid) {
738 evt.recycle();
739 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700740 }
741 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700742 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
744 }
745 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700746 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800747 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700748 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700749 if (myPid != touchedWin.mSession.mPid) {
750 evt.recycle();
751 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700752 }
753 } catch (RemoteException e) {
754 Slog.w(TAG, "can't send drag notification to windows");
755 }
756 mTargetWindow = touchedWin;
757 }
758
Chris Tated4533f142010-10-19 15:15:08 -0700759 // Tell the drop target about the data. Returns 'true' if we can immediately
760 // dispatch the global drag-ended message, 'false' if we need to wait for a
761 // result from the recipient.
762 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700763 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700764 if (touchedWin == null) {
765 // "drop" outside a valid window -- no recipient to apply a
766 // timeout to, and we can send the drag-ended message immediately.
767 mDragResult = false;
768 return true;
769 }
770
771 if (DEBUG_DRAG) {
772 Slog.d(TAG, "sending DROP to " + touchedWin);
773 }
774 final int myPid = Process.myPid();
775 final IBinder token = touchedWin.mClient.asBinder();
776 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
777 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800778 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700779 try {
780 touchedWin.mClient.dispatchDragEvent(evt);
781
782 // 5 second timeout for this window to respond to the drop
783 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
784 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
785 mH.sendMessageDelayed(msg, 5000);
786 } catch (RemoteException e) {
787 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
788 return true;
789 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700790 if (myPid != touchedWin.mSession.mPid) {
791 evt.recycle();
792 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700793 }
Chris Tated4533f142010-10-19 15:15:08 -0700794 mToken = token;
795 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700796 }
797
798 // Find the visible, touch-deliverable window under the given point
799 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
800 WindowState touchedWin = null;
801 final int x = (int) xf;
802 final int y = (int) yf;
803 final ArrayList<WindowState> windows = mWindows;
804 final int N = windows.size();
805 for (int i = N - 1; i >= 0; i--) {
806 WindowState child = windows.get(i);
807 final int flags = child.mAttrs.flags;
808 if (!child.isVisibleLw()) {
809 // not visible == don't tell about drags
810 continue;
811 }
812 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
813 // not touchable == don't tell about drags
814 continue;
815 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800816
817 child.getTouchableRegion(mTmpRegion);
818
Christopher Tatea53146c2010-09-07 11:57:52 -0700819 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800820 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
821 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
822 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700823 // Found it
824 touchedWin = child;
825 break;
826 }
827 }
828
829 return touchedWin;
830 }
831 }
832
833 DragState mDragState = null;
834 private final InputHandler mDragInputHandler = new BaseInputHandler() {
835 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700836 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
837 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700838 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700839 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
840 && mDragState != null) {
841 boolean endDrag = false;
842 final float newX = event.getRawX();
843 final float newY = event.getRawY();
844
Christopher Tatea53146c2010-09-07 11:57:52 -0700845 switch (event.getAction()) {
846 case MotionEvent.ACTION_DOWN: {
847 if (DEBUG_DRAG) {
848 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
849 }
850 } break;
851
852 case MotionEvent.ACTION_MOVE: {
853 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700854 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700855 mDragState.notifyMoveLw(newX, newY);
856 }
857 } break;
858
859 case MotionEvent.ACTION_UP: {
860 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
861 + newX + "," + newY);
862 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700863 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700864 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700865 } break;
866
867 case MotionEvent.ACTION_CANCEL: {
868 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
869 endDrag = true;
870 } break;
871 }
872
873 if (endDrag) {
874 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
875 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700876 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700877 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700878 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700879 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700880
881 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700882 }
883 } catch (Exception e) {
884 Slog.e(TAG, "Exception caught by drag handleMotion", e);
885 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700886 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700887 }
888 }
889 };
890
891 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 * Whether the UI is currently running in touch mode (not showing
893 * navigational focus because the user is directly pressing the screen).
894 */
895 boolean mInTouchMode = false;
896
897 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700898 private ArrayList<WindowChangeListener> mWindowChangeListeners =
899 new ArrayList<WindowChangeListener>();
900 private boolean mWindowsChanged = false;
901
902 public interface WindowChangeListener {
903 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700904 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906
Dianne Hackbornc485a602009-03-24 22:39:49 -0700907 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700908 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700909
910 // The frame use to limit the size of the app running in compatibility mode.
911 Rect mCompatibleScreenFrame = new Rect();
912 // The surface used to fill the outer rim of the app running in compatibility mode.
913 Surface mBackgroundFillerSurface = null;
914 boolean mBackgroundFillerShown = false;
915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 public static WindowManagerService main(Context context,
917 PowerManagerService pm, boolean haveInputMethods) {
918 WMThread thr = new WMThread(context, pm, haveInputMethods);
919 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 synchronized (thr) {
922 while (thr.mService == null) {
923 try {
924 thr.wait();
925 } catch (InterruptedException e) {
926 }
927 }
928 }
Romain Guy06882f82009-06-10 13:36:04 -0700929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 return thr.mService;
931 }
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 static class WMThread extends Thread {
934 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 private final Context mContext;
937 private final PowerManagerService mPM;
938 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 public WMThread(Context context, PowerManagerService pm,
941 boolean haveInputMethods) {
942 super("WindowManager");
943 mContext = context;
944 mPM = pm;
945 mHaveInputMethods = haveInputMethods;
946 }
Romain Guy06882f82009-06-10 13:36:04 -0700947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 public void run() {
949 Looper.prepare();
950 WindowManagerService s = new WindowManagerService(mContext, mPM,
951 mHaveInputMethods);
952 android.os.Process.setThreadPriority(
953 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700954 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 synchronized (this) {
957 mService = s;
958 notifyAll();
959 }
Romain Guy06882f82009-06-10 13:36:04 -0700960
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700961 // For debug builds, log event loop stalls to dropbox for analysis.
962 if (StrictMode.conditionallyEnableDebugLogging()) {
963 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
964 }
965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 Looper.loop();
967 }
968 }
969
970 static class PolicyThread extends Thread {
971 private final WindowManagerPolicy mPolicy;
972 private final WindowManagerService mService;
973 private final Context mContext;
974 private final PowerManagerService mPM;
975 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 public PolicyThread(WindowManagerPolicy policy,
978 WindowManagerService service, Context context,
979 PowerManagerService pm) {
980 super("WindowManagerPolicy");
981 mPolicy = policy;
982 mService = service;
983 mContext = context;
984 mPM = pm;
985 }
Romain Guy06882f82009-06-10 13:36:04 -0700986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 public void run() {
988 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800989 WindowManagerPolicyThread.set(this, Looper.myLooper());
990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800992 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 android.os.Process.setThreadPriority(
994 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700995 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 synchronized (this) {
999 mRunning = true;
1000 notifyAll();
1001 }
Romain Guy06882f82009-06-10 13:36:04 -07001002
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001003 // For debug builds, log event loop stalls to dropbox for analysis.
1004 if (StrictMode.conditionallyEnableDebugLogging()) {
1005 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1006 }
1007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 Looper.loop();
1009 }
1010 }
1011
1012 private WindowManagerService(Context context, PowerManagerService pm,
1013 boolean haveInputMethods) {
1014 mContext = context;
1015 mHaveInputMethods = haveInputMethods;
1016 mLimitedAlphaCompositing = context.getResources().getBoolean(
1017 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 mPowerManager = pm;
1020 mPowerManager.setPolicy(mPolicy);
1021 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1022 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1023 "SCREEN_FROZEN");
1024 mScreenFrozenLock.setReferenceCounted(false);
1025
1026 mActivityManager = ActivityManagerNative.getDefault();
1027 mBatteryStats = BatteryStatsService.getService();
1028
1029 // Get persisted window scale setting
1030 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1031 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1032 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1033 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001034
Jim Miller284b62e2010-06-08 14:27:42 -07001035 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1036 IntentFilter filter = new IntentFilter();
1037 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1038 mContext.registerReceiver(mBroadcastReceiver, filter);
1039
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001040 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1041 "KEEP_SCREEN_ON_FLAG");
1042 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043
Jeff Browne33348b2010-07-15 23:54:05 -07001044 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1047 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 synchronized (thr) {
1050 while (!thr.mRunning) {
1051 try {
1052 thr.wait();
1053 } catch (InterruptedException e) {
1054 }
1055 }
1056 }
Romain Guy06882f82009-06-10 13:36:04 -07001057
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001058 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 // Add ourself to the Watchdog monitors.
1061 Watchdog.getInstance().addMonitor(this);
1062 }
1063
1064 @Override
1065 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1066 throws RemoteException {
1067 try {
1068 return super.onTransact(code, data, reply, flags);
1069 } catch (RuntimeException e) {
1070 // The window manager only throws security exceptions, so let's
1071 // log all others.
1072 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001073 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 }
1075 throw e;
1076 }
1077 }
1078
Jeff Browne33348b2010-07-15 23:54:05 -07001079 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001081 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 TAG, "Adding window " + window + " at "
1083 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1084 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001085 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 }
1087
Jeff Browne33348b2010-07-15 23:54:05 -07001088 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001090 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 TAG, "Adding window " + window + " at "
1092 + i + " of " + mWindows.size() + " (before " + pos + ")");
1093 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001094 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 }
1096
1097 //This method finds out the index of a window that has the same app token as
1098 //win. used for z ordering the windows in mWindows
1099 private int findIdxBasedOnAppTokens(WindowState win) {
1100 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001101 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 int jmax = localmWindows.size();
1103 if(jmax == 0) {
1104 return -1;
1105 }
1106 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001107 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 if(wentry.mAppToken == win.mAppToken) {
1109 return j;
1110 }
1111 }
1112 return -1;
1113 }
Romain Guy06882f82009-06-10 13:36:04 -07001114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1116 final IWindow client = win.mClient;
1117 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001118 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 final int N = localmWindows.size();
1121 final WindowState attached = win.mAttachedWindow;
1122 int i;
1123 if (attached == null) {
1124 int tokenWindowsPos = token.windows.size();
1125 if (token.appWindowToken != null) {
1126 int index = tokenWindowsPos-1;
1127 if (index >= 0) {
1128 // If this application has existing windows, we
1129 // simply place the new window on top of them... but
1130 // keep the starting window on top.
1131 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1132 // Base windows go behind everything else.
1133 placeWindowBefore(token.windows.get(0), win);
1134 tokenWindowsPos = 0;
1135 } else {
1136 AppWindowToken atoken = win.mAppToken;
1137 if (atoken != null &&
1138 token.windows.get(index) == atoken.startingWindow) {
1139 placeWindowBefore(token.windows.get(index), win);
1140 tokenWindowsPos--;
1141 } else {
1142 int newIdx = findIdxBasedOnAppTokens(win);
1143 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001144 //there is a window above this one associated with the same
1145 //apptoken note that the window could be a floating window
1146 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001148 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1149 Slog.v(TAG, "Adding window " + win + " at "
1150 + (newIdx+1) + " of " + N);
1151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001153 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001154 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 }
1156 }
1157 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001158 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 TAG, "Figuring out where to add app window "
1160 + client.asBinder() + " (token=" + token + ")");
1161 // Figure out where the window should go, based on the
1162 // order of applications.
1163 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001164 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 for (i=NA-1; i>=0; i--) {
1166 AppWindowToken t = mAppTokens.get(i);
1167 if (t == token) {
1168 i--;
1169 break;
1170 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001171
Dianne Hackborna8f60182009-09-01 19:01:50 -07001172 // We haven't reached the token yet; if this token
1173 // is not going to the bottom and has windows, we can
1174 // use it as an anchor for when we do reach the token.
1175 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 pos = t.windows.get(0);
1177 }
1178 }
1179 // We now know the index into the apps. If we found
1180 // an app window above, that gives us the position; else
1181 // we need to look some more.
1182 if (pos != null) {
1183 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001184 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 if (atoken != null) {
1186 final int NC = atoken.windows.size();
1187 if (NC > 0) {
1188 WindowState bottom = atoken.windows.get(0);
1189 if (bottom.mSubLayer < 0) {
1190 pos = bottom;
1191 }
1192 }
1193 }
1194 placeWindowBefore(pos, win);
1195 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001196 // Continue looking down until we find the first
1197 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 while (i >= 0) {
1199 AppWindowToken t = mAppTokens.get(i);
1200 final int NW = t.windows.size();
1201 if (NW > 0) {
1202 pos = t.windows.get(NW-1);
1203 break;
1204 }
1205 i--;
1206 }
1207 if (pos != null) {
1208 // Move in front of any windows attached to this
1209 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001210 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 if (atoken != null) {
1212 final int NC = atoken.windows.size();
1213 if (NC > 0) {
1214 WindowState top = atoken.windows.get(NC-1);
1215 if (top.mSubLayer >= 0) {
1216 pos = top;
1217 }
1218 }
1219 }
1220 placeWindowAfter(pos, win);
1221 } else {
1222 // Just search for the start of this layer.
1223 final int myLayer = win.mBaseLayer;
1224 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001225 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 if (w.mBaseLayer > myLayer) {
1227 break;
1228 }
1229 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001230 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1231 Slog.v(TAG, "Adding window " + win + " at "
1232 + i + " of " + N);
1233 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001235 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 }
1237 }
1238 }
1239 } else {
1240 // Figure out where window should go, based on layer.
1241 final int myLayer = win.mBaseLayer;
1242 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001243 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 i++;
1245 break;
1246 }
1247 }
1248 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001249 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001250 TAG, "Adding window " + win + " at "
1251 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001253 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 }
1255 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001256 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 token.windows.add(tokenWindowsPos, win);
1258 }
1259
1260 } else {
1261 // Figure out this window's ordering relative to the window
1262 // it is attached to.
1263 final int NA = token.windows.size();
1264 final int sublayer = win.mSubLayer;
1265 int largestSublayer = Integer.MIN_VALUE;
1266 WindowState windowWithLargestSublayer = null;
1267 for (i=0; i<NA; i++) {
1268 WindowState w = token.windows.get(i);
1269 final int wSublayer = w.mSubLayer;
1270 if (wSublayer >= largestSublayer) {
1271 largestSublayer = wSublayer;
1272 windowWithLargestSublayer = w;
1273 }
1274 if (sublayer < 0) {
1275 // For negative sublayers, we go below all windows
1276 // in the same sublayer.
1277 if (wSublayer >= sublayer) {
1278 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001279 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 token.windows.add(i, win);
1281 }
1282 placeWindowBefore(
1283 wSublayer >= 0 ? attached : w, win);
1284 break;
1285 }
1286 } else {
1287 // For positive sublayers, we go above all windows
1288 // in the same sublayer.
1289 if (wSublayer > sublayer) {
1290 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001291 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 token.windows.add(i, win);
1293 }
1294 placeWindowBefore(w, win);
1295 break;
1296 }
1297 }
1298 }
1299 if (i >= NA) {
1300 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001301 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 token.windows.add(win);
1303 }
1304 if (sublayer < 0) {
1305 placeWindowBefore(attached, win);
1306 } else {
1307 placeWindowAfter(largestSublayer >= 0
1308 ? windowWithLargestSublayer
1309 : attached,
1310 win);
1311 }
1312 }
1313 }
Romain Guy06882f82009-06-10 13:36:04 -07001314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 if (win.mAppToken != null && addToToken) {
1316 win.mAppToken.allAppWindows.add(win);
1317 }
1318 }
Romain Guy06882f82009-06-10 13:36:04 -07001319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 static boolean canBeImeTarget(WindowState w) {
1321 final int fl = w.mAttrs.flags
1322 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001323 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
1324 || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
1325 if (DEBUG_INPUT_METHOD) {
1326 Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1327 if (!w.isVisibleOrAdding()) {
1328 Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface
1329 + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
1330 + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
1331 + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
1332 if (w.mAppToken != null) {
1333 Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1334 }
1335 }
1336 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 return w.isVisibleOrAdding();
1338 }
1339 return false;
1340 }
Romain Guy06882f82009-06-10 13:36:04 -07001341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001343 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 final int N = localmWindows.size();
1345 WindowState w = null;
1346 int i = N;
1347 while (i > 0) {
1348 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001349 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001350
Dianne Hackborne75d8722011-01-27 19:37:40 -08001351 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
1352 + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001354 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 // Yet more tricksyness! If this window is a "starting"
1357 // window, we do actually want to be on top of it, but
1358 // it is not -really- where input will go. So if the caller
1359 // is not actually looking to move the IME, look down below
1360 // for a real window to target...
1361 if (!willMove
1362 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1363 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001364 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1366 i--;
1367 w = wb;
1368 }
1369 }
1370 break;
1371 }
1372 }
Romain Guy06882f82009-06-10 13:36:04 -07001373
Dianne Hackborne75d8722011-01-27 19:37:40 -08001374 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
1375
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001376 // Now, a special case -- if the last target's window is in the
1377 // process of exiting, and is above the new target, keep on the
1378 // last target to avoid flicker. Consider for example a Dialog with
1379 // the IME shown: when the Dialog is dismissed, we want to keep
1380 // the IME above it until it is completely gone so it doesn't drop
1381 // behind the dialog or its full-screen scrim.
1382 if (mInputMethodTarget != null && w != null
1383 && mInputMethodTarget.isDisplayedLw()
1384 && mInputMethodTarget.mExiting) {
1385 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1386 w = mInputMethodTarget;
1387 i = localmWindows.indexOf(w);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001388 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w);
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001389 }
1390 }
Romain Guy06882f82009-06-10 13:36:04 -07001391
Joe Onorato8a9b2202010-02-26 18:56:32 -08001392 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 if (willMove && w != null) {
1396 final WindowState curTarget = mInputMethodTarget;
1397 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 // Now some fun for dealing with window animations that
1400 // modify the Z order. We need to look at all windows below
1401 // the current target that are in this app, finding the highest
1402 // visible one in layering.
1403 AppWindowToken token = curTarget.mAppToken;
1404 WindowState highestTarget = null;
1405 int highestPos = 0;
1406 if (token.animating || token.animation != null) {
1407 int pos = 0;
1408 pos = localmWindows.indexOf(curTarget);
1409 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001410 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 if (win.mAppToken != token) {
1412 break;
1413 }
1414 if (!win.mRemoved) {
1415 if (highestTarget == null || win.mAnimLayer >
1416 highestTarget.mAnimLayer) {
1417 highestTarget = win;
1418 highestPos = pos;
1419 }
1420 }
1421 pos--;
1422 }
1423 }
Romain Guy06882f82009-06-10 13:36:04 -07001424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001426 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 + mNextAppTransition + " " + highestTarget
1428 + " animating=" + highestTarget.isAnimating()
1429 + " layer=" + highestTarget.mAnimLayer
1430 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001431
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001432 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 // If we are currently setting up for an animation,
1434 // hold everything until we can find out what will happen.
1435 mInputMethodTargetWaitingAnim = true;
1436 mInputMethodTarget = highestTarget;
1437 return highestPos + 1;
1438 } else if (highestTarget.isAnimating() &&
1439 highestTarget.mAnimLayer > w.mAnimLayer) {
1440 // If the window we are currently targeting is involved
1441 // with an animation, and it is on top of the next target
1442 // we will be over, then hold off on moving until
1443 // that is done.
Dianne Hackborne75d8722011-01-27 19:37:40 -08001444 mInputMethodTargetWaitingAnim = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 mInputMethodTarget = highestTarget;
1446 return highestPos + 1;
1447 }
1448 }
1449 }
1450 }
Romain Guy06882f82009-06-10 13:36:04 -07001451
Joe Onorato8a9b2202010-02-26 18:56:32 -08001452 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 if (w != null) {
1454 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001455 if (DEBUG_INPUT_METHOD) {
1456 RuntimeException e = null;
1457 if (!HIDE_STACK_CRAWLS) {
1458 e = new RuntimeException();
1459 e.fillInStackTrace();
1460 }
1461 Slog.w(TAG, "Moving IM target from "
1462 + mInputMethodTarget + " to " + w, e);
1463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 mInputMethodTarget = w;
Dianne Hackborne75d8722011-01-27 19:37:40 -08001465 mInputMethodTargetWaitingAnim = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 if (w.mAppToken != null) {
1467 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1468 } else {
1469 setInputMethodAnimLayerAdjustment(0);
1470 }
1471 }
1472 return i+1;
1473 }
1474 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001475 if (DEBUG_INPUT_METHOD) {
1476 RuntimeException e = null;
1477 if (!HIDE_STACK_CRAWLS) {
1478 e = new RuntimeException();
1479 e.fillInStackTrace();
1480 }
1481 Slog.w(TAG, "Moving IM target from "
1482 + mInputMethodTarget + " to null", e);
1483 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 mInputMethodTarget = null;
1485 setInputMethodAnimLayerAdjustment(0);
1486 }
1487 return -1;
1488 }
Romain Guy06882f82009-06-10 13:36:04 -07001489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 void addInputMethodWindowToListLocked(WindowState win) {
1491 int pos = findDesiredInputMethodWindowIndexLocked(true);
1492 if (pos >= 0) {
1493 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001494 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001495 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001497 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 moveInputMethodDialogsLocked(pos+1);
1499 return;
1500 }
1501 win.mTargetAppToken = null;
1502 addWindowToListInOrderLocked(win, true);
1503 moveInputMethodDialogsLocked(pos);
1504 }
Romain Guy06882f82009-06-10 13:36:04 -07001505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 mInputMethodAnimLayerAdjustment = adj;
1509 WindowState imw = mInputMethodWindow;
1510 if (imw != null) {
1511 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001512 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 + " anim layer: " + imw.mAnimLayer);
1514 int wi = imw.mChildWindows.size();
1515 while (wi > 0) {
1516 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001517 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001519 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 + " anim layer: " + cw.mAnimLayer);
1521 }
1522 }
1523 int di = mInputMethodDialogs.size();
1524 while (di > 0) {
1525 di --;
1526 imw = mInputMethodDialogs.get(di);
1527 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001528 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 + " anim layer: " + imw.mAnimLayer);
1530 }
1531 }
Romain Guy06882f82009-06-10 13:36:04 -07001532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1534 int wpos = mWindows.indexOf(win);
1535 if (wpos >= 0) {
1536 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001537 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001539 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 int NC = win.mChildWindows.size();
1541 while (NC > 0) {
1542 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001543 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 int cpos = mWindows.indexOf(cw);
1545 if (cpos >= 0) {
1546 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001547 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001548 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 mWindows.remove(cpos);
1550 }
1551 }
1552 }
1553 return interestingPos;
1554 }
Romain Guy06882f82009-06-10 13:36:04 -07001555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 private void reAddWindowToListInOrderLocked(WindowState win) {
1557 addWindowToListInOrderLocked(win, false);
1558 // This is a hack to get all of the child windows added as well
1559 // at the right position. Child windows should be rare and
1560 // this case should be rare, so it shouldn't be that big a deal.
1561 int wpos = mWindows.indexOf(win);
1562 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001563 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001564 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001566 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 reAddWindowLocked(wpos, win);
1568 }
1569 }
Romain Guy06882f82009-06-10 13:36:04 -07001570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 void logWindowList(String prefix) {
1572 int N = mWindows.size();
1573 while (N > 0) {
1574 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001575 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 }
1577 }
Romain Guy06882f82009-06-10 13:36:04 -07001578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 void moveInputMethodDialogsLocked(int pos) {
1580 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001583 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 for (int i=0; i<N; i++) {
1585 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1586 }
1587 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001588 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 logWindowList(" ");
1590 }
Romain Guy06882f82009-06-10 13:36:04 -07001591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 if (pos >= 0) {
1593 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1594 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001595 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 if (wp == mInputMethodWindow) {
1597 pos++;
1598 }
1599 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001600 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 for (int i=0; i<N; i++) {
1602 WindowState win = dialogs.get(i);
1603 win.mTargetAppToken = targetAppToken;
1604 pos = reAddWindowLocked(pos, win);
1605 }
1606 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001607 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 logWindowList(" ");
1609 }
1610 return;
1611 }
1612 for (int i=0; i<N; i++) {
1613 WindowState win = dialogs.get(i);
1614 win.mTargetAppToken = null;
1615 reAddWindowToListInOrderLocked(win);
1616 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001617 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 logWindowList(" ");
1619 }
1620 }
1621 }
Romain Guy06882f82009-06-10 13:36:04 -07001622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1624 final WindowState imWin = mInputMethodWindow;
1625 final int DN = mInputMethodDialogs.size();
1626 if (imWin == null && DN == 0) {
1627 return false;
1628 }
Romain Guy06882f82009-06-10 13:36:04 -07001629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1631 if (imPos >= 0) {
1632 // In this case, the input method windows are to be placed
1633 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 // First check to see if the input method windows are already
1636 // located here, and contiguous.
1637 final int N = mWindows.size();
1638 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001639 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 // Figure out the actual input method window that should be
1642 // at the bottom of their stack.
1643 WindowState baseImWin = imWin != null
1644 ? imWin : mInputMethodDialogs.get(0);
1645 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001646 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 if (cw.mSubLayer < 0) baseImWin = cw;
1648 }
Romain Guy06882f82009-06-10 13:36:04 -07001649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 if (firstImWin == baseImWin) {
1651 // The windows haven't moved... but are they still contiguous?
1652 // First find the top IM window.
1653 int pos = imPos+1;
1654 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001655 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 break;
1657 }
1658 pos++;
1659 }
1660 pos++;
1661 // Now there should be no more input method windows above.
1662 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001663 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001664 break;
1665 }
1666 pos++;
1667 }
1668 if (pos >= N) {
1669 // All is good!
1670 return false;
1671 }
1672 }
Romain Guy06882f82009-06-10 13:36:04 -07001673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 if (imWin != null) {
1675 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001676 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 logWindowList(" ");
1678 }
1679 imPos = tmpRemoveWindowLocked(imPos, imWin);
1680 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001681 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 logWindowList(" ");
1683 }
1684 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1685 reAddWindowLocked(imPos, imWin);
1686 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001687 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688 logWindowList(" ");
1689 }
1690 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1691 } else {
1692 moveInputMethodDialogsLocked(imPos);
1693 }
Romain Guy06882f82009-06-10 13:36:04 -07001694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 } else {
1696 // In this case, the input method windows go in a fixed layer,
1697 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 tmpRemoveWindowLocked(0, imWin);
1702 imWin.mTargetAppToken = null;
1703 reAddWindowToListInOrderLocked(imWin);
1704 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001705 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 logWindowList(" ");
1707 }
1708 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1709 } else {
1710 moveInputMethodDialogsLocked(-1);;
1711 }
Romain Guy06882f82009-06-10 13:36:04 -07001712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 }
Romain Guy06882f82009-06-10 13:36:04 -07001714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 if (needAssignLayers) {
1716 assignLayersLocked();
1717 }
Romain Guy06882f82009-06-10 13:36:04 -07001718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 return true;
1720 }
Romain Guy06882f82009-06-10 13:36:04 -07001721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 void adjustInputMethodDialogsLocked() {
1723 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1724 }
Romain Guy06882f82009-06-10 13:36:04 -07001725
Dianne Hackborn25994b42009-09-04 14:21:19 -07001726 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001727 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001728 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1729 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1730 ? wallpaperTarget.mAppToken.animation : null)
1731 + " upper=" + mUpperWallpaperTarget
1732 + " lower=" + mLowerWallpaperTarget);
1733 return (wallpaperTarget != null
1734 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1735 && wallpaperTarget.mAppToken.animation != null)))
1736 || mUpperWallpaperTarget != null
1737 || mLowerWallpaperTarget != null;
1738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001740 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1741 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001743 int adjustWallpaperWindowsLocked() {
1744 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 final int dw = mDisplay.getWidth();
1747 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001749 // First find top-most window that has asked to be on top of the
1750 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001751 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001752 int N = localmWindows.size();
1753 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001754 WindowState foundW = null;
1755 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001756 WindowState topCurW = null;
1757 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001758 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001759 int i = N;
1760 while (i > 0) {
1761 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001762 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001763 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1764 if (topCurW == null) {
1765 topCurW = w;
1766 topCurI = i;
1767 }
1768 continue;
1769 }
1770 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001771 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001772 // If this window's app token is hidden and not animating,
1773 // it is of no interest to us.
1774 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001775 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001776 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001777 continue;
1778 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001779 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001780 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001781 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1782 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001783 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001784 && (mWallpaperTarget == w
1785 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001786 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001787 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001788 foundW = w;
1789 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001790 if (w == mWallpaperTarget && ((w.mAppToken != null
1791 && w.mAppToken.animation != null)
1792 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001793 // The current wallpaper target is animating, so we'll
1794 // look behind it for another possible target and figure
1795 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001796 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001798 continue;
1799 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001800 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001801 } else if (w == mWindowDetachedWallpaper) {
1802 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001803 }
1804 }
1805
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001806 if (foundW == null && windowDetachedI >= 0) {
1807 if (DEBUG_WALLPAPER) Slog.v(TAG,
1808 "Found animating detached wallpaper activity: #" + i + "=" + w);
1809 foundW = w;
1810 foundI = windowDetachedI;
1811 }
1812
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001813 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001814 // If we are currently waiting for an app transition, and either
1815 // the current target or the next target are involved with it,
1816 // then hold off on doing anything with the wallpaper.
1817 // Note that we are checking here for just whether the target
1818 // is part of an app token... which is potentially overly aggressive
1819 // (the app token may not be involved in the transition), but good
1820 // enough (we'll just wait until whatever transition is pending
1821 // executes).
1822 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001823 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001824 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001825 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001826 }
1827 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001828 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001829 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001830 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001831 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001832 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001833
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001834 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001835 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001836 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001837 + " oldTarget: " + mWallpaperTarget);
1838 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001839
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001840 mLowerWallpaperTarget = null;
1841 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001842
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001843 WindowState oldW = mWallpaperTarget;
1844 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001845
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001846 // Now what is happening... if the current and new targets are
1847 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001848 if (foundW != null && oldW != null) {
1849 boolean oldAnim = oldW.mAnimation != null
1850 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1851 boolean foundAnim = foundW.mAnimation != null
1852 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001853 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001854 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001855 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001856 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001857 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001858 int oldI = localmWindows.indexOf(oldW);
1859 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001861 }
1862 if (oldI >= 0) {
1863 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001864 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001865 + "=" + oldW + "; new#" + foundI
1866 + "=" + foundW);
1867 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001868
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001869 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001870 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001871 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001872 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001873 }
1874 mWallpaperTarget = oldW;
1875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001876
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001877 // Now set the upper and lower wallpaper targets
1878 // correctly, and make sure that we are positioning
1879 // the wallpaper below the lower.
1880 if (foundI > oldI) {
1881 // The new target is on top of the old one.
1882 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001884 }
1885 mUpperWallpaperTarget = foundW;
1886 mLowerWallpaperTarget = oldW;
1887 foundW = oldW;
1888 foundI = oldI;
1889 } else {
1890 // The new target is below the old one.
1891 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001892 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001893 }
1894 mUpperWallpaperTarget = oldW;
1895 mLowerWallpaperTarget = foundW;
1896 }
1897 }
1898 }
1899 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001900
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001901 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001902 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001903 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1904 || (mLowerWallpaperTarget.mAppToken != null
1905 && mLowerWallpaperTarget.mAppToken.animation != null);
1906 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1907 || (mUpperWallpaperTarget.mAppToken != null
1908 && mUpperWallpaperTarget.mAppToken.animation != null);
1909 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001910 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001911 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001912 }
1913 mLowerWallpaperTarget = null;
1914 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001915 }
1916 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001917
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001918 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001919 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001920 // The window is visible to the compositor... but is it visible
1921 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001922 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001923 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001924
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001925 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001926 // its layer adjustment. Only do this if we are not transfering
1927 // between two wallpaper targets.
1928 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001929 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001930 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001931
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001932 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1933 * TYPE_LAYER_MULTIPLIER
1934 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001935
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001936 // Now w is the window we are supposed to be behind... but we
1937 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001938 // AND any starting window associated with it, AND below the
1939 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001940 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001941 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001942 if (wb.mBaseLayer < maxLayer &&
1943 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001944 (foundW.mAttachedWindow == null ||
1945 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001946 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001947 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001948 // This window is not related to the previous one in any
1949 // interesting way, so stop here.
1950 break;
1951 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001952 foundW = wb;
1953 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001954 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001955 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001956 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001958
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001959 if (foundW == null && topCurW != null) {
1960 // There is no wallpaper target, so it goes at the bottom.
1961 // We will assume it is the same place as last time, if known.
1962 foundW = topCurW;
1963 foundI = topCurI+1;
1964 } else {
1965 // Okay i is the position immediately above the wallpaper. Look at
1966 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001967 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001968 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001969
Dianne Hackborn284ac932009-08-28 10:34:25 -07001970 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001971 if (mWallpaperTarget.mWallpaperX >= 0) {
1972 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001973 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001974 }
1975 if (mWallpaperTarget.mWallpaperY >= 0) {
1976 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001977 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001978 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001979 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001980
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 // Start stepping backwards from here, ensuring that our wallpaper windows
1982 // are correctly placed.
1983 int curTokenIndex = mWallpaperTokens.size();
1984 while (curTokenIndex > 0) {
1985 curTokenIndex--;
1986 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001987 if (token.hidden == visible) {
1988 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1989 token.hidden = !visible;
1990 // Need to do a layout to ensure the wallpaper now has the
1991 // correct size.
1992 mLayoutNeeded = true;
1993 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001994
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001995 int curWallpaperIndex = token.windows.size();
1996 while (curWallpaperIndex > 0) {
1997 curWallpaperIndex--;
1998 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001999
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002000 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002001 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002002 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002003
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002004 // First, make sure the client has the current visibility
2005 // state.
2006 if (wallpaper.mWallpaperVisible != visible) {
2007 wallpaper.mWallpaperVisible = visible;
2008 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002009 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002010 "Setting visibility of wallpaper " + wallpaper
2011 + ": " + visible);
2012 wallpaper.mClient.dispatchAppVisibility(visible);
2013 } catch (RemoteException e) {
2014 }
2015 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002016
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002017 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002018 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002019 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002020
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002021 // First, if this window is at the current index, then all
2022 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002023 if (wallpaper == foundW) {
2024 foundI--;
2025 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002026 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002027 continue;
2028 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002029
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002030 // The window didn't match... the current wallpaper window,
2031 // wherever it is, is in the wrong place, so make sure it is
2032 // not in the list.
2033 int oldIndex = localmWindows.indexOf(wallpaper);
2034 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002035 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002036 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002037 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002038 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002039 if (oldIndex < foundI) {
2040 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002041 }
2042 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002043
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002044 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002045 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2046 Slog.v(TAG, "Moving wallpaper " + wallpaper
2047 + " from " + oldIndex + " to " + foundI);
2048 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002049
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002050 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002051 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002052 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002053 }
2054 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002055
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002056 return changed;
2057 }
2058
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002059 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002060 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002061 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002062 mWallpaperAnimLayerAdjustment = adj;
2063 int curTokenIndex = mWallpaperTokens.size();
2064 while (curTokenIndex > 0) {
2065 curTokenIndex--;
2066 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2067 int curWallpaperIndex = token.windows.size();
2068 while (curWallpaperIndex > 0) {
2069 curWallpaperIndex--;
2070 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2071 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002072 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002073 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002074 }
2075 }
2076 }
2077
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002078 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2079 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002080 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002081 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002082 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002083 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002084 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2085 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2086 changed = wallpaperWin.mXOffset != offset;
2087 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002088 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002089 + wallpaperWin + " x: " + offset);
2090 wallpaperWin.mXOffset = offset;
2091 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002092 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002093 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002094 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002095 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002096 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002097
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002098 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002099 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002100 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2101 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2102 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002103 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002104 + wallpaperWin + " y: " + offset);
2105 changed = true;
2106 wallpaperWin.mYOffset = offset;
2107 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002108 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002109 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002110 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002111 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002112 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002113
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002114 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002115 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002116 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002117 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2118 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002119 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002120 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002121 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002122 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002123 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2124 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002125 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002126 if (mWaitingOnWallpaper != null) {
2127 long start = SystemClock.uptimeMillis();
2128 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2129 < start) {
2130 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002131 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002132 "Waiting for offset complete...");
2133 mWindowMap.wait(WALLPAPER_TIMEOUT);
2134 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002135 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002136 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002137 if ((start+WALLPAPER_TIMEOUT)
2138 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002139 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002140 + wallpaperWin);
2141 mLastWallpaperTimeoutTime = start;
2142 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002143 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002144 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002145 }
2146 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002147 } catch (RemoteException e) {
2148 }
2149 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002150
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002151 return changed;
2152 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002153
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002154 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002155 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002156 if (mWaitingOnWallpaper != null &&
2157 mWaitingOnWallpaper.mClient.asBinder() == window) {
2158 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002159 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002160 }
2161 }
2162 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002163
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002164 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002165 final int dw = mDisplay.getWidth();
2166 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002167
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002168 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002169
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002170 WindowState target = mWallpaperTarget;
2171 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002172 if (target.mWallpaperX >= 0) {
2173 mLastWallpaperX = target.mWallpaperX;
2174 } else if (changingTarget.mWallpaperX >= 0) {
2175 mLastWallpaperX = changingTarget.mWallpaperX;
2176 }
2177 if (target.mWallpaperY >= 0) {
2178 mLastWallpaperY = target.mWallpaperY;
2179 } else if (changingTarget.mWallpaperY >= 0) {
2180 mLastWallpaperY = changingTarget.mWallpaperY;
2181 }
2182 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002183
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002184 int curTokenIndex = mWallpaperTokens.size();
2185 while (curTokenIndex > 0) {
2186 curTokenIndex--;
2187 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2188 int curWallpaperIndex = token.windows.size();
2189 while (curWallpaperIndex > 0) {
2190 curWallpaperIndex--;
2191 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2192 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2193 wallpaper.computeShownFrameLocked();
2194 changed = true;
2195 // We only want to be synchronous with one wallpaper.
2196 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002197 }
2198 }
2199 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002200
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002201 return changed;
2202 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002203
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002204 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002205 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002206 final int dw = mDisplay.getWidth();
2207 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002208
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002209 int curTokenIndex = mWallpaperTokens.size();
2210 while (curTokenIndex > 0) {
2211 curTokenIndex--;
2212 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002213 if (token.hidden == visible) {
2214 token.hidden = !visible;
2215 // Need to do a layout to ensure the wallpaper now has the
2216 // correct size.
2217 mLayoutNeeded = true;
2218 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002219
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002220 int curWallpaperIndex = token.windows.size();
2221 while (curWallpaperIndex > 0) {
2222 curWallpaperIndex--;
2223 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2224 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002225 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002226 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002227
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002228 if (wallpaper.mWallpaperVisible != visible) {
2229 wallpaper.mWallpaperVisible = visible;
2230 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002231 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002232 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002233 + ": " + visible);
2234 wallpaper.mClient.dispatchAppVisibility(visible);
2235 } catch (RemoteException e) {
2236 }
2237 }
2238 }
2239 }
2240 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 public int addWindow(Session session, IWindow client,
2243 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002244 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 int res = mPolicy.checkAddPermission(attrs);
2246 if (res != WindowManagerImpl.ADD_OKAY) {
2247 return res;
2248 }
Romain Guy06882f82009-06-10 13:36:04 -07002249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 boolean reportNewConfig = false;
2251 WindowState attachedWindow = null;
2252 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002253 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002257 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 }
Romain Guy06882f82009-06-10 13:36:04 -07002259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002261 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2263 }
2264
2265 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002266 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002268 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 + attrs.token + ". Aborting.");
2270 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2271 }
2272 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2273 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002274 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 + attrs.token + ". Aborting.");
2276 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2277 }
2278 }
2279
2280 boolean addToken = false;
2281 WindowToken token = mTokenMap.get(attrs.token);
2282 if (token == null) {
2283 if (attrs.type >= FIRST_APPLICATION_WINDOW
2284 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002285 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 + attrs.token + ". Aborting.");
2287 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2288 }
2289 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002290 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 + attrs.token + ". Aborting.");
2292 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2293 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002294 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002295 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002296 + attrs.token + ". Aborting.");
2297 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 token = new WindowToken(attrs.token, -1, false);
2300 addToken = true;
2301 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2302 && attrs.type <= LAST_APPLICATION_WINDOW) {
2303 AppWindowToken atoken = token.appWindowToken;
2304 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002305 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 + token + ". Aborting.");
2307 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2308 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002309 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 + token + ". Aborting.");
2311 return WindowManagerImpl.ADD_APP_EXITING;
2312 }
2313 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2314 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002315 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2317 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2318 }
2319 } else if (attrs.type == TYPE_INPUT_METHOD) {
2320 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002321 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 + attrs.token + ". Aborting.");
2323 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2324 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002325 } else if (attrs.type == TYPE_WALLPAPER) {
2326 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002327 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002328 + attrs.token + ". Aborting.");
2329 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2330 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 }
2332
2333 win = new WindowState(session, client, token,
2334 attachedWindow, attrs, viewVisibility);
2335 if (win.mDeathRecipient == null) {
2336 // Client has apparently died, so there is no reason to
2337 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002338 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 + " that is dead, aborting.");
2340 return WindowManagerImpl.ADD_APP_EXITING;
2341 }
2342
2343 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 res = mPolicy.prepareAddWindowLw(win, attrs);
2346 if (res != WindowManagerImpl.ADD_OKAY) {
2347 return res;
2348 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002349
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002350 if (outInputChannel != null) {
2351 String name = win.makeInputChannelName();
2352 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2353 win.mInputChannel = inputChannels[0];
2354 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2355
Jeff Brown928e0542011-01-10 11:17:36 -08002356 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358
2359 // From now on, no exceptions or errors allowed!
2360
2361 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002362
Dianne Hackborn5132b372010-07-29 12:51:35 -07002363 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 if (addToken) {
2366 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 }
2368 win.attach();
2369 mWindowMap.put(client.asBinder(), win);
2370
2371 if (attrs.type == TYPE_APPLICATION_STARTING &&
2372 token.appWindowToken != null) {
2373 token.appWindowToken.startingWindow = win;
2374 }
2375
2376 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 if (attrs.type == TYPE_INPUT_METHOD) {
2379 mInputMethodWindow = win;
2380 addInputMethodWindowToListLocked(win);
2381 imMayMove = false;
2382 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2383 mInputMethodDialogs.add(win);
2384 addWindowToListInOrderLocked(win, true);
2385 adjustInputMethodDialogsLocked();
2386 imMayMove = false;
2387 } else {
2388 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002389 if (attrs.type == TYPE_WALLPAPER) {
2390 mLastWallpaperTimeoutTime = 0;
2391 adjustWallpaperWindowsLocked();
2392 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002393 adjustWallpaperWindowsLocked();
2394 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 }
Romain Guy06882f82009-06-10 13:36:04 -07002396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 if (mInTouchMode) {
2402 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2403 }
2404 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2405 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2406 }
Romain Guy06882f82009-06-10 13:36:04 -07002407
Jeff Brown2e44b072011-01-24 15:21:56 -08002408 mInputMonitor.setUpdateInputWindowsNeededLw();
2409
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002410 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002412 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2413 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002414 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 imMayMove = false;
2416 }
2417 }
Romain Guy06882f82009-06-10 13:36:04 -07002418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002420 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 }
Romain Guy06882f82009-06-10 13:36:04 -07002422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 assignLayersLocked();
2424 // Don't do layout here, the window must call
2425 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 //dump();
2428
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002429 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002430 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002431 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002432 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002433
Joe Onorato8a9b2202010-02-26 18:56:32 -08002434 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 TAG, "New client " + client.asBinder()
2436 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002437
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002438 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002439 reportNewConfig = true;
2440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 }
2442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 if (reportNewConfig) {
2444 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 return res;
2450 }
Romain Guy06882f82009-06-10 13:36:04 -07002451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 public void removeWindow(Session session, IWindow client) {
2453 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002454 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 if (win == null) {
2456 return;
2457 }
2458 removeWindowLocked(session, win);
2459 }
2460 }
Romain Guy06882f82009-06-10 13:36:04 -07002461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 public void removeWindowLocked(Session session, WindowState win) {
2463
Joe Onorato8a9b2202010-02-26 18:56:32 -08002464 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 TAG, "Remove " + win + " client="
2466 + Integer.toHexString(System.identityHashCode(
2467 win.mClient.asBinder()))
2468 + ", surface=" + win.mSurface);
2469
2470 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002471
2472 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002473
Joe Onorato8a9b2202010-02-26 18:56:32 -08002474 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2476 + " mExiting=" + win.mExiting
2477 + " isAnimating=" + win.isAnimating()
2478 + " app-animation="
2479 + (win.mAppToken != null ? win.mAppToken.animation : null)
2480 + " inPendingTransaction="
2481 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2482 + " mDisplayFrozen=" + mDisplayFrozen);
2483 // Visibility of the removed window. Will be used later to update orientation later on.
2484 boolean wasVisible = false;
2485 // First, see if we need to run an animation. If we do, we have
2486 // to hold off on removing the window until the animation is done.
2487 // If the display is frozen, just remove immediately, since the
2488 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002489 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 // If we are not currently running the exit animation, we
2491 // need to see about starting one.
2492 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2495 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2496 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2497 }
2498 // Try starting an animation.
2499 if (applyAnimationLocked(win, transit, false)) {
2500 win.mExiting = true;
2501 }
2502 }
2503 if (win.mExiting || win.isAnimating()) {
2504 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002505 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 win.mExiting = true;
2507 win.mRemoveOnExit = true;
2508 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002509 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2510 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002512 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 if (win.mAppToken != null) {
2514 win.mAppToken.updateReportedVisibilityLocked();
2515 }
2516 //dump();
2517 Binder.restoreCallingIdentity(origId);
2518 return;
2519 }
2520 }
2521
2522 removeWindowInnerLocked(session, win);
2523 // Removing a visible window will effect the computed orientation
2524 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002525 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002526 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002527 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002528 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002530 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 Binder.restoreCallingIdentity(origId);
2532 }
Romain Guy06882f82009-06-10 13:36:04 -07002533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002535 if (win.mRemoved) {
2536 // Nothing to do.
2537 return;
2538 }
2539
2540 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2541 WindowState cwin = win.mChildWindows.get(i);
2542 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2543 + win);
2544 removeWindowInnerLocked(cwin.mSession, cwin);
2545 }
2546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 if (mInputMethodTarget == win) {
2550 moveInputMethodWindowsIfNeededLocked(false);
2551 }
Romain Guy06882f82009-06-10 13:36:04 -07002552
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002553 if (false) {
2554 RuntimeException e = new RuntimeException("here");
2555 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002556 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 mPolicy.removeWindowLw(win);
2560 win.removeLocked();
2561
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002562 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 mWindowMap.remove(win.mClient.asBinder());
2564 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002565 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002566 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002567 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568
2569 if (mInputMethodWindow == win) {
2570 mInputMethodWindow = null;
2571 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2572 mInputMethodDialogs.remove(win);
2573 }
Romain Guy06882f82009-06-10 13:36:04 -07002574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 final WindowToken token = win.mToken;
2576 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002577 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 token.windows.remove(win);
2579 if (atoken != null) {
2580 atoken.allAppWindows.remove(win);
2581 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002582 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 TAG, "**** Removing window " + win + ": count="
2584 + token.windows.size());
2585 if (token.windows.size() == 0) {
2586 if (!token.explicit) {
2587 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 } else if (atoken != null) {
2589 atoken.firstWindowDrawn = false;
2590 }
2591 }
2592
2593 if (atoken != null) {
2594 if (atoken.startingWindow == win) {
2595 atoken.startingWindow = null;
2596 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2597 // If this is the last window and we had requested a starting
2598 // transition window, well there is no point now.
2599 atoken.startingData = null;
2600 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2601 // If this is the last window except for a starting transition
2602 // window, we need to get rid of the starting transition.
2603 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002604 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 + ": no more real windows");
2606 }
2607 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2608 mH.sendMessage(m);
2609 }
2610 }
Romain Guy06882f82009-06-10 13:36:04 -07002611
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002612 if (win.mAttrs.type == TYPE_WALLPAPER) {
2613 mLastWallpaperTimeoutTime = 0;
2614 adjustWallpaperWindowsLocked();
2615 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002616 adjustWallpaperWindowsLocked();
2617 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 if (!mInLayout) {
2620 assignLayersLocked();
2621 mLayoutNeeded = true;
2622 performLayoutAndPlaceSurfacesLocked();
2623 if (win.mAppToken != null) {
2624 win.mAppToken.updateReportedVisibilityLocked();
2625 }
2626 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002627
Jeff Brown2e44b072011-01-24 15:21:56 -08002628 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 }
2630
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002631 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2632 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2633 + ": " + msg + " / " + w.mAttrs.getTitle();
2634 if (where != null) {
2635 Slog.i(TAG, str, where);
2636 } else {
2637 Slog.i(TAG, str);
2638 }
2639 }
2640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2642 long origId = Binder.clearCallingIdentity();
2643 try {
2644 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002645 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002647 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2648 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 Surface.openTransaction();
2650 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002651 if (SHOW_TRANSACTIONS) logSurface(w,
2652 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 w.mSurface.setTransparentRegionHint(region);
2654 } finally {
2655 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002656 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2657 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 }
2659 }
2660 }
2661 } finally {
2662 Binder.restoreCallingIdentity(origId);
2663 }
2664 }
2665
2666 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002667 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002668 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 long origId = Binder.clearCallingIdentity();
2670 try {
2671 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002672 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002673 if (w != null) {
2674 w.mGivenInsetsPending = false;
2675 w.mGivenContentInsets.set(contentInsets);
2676 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002677 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002678 w.mTouchableInsets = touchableInsets;
2679 mLayoutNeeded = true;
2680 performLayoutAndPlaceSurfacesLocked();
2681 }
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(origId);
2685 }
2686 }
Romain Guy06882f82009-06-10 13:36:04 -07002687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 public void getWindowDisplayFrame(Session session, IWindow client,
2689 Rect outDisplayFrame) {
2690 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002691 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 if (win == null) {
2693 outDisplayFrame.setEmpty();
2694 return;
2695 }
2696 outDisplayFrame.set(win.mDisplayFrame);
2697 }
2698 }
2699
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002700 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2701 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002702 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2703 window.mWallpaperX = x;
2704 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002705 window.mWallpaperXStep = xStep;
2706 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002707 if (updateWallpaperOffsetLocked(window, true)) {
2708 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002709 }
2710 }
2711 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002712
Dianne Hackborn75804932009-10-20 20:15:20 -07002713 void wallpaperCommandComplete(IBinder window, Bundle result) {
2714 synchronized (mWindowMap) {
2715 if (mWaitingOnWallpaper != null &&
2716 mWaitingOnWallpaper.mClient.asBinder() == window) {
2717 mWaitingOnWallpaper = null;
2718 mWindowMap.notifyAll();
2719 }
2720 }
2721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002722
Dianne Hackborn75804932009-10-20 20:15:20 -07002723 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2724 String action, int x, int y, int z, Bundle extras, boolean sync) {
2725 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2726 || window == mUpperWallpaperTarget) {
2727 boolean doWait = sync;
2728 int curTokenIndex = mWallpaperTokens.size();
2729 while (curTokenIndex > 0) {
2730 curTokenIndex--;
2731 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2732 int curWallpaperIndex = token.windows.size();
2733 while (curWallpaperIndex > 0) {
2734 curWallpaperIndex--;
2735 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2736 try {
2737 wallpaper.mClient.dispatchWallpaperCommand(action,
2738 x, y, z, extras, sync);
2739 // We only want to be synchronous with one wallpaper.
2740 sync = false;
2741 } catch (RemoteException e) {
2742 }
2743 }
2744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002745
Dianne Hackborn75804932009-10-20 20:15:20 -07002746 if (doWait) {
2747 // XXX Need to wait for result.
2748 }
2749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002750
Dianne Hackborn75804932009-10-20 20:15:20 -07002751 return null;
2752 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 public int relayoutWindow(Session session, IWindow client,
2755 WindowManager.LayoutParams attrs, int requestedWidth,
2756 int requestedHeight, int viewVisibility, boolean insetsPending,
2757 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002758 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002759 boolean displayed = false;
2760 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002761 boolean configChanged;
Joe Onoratoac0ee892011-01-30 15:38:30 -08002762
2763 // if they don't have this permission, mask out the status bar bits
2764 if (attrs != null) {
2765 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
2766 != PackageManager.PERMISSION_GRANTED) {
2767 attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2768 attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2769 }
2770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002774 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 if (win == null) {
2776 return 0;
2777 }
2778 win.mRequestedWidth = requestedWidth;
2779 win.mRequestedHeight = requestedHeight;
2780
2781 if (attrs != null) {
2782 mPolicy.adjustWindowParamsLw(attrs);
2783 }
Romain Guy06882f82009-06-10 13:36:04 -07002784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 int attrChanges = 0;
2786 int flagChanges = 0;
2787 if (attrs != null) {
2788 flagChanges = win.mAttrs.flags ^= attrs.flags;
2789 attrChanges = win.mAttrs.copyFrom(attrs);
2790 }
2791
Joe Onorato8a9b2202010-02-26 18:56:32 -08002792 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002793
2794 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2795 win.mAlpha = attrs.alpha;
2796 }
2797
2798 final boolean scaledWindow =
2799 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2800
2801 if (scaledWindow) {
2802 // requested{Width|Height} Surface's physical size
2803 // attrs.{width|height} Size on screen
2804 win.mHScale = (attrs.width != requestedWidth) ?
2805 (attrs.width / (float)requestedWidth) : 1.0f;
2806 win.mVScale = (attrs.height != requestedHeight) ?
2807 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002808 } else {
2809 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 }
2811
2812 boolean imMayMove = (flagChanges&(
2813 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2814 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 boolean focusMayChange = win.mViewVisibility != viewVisibility
2817 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2818 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002819
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002820 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2821 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 win.mRelayoutCalled = true;
2824 final int oldVisibility = win.mViewVisibility;
2825 win.mViewVisibility = viewVisibility;
2826 if (viewVisibility == View.VISIBLE &&
2827 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2828 displayed = !win.isVisibleLw();
2829 if (win.mExiting) {
2830 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002831 if (win.mAnimation != null) {
2832 win.mAnimation.cancel();
2833 win.mAnimation = null;
2834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 }
2836 if (win.mDestroying) {
2837 win.mDestroying = false;
2838 mDestroySurface.remove(win);
2839 }
2840 if (oldVisibility == View.GONE) {
2841 win.mEnterAnimationPending = true;
2842 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002843 if (displayed) {
2844 if (win.mSurface != null && !win.mDrawPending
2845 && !win.mCommitDrawPending && !mDisplayFrozen
2846 && mPolicy.isScreenOn()) {
2847 applyEnterAnimationLocked(win);
2848 }
2849 if ((win.mAttrs.flags
2850 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2851 if (DEBUG_VISIBILITY) Slog.v(TAG,
2852 "Relayout window turning screen on: " + win);
2853 win.mTurnOnScreen = true;
2854 }
2855 int diff = 0;
2856 if (win.mConfiguration != mCurConfiguration
2857 && (win.mConfiguration == null
2858 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2859 win.mConfiguration = mCurConfiguration;
2860 if (DEBUG_CONFIGURATION) {
2861 Slog.i(TAG, "Window " + win + " visible with new config: "
2862 + win.mConfiguration + " / 0x"
2863 + Integer.toHexString(diff));
2864 }
2865 outConfig.setTo(mCurConfiguration);
2866 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002867 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2869 // To change the format, we need to re-build the surface.
2870 win.destroySurfaceLocked();
2871 displayed = true;
2872 }
2873 try {
2874 Surface surface = win.createSurfaceLocked();
2875 if (surface != null) {
2876 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002877 win.mReportDestroySurface = false;
2878 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002879 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002880 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002882 // For some reason there isn't a surface. Clear the
2883 // caller's object so they see the same state.
2884 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 }
2886 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002887 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002888
Joe Onorato8a9b2202010-02-26 18:56:32 -08002889 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002890 + client + " (" + win.mAttrs.getTitle() + ")",
2891 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 Binder.restoreCallingIdentity(origId);
2893 return 0;
2894 }
2895 if (displayed) {
2896 focusMayChange = true;
2897 }
2898 if (win.mAttrs.type == TYPE_INPUT_METHOD
2899 && mInputMethodWindow == null) {
2900 mInputMethodWindow = win;
2901 imMayMove = true;
2902 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002903 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2904 && win.mAppToken != null
2905 && win.mAppToken.startingWindow != null) {
2906 // Special handling of starting window over the base
2907 // window of the app: propagate lock screen flags to it,
2908 // to provide the correct semantics while starting.
2909 final int mask =
2910 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002911 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2912 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002913 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2914 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2915 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 } else {
2917 win.mEnterAnimationPending = false;
2918 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002919 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002920 + ": mExiting=" + win.mExiting
2921 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 // If we are not currently running the exit animation, we
2923 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002924 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 // Try starting an animation; if there isn't one, we
2926 // can destroy the surface right away.
2927 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2928 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2929 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2930 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002931 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002933 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 } else if (win.isAnimating()) {
2936 // Currently in a hide animation... turn this into
2937 // an exit.
2938 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002939 } else if (win == mWallpaperTarget) {
2940 // If the wallpaper is currently behind this
2941 // window, we need to change both of them inside
2942 // of a transaction to avoid artifacts.
2943 win.mExiting = true;
2944 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 } else {
2946 if (mInputMethodWindow == win) {
2947 mInputMethodWindow = null;
2948 }
2949 win.destroySurfaceLocked();
2950 }
2951 }
2952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002953
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002954 if (win.mSurface == null || (win.getAttrs().flags
2955 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2956 || win.mSurfacePendingDestroy) {
2957 // We are being called from a local process, which
2958 // means outSurface holds its current surface. Ensure the
2959 // surface object is cleared, but we don't want it actually
2960 // destroyed at this point.
2961 win.mSurfacePendingDestroy = false;
2962 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002963 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002964 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002965 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002966 "Keeping surface, will report destroy: " + win);
2967 win.mReportDestroySurface = true;
2968 outSurface.copyFrom(win.mSurface);
2969 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002970 }
2971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 if (focusMayChange) {
2973 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002974 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2975 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 imMayMove = false;
2977 }
2978 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2979 }
Romain Guy06882f82009-06-10 13:36:04 -07002980
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002981 // updateFocusedWindowLocked() already assigned layers so we only need to
2982 // reassign them at this point if the IM window state gets shuffled
2983 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002986 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2987 // Little hack here -- we -should- be able to rely on the
2988 // function to return true if the IME has moved and needs
2989 // its layer recomputed. However, if the IME was hidden
2990 // and isn't actually moved in the list, its layer may be
2991 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 assignLayers = true;
2993 }
2994 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002995 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002996 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002997 assignLayers = true;
2998 }
2999 }
Romain Guy06882f82009-06-10 13:36:04 -07003000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 mLayoutNeeded = true;
3002 win.mGivenInsetsPending = insetsPending;
3003 if (assignLayers) {
3004 assignLayersLocked();
3005 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003006 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07003008 if (displayed && win.mIsWallpaper) {
3009 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07003010 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07003011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 if (win.mAppToken != null) {
3013 win.mAppToken.updateReportedVisibilityLocked();
3014 }
3015 outFrame.set(win.mFrame);
3016 outContentInsets.set(win.mContentInsets);
3017 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003018 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07003020 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 + ", requestedHeight=" + requestedHeight
3022 + ", viewVisibility=" + viewVisibility
3023 + "\nRelayout returning frame=" + outFrame
3024 + ", surface=" + outSurface);
3025
Joe Onorato8a9b2202010-02-26 18:56:32 -08003026 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3028
3029 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003030
Jeff Brown2e44b072011-01-24 15:21:56 -08003031 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 }
3033
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003034 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 sendNewConfiguration();
3036 }
Romain Guy06882f82009-06-10 13:36:04 -07003037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3041 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3042 }
3043
3044 public void finishDrawingWindow(Session session, IWindow client) {
3045 final long origId = Binder.clearCallingIdentity();
3046 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003047 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003049 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3050 adjustWallpaperWindowsLocked();
3051 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003052 mLayoutNeeded = true;
3053 performLayoutAndPlaceSurfacesLocked();
3054 }
3055 }
3056 Binder.restoreCallingIdentity(origId);
3057 }
3058
3059 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003060 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 + (lp != null ? lp.packageName : null)
3062 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3063 if (lp != null && lp.windowAnimations != 0) {
3064 // If this is a system resource, don't try to load it from the
3065 // application resources. It is nice to avoid loading application
3066 // resources if we can.
3067 String packageName = lp.packageName != null ? lp.packageName : "android";
3068 int resId = lp.windowAnimations;
3069 if ((resId&0xFF000000) == 0x01000000) {
3070 packageName = "android";
3071 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003072 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 + packageName);
3074 return AttributeCache.instance().get(packageName, resId,
3075 com.android.internal.R.styleable.WindowAnimation);
3076 }
3077 return null;
3078 }
Romain Guy06882f82009-06-10 13:36:04 -07003079
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003080 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003081 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003082 + packageName + " resId=0x" + Integer.toHexString(resId));
3083 if (packageName != null) {
3084 if ((resId&0xFF000000) == 0x01000000) {
3085 packageName = "android";
3086 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003087 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003088 + packageName);
3089 return AttributeCache.instance().get(packageName, resId,
3090 com.android.internal.R.styleable.WindowAnimation);
3091 }
3092 return null;
3093 }
3094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095 private void applyEnterAnimationLocked(WindowState win) {
3096 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3097 if (win.mEnterAnimationPending) {
3098 win.mEnterAnimationPending = false;
3099 transit = WindowManagerPolicy.TRANSIT_ENTER;
3100 }
3101
3102 applyAnimationLocked(win, transit, true);
3103 }
3104
3105 private boolean applyAnimationLocked(WindowState win,
3106 int transit, boolean isEntrance) {
3107 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3108 // If we are trying to apply an animation, but already running
3109 // an animation of the same type, then just leave that one alone.
3110 return true;
3111 }
Romain Guy06882f82009-06-10 13:36:04 -07003112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003113 // Only apply an animation if the display isn't frozen. If it is
3114 // frozen, there is no reason to animate and it can cause strange
3115 // artifacts when we unfreeze the display if some different animation
3116 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003117 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 int anim = mPolicy.selectAnimationLw(win, transit);
3119 int attr = -1;
3120 Animation a = null;
3121 if (anim != 0) {
3122 a = AnimationUtils.loadAnimation(mContext, anim);
3123 } else {
3124 switch (transit) {
3125 case WindowManagerPolicy.TRANSIT_ENTER:
3126 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3127 break;
3128 case WindowManagerPolicy.TRANSIT_EXIT:
3129 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3130 break;
3131 case WindowManagerPolicy.TRANSIT_SHOW:
3132 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3133 break;
3134 case WindowManagerPolicy.TRANSIT_HIDE:
3135 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3136 break;
3137 }
3138 if (attr >= 0) {
3139 a = loadAnimation(win.mAttrs, attr);
3140 }
3141 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003142 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3144 + " mAnimation=" + win.mAnimation
3145 + " isEntrance=" + isEntrance);
3146 if (a != null) {
3147 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003148 RuntimeException e = null;
3149 if (!HIDE_STACK_CRAWLS) {
3150 e = new RuntimeException();
3151 e.fillInStackTrace();
3152 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003153 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 }
3155 win.setAnimation(a);
3156 win.mAnimationIsEntrance = isEntrance;
3157 }
3158 } else {
3159 win.clearAnimation();
3160 }
3161
3162 return win.mAnimation != null;
3163 }
3164
3165 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3166 int anim = 0;
3167 Context context = mContext;
3168 if (animAttr >= 0) {
3169 AttributeCache.Entry ent = getCachedAnimations(lp);
3170 if (ent != null) {
3171 context = ent.context;
3172 anim = ent.array.getResourceId(animAttr, 0);
3173 }
3174 }
3175 if (anim != 0) {
3176 return AnimationUtils.loadAnimation(context, anim);
3177 }
3178 return null;
3179 }
Romain Guy06882f82009-06-10 13:36:04 -07003180
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003181 private Animation loadAnimation(String packageName, int resId) {
3182 int anim = 0;
3183 Context context = mContext;
3184 if (resId >= 0) {
3185 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3186 if (ent != null) {
3187 context = ent.context;
3188 anim = resId;
3189 }
3190 }
3191 if (anim != 0) {
3192 return AnimationUtils.loadAnimation(context, anim);
3193 }
3194 return null;
3195 }
3196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 private boolean applyAnimationLocked(AppWindowToken wtoken,
3198 WindowManager.LayoutParams lp, int transit, boolean enter) {
3199 // Only apply an animation if the display isn't frozen. If it is
3200 // frozen, there is no reason to animate and it can cause strange
3201 // artifacts when we unfreeze the display if some different animation
3202 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003203 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003204 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003205 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003206 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003207 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003208 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003209 } else if (mNextAppTransitionPackage != null) {
3210 a = loadAnimation(mNextAppTransitionPackage, enter ?
3211 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003212 } else {
3213 int animAttr = 0;
3214 switch (transit) {
3215 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3216 animAttr = enter
3217 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3218 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3219 break;
3220 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3221 animAttr = enter
3222 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3223 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3224 break;
3225 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3226 animAttr = enter
3227 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3228 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3229 break;
3230 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3231 animAttr = enter
3232 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3233 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3234 break;
3235 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3236 animAttr = enter
3237 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3238 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3239 break;
3240 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3241 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003242 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003243 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3244 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003245 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003246 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003247 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3248 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003249 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003250 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003251 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003252 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3253 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3254 break;
3255 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3256 animAttr = enter
3257 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3258 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3259 break;
3260 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3261 animAttr = enter
3262 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3263 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003264 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003265 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003266 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003267 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003268 + " anim=" + a
3269 + " animAttr=0x" + Integer.toHexString(animAttr)
3270 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 if (a != null) {
3273 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003274 RuntimeException e = null;
3275 if (!HIDE_STACK_CRAWLS) {
3276 e = new RuntimeException();
3277 e.fillInStackTrace();
3278 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003279 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 }
3281 wtoken.setAnimation(a);
3282 }
3283 } else {
3284 wtoken.clearAnimation();
3285 }
3286
3287 return wtoken.animation != null;
3288 }
3289
3290 // -------------------------------------------------------------
3291 // Application Window Tokens
3292 // -------------------------------------------------------------
3293
3294 public void validateAppTokens(List tokens) {
3295 int v = tokens.size()-1;
3296 int m = mAppTokens.size()-1;
3297 while (v >= 0 && m >= 0) {
3298 AppWindowToken wtoken = mAppTokens.get(m);
3299 if (wtoken.removed) {
3300 m--;
3301 continue;
3302 }
3303 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003304 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3306 }
3307 v--;
3308 m--;
3309 }
3310 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003311 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 v--;
3313 }
3314 while (m >= 0) {
3315 AppWindowToken wtoken = mAppTokens.get(m);
3316 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003317 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 }
3319 m--;
3320 }
3321 }
3322
3323 boolean checkCallingPermission(String permission, String func) {
3324 // Quick check: if the calling permission is me, it's all okay.
3325 if (Binder.getCallingPid() == Process.myPid()) {
3326 return true;
3327 }
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 if (mContext.checkCallingPermission(permission)
3330 == PackageManager.PERMISSION_GRANTED) {
3331 return true;
3332 }
3333 String msg = "Permission Denial: " + func + " from pid="
3334 + Binder.getCallingPid()
3335 + ", uid=" + Binder.getCallingUid()
3336 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003337 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 return false;
3339 }
Romain Guy06882f82009-06-10 13:36:04 -07003340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 AppWindowToken findAppWindowToken(IBinder token) {
3342 WindowToken wtoken = mTokenMap.get(token);
3343 if (wtoken == null) {
3344 return null;
3345 }
3346 return wtoken.appWindowToken;
3347 }
Romain Guy06882f82009-06-10 13:36:04 -07003348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 public void addWindowToken(IBinder token, int type) {
3350 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3351 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003352 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 }
Romain Guy06882f82009-06-10 13:36:04 -07003354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 synchronized(mWindowMap) {
3356 WindowToken wtoken = mTokenMap.get(token);
3357 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003358 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 return;
3360 }
3361 wtoken = new WindowToken(token, type, true);
3362 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003363 if (type == TYPE_WALLPAPER) {
3364 mWallpaperTokens.add(wtoken);
3365 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 }
3367 }
Romain Guy06882f82009-06-10 13:36:04 -07003368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 public void removeWindowToken(IBinder token) {
3370 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3371 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003372 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 }
3374
3375 final long origId = Binder.clearCallingIdentity();
3376 synchronized(mWindowMap) {
3377 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 if (wtoken != null) {
3379 boolean delayed = false;
3380 if (!wtoken.hidden) {
3381 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 final int N = wtoken.windows.size();
3384 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 for (int i=0; i<N; i++) {
3387 WindowState win = wtoken.windows.get(i);
3388
3389 if (win.isAnimating()) {
3390 delayed = true;
3391 }
Romain Guy06882f82009-06-10 13:36:04 -07003392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 if (win.isVisibleNow()) {
3394 applyAnimationLocked(win,
3395 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003396 changed = true;
3397 }
3398 }
3399
3400 if (changed) {
3401 mLayoutNeeded = true;
3402 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003403 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3404 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 }
Romain Guy06882f82009-06-10 13:36:04 -07003406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 if (delayed) {
3408 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003409 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3410 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 }
3412 }
Romain Guy06882f82009-06-10 13:36:04 -07003413
Jeff Brown2e44b072011-01-24 15:21:56 -08003414 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003416 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417 }
3418 }
3419 Binder.restoreCallingIdentity(origId);
3420 }
3421
3422 public void addAppToken(int addPos, IApplicationToken token,
3423 int groupId, int requestedOrientation, boolean fullscreen) {
3424 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3425 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003426 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003427 }
Jeff Brown349703e2010-06-22 01:27:15 -07003428
3429 // Get the dispatching timeout here while we are not holding any locks so that it
3430 // can be cached by the AppWindowToken. The timeout value is used later by the
3431 // input dispatcher in code that does hold locks. If we did not cache the value
3432 // here we would run the chance of introducing a deadlock between the window manager
3433 // (which holds locks while updating the input dispatcher state) and the activity manager
3434 // (which holds locks while querying the application token).
3435 long inputDispatchingTimeoutNanos;
3436 try {
3437 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3438 } catch (RemoteException ex) {
3439 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3440 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3441 }
Romain Guy06882f82009-06-10 13:36:04 -07003442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443 synchronized(mWindowMap) {
3444 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3445 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003446 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 return;
3448 }
3449 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003450 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003451 wtoken.groupId = groupId;
3452 wtoken.appFullscreen = fullscreen;
3453 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003454 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003455 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003458 // Application tokens start out hidden.
3459 wtoken.hidden = true;
3460 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003462 //dump();
3463 }
3464 }
Romain Guy06882f82009-06-10 13:36:04 -07003465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 public void setAppGroupId(IBinder token, int groupId) {
3467 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3468 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003469 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 }
3471
3472 synchronized(mWindowMap) {
3473 AppWindowToken wtoken = findAppWindowToken(token);
3474 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003475 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 return;
3477 }
3478 wtoken.groupId = groupId;
3479 }
3480 }
Romain Guy06882f82009-06-10 13:36:04 -07003481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 public int getOrientationFromWindowsLocked() {
3483 int pos = mWindows.size() - 1;
3484 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003485 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 pos--;
3487 if (wtoken.mAppToken != null) {
3488 // We hit an application window. so the orientation will be determined by the
3489 // app window. No point in continuing further.
3490 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3491 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003492 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 continue;
3494 }
3495 int req = wtoken.mAttrs.screenOrientation;
3496 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3497 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3498 continue;
3499 } else {
3500 return req;
3501 }
3502 }
3503 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3504 }
Romain Guy06882f82009-06-10 13:36:04 -07003505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003507 int pos = mAppTokens.size() - 1;
3508 int curGroup = 0;
3509 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3510 boolean findingBehind = false;
3511 boolean haveGroup = false;
3512 boolean lastFullscreen = false;
3513 while (pos >= 0) {
3514 AppWindowToken wtoken = mAppTokens.get(pos);
3515 pos--;
3516 // if we're about to tear down this window and not seek for
3517 // the behind activity, don't use it for orientation
3518 if (!findingBehind
3519 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3520 continue;
3521 }
3522
3523 if (!haveGroup) {
3524 // We ignore any hidden applications on the top.
3525 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003526 continue;
3527 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003528 haveGroup = true;
3529 curGroup = wtoken.groupId;
3530 lastOrientation = wtoken.requestedOrientation;
3531 } else if (curGroup != wtoken.groupId) {
3532 // If we have hit a new application group, and the bottom
3533 // of the previous group didn't explicitly say to use
3534 // the orientation behind it, and the last app was
3535 // full screen, then we'll stick with the
3536 // user's orientation.
3537 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3538 && lastFullscreen) {
3539 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003542 int or = wtoken.requestedOrientation;
3543 // If this application is fullscreen, and didn't explicitly say
3544 // to use the orientation behind it, then just take whatever
3545 // orientation it has and ignores whatever is under it.
3546 lastFullscreen = wtoken.appFullscreen;
3547 if (lastFullscreen
3548 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3549 return or;
3550 }
3551 // If this application has requested an explicit orientation,
3552 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003553 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3554 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003555 return or;
3556 }
3557 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3558 }
3559 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 }
Romain Guy06882f82009-06-10 13:36:04 -07003561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003563 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003564 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3565 "updateOrientationFromAppTokens()")) {
3566 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003568
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003569 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003571
3572 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003573 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003574 if (freezeThisOneIfNeeded != null) {
3575 AppWindowToken wtoken = findAppWindowToken(
3576 freezeThisOneIfNeeded);
3577 if (wtoken != null) {
3578 startAppFreezingScreenLocked(wtoken,
3579 ActivityInfo.CONFIG_ORIENTATION);
3580 }
3581 }
3582 config = computeNewConfigurationLocked();
3583
3584 } else if (currentConfig != null) {
3585 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003586 // state mismatches the activity manager's, update it,
3587 // disregarding font scale, which should remain set to
3588 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003589 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003590 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003591 if (computeNewConfigurationLocked(mTempConfiguration)) {
3592 if (currentConfig.diff(mTempConfiguration) != 0) {
3593 mWaitingForConfig = true;
3594 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003595 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003596 config = new Configuration(mTempConfiguration);
3597 }
3598 }
3599 }
3600 }
3601
Dianne Hackborncfaef692009-06-15 14:24:44 -07003602 Binder.restoreCallingIdentity(ident);
3603 return config;
3604 }
3605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003607 * Determine the new desired orientation of the display, returning
3608 * a non-null new Configuration if it has changed from the current
3609 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3610 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3611 * SCREEN. This will typically be done for you if you call
3612 * sendNewConfiguration().
3613 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 * The orientation is computed from non-application windows first. If none of
3615 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003616 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3618 * android.os.IBinder)
3619 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003620 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3621 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003622 // If the display is frozen, some activities may be in the middle
3623 // of restarting, and thus have removed their old window. If the
3624 // window has the flag to hide the lock screen, then the lock screen
3625 // can re-appear and inflict its own orientation on us. Keep the
3626 // orientation stable until this all settles down.
3627 return false;
3628 }
3629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 long ident = Binder.clearCallingIdentity();
3632 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003633 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 mForcedAppOrientation = req;
3637 //send a message to Policy indicating orientation change to take
3638 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003639 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003640 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003641 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3642 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003643 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 }
3645 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003646
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003647 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 } finally {
3649 Binder.restoreCallingIdentity(ident);
3650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 }
Romain Guy06882f82009-06-10 13:36:04 -07003652
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003653 int computeForcedAppOrientationLocked() {
3654 int req = getOrientationFromWindowsLocked();
3655 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3656 req = getOrientationFromAppTokensLocked();
3657 }
3658 return req;
3659 }
Romain Guy06882f82009-06-10 13:36:04 -07003660
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003661 public void setNewConfiguration(Configuration config) {
3662 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3663 "setNewConfiguration()")) {
3664 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3665 }
3666
3667 synchronized(mWindowMap) {
3668 mCurConfiguration = new Configuration(config);
3669 mWaitingForConfig = false;
3670 performLayoutAndPlaceSurfacesLocked();
3671 }
3672 }
3673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3675 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3676 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003677 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 }
Romain Guy06882f82009-06-10 13:36:04 -07003679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 synchronized(mWindowMap) {
3681 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3682 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003683 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 return;
3685 }
Romain Guy06882f82009-06-10 13:36:04 -07003686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 wtoken.requestedOrientation = requestedOrientation;
3688 }
3689 }
Romain Guy06882f82009-06-10 13:36:04 -07003690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 public int getAppOrientation(IApplicationToken token) {
3692 synchronized(mWindowMap) {
3693 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3694 if (wtoken == null) {
3695 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3696 }
Romain Guy06882f82009-06-10 13:36:04 -07003697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 return wtoken.requestedOrientation;
3699 }
3700 }
Romain Guy06882f82009-06-10 13:36:04 -07003701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3703 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3704 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003705 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 }
3707
3708 synchronized(mWindowMap) {
3709 boolean changed = false;
3710 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003711 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 changed = mFocusedApp != null;
3713 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003714 if (changed) {
3715 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 } else {
3718 AppWindowToken newFocus = findAppWindowToken(token);
3719 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003720 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 return;
3722 }
3723 changed = mFocusedApp != newFocus;
3724 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003725 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003726 if (changed) {
3727 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003728 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 }
3730
3731 if (moveFocusNow && changed) {
3732 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003733 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 Binder.restoreCallingIdentity(origId);
3735 }
3736 }
3737 }
3738
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003739 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3741 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003742 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 }
Romain Guy06882f82009-06-10 13:36:04 -07003744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003746 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 TAG, "Prepare app transition: transit=" + transit
3748 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003749 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003750 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3751 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003753 } else if (!alwaysKeepCurrent) {
3754 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3755 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3756 // Opening a new task always supersedes a close for the anim.
3757 mNextAppTransition = transit;
3758 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3759 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3760 // Opening a new activity always supersedes a close for the anim.
3761 mNextAppTransition = transit;
3762 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 }
3764 mAppTransitionReady = false;
3765 mAppTransitionTimeout = false;
3766 mStartingIconInTransition = false;
3767 mSkipAppTransitionAnimation = false;
3768 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3769 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3770 5000);
3771 }
3772 }
3773 }
3774
3775 public int getPendingAppTransition() {
3776 return mNextAppTransition;
3777 }
Romain Guy06882f82009-06-10 13:36:04 -07003778
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003779 public void overridePendingAppTransition(String packageName,
3780 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003781 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003782 mNextAppTransitionPackage = packageName;
3783 mNextAppTransitionEnter = enterAnim;
3784 mNextAppTransitionExit = exitAnim;
3785 }
3786 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 public void executeAppTransition() {
3789 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3790 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003791 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 }
Romain Guy06882f82009-06-10 13:36:04 -07003793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003795 if (DEBUG_APP_TRANSITIONS) {
3796 RuntimeException e = new RuntimeException("here");
3797 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003798 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003799 + mNextAppTransition, e);
3800 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003801 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 mAppTransitionReady = true;
3803 final long origId = Binder.clearCallingIdentity();
3804 performLayoutAndPlaceSurfacesLocked();
3805 Binder.restoreCallingIdentity(origId);
3806 }
3807 }
3808 }
3809
3810 public void setAppStartingWindow(IBinder token, String pkg,
3811 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003812 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3814 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003815 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 }
3817
3818 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003819 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3821 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 AppWindowToken wtoken = findAppWindowToken(token);
3824 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003825 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 return;
3827 }
3828
3829 // If the display is frozen, we won't do anything until the
3830 // actual window is displayed so there is no reason to put in
3831 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003832 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 return;
3834 }
Romain Guy06882f82009-06-10 13:36:04 -07003835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 if (wtoken.startingData != null) {
3837 return;
3838 }
Romain Guy06882f82009-06-10 13:36:04 -07003839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 if (transferFrom != null) {
3841 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3842 if (ttoken != null) {
3843 WindowState startingWindow = ttoken.startingWindow;
3844 if (startingWindow != null) {
3845 if (mStartingIconInTransition) {
3846 // In this case, the starting icon has already
3847 // been displayed, so start letting windows get
3848 // shown immediately without any more transitions.
3849 mSkipAppTransitionAnimation = true;
3850 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003851 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003852 "Moving existing starting from " + ttoken
3853 + " to " + wtoken);
3854 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 // Transfer the starting window over to the new
3857 // token.
3858 wtoken.startingData = ttoken.startingData;
3859 wtoken.startingView = ttoken.startingView;
3860 wtoken.startingWindow = startingWindow;
3861 ttoken.startingData = null;
3862 ttoken.startingView = null;
3863 ttoken.startingWindow = null;
3864 ttoken.startingMoved = true;
3865 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003866 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003868 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003869 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003870 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003871 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003872 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3873 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 ttoken.windows.remove(startingWindow);
3875 ttoken.allAppWindows.remove(startingWindow);
3876 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 // Propagate other interesting state between the
3879 // tokens. If the old token is displayed, we should
3880 // immediately force the new one to be displayed. If
3881 // it is animating, we need to move that animation to
3882 // the new one.
3883 if (ttoken.allDrawn) {
3884 wtoken.allDrawn = true;
3885 }
3886 if (ttoken.firstWindowDrawn) {
3887 wtoken.firstWindowDrawn = true;
3888 }
3889 if (!ttoken.hidden) {
3890 wtoken.hidden = false;
3891 wtoken.hiddenRequested = false;
3892 wtoken.willBeHidden = false;
3893 }
3894 if (wtoken.clientHidden != ttoken.clientHidden) {
3895 wtoken.clientHidden = ttoken.clientHidden;
3896 wtoken.sendAppVisibilityToClients();
3897 }
3898 if (ttoken.animation != null) {
3899 wtoken.animation = ttoken.animation;
3900 wtoken.animating = ttoken.animating;
3901 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3902 ttoken.animation = null;
3903 ttoken.animLayerAdjustment = 0;
3904 wtoken.updateLayers();
3905 ttoken.updateLayers();
3906 }
Romain Guy06882f82009-06-10 13:36:04 -07003907
Jeff Brown3a22cd92011-01-21 13:59:04 -08003908 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3909 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 mLayoutNeeded = true;
3911 performLayoutAndPlaceSurfacesLocked();
3912 Binder.restoreCallingIdentity(origId);
3913 return;
3914 } else if (ttoken.startingData != null) {
3915 // The previous app was getting ready to show a
3916 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003917 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918 "Moving pending starting from " + ttoken
3919 + " to " + wtoken);
3920 wtoken.startingData = ttoken.startingData;
3921 ttoken.startingData = null;
3922 ttoken.startingMoved = true;
3923 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3924 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3925 // want to process the message ASAP, before any other queued
3926 // messages.
3927 mH.sendMessageAtFrontOfQueue(m);
3928 return;
3929 }
3930 }
3931 }
3932
3933 // There is no existing starting window, and the caller doesn't
3934 // want us to create one, so that's it!
3935 if (!createIfNeeded) {
3936 return;
3937 }
Romain Guy06882f82009-06-10 13:36:04 -07003938
Dianne Hackborn284ac932009-08-28 10:34:25 -07003939 // If this is a translucent or wallpaper window, then don't
3940 // show a starting window -- the current effect (a full-screen
3941 // opaque starting window that fades away to the real contents
3942 // when it is ready) does not work for this.
3943 if (theme != 0) {
3944 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3945 com.android.internal.R.styleable.Window);
3946 if (ent.array.getBoolean(
3947 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3948 return;
3949 }
3950 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003951 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3952 return;
3953 }
3954 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003955 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3956 return;
3957 }
3958 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003960 mStartingIconInTransition = true;
3961 wtoken.startingData = new StartingData(
3962 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003963 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3965 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3966 // want to process the message ASAP, before any other queued
3967 // messages.
3968 mH.sendMessageAtFrontOfQueue(m);
3969 }
3970 }
3971
3972 public void setAppWillBeHidden(IBinder token) {
3973 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3974 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003975 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 }
3977
3978 AppWindowToken wtoken;
3979
3980 synchronized(mWindowMap) {
3981 wtoken = findAppWindowToken(token);
3982 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003983 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 -08003984 return;
3985 }
3986 wtoken.willBeHidden = true;
3987 }
3988 }
Romain Guy06882f82009-06-10 13:36:04 -07003989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3991 boolean visible, int transit, boolean performLayout) {
3992 boolean delayed = false;
3993
3994 if (wtoken.clientHidden == visible) {
3995 wtoken.clientHidden = !visible;
3996 wtoken.sendAppVisibilityToClients();
3997 }
Romain Guy06882f82009-06-10 13:36:04 -07003998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 wtoken.willBeHidden = false;
4000 if (wtoken.hidden == visible) {
4001 final int N = wtoken.allAppWindows.size();
4002 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08004003 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
4005 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07004006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07004008
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004009 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 if (wtoken.animation == sDummyAnimation) {
4011 wtoken.animation = null;
4012 }
4013 applyAnimationLocked(wtoken, lp, transit, visible);
4014 changed = true;
4015 if (wtoken.animation != null) {
4016 delayed = runningAppAnimation = true;
4017 }
4018 }
Romain Guy06882f82009-06-10 13:36:04 -07004019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 for (int i=0; i<N; i++) {
4021 WindowState win = wtoken.allAppWindows.get(i);
4022 if (win == wtoken.startingWindow) {
4023 continue;
4024 }
4025
4026 if (win.isAnimating()) {
4027 delayed = true;
4028 }
Romain Guy06882f82009-06-10 13:36:04 -07004029
Joe Onorato8a9b2202010-02-26 18:56:32 -08004030 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 //win.dump(" ");
4032 if (visible) {
4033 if (!win.isVisibleNow()) {
4034 if (!runningAppAnimation) {
4035 applyAnimationLocked(win,
4036 WindowManagerPolicy.TRANSIT_ENTER, true);
4037 }
4038 changed = true;
4039 }
4040 } else if (win.isVisibleNow()) {
4041 if (!runningAppAnimation) {
4042 applyAnimationLocked(win,
4043 WindowManagerPolicy.TRANSIT_EXIT, false);
4044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 changed = true;
4046 }
4047 }
4048
4049 wtoken.hidden = wtoken.hiddenRequested = !visible;
4050 if (!visible) {
4051 unsetAppFreezingScreenLocked(wtoken, true, true);
4052 } else {
4053 // If we are being set visible, and the starting window is
4054 // not yet displayed, then make sure it doesn't get displayed.
4055 WindowState swin = wtoken.startingWindow;
4056 if (swin != null && (swin.mDrawPending
4057 || swin.mCommitDrawPending)) {
4058 swin.mPolicyVisibility = false;
4059 swin.mPolicyVisibilityAfterAnim = false;
4060 }
4061 }
Romain Guy06882f82009-06-10 13:36:04 -07004062
Joe Onorato8a9b2202010-02-26 18:56:32 -08004063 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4065 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004066
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004067 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004069 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004070 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004071 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4072 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004073 performLayoutAndPlaceSurfacesLocked();
4074 }
Jeff Brown2e44b072011-01-24 15:21:56 -08004075 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 }
4077 }
4078
4079 if (wtoken.animation != null) {
4080 delayed = true;
4081 }
Romain Guy06882f82009-06-10 13:36:04 -07004082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 return delayed;
4084 }
4085
4086 public void setAppVisibility(IBinder token, boolean visible) {
4087 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4088 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004089 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 }
4091
4092 AppWindowToken wtoken;
4093
4094 synchronized(mWindowMap) {
4095 wtoken = findAppWindowToken(token);
4096 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004097 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 return;
4099 }
4100
4101 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004102 RuntimeException e = null;
4103 if (!HIDE_STACK_CRAWLS) {
4104 e = new RuntimeException();
4105 e.fillInStackTrace();
4106 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004107 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 + "): mNextAppTransition=" + mNextAppTransition
4109 + " hidden=" + wtoken.hidden
4110 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4111 }
Romain Guy06882f82009-06-10 13:36:04 -07004112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 // If we are preparing an app transition, then delay changing
4114 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004115 if (!mDisplayFrozen && mPolicy.isScreenOn()
4116 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 // Already in requested state, don't do anything more.
4118 if (wtoken.hiddenRequested != visible) {
4119 return;
4120 }
4121 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004122
Joe Onorato8a9b2202010-02-26 18:56:32 -08004123 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004124 TAG, "Setting dummy animation on: " + wtoken);
4125 wtoken.setDummyAnimation();
4126 mOpeningApps.remove(wtoken);
4127 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004128 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 wtoken.inPendingTransaction = true;
4130 if (visible) {
4131 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 wtoken.startingDisplayed = false;
4133 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004134
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004135 // If the token is currently hidden (should be the
4136 // common case), then we need to set up to wait for
4137 // its windows to be ready.
4138 if (wtoken.hidden) {
4139 wtoken.allDrawn = false;
4140 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004141
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004142 if (wtoken.clientHidden) {
4143 // In the case where we are making an app visible
4144 // but holding off for a transition, we still need
4145 // to tell the client to make its windows visible so
4146 // they get drawn. Otherwise, we will wait on
4147 // performing the transition until all windows have
4148 // been drawn, they never will be, and we are sad.
4149 wtoken.clientHidden = false;
4150 wtoken.sendAppVisibilityToClients();
4151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004152 }
4153 } else {
4154 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004155
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004156 // If the token is currently visible (should be the
4157 // common case), then set up to wait for it to be hidden.
4158 if (!wtoken.hidden) {
4159 wtoken.waitingToHide = true;
4160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 }
4162 return;
4163 }
Romain Guy06882f82009-06-10 13:36:04 -07004164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004166 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004167 wtoken.updateReportedVisibilityLocked();
4168 Binder.restoreCallingIdentity(origId);
4169 }
4170 }
4171
4172 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4173 boolean unfreezeSurfaceNow, boolean force) {
4174 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004175 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 + " force=" + force);
4177 final int N = wtoken.allAppWindows.size();
4178 boolean unfrozeWindows = false;
4179 for (int i=0; i<N; i++) {
4180 WindowState w = wtoken.allAppWindows.get(i);
4181 if (w.mAppFreezing) {
4182 w.mAppFreezing = false;
4183 if (w.mSurface != null && !w.mOrientationChanging) {
4184 w.mOrientationChanging = true;
4185 }
4186 unfrozeWindows = true;
4187 }
4188 }
4189 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004190 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191 wtoken.freezingScreen = false;
4192 mAppsFreezingScreen--;
4193 }
4194 if (unfreezeSurfaceNow) {
4195 if (unfrozeWindows) {
4196 mLayoutNeeded = true;
4197 performLayoutAndPlaceSurfacesLocked();
4198 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004199 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 }
4201 }
4202 }
Romain Guy06882f82009-06-10 13:36:04 -07004203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4205 int configChanges) {
4206 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004207 RuntimeException e = null;
4208 if (!HIDE_STACK_CRAWLS) {
4209 e = new RuntimeException();
4210 e.fillInStackTrace();
4211 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004212 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 + ": hidden=" + wtoken.hidden + " freezing="
4214 + wtoken.freezingScreen, e);
4215 }
4216 if (!wtoken.hiddenRequested) {
4217 if (!wtoken.freezingScreen) {
4218 wtoken.freezingScreen = true;
4219 mAppsFreezingScreen++;
4220 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004221 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4223 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4224 5000);
4225 }
4226 }
4227 final int N = wtoken.allAppWindows.size();
4228 for (int i=0; i<N; i++) {
4229 WindowState w = wtoken.allAppWindows.get(i);
4230 w.mAppFreezing = true;
4231 }
4232 }
4233 }
Romain Guy06882f82009-06-10 13:36:04 -07004234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004235 public void startAppFreezingScreen(IBinder token, int configChanges) {
4236 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4237 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004238 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 }
4240
4241 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004242 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004243 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 return;
4245 }
Romain Guy06882f82009-06-10 13:36:04 -07004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 AppWindowToken wtoken = findAppWindowToken(token);
4248 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004249 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 return;
4251 }
4252 final long origId = Binder.clearCallingIdentity();
4253 startAppFreezingScreenLocked(wtoken, configChanges);
4254 Binder.restoreCallingIdentity(origId);
4255 }
4256 }
Romain Guy06882f82009-06-10 13:36:04 -07004257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 public void stopAppFreezingScreen(IBinder token, boolean force) {
4259 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4260 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004261 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 }
4263
4264 synchronized(mWindowMap) {
4265 AppWindowToken wtoken = findAppWindowToken(token);
4266 if (wtoken == null || wtoken.appToken == null) {
4267 return;
4268 }
4269 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004270 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4272 unsetAppFreezingScreenLocked(wtoken, true, force);
4273 Binder.restoreCallingIdentity(origId);
4274 }
4275 }
Romain Guy06882f82009-06-10 13:36:04 -07004276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004277 public void removeAppToken(IBinder token) {
4278 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4279 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004280 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 }
4282
4283 AppWindowToken wtoken = null;
4284 AppWindowToken startingToken = null;
4285 boolean delayed = false;
4286
4287 final long origId = Binder.clearCallingIdentity();
4288 synchronized(mWindowMap) {
4289 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004291 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004292 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 wtoken.inPendingTransaction = false;
4294 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004295 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 if (mClosingApps.contains(wtoken)) {
4297 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004298 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004300 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 delayed = true;
4302 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004303 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 TAG, "Removing app " + wtoken + " delayed=" + delayed
4305 + " animation=" + wtoken.animation
4306 + " animating=" + wtoken.animating);
4307 if (delayed) {
4308 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004309 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4310 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004312 } else {
4313 // Make sure there is no animation running on this token,
4314 // so any windows associated with it will be removed as
4315 // soon as their animations are complete
4316 wtoken.animation = null;
4317 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004319 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4320 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 mAppTokens.remove(wtoken);
4322 wtoken.removed = true;
4323 if (wtoken.startingData != null) {
4324 startingToken = wtoken;
4325 }
4326 unsetAppFreezingScreenLocked(wtoken, true, true);
4327 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004328 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004330 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004331 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
4333 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004334 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 }
Romain Guy06882f82009-06-10 13:36:04 -07004336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 if (!delayed && wtoken != null) {
4338 wtoken.updateReportedVisibilityLocked();
4339 }
4340 }
4341 Binder.restoreCallingIdentity(origId);
4342
4343 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004344 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 + startingToken + ": app token removed");
4346 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4347 mH.sendMessage(m);
4348 }
4349 }
4350
4351 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4352 final int NW = token.windows.size();
4353 for (int i=0; i<NW; i++) {
4354 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004355 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004357 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 int j = win.mChildWindows.size();
4359 while (j > 0) {
4360 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004361 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004363 "Tmp removing child window " + cwin);
4364 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
4366 }
4367 return NW > 0;
4368 }
4369
4370 void dumpAppTokensLocked() {
4371 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004372 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004373 }
4374 }
Romain Guy06882f82009-06-10 13:36:04 -07004375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 void dumpWindowsLocked() {
4377 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004378 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379 }
4380 }
Romain Guy06882f82009-06-10 13:36:04 -07004381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 private int findWindowOffsetLocked(int tokenPos) {
4383 final int NW = mWindows.size();
4384
4385 if (tokenPos >= mAppTokens.size()) {
4386 int i = NW;
4387 while (i > 0) {
4388 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004389 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 if (win.getAppToken() != null) {
4391 return i+1;
4392 }
4393 }
4394 }
4395
4396 while (tokenPos > 0) {
4397 // Find the first app token below the new position that has
4398 // a window displayed.
4399 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004400 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004402 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004403 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004404 "Skipping token -- currently sending to bottom");
4405 tokenPos--;
4406 continue;
4407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 int i = wtoken.windows.size();
4409 while (i > 0) {
4410 i--;
4411 WindowState win = wtoken.windows.get(i);
4412 int j = win.mChildWindows.size();
4413 while (j > 0) {
4414 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004415 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004416 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 for (int pos=NW-1; pos>=0; pos--) {
4418 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004419 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 "Found child win @" + (pos+1));
4421 return pos+1;
4422 }
4423 }
4424 }
4425 }
4426 for (int pos=NW-1; pos>=0; pos--) {
4427 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004428 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004429 return pos+1;
4430 }
4431 }
4432 }
4433 tokenPos--;
4434 }
4435
4436 return 0;
4437 }
4438
4439 private final int reAddWindowLocked(int index, WindowState win) {
4440 final int NCW = win.mChildWindows.size();
4441 boolean added = false;
4442 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004443 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004445 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004446 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004447 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 mWindows.add(index, win);
4449 index++;
4450 added = true;
4451 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004452 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004453 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004454 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 mWindows.add(index, cwin);
4456 index++;
4457 }
4458 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004459 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004460 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004461 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 mWindows.add(index, win);
4463 index++;
4464 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004465 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 return index;
4467 }
Romain Guy06882f82009-06-10 13:36:04 -07004468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4470 final int NW = token.windows.size();
4471 for (int i=0; i<NW; i++) {
4472 index = reAddWindowLocked(index, token.windows.get(i));
4473 }
4474 return index;
4475 }
4476
4477 public void moveAppToken(int index, IBinder token) {
4478 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4479 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004480 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 }
4482
4483 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004484 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 if (DEBUG_REORDER) dumpAppTokensLocked();
4486 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004487 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4488 "Start moving token " + wtoken + " initially at "
4489 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004491 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 + token + " (" + wtoken + ")");
4493 return;
4494 }
4495 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004496 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004497 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004500 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004501 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 if (DEBUG_REORDER) dumpWindowsLocked();
4503 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004504 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 if (DEBUG_REORDER) dumpWindowsLocked();
4506 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004507 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004509 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4510 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004512 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004514 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 }
4516 Binder.restoreCallingIdentity(origId);
4517 }
4518 }
4519
4520 private void removeAppTokensLocked(List<IBinder> tokens) {
4521 // XXX This should be done more efficiently!
4522 // (take advantage of the fact that both lists should be
4523 // ordered in the same way.)
4524 int N = tokens.size();
4525 for (int i=0; i<N; i++) {
4526 IBinder token = tokens.get(i);
4527 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004528 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4529 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004531 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 + token + " (" + wtoken + ")");
4533 i--;
4534 N--;
4535 }
4536 }
4537 }
4538
Dianne Hackborna8f60182009-09-01 19:01:50 -07004539 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4540 boolean updateFocusAndLayout) {
4541 // First remove all of the windows from the list.
4542 tmpRemoveAppWindowsLocked(wtoken);
4543
4544 // Where to start adding?
4545 int pos = findWindowOffsetLocked(tokenPos);
4546
4547 // And now add them back at the correct place.
4548 pos = reAddAppWindowsLocked(pos, wtoken);
4549
4550 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004551 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004552 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4553 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004554 assignLayersLocked();
4555 }
4556 mLayoutNeeded = true;
4557 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004558 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004559 }
4560 }
4561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004562 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4563 // First remove all of the windows from the list.
4564 final int N = tokens.size();
4565 int i;
4566 for (i=0; i<N; i++) {
4567 WindowToken token = mTokenMap.get(tokens.get(i));
4568 if (token != null) {
4569 tmpRemoveAppWindowsLocked(token);
4570 }
4571 }
4572
4573 // Where to start adding?
4574 int pos = findWindowOffsetLocked(tokenPos);
4575
4576 // And now add them back at the correct place.
4577 for (i=0; i<N; i++) {
4578 WindowToken token = mTokenMap.get(tokens.get(i));
4579 if (token != null) {
4580 pos = reAddAppWindowsLocked(pos, token);
4581 }
4582 }
4583
Jeff Brown2e44b072011-01-24 15:21:56 -08004584 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004585 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4586 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004587 assignLayersLocked();
4588 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004589 mLayoutNeeded = true;
4590 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004591 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592
4593 //dump();
4594 }
4595
4596 public void moveAppTokensToTop(List<IBinder> tokens) {
4597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4598 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600 }
4601
4602 final long origId = Binder.clearCallingIdentity();
4603 synchronized(mWindowMap) {
4604 removeAppTokensLocked(tokens);
4605 final int N = tokens.size();
4606 for (int i=0; i<N; i++) {
4607 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4608 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004609 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4610 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004611 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004612 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004613 mToTopApps.remove(wt);
4614 mToBottomApps.remove(wt);
4615 mToTopApps.add(wt);
4616 wt.sendingToBottom = false;
4617 wt.sendingToTop = true;
4618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004619 }
4620 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004621
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004622 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004623 moveAppWindowsLocked(tokens, mAppTokens.size());
4624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004625 }
4626 Binder.restoreCallingIdentity(origId);
4627 }
4628
4629 public void moveAppTokensToBottom(List<IBinder> tokens) {
4630 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4631 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004632 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 }
4634
4635 final long origId = Binder.clearCallingIdentity();
4636 synchronized(mWindowMap) {
4637 removeAppTokensLocked(tokens);
4638 final int N = tokens.size();
4639 int pos = 0;
4640 for (int i=0; i<N; i++) {
4641 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4642 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004643 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4644 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004646 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004647 mToTopApps.remove(wt);
4648 mToBottomApps.remove(wt);
4649 mToBottomApps.add(i, wt);
4650 wt.sendingToTop = false;
4651 wt.sendingToBottom = true;
4652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 pos++;
4654 }
4655 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004656
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004657 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004658 moveAppWindowsLocked(tokens, 0);
4659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 }
4661 Binder.restoreCallingIdentity(origId);
4662 }
4663
4664 // -------------------------------------------------------------
4665 // Misc IWindowSession methods
4666 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004667
Jim Miller284b62e2010-06-08 14:27:42 -07004668 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004669 {
Jim Miller284b62e2010-06-08 14:27:42 -07004670 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4671 // called before DevicePolicyManagerService has started.
4672 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4673 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4674 Context.DEVICE_POLICY_SERVICE);
4675 if (dpm != null) {
4676 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4677 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4678 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4679 }
Jim Millerd6b57052010-06-07 17:52:42 -07004680 }
Jim Miller284b62e2010-06-08 14:27:42 -07004681 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004682 }
4683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004685 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 != PackageManager.PERMISSION_GRANTED) {
4687 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4688 }
Jim Millerd6b57052010-06-07 17:52:42 -07004689
Jim Miller284b62e2010-06-08 14:27:42 -07004690 synchronized (mKeyguardTokenWatcher) {
4691 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004692 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 }
4694
4695 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004696 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 != PackageManager.PERMISSION_GRANTED) {
4698 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4699 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700
Jim Miller284b62e2010-06-08 14:27:42 -07004701 synchronized (mKeyguardTokenWatcher) {
4702 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004703
Jim Miller284b62e2010-06-08 14:27:42 -07004704 if (!mKeyguardTokenWatcher.isAcquired()) {
4705 // If we are the last one to reenable the keyguard wait until
4706 // we have actually finished reenabling until returning.
4707 // It is possible that reenableKeyguard() can be called before
4708 // the previous disableKeyguard() is handled, in which case
4709 // neither mKeyguardTokenWatcher.acquired() or released() would
4710 // be called. In that case mKeyguardDisabled will be false here
4711 // and we have nothing to wait for.
4712 while (mKeyguardDisabled) {
4713 try {
4714 mKeyguardTokenWatcher.wait();
4715 } catch (InterruptedException e) {
4716 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 }
4718 }
4719 }
4720 }
4721 }
4722
4723 /**
4724 * @see android.app.KeyguardManager#exitKeyguardSecurely
4725 */
4726 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004727 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004728 != PackageManager.PERMISSION_GRANTED) {
4729 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4730 }
4731 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4732 public void onKeyguardExitResult(boolean success) {
4733 try {
4734 callback.onKeyguardExitResult(success);
4735 } catch (RemoteException e) {
4736 // Client has died, we don't care.
4737 }
4738 }
4739 });
4740 }
4741
4742 public boolean inKeyguardRestrictedInputMode() {
4743 return mPolicy.inKeyguardRestrictedKeyInputMode();
4744 }
Romain Guy06882f82009-06-10 13:36:04 -07004745
Dianne Hackbornffa42482009-09-23 22:20:11 -07004746 public void closeSystemDialogs(String reason) {
4747 synchronized(mWindowMap) {
4748 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004749 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004750 if (w.mSurface != null) {
4751 try {
4752 w.mClient.closeSystemDialogs(reason);
4753 } catch (RemoteException e) {
4754 }
4755 }
4756 }
4757 }
4758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004760 static float fixScale(float scale) {
4761 if (scale < 0) scale = 0;
4762 else if (scale > 20) scale = 20;
4763 return Math.abs(scale);
4764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 public void setAnimationScale(int which, float scale) {
4767 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4768 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004769 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 }
4771
4772 if (scale < 0) scale = 0;
4773 else if (scale > 20) scale = 20;
4774 scale = Math.abs(scale);
4775 switch (which) {
4776 case 0: mWindowAnimationScale = fixScale(scale); break;
4777 case 1: mTransitionAnimationScale = fixScale(scale); break;
4778 }
Romain Guy06882f82009-06-10 13:36:04 -07004779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004780 // Persist setting
4781 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4782 }
Romain Guy06882f82009-06-10 13:36:04 -07004783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004784 public void setAnimationScales(float[] scales) {
4785 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4786 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004787 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 }
4789
4790 if (scales != null) {
4791 if (scales.length >= 1) {
4792 mWindowAnimationScale = fixScale(scales[0]);
4793 }
4794 if (scales.length >= 2) {
4795 mTransitionAnimationScale = fixScale(scales[1]);
4796 }
4797 }
Romain Guy06882f82009-06-10 13:36:04 -07004798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 // Persist setting
4800 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4801 }
Romain Guy06882f82009-06-10 13:36:04 -07004802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004803 public float getAnimationScale(int which) {
4804 switch (which) {
4805 case 0: return mWindowAnimationScale;
4806 case 1: return mTransitionAnimationScale;
4807 }
4808 return 0;
4809 }
Romain Guy06882f82009-06-10 13:36:04 -07004810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 public float[] getAnimationScales() {
4812 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4813 }
Romain Guy06882f82009-06-10 13:36:04 -07004814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815 public int getSwitchState(int sw) {
4816 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4817 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004818 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004819 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004820 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 }
Romain Guy06882f82009-06-10 13:36:04 -07004822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823 public int getSwitchStateForDevice(int devid, int sw) {
4824 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4825 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004826 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004828 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 }
Romain Guy06882f82009-06-10 13:36:04 -07004830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 public int getScancodeState(int sw) {
4832 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4833 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004834 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004836 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 }
Romain Guy06882f82009-06-10 13:36:04 -07004838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 public int getScancodeStateForDevice(int devid, int sw) {
4840 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4841 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004842 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004844 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004845 }
Romain Guy06882f82009-06-10 13:36:04 -07004846
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004847 public int getTrackballScancodeState(int sw) {
4848 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4849 "getTrackballScancodeState()")) {
4850 throw new SecurityException("Requires READ_INPUT_STATE permission");
4851 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004852 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004853 }
4854
4855 public int getDPadScancodeState(int sw) {
4856 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4857 "getDPadScancodeState()")) {
4858 throw new SecurityException("Requires READ_INPUT_STATE permission");
4859 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004860 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004861 }
4862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 public int getKeycodeState(int sw) {
4864 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4865 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004866 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004868 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004869 }
Romain Guy06882f82009-06-10 13:36:04 -07004870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 public int getKeycodeStateForDevice(int devid, int sw) {
4872 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4873 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004874 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004875 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004876 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004877 }
Romain Guy06882f82009-06-10 13:36:04 -07004878
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004879 public int getTrackballKeycodeState(int sw) {
4880 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4881 "getTrackballKeycodeState()")) {
4882 throw new SecurityException("Requires READ_INPUT_STATE permission");
4883 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004884 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004885 }
4886
4887 public int getDPadKeycodeState(int sw) {
4888 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4889 "getDPadKeycodeState()")) {
4890 throw new SecurityException("Requires READ_INPUT_STATE permission");
4891 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004892 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004893 }
Jeff Browna41ca772010-08-11 14:46:32 -07004894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004896 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 }
Romain Guy06882f82009-06-10 13:36:04 -07004898
Jeff Browna41ca772010-08-11 14:46:32 -07004899 public InputChannel monitorInput(String inputChannelName) {
4900 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4901 "monitorInput()")) {
4902 throw new SecurityException("Requires READ_INPUT_STATE permission");
4903 }
4904 return mInputManager.monitorInput(inputChannelName);
4905 }
4906
Jeff Brown8d608662010-08-30 03:02:23 -07004907 public InputDevice getInputDevice(int deviceId) {
4908 return mInputManager.getInputDevice(deviceId);
4909 }
4910
4911 public int[] getInputDeviceIds() {
4912 return mInputManager.getInputDeviceIds();
4913 }
4914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 public void enableScreenAfterBoot() {
4916 synchronized(mWindowMap) {
4917 if (mSystemBooted) {
4918 return;
4919 }
4920 mSystemBooted = true;
4921 }
Romain Guy06882f82009-06-10 13:36:04 -07004922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004923 performEnableScreen();
4924 }
Romain Guy06882f82009-06-10 13:36:04 -07004925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 public void enableScreenIfNeededLocked() {
4927 if (mDisplayEnabled) {
4928 return;
4929 }
4930 if (!mSystemBooted) {
4931 return;
4932 }
4933 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4934 }
Romain Guy06882f82009-06-10 13:36:04 -07004935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 public void performEnableScreen() {
4937 synchronized(mWindowMap) {
4938 if (mDisplayEnabled) {
4939 return;
4940 }
4941 if (!mSystemBooted) {
4942 return;
4943 }
Romain Guy06882f82009-06-10 13:36:04 -07004944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 // Don't enable the screen until all existing windows
4946 // have been drawn.
4947 final int N = mWindows.size();
4948 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004949 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004950 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004951 return;
4952 }
4953 }
Romain Guy06882f82009-06-10 13:36:04 -07004954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 mDisplayEnabled = true;
4956 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004957 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004958 StringWriter sw = new StringWriter();
4959 PrintWriter pw = new PrintWriter(sw);
4960 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004961 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 }
4963 try {
4964 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4965 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004966 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004967 Parcel data = Parcel.obtain();
4968 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4969 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4970 data, null, 0);
4971 data.recycle();
4972 }
4973 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004974 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 }
4976 }
Romain Guy06882f82009-06-10 13:36:04 -07004977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004978 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004981 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4982 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 }
Romain Guy06882f82009-06-10 13:36:04 -07004984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004985 public void setInTouchMode(boolean mode) {
4986 synchronized(mWindowMap) {
4987 mInTouchMode = mode;
4988 }
4989 }
4990
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004991 // TODO: more accounting of which pid(s) turned it on, keep count,
4992 // only allow disables from pids which have count on, etc.
4993 public void showStrictModeViolation(boolean on) {
4994 int pid = Binder.getCallingPid();
4995 synchronized(mWindowMap) {
4996 // Ignoring requests to enable the red border from clients
4997 // which aren't on screen. (e.g. Broadcast Receivers in
4998 // the background..)
4999 if (on) {
5000 boolean isVisible = false;
5001 for (WindowState ws : mWindows) {
5002 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
5003 isVisible = true;
5004 break;
5005 }
5006 }
5007 if (!isVisible) {
5008 return;
5009 }
5010 }
5011
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005012 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005013 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005014 try {
5015 if (mStrictModeFlash == null) {
5016 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
5017 }
5018 mStrictModeFlash.setVisibility(on);
5019 } finally {
5020 Surface.closeTransaction();
5021 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005022 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005023 }
5024 }
5025
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08005026 public void setStrictModeVisualIndicatorPreference(String value) {
5027 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
5028 }
5029
Dianne Hackbornd2835932010-12-13 16:28:46 -08005030 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005031 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5032 "screenshotApplications()")) {
5033 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5034 }
5035
5036 Bitmap rawss;
5037
Dianne Hackbornd2835932010-12-13 16:28:46 -08005038 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005039 final Rect frame = new Rect();
5040
5041 float scale;
5042 int sw, sh, dw, dh;
5043 int rot;
5044
5045 synchronized(mWindowMap) {
5046 long ident = Binder.clearCallingIdentity();
5047
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005048 dw = mDisplay.getWidth();
5049 dh = mDisplay.getHeight();
5050
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005051 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5052 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5053 + TYPE_LAYER_OFFSET;
5054 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5055
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005056 boolean isImeTarget = mInputMethodTarget != null
5057 && mInputMethodTarget.mAppToken != null
5058 && mInputMethodTarget.mAppToken.appToken != null
5059 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
5060
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005061 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005062 boolean including = false;
5063 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005064 WindowState ws = mWindows.get(i);
5065 if (ws.mSurface == null) {
5066 continue;
5067 }
5068 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08005069 continue;
5070 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005071 // When we will skip windows: when we are not including
5072 // ones behind a window we didn't skip, and we are actually
5073 // taking a screenshot of a specific app.
5074 if (!including && appToken != null) {
5075 // Also, we can possibly skip this window if it is not
5076 // an IME target or the application for the screenshot
5077 // is not the current IME target.
5078 if (!ws.mIsImWindow || !isImeTarget) {
5079 // And finally, this window is of no interest if it
5080 // is not associated with the screenshot app.
5081 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
5082 continue;
5083 }
5084 }
5085 }
5086
5087 // We keep on including windows until we go past a full-screen
5088 // window.
5089 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
5090
Dianne Hackbornd2835932010-12-13 16:28:46 -08005091 if (maxLayer < ws.mAnimLayer) {
5092 maxLayer = ws.mAnimLayer;
5093 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005094 final Rect wf = ws.mFrame;
5095 final Rect cr = ws.mContentInsets;
5096 int left = wf.left + cr.left;
5097 int top = wf.top + cr.top;
5098 int right = wf.right - cr.right;
5099 int bottom = wf.bottom - cr.bottom;
5100 frame.union(left, top, right, bottom);
5101 }
5102 Binder.restoreCallingIdentity(ident);
5103
Dianne Hackborndd962ee2011-02-02 11:11:50 -08005104 // Constrain frame to the screen size.
5105 frame.intersect(0, 0, dw, dh);
5106
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005107 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005108 return null;
5109 }
5110
5111 // The screenshot API does not apply the current screen rotation.
5112 rot = mDisplay.getRotation();
5113 int fw = frame.width();
5114 int fh = frame.height();
5115
5116 // First try reducing to fit in x dimension.
5117 scale = maxWidth/(float)fw;
5118 sw = maxWidth;
5119 sh = (int)(fh*scale);
5120 if (sh > maxHeight) {
5121 // y dimension became too long; constrain by that.
5122 scale = maxHeight/(float)fh;
5123 sw = (int)(fw*scale);
5124 sh = maxHeight;
5125 }
5126
5127 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005128 dw = (int)(dw*scale);
5129 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005130 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5131 int tmp = dw;
5132 dw = dh;
5133 dh = tmp;
5134 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5135 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005136 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005137 }
5138
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005139 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005140 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5141 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005142 return null;
5143 }
5144
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005145 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5146 Matrix matrix = new Matrix();
5147 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5148 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5149 Canvas canvas = new Canvas(bm);
5150 canvas.drawBitmap(rawss, matrix, null);
5151
5152 rawss.recycle();
5153 return bm;
5154 }
5155
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005156 public void freezeRotation() {
5157 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5158 "setRotation()")) {
5159 throw new SecurityException("Requires SET_ORIENTATION permission");
5160 }
5161
5162 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5163 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5164 }
5165
5166 public void thawRotation() {
5167 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5168 "setRotation()")) {
5169 throw new SecurityException("Requires SET_ORIENTATION permission");
5170 }
5171
5172 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5173 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5174 }
5175
Romain Guy06882f82009-06-10 13:36:04 -07005176 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005177 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005179 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005180 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005181 }
5182
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005183 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 }
Romain Guy06882f82009-06-10 13:36:04 -07005185
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005186 public void setRotationUnchecked(int rotation,
5187 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005188 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005191 long origId = Binder.clearCallingIdentity();
5192 boolean changed;
5193 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005194 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005195 }
Romain Guy06882f82009-06-10 13:36:04 -07005196
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005197 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005198 sendNewConfiguration();
5199 }
Romain Guy06882f82009-06-10 13:36:04 -07005200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005201 Binder.restoreCallingIdentity(origId);
5202 }
Romain Guy06882f82009-06-10 13:36:04 -07005203
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005204 /**
5205 * Apply a new rotation to the screen, respecting the requests of
5206 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5207 * re-evaluate the desired rotation.
5208 *
5209 * Returns null if the rotation has been changed. In this case YOU
5210 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5211 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005212 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005213 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005214 // Potential rotation during a drag. Don't do the rotation now, but make
5215 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005216 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5217 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5218 mDeferredRotation = rotation;
5219 mDeferredRotationAnimFlags = animFlags;
5220 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005221 return false;
5222 }
5223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 boolean changed;
5225 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005226 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5227 rotation = mDeferredRotation;
5228 mRequestedRotation = rotation;
5229 mLastRotationFlags = mDeferredRotationAnimFlags;
5230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231 rotation = mRequestedRotation;
5232 } else {
5233 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005234 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005235 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005236 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005237 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005238 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005239 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005240 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005243 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005244 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 "Rotation changed to " + rotation
5246 + " from " + mRotation
5247 + " (forceApp=" + mForcedAppOrientation
5248 + ", req=" + mRequestedRotation + ")");
5249 mRotation = rotation;
5250 mWindowsFreezingScreen = true;
5251 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5252 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5253 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005254 mWaitingForConfig = true;
5255 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005256 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005257 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005258 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005259 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005260 if (CUSTOM_SCREEN_ROTATION) {
5261 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005262 if (!inTransaction) {
5263 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5264 ">>> OPEN TRANSACTION setRotationUnchecked");
5265 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005266 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005267 try {
5268 if (mScreenRotationAnimation != null) {
5269 mScreenRotationAnimation.setRotation(rotation);
5270 }
5271 } finally {
5272 if (!inTransaction) {
5273 Surface.closeTransaction();
5274 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5275 "<<< CLOSE TRANSACTION setRotationUnchecked");
5276 }
5277 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005278 Surface.setOrientation(0, rotation, animFlags);
5279 Surface.unfreezeDisplay(0);
5280 } else {
5281 Surface.setOrientation(0, rotation, animFlags);
5282 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005283 }
5284 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005285 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005286 if (w.mSurface != null) {
5287 w.mOrientationChanging = true;
5288 }
5289 }
5290 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5291 try {
5292 mRotationWatchers.get(i).onRotationChanged(rotation);
5293 } catch (RemoteException e) {
5294 }
5295 }
5296 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005298 return changed;
5299 }
Romain Guy06882f82009-06-10 13:36:04 -07005300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005301 public int getRotation() {
5302 return mRotation;
5303 }
5304
5305 public int watchRotation(IRotationWatcher watcher) {
5306 final IBinder watcherBinder = watcher.asBinder();
5307 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5308 public void binderDied() {
5309 synchronized (mWindowMap) {
5310 for (int i=0; i<mRotationWatchers.size(); i++) {
5311 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005312 IRotationWatcher removed = mRotationWatchers.remove(i);
5313 if (removed != null) {
5314 removed.asBinder().unlinkToDeath(this, 0);
5315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005316 i--;
5317 }
5318 }
5319 }
5320 }
5321 };
Romain Guy06882f82009-06-10 13:36:04 -07005322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 synchronized (mWindowMap) {
5324 try {
5325 watcher.asBinder().linkToDeath(dr, 0);
5326 mRotationWatchers.add(watcher);
5327 } catch (RemoteException e) {
5328 // Client died, no cleanup needed.
5329 }
Romain Guy06882f82009-06-10 13:36:04 -07005330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005331 return mRotation;
5332 }
5333 }
5334
5335 /**
5336 * Starts the view server on the specified port.
5337 *
5338 * @param port The port to listener to.
5339 *
5340 * @return True if the server was successfully started, false otherwise.
5341 *
5342 * @see com.android.server.ViewServer
5343 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5344 */
5345 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005346 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 return false;
5348 }
5349
5350 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5351 return false;
5352 }
5353
5354 if (port < 1024) {
5355 return false;
5356 }
5357
5358 if (mViewServer != null) {
5359 if (!mViewServer.isRunning()) {
5360 try {
5361 return mViewServer.start();
5362 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005363 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005364 }
5365 }
5366 return false;
5367 }
5368
5369 try {
5370 mViewServer = new ViewServer(this, port);
5371 return mViewServer.start();
5372 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005373 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374 }
5375 return false;
5376 }
5377
Romain Guy06882f82009-06-10 13:36:04 -07005378 private boolean isSystemSecure() {
5379 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5380 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5381 }
5382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005383 /**
5384 * Stops the view server if it exists.
5385 *
5386 * @return True if the server stopped, false if it wasn't started or
5387 * couldn't be stopped.
5388 *
5389 * @see com.android.server.ViewServer
5390 */
5391 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005392 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 return false;
5394 }
5395
5396 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5397 return false;
5398 }
5399
5400 if (mViewServer != null) {
5401 return mViewServer.stop();
5402 }
5403 return false;
5404 }
5405
5406 /**
5407 * Indicates whether the view server is running.
5408 *
5409 * @return True if the server is running, false otherwise.
5410 *
5411 * @see com.android.server.ViewServer
5412 */
5413 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005414 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005415 return false;
5416 }
5417
5418 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5419 return false;
5420 }
5421
5422 return mViewServer != null && mViewServer.isRunning();
5423 }
5424
5425 /**
5426 * Lists all availble windows in the system. The listing is written in the
5427 * specified Socket's output stream with the following syntax:
5428 * windowHashCodeInHexadecimal windowName
5429 * Each line of the ouput represents a different window.
5430 *
5431 * @param client The remote client to send the listing to.
5432 * @return False if an error occured, true otherwise.
5433 */
5434 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005435 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 return false;
5437 }
5438
5439 boolean result = true;
5440
Jeff Browne33348b2010-07-15 23:54:05 -07005441 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005442 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005443 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005444 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445 }
5446
5447 BufferedWriter out = null;
5448
5449 // Any uncaught exception will crash the system process
5450 try {
5451 OutputStream clientStream = client.getOutputStream();
5452 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5453
5454 final int count = windows.length;
5455 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005456 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 out.write(Integer.toHexString(System.identityHashCode(w)));
5458 out.write(' ');
5459 out.append(w.mAttrs.getTitle());
5460 out.write('\n');
5461 }
5462
5463 out.write("DONE.\n");
5464 out.flush();
5465 } catch (Exception e) {
5466 result = false;
5467 } finally {
5468 if (out != null) {
5469 try {
5470 out.close();
5471 } catch (IOException e) {
5472 result = false;
5473 }
5474 }
5475 }
5476
5477 return result;
5478 }
5479
5480 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005481 * Returns the focused window in the following format:
5482 * windowHashCodeInHexadecimal windowName
5483 *
5484 * @param client The remote client to send the listing to.
5485 * @return False if an error occurred, true otherwise.
5486 */
5487 boolean viewServerGetFocusedWindow(Socket client) {
5488 if (isSystemSecure()) {
5489 return false;
5490 }
5491
5492 boolean result = true;
5493
5494 WindowState focusedWindow = getFocusedWindow();
5495
5496 BufferedWriter out = null;
5497
5498 // Any uncaught exception will crash the system process
5499 try {
5500 OutputStream clientStream = client.getOutputStream();
5501 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5502
5503 if(focusedWindow != null) {
5504 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5505 out.write(' ');
5506 out.append(focusedWindow.mAttrs.getTitle());
5507 }
5508 out.write('\n');
5509 out.flush();
5510 } catch (Exception e) {
5511 result = false;
5512 } finally {
5513 if (out != null) {
5514 try {
5515 out.close();
5516 } catch (IOException e) {
5517 result = false;
5518 }
5519 }
5520 }
5521
5522 return result;
5523 }
5524
5525 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005526 * Sends a command to a target window. The result of the command, if any, will be
5527 * written in the output stream of the specified socket.
5528 *
5529 * The parameters must follow this syntax:
5530 * windowHashcode extra
5531 *
5532 * Where XX is the length in characeters of the windowTitle.
5533 *
5534 * The first parameter is the target window. The window with the specified hashcode
5535 * will be the target. If no target can be found, nothing happens. The extra parameters
5536 * will be delivered to the target window and as parameters to the command itself.
5537 *
5538 * @param client The remote client to sent the result, if any, to.
5539 * @param command The command to execute.
5540 * @param parameters The command parameters.
5541 *
5542 * @return True if the command was successfully delivered, false otherwise. This does
5543 * not indicate whether the command itself was successful.
5544 */
5545 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005546 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005547 return false;
5548 }
5549
5550 boolean success = true;
5551 Parcel data = null;
5552 Parcel reply = null;
5553
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005554 BufferedWriter out = null;
5555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005556 // Any uncaught exception will crash the system process
5557 try {
5558 // Find the hashcode of the window
5559 int index = parameters.indexOf(' ');
5560 if (index == -1) {
5561 index = parameters.length();
5562 }
5563 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005564 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005565
5566 // Extract the command's parameter after the window description
5567 if (index < parameters.length()) {
5568 parameters = parameters.substring(index + 1);
5569 } else {
5570 parameters = "";
5571 }
5572
5573 final WindowManagerService.WindowState window = findWindow(hashCode);
5574 if (window == null) {
5575 return false;
5576 }
5577
5578 data = Parcel.obtain();
5579 data.writeInterfaceToken("android.view.IWindow");
5580 data.writeString(command);
5581 data.writeString(parameters);
5582 data.writeInt(1);
5583 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5584
5585 reply = Parcel.obtain();
5586
5587 final IBinder binder = window.mClient.asBinder();
5588 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5589 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5590
5591 reply.readException();
5592
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005593 if (!client.isOutputShutdown()) {
5594 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5595 out.write("DONE\n");
5596 out.flush();
5597 }
5598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005599 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005600 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005601 success = false;
5602 } finally {
5603 if (data != null) {
5604 data.recycle();
5605 }
5606 if (reply != null) {
5607 reply.recycle();
5608 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005609 if (out != null) {
5610 try {
5611 out.close();
5612 } catch (IOException e) {
5613
5614 }
5615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616 }
5617
5618 return success;
5619 }
5620
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005621 public void addWindowChangeListener(WindowChangeListener listener) {
5622 synchronized(mWindowMap) {
5623 mWindowChangeListeners.add(listener);
5624 }
5625 }
5626
5627 public void removeWindowChangeListener(WindowChangeListener listener) {
5628 synchronized(mWindowMap) {
5629 mWindowChangeListeners.remove(listener);
5630 }
5631 }
5632
5633 private void notifyWindowsChanged() {
5634 WindowChangeListener[] windowChangeListeners;
5635 synchronized(mWindowMap) {
5636 if(mWindowChangeListeners.isEmpty()) {
5637 return;
5638 }
5639 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5640 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5641 }
5642 int N = windowChangeListeners.length;
5643 for(int i = 0; i < N; i++) {
5644 windowChangeListeners[i].windowsChanged();
5645 }
5646 }
5647
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005648 private void notifyFocusChanged() {
5649 WindowChangeListener[] windowChangeListeners;
5650 synchronized(mWindowMap) {
5651 if(mWindowChangeListeners.isEmpty()) {
5652 return;
5653 }
5654 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5655 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5656 }
5657 int N = windowChangeListeners.length;
5658 for(int i = 0; i < N; i++) {
5659 windowChangeListeners[i].focusChanged();
5660 }
5661 }
5662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005663 private WindowState findWindow(int hashCode) {
5664 if (hashCode == -1) {
5665 return getFocusedWindow();
5666 }
5667
5668 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005669 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005670 final int count = windows.size();
5671
5672 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005673 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005674 if (System.identityHashCode(w) == hashCode) {
5675 return w;
5676 }
5677 }
5678 }
5679
5680 return null;
5681 }
5682
5683 /*
5684 * Instruct the Activity Manager to fetch the current configuration and broadcast
5685 * that to config-changed listeners if appropriate.
5686 */
5687 void sendNewConfiguration() {
5688 try {
5689 mActivityManager.updateConfiguration(null);
5690 } catch (RemoteException e) {
5691 }
5692 }
Romain Guy06882f82009-06-10 13:36:04 -07005693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005694 public Configuration computeNewConfiguration() {
5695 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005696 Configuration config = computeNewConfigurationLocked();
5697 if (config == null && mWaitingForConfig) {
5698 // Nothing changed but we are waiting for something... stop that!
5699 mWaitingForConfig = false;
5700 performLayoutAndPlaceSurfacesLocked();
5701 }
5702 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005703 }
5704 }
Romain Guy06882f82009-06-10 13:36:04 -07005705
Dianne Hackbornc485a602009-03-24 22:39:49 -07005706 Configuration computeNewConfigurationLocked() {
5707 Configuration config = new Configuration();
5708 if (!computeNewConfigurationLocked(config)) {
5709 return null;
5710 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005711 return config;
5712 }
Romain Guy06882f82009-06-10 13:36:04 -07005713
Dianne Hackbornc485a602009-03-24 22:39:49 -07005714 boolean computeNewConfigurationLocked(Configuration config) {
5715 if (mDisplay == null) {
5716 return false;
5717 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005718
5719 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005720
5721 // Use the effective "visual" dimensions based on current rotation
5722 final boolean rotated = (mRotation == Surface.ROTATION_90
5723 || mRotation == Surface.ROTATION_270);
5724 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5725 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5726
Dianne Hackbornc485a602009-03-24 22:39:49 -07005727 int orientation = Configuration.ORIENTATION_SQUARE;
5728 if (dw < dh) {
5729 orientation = Configuration.ORIENTATION_PORTRAIT;
5730 } else if (dw > dh) {
5731 orientation = Configuration.ORIENTATION_LANDSCAPE;
5732 }
5733 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005734
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005735 DisplayMetrics dm = new DisplayMetrics();
5736 mDisplay.getMetrics(dm);
5737 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5738
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005739 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005740 // Note we only do this once because at this point we don't
5741 // expect the screen to change in this way at runtime, and want
5742 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005743 int longSize = dw;
5744 int shortSize = dh;
5745 if (longSize < shortSize) {
5746 int tmp = longSize;
5747 longSize = shortSize;
5748 shortSize = tmp;
5749 }
5750 longSize = (int)(longSize/dm.density);
5751 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005752
Dianne Hackborn723738c2009-06-25 19:48:04 -07005753 // These semi-magic numbers define our compatibility modes for
5754 // applications with different screens. Don't change unless you
5755 // make sure to test lots and lots of apps!
5756 if (longSize < 470) {
5757 // This is shorter than an HVGA normal density screen (which
5758 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005759 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5760 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005761 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005762 // What size is this screen screen?
5763 if (longSize >= 800 && shortSize >= 600) {
5764 // SVGA or larger screens at medium density are the point
5765 // at which we consider it to be an extra large screen.
5766 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005767 } else if (longSize >= 530 && shortSize >= 400) {
5768 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005769 // at which we consider it to be a large screen.
5770 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5771 } else {
5772 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Dianne Hackborne97a12e2011-01-29 13:22:02 -08005773 }
5774
5775 // If this screen is wider than normal HVGA, or taller
5776 // than FWVGA, then for old apps we want to run in size
5777 // compatibility mode.
5778 if (shortSize > 321 || longSize > 570) {
5779 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005780 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005781
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005782 // Is this a long screen?
5783 if (((longSize*3)/5) >= (shortSize-1)) {
5784 // Anything wider than WVGA (5:3) is considering to be long.
5785 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5786 } else {
5787 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5788 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005789 }
5790 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005791 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005792
Jeff Brown597eec82011-01-31 17:12:25 -08005793 // Determine whether a hard keyboard is available and enabled.
Jeff Brown2992ea72011-01-28 22:04:14 -08005794 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5795 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5796 mHardKeyboardAvailable = hardKeyboardAvailable;
5797 mHardKeyboardEnabled = hardKeyboardAvailable;
5798
5799 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5800 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5801 }
5802 if (!mHardKeyboardEnabled) {
5803 config.keyboard = Configuration.KEYBOARD_NOKEYS;
Jeff Brown2992ea72011-01-28 22:04:14 -08005804 }
Jeff Brown597eec82011-01-31 17:12:25 -08005805
5806 // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
5807 // based on whether a hard or soft keyboard is present, whether navigation keys
5808 // are present and the lid switch state.
5809 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5810 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5811 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
5812 mPolicy.adjustConfigurationLw(config);
Dianne Hackbornc485a602009-03-24 22:39:49 -07005813 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005814 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005815
Jeff Brown2992ea72011-01-28 22:04:14 -08005816 public boolean isHardKeyboardAvailable() {
5817 synchronized (mWindowMap) {
5818 return mHardKeyboardAvailable;
5819 }
5820 }
5821
5822 public boolean isHardKeyboardEnabled() {
5823 synchronized (mWindowMap) {
5824 return mHardKeyboardEnabled;
5825 }
5826 }
5827
5828 public void setHardKeyboardEnabled(boolean enabled) {
5829 synchronized (mWindowMap) {
5830 if (mHardKeyboardEnabled != enabled) {
5831 mHardKeyboardEnabled = enabled;
5832 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5833 }
5834 }
5835 }
5836
5837 public void setOnHardKeyboardStatusChangeListener(
5838 OnHardKeyboardStatusChangeListener listener) {
5839 synchronized (mWindowMap) {
5840 mHardKeyboardStatusChangeListener = listener;
5841 }
5842 }
5843
5844 void notifyHardKeyboardStatusChange() {
5845 final boolean available, enabled;
5846 final OnHardKeyboardStatusChangeListener listener;
5847 synchronized (mWindowMap) {
5848 listener = mHardKeyboardStatusChangeListener;
5849 available = mHardKeyboardAvailable;
5850 enabled = mHardKeyboardEnabled;
5851 }
5852 if (listener != null) {
5853 listener.onHardKeyboardStatusChange(available, enabled);
5854 }
5855 }
5856
Christopher Tatea53146c2010-09-07 11:57:52 -07005857 // -------------------------------------------------------------
5858 // Drag and drop
5859 // -------------------------------------------------------------
5860
5861 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005862 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005863 if (DEBUG_DRAG) {
5864 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005865 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005866 + " asbinder=" + window.asBinder());
5867 }
5868
5869 final int callerPid = Binder.getCallingPid();
5870 final long origId = Binder.clearCallingIdentity();
5871 IBinder token = null;
5872
5873 try {
5874 synchronized (mWindowMap) {
5875 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005876 if (mDragState == null) {
5877 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5878 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5879 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005880 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005881 token = new Binder();
Christopher Tate251602f2011-01-28 17:54:12 -08005882 mDragState = new DragState(token, surface, flags, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005883 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005884 token = mDragState.mToken = new Binder();
5885
5886 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005887 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5888 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005889 mH.sendMessageDelayed(msg, 5000);
5890 } else {
5891 Slog.w(TAG, "Drag already in progress");
5892 }
5893 } catch (Surface.OutOfResourcesException e) {
5894 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5895 if (mDragState != null) {
5896 mDragState.reset();
5897 mDragState = null;
5898 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005899 }
5900 }
5901 } finally {
5902 Binder.restoreCallingIdentity(origId);
5903 }
5904
5905 return token;
5906 }
5907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005908 // -------------------------------------------------------------
5909 // Input Events and Focus Management
5910 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005911
Jeff Brown349703e2010-06-22 01:27:15 -07005912 InputMonitor mInputMonitor = new InputMonitor();
5913
5914 /* Tracks the progress of input dispatch and ensures that input dispatch state
5915 * is kept in sync with changes in window focus, visibility, registration, and
5916 * other relevant Window Manager state transitions. */
5917 final class InputMonitor {
5918 // Current window with input focus for keys and other non-touch events. May be null.
5919 private WindowState mInputFocus;
5920
5921 // When true, prevents input dispatch from proceeding until set to false again.
5922 private boolean mInputDispatchFrozen;
5923
5924 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5925 private boolean mInputDispatchEnabled = true;
5926
Jeff Brown3a22cd92011-01-21 13:59:04 -08005927 // When true, need to call updateInputWindowsLw().
5928 private boolean mUpdateInputWindowsNeeded = true;
5929
Jeff Brown349703e2010-06-22 01:27:15 -07005930 // Temporary list of windows information to provide to the input dispatcher.
5931 private InputWindowList mTempInputWindows = new InputWindowList();
5932
5933 // Temporary input application object to provide to the input dispatcher.
5934 private InputApplication mTempInputApplication = new InputApplication();
5935
Jeff Brownb09abc12011-01-13 21:08:27 -08005936 // Set to true when the first input device configuration change notification
5937 // is received to indicate that the input devices are ready.
5938 private final Object mInputDevicesReadyMonitor = new Object();
5939 private boolean mInputDevicesReady;
5940
Jeff Brown349703e2010-06-22 01:27:15 -07005941 /* Notifies the window manager about a broken input channel.
5942 *
5943 * Called by the InputManager.
5944 */
Jeff Brown928e0542011-01-10 11:17:36 -08005945 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5946 if (inputWindowHandle == null) {
5947 return;
5948 }
5949
Jeff Brown349703e2010-06-22 01:27:15 -07005950 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005951 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005952 Slog.i(TAG, "WINDOW DIED " + windowState);
5953 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005954 }
5955 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005956
Jeff Brown519e0242010-09-15 15:18:56 -07005957 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005958 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005959 *
5960 * Called by the InputManager.
5961 */
Jeff Brown928e0542011-01-10 11:17:36 -08005962 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5963 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005964 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005965 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005966 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005967 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005968 if (windowState != null) {
5969 Slog.i(TAG, "Input event dispatching timed out sending to "
5970 + windowState.mAttrs.getTitle());
5971 appWindowToken = windowState.mAppToken;
5972 }
Jeff Brown349703e2010-06-22 01:27:15 -07005973 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005974 }
5975
Jeff Brown928e0542011-01-10 11:17:36 -08005976 if (appWindowToken == null && inputApplicationHandle != null) {
5977 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005978 Slog.i(TAG, "Input event dispatching timed out sending to application "
5979 + appWindowToken.stringName);
5980 }
Jeff Brown349703e2010-06-22 01:27:15 -07005981
Jeff Brown519e0242010-09-15 15:18:56 -07005982 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005983 try {
5984 // Notify the activity manager about the timeout and let it decide whether
5985 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005986 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005987 if (! abort) {
5988 // The activity manager declined to abort dispatching.
5989 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005990 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005991 }
Jeff Brown349703e2010-06-22 01:27:15 -07005992 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005993 }
5994 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005995 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005996 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005997
Chris Tatea32dcf72010-10-14 12:13:50 -07005998 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005999 final InputWindow inputWindow = windowList.add();
6000 inputWindow.inputChannel = mDragState.mServerChannel;
6001 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08006002 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07006003 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
6004 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6005 inputWindow.visible = true;
6006 inputWindow.canReceiveKeys = false;
6007 inputWindow.hasFocus = true;
6008 inputWindow.hasWallpaper = false;
6009 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07006010 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07006011 inputWindow.ownerPid = Process.myPid();
6012 inputWindow.ownerUid = Process.myUid();
6013
6014 // The drag window covers the entire display
6015 inputWindow.frameLeft = 0;
6016 inputWindow.frameTop = 0;
6017 inputWindow.frameRight = mDisplay.getWidth();
6018 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07006019
Jeff Brownfbf09772011-01-16 14:06:57 -08006020 // The drag window cannot receive new touches.
6021 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07006022 }
6023
Jeff Brown3a22cd92011-01-21 13:59:04 -08006024 public void setUpdateInputWindowsNeededLw() {
6025 mUpdateInputWindowsNeeded = true;
6026 }
6027
Jeff Brown349703e2010-06-22 01:27:15 -07006028 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08006029 public void updateInputWindowsLw(boolean force) {
6030 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006031 return;
6032 }
6033 mUpdateInputWindowsNeeded = false;
6034
Jeff Brown349703e2010-06-22 01:27:15 -07006035 // Populate the input window list with information about all of the windows that
6036 // could potentially receive input.
6037 // As an optimization, we could try to prune the list of windows but this turns
6038 // out to be difficult because only the native code knows for sure which window
6039 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07006040 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07006041
6042 // If there's a drag in flight, provide a pseudowindow to catch drag input
6043 final boolean inDrag = (mDragState != null);
6044 if (inDrag) {
6045 if (DEBUG_DRAG) {
6046 Log.d(TAG, "Inserting drag window");
6047 }
Chris Tatea32dcf72010-10-14 12:13:50 -07006048 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07006049 }
6050
Jeff Brown7fbdc842010-06-17 20:52:56 -07006051 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07006052 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006053 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07006054 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07006055 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07006056 continue;
6057 }
6058
Jeff Brown349703e2010-06-22 01:27:15 -07006059 final int flags = child.mAttrs.flags;
6060 final int type = child.mAttrs.type;
6061
6062 final boolean hasFocus = (child == mInputFocus);
6063 final boolean isVisible = child.isVisibleLw();
6064 final boolean hasWallpaper = (child == mWallpaperTarget)
6065 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07006066
6067 // If there's a drag in progress and 'child' is a potential drop target,
6068 // make sure it's been told about the drag
6069 if (inDrag && isVisible) {
6070 mDragState.sendDragStartedIfNeededLw(child);
6071 }
6072
Jeff Brown349703e2010-06-22 01:27:15 -07006073 // Add a window to our list of input windows.
6074 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08006075 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006076 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07006077 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07006078 inputWindow.layoutParamsFlags = flags;
6079 inputWindow.layoutParamsType = type;
6080 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
6081 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07006082 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07006083 inputWindow.hasFocus = hasFocus;
6084 inputWindow.hasWallpaper = hasWallpaper;
6085 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07006086 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07006087 inputWindow.ownerPid = child.mSession.mPid;
6088 inputWindow.ownerUid = child.mSession.mUid;
6089
6090 final Rect frame = child.mFrame;
6091 inputWindow.frameLeft = frame.left;
6092 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006093 inputWindow.frameRight = frame.right;
6094 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006095
6096 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006097 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006098
Jeff Brown349703e2010-06-22 01:27:15 -07006099 // Send windows to native code.
6100 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006101
Jeff Brown349703e2010-06-22 01:27:15 -07006102 // Clear the list in preparation for the next round.
6103 // Also avoids keeping InputChannel objects referenced unnecessarily.
6104 mTempInputWindows.clear();
6105 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006106
6107 /* Notifies that the input device configuration has changed. */
6108 public void notifyConfigurationChanged() {
6109 sendNewConfiguration();
6110
6111 synchronized (mInputDevicesReadyMonitor) {
6112 if (!mInputDevicesReady) {
6113 mInputDevicesReady = true;
6114 mInputDevicesReadyMonitor.notifyAll();
6115 }
6116 }
6117 }
6118
6119 /* Waits until the built-in input devices have been configured. */
6120 public boolean waitForInputDevicesReady(long timeoutMillis) {
6121 synchronized (mInputDevicesReadyMonitor) {
6122 if (!mInputDevicesReady) {
6123 try {
6124 mInputDevicesReadyMonitor.wait(timeoutMillis);
6125 } catch (InterruptedException ex) {
6126 }
6127 }
6128 return mInputDevicesReady;
6129 }
6130 }
6131
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006132 /* Notifies that the lid switch changed state. */
6133 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6134 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6135 }
6136
Jeff Brown349703e2010-06-22 01:27:15 -07006137 /* Provides an opportunity for the window manager policy to intercept early key
6138 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006139 public int interceptKeyBeforeQueueing(
6140 KeyEvent event, int policyFlags, boolean isScreenOn) {
6141 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006142 }
6143
6144 /* Provides an opportunity for the window manager policy to process a key before
6145 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006146 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006147 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006148 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006149 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006150 }
6151
Jeff Brown3915bb82010-11-05 15:02:16 -07006152 /* Provides an opportunity for the window manager policy to process a key that
6153 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006154 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006155 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006156 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006157 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006158 }
6159
Jeff Brown349703e2010-06-22 01:27:15 -07006160 /* Called when the current input focus changes.
6161 * Layer assignment is assumed to be complete by the time this is called.
6162 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006163 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006164 if (DEBUG_INPUT) {
6165 Slog.d(TAG, "Input focus has changed to " + newWindow);
6166 }
6167
6168 if (newWindow != mInputFocus) {
6169 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006170 // Displaying a window implicitly causes dispatching to be unpaused.
6171 // This is to protect against bugs if someone pauses dispatching but
6172 // forgets to resume.
6173 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006174 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006175
Jeff Brown349703e2010-06-22 01:27:15 -07006176 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006177 setUpdateInputWindowsNeededLw();
6178
6179 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006180 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006181 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006182 }
6183 }
6184
Jeff Brown349703e2010-06-22 01:27:15 -07006185 public void setFocusedAppLw(AppWindowToken newApp) {
6186 // Focused app has changed.
6187 if (newApp == null) {
6188 mInputManager.setFocusedApplication(null);
6189 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006190 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006191 mTempInputApplication.name = newApp.toString();
6192 mTempInputApplication.dispatchingTimeoutNanos =
6193 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006194
Jeff Brown349703e2010-06-22 01:27:15 -07006195 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006196
6197 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006198 }
6199 }
6200
Jeff Brown349703e2010-06-22 01:27:15 -07006201 public void pauseDispatchingLw(WindowToken window) {
6202 if (! window.paused) {
6203 if (DEBUG_INPUT) {
6204 Slog.v(TAG, "Pausing WindowToken " + window);
6205 }
6206
6207 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006208 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006209 }
6210 }
6211
6212 public void resumeDispatchingLw(WindowToken window) {
6213 if (window.paused) {
6214 if (DEBUG_INPUT) {
6215 Slog.v(TAG, "Resuming WindowToken " + window);
6216 }
6217
6218 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006219 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006220 }
6221 }
6222
6223 public void freezeInputDispatchingLw() {
6224 if (! mInputDispatchFrozen) {
6225 if (DEBUG_INPUT) {
6226 Slog.v(TAG, "Freezing input dispatching");
6227 }
6228
6229 mInputDispatchFrozen = true;
6230 updateInputDispatchModeLw();
6231 }
6232 }
6233
6234 public void thawInputDispatchingLw() {
6235 if (mInputDispatchFrozen) {
6236 if (DEBUG_INPUT) {
6237 Slog.v(TAG, "Thawing input dispatching");
6238 }
6239
6240 mInputDispatchFrozen = false;
6241 updateInputDispatchModeLw();
6242 }
6243 }
6244
6245 public void setEventDispatchingLw(boolean enabled) {
6246 if (mInputDispatchEnabled != enabled) {
6247 if (DEBUG_INPUT) {
6248 Slog.v(TAG, "Setting event dispatching to " + enabled);
6249 }
6250
6251 mInputDispatchEnabled = enabled;
6252 updateInputDispatchModeLw();
6253 }
6254 }
6255
6256 private void updateInputDispatchModeLw() {
6257 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6258 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006259 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006261 public void pauseKeyDispatching(IBinder _token) {
6262 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6263 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006264 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006265 }
6266
6267 synchronized (mWindowMap) {
6268 WindowToken token = mTokenMap.get(_token);
6269 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006270 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006271 }
6272 }
6273 }
6274
6275 public void resumeKeyDispatching(IBinder _token) {
6276 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6277 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006278 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006279 }
6280
6281 synchronized (mWindowMap) {
6282 WindowToken token = mTokenMap.get(_token);
6283 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006284 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 }
6286 }
6287 }
6288
6289 public void setEventDispatching(boolean enabled) {
6290 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6291 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006292 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006293 }
6294
6295 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006296 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 }
6298 }
Romain Guy06882f82009-06-10 13:36:04 -07006299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006300 /**
6301 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006302 * Even when sync is false, this method may block while waiting for current
6303 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006304 *
6305 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306 * {@link SystemClock#uptimeMillis()} as the timebase.)
6307 * @param sync If true, wait for the event to be completed before returning to the caller.
6308 * @return Returns true if event was dispatched, false if it was dropped for any reason
6309 */
6310 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6311 long downTime = ev.getDownTime();
6312 long eventTime = ev.getEventTime();
6313
6314 int action = ev.getAction();
6315 int code = ev.getKeyCode();
6316 int repeatCount = ev.getRepeatCount();
6317 int metaState = ev.getMetaState();
6318 int deviceId = ev.getDeviceId();
6319 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006320 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006321 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006322
6323 if (source == InputDevice.SOURCE_UNKNOWN) {
6324 source = InputDevice.SOURCE_KEYBOARD;
6325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326
6327 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6328 if (downTime == 0) downTime = eventTime;
6329
6330 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006331 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006332
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006333 final int pid = Binder.getCallingPid();
6334 final int uid = Binder.getCallingUid();
6335 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006336
Jeff Brownbbda99d2010-07-28 15:48:59 -07006337 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6338 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6339 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6340 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006341
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006342 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006343 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006344 }
6345
6346 /**
6347 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006348 * Even when sync is false, this method may block while waiting for current
6349 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006350 *
6351 * @param ev A motion event describing the pointer (touch) action. (As noted in
6352 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006353 * {@link SystemClock#uptimeMillis()} as the timebase.)
6354 * @param sync If true, wait for the event to be completed before returning to the caller.
6355 * @return Returns true if event was dispatched, false if it was dropped for any reason
6356 */
6357 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006358 final int pid = Binder.getCallingPid();
6359 final int uid = Binder.getCallingUid();
6360 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006361
Jeff Brownc5ed5912010-07-14 18:48:53 -07006362 MotionEvent newEvent = MotionEvent.obtain(ev);
6363 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6364 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6365 }
6366
Jeff Brownbbda99d2010-07-28 15:48:59 -07006367 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6368 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6369 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6370 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006371
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006372 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006373 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 }
Romain Guy06882f82009-06-10 13:36:04 -07006375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 /**
6377 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006378 * Even when sync is false, this method may block while waiting for current
6379 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006380 *
6381 * @param ev A motion event describing the trackball action. (As noted in
6382 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 * {@link SystemClock#uptimeMillis()} as the timebase.)
6384 * @param sync If true, wait for the event to be completed before returning to the caller.
6385 * @return Returns true if event was dispatched, false if it was dropped for any reason
6386 */
6387 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006388 final int pid = Binder.getCallingPid();
6389 final int uid = Binder.getCallingUid();
6390 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006391
Jeff Brownc5ed5912010-07-14 18:48:53 -07006392 MotionEvent newEvent = MotionEvent.obtain(ev);
6393 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6394 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6395 }
6396
Jeff Brownbbda99d2010-07-28 15:48:59 -07006397 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6398 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6399 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6400 INJECTION_TIMEOUT_MILLIS);
6401
6402 Binder.restoreCallingIdentity(ident);
6403 return reportInjectionResult(result);
6404 }
6405
6406 /**
6407 * Inject an input event into the UI without waiting for dispatch to commence.
6408 * This variant is useful for fire-and-forget input event injection. It does not
6409 * block any longer than it takes to enqueue the input event.
6410 *
6411 * @param ev An input event. (Be sure to set the input source correctly.)
6412 * @return Returns true if event was dispatched, false if it was dropped for any reason
6413 */
6414 public boolean injectInputEventNoWait(InputEvent ev) {
6415 final int pid = Binder.getCallingPid();
6416 final int uid = Binder.getCallingUid();
6417 final long ident = Binder.clearCallingIdentity();
6418
6419 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6420 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6421 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006422
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006423 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006424 return reportInjectionResult(result);
6425 }
6426
6427 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006428 switch (result) {
6429 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6430 Slog.w(TAG, "Input event injection permission denied.");
6431 throw new SecurityException(
6432 "Injecting to another application requires INJECT_EVENTS permission");
6433 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006434 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006435 return true;
6436 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6437 Slog.w(TAG, "Input event injection timed out.");
6438 return false;
6439 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6440 default:
6441 Slog.w(TAG, "Input event injection failed.");
6442 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006444 }
Romain Guy06882f82009-06-10 13:36:04 -07006445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006446 private WindowState getFocusedWindow() {
6447 synchronized (mWindowMap) {
6448 return getFocusedWindowLocked();
6449 }
6450 }
6451
6452 private WindowState getFocusedWindowLocked() {
6453 return mCurrentFocus;
6454 }
Romain Guy06882f82009-06-10 13:36:04 -07006455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006457 if (!mInputMonitor.waitForInputDevicesReady(
6458 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6459 Slog.w(TAG, "Devices still not ready after waiting "
6460 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6461 + " milliseconds before attempting to detect safe mode.");
6462 }
6463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006464 mSafeMode = mPolicy.detectSafeMode();
6465 return mSafeMode;
6466 }
Romain Guy06882f82009-06-10 13:36:04 -07006467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006468 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006469 synchronized(mWindowMap) {
6470 if (mDisplay != null) {
6471 throw new IllegalStateException("Display already initialized");
6472 }
6473 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6474 mDisplay = wm.getDefaultDisplay();
6475 mInitialDisplayWidth = mDisplay.getWidth();
6476 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006477 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6478 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006479 }
6480
6481 try {
6482 mActivityManager.updateConfiguration(null);
6483 } catch (RemoteException e) {
6484 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006485
6486 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006487 }
6488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006489 // -------------------------------------------------------------
6490 // Client Session State
6491 // -------------------------------------------------------------
6492
6493 private final class Session extends IWindowSession.Stub
6494 implements IBinder.DeathRecipient {
6495 final IInputMethodClient mClient;
6496 final IInputContext mInputContext;
6497 final int mUid;
6498 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006499 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006500 SurfaceSession mSurfaceSession;
6501 int mNumWindow = 0;
6502 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006504 public Session(IInputMethodClient client, IInputContext inputContext) {
6505 mClient = client;
6506 mInputContext = inputContext;
6507 mUid = Binder.getCallingUid();
6508 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006509 StringBuilder sb = new StringBuilder();
6510 sb.append("Session{");
6511 sb.append(Integer.toHexString(System.identityHashCode(this)));
6512 sb.append(" uid ");
6513 sb.append(mUid);
6514 sb.append("}");
6515 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006517 synchronized (mWindowMap) {
6518 if (mInputMethodManager == null && mHaveInputMethods) {
6519 IBinder b = ServiceManager.getService(
6520 Context.INPUT_METHOD_SERVICE);
6521 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6522 }
6523 }
6524 long ident = Binder.clearCallingIdentity();
6525 try {
6526 // Note: it is safe to call in to the input method manager
6527 // here because we are not holding our lock.
6528 if (mInputMethodManager != null) {
6529 mInputMethodManager.addClient(client, inputContext,
6530 mUid, mPid);
6531 } else {
6532 client.setUsingInputMethod(false);
6533 }
6534 client.asBinder().linkToDeath(this, 0);
6535 } catch (RemoteException e) {
6536 // The caller has died, so we can just forget about this.
6537 try {
6538 if (mInputMethodManager != null) {
6539 mInputMethodManager.removeClient(client);
6540 }
6541 } catch (RemoteException ee) {
6542 }
6543 } finally {
6544 Binder.restoreCallingIdentity(ident);
6545 }
6546 }
Romain Guy06882f82009-06-10 13:36:04 -07006547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 @Override
6549 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6550 throws RemoteException {
6551 try {
6552 return super.onTransact(code, data, reply, flags);
6553 } catch (RuntimeException e) {
6554 // Log all 'real' exceptions thrown to the caller
6555 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006556 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006557 }
6558 throw e;
6559 }
6560 }
6561
6562 public void binderDied() {
6563 // Note: it is safe to call in to the input method manager
6564 // here because we are not holding our lock.
6565 try {
6566 if (mInputMethodManager != null) {
6567 mInputMethodManager.removeClient(mClient);
6568 }
6569 } catch (RemoteException e) {
6570 }
6571 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006572 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 mClientDead = true;
6574 killSessionLocked();
6575 }
6576 }
6577
6578 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006579 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6580 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6581 outInputChannel);
6582 }
6583
6584 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006586 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 }
Romain Guy06882f82009-06-10 13:36:04 -07006588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006589 public void remove(IWindow window) {
6590 removeWindow(this, window);
6591 }
Romain Guy06882f82009-06-10 13:36:04 -07006592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6594 int requestedWidth, int requestedHeight, int viewFlags,
6595 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006596 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006597 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6598 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006599 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006600 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006601 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6602 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 }
Romain Guy06882f82009-06-10 13:36:04 -07006604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006605 public void setTransparentRegion(IWindow window, Region region) {
6606 setTransparentRegionWindow(this, window, region);
6607 }
Romain Guy06882f82009-06-10 13:36:04 -07006608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006610 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006611 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006612 visibleInsets, touchableArea);
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 getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6616 getWindowDisplayFrame(this, window, outDisplayFrame);
6617 }
Romain Guy06882f82009-06-10 13:36:04 -07006618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006620 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006621 TAG, "IWindow finishDrawing called for " + window);
6622 finishDrawingWindow(this, window);
6623 }
6624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006625 public void setInTouchMode(boolean mode) {
6626 synchronized(mWindowMap) {
6627 mInTouchMode = mode;
6628 }
6629 }
6630
6631 public boolean getInTouchMode() {
6632 synchronized(mWindowMap) {
6633 return mInTouchMode;
6634 }
6635 }
6636
6637 public boolean performHapticFeedback(IWindow window, int effectId,
6638 boolean always) {
6639 synchronized(mWindowMap) {
6640 long ident = Binder.clearCallingIdentity();
6641 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006642 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006643 windowForClientLocked(this, window, true),
6644 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006645 } finally {
6646 Binder.restoreCallingIdentity(ident);
6647 }
6648 }
6649 }
Romain Guy06882f82009-06-10 13:36:04 -07006650
Christopher Tatea53146c2010-09-07 11:57:52 -07006651 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006652 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006653 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006654 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006655 width, height, outSurface);
6656 }
6657
6658 public boolean performDrag(IWindow window, IBinder dragToken,
6659 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6660 ClipData data) {
6661 if (DEBUG_DRAG) {
6662 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6663 }
6664
6665 synchronized (mWindowMap) {
6666 if (mDragState == null) {
6667 Slog.w(TAG, "No drag prepared");
6668 throw new IllegalStateException("performDrag() without prepareDrag()");
6669 }
6670
6671 if (dragToken != mDragState.mToken) {
6672 Slog.w(TAG, "Performing mismatched drag");
6673 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6674 }
6675
6676 WindowState callingWin = windowForClientLocked(null, window, false);
6677 if (callingWin == null) {
6678 Slog.w(TAG, "Bad requesting window " + window);
6679 return false; // !!! TODO: throw here?
6680 }
6681
6682 // !!! TODO: if input is not still focused on the initiating window, fail
6683 // the drag initiation (e.g. an alarm window popped up just as the application
6684 // called performDrag()
6685
6686 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6687
Christopher Tate2c095f32010-10-04 14:13:40 -07006688 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6689 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006690
Chris Tateb478f462010-10-15 16:02:26 -07006691 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6692 // the actual drag event dispatch stuff in the dragstate
6693
Christopher Tatea53146c2010-09-07 11:57:52 -07006694 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006695 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006696 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6697 mDragState.mServerChannel)) {
6698 Slog.e(TAG, "Unable to transfer touch focus");
6699 mDragState.unregister();
6700 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006701 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006702 return false;
6703 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006704
6705 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006706 mDragState.mCurrentX = touchX;
6707 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006708 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006709
6710 // remember the thumb offsets for later
6711 mDragState.mThumbOffsetX = thumbCenterX;
6712 mDragState.mThumbOffsetY = thumbCenterY;
6713
6714 // Make the surface visible at the proper location
6715 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006716 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006717 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006718 try {
6719 surface.setPosition((int)(touchX - thumbCenterX),
6720 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006721 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006722 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006723 surface.show();
6724 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006725 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006726 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006727 }
6728 }
6729
6730 return true; // success!
6731 }
6732
Chris Tated4533f142010-10-19 15:15:08 -07006733 public void reportDropResult(IWindow window, boolean consumed) {
6734 IBinder token = window.asBinder();
6735 if (DEBUG_DRAG) {
6736 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6737 }
6738
6739 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006740 long ident = Binder.clearCallingIdentity();
6741 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006742 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006743 Slog.w(TAG, "Invalid drop-result claim by " + window);
6744 throw new IllegalStateException("reportDropResult() by non-recipient");
6745 }
6746
6747 // The right window has responded, even if it's no longer around,
6748 // so be sure to halt the timeout even if the later WindowState
6749 // lookup fails.
6750 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6751 WindowState callingWin = windowForClientLocked(null, window, false);
6752 if (callingWin == null) {
6753 Slog.w(TAG, "Bad result-reporting window " + window);
6754 return; // !!! TODO: throw here?
6755 }
6756
6757 mDragState.mDragResult = consumed;
6758 mDragState.endDragLw();
6759 } finally {
6760 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006761 }
Chris Tated4533f142010-10-19 15:15:08 -07006762 }
6763 }
6764
Christopher Tatea53146c2010-09-07 11:57:52 -07006765 public void dragRecipientEntered(IWindow window) {
6766 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006767 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006768 }
6769 }
6770
6771 public void dragRecipientExited(IWindow window) {
6772 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006773 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006774 }
6775 }
6776
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006777 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006778 synchronized(mWindowMap) {
6779 long ident = Binder.clearCallingIdentity();
6780 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006781 setWindowWallpaperPositionLocked(
6782 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006783 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006784 } finally {
6785 Binder.restoreCallingIdentity(ident);
6786 }
6787 }
6788 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006789
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006790 public void wallpaperOffsetsComplete(IBinder window) {
6791 WindowManagerService.this.wallpaperOffsetsComplete(window);
6792 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006793
Dianne Hackborn75804932009-10-20 20:15:20 -07006794 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6795 int z, Bundle extras, boolean sync) {
6796 synchronized(mWindowMap) {
6797 long ident = Binder.clearCallingIdentity();
6798 try {
6799 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006800 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006801 action, x, y, z, extras, sync);
6802 } finally {
6803 Binder.restoreCallingIdentity(ident);
6804 }
6805 }
6806 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006807
Dianne Hackborn75804932009-10-20 20:15:20 -07006808 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6809 WindowManagerService.this.wallpaperCommandComplete(window, result);
6810 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 void windowAddedLocked() {
6813 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006814 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 TAG, "First window added to " + this + ", creating SurfaceSession");
6816 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006817 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006818 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006819 mSessions.add(this);
6820 }
6821 mNumWindow++;
6822 }
6823
6824 void windowRemovedLocked() {
6825 mNumWindow--;
6826 killSessionLocked();
6827 }
Romain Guy06882f82009-06-10 13:36:04 -07006828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006829 void killSessionLocked() {
6830 if (mNumWindow <= 0 && mClientDead) {
6831 mSessions.remove(this);
6832 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006833 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 TAG, "Last window removed from " + this
6835 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006836 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006837 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 try {
6839 mSurfaceSession.kill();
6840 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006841 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006842 + mSurfaceSession + " in session " + this
6843 + ": " + e.toString());
6844 }
6845 mSurfaceSession = null;
6846 }
6847 }
6848 }
Romain Guy06882f82009-06-10 13:36:04 -07006849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006850 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006851 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6852 pw.print(" mClientDead="); pw.print(mClientDead);
6853 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 }
6855
6856 @Override
6857 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006858 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006859 }
6860 }
6861
6862 // -------------------------------------------------------------
6863 // Client Window State
6864 // -------------------------------------------------------------
6865
6866 private final class WindowState implements WindowManagerPolicy.WindowState {
6867 final Session mSession;
6868 final IWindow mClient;
6869 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006870 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 AppWindowToken mAppToken;
6872 AppWindowToken mTargetAppToken;
6873 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6874 final DeathRecipient mDeathRecipient;
6875 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006876 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 final int mBaseLayer;
6878 final int mSubLayer;
6879 final boolean mLayoutAttached;
6880 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006881 final boolean mIsWallpaper;
6882 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 int mViewVisibility;
6884 boolean mPolicyVisibility = true;
6885 boolean mPolicyVisibilityAfterAnim = true;
6886 boolean mAppFreezing;
6887 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006888 boolean mReportDestroySurface;
6889 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006890 boolean mAttachedHidden; // is our parent window hidden?
6891 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006892 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 int mRequestedWidth;
6894 int mRequestedHeight;
6895 int mLastRequestedWidth;
6896 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 int mLayer;
6898 int mAnimLayer;
6899 int mLastLayer;
6900 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006901 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006902 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006904 int mLayoutSeq = -1;
6905
6906 Configuration mConfiguration = null;
6907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006908 // Actual frame shown on-screen (may be modified by animation)
6909 final Rect mShownFrame = new Rect();
6910 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006912 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006913 * Set when we have changed the size of the surface, to know that
6914 * we must tell them application to resize (and thus redraw itself).
6915 */
6916 boolean mSurfaceResized;
6917
6918 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006919 * Insets that determine the actually visible area
6920 */
6921 final Rect mVisibleInsets = new Rect();
6922 final Rect mLastVisibleInsets = new Rect();
6923 boolean mVisibleInsetsChanged;
6924
6925 /**
6926 * Insets that are covered by system windows
6927 */
6928 final Rect mContentInsets = new Rect();
6929 final Rect mLastContentInsets = new Rect();
6930 boolean mContentInsetsChanged;
6931
6932 /**
6933 * Set to true if we are waiting for this window to receive its
6934 * given internal insets before laying out other windows based on it.
6935 */
6936 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006938 /**
6939 * These are the content insets that were given during layout for
6940 * this window, to be applied to windows behind it.
6941 */
6942 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006944 /**
6945 * These are the visible insets that were given during layout for
6946 * this window, to be applied to windows behind it.
6947 */
6948 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006950 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006951 * This is the given touchable area relative to the window frame, or null if none.
6952 */
6953 final Region mGivenTouchableRegion = new Region();
6954
6955 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 * Flag indicating whether the touchable region should be adjusted by
6957 * the visible insets; if false the area outside the visible insets is
6958 * NOT touchable, so we must use those to adjust the frame during hit
6959 * tests.
6960 */
6961 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006964 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006965 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6966 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6967 float mHScale=1, mVScale=1;
6968 float mLastHScale=1, mLastVScale=1;
6969 final Matrix mTmpMatrix = new Matrix();
6970
6971 // "Real" frame that the application sees.
6972 final Rect mFrame = new Rect();
6973 final Rect mLastFrame = new Rect();
6974
6975 final Rect mContainingFrame = new Rect();
6976 final Rect mDisplayFrame = new Rect();
6977 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006978 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006979 final Rect mVisibleFrame = new Rect();
6980
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006981 boolean mContentChanged;
6982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006983 float mShownAlpha = 1;
6984 float mAlpha = 1;
6985 float mLastAlpha = 1;
6986
6987 // Set to true if, when the window gets displayed, it should perform
6988 // an enter animation.
6989 boolean mEnterAnimationPending;
6990
6991 // Currently running animation.
6992 boolean mAnimating;
6993 boolean mLocalAnimating;
6994 Animation mAnimation;
6995 boolean mAnimationIsEntrance;
6996 boolean mHasTransformation;
6997 boolean mHasLocalTransformation;
6998 final Transformation mTransformation = new Transformation();
6999
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007000 // If a window showing a wallpaper: the requested offset for the
7001 // wallpaper; if a wallpaper window: the currently applied offset.
7002 float mWallpaperX = -1;
7003 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007004
7005 // If a window showing a wallpaper: what fraction of the offset
7006 // range corresponds to a full virtual screen.
7007 float mWallpaperXStep = -1;
7008 float mWallpaperYStep = -1;
7009
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007010 // Wallpaper windows: pixels offset based on above variables.
7011 int mXOffset;
7012 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007014 // This is set after IWindowSession.relayout() has been called at
7015 // least once for the window. It allows us to detect the situation
7016 // where we don't yet have a surface, but should have one soon, so
7017 // we can give the window focus before waiting for the relayout.
7018 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007020 // This is set after the Surface has been created but before the
7021 // window has been drawn. During this time the surface is hidden.
7022 boolean mDrawPending;
7023
7024 // This is set after the window has finished drawing for the first
7025 // time but before its surface is shown. The surface will be
7026 // displayed when the next layout is run.
7027 boolean mCommitDrawPending;
7028
7029 // This is set during the time after the window's drawing has been
7030 // committed, and before its surface is actually shown. It is used
7031 // to delay showing the surface until all windows in a token are ready
7032 // to be shown.
7033 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 // Set when the window has been shown in the screen the first time.
7036 boolean mHasDrawn;
7037
7038 // Currently running an exit animation?
7039 boolean mExiting;
7040
7041 // Currently on the mDestroySurface list?
7042 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044 // Completely remove from window manager after exit animation?
7045 boolean mRemoveOnExit;
7046
7047 // Set when the orientation is changing and this window has not yet
7048 // been updated for the new orientation.
7049 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007051 // Is this window now (or just being) removed?
7052 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007053
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007054 // Temp for keeping track of windows that have been removed when
7055 // rebuilding window list.
7056 boolean mRebuilding;
7057
Dianne Hackborn16064f92010-03-25 00:47:24 -07007058 // For debugging, this is the last information given to the surface flinger.
7059 boolean mSurfaceShown;
7060 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7061 int mSurfaceLayer;
7062 float mSurfaceAlpha;
7063
Jeff Brown928e0542011-01-10 11:17:36 -08007064 // Input channel and input window handle used by the input dispatcher.
7065 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007066 InputChannel mInputChannel;
7067
Mattias Petersson1622eee2010-12-21 10:15:11 +01007068 // Used to improve performance of toString()
7069 String mStringNameCache;
7070 CharSequence mLastTitle;
7071 boolean mWasPaused;
7072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007073 WindowState(Session s, IWindow c, WindowToken token,
7074 WindowState attachedWindow, WindowManager.LayoutParams a,
7075 int viewVisibility) {
7076 mSession = s;
7077 mClient = c;
7078 mToken = token;
7079 mAttrs.copyFrom(a);
7080 mViewVisibility = viewVisibility;
7081 DeathRecipient deathRecipient = new DeathRecipient();
7082 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007083 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 TAG, "Window " + this + " client=" + c.asBinder()
7085 + " token=" + token + " (" + mAttrs.token + ")");
7086 try {
7087 c.asBinder().linkToDeath(deathRecipient, 0);
7088 } catch (RemoteException e) {
7089 mDeathRecipient = null;
7090 mAttachedWindow = null;
7091 mLayoutAttached = false;
7092 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007093 mIsWallpaper = false;
7094 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095 mBaseLayer = 0;
7096 mSubLayer = 0;
7097 return;
7098 }
7099 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007101 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7102 mAttrs.type <= LAST_SUB_WINDOW)) {
7103 // The multiplier here is to reserve space for multiple
7104 // windows in the same type layer.
7105 mBaseLayer = mPolicy.windowTypeToLayerLw(
7106 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7107 + TYPE_LAYER_OFFSET;
7108 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7109 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007110 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 mAttachedWindow.mChildWindows.add(this);
7112 mLayoutAttached = mAttrs.type !=
7113 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7114 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7115 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007116 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7117 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007118 } else {
7119 // The multiplier here is to reserve space for multiple
7120 // windows in the same type layer.
7121 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7122 * TYPE_LAYER_MULTIPLIER
7123 + TYPE_LAYER_OFFSET;
7124 mSubLayer = 0;
7125 mAttachedWindow = null;
7126 mLayoutAttached = false;
7127 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7128 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007129 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7130 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007131 }
7132
7133 WindowState appWin = this;
7134 while (appWin.mAttachedWindow != null) {
7135 appWin = mAttachedWindow;
7136 }
7137 WindowToken appToken = appWin.mToken;
7138 while (appToken.appWindowToken == null) {
7139 WindowToken parent = mTokenMap.get(appToken.token);
7140 if (parent == null || appToken == parent) {
7141 break;
7142 }
7143 appToken = parent;
7144 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007145 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007146 mAppToken = appToken.appWindowToken;
7147
7148 mSurface = null;
7149 mRequestedWidth = 0;
7150 mRequestedHeight = 0;
7151 mLastRequestedWidth = 0;
7152 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007153 mXOffset = 0;
7154 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007155 mLayer = 0;
7156 mAnimLayer = 0;
7157 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007158 mInputWindowHandle = new InputWindowHandle(
7159 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007160 }
7161
7162 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007163 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007164 TAG, "Attaching " + this + " token=" + mToken
7165 + ", list=" + mToken.windows);
7166 mSession.windowAddedLocked();
7167 }
7168
7169 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7170 mHaveFrame = true;
7171
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007172 final Rect container = mContainingFrame;
7173 container.set(pf);
7174
7175 final Rect display = mDisplayFrame;
7176 display.set(df);
7177
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007178 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007179 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007180 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7181 display.intersect(mCompatibleScreenFrame);
7182 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007183 }
7184
7185 final int pw = container.right - container.left;
7186 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007187
7188 int w,h;
7189 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7190 w = mAttrs.width < 0 ? pw : mAttrs.width;
7191 h = mAttrs.height< 0 ? ph : mAttrs.height;
7192 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007193 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7194 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 }
Romain Guy06882f82009-06-10 13:36:04 -07007196
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007197 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007198 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7199 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007200 mParentFrame.set(pf);
7201 mContentChanged = true;
7202 }
7203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007204 final Rect content = mContentFrame;
7205 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007207 final Rect visible = mVisibleFrame;
7208 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007211 final int fw = frame.width();
7212 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007214 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7215 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7216
7217 Gravity.apply(mAttrs.gravity, w, h, container,
7218 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7219 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7220
7221 //System.out.println("Out: " + mFrame);
7222
7223 // Now make sure the window fits in the overall display.
7224 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007226 // Make sure the content and visible frames are inside of the
7227 // final window frame.
7228 if (content.left < frame.left) content.left = frame.left;
7229 if (content.top < frame.top) content.top = frame.top;
7230 if (content.right > frame.right) content.right = frame.right;
7231 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7232 if (visible.left < frame.left) visible.left = frame.left;
7233 if (visible.top < frame.top) visible.top = frame.top;
7234 if (visible.right > frame.right) visible.right = frame.right;
7235 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007237 final Rect contentInsets = mContentInsets;
7238 contentInsets.left = content.left-frame.left;
7239 contentInsets.top = content.top-frame.top;
7240 contentInsets.right = frame.right-content.right;
7241 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007243 final Rect visibleInsets = mVisibleInsets;
7244 visibleInsets.left = visible.left-frame.left;
7245 visibleInsets.top = visible.top-frame.top;
7246 visibleInsets.right = frame.right-visible.right;
7247 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007248
Dianne Hackborn284ac932009-08-28 10:34:25 -07007249 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7250 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007251 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007252 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007254 if (localLOGV) {
7255 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7256 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007257 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007258 + mRequestedWidth + ", mRequestedheight="
7259 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7260 + "): frame=" + mFrame.toShortString()
7261 + " ci=" + contentInsets.toShortString()
7262 + " vi=" + visibleInsets.toShortString());
7263 //}
7264 }
7265 }
Romain Guy06882f82009-06-10 13:36:04 -07007266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007267 public Rect getFrameLw() {
7268 return mFrame;
7269 }
7270
7271 public Rect getShownFrameLw() {
7272 return mShownFrame;
7273 }
7274
7275 public Rect getDisplayFrameLw() {
7276 return mDisplayFrame;
7277 }
7278
7279 public Rect getContentFrameLw() {
7280 return mContentFrame;
7281 }
7282
7283 public Rect getVisibleFrameLw() {
7284 return mVisibleFrame;
7285 }
7286
7287 public boolean getGivenInsetsPendingLw() {
7288 return mGivenInsetsPending;
7289 }
7290
7291 public Rect getGivenContentInsetsLw() {
7292 return mGivenContentInsets;
7293 }
Romain Guy06882f82009-06-10 13:36:04 -07007294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 public Rect getGivenVisibleInsetsLw() {
7296 return mGivenVisibleInsets;
7297 }
Romain Guy06882f82009-06-10 13:36:04 -07007298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 public WindowManager.LayoutParams getAttrs() {
7300 return mAttrs;
7301 }
7302
7303 public int getSurfaceLayer() {
7304 return mLayer;
7305 }
Romain Guy06882f82009-06-10 13:36:04 -07007306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007307 public IApplicationToken getAppToken() {
7308 return mAppToken != null ? mAppToken.appToken : null;
7309 }
Jeff Brown349703e2010-06-22 01:27:15 -07007310
7311 public long getInputDispatchingTimeoutNanos() {
7312 return mAppToken != null
7313 ? mAppToken.inputDispatchingTimeoutNanos
7314 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316
7317 public boolean hasAppShownWindows() {
7318 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7319 }
7320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007322 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007323 TAG, "Setting animation in " + this + ": " + anim);
7324 mAnimating = false;
7325 mLocalAnimating = false;
7326 mAnimation = anim;
7327 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7328 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7329 }
7330
7331 public void clearAnimation() {
7332 if (mAnimation != null) {
7333 mAnimating = true;
7334 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007335 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 mAnimation = null;
7337 }
7338 }
Romain Guy06882f82009-06-10 13:36:04 -07007339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 Surface createSurfaceLocked() {
7341 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007342 mReportDestroySurface = false;
7343 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 mDrawPending = true;
7345 mCommitDrawPending = false;
7346 mReadyToShow = false;
7347 if (mAppToken != null) {
7348 mAppToken.allDrawn = false;
7349 }
7350
7351 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352
7353 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7354 flags |= Surface.SECURE;
7355 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007356 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007357 TAG, "Creating surface in session "
7358 + mSession.mSurfaceSession + " window " + this
7359 + " w=" + mFrame.width()
7360 + " h=" + mFrame.height() + " format="
7361 + mAttrs.format + " flags=" + flags);
7362
7363 int w = mFrame.width();
7364 int h = mFrame.height();
7365 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7366 // for a scaled surface, we always want the requested
7367 // size.
7368 w = mRequestedWidth;
7369 h = mRequestedHeight;
7370 }
7371
Romain Guy9825ec62009-10-01 00:58:09 -07007372 // Something is wrong and SurfaceFlinger will not like this,
7373 // try to revert to sane values
7374 if (w <= 0) w = 1;
7375 if (h <= 0) h = 1;
7376
Dianne Hackborn16064f92010-03-25 00:47:24 -07007377 mSurfaceShown = false;
7378 mSurfaceLayer = 0;
7379 mSurfaceAlpha = 1;
7380 mSurfaceX = 0;
7381 mSurfaceY = 0;
7382 mSurfaceW = w;
7383 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007384 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007385 final boolean isHwAccelerated = (mAttrs.flags &
7386 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7387 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7388 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7389 flags |= Surface.OPAQUE;
7390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007391 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007392 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007393 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007394 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007395 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007396 + mSurface + " IN SESSION "
7397 + mSession.mSurfaceSession
7398 + ": pid=" + mSession.mPid + " format="
7399 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007400 + Integer.toHexString(flags)
7401 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007403 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 reclaimSomeSurfaceMemoryLocked(this, "create");
7405 return null;
7406 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007407 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 return null;
7409 }
Romain Guy06882f82009-06-10 13:36:04 -07007410
Joe Onorato8a9b2202010-02-26 18:56:32 -08007411 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 TAG, "Got surface: " + mSurface
7413 + ", set left=" + mFrame.left + " top=" + mFrame.top
7414 + ", animLayer=" + mAnimLayer);
7415 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007416 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7417 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007418 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7419 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007420 }
7421 Surface.openTransaction();
7422 try {
7423 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007424 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007425 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007426 mSurface.setPosition(mSurfaceX, mSurfaceY);
7427 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007429 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 mSurface.hide();
7431 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007432 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 mSurface.setFlags(Surface.SURFACE_DITHER,
7434 Surface.SURFACE_DITHER);
7435 }
7436 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007437 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7439 }
7440 mLastHidden = true;
7441 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007443 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007445 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 TAG, "Created surface " + this);
7447 }
7448 return mSurface;
7449 }
Romain Guy06882f82009-06-10 13:36:04 -07007450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 if (mAppToken != null && this == mAppToken.startingWindow) {
7453 mAppToken.startingDisplayed = false;
7454 }
Romain Guy06882f82009-06-10 13:36:04 -07007455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007457 mDrawPending = false;
7458 mCommitDrawPending = false;
7459 mReadyToShow = false;
7460
7461 int i = mChildWindows.size();
7462 while (i > 0) {
7463 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007464 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007465 c.mAttachedHidden = true;
7466 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007467
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007468 if (mReportDestroySurface) {
7469 mReportDestroySurface = false;
7470 mSurfacePendingDestroy = true;
7471 try {
7472 mClient.dispatchGetNewSurface();
7473 // We'll really destroy on the next time around.
7474 return;
7475 } catch (RemoteException e) {
7476 }
7477 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007479 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007480 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007481 RuntimeException e = null;
7482 if (!HIDE_STACK_CRAWLS) {
7483 e = new RuntimeException();
7484 e.fillInStackTrace();
7485 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007486 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007487 + mSurface + ", session " + mSession, e);
7488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007489 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007490 RuntimeException e = null;
7491 if (!HIDE_STACK_CRAWLS) {
7492 e = new RuntimeException();
7493 e.fillInStackTrace();
7494 }
7495 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007496 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007497 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007499 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 + " surface " + mSurface + " session " + mSession
7501 + ": " + e.toString());
7502 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007503
Dianne Hackborn16064f92010-03-25 00:47:24 -07007504 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007506 }
7507 }
7508
7509 boolean finishDrawingLocked() {
7510 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007511 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 TAG, "finishDrawingLocked: " + mSurface);
7513 mCommitDrawPending = true;
7514 mDrawPending = false;
7515 return true;
7516 }
7517 return false;
7518 }
7519
7520 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007521 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007522 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007523 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007524 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 }
7526 mCommitDrawPending = false;
7527 mReadyToShow = true;
7528 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7529 final AppWindowToken atoken = mAppToken;
7530 if (atoken == null || atoken.allDrawn || starting) {
7531 performShowLocked();
7532 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007533 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007534 }
7535
7536 // This must be called while inside a transaction.
7537 boolean performShowLocked() {
7538 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007539 RuntimeException e = null;
7540 if (!HIDE_STACK_CRAWLS) {
7541 e = new RuntimeException();
7542 e.fillInStackTrace();
7543 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007544 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007545 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7546 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7547 }
7548 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007549 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7550 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007551 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007552 + " during animation: policyVis=" + mPolicyVisibility
7553 + " attHidden=" + mAttachedHidden
7554 + " tok.hiddenRequested="
7555 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007556 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 + (mAppToken != null ? mAppToken.hidden : false)
7558 + " animating=" + mAnimating
7559 + " tok animating="
7560 + (mAppToken != null ? mAppToken.animating : false));
7561 if (!showSurfaceRobustlyLocked(this)) {
7562 return false;
7563 }
7564 mLastAlpha = -1;
7565 mHasDrawn = true;
7566 mLastHidden = false;
7567 mReadyToShow = false;
7568 enableScreenIfNeededLocked();
7569
7570 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 int i = mChildWindows.size();
7573 while (i > 0) {
7574 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007575 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007576 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007577 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007578 if (c.mSurface != null) {
7579 c.performShowLocked();
7580 // It hadn't been shown, which means layout not
7581 // performed on it, so now we want to make sure to
7582 // do a layout. If called from within the transaction
7583 // loop, this will cause it to restart with a new
7584 // layout.
7585 mLayoutNeeded = true;
7586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 }
7588 }
Romain Guy06882f82009-06-10 13:36:04 -07007589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007590 if (mAttrs.type != TYPE_APPLICATION_STARTING
7591 && mAppToken != null) {
7592 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007593
Dianne Hackborn248b1882009-09-16 16:46:44 -07007594 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007595 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007596 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007598 // If this initial window is animating, stop it -- we
7599 // will do an animation to reveal it from behind the
7600 // starting window, so there is no need for it to also
7601 // be doing its own stuff.
7602 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007603 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007604 mAnimation = null;
7605 // Make sure we clean up the animation.
7606 mAnimating = true;
7607 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007608 mFinishedStarting.add(mAppToken);
7609 mH.sendEmptyMessage(H.FINISHED_STARTING);
7610 }
7611 mAppToken.updateReportedVisibilityLocked();
7612 }
7613 }
7614 return true;
7615 }
Romain Guy06882f82009-06-10 13:36:04 -07007616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 // This must be called while inside a transaction. Returns true if
7618 // there is more animation to run.
7619 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007620 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7624 mHasTransformation = true;
7625 mHasLocalTransformation = true;
7626 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007627 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007628 TAG, "Starting animation in " + this +
7629 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7630 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7631 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7632 mAnimation.setStartTime(currentTime);
7633 mLocalAnimating = true;
7634 mAnimating = true;
7635 }
7636 mTransformation.clear();
7637 final boolean more = mAnimation.getTransformation(
7638 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007639 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 TAG, "Stepped animation in " + this +
7641 ": more=" + more + ", xform=" + mTransformation);
7642 if (more) {
7643 // we're not done!
7644 return true;
7645 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007646 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007647 TAG, "Finished animation in " + this +
7648 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007649
7650 if (mAnimation != null) {
7651 mAnimation.cancel();
7652 mAnimation = null;
7653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007654 //WindowManagerService.this.dump();
7655 }
7656 mHasLocalTransformation = false;
7657 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007658 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 // When our app token is animating, we kind-of pretend like
7660 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7661 // part of this check means that we will only do this if
7662 // our window is not currently exiting, or it is not
7663 // locally animating itself. The idea being that one that
7664 // is exiting and doing a local animation should be removed
7665 // once that animation is done.
7666 mAnimating = true;
7667 mHasTransformation = true;
7668 mTransformation.clear();
7669 return false;
7670 } else if (mHasTransformation) {
7671 // Little trick to get through the path below to act like
7672 // we have finished an animation.
7673 mAnimating = true;
7674 } else if (isAnimating()) {
7675 mAnimating = true;
7676 }
7677 } else if (mAnimation != null) {
7678 // If the display is frozen, and there is a pending animation,
7679 // clear it and make sure we run the cleanup code.
7680 mAnimating = true;
7681 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007682 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007683 mAnimation = null;
7684 }
Romain Guy06882f82009-06-10 13:36:04 -07007685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 if (!mAnimating && !mLocalAnimating) {
7687 return false;
7688 }
7689
Joe Onorato8a9b2202010-02-26 18:56:32 -08007690 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007691 TAG, "Animation done in " + this + ": exiting=" + mExiting
7692 + ", reportedVisible="
7693 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007695 mAnimating = false;
7696 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007697 if (mAnimation != null) {
7698 mAnimation.cancel();
7699 mAnimation = null;
7700 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007701 mAnimLayer = mLayer;
7702 if (mIsImWindow) {
7703 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007704 } else if (mIsWallpaper) {
7705 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007707 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708 + " anim layer: " + mAnimLayer);
7709 mHasTransformation = false;
7710 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007711 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7712 if (DEBUG_VISIBILITY) {
7713 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7714 + mPolicyVisibilityAfterAnim);
7715 }
7716 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7717 if (!mPolicyVisibility) {
7718 if (mCurrentFocus == this) {
7719 mFocusMayChange = true;
7720 }
7721 // Window is no longer visible -- make sure if we were waiting
7722 // for it to be displayed before enabling the display, that
7723 // we allow the display to be enabled now.
7724 enableScreenIfNeededLocked();
7725 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007726 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007727 mTransformation.clear();
7728 if (mHasDrawn
7729 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7730 && mAppToken != null
7731 && mAppToken.firstWindowDrawn
7732 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007733 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007734 + mToken + ": first real window done animating");
7735 mFinishedStarting.add(mAppToken);
7736 mH.sendEmptyMessage(H.FINISHED_STARTING);
7737 }
Romain Guy06882f82009-06-10 13:36:04 -07007738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007739 finishExit();
7740
7741 if (mAppToken != null) {
7742 mAppToken.updateReportedVisibilityLocked();
7743 }
7744
7745 return false;
7746 }
7747
7748 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007749 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 TAG, "finishExit in " + this
7751 + ": exiting=" + mExiting
7752 + " remove=" + mRemoveOnExit
7753 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007755 final int N = mChildWindows.size();
7756 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007757 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 }
Romain Guy06882f82009-06-10 13:36:04 -07007759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007760 if (!mExiting) {
7761 return;
7762 }
Romain Guy06882f82009-06-10 13:36:04 -07007763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007764 if (isWindowAnimating()) {
7765 return;
7766 }
7767
Joe Onorato8a9b2202010-02-26 18:56:32 -08007768 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007769 TAG, "Exit animation finished in " + this
7770 + ": remove=" + mRemoveOnExit);
7771 if (mSurface != null) {
7772 mDestroySurface.add(this);
7773 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007774 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007775 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 try {
7777 mSurface.hide();
7778 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007779 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007780 }
7781 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007782 }
7783 mExiting = false;
7784 if (mRemoveOnExit) {
7785 mPendingRemove.add(this);
7786 mRemoveOnExit = false;
7787 }
7788 }
Romain Guy06882f82009-06-10 13:36:04 -07007789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7791 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7792 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7793 if (dtdx < -.000001f || dtdx > .000001f) return false;
7794 if (dsdy < -.000001f || dsdy > .000001f) return false;
7795 return true;
7796 }
Romain Guy06882f82009-06-10 13:36:04 -07007797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007798 void computeShownFrameLocked() {
7799 final boolean selfTransformation = mHasLocalTransformation;
7800 Transformation attachedTransformation =
7801 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7802 ? mAttachedWindow.mTransformation : null;
7803 Transformation appTransformation =
7804 (mAppToken != null && mAppToken.hasTransformation)
7805 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007806
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007807 // Wallpapers are animated based on the "real" window they
7808 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007809 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007810 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007811 if (mWallpaperTarget.mHasLocalTransformation &&
7812 mWallpaperTarget.mAnimation != null &&
7813 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007814 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007815 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007816 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007817 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007818 }
7819 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007820 mWallpaperTarget.mAppToken.hasTransformation &&
7821 mWallpaperTarget.mAppToken.animation != null &&
7822 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007823 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007824 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007825 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007826 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007827 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007829
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007830 final boolean screenAnimation = mScreenRotationAnimation != null
7831 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007832 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007833 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007834 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007835 final Rect frame = mFrame;
7836 final float tmpFloats[] = mTmpFloats;
7837 final Matrix tmpMatrix = mTmpMatrix;
7838
7839 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007840 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007841 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007842 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007843 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007844 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007846 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007847 }
7848 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007849 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007850 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007851 if (screenAnimation) {
7852 tmpMatrix.postConcat(
7853 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855
7856 // "convert" it into SurfaceFlinger's format
7857 // (a 2x2 matrix + an offset)
7858 // Here we must not transform the position of the surface
7859 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007860 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007861
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007862 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007863 tmpMatrix.getValues(tmpFloats);
7864 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007865 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7866 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007867 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007868 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7869 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 int w = frame.width();
7871 int h = frame.height();
7872 mShownFrame.set(x, y, x+w, y+h);
7873
7874 // Now set the alpha... but because our current hardware
7875 // can't do alpha transformation on a non-opaque surface,
7876 // turn it off if we are running an animation that is also
7877 // transforming since it is more important to have that
7878 // animation be smooth.
7879 mShownAlpha = mAlpha;
7880 if (!mLimitedAlphaCompositing
7881 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7882 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7883 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007884 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 if (selfTransformation) {
7886 mShownAlpha *= mTransformation.getAlpha();
7887 }
7888 if (attachedTransformation != null) {
7889 mShownAlpha *= attachedTransformation.getAlpha();
7890 }
7891 if (appTransformation != null) {
7892 mShownAlpha *= appTransformation.getAlpha();
7893 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007894 if (screenAnimation) {
7895 mShownAlpha *=
7896 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007899 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007900 }
Romain Guy06882f82009-06-10 13:36:04 -07007901
Joe Onorato8a9b2202010-02-26 18:56:32 -08007902 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007903 TAG, "Continuing animation in " + this +
7904 ": " + mShownFrame +
7905 ", alpha=" + mTransformation.getAlpha());
7906 return;
7907 }
Romain Guy06882f82009-06-10 13:36:04 -07007908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007909 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007910 if (mXOffset != 0 || mYOffset != 0) {
7911 mShownFrame.offset(mXOffset, mYOffset);
7912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007914 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007915 mDsDx = 1;
7916 mDtDx = 0;
7917 mDsDy = 0;
7918 mDtDy = 1;
7919 }
Romain Guy06882f82009-06-10 13:36:04 -07007920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007921 /**
7922 * Is this window visible? It is not visible if there is no
7923 * surface, or we are in the process of running an exit animation
7924 * that will remove the surface, or its app token has been hidden.
7925 */
7926 public boolean isVisibleLw() {
7927 final AppWindowToken atoken = mAppToken;
7928 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7929 && (atoken == null || !atoken.hiddenRequested)
7930 && !mExiting && !mDestroying;
7931 }
7932
7933 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007934 * Like {@link #isVisibleLw}, but also counts a window that is currently
7935 * "hidden" behind the keyguard as visible. This allows us to apply
7936 * things like window flags that impact the keyguard.
7937 * XXX I am starting to think we need to have ANOTHER visibility flag
7938 * for this "hidden behind keyguard" state rather than overloading
7939 * mPolicyVisibility. Ungh.
7940 */
7941 public boolean isVisibleOrBehindKeyguardLw() {
7942 final AppWindowToken atoken = mAppToken;
7943 return mSurface != null && !mAttachedHidden
7944 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007945 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007946 && !mExiting && !mDestroying;
7947 }
7948
7949 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007950 * Is this window visible, ignoring its app token? It is not visible
7951 * if there is no surface, or we are in the process of running an exit animation
7952 * that will remove the surface.
7953 */
7954 public boolean isWinVisibleLw() {
7955 final AppWindowToken atoken = mAppToken;
7956 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7957 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7958 && !mExiting && !mDestroying;
7959 }
7960
7961 /**
7962 * The same as isVisible(), but follows the current hidden state of
7963 * the associated app token, not the pending requested hidden state.
7964 */
7965 boolean isVisibleNow() {
7966 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007967 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007968 }
7969
7970 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007971 * Can this window possibly be a drag/drop target? The test here is
7972 * a combination of the above "visible now" with the check that the
7973 * Input Manager uses when discarding windows from input consideration.
7974 */
7975 boolean isPotentialDragTarget() {
7976 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7977 }
7978
7979 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 * Same as isVisible(), but we also count it as visible between the
7981 * call to IWindowSession.add() and the first relayout().
7982 */
7983 boolean isVisibleOrAdding() {
7984 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007985 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007986 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7987 && mPolicyVisibility && !mAttachedHidden
7988 && (atoken == null || !atoken.hiddenRequested)
7989 && !mExiting && !mDestroying;
7990 }
7991
7992 /**
7993 * Is this window currently on-screen? It is on-screen either if it
7994 * is visible or it is currently running an animation before no longer
7995 * being visible.
7996 */
7997 boolean isOnScreen() {
7998 final AppWindowToken atoken = mAppToken;
7999 if (atoken != null) {
8000 return mSurface != null && mPolicyVisibility && !mDestroying
8001 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008002 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008003 } else {
8004 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008005 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008006 }
8007 }
Romain Guy06882f82009-06-10 13:36:04 -07008008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008009 /**
8010 * Like isOnScreen(), but we don't return true if the window is part
8011 * of a transition that has not yet been started.
8012 */
8013 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008014 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008015 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008016 return false;
8017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008018 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008019 final boolean animating = atoken != null
8020 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008022 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8023 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008024 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 }
8026
8027 /** Is the window or its container currently animating? */
8028 boolean isAnimating() {
8029 final WindowState attached = mAttachedWindow;
8030 final AppWindowToken atoken = mAppToken;
8031 return mAnimation != null
8032 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008033 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 (atoken.animation != null
8035 || atoken.inPendingTransaction));
8036 }
8037
8038 /** Is this window currently animating? */
8039 boolean isWindowAnimating() {
8040 return mAnimation != null;
8041 }
8042
8043 /**
8044 * Like isOnScreen, but returns false if the surface hasn't yet
8045 * been drawn.
8046 */
8047 public boolean isDisplayedLw() {
8048 final AppWindowToken atoken = mAppToken;
8049 return mSurface != null && mPolicyVisibility && !mDestroying
8050 && !mDrawPending && !mCommitDrawPending
8051 && ((!mAttachedHidden &&
8052 (atoken == null || !atoken.hiddenRequested))
8053 || mAnimating);
8054 }
8055
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008056 /**
8057 * Returns true if the window has a surface that it has drawn a
8058 * complete UI in to.
8059 */
8060 public boolean isDrawnLw() {
8061 final AppWindowToken atoken = mAppToken;
8062 return mSurface != null && !mDestroying
8063 && !mDrawPending && !mCommitDrawPending;
8064 }
8065
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008066 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008067 * Return true if the window is opaque and fully drawn. This indicates
8068 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008069 */
8070 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008071 return (mAttrs.format == PixelFormat.OPAQUE
8072 || mAttrs.type == TYPE_WALLPAPER)
8073 && mSurface != null && mAnimation == null
8074 && (mAppToken == null || mAppToken.animation == null)
8075 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008076 }
8077
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008078 /**
8079 * Return whether this window is wanting to have a translation
8080 * animation applied to it for an in-progress move. (Only makes
8081 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
8082 */
8083 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008084 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008085 && (mFrame.top != mLastFrame.top
8086 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008087 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008088 && mPolicy.isScreenOn();
8089 }
8090
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008091 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8092 return
8093 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008094 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8095 // only if it's visible
8096 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008097 // and only if the application fills the compatible screen
8098 mFrame.left <= mCompatibleScreenFrame.left &&
8099 mFrame.top <= mCompatibleScreenFrame.top &&
8100 mFrame.right >= mCompatibleScreenFrame.right &&
8101 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008102 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008103 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008104 }
8105
8106 boolean isFullscreen(int screenWidth, int screenHeight) {
8107 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008108 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008109 }
8110
8111 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008112 disposeInputChannel();
8113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008114 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008115 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008116 mAttachedWindow.mChildWindows.remove(this);
8117 }
8118 destroySurfaceLocked();
8119 mSession.windowRemovedLocked();
8120 try {
8121 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8122 } catch (RuntimeException e) {
8123 // Ignore if it has already been removed (usually because
8124 // we are doing this as part of processing a death note.)
8125 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008126 }
8127
8128 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008129 if (mInputChannel != null) {
8130 mInputManager.unregisterInputChannel(mInputChannel);
8131
8132 mInputChannel.dispose();
8133 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008135 }
8136
8137 private class DeathRecipient implements IBinder.DeathRecipient {
8138 public void binderDied() {
8139 try {
8140 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008141 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008142 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008143 if (win != null) {
8144 removeWindowLocked(mSession, win);
8145 }
8146 }
8147 } catch (IllegalArgumentException ex) {
8148 // This will happen if the window has already been
8149 // removed.
8150 }
8151 }
8152 }
8153
8154 /** Returns true if this window desires key events. */
8155 public final boolean canReceiveKeys() {
8156 return isVisibleOrAdding()
8157 && (mViewVisibility == View.VISIBLE)
8158 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8159 }
8160
8161 public boolean hasDrawnLw() {
8162 return mHasDrawn;
8163 }
8164
8165 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008166 return showLw(doAnimation, true);
8167 }
8168
8169 boolean showLw(boolean doAnimation, boolean requestAnim) {
8170 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8171 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008172 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008173 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008174 if (doAnimation) {
8175 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8176 + mPolicyVisibility + " mAnimation=" + mAnimation);
8177 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8178 doAnimation = false;
8179 } else if (mPolicyVisibility && mAnimation == null) {
8180 // Check for the case where we are currently visible and
8181 // not animating; we do not want to do animation at such a
8182 // point to become visible when we already are.
8183 doAnimation = false;
8184 }
8185 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008186 mPolicyVisibility = true;
8187 mPolicyVisibilityAfterAnim = true;
8188 if (doAnimation) {
8189 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8190 }
8191 if (requestAnim) {
8192 requestAnimationLocked(0);
8193 }
8194 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008195 }
8196
8197 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008198 return hideLw(doAnimation, true);
8199 }
8200
8201 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008202 if (doAnimation) {
8203 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8204 doAnimation = false;
8205 }
8206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008207 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8208 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008209 if (!current) {
8210 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008211 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008212 if (doAnimation) {
8213 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8214 if (mAnimation == null) {
8215 doAnimation = false;
8216 }
8217 }
8218 if (doAnimation) {
8219 mPolicyVisibilityAfterAnim = false;
8220 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008221 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008222 mPolicyVisibilityAfterAnim = false;
8223 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008224 // Window is no longer visible -- make sure if we were waiting
8225 // for it to be displayed before enabling the display, that
8226 // we allow the display to be enabled now.
8227 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008228 if (mCurrentFocus == this) {
8229 mFocusMayChange = true;
8230 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008231 }
8232 if (requestAnim) {
8233 requestAnimationLocked(0);
8234 }
8235 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008236 }
8237
Jeff Brownfbf09772011-01-16 14:06:57 -08008238 public void getTouchableRegion(Region outRegion) {
8239 final Rect frame = mFrame;
8240 switch (mTouchableInsets) {
8241 default:
8242 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8243 outRegion.set(frame);
8244 break;
8245 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8246 final Rect inset = mGivenContentInsets;
8247 outRegion.set(
8248 frame.left + inset.left, frame.top + inset.top,
8249 frame.right - inset.right, frame.bottom - inset.bottom);
8250 break;
8251 }
8252 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8253 final Rect inset = mGivenVisibleInsets;
8254 outRegion.set(
8255 frame.left + inset.left, frame.top + inset.top,
8256 frame.right - inset.right, frame.bottom - inset.bottom);
8257 break;
8258 }
8259 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8260 final Region givenTouchableRegion = mGivenTouchableRegion;
8261 outRegion.set(givenTouchableRegion);
8262 outRegion.translate(frame.left, frame.top);
8263 break;
8264 }
8265 }
8266 }
8267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008269 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8270 pw.print(" mClient="); pw.println(mClient.asBinder());
8271 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8272 if (mAttachedWindow != null || mLayoutAttached) {
8273 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8274 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8275 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008276 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8277 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8278 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008279 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8280 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008281 }
8282 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8283 pw.print(" mSubLayer="); pw.print(mSubLayer);
8284 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8285 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8286 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8287 pw.print("="); pw.print(mAnimLayer);
8288 pw.print(" mLastLayer="); pw.println(mLastLayer);
8289 if (mSurface != null) {
8290 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008291 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8292 pw.print(" layer="); pw.print(mSurfaceLayer);
8293 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8294 pw.print(" rect=("); pw.print(mSurfaceX);
8295 pw.print(","); pw.print(mSurfaceY);
8296 pw.print(") "); pw.print(mSurfaceW);
8297 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008298 }
8299 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8300 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8301 if (mAppToken != null) {
8302 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8303 }
8304 if (mTargetAppToken != null) {
8305 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8306 }
8307 pw.print(prefix); pw.print("mViewVisibility=0x");
8308 pw.print(Integer.toHexString(mViewVisibility));
8309 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008310 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8311 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008312 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8313 pw.print(prefix); pw.print("mPolicyVisibility=");
8314 pw.print(mPolicyVisibility);
8315 pw.print(" mPolicyVisibilityAfterAnim=");
8316 pw.print(mPolicyVisibilityAfterAnim);
8317 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8318 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008319 if (!mRelayoutCalled) {
8320 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8321 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008322 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008323 pw.print(" h="); pw.print(mRequestedHeight);
8324 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008325 if (mXOffset != 0 || mYOffset != 0) {
8326 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8327 pw.print(" y="); pw.println(mYOffset);
8328 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008329 pw.print(prefix); pw.print("mGivenContentInsets=");
8330 mGivenContentInsets.printShortString(pw);
8331 pw.print(" mGivenVisibleInsets=");
8332 mGivenVisibleInsets.printShortString(pw);
8333 pw.println();
8334 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8335 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8336 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8337 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008338 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008339 pw.print(prefix); pw.print("mShownFrame=");
8340 mShownFrame.printShortString(pw);
8341 pw.print(" last="); mLastShownFrame.printShortString(pw);
8342 pw.println();
8343 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8344 pw.print(" last="); mLastFrame.printShortString(pw);
8345 pw.println();
8346 pw.print(prefix); pw.print("mContainingFrame=");
8347 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008348 pw.print(" mParentFrame=");
8349 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008350 pw.print(" mDisplayFrame=");
8351 mDisplayFrame.printShortString(pw);
8352 pw.println();
8353 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8354 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8355 pw.println();
8356 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8357 pw.print(" last="); mLastContentInsets.printShortString(pw);
8358 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8359 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8360 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008361 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8362 || mAnimation != null) {
8363 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8364 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8365 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8366 pw.print(" mAnimation="); pw.println(mAnimation);
8367 }
8368 if (mHasTransformation || mHasLocalTransformation) {
8369 pw.print(prefix); pw.print("XForm: has=");
8370 pw.print(mHasTransformation);
8371 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8372 pw.print(" "); mTransformation.printShortString(pw);
8373 pw.println();
8374 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008375 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8376 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8377 pw.print(" mAlpha="); pw.print(mAlpha);
8378 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8379 }
8380 if (mHaveMatrix) {
8381 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8382 pw.print(" mDtDx="); pw.print(mDtDx);
8383 pw.print(" mDsDy="); pw.print(mDsDy);
8384 pw.print(" mDtDy="); pw.println(mDtDy);
8385 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008386 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8387 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8388 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8389 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8390 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8391 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8392 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8393 pw.print(" mDestroying="); pw.print(mDestroying);
8394 pw.print(" mRemoved="); pw.println(mRemoved);
8395 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008396 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008397 pw.print(prefix); pw.print("mOrientationChanging=");
8398 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008399 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8400 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008401 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008402 if (mHScale != 1 || mVScale != 1) {
8403 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8404 pw.print(" mVScale="); pw.println(mVScale);
8405 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008406 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008407 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8408 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8409 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008410 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8411 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8412 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008415
8416 String makeInputChannelName() {
8417 return Integer.toHexString(System.identityHashCode(this))
8418 + " " + mAttrs.getTitle();
8419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008420
8421 @Override
8422 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008423 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8424 || mWasPaused != mToken.paused) {
8425 mLastTitle = mAttrs.getTitle();
8426 mWasPaused = mToken.paused;
8427 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8428 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8429 }
8430 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008431 }
8432 }
Romain Guy06882f82009-06-10 13:36:04 -07008433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008434 // -------------------------------------------------------------
8435 // Window Token State
8436 // -------------------------------------------------------------
8437
8438 class WindowToken {
8439 // The actual token.
8440 final IBinder token;
8441
8442 // The type of window this token is for, as per WindowManager.LayoutParams.
8443 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008445 // Set if this token was explicitly added by a client, so should
8446 // not be removed when all windows are removed.
8447 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008448
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008449 // For printing.
8450 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 // If this is an AppWindowToken, this is non-null.
8453 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008455 // All of the windows associated with this token.
8456 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8457
8458 // Is key dispatching paused for this token?
8459 boolean paused = false;
8460
8461 // Should this token's windows be hidden?
8462 boolean hidden;
8463
8464 // Temporary for finding which tokens no longer have visible windows.
8465 boolean hasVisible;
8466
Dianne Hackborna8f60182009-09-01 19:01:50 -07008467 // Set to true when this token is in a pending transaction where it
8468 // will be shown.
8469 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008470
Dianne Hackborna8f60182009-09-01 19:01:50 -07008471 // Set to true when this token is in a pending transaction where it
8472 // will be hidden.
8473 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008474
Dianne Hackborna8f60182009-09-01 19:01:50 -07008475 // Set to true when this token is in a pending transaction where its
8476 // windows will be put to the bottom of the list.
8477 boolean sendingToBottom;
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 its
8480 // windows will be put to the top of the list.
8481 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008483 WindowToken(IBinder _token, int type, boolean _explicit) {
8484 token = _token;
8485 windowType = type;
8486 explicit = _explicit;
8487 }
8488
8489 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008490 pw.print(prefix); pw.print("token="); pw.println(token);
8491 pw.print(prefix); pw.print("windows="); pw.println(windows);
8492 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8493 pw.print(" hidden="); pw.print(hidden);
8494 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008495 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8496 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8497 pw.print(" waitingToHide="); pw.print(waitingToHide);
8498 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8499 pw.print(" sendingToTop="); pw.println(sendingToTop);
8500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 }
8502
8503 @Override
8504 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008505 if (stringName == null) {
8506 StringBuilder sb = new StringBuilder();
8507 sb.append("WindowToken{");
8508 sb.append(Integer.toHexString(System.identityHashCode(this)));
8509 sb.append(" token="); sb.append(token); sb.append('}');
8510 stringName = sb.toString();
8511 }
8512 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 }
8514 };
8515
8516 class AppWindowToken extends WindowToken {
8517 // Non-null only for application tokens.
8518 final IApplicationToken appToken;
8519
8520 // All of the windows and child windows that are included in this
8521 // application token. Note this list is NOT sorted!
8522 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8523
8524 int groupId = -1;
8525 boolean appFullscreen;
8526 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008527
8528 // The input dispatching timeout for this application token in nanoseconds.
8529 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 // These are used for determining when all windows associated with
8532 // an activity have been drawn, so they can be made visible together
8533 // at the same time.
8534 int lastTransactionSequence = mTransactionSequence-1;
8535 int numInterestingWindows;
8536 int numDrawnWindows;
8537 boolean inPendingTransaction;
8538 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 // Is this token going to be hidden in a little while? If so, it
8541 // won't be taken into account for setting the screen orientation.
8542 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 // Is this window's surface needed? This is almost like hidden, except
8545 // it will sometimes be true a little earlier: when the token has
8546 // been shown, but is still waiting for its app transition to execute
8547 // before making its windows shown.
8548 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008550 // Have we told the window clients to hide themselves?
8551 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008553 // Last visibility state we reported to the app token.
8554 boolean reportedVisible;
8555
8556 // Set to true when the token has been removed from the window mgr.
8557 boolean removed;
8558
8559 // Have we been asked to have this token keep the screen frozen?
8560 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008562 boolean animating;
8563 Animation animation;
8564 boolean hasTransformation;
8565 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008567 // Offset to the window of all layers in the token, for use by
8568 // AppWindowToken animations.
8569 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008571 // Information about an application starting window if displayed.
8572 StartingData startingData;
8573 WindowState startingWindow;
8574 View startingView;
8575 boolean startingDisplayed;
8576 boolean startingMoved;
8577 boolean firstWindowDrawn;
8578
Jeff Brown928e0542011-01-10 11:17:36 -08008579 // Input application handle used by the input dispatcher.
8580 InputApplicationHandle mInputApplicationHandle;
8581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 AppWindowToken(IApplicationToken _token) {
8583 super(_token.asBinder(),
8584 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8585 appWindowToken = this;
8586 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008587 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008588 }
Romain Guy06882f82009-06-10 13:36:04 -07008589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008591 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008592 TAG, "Setting animation in " + this + ": " + anim);
8593 animation = anim;
8594 animating = false;
8595 anim.restrictDuration(MAX_ANIMATION_DURATION);
8596 anim.scaleCurrentDuration(mTransitionAnimationScale);
8597 int zorder = anim.getZAdjustment();
8598 int adj = 0;
8599 if (zorder == Animation.ZORDER_TOP) {
8600 adj = TYPE_LAYER_OFFSET;
8601 } else if (zorder == Animation.ZORDER_BOTTOM) {
8602 adj = -TYPE_LAYER_OFFSET;
8603 }
Romain Guy06882f82009-06-10 13:36:04 -07008604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008605 if (animLayerAdjustment != adj) {
8606 animLayerAdjustment = adj;
8607 updateLayers();
8608 }
8609 }
Romain Guy06882f82009-06-10 13:36:04 -07008610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 public void setDummyAnimation() {
8612 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008613 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008614 TAG, "Setting dummy animation in " + this);
8615 animation = sDummyAnimation;
8616 }
8617 }
8618
8619 public void clearAnimation() {
8620 if (animation != null) {
8621 animation = null;
8622 animating = true;
8623 }
8624 }
Romain Guy06882f82009-06-10 13:36:04 -07008625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 void updateLayers() {
8627 final int N = allAppWindows.size();
8628 final int adj = animLayerAdjustment;
8629 for (int i=0; i<N; i++) {
8630 WindowState w = allAppWindows.get(i);
8631 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008632 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008633 + w.mAnimLayer);
Dianne Hackborne75d8722011-01-27 19:37:40 -08008634 if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008635 setInputMethodAnimLayerAdjustment(adj);
8636 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008637 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008638 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 }
8641 }
Romain Guy06882f82009-06-10 13:36:04 -07008642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008643 void sendAppVisibilityToClients() {
8644 final int N = allAppWindows.size();
8645 for (int i=0; i<N; i++) {
8646 WindowState win = allAppWindows.get(i);
8647 if (win == startingWindow && clientHidden) {
8648 // Don't hide the starting window.
8649 continue;
8650 }
8651 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008652 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 "Setting visibility of " + win + ": " + (!clientHidden));
8654 win.mClient.dispatchAppVisibility(!clientHidden);
8655 } catch (RemoteException e) {
8656 }
8657 }
8658 }
Romain Guy06882f82009-06-10 13:36:04 -07008659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008660 void showAllWindowsLocked() {
8661 final int NW = allAppWindows.size();
8662 for (int i=0; i<NW; i++) {
8663 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008664 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008665 "performing show on: " + w);
8666 w.performShowLocked();
8667 }
8668 }
Romain Guy06882f82009-06-10 13:36:04 -07008669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008670 // This must be called while inside a transaction.
8671 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008672 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008675 if (animation == sDummyAnimation) {
8676 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008677 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008678 // when it is really time to animate, this will be set to
8679 // a real animation and the next call will execute normally.
8680 return false;
8681 }
Romain Guy06882f82009-06-10 13:36:04 -07008682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8684 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008685 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 TAG, "Starting animation in " + this +
8687 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8688 + " scale=" + mTransitionAnimationScale
8689 + " allDrawn=" + allDrawn + " animating=" + animating);
8690 animation.initialize(dw, dh, dw, dh);
8691 animation.setStartTime(currentTime);
8692 animating = true;
8693 }
8694 transformation.clear();
8695 final boolean more = animation.getTransformation(
8696 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008697 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698 TAG, "Stepped animation in " + this +
8699 ": more=" + more + ", xform=" + transformation);
8700 if (more) {
8701 // we're done!
8702 hasTransformation = true;
8703 return true;
8704 }
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, "Finished animation in " + this +
8707 " @ " + currentTime);
8708 animation = null;
8709 }
8710 } else if (animation != null) {
8711 // If the display is frozen, and there is a pending animation,
8712 // clear it and make sure we run the cleanup code.
8713 animating = true;
8714 animation = null;
8715 }
8716
8717 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 if (!animating) {
8720 return false;
8721 }
8722
8723 clearAnimation();
8724 animating = false;
Dianne Hackborne75d8722011-01-27 19:37:40 -08008725 if (animLayerAdjustment != 0) {
8726 animLayerAdjustment = 0;
8727 updateLayers();
8728 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008729 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8730 moveInputMethodWindowsIfNeededLocked(true);
8731 }
Romain Guy06882f82009-06-10 13:36:04 -07008732
Joe Onorato8a9b2202010-02-26 18:56:32 -08008733 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734 TAG, "Animation done in " + this
8735 + ": reportedVisible=" + reportedVisible);
8736
8737 transformation.clear();
Romain Guy06882f82009-06-10 13:36:04 -07008738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008739 final int N = windows.size();
8740 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008741 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008742 }
8743 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008745 return false;
8746 }
8747
8748 void updateReportedVisibilityLocked() {
8749 if (appToken == null) {
8750 return;
8751 }
Romain Guy06882f82009-06-10 13:36:04 -07008752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008753 int numInteresting = 0;
8754 int numVisible = 0;
8755 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008756
Joe Onorato8a9b2202010-02-26 18:56:32 -08008757 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008758 final int N = allAppWindows.size();
8759 for (int i=0; i<N; i++) {
8760 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008761 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008762 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008763 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8764 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008765 continue;
8766 }
8767 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008768 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008769 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008770 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008771 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008772 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008773 + " pv=" + win.mPolicyVisibility
8774 + " dp=" + win.mDrawPending
8775 + " cdp=" + win.mCommitDrawPending
8776 + " ah=" + win.mAttachedHidden
8777 + " th="
8778 + (win.mAppToken != null
8779 ? win.mAppToken.hiddenRequested : false)
8780 + " a=" + win.mAnimating);
8781 }
8782 }
8783 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008784 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008785 if (!win.isAnimating()) {
8786 numVisible++;
8787 }
8788 nowGone = false;
8789 } else if (win.isAnimating()) {
8790 nowGone = false;
8791 }
8792 }
Romain Guy06882f82009-06-10 13:36:04 -07008793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008794 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008795 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008796 + numInteresting + " visible=" + numVisible);
8797 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008798 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008799 TAG, "Visibility changed in " + this
8800 + ": vis=" + nowVisible);
8801 reportedVisible = nowVisible;
8802 Message m = mH.obtainMessage(
8803 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8804 nowVisible ? 1 : 0,
8805 nowGone ? 1 : 0,
8806 this);
8807 mH.sendMessage(m);
8808 }
8809 }
Romain Guy06882f82009-06-10 13:36:04 -07008810
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008811 WindowState findMainWindow() {
8812 int j = windows.size();
8813 while (j > 0) {
8814 j--;
8815 WindowState win = windows.get(j);
8816 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8817 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8818 return win;
8819 }
8820 }
8821 return null;
8822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008824 void dump(PrintWriter pw, String prefix) {
8825 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008826 if (appToken != null) {
8827 pw.print(prefix); pw.println("app=true");
8828 }
8829 if (allAppWindows.size() > 0) {
8830 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8831 }
8832 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008833 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008834 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8835 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8836 pw.print(" clientHidden="); pw.print(clientHidden);
8837 pw.print(" willBeHidden="); pw.print(willBeHidden);
8838 pw.print(" reportedVisible="); pw.println(reportedVisible);
8839 if (paused || freezingScreen) {
8840 pw.print(prefix); pw.print("paused="); pw.print(paused);
8841 pw.print(" freezingScreen="); pw.println(freezingScreen);
8842 }
8843 if (numInterestingWindows != 0 || numDrawnWindows != 0
8844 || inPendingTransaction || allDrawn) {
8845 pw.print(prefix); pw.print("numInterestingWindows=");
8846 pw.print(numInterestingWindows);
8847 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8848 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8849 pw.print(" allDrawn="); pw.println(allDrawn);
8850 }
8851 if (animating || animation != null) {
8852 pw.print(prefix); pw.print("animating="); pw.print(animating);
8853 pw.print(" animation="); pw.println(animation);
8854 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008855 if (hasTransformation) {
8856 pw.print(prefix); pw.print("XForm: ");
8857 transformation.printShortString(pw);
8858 pw.println();
8859 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008860 if (animLayerAdjustment != 0) {
8861 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8862 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008863 if (startingData != null || removed || firstWindowDrawn) {
8864 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8865 pw.print(" removed="); pw.print(removed);
8866 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8867 }
8868 if (startingWindow != null || startingView != null
8869 || startingDisplayed || startingMoved) {
8870 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8871 pw.print(" startingView="); pw.print(startingView);
8872 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8873 pw.print(" startingMoved"); pw.println(startingMoved);
8874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 }
8876
8877 @Override
8878 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008879 if (stringName == null) {
8880 StringBuilder sb = new StringBuilder();
8881 sb.append("AppWindowToken{");
8882 sb.append(Integer.toHexString(System.identityHashCode(this)));
8883 sb.append(" token="); sb.append(token); sb.append('}');
8884 stringName = sb.toString();
8885 }
8886 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008887 }
8888 }
Romain Guy06882f82009-06-10 13:36:04 -07008889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 // -------------------------------------------------------------
8891 // DummyAnimation
8892 // -------------------------------------------------------------
8893
8894 // This is an animation that does nothing: it just immediately finishes
8895 // itself every time it is called. It is used as a stub animation in cases
8896 // where we want to synchronize multiple things that may be animating.
8897 static final class DummyAnimation extends Animation {
8898 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8899 return false;
8900 }
8901 }
8902 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008904 // -------------------------------------------------------------
8905 // Async Handler
8906 // -------------------------------------------------------------
8907
8908 static final class StartingData {
8909 final String pkg;
8910 final int theme;
8911 final CharSequence nonLocalizedLabel;
8912 final int labelRes;
8913 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008914 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008916 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008917 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008918 pkg = _pkg;
8919 theme = _theme;
8920 nonLocalizedLabel = _nonLocalizedLabel;
8921 labelRes = _labelRes;
8922 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008923 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008924 }
8925 }
8926
8927 private final class H extends Handler {
8928 public static final int REPORT_FOCUS_CHANGE = 2;
8929 public static final int REPORT_LOSING_FOCUS = 3;
8930 public static final int ANIMATE = 4;
8931 public static final int ADD_STARTING = 5;
8932 public static final int REMOVE_STARTING = 6;
8933 public static final int FINISHED_STARTING = 7;
8934 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008935 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8936 public static final int HOLD_SCREEN_CHANGED = 12;
8937 public static final int APP_TRANSITION_TIMEOUT = 13;
8938 public static final int PERSIST_ANIMATION_SCALE = 14;
8939 public static final int FORCE_GC = 15;
8940 public static final int ENABLE_SCREEN = 16;
8941 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008942 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008943 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008944 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008945 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08008946 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07008947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008948 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008950 public H() {
8951 }
Romain Guy06882f82009-06-10 13:36:04 -07008952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008953 @Override
8954 public void handleMessage(Message msg) {
8955 switch (msg.what) {
8956 case REPORT_FOCUS_CHANGE: {
8957 WindowState lastFocus;
8958 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008960 synchronized(mWindowMap) {
8961 lastFocus = mLastFocus;
8962 newFocus = mCurrentFocus;
8963 if (lastFocus == newFocus) {
8964 // Focus is not changing, so nothing to do.
8965 return;
8966 }
8967 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008968 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008969 // + " to " + newFocus);
8970 if (newFocus != null && lastFocus != null
8971 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008972 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 mLosingFocus.add(lastFocus);
8974 lastFocus = null;
8975 }
8976 }
8977
8978 if (lastFocus != newFocus) {
8979 //System.out.println("Changing focus from " + lastFocus
8980 // + " to " + newFocus);
8981 if (newFocus != null) {
8982 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008983 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008984 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8985 } catch (RemoteException e) {
8986 // Ignore if process has died.
8987 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008988 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008989 }
8990
8991 if (lastFocus != null) {
8992 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008993 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008994 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8995 } catch (RemoteException e) {
8996 // Ignore if process has died.
8997 }
8998 }
Joe Onorato664644d2011-01-23 17:53:23 -08008999
9000 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 }
9002 } break;
9003
9004 case REPORT_LOSING_FOCUS: {
9005 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07009006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009007 synchronized(mWindowMap) {
9008 losers = mLosingFocus;
9009 mLosingFocus = new ArrayList<WindowState>();
9010 }
9011
9012 final int N = losers.size();
9013 for (int i=0; i<N; i++) {
9014 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009015 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009016 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
9017 } catch (RemoteException e) {
9018 // Ignore if process has died.
9019 }
9020 }
9021 } break;
9022
9023 case ANIMATE: {
9024 synchronized(mWindowMap) {
9025 mAnimationPending = false;
9026 performLayoutAndPlaceSurfacesLocked();
9027 }
9028 } break;
9029
9030 case ADD_STARTING: {
9031 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9032 final StartingData sd = wtoken.startingData;
9033
9034 if (sd == null) {
9035 // Animation has been canceled... do nothing.
9036 return;
9037 }
Romain Guy06882f82009-06-10 13:36:04 -07009038
Joe Onorato8a9b2202010-02-26 18:56:32 -08009039 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009040 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07009041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009042 View view = null;
9043 try {
9044 view = mPolicy.addStartingWindow(
9045 wtoken.token, sd.pkg,
9046 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08009047 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009048 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009049 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009050 }
9051
9052 if (view != null) {
9053 boolean abort = false;
9054
9055 synchronized(mWindowMap) {
9056 if (wtoken.removed || wtoken.startingData == null) {
9057 // If the window was successfully added, then
9058 // we need to remove it.
9059 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009060 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009061 "Aborted starting " + wtoken
9062 + ": removed=" + wtoken.removed
9063 + " startingData=" + wtoken.startingData);
9064 wtoken.startingWindow = null;
9065 wtoken.startingData = null;
9066 abort = true;
9067 }
9068 } else {
9069 wtoken.startingView = view;
9070 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009071 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009072 "Added starting " + wtoken
9073 + ": startingWindow="
9074 + wtoken.startingWindow + " startingView="
9075 + wtoken.startingView);
9076 }
9077
9078 if (abort) {
9079 try {
9080 mPolicy.removeStartingWindow(wtoken.token, view);
9081 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009082 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009083 }
9084 }
9085 }
9086 } break;
9087
9088 case REMOVE_STARTING: {
9089 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9090 IBinder token = null;
9091 View view = null;
9092 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009093 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009094 + wtoken + ": startingWindow="
9095 + wtoken.startingWindow + " startingView="
9096 + wtoken.startingView);
9097 if (wtoken.startingWindow != null) {
9098 view = wtoken.startingView;
9099 token = wtoken.token;
9100 wtoken.startingData = null;
9101 wtoken.startingView = null;
9102 wtoken.startingWindow = null;
9103 }
9104 }
9105 if (view != null) {
9106 try {
9107 mPolicy.removeStartingWindow(token, view);
9108 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009109 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009110 }
9111 }
9112 } break;
9113
9114 case FINISHED_STARTING: {
9115 IBinder token = null;
9116 View view = null;
9117 while (true) {
9118 synchronized (mWindowMap) {
9119 final int N = mFinishedStarting.size();
9120 if (N <= 0) {
9121 break;
9122 }
9123 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9124
Joe Onorato8a9b2202010-02-26 18:56:32 -08009125 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009126 "Finished starting " + wtoken
9127 + ": startingWindow=" + wtoken.startingWindow
9128 + " startingView=" + wtoken.startingView);
9129
9130 if (wtoken.startingWindow == null) {
9131 continue;
9132 }
9133
9134 view = wtoken.startingView;
9135 token = wtoken.token;
9136 wtoken.startingData = null;
9137 wtoken.startingView = null;
9138 wtoken.startingWindow = null;
9139 }
9140
9141 try {
9142 mPolicy.removeStartingWindow(token, view);
9143 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009144 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 }
9146 }
9147 } break;
9148
9149 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9150 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9151
9152 boolean nowVisible = msg.arg1 != 0;
9153 boolean nowGone = msg.arg2 != 0;
9154
9155 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009156 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009157 TAG, "Reporting visible in " + wtoken
9158 + " visible=" + nowVisible
9159 + " gone=" + nowGone);
9160 if (nowVisible) {
9161 wtoken.appToken.windowsVisible();
9162 } else {
9163 wtoken.appToken.windowsGone();
9164 }
9165 } catch (RemoteException ex) {
9166 }
9167 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009169 case WINDOW_FREEZE_TIMEOUT: {
9170 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009171 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009172 int i = mWindows.size();
9173 while (i > 0) {
9174 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009175 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009176 if (w.mOrientationChanging) {
9177 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009178 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009179 }
9180 }
9181 performLayoutAndPlaceSurfacesLocked();
9182 }
9183 break;
9184 }
Romain Guy06882f82009-06-10 13:36:04 -07009185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009186 case HOLD_SCREEN_CHANGED: {
9187 Session oldHold;
9188 Session newHold;
9189 synchronized (mWindowMap) {
9190 oldHold = mLastReportedHold;
9191 newHold = (Session)msg.obj;
9192 mLastReportedHold = newHold;
9193 }
Romain Guy06882f82009-06-10 13:36:04 -07009194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009195 if (oldHold != newHold) {
9196 try {
9197 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009198 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 "window",
9200 BatteryStats.WAKE_TYPE_WINDOW);
9201 }
9202 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009203 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009204 "window",
9205 BatteryStats.WAKE_TYPE_WINDOW);
9206 }
9207 } catch (RemoteException e) {
9208 }
9209 }
9210 break;
9211 }
Romain Guy06882f82009-06-10 13:36:04 -07009212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009213 case APP_TRANSITION_TIMEOUT: {
9214 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009215 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009216 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009217 "*** APP TRANSITION TIMEOUT");
9218 mAppTransitionReady = true;
9219 mAppTransitionTimeout = true;
9220 performLayoutAndPlaceSurfacesLocked();
9221 }
9222 }
9223 break;
9224 }
Romain Guy06882f82009-06-10 13:36:04 -07009225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 case PERSIST_ANIMATION_SCALE: {
9227 Settings.System.putFloat(mContext.getContentResolver(),
9228 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9229 Settings.System.putFloat(mContext.getContentResolver(),
9230 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9231 break;
9232 }
Romain Guy06882f82009-06-10 13:36:04 -07009233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009234 case FORCE_GC: {
9235 synchronized(mWindowMap) {
9236 if (mAnimationPending) {
9237 // If we are animating, don't do the gc now but
9238 // delay a bit so we don't interrupt the animation.
9239 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9240 2000);
9241 return;
9242 }
9243 // If we are currently rotating the display, it will
9244 // schedule a new message when done.
9245 if (mDisplayFrozen) {
9246 return;
9247 }
9248 mFreezeGcPending = 0;
9249 }
9250 Runtime.getRuntime().gc();
9251 break;
9252 }
Romain Guy06882f82009-06-10 13:36:04 -07009253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009254 case ENABLE_SCREEN: {
9255 performEnableScreen();
9256 break;
9257 }
Romain Guy06882f82009-06-10 13:36:04 -07009258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009259 case APP_FREEZE_TIMEOUT: {
9260 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009261 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 int i = mAppTokens.size();
9263 while (i > 0) {
9264 i--;
9265 AppWindowToken tok = mAppTokens.get(i);
9266 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009267 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009268 unsetAppFreezingScreenLocked(tok, true, true);
9269 }
9270 }
9271 }
9272 break;
9273 }
Romain Guy06882f82009-06-10 13:36:04 -07009274
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009275 case SEND_NEW_CONFIGURATION: {
9276 removeMessages(SEND_NEW_CONFIGURATION);
9277 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009278 break;
9279 }
Romain Guy06882f82009-06-10 13:36:04 -07009280
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009281 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009282 if (mWindowsChanged) {
9283 synchronized (mWindowMap) {
9284 mWindowsChanged = false;
9285 }
9286 notifyWindowsChanged();
9287 }
9288 break;
9289 }
9290
Christopher Tatea53146c2010-09-07 11:57:52 -07009291 case DRAG_START_TIMEOUT: {
9292 IBinder win = (IBinder)msg.obj;
9293 if (DEBUG_DRAG) {
9294 Slog.w(TAG, "Timeout starting drag by win " + win);
9295 }
9296 synchronized (mWindowMap) {
9297 // !!! TODO: ANR the app that has failed to start the drag in time
9298 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009299 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009300 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009301 mDragState.reset();
9302 mDragState = null;
9303 }
9304 }
Chris Tated4533f142010-10-19 15:15:08 -07009305 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009306 }
9307
Chris Tated4533f142010-10-19 15:15:08 -07009308 case DRAG_END_TIMEOUT: {
9309 IBinder win = (IBinder)msg.obj;
9310 if (DEBUG_DRAG) {
9311 Slog.w(TAG, "Timeout ending drag to win " + win);
9312 }
9313 synchronized (mWindowMap) {
9314 // !!! TODO: ANR the drag-receiving app
9315 mDragState.mDragResult = false;
9316 mDragState.endDragLw();
9317 }
9318 break;
9319 }
Jeff Brown2992ea72011-01-28 22:04:14 -08009320
9321 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
9322 notifyHardKeyboardStatusChange();
9323 break;
9324 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009325 }
9326 }
9327 }
9328
9329 // -------------------------------------------------------------
9330 // IWindowManager API
9331 // -------------------------------------------------------------
9332
9333 public IWindowSession openSession(IInputMethodClient client,
9334 IInputContext inputContext) {
9335 if (client == null) throw new IllegalArgumentException("null client");
9336 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009337 Session session = new Session(client, inputContext);
9338 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009339 }
9340
9341 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9342 synchronized (mWindowMap) {
9343 // The focus for the client is the window immediately below
9344 // where we would place the input method window.
9345 int idx = findDesiredInputMethodWindowIndexLocked(false);
9346 WindowState imFocus;
9347 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009348 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08009349 //Log.i(TAG, "Desired input method target: " + imFocus);
9350 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
9351 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009352 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08009353 // This may be a starting window, in which case we still want
9354 // to count it as okay.
9355 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
9356 && imFocus.mAppToken != null) {
9357 // The client has definitely started, so it really should
9358 // have a window in this app token. Let's look for it.
9359 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
9360 WindowState w = imFocus.mAppToken.windows.get(i);
9361 if (w != imFocus) {
9362 //Log.i(TAG, "Switching to real app window: " + w);
9363 imFocus = w;
9364 break;
9365 }
9366 }
9367 }
9368 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
9369 //if (imFocus.mSession.mClient != null) {
9370 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
9371 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
9372 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009373 if (imFocus.mSession.mClient != null &&
9374 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9375 return true;
9376 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08009377
9378 // Okay, how about this... what is the current focus?
9379 // It seems in some cases we may not have moved the IM
9380 // target window, such as when it was in a pop-up window,
9381 // so let's also look at the current focus. (An example:
9382 // go to Gmail, start searching so the keyboard goes up,
9383 // press home. Sometimes the IME won't go down.)
9384 // Would be nice to fix this more correctly, but it's
9385 // way at the end of a release, and this should be good enough.
9386 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
9387 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
9388 return true;
9389 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009390 }
9391 }
9392 }
9393 return false;
9394 }
Romain Guy06882f82009-06-10 13:36:04 -07009395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009396 // -------------------------------------------------------------
9397 // Internals
9398 // -------------------------------------------------------------
9399
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009400 final WindowState windowForClientLocked(Session session, IWindow client,
9401 boolean throwOnError) {
9402 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009403 }
Romain Guy06882f82009-06-10 13:36:04 -07009404
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009405 final WindowState windowForClientLocked(Session session, IBinder client,
9406 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009408 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009409 TAG, "Looking up client " + client + ": " + win);
9410 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009411 RuntimeException ex = new IllegalArgumentException(
9412 "Requested window " + client + " does not exist");
9413 if (throwOnError) {
9414 throw ex;
9415 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009416 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 return null;
9418 }
9419 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009420 RuntimeException ex = new IllegalArgumentException(
9421 "Requested window " + client + " is in session " +
9422 win.mSession + ", not " + session);
9423 if (throwOnError) {
9424 throw ex;
9425 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009426 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 return null;
9428 }
9429
9430 return win;
9431 }
9432
Dianne Hackborna8f60182009-09-01 19:01:50 -07009433 final void rebuildAppWindowListLocked() {
9434 int NW = mWindows.size();
9435 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009436 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009437 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009438
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009439 if (mRebuildTmp.length < NW) {
9440 mRebuildTmp = new WindowState[NW+10];
9441 }
9442
Dianne Hackborna8f60182009-09-01 19:01:50 -07009443 // First remove all existing app windows.
9444 i=0;
9445 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009446 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009447 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009448 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009449 win.mRebuilding = true;
9450 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009451 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009452 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009453 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009454 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009455 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009456 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009457 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9458 && lastWallpaper == i-1) {
9459 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009460 }
9461 i++;
9462 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009463
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009464 // The wallpaper window(s) typically live at the bottom of the stack,
9465 // so skip them before adding app tokens.
9466 lastWallpaper++;
9467 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009468
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009469 // First add all of the exiting app tokens... these are no longer
9470 // in the main app list, but still have windows shown. We put them
9471 // in the back because now that the animation is over we no longer
9472 // will care about them.
9473 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009474 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009475 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9476 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009477
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009478 // And add in the still active app tokens in Z order.
9479 NT = mAppTokens.size();
9480 for (int j=0; j<NT; j++) {
9481 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009482 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009483
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009484 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009485 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009486 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009487 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009488 for (i=0; i<numRemoved; i++) {
9489 WindowState ws = mRebuildTmp[i];
9490 if (ws.mRebuilding) {
9491 StringWriter sw = new StringWriter();
9492 PrintWriter pw = new PrintWriter(sw);
9493 ws.dump(pw, "");
9494 pw.flush();
9495 Slog.w(TAG, "This window was lost: " + ws);
9496 Slog.w(TAG, sw.toString());
9497 }
9498 }
9499 Slog.w(TAG, "Current app token list:");
9500 dumpAppTokensLocked();
9501 Slog.w(TAG, "Final window list:");
9502 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009503 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009504 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009506 private final void assignLayersLocked() {
9507 int N = mWindows.size();
9508 int curBaseLayer = 0;
9509 int curLayer = 0;
9510 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009511
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009512 if (DEBUG_LAYERS) {
9513 RuntimeException here = new RuntimeException("here");
9514 here.fillInStackTrace();
9515 Log.v(TAG, "Assigning layers", here);
9516 }
9517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009518 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009519 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009520 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9521 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009522 curLayer += WINDOW_LAYER_MULTIPLIER;
9523 w.mLayer = curLayer;
9524 } else {
9525 curBaseLayer = curLayer = w.mBaseLayer;
9526 w.mLayer = curLayer;
9527 }
9528 if (w.mTargetAppToken != null) {
9529 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9530 } else if (w.mAppToken != null) {
9531 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9532 } else {
9533 w.mAnimLayer = w.mLayer;
9534 }
9535 if (w.mIsImWindow) {
9536 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009537 } else if (w.mIsWallpaper) {
9538 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009540 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009541 + w.mAnimLayer);
9542 //System.out.println(
9543 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9544 }
9545 }
9546
9547 private boolean mInLayout = false;
9548 private final void performLayoutAndPlaceSurfacesLocked() {
9549 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009550 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 throw new RuntimeException("Recursive call!");
9552 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009553 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009554 return;
9555 }
9556
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009557 if (mWaitingForConfig) {
9558 // Our configuration has changed (most likely rotation), but we
9559 // don't yet have the complete configuration to report to
9560 // applications. Don't do any window layout until we have it.
9561 return;
9562 }
9563
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009564 if (mDisplay == null) {
9565 // Not yet initialized, nothing to do.
9566 return;
9567 }
9568
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009569 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009570 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009571
9572 try {
9573 if (mForceRemoves != null) {
9574 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009575 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009576 for (int i=0; i<mForceRemoves.size(); i++) {
9577 WindowState ws = mForceRemoves.get(i);
9578 Slog.i(TAG, "Force removing: " + ws);
9579 removeWindowInnerLocked(ws.mSession, ws);
9580 }
9581 mForceRemoves = null;
9582 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9583 Object tmp = new Object();
9584 synchronized (tmp) {
9585 try {
9586 tmp.wait(250);
9587 } catch (InterruptedException e) {
9588 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 }
9590 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009591 } catch (RuntimeException e) {
9592 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009595 try {
9596 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009597
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009598 int N = mPendingRemove.size();
9599 if (N > 0) {
9600 if (mPendingRemoveTmp.length < N) {
9601 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009602 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009603 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009604 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009605 for (int i=0; i<N; i++) {
9606 WindowState w = mPendingRemoveTmp[i];
9607 removeWindowInnerLocked(w.mSession, w);
9608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009609
9610 mInLayout = false;
9611 assignLayersLocked();
9612 mLayoutNeeded = true;
9613 performLayoutAndPlaceSurfacesLocked();
9614
9615 } else {
9616 mInLayout = false;
9617 if (mLayoutNeeded) {
9618 requestAnimationLocked(0);
9619 }
9620 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009621 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009622 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9623 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009625 } catch (RuntimeException e) {
9626 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009627 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009628 }
9629 }
9630
Jeff Brown3a22cd92011-01-21 13:59:04 -08009631 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009632 if (!mLayoutNeeded) {
9633 return 0;
9634 }
9635
9636 mLayoutNeeded = false;
9637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009638 final int dw = mDisplay.getWidth();
9639 final int dh = mDisplay.getHeight();
9640
9641 final int N = mWindows.size();
9642 int i;
9643
Joe Onorato8a9b2202010-02-26 18:56:32 -08009644 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009645 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9646
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009647 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009648
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009649 int seq = mLayoutSeq+1;
9650 if (seq < 0) seq = 0;
9651 mLayoutSeq = seq;
9652
9653 // First perform layout of any root windows (not attached
9654 // to another window).
9655 int topAttached = -1;
9656 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009657 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009658
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009659 // Don't do layout of a window if it is not visible, or
9660 // soon won't be visible, to avoid wasting time and funky
9661 // changes while a window is animating away.
9662 final AppWindowToken atoken = win.mAppToken;
9663 final boolean gone = win.mViewVisibility == View.GONE
9664 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009665 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009666 || (atoken != null && atoken.hiddenRequested)
9667 || win.mAttachedHidden
9668 || win.mExiting || win.mDestroying;
9669
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009670 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9671 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009672 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9673 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009674 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009675 + win.mViewVisibility + " mRelayoutCalled="
9676 + win.mRelayoutCalled + " hidden="
9677 + win.mRootToken.hidden + " hiddenRequested="
9678 + (atoken != null && atoken.hiddenRequested)
9679 + " mAttachedHidden=" + win.mAttachedHidden);
9680 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009681
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009682 // If this view is GONE, then skip it -- keep the current
9683 // frame, and let the caller know so they can ignore it
9684 // if they want. (We do the normal layout for INVISIBLE
9685 // windows, since that means "perform layout as normal,
9686 // just don't display").
9687 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009688 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009689 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009690 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009691 win.mContentChanged = false;
9692 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009693 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9694 win.mLayoutSeq = seq;
9695 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9696 + win.mFrame + " mContainingFrame="
9697 + win.mContainingFrame + " mDisplayFrame="
9698 + win.mDisplayFrame);
9699 } else {
9700 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009701 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009703 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009704
9705 // Now perform layout of attached windows, which usually
9706 // depend on the position of the window they are attached to.
9707 // XXX does not deal with windows that are attached to windows
9708 // that are themselves attached.
9709 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009710 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009711
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009712 if (win.mLayoutAttached) {
9713 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9714 + " mHaveFrame=" + win.mHaveFrame
9715 + " mViewVisibility=" + win.mViewVisibility
9716 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009717 // If this view is GONE, then skip it -- keep the current
9718 // frame, and let the caller know so they can ignore it
9719 // if they want. (We do the normal layout for INVISIBLE
9720 // windows, since that means "perform layout as normal,
9721 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009722 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9723 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009724 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009725 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009726 win.mContentChanged = false;
9727 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009728 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9729 win.mLayoutSeq = seq;
9730 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9731 + win.mFrame + " mContainingFrame="
9732 + win.mContainingFrame + " mDisplayFrame="
9733 + win.mDisplayFrame);
9734 }
9735 }
9736 }
Jeff Brown349703e2010-06-22 01:27:15 -07009737
9738 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009739 mInputMonitor.setUpdateInputWindowsNeededLw();
9740 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009741 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009742 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009743
9744 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009745 }
Romain Guy06882f82009-06-10 13:36:04 -07009746
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009747 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009748 private final void performLayoutAndPlaceSurfacesLockedInner(
9749 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009750 if (mDisplay == null) {
9751 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9752 return;
9753 }
9754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 final long currentTime = SystemClock.uptimeMillis();
9756 final int dw = mDisplay.getWidth();
9757 final int dh = mDisplay.getHeight();
9758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009759 int i;
9760
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009761 if (mFocusMayChange) {
9762 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009763 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9764 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009765 }
9766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 // Initialize state of exiting tokens.
9768 for (i=mExitingTokens.size()-1; i>=0; i--) {
9769 mExitingTokens.get(i).hasVisible = false;
9770 }
9771
9772 // Initialize state of exiting applications.
9773 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9774 mExitingAppTokens.get(i).hasVisible = false;
9775 }
9776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009777 boolean orientationChangeComplete = true;
9778 Session holdScreen = null;
9779 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009780 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009781 boolean focusDisplayed = false;
9782 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009783 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009784 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009785
9786 if (mFxSession == null) {
9787 mFxSession = new SurfaceSession();
9788 createWatermark = true;
9789 }
9790
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009791 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009792
9793 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009794
9795 if (createWatermark) {
9796 createWatermark();
9797 }
9798 if (mWatermark != null) {
9799 mWatermark.positionSurface(dw, dh);
9800 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009801 if (mStrictModeFlash != null) {
9802 mStrictModeFlash.positionSurface(dw, dh);
9803 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009806 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009807 int repeats = 0;
9808 int changes = 0;
9809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009810 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009811 repeats++;
9812 if (repeats > 6) {
9813 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9814 mLayoutNeeded = false;
9815 break;
9816 }
9817
9818 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9819 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9820 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9821 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9822 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9823 assignLayersLocked();
9824 mLayoutNeeded = true;
9825 }
9826 }
9827 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9828 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009829 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009830 mLayoutNeeded = true;
9831 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9832 }
9833 }
9834 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9835 mLayoutNeeded = true;
9836 }
9837 }
9838
9839 // FIRST LOOP: Perform a layout, if needed.
9840 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009841 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009842 if (changes != 0) {
9843 continue;
9844 }
9845 } else {
9846 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9847 changes = 0;
9848 }
9849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009850 final int transactionSequence = ++mTransactionSequence;
9851
9852 // Update animations of all applications, including those
9853 // associated with exiting/removed apps
9854 boolean tokensAnimating = false;
9855 final int NAT = mAppTokens.size();
9856 for (i=0; i<NAT; i++) {
9857 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9858 tokensAnimating = true;
9859 }
9860 }
9861 final int NEAT = mExitingAppTokens.size();
9862 for (i=0; i<NEAT; i++) {
9863 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9864 tokensAnimating = true;
9865 }
9866 }
9867
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009868 // SECOND LOOP: Execute animations and update visibility of windows.
9869
Joe Onorato8a9b2202010-02-26 18:56:32 -08009870 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009871 + transactionSequence + " tokensAnimating="
9872 + tokensAnimating);
9873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009874 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009875
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009876 if (mScreenRotationAnimation != null) {
9877 if (mScreenRotationAnimation.isAnimating()) {
9878 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9879 animating = true;
9880 } else {
9881 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009882 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009883 }
9884 }
9885 }
9886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009888 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009889 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009890 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009891
9892 mPolicy.beginAnimationLw(dw, dh);
9893
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009894 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009897 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009898
9899 final WindowManager.LayoutParams attrs = w.mAttrs;
9900
9901 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009902 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009903 if (w.commitFinishDrawingLocked(currentTime)) {
9904 if ((w.mAttrs.flags
9905 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009906 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009907 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009908 wallpaperMayChange = true;
9909 }
9910 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009911
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009912 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009913
9914 int animDw = dw;
9915 int animDh = dh;
9916
9917 // If the window has moved due to its containing
9918 // content frame changing, then we'd like to animate
9919 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009920 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009921 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009922 // Frame has moved, containing content frame
9923 // has also moved, and we're not currently animating...
9924 // let's do something.
9925 Animation a = AnimationUtils.loadAnimation(mContext,
9926 com.android.internal.R.anim.window_move_from_decor);
9927 w.setAnimation(a);
9928 animDw = w.mLastFrame.left - w.mFrame.left;
9929 animDh = w.mLastFrame.top - w.mFrame.top;
9930 }
9931
9932 // Execute animation.
9933 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9934 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009935
9936 // If this window is animating, make a note that we have
9937 // an animating window and take care of a request to run
9938 // a detached wallpaper animation.
9939 if (nowAnimating) {
9940 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9941 windowDetachedWallpaper = w;
9942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009943 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009945
9946 // If this window's app token is running a detached wallpaper
9947 // animation, make a note so we can ensure the wallpaper is
9948 // displayed behind it.
9949 if (w.mAppToken != null && w.mAppToken.animation != null
9950 && w.mAppToken.animation.getDetachWallpaper()) {
9951 windowDetachedWallpaper = w;
9952 }
9953
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009954 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9955 wallpaperMayChange = true;
9956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009957
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009958 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009959 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009960 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009961 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009962 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009963 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009964 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009965 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9966 forceHiding = true;
9967 }
9968 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9969 boolean changed;
9970 if (forceHiding) {
9971 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009972 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9973 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009974 } else {
9975 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009976 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9977 "Now policy shown: " + w);
9978 if (changed) {
9979 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009980 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009981 // Assume we will need to animate. If
9982 // we don't (because the wallpaper will
9983 // stay with the lock screen), then we will
9984 // clean up later.
9985 Animation a = mPolicy.createForceHideEnterAnimation();
9986 if (a != null) {
9987 w.setAnimation(a);
9988 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009989 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009990 if (mCurrentFocus == null ||
9991 mCurrentFocus.mLayer < w.mLayer) {
9992 // We are showing on to of the current
9993 // focus, so re-evaluate focus to make
9994 // sure it is correct.
9995 mFocusMayChange = true;
9996 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009997 }
9998 }
9999 if (changed && (attrs.flags
10000 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
10001 wallpaperMayChange = true;
10002 }
10003 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 mPolicy.animatingWindowLw(w, attrs);
10006 }
10007
10008 final AppWindowToken atoken = w.mAppToken;
10009 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
10010 if (atoken.lastTransactionSequence != transactionSequence) {
10011 atoken.lastTransactionSequence = transactionSequence;
10012 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
10013 atoken.startingDisplayed = false;
10014 }
10015 if ((w.isOnScreen() || w.mAttrs.type
10016 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
10017 && !w.mExiting && !w.mDestroying) {
10018 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010019 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010020 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010022 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010023 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010024 + " pv=" + w.mPolicyVisibility
10025 + " dp=" + w.mDrawPending
10026 + " cdp=" + w.mCommitDrawPending
10027 + " ah=" + w.mAttachedHidden
10028 + " th=" + atoken.hiddenRequested
10029 + " a=" + w.mAnimating);
10030 }
10031 }
10032 if (w != atoken.startingWindow) {
10033 if (!atoken.freezingScreen || !w.mAppFreezing) {
10034 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010035 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010036 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010037 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010038 "tokenMayBeDrawn: " + atoken
10039 + " freezingScreen=" + atoken.freezingScreen
10040 + " mAppFreezing=" + w.mAppFreezing);
10041 tokenMayBeDrawn = true;
10042 }
10043 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010044 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010045 atoken.startingDisplayed = true;
10046 }
10047 }
10048 } else if (w.mReadyToShow) {
10049 w.performShowLocked();
10050 }
10051 }
10052
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010053 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054
10055 if (tokenMayBeDrawn) {
10056 // See if any windows have been drawn, so they (and others
10057 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010058 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010059 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010060 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010061 if (wtoken.freezingScreen) {
10062 int numInteresting = wtoken.numInterestingWindows;
10063 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010064 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010065 "allDrawn: " + wtoken
10066 + " interesting=" + numInteresting
10067 + " drawn=" + wtoken.numDrawnWindows);
10068 wtoken.showAllWindowsLocked();
10069 unsetAppFreezingScreenLocked(wtoken, false, true);
10070 orientationChangeComplete = true;
10071 }
10072 } else if (!wtoken.allDrawn) {
10073 int numInteresting = wtoken.numInterestingWindows;
10074 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010075 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010076 "allDrawn: " + wtoken
10077 + " interesting=" + numInteresting
10078 + " drawn=" + wtoken.numDrawnWindows);
10079 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010080 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081
10082 // We can now show all of the drawn windows!
10083 if (!mOpeningApps.contains(wtoken)) {
10084 wtoken.showAllWindowsLocked();
10085 }
10086 }
10087 }
10088 }
10089 }
10090
10091 // If we are ready to perform an app transition, check through
10092 // all of the app tokens to be shown and see if they are ready
10093 // to go.
10094 if (mAppTransitionReady) {
10095 int NN = mOpeningApps.size();
10096 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010097 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010098 "Checking " + NN + " opening apps (frozen="
10099 + mDisplayFrozen + " timeout="
10100 + mAppTransitionTimeout + ")...");
10101 if (!mDisplayFrozen && !mAppTransitionTimeout) {
10102 // If the display isn't frozen, wait to do anything until
10103 // all of the apps are ready. Otherwise just go because
10104 // we'll unfreeze the display when everyone is ready.
10105 for (i=0; i<NN && goodToGo; i++) {
10106 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010107 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010108 "Check opening app" + wtoken + ": allDrawn="
10109 + wtoken.allDrawn + " startingDisplayed="
10110 + wtoken.startingDisplayed);
10111 if (!wtoken.allDrawn && !wtoken.startingDisplayed
10112 && !wtoken.startingMoved) {
10113 goodToGo = false;
10114 }
10115 }
10116 }
10117 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010118 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010119 int transit = mNextAppTransition;
10120 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010121 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010122 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010123 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010124 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010125 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010126 mAppTransitionTimeout = false;
10127 mStartingIconInTransition = false;
10128 mSkipAppTransitionAnimation = false;
10129
10130 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
10131
Dianne Hackborna8f60182009-09-01 19:01:50 -070010132 // If there are applications waiting to come to the
10133 // top of the stack, now is the time to move their windows.
10134 // (Note that we don't do apps going to the bottom
10135 // here -- we want to keep their windows in the old
10136 // Z-order until the animation completes.)
10137 if (mToTopApps.size() > 0) {
10138 NN = mAppTokens.size();
10139 for (i=0; i<NN; i++) {
10140 AppWindowToken wtoken = mAppTokens.get(i);
10141 if (wtoken.sendingToTop) {
10142 wtoken.sendingToTop = false;
10143 moveAppWindowsLocked(wtoken, NN, false);
10144 }
10145 }
10146 mToTopApps.clear();
10147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010148
Dianne Hackborn25994b42009-09-04 14:21:19 -070010149 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010150
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010151 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010152 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010153
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010154 // The top-most window will supply the layout params,
10155 // and we will determine it below.
10156 LayoutParams animLp = null;
10157 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010158 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010159
Joe Onorato8a9b2202010-02-26 18:56:32 -080010160 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010161 "New wallpaper target=" + mWallpaperTarget
10162 + ", lower target=" + mLowerWallpaperTarget
10163 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010164 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010165 // Do a first pass through the tokens for two
10166 // things:
10167 // (1) Determine if both the closing and opening
10168 // app token sets are wallpaper targets, in which
10169 // case special animations are needed
10170 // (since the wallpaper needs to stay static
10171 // behind them).
10172 // (2) Find the layout params of the top-most
10173 // application window in the tokens, which is
10174 // what will control the animation theme.
10175 final int NC = mClosingApps.size();
10176 NN = NC + mOpeningApps.size();
10177 for (i=0; i<NN; i++) {
10178 AppWindowToken wtoken;
10179 int mode;
10180 if (i < NC) {
10181 wtoken = mClosingApps.get(i);
10182 mode = 1;
10183 } else {
10184 wtoken = mOpeningApps.get(i-NC);
10185 mode = 2;
10186 }
10187 if (mLowerWallpaperTarget != null) {
10188 if (mLowerWallpaperTarget.mAppToken == wtoken
10189 || mUpperWallpaperTarget.mAppToken == wtoken) {
10190 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010191 }
10192 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010193 if (wtoken.appFullscreen) {
10194 WindowState ws = wtoken.findMainWindow();
10195 if (ws != null) {
10196 // If this is a compatibility mode
10197 // window, we will always use its anim.
10198 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10199 animLp = ws.mAttrs;
10200 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010201 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010202 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010203 bestAnimLayer = ws.mLayer;
10204 }
10205 fullscreenAnim = true;
10206 }
10207 } else if (!fullscreenAnim) {
10208 WindowState ws = wtoken.findMainWindow();
10209 if (ws != null) {
10210 if (ws.mLayer > bestAnimLayer) {
10211 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010212 bestAnimLayer = ws.mLayer;
10213 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010214 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010215 }
10216 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010217
Dianne Hackborn25994b42009-09-04 14:21:19 -070010218 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010219 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010220 "Wallpaper animation!");
10221 switch (transit) {
10222 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10223 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10224 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10225 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10226 break;
10227 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10228 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10229 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10230 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10231 break;
10232 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010233 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010234 "New transit: " + transit);
10235 } else if (oldWallpaper != null) {
10236 // We are transitioning from an activity with
10237 // a wallpaper to one without.
10238 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010239 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010240 "New transit away from wallpaper: " + transit);
10241 } else if (mWallpaperTarget != null) {
10242 // We are transitioning from an activity without
10243 // a wallpaper to now showing the wallpaper
10244 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010245 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010246 "New transit into wallpaper: " + transit);
10247 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010248
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010249 // If all closing windows are obscured, then there is
10250 // no need to do an animation. This is the case, for
10251 // example, when this transition is being done behind
10252 // the lock screen.
10253 if (!mPolicy.allowAppAnimationsLw()) {
10254 animLp = null;
10255 }
10256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010257 NN = mOpeningApps.size();
10258 for (i=0; i<NN; i++) {
10259 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010260 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010261 "Now opening app" + wtoken);
10262 wtoken.reportedVisible = false;
10263 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010264 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010265 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010267 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 wtoken.showAllWindowsLocked();
10269 }
10270 NN = mClosingApps.size();
10271 for (i=0; i<NN; i++) {
10272 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010273 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010274 "Now closing app" + wtoken);
10275 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010276 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010277 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010279 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 // Force the allDrawn flag, because we want to start
10281 // this guy's animations regardless of whether it's
10282 // gotten drawn.
10283 wtoken.allDrawn = true;
10284 }
10285
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010286 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010288 mOpeningApps.clear();
10289 mClosingApps.clear();
10290
10291 // This has changed the visibility of windows, so perform
10292 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010293 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10294 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010295 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010296 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10297 assignLayersLocked();
10298 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010299 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10300 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010301 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010302 }
10303 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010304
Dianne Hackborn16064f92010-03-25 00:47:24 -070010305 int adjResult = 0;
10306
Dianne Hackborna8f60182009-09-01 19:01:50 -070010307 if (!animating && mAppTransitionRunning) {
10308 // We have finished the animation of an app transition. To do
10309 // this, we have delayed a lot of operations like showing and
10310 // hiding apps, moving apps in Z-order, etc. The app token list
10311 // reflects the correct Z-order, but the window list may now
10312 // be out of sync with it. So here we will just rebuild the
10313 // entire app window list. Fun!
10314 mAppTransitionRunning = false;
10315 // Clear information about apps that were moving.
10316 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010317
Dianne Hackborna8f60182009-09-01 19:01:50 -070010318 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010319 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010320 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010321 moveInputMethodWindowsIfNeededLocked(false);
10322 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010323 // Since the window list has been rebuilt, focus might
10324 // have to be recomputed since the actual order of windows
10325 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010326 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010327 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010328
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010329 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010330 // At this point, there was a window with a wallpaper that
10331 // was force hiding other windows behind it, but now it
10332 // is going away. This may be simple -- just animate
10333 // away the wallpaper and its window -- or it may be
10334 // hard -- the wallpaper now needs to be shown behind
10335 // something that was hidden.
10336 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010337 if (mLowerWallpaperTarget != null
10338 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010339 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010340 "wallpaperForceHiding changed with lower="
10341 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010342 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010343 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10344 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10345 if (mLowerWallpaperTarget.mAppToken.hidden) {
10346 // The lower target has become hidden before we
10347 // actually started the animation... let's completely
10348 // re-evaluate everything.
10349 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010350 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010351 }
10352 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010353 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010354 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010355 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010356 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010357 + " NEW: " + mWallpaperTarget
10358 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010359 if (mLowerWallpaperTarget == null) {
10360 // Whoops, we don't need a special wallpaper animation.
10361 // Clear them out.
10362 forceHiding = false;
10363 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010364 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010365 if (w.mSurface != null) {
10366 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010367 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010368 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010369 forceHiding = true;
10370 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10371 if (!w.mAnimating) {
10372 // We set the animation above so it
10373 // is not yet running.
10374 w.clearAnimation();
10375 }
10376 }
10377 }
10378 }
10379 }
10380 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010381
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010382 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10383 if (DEBUG_WALLPAPER) Slog.v(TAG,
10384 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10385 + windowDetachedWallpaper);
10386 mWindowDetachedWallpaper = windowDetachedWallpaper;
10387 wallpaperMayChange = true;
10388 }
10389
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010390 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010391 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010392 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010393 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010394 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010395
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010396 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010397 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010398 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010399 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010400 assignLayersLocked();
10401 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010402 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010403 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010404 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010405 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010406
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010407 if (mFocusMayChange) {
10408 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010409 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10410 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010411 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010412 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010413 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010414 }
10415
10416 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010417 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010418 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010419
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010420 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10421 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010422 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423
10424 // THIRD LOOP: Update the surfaces of all windows.
10425
10426 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10427
10428 boolean obscured = false;
10429 boolean blurring = false;
10430 boolean dimming = false;
10431 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010432 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010433 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010434
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010435 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010438 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010439
10440 boolean displayed = false;
10441 final WindowManager.LayoutParams attrs = w.mAttrs;
10442 final int attrFlags = attrs.flags;
10443
10444 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010445 // XXX NOTE: The logic here could be improved. We have
10446 // the decision about whether to resize a window separated
10447 // from whether to hide the surface. This can cause us to
10448 // resize a surface even if we are going to hide it. You
10449 // can see this by (1) holding device in landscape mode on
10450 // home screen; (2) tapping browser icon (device will rotate
10451 // to landscape; (3) tap home. The wallpaper will be resized
10452 // in step 2 but then immediately hidden, causing us to
10453 // have to resize and then redraw it again in step 3. It
10454 // would be nice to figure out how to avoid this, but it is
10455 // difficult because we do need to resize surfaces in some
10456 // cases while they are hidden such as when first showing a
10457 // window.
10458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010460 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 TAG, "Placing surface #" + i + " " + w.mSurface
10462 + ": new=" + w.mShownFrame + ", old="
10463 + w.mLastShownFrame);
10464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010465 int width, height;
10466 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010467 // for a scaled surface, we just want to use
10468 // the requested size.
10469 width = w.mRequestedWidth;
10470 height = w.mRequestedHeight;
10471 w.mLastRequestedWidth = width;
10472 w.mLastRequestedHeight = height;
10473 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010474 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 width = w.mShownFrame.width();
10476 height = w.mShownFrame.height();
10477 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 }
10479
Jeff Brownfbae7222011-01-23 13:07:25 -080010480 if (w.mSurface != null) {
10481 if (w.mSurfaceX != w.mShownFrame.left
10482 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010483 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010484 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010485 "POS " + w.mShownFrame.left
10486 + ", " + w.mShownFrame.top, null);
10487 w.mSurfaceX = w.mShownFrame.left;
10488 w.mSurfaceY = w.mShownFrame.top;
10489 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10490 } catch (RuntimeException e) {
10491 Slog.w(TAG, "Error positioning surface of " + w
10492 + " pos=(" + w.mShownFrame.left
10493 + "," + w.mShownFrame.top + ")", e);
10494 if (!recoveringMemory) {
10495 reclaimSomeSurfaceMemoryLocked(w, "position");
10496 }
10497 }
10498 }
10499
10500 if (width < 1) {
10501 width = 1;
10502 }
10503 if (height < 1) {
10504 height = 1;
10505 }
10506
10507 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10508 try {
10509 if (SHOW_TRANSACTIONS) logSurface(w,
10510 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010511 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010512 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010513 w.mSurfaceW = width;
10514 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 } catch (RuntimeException e) {
10517 // If something goes wrong with the surface (such
10518 // as running out of memory), don't take down the
10519 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010520 Slog.e(TAG, "Error resizing surface of " + w
10521 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010522 if (!recoveringMemory) {
10523 reclaimSomeSurfaceMemoryLocked(w, "size");
10524 }
10525 }
10526 }
10527 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010528
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010529 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010530 w.mContentInsetsChanged =
10531 !w.mLastContentInsets.equals(w.mContentInsets);
10532 w.mVisibleInsetsChanged =
10533 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010534 boolean configChanged =
10535 w.mConfiguration != mCurConfiguration
10536 && (w.mConfiguration == null
10537 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010538 if (DEBUG_CONFIGURATION && configChanged) {
10539 Slog.v(TAG, "Win " + w + " config changed: "
10540 + mCurConfiguration);
10541 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010542 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010543 + ": configChanged=" + configChanged
10544 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010545 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10546 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010547 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010548 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010549 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010550 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010551 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10552 Slog.v(TAG, "Resize reasons: "
10553 + "frameChanged=" + frameChanged
10554 + " contentInsetsChanged=" + w.mContentInsetsChanged
10555 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10556 + " surfaceResized=" + w.mSurfaceResized
10557 + " configChanged=" + configChanged);
10558 }
10559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010560 w.mLastFrame.set(w.mFrame);
10561 w.mLastContentInsets.set(w.mContentInsets);
10562 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010563 // If the screen is currently frozen, then keep
10564 // it frozen until this window draws at its new
10565 // orientation.
10566 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010567 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010568 "Resizing while display frozen: " + w);
10569 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010570 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010571 mWindowsFreezingScreen = true;
10572 // XXX should probably keep timeout from
10573 // when we first froze the display.
10574 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10575 mH.sendMessageDelayed(mH.obtainMessage(
10576 H.WINDOW_FREEZE_TIMEOUT), 2000);
10577 }
10578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010579 // If the orientation is changing, then we need to
10580 // hold off on unfreezing the display until this
10581 // window has been redrawn; to do that, we need
10582 // to go through the process of getting informed
10583 // by the application when it has finished drawing.
10584 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010585 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010586 "Orientation start waiting for draw in "
10587 + w + ", surface " + w.mSurface);
10588 w.mDrawPending = true;
10589 w.mCommitDrawPending = false;
10590 w.mReadyToShow = false;
10591 if (w.mAppToken != null) {
10592 w.mAppToken.allDrawn = false;
10593 }
10594 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010595 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010596 "Resizing window " + w + " to " + w.mFrame);
10597 mResizingWindows.add(w);
10598 } else if (w.mOrientationChanging) {
10599 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010600 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 "Orientation not waiting for draw in "
10602 + w + ", surface " + w.mSurface);
10603 w.mOrientationChanging = false;
10604 }
10605 }
10606 }
10607
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010608 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010609 if (!w.mLastHidden) {
10610 //dump();
10611 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010612 if (SHOW_TRANSACTIONS) logSurface(w,
10613 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010614 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010615 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010616 try {
10617 w.mSurface.hide();
10618 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010619 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 }
10621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010622 }
10623 // If we are waiting for this window to handle an
10624 // orientation change, well, it is hidden, so
10625 // doesn't really matter. Note that this does
10626 // introduce a potential glitch if the window
10627 // becomes unhidden before it has drawn for the
10628 // new orientation.
10629 if (w.mOrientationChanging) {
10630 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010631 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 "Orientation change skips hidden " + w);
10633 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010634 } else if (w.mLastLayer != w.mAnimLayer
10635 || w.mLastAlpha != w.mShownAlpha
10636 || w.mLastDsDx != w.mDsDx
10637 || w.mLastDtDx != w.mDtDx
10638 || w.mLastDsDy != w.mDsDy
10639 || w.mLastDtDy != w.mDtDy
10640 || w.mLastHScale != w.mHScale
10641 || w.mLastVScale != w.mVScale
10642 || w.mLastHidden) {
10643 displayed = true;
10644 w.mLastAlpha = w.mShownAlpha;
10645 w.mLastLayer = w.mAnimLayer;
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;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010652 if (SHOW_TRANSACTIONS) logSurface(w,
10653 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010654 + " matrix=[" + (w.mDsDx*w.mHScale)
10655 + "," + (w.mDtDx*w.mVScale)
10656 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010657 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010658 if (w.mSurface != null) {
10659 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010660 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010661 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010662 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010663 w.mSurface.setLayer(w.mAnimLayer);
10664 w.mSurface.setMatrix(
10665 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10666 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10667 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010668 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010669 if (!recoveringMemory) {
10670 reclaimSomeSurfaceMemoryLocked(w, "update");
10671 }
10672 }
10673 }
10674
10675 if (w.mLastHidden && !w.mDrawPending
10676 && !w.mCommitDrawPending
10677 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010678 if (SHOW_TRANSACTIONS) logSurface(w,
10679 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010680 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010681 + " during relayout");
10682 if (showSurfaceRobustlyLocked(w)) {
10683 w.mHasDrawn = true;
10684 w.mLastHidden = false;
10685 } else {
10686 w.mOrientationChanging = false;
10687 }
10688 }
10689 if (w.mSurface != null) {
10690 w.mToken.hasVisible = true;
10691 }
10692 } else {
10693 displayed = true;
10694 }
10695
10696 if (displayed) {
10697 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010698 if (attrs.width == LayoutParams.MATCH_PARENT
10699 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010700 covered = true;
10701 }
10702 }
10703 if (w.mOrientationChanging) {
10704 if (w.mDrawPending || w.mCommitDrawPending) {
10705 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010706 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010707 "Orientation continue waiting for draw in " + w);
10708 } else {
10709 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010710 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010711 "Orientation change complete in " + w);
10712 }
10713 }
10714 w.mToken.hasVisible = true;
10715 }
10716 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010717 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010718 "Orientation change skips hidden " + w);
10719 w.mOrientationChanging = false;
10720 }
10721
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010722 if (w.mContentChanged) {
10723 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10724 w.mContentChanged = false;
10725 }
10726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010727 final boolean canBeSeen = w.isDisplayedLw();
10728
10729 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10730 focusDisplayed = true;
10731 }
10732
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010733 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010735 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010736 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010737 if (w.mSurface != null) {
10738 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10739 holdScreen = w.mSession;
10740 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010741 if (!syswin && w.mAttrs.screenBrightness >= 0
10742 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010743 screenBrightness = w.mAttrs.screenBrightness;
10744 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010745 if (!syswin && w.mAttrs.buttonBrightness >= 0
10746 && buttonBrightness < 0) {
10747 buttonBrightness = w.mAttrs.buttonBrightness;
10748 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010749 if (canBeSeen
10750 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10751 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10752 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010753 syswin = true;
10754 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010755 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010756
Dianne Hackborn25994b42009-09-04 14:21:19 -070010757 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10758 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010759 // This window completely covers everything behind it,
10760 // so we want to leave all of them as unblurred (for
10761 // performance reasons).
10762 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010763 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010764 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010765 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010766 obscured = true;
10767 if (mBackgroundFillerSurface == null) {
10768 try {
10769 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010770 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010771 0, dw, dh,
10772 PixelFormat.OPAQUE,
10773 Surface.FX_SURFACE_NORMAL);
10774 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010775 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010776 }
10777 }
10778 try {
10779 mBackgroundFillerSurface.setPosition(0, 0);
10780 mBackgroundFillerSurface.setSize(dw, dh);
10781 // Using the same layer as Dim because they will never be shown at the
10782 // same time.
10783 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10784 mBackgroundFillerSurface.show();
10785 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010786 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010787 }
10788 backgroundFillerShown = true;
10789 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010790 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010791 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010792 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010793 + ": blurring=" + blurring
10794 + " obscured=" + obscured
10795 + " displayed=" + displayed);
10796 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10797 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010798 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010799 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010800 if (mDimAnimator == null) {
10801 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010802 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010803 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010804 mDimAnimator.updateParameters(mContext.getResources(),
10805 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010806 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010807 }
10808 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10809 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010810 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010811 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010812 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010813 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010814 + mBlurSurface + ": CREATE");
10815 try {
Romain Guy06882f82009-06-10 13:36:04 -070010816 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010817 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010818 -1, 16, 16,
10819 PixelFormat.OPAQUE,
10820 Surface.FX_SURFACE_BLUR);
10821 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010822 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010823 }
10824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010825 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010826 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10827 + mBlurSurface + ": pos=(0,0) (" +
10828 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010829 mBlurSurface.setPosition(0, 0);
10830 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010831 mBlurSurface.setLayer(w.mAnimLayer-2);
10832 if (!mBlurShown) {
10833 try {
10834 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10835 + mBlurSurface + ": SHOW");
10836 mBlurSurface.show();
10837 } catch (RuntimeException e) {
10838 Slog.w(TAG, "Failure showing blur surface", e);
10839 }
10840 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010841 }
10842 }
10843 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010844 }
10845 }
10846 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010847
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010848 if (obscuredChanged && mWallpaperTarget == w) {
10849 // This is the wallpaper target and its obscured state
10850 // changed... make sure the current wallaper's visibility
10851 // has been updated accordingly.
10852 updateWallpaperVisibilityLocked();
10853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010854 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010855
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010856 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10857 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010858 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010859 try {
10860 mBackgroundFillerSurface.hide();
10861 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010862 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010863 }
10864 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010865
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010866 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010867 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10868 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010869 }
Romain Guy06882f82009-06-10 13:36:04 -070010870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010871 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010872 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010873 + ": HIDE");
10874 try {
10875 mBlurSurface.hide();
10876 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010877 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010878 }
10879 mBlurShown = false;
10880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010881 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010882 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010883 }
10884
10885 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010886
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010887 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10888
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010889 if (mWatermark != null) {
10890 mWatermark.drawIfNeeded();
10891 }
10892
Joe Onorato8a9b2202010-02-26 18:56:32 -080010893 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010894 "With display frozen, orientationChangeComplete="
10895 + orientationChangeComplete);
10896 if (orientationChangeComplete) {
10897 if (mWindowsFreezingScreen) {
10898 mWindowsFreezingScreen = false;
10899 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10900 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010901 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010902 }
Romain Guy06882f82009-06-10 13:36:04 -070010903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904 i = mResizingWindows.size();
10905 if (i > 0) {
10906 do {
10907 i--;
10908 WindowState win = mResizingWindows.get(i);
10909 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010910 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10911 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010912 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010913 boolean configChanged =
10914 win.mConfiguration != mCurConfiguration
10915 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010916 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10917 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10918 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010919 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010920 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010921 + " / " + mCurConfiguration + " / 0x"
10922 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010923 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010924 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010925 win.mClient.resized(win.mFrame.width(),
10926 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010927 win.mLastVisibleInsets, win.mDrawPending,
10928 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010929 win.mContentInsetsChanged = false;
10930 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010931 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010932 } catch (RemoteException e) {
10933 win.mOrientationChanging = false;
10934 }
10935 } while (i > 0);
10936 mResizingWindows.clear();
10937 }
Romain Guy06882f82009-06-10 13:36:04 -070010938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010940 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010941 i = mDestroySurface.size();
10942 if (i > 0) {
10943 do {
10944 i--;
10945 WindowState win = mDestroySurface.get(i);
10946 win.mDestroying = false;
10947 if (mInputMethodWindow == win) {
10948 mInputMethodWindow = null;
10949 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010950 if (win == mWallpaperTarget) {
10951 wallpaperDestroyed = true;
10952 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010953 win.destroySurfaceLocked();
10954 } while (i > 0);
10955 mDestroySurface.clear();
10956 }
10957
10958 // Time to remove any exiting tokens?
10959 for (i=mExitingTokens.size()-1; i>=0; i--) {
10960 WindowToken token = mExitingTokens.get(i);
10961 if (!token.hasVisible) {
10962 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010963 if (token.windowType == TYPE_WALLPAPER) {
10964 mWallpaperTokens.remove(token);
10965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010966 }
10967 }
10968
10969 // Time to remove any exiting applications?
10970 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10971 AppWindowToken token = mExitingAppTokens.get(i);
10972 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010973 // Make sure there is no animation running on this token,
10974 // so any windows associated with it will be removed as
10975 // soon as their animations are complete
10976 token.animation = null;
10977 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010978 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10979 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 mAppTokens.remove(token);
10981 mExitingAppTokens.remove(i);
10982 }
10983 }
10984
Dianne Hackborna8f60182009-09-01 19:01:50 -070010985 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010986
Dianne Hackborna8f60182009-09-01 19:01:50 -070010987 if (!animating && mAppTransitionRunning) {
10988 // We have finished the animation of an app transition. To do
10989 // this, we have delayed a lot of operations like showing and
10990 // hiding apps, moving apps in Z-order, etc. The app token list
10991 // reflects the correct Z-order, but the window list may now
10992 // be out of sync with it. So here we will just rebuild the
10993 // entire app window list. Fun!
10994 mAppTransitionRunning = false;
10995 needRelayout = true;
10996 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010997 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010998 // Clear information about apps that were moving.
10999 mToBottomApps.clear();
11000 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011002 if (focusDisplayed) {
11003 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
11004 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011005 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011006 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011007 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011008 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011009 requestAnimationLocked(0);
11010 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011011 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
11012 }
Jeff Browneb857f12010-07-16 10:06:33 -070011013
Jeff Brown3a22cd92011-01-21 13:59:04 -080011014 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080011015 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070011016
Jeff Brown8e03b752010-06-13 19:16:55 -070011017 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080011018 if (!mDisplayFrozen) {
11019 if (screenBrightness < 0 || screenBrightness > 1.0f) {
11020 mPowerManager.setScreenBrightnessOverride(-1);
11021 } else {
11022 mPowerManager.setScreenBrightnessOverride((int)
11023 (screenBrightness * Power.BRIGHTNESS_ON));
11024 }
11025 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
11026 mPowerManager.setButtonBrightnessOverride(-1);
11027 } else {
11028 mPowerManager.setButtonBrightnessOverride((int)
11029 (buttonBrightness * Power.BRIGHTNESS_ON));
11030 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050011031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011032 if (holdScreen != mHoldingScreenOn) {
11033 mHoldingScreenOn = holdScreen;
11034 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
11035 mH.sendMessage(m);
11036 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011037
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011038 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011039 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011040 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
11041 LocalPowerManager.BUTTON_EVENT, true);
11042 mTurnOnScreen = false;
11043 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011044
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011045 if (updateRotation) {
11046 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11047 boolean changed = setRotationUncheckedLocked(
11048 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11049 if (changed) {
11050 sendNewConfiguration();
11051 }
11052 }
11053
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011054 // Check to see if we are now in a state where the screen should
11055 // be enabled, because the window obscured flags have changed.
11056 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011057 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070011058
11059 /**
11060 * Must be called with the main window manager lock held.
11061 */
11062 void setHoldScreenLocked(boolean holding) {
11063 boolean state = mHoldingScreenWakeLock.isHeld();
11064 if (holding != state) {
11065 if (holding) {
11066 mHoldingScreenWakeLock.acquire();
11067 } else {
11068 mPolicy.screenOnStoppedLw();
11069 mHoldingScreenWakeLock.release();
11070 }
11071 }
11072 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011073
11074 void requestAnimationLocked(long delay) {
11075 if (!mAnimationPending) {
11076 mAnimationPending = true;
11077 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
11078 }
11079 }
Romain Guy06882f82009-06-10 13:36:04 -070011080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011081 /**
11082 * Have the surface flinger show a surface, robustly dealing with
11083 * error conditions. In particular, if there is not enough memory
11084 * to show the surface, then we will try to get rid of other surfaces
11085 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070011086 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011087 * @return Returns true if the surface was successfully shown.
11088 */
11089 boolean showSurfaceRobustlyLocked(WindowState win) {
11090 try {
11091 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011092 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011093 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011094 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011095 if (DEBUG_VISIBILITY) Slog.v(TAG,
11096 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011097 win.mTurnOnScreen = false;
11098 mTurnOnScreen = true;
11099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011100 }
11101 return true;
11102 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011103 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011104 }
Romain Guy06882f82009-06-10 13:36:04 -070011105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011106 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070011107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011108 return false;
11109 }
Romain Guy06882f82009-06-10 13:36:04 -070011110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011111 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
11112 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070011113
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011114 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070011116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011117 if (mForceRemoves == null) {
11118 mForceRemoves = new ArrayList<WindowState>();
11119 }
Romain Guy06882f82009-06-10 13:36:04 -070011120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011121 long callingIdentity = Binder.clearCallingIdentity();
11122 try {
11123 // There was some problem... first, do a sanity check of the
11124 // window list to make sure we haven't left any dangling surfaces
11125 // around.
11126 int N = mWindows.size();
11127 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011128 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011129 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011130 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011131 if (ws.mSurface != null) {
11132 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011133 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011134 + ws + " surface=" + ws.mSurface
11135 + " token=" + win.mToken
11136 + " pid=" + ws.mSession.mPid
11137 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011138 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011139 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011140 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011141 ws.mSurface = null;
11142 mForceRemoves.add(ws);
11143 i--;
11144 N--;
11145 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011146 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011147 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011148 + ws + " surface=" + ws.mSurface
11149 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011150 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011151 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011152 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011153 ws.mSurface = null;
11154 leakedSurface = true;
11155 }
11156 }
11157 }
Romain Guy06882f82009-06-10 13:36:04 -070011158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011159 boolean killedApps = false;
11160 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011161 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011162 SparseIntArray pidCandidates = new SparseIntArray();
11163 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011164 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011165 if (ws.mSurface != null) {
11166 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11167 }
11168 }
11169 if (pidCandidates.size() > 0) {
11170 int[] pids = new int[pidCandidates.size()];
11171 for (int i=0; i<pids.length; i++) {
11172 pids[i] = pidCandidates.keyAt(i);
11173 }
11174 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011175 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011176 killedApps = true;
11177 }
11178 } catch (RemoteException e) {
11179 }
11180 }
11181 }
Romain Guy06882f82009-06-10 13:36:04 -070011182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011183 if (leakedSurface || killedApps) {
11184 // We managed to reclaim some memory, so get rid of the trouble
11185 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011186 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011187 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011188 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011189 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011190 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011191 win.mSurface = null;
11192 }
Romain Guy06882f82009-06-10 13:36:04 -070011193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011194 try {
11195 win.mClient.dispatchGetNewSurface();
11196 } catch (RemoteException e) {
11197 }
11198 }
11199 } finally {
11200 Binder.restoreCallingIdentity(callingIdentity);
11201 }
11202 }
Romain Guy06882f82009-06-10 13:36:04 -070011203
Jeff Brown3a22cd92011-01-21 13:59:04 -080011204 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011205 WindowState newFocus = computeFocusedWindowLocked();
11206 if (mCurrentFocus != newFocus) {
11207 // This check makes sure that we don't already have the focus
11208 // change message pending.
11209 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11210 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011211 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011212 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11213 final WindowState oldFocus = mCurrentFocus;
11214 mCurrentFocus = newFocus;
11215 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011217 final WindowState imWindow = mInputMethodWindow;
11218 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011219 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011220 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011221 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11222 mLayoutNeeded = true;
11223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011224 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011225 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011226 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11227 // Client will do the layout, but we need to assign layers
11228 // for handleNewWindowLocked() below.
11229 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011230 }
11231 }
Jeff Brown349703e2010-06-22 01:27:15 -070011232
11233 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11234 // If we defer assigning layers, then the caller is responsible for
11235 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011236 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011238 return true;
11239 }
11240 return false;
11241 }
Jeff Brown349703e2010-06-22 01:27:15 -070011242
Jeff Brown3a22cd92011-01-21 13:59:04 -080011243 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11244 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011246
11247 private WindowState computeFocusedWindowLocked() {
11248 WindowState result = null;
11249 WindowState win;
11250
11251 int i = mWindows.size() - 1;
11252 int nextAppIndex = mAppTokens.size()-1;
11253 WindowToken nextApp = nextAppIndex >= 0
11254 ? mAppTokens.get(nextAppIndex) : null;
11255
11256 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011257 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011258
Joe Onorato8a9b2202010-02-26 18:56:32 -080011259 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011260 TAG, "Looking for focus: " + i
11261 + " = " + win
11262 + ", flags=" + win.mAttrs.flags
11263 + ", canReceive=" + win.canReceiveKeys());
11264
11265 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011267 // If this window's application has been removed, just skip it.
11268 if (thisApp != null && thisApp.removed) {
11269 i--;
11270 continue;
11271 }
Romain Guy06882f82009-06-10 13:36:04 -070011272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011273 // If there is a focused app, don't allow focus to go to any
11274 // windows below it. If this is an application window, step
11275 // through the app tokens until we find its app.
11276 if (thisApp != null && nextApp != null && thisApp != nextApp
11277 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11278 int origAppIndex = nextAppIndex;
11279 while (nextAppIndex > 0) {
11280 if (nextApp == mFocusedApp) {
11281 // Whoops, we are below the focused app... no focus
11282 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011283 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011284 TAG, "Reached focused app: " + mFocusedApp);
11285 return null;
11286 }
11287 nextAppIndex--;
11288 nextApp = mAppTokens.get(nextAppIndex);
11289 if (nextApp == thisApp) {
11290 break;
11291 }
11292 }
11293 if (thisApp != nextApp) {
11294 // Uh oh, the app token doesn't exist! This shouldn't
11295 // happen, but if it does we can get totally hosed...
11296 // so restart at the original app.
11297 nextAppIndex = origAppIndex;
11298 nextApp = mAppTokens.get(nextAppIndex);
11299 }
11300 }
11301
11302 // Dispatch to this window if it is wants key events.
11303 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011304 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011305 TAG, "Found focus @ " + i + " = " + win);
11306 result = win;
11307 break;
11308 }
11309
11310 i--;
11311 }
11312
11313 return result;
11314 }
11315
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011316 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011317 if (mDisplayFrozen) {
11318 return;
11319 }
Romain Guy06882f82009-06-10 13:36:04 -070011320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011321 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011323 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011324 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011325 if (mFreezeGcPending != 0) {
11326 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011327 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011328 mH.removeMessages(H.FORCE_GC);
11329 Runtime.getRuntime().gc();
11330 mFreezeGcPending = now;
11331 }
11332 } else {
11333 mFreezeGcPending = now;
11334 }
Romain Guy06882f82009-06-10 13:36:04 -070011335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011336 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011337
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011338 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011339
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011340 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11341 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011342 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011343 mAppTransitionReady = true;
11344 }
Romain Guy06882f82009-06-10 13:36:04 -070011345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011346 if (PROFILE_ORIENTATION) {
11347 File file = new File("/data/system/frozen");
11348 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11349 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011350
11351 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011352 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11353 mScreenRotationAnimation.kill();
11354 mScreenRotationAnimation = null;
11355 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011356 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011357 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011358 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011359 }
11360 } else {
11361 Surface.freezeDisplay(0);
11362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011363 }
Romain Guy06882f82009-06-10 13:36:04 -070011364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011365 private void stopFreezingDisplayLocked() {
11366 if (!mDisplayFrozen) {
11367 return;
11368 }
Romain Guy06882f82009-06-10 13:36:04 -070011369
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011370 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11371 return;
11372 }
11373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011374 mDisplayFrozen = false;
11375 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11376 if (PROFILE_ORIENTATION) {
11377 Debug.stopMethodTracing();
11378 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011379
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011380 boolean updateRotation = false;
11381
Dianne Hackborna1111872010-11-23 20:55:11 -080011382 if (CUSTOM_SCREEN_ROTATION) {
11383 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011384 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11385 mTransitionAnimationScale)) {
11386 requestAnimationLocked(0);
11387 } else {
11388 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011389 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011390 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011391 }
11392 } else {
11393 Surface.unfreezeDisplay(0);
11394 }
Romain Guy06882f82009-06-10 13:36:04 -070011395
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011396 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011397
Dianne Hackborn420829e2011-01-28 11:30:35 -080011398 boolean configChanged;
11399
Christopher Tateb696aee2010-04-02 19:08:30 -070011400 // While the display is frozen we don't re-compute the orientation
11401 // to avoid inconsistent states. However, something interesting
11402 // could have actually changed during that time so re-evaluate it
11403 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -080011404 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -070011405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011406 // A little kludge: a lot could have happened while the
11407 // display was frozen, so now that we are coming back we
11408 // do a gc so that any remote references the system
11409 // processes holds on others can be released if they are
11410 // no longer needed.
11411 mH.removeMessages(H.FORCE_GC);
11412 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11413 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011415 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011416
11417 if (updateRotation) {
11418 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -080011419 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011420 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -080011421 }
11422
11423 if (configChanged) {
11424 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011425 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011426 }
Romain Guy06882f82009-06-10 13:36:04 -070011427
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011428 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11429 DisplayMetrics dm) {
11430 if (index < tokens.length) {
11431 String str = tokens[index];
11432 if (str != null && str.length() > 0) {
11433 try {
11434 int val = Integer.parseInt(str);
11435 return val;
11436 } catch (Exception e) {
11437 }
11438 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011439 }
11440 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11441 return defDps;
11442 }
11443 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11444 return val;
11445 }
11446
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011447 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011448 final String[] mTokens;
11449 final String mText;
11450 final Paint mTextPaint;
11451 final int mTextWidth;
11452 final int mTextHeight;
11453 final int mTextAscent;
11454 final int mTextDescent;
11455 final int mDeltaX;
11456 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011457
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011458 Surface mSurface;
11459 int mLastDW;
11460 int mLastDH;
11461 boolean mDrawNeeded;
11462
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011463 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011464 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011465 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011466
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011467 if (false) {
11468 Log.i(TAG, "*********************** WATERMARK");
11469 for (int i=0; i<tokens.length; i++) {
11470 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11471 }
11472 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011473
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011474 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011475
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011476 StringBuilder builder = new StringBuilder(32);
11477 int len = mTokens[0].length();
11478 len = len & ~1;
11479 for (int i=0; i<len; i+=2) {
11480 int c1 = mTokens[0].charAt(i);
11481 int c2 = mTokens[0].charAt(i+1);
11482 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11483 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11484 else c1 -= '0';
11485 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11486 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11487 else c2 -= '0';
11488 builder.append((char)(255-((c1*16)+c2)));
11489 }
11490 mText = builder.toString();
11491 if (false) {
11492 Log.i(TAG, "Final text: " + mText);
11493 }
11494
11495 int fontSize = getPropertyInt(tokens, 1,
11496 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11497
11498 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11499 mTextPaint.setTextSize(fontSize);
11500 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11501
11502 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11503 mTextWidth = (int)mTextPaint.measureText(mText);
11504 mTextAscent = fm.ascent;
11505 mTextDescent = fm.descent;
11506 mTextHeight = fm.descent - fm.ascent;
11507
11508 mDeltaX = getPropertyInt(tokens, 2,
11509 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11510 mDeltaY = getPropertyInt(tokens, 3,
11511 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11512 int shadowColor = getPropertyInt(tokens, 4,
11513 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11514 int color = getPropertyInt(tokens, 5,
11515 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11516 int shadowRadius = getPropertyInt(tokens, 6,
11517 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11518 int shadowDx = getPropertyInt(tokens, 8,
11519 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11520 int shadowDy = getPropertyInt(tokens, 9,
11521 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11522
11523 mTextPaint.setColor(color);
11524 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011525
11526 try {
11527 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011528 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011529 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011530 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011531 mSurface.show();
11532 } catch (OutOfResourcesException e) {
11533 }
11534 }
11535
11536 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011537 if (mLastDW != dw || mLastDH != dh) {
11538 mLastDW = dw;
11539 mLastDH = dh;
11540 mSurface.setSize(dw, dh);
11541 mDrawNeeded = true;
11542 }
11543 }
11544
11545 void drawIfNeeded() {
11546 if (mDrawNeeded) {
11547 final int dw = mLastDW;
11548 final int dh = mLastDH;
11549
11550 mDrawNeeded = false;
11551 Rect dirty = new Rect(0, 0, dw, dh);
11552 Canvas c = null;
11553 try {
11554 c = mSurface.lockCanvas(dirty);
11555 } catch (IllegalArgumentException e) {
11556 } catch (OutOfResourcesException e) {
11557 }
11558 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011559 c.drawColor(0, PorterDuff.Mode.CLEAR);
11560
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011561 int deltaX = mDeltaX;
11562 int deltaY = mDeltaY;
11563
11564 // deltaX shouldn't be close to a round fraction of our
11565 // x step, or else things will line up too much.
11566 int div = (dw+mTextWidth)/deltaX;
11567 int rem = (dw+mTextWidth) - (div*deltaX);
11568 int qdelta = deltaX/4;
11569 if (rem < qdelta || rem > (deltaX-qdelta)) {
11570 deltaX += deltaX/3;
11571 }
11572
11573 int y = -mTextHeight;
11574 int x = -mTextWidth;
11575 while (y < (dh+mTextHeight)) {
11576 c.drawText(mText, x, y, mTextPaint);
11577 x += deltaX;
11578 if (x >= dw) {
11579 x -= (dw+mTextWidth);
11580 y += deltaY;
11581 }
11582 }
11583 mSurface.unlockCanvasAndPost(c);
11584 }
11585 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011586 }
11587 }
11588
11589 void createWatermark() {
11590 if (mWatermark != null) {
11591 return;
11592 }
11593
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011594 File file = new File("/system/etc/setup.conf");
11595 FileInputStream in = null;
11596 try {
11597 in = new FileInputStream(file);
11598 DataInputStream ind = new DataInputStream(in);
11599 String line = ind.readLine();
11600 if (line != null) {
11601 String[] toks = line.split("%");
11602 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011603 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011604 }
11605 }
11606 } catch (FileNotFoundException e) {
11607 } catch (IOException e) {
11608 } finally {
11609 if (in != null) {
11610 try {
11611 in.close();
11612 } catch (IOException e) {
11613 }
11614 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011615 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011616 }
11617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011618 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011619 public void statusBarVisibilityChanged(int visibility) {
11620 synchronized (mWindowMap) {
11621 final int N = mWindows.size();
11622 for (int i = 0; i < N; i++) {
11623 WindowState ws = mWindows.get(i);
11624 try {
11625 if (ws.getAttrs().hasSystemUiListeners) {
11626 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11627 }
11628 } catch (RemoteException e) {
11629 // so sorry
11630 }
11631 }
11632 }
11633 }
11634
11635 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011636 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11637 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11638 != PackageManager.PERMISSION_GRANTED) {
11639 pw.println("Permission Denial: can't dump WindowManager from from pid="
11640 + Binder.getCallingPid()
11641 + ", uid=" + Binder.getCallingUid());
11642 return;
11643 }
Romain Guy06882f82009-06-10 13:36:04 -070011644
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011645 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011646 pw.println(" ");
11647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011648 synchronized(mWindowMap) {
11649 pw.println("Current Window Manager state:");
11650 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011651 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011652 pw.print(" Window #"); pw.print(i); pw.print(' ');
11653 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011654 w.dump(pw, " ");
11655 }
11656 if (mInputMethodDialogs.size() > 0) {
11657 pw.println(" ");
11658 pw.println(" Input method dialogs:");
11659 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11660 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011661 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011662 }
11663 }
11664 if (mPendingRemove.size() > 0) {
11665 pw.println(" ");
11666 pw.println(" Remove pending for:");
11667 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11668 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011669 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11670 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011671 w.dump(pw, " ");
11672 }
11673 }
11674 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11675 pw.println(" ");
11676 pw.println(" Windows force removing:");
11677 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11678 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011679 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11680 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011681 w.dump(pw, " ");
11682 }
11683 }
11684 if (mDestroySurface.size() > 0) {
11685 pw.println(" ");
11686 pw.println(" Windows waiting to destroy their surface:");
11687 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11688 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011689 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11690 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011691 w.dump(pw, " ");
11692 }
11693 }
11694 if (mLosingFocus.size() > 0) {
11695 pw.println(" ");
11696 pw.println(" Windows losing focus:");
11697 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11698 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011699 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11700 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011701 w.dump(pw, " ");
11702 }
11703 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011704 if (mResizingWindows.size() > 0) {
11705 pw.println(" ");
11706 pw.println(" Windows waiting to resize:");
11707 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11708 WindowState w = mResizingWindows.get(i);
11709 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11710 pw.print(w); pw.println(":");
11711 w.dump(pw, " ");
11712 }
11713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011714 if (mSessions.size() > 0) {
11715 pw.println(" ");
11716 pw.println(" All active sessions:");
11717 Iterator<Session> it = mSessions.iterator();
11718 while (it.hasNext()) {
11719 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011720 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011721 s.dump(pw, " ");
11722 }
11723 }
11724 if (mTokenMap.size() > 0) {
11725 pw.println(" ");
11726 pw.println(" All tokens:");
11727 Iterator<WindowToken> it = mTokenMap.values().iterator();
11728 while (it.hasNext()) {
11729 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011730 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011731 token.dump(pw, " ");
11732 }
11733 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011734 if (mWallpaperTokens.size() > 0) {
11735 pw.println(" ");
11736 pw.println(" Wallpaper tokens:");
11737 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11738 WindowToken token = mWallpaperTokens.get(i);
11739 pw.print(" Wallpaper #"); pw.print(i);
11740 pw.print(' '); pw.print(token); pw.println(':');
11741 token.dump(pw, " ");
11742 }
11743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011744 if (mAppTokens.size() > 0) {
11745 pw.println(" ");
11746 pw.println(" Application tokens in Z order:");
11747 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011748 pw.print(" App #"); pw.print(i); pw.print(": ");
11749 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011750 }
11751 }
11752 if (mFinishedStarting.size() > 0) {
11753 pw.println(" ");
11754 pw.println(" Finishing start of application tokens:");
11755 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11756 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011757 pw.print(" Finished Starting #"); pw.print(i);
11758 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011759 token.dump(pw, " ");
11760 }
11761 }
11762 if (mExitingTokens.size() > 0) {
11763 pw.println(" ");
11764 pw.println(" Exiting tokens:");
11765 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11766 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011767 pw.print(" Exiting #"); pw.print(i);
11768 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011769 token.dump(pw, " ");
11770 }
11771 }
11772 if (mExitingAppTokens.size() > 0) {
11773 pw.println(" ");
11774 pw.println(" Exiting application tokens:");
11775 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11776 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011777 pw.print(" Exiting App #"); pw.print(i);
11778 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011779 token.dump(pw, " ");
11780 }
11781 }
11782 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011783 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11784 pw.print(" mLastFocus="); pw.println(mLastFocus);
11785 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11786 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11787 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011788 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011789 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11790 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11791 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11792 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011793 if (mWindowDetachedWallpaper != null) {
11794 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11795 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011796 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11797 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11798 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011799 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11800 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11801 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11802 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011803 if (mDimAnimator != null) {
11804 mDimAnimator.printTo(pw);
11805 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011806 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011807 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011808 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011809 pw.print(mInputMethodAnimLayerAdjustment);
11810 pw.print(" mWallpaperAnimLayerAdjustment=");
11811 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011812 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11813 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011814 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11815 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011816 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11817 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011818 pw.print(" mRotation="); pw.print(mRotation);
11819 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11820 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011821 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11822 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011823 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11824 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11825 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11826 pw.print(" mNextAppTransition=0x");
11827 pw.print(Integer.toHexString(mNextAppTransition));
11828 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011829 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011830 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011831 if (mNextAppTransitionPackage != null) {
11832 pw.print(" mNextAppTransitionPackage=");
11833 pw.print(mNextAppTransitionPackage);
11834 pw.print(", mNextAppTransitionEnter=0x");
11835 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11836 pw.print(", mNextAppTransitionExit=0x");
11837 pw.print(Integer.toHexString(mNextAppTransitionExit));
11838 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011839 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11840 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11841 if (mOpeningApps.size() > 0) {
11842 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11843 }
11844 if (mClosingApps.size() > 0) {
11845 pw.print(" mClosingApps="); pw.println(mClosingApps);
11846 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011847 if (mToTopApps.size() > 0) {
11848 pw.print(" mToTopApps="); pw.println(mToTopApps);
11849 }
11850 if (mToBottomApps.size() > 0) {
11851 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11852 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011853 if (mDisplay != null) {
11854 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11855 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11856 } else {
11857 pw.println(" NO DISPLAY");
11858 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011859 pw.println(" Policy:");
11860 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011861 }
11862 }
11863
Jeff Brown349703e2010-06-22 01:27:15 -070011864 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011865 public void monitor() {
11866 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011867 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011868 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011869
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011870 /**
11871 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011872 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011873 */
11874 private static class DimAnimator {
11875 Surface mDimSurface;
11876 boolean mDimShown = false;
11877 float mDimCurrentAlpha;
11878 float mDimTargetAlpha;
11879 float mDimDeltaPerMs;
11880 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011881
11882 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011883
11884 DimAnimator (SurfaceSession session) {
11885 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011886 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011887 + mDimSurface + ": CREATE");
11888 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011889 mDimSurface = new Surface(session, 0,
11890 "DimSurface",
11891 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011892 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011893 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011894 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011895 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011896 }
11897 }
11898 }
11899
11900 /**
11901 * Show the dim surface.
11902 */
11903 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011904 if (!mDimShown) {
11905 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11906 dw + "x" + dh + ")");
11907 mDimShown = true;
11908 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011909 mLastDimWidth = dw;
11910 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011911 mDimSurface.setPosition(0, 0);
11912 mDimSurface.setSize(dw, dh);
11913 mDimSurface.show();
11914 } catch (RuntimeException e) {
11915 Slog.w(TAG, "Failure showing dim surface", e);
11916 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011917 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11918 mLastDimWidth = dw;
11919 mLastDimHeight = dh;
11920 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011921 }
11922 }
11923
11924 /**
11925 * Set's the dim surface's layer and update dim parameters that will be used in
11926 * {@link updateSurface} after all windows are examined.
11927 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011928 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011929 mDimSurface.setLayer(w.mAnimLayer-1);
11930
11931 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011932 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011933 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011934 if (mDimTargetAlpha != target) {
11935 // If the desired dim level has changed, then
11936 // start an animation to it.
11937 mLastDimAnimTime = currentTime;
11938 long duration = (w.mAnimating && w.mAnimation != null)
11939 ? w.mAnimation.computeDurationHint()
11940 : DEFAULT_DIM_DURATION;
11941 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011942 TypedValue tv = new TypedValue();
11943 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11944 tv, true);
11945 if (tv.type == TypedValue.TYPE_FRACTION) {
11946 duration = (long)tv.getFraction((float)duration, (float)duration);
11947 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11948 && tv.type <= TypedValue.TYPE_LAST_INT) {
11949 duration = tv.data;
11950 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011951 }
11952 if (duration < 1) {
11953 // Don't divide by zero
11954 duration = 1;
11955 }
11956 mDimTargetAlpha = target;
11957 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11958 }
11959 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011960
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011961 /**
11962 * Updating the surface's alpha. Returns true if the animation continues, or returns
11963 * false when the animation is finished and the dim surface is hidden.
11964 */
11965 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11966 if (!dimming) {
11967 if (mDimTargetAlpha != 0) {
11968 mLastDimAnimTime = currentTime;
11969 mDimTargetAlpha = 0;
11970 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11971 }
11972 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011973
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011974 boolean animating = false;
11975 if (mLastDimAnimTime != 0) {
11976 mDimCurrentAlpha += mDimDeltaPerMs
11977 * (currentTime-mLastDimAnimTime);
11978 boolean more = true;
11979 if (displayFrozen) {
11980 // If the display is frozen, there is no reason to animate.
11981 more = false;
11982 } else if (mDimDeltaPerMs > 0) {
11983 if (mDimCurrentAlpha > mDimTargetAlpha) {
11984 more = false;
11985 }
11986 } else if (mDimDeltaPerMs < 0) {
11987 if (mDimCurrentAlpha < mDimTargetAlpha) {
11988 more = false;
11989 }
11990 } else {
11991 more = false;
11992 }
11993
11994 // Do we need to continue animating?
11995 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011996 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011997 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11998 mLastDimAnimTime = currentTime;
11999 mDimSurface.setAlpha(mDimCurrentAlpha);
12000 animating = true;
12001 } else {
12002 mDimCurrentAlpha = mDimTargetAlpha;
12003 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080012004 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012005 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
12006 mDimSurface.setAlpha(mDimCurrentAlpha);
12007 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012008 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012009 + ": HIDE");
12010 try {
12011 mDimSurface.hide();
12012 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012013 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012014 }
12015 mDimShown = false;
12016 }
12017 }
12018 }
12019 return animating;
12020 }
12021
12022 public void printTo(PrintWriter pw) {
12023 pw.print(" mDimShown="); pw.print(mDimShown);
12024 pw.print(" current="); pw.print(mDimCurrentAlpha);
12025 pw.print(" target="); pw.print(mDimTargetAlpha);
12026 pw.print(" delta="); pw.print(mDimDeltaPerMs);
12027 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
12028 }
12029 }
12030
12031 /**
12032 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
12033 * This is used for opening/closing transition for apps in compatible mode.
12034 */
12035 private static class FadeInOutAnimation extends Animation {
12036 int mWidth;
12037 boolean mFadeIn;
12038
12039 public FadeInOutAnimation(boolean fadeIn) {
12040 setInterpolator(new AccelerateInterpolator());
12041 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
12042 mFadeIn = fadeIn;
12043 }
12044
12045 @Override
12046 protected void applyTransformation(float interpolatedTime, Transformation t) {
12047 float x = interpolatedTime;
12048 if (!mFadeIn) {
12049 x = 1.0f - x; // reverse the interpolation for fade out
12050 }
12051 if (x < 0.5) {
12052 // move the window out of the screen.
12053 t.getMatrix().setTranslate(mWidth, 0);
12054 } else {
12055 t.getMatrix().setTranslate(0, 0);// show
12056 t.setAlpha((x - 0.5f) * 2);
12057 }
12058 }
12059
12060 @Override
12061 public void initialize(int width, int height, int parentWidth, int parentHeight) {
12062 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
12063 mWidth = width;
12064 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012065
12066 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070012067 public int getZAdjustment() {
12068 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012069 }
12070 }
Jeff Brown2992ea72011-01-28 22:04:14 -080012071
12072 public interface OnHardKeyboardStatusChangeListener {
12073 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
12074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012075}