blob: b7ff64dbc63c0f07f5581efa60cb8174cf9b1ae7 [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;
Jim Millerd6b57052010-06-07 17:52:42 -070050import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070051import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070052import android.content.ClipData;
53import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.Intent;
56import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080061import android.content.res.Resources;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080062import android.graphics.Bitmap;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070065import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070067import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070088import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.os.SystemClock;
90import android.os.SystemProperties;
91import android.os.TokenWatcher;
92import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070093import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070095import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080096import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070098import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700100import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101import android.view.Gravity;
102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
129import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.File;
132import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.FileInputStream;
134import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135import java.io.IOException;
136import java.io.OutputStream;
137import java.io.OutputStreamWriter;
138import java.io.PrintWriter;
139import java.io.StringWriter;
140import java.net.Socket;
141import java.util.ArrayList;
142import java.util.HashMap;
143import java.util.HashSet;
144import java.util.Iterator;
145import java.util.List;
146
147/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700148public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700149 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800152 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800162 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700164 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean DEBUG_APP_TRANSITIONS = false;
166 static final boolean DEBUG_STARTING_WINDOW = false;
167 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700168 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800169 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700171 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 static final boolean PROFILE_ORIENTATION = false;
174 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700175 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to multiply the policy's type layer, to reserve room
178 * for multiple windows of the same type and Z-ordering adjustment
179 * with TYPE_LAYER_OFFSET. */
180 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
183 * or below others in the same layer. */
184 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /** How much to increment the layer for each window, to reserve room
187 * for effect surfaces between them.
188 */
189 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /** The maximum length we will accept for a loaded animation duration:
192 * this is 10 seconds.
193 */
194 static final int MAX_ANIMATION_DURATION = 10*1000;
195
196 /** Amount of time (in milliseconds) to animate the dim surface from one
197 * value to another, when no window animation is driving it.
198 */
199 static final int DEFAULT_DIM_DURATION = 200;
200
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700201 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
202 * compatible windows.
203 */
204 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
205
Dianne Hackborna1111872010-11-23 20:55:11 -0800206 /**
207 * If true, the window manager will do its own custom freezing and general
208 * management of the screen during rotation.
209 */
210 static final boolean CUSTOM_SCREEN_ROTATION = true;
211
Jeff Brown7fbdc842010-06-17 20:52:56 -0700212 // Maximum number of milliseconds to wait for input event injection.
213 // FIXME is this value reasonable?
214 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800215
216 // Maximum number of milliseconds to wait for input devices to be enumerated before
217 // proceding with safe mode detection.
218 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700219
220 // Default input dispatching timeout in nanoseconds.
221 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 static final int UPDATE_FOCUS_NORMAL = 0;
224 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
225 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
226 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700229 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
231 /**
232 * Condition waited on by {@link #reenableKeyguard} to know the call to
233 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500234 * This is set to true only if mKeyguardTokenWatcher.acquired() has
235 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
Jim Miller284b62e2010-06-08 14:27:42 -0700239 private static final int ALLOW_DISABLE_YES = 1;
240 private static final int ALLOW_DISABLE_NO = 0;
241 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
242 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
243
Mike Lockwood983ee092009-11-22 01:42:24 -0500244 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
245 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700247 if (shouldAllowDisableKeyguard()) {
248 mPolicy.enableKeyguard(false);
249 mKeyguardDisabled = true;
250 } else {
251 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700255 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500256 synchronized (mKeyguardTokenWatcher) {
257 mKeyguardDisabled = false;
258 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260 }
261 };
262
Jim Miller284b62e2010-06-08 14:27:42 -0700263 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
264 @Override
265 public void onReceive(Context context, Intent intent) {
266 mPolicy.enableKeyguard(true);
267 synchronized(mKeyguardTokenWatcher) {
268 // lazily evaluate this next time we're asked to disable keyguard
269 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
270 mKeyguardDisabled = false;
271 }
272 }
273 };
274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final Context mContext;
276
277 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
282
283 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 /**
288 * All currently active sessions with clients.
289 */
290 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 /**
293 * Mapping from an IWindow IBinder to the server's Window object.
294 * This is also used as the lock for all of our state.
295 */
296 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
297
298 /**
299 * Mapping from a token IBinder to a WindowToken object.
300 */
301 final HashMap<IBinder, WindowToken> mTokenMap =
302 new HashMap<IBinder, WindowToken>();
303
304 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 * Window tokens that are in the process of exiting, but still
306 * on screen for animations.
307 */
308 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
309
310 /**
311 * Z-ordered (bottom-most first) list of all application tokens, for
312 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800313 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 */
315 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
316
317 /**
318 * Application tokens that are in the process of exiting, but still
319 * on screen for animations.
320 */
321 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
322
323 /**
324 * List of window tokens that have finished starting their application,
325 * and now need to have the policy remove their windows.
326 */
327 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
328
329 /**
330 * Z-ordered (bottom-most first) list of all Window objects.
331 */
Jeff Browne33348b2010-07-15 23:54:05 -0700332 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
334 /**
335 * Windows that are being resized. Used so we can tell the client about
336 * the resize after closing the transaction in which we resized the
337 * underlying surface.
338 */
339 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
340
341 /**
342 * Windows whose animations have ended and now must be removed.
343 */
344 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
345
346 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800347 * Used when processing mPendingRemove to avoid working on the original array.
348 */
349 WindowState[] mPendingRemoveTmp = new WindowState[20];
350
351 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 * Windows whose surface should be destroyed.
353 */
354 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
355
356 /**
357 * Windows that have lost input focus and are waiting for the new
358 * focus window to be displayed before they are told about this.
359 */
360 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
361
362 /**
363 * This is set when we have run out of memory, and will either be an empty
364 * list or contain windows that need to be force removed.
365 */
366 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700367
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800368 /**
369 * Used when rebuilding window list to keep track of windows that have
370 * been removed.
371 */
372 WindowState[] mRebuildTmp = new WindowState[20];
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800381 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800382 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 final float[] mTmpFloats = new float[9];
387
388 boolean mSafeMode;
389 boolean mDisplayEnabled = false;
390 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700391 int mInitialDisplayWidth = 0;
392 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 int mRotation = 0;
394 int mRequestedRotation = 0;
395 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700396 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 ArrayList<IRotationWatcher> mRotationWatchers
398 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 boolean mLayoutNeeded = true;
401 boolean mAnimationPending = false;
402 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800403 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 boolean mWindowsFreezingScreen = false;
405 long mFreezeGcPending = 0;
406 int mAppsFreezingScreen = 0;
407
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800408 int mLayoutSeq = 0;
409
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800410 // State while inside of layoutAndPlaceSurfacesLocked().
411 boolean mFocusMayChange;
412
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800413 Configuration mCurConfiguration = new Configuration();
414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 // This is held as long as we have the screen frozen, to give us time to
416 // perform a rotation animation when turning off shows the lock screen which
417 // changes the orientation.
418 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 // State management of app transitions. When we are preparing for a
421 // transition, mNextAppTransition will be the kind of transition to
422 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
423 // mOpeningApps and mClosingApps are the lists of tokens that will be
424 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700425 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700426 String mNextAppTransitionPackage;
427 int mNextAppTransitionEnter;
428 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700430 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionTimeout = false;
432 boolean mStartingIconInTransition = false;
433 boolean mSkipAppTransitionAnimation = false;
434 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700436 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 H mH = new H();
442
443 WindowState mCurrentFocus = null;
444 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 // This just indicates the window the input method is on top of, not
447 // necessarily the window its input is going to.
448 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 boolean mInputMethodTargetWaitingAnim;
450 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 WindowState mInputMethodWindow = null;
453 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
454
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700455 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800456
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700457 // If non-null, this is the currently visible window that is associated
458 // with the wallpaper.
459 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700460 // If non-null, we are in the middle of animating from one wallpaper target
461 // to another, and this is the lower one in Z-order.
462 WindowState mLowerWallpaperTarget = null;
463 // If non-null, we are in the middle of animating from one wallpaper target
464 // to another, and this is the higher one in Z-order.
465 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800466 // Window currently running an animation that has requested it be detached
467 // from the wallpaper. This means we need to ensure the wallpaper is
468 // visible behind it in case it animates in a way that would allow it to be
469 // seen.
470 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700471 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700472 float mLastWallpaperX = -1;
473 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800474 float mLastWallpaperXStep = -1;
475 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700476 // This is set when we are waiting for a wallpaper to tell us it is done
477 // changing its scroll position.
478 WindowState mWaitingOnWallpaper;
479 // The last time we had a timeout when waiting for a wallpaper.
480 long mLastWallpaperTimeoutTime;
481 // We give a wallpaper up to 150ms to finish scrolling.
482 static final long WALLPAPER_TIMEOUT = 150;
483 // Time we wait after a timeout before trying to wait again.
484 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 AppWindowToken mFocusedApp = null;
487
488 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 float mWindowAnimationScale = 1.0f;
491 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700493 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494
495 // Who is holding the screen on.
496 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700497 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700498
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700499 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700502 * Drag/drop state
503 */
504 class DragState {
505 IBinder mToken;
506 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800507 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700508 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 ClipData mData;
510 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700511 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700512 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700513 float mThumbOffsetX, mThumbOffsetY;
514 InputChannel mServerChannel, mClientChannel;
515 WindowState mTargetWindow;
516 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700517 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700518
Christopher Tateccd24de2011-01-12 15:02:55 -0800519 boolean mPerformDeferredRotation;
520 int mRotation;
521 int mAnimFlags;
522
Jeff Brownfbf09772011-01-16 14:06:57 -0800523 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700524
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800525 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700526 mToken = token;
527 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800528 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700529 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700530 mNotifiedWindows = new ArrayList<WindowState>();
531 }
532
533 void reset() {
534 if (mSurface != null) {
535 mSurface.destroy();
536 }
537 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800538 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700539 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700540 mToken = null;
541 mData = null;
542 mThumbOffsetX = mThumbOffsetY = 0;
543 mNotifiedWindows = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800544 mPerformDeferredRotation = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700545 }
546
547 void register() {
548 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
549 if (mClientChannel != null) {
550 Slog.e(TAG, "Duplicate register of drag input channel");
551 } else {
552 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
553 mServerChannel = channels[0];
554 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800555 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700556 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
557 mH.getLooper().getQueue());
558 }
559 }
560
561 void unregister() {
562 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
563 if (mClientChannel == null) {
564 Slog.e(TAG, "Unregister of nonexistent drag input channel");
565 } else {
566 mInputManager.unregisterInputChannel(mServerChannel);
567 InputQueue.unregisterInputChannel(mClientChannel);
568 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700569 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700570 mClientChannel = null;
571 mServerChannel = null;
572 }
573 }
574
Chris Tatea32dcf72010-10-14 12:13:50 -0700575 int getDragLayerLw() {
576 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
577 * TYPE_LAYER_MULTIPLIER
578 + TYPE_LAYER_OFFSET;
579 }
580
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 /* call out to each visible window/session informing it about the drag
582 */
Chris Tateb8203e92010-10-12 14:23:21 -0700583 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 // Cache a base-class instance of the clip metadata so that parceling
585 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800586 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700587 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700588 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700589
590 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700591 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700592 }
593
Christopher Tate2c095f32010-10-04 14:13:40 -0700594 final int N = mWindows.size();
595 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700596 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700597 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 }
599
600 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
601 * designated window is potentially a drop recipient. There are race situations
602 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
603 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700604 *
605 * This method clones the 'event' parameter if it's being delivered to the same
606 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700607 */
Chris Tateb478f462010-10-15 16:02:26 -0700608 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
609 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700610 // Don't actually send the event if the drag is supposed to be pinned
611 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800612 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700613 final IBinder winBinder = newWin.mClient.asBinder();
614 if (winBinder != mLocalWin) {
615 if (DEBUG_DRAG) {
616 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
617 }
618 return;
619 }
620 }
621
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700622 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700623 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
624 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800625 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700626 try {
627 newWin.mClient.dispatchDragEvent(event);
628 // track each window that we've notified that the drag is starting
629 mNotifiedWindows.add(newWin);
630 } catch (RemoteException e) {
631 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700632 } finally {
633 // if the callee was local, the dispatch has already recycled the event
634 if (Process.myPid() != newWin.mSession.mPid) {
635 event.recycle();
636 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700637 }
638 }
639 }
640
641 /* helper - construct and send a DRAG_STARTED event only if the window has not
642 * previously been notified, i.e. it became visible after the drag operation
643 * was begun. This is a rare case.
644 */
645 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700646 if (mDragInProgress) {
647 // If we have sent the drag-started, we needn't do so again
648 for (WindowState ws : mNotifiedWindows) {
649 if (ws == newWin) {
650 return;
651 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700652 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700653 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700654 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700655 }
Chris Tateb478f462010-10-15 16:02:26 -0700656 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700657 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700658 }
659
Chris Tated4533f142010-10-19 15:15:08 -0700660 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700661 if (DEBUG_DRAG) {
662 Slog.d(TAG, "broadcasting DRAG_ENDED");
663 }
Chris Tated4533f142010-10-19 15:15:08 -0700664 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800665 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700666 for (WindowState ws: mNotifiedWindows) {
667 try {
668 ws.mClient.dispatchDragEvent(evt);
669 } catch (RemoteException e) {
670 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700671 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 }
Chris Tated4533f142010-10-19 15:15:08 -0700673 mNotifiedWindows.clear();
674 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700675 evt.recycle();
676 }
677
Chris Tated4533f142010-10-19 15:15:08 -0700678 void endDragLw() {
679 mDragState.broadcastDragEndedLw();
680
681 // stop intercepting input
682 mDragState.unregister();
683 mInputMonitor.updateInputWindowsLw();
684
Christopher Tateccd24de2011-01-12 15:02:55 -0800685 // Retain the parameters of any deferred rotation operation so
686 // that we can perform it after the reset / unref of the drag state
687 final boolean performRotation = mPerformDeferredRotation;
688 final int rotation = mRotation;
689 final int animFlags = mAnimFlags;
690
Chris Tated4533f142010-10-19 15:15:08 -0700691 // free our resources and drop all the object references
692 mDragState.reset();
693 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800694
695 // Now that we've officially ended the drag, execute any
696 // deferred rotation
697 if (performRotation) {
698 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800699 boolean changed = setRotationUncheckedLocked(rotation, animFlags, false);
Christopher Tateccd24de2011-01-12 15:02:55 -0800700 if (changed) {
701 sendNewConfiguration();
702 }
703 }
Chris Tated4533f142010-10-19 15:15:08 -0700704 }
705
Christopher Tatea53146c2010-09-07 11:57:52 -0700706 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700707 final int myPid = Process.myPid();
708
709 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800710 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800711 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800712 try {
713 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
714 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800715 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800716 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
717 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700718
719 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700720 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800721 if (touchedWin == null) {
722 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
723 return;
724 }
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800725 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700726 final IBinder touchedBinder = touchedWin.mClient.asBinder();
727 if (touchedBinder != mLocalWin) {
728 // This drag is pinned only to the originating window, but the drag
729 // point is outside that window. Pretend it's over empty space.
730 touchedWin = null;
731 }
732 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700733 try {
734 // have we dragged over a new window?
735 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
736 if (DEBUG_DRAG) {
737 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
738 }
739 // force DRAG_EXITED_EVENT if appropriate
740 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700741 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800742 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700744 if (myPid != mTargetWindow.mSession.mPid) {
745 evt.recycle();
746 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700747 }
748 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700749 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700750 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
751 }
752 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700753 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800754 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700755 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700756 if (myPid != touchedWin.mSession.mPid) {
757 evt.recycle();
758 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700759 }
760 } catch (RemoteException e) {
761 Slog.w(TAG, "can't send drag notification to windows");
762 }
763 mTargetWindow = touchedWin;
764 }
765
Chris Tated4533f142010-10-19 15:15:08 -0700766 // Tell the drop target about the data. Returns 'true' if we can immediately
767 // dispatch the global drag-ended message, 'false' if we need to wait for a
768 // result from the recipient.
769 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700770 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700771 if (touchedWin == null) {
772 // "drop" outside a valid window -- no recipient to apply a
773 // timeout to, and we can send the drag-ended message immediately.
774 mDragResult = false;
775 return true;
776 }
777
778 if (DEBUG_DRAG) {
779 Slog.d(TAG, "sending DROP to " + touchedWin);
780 }
781 final int myPid = Process.myPid();
782 final IBinder token = touchedWin.mClient.asBinder();
783 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
784 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800785 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700786 try {
787 touchedWin.mClient.dispatchDragEvent(evt);
788
789 // 5 second timeout for this window to respond to the drop
790 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
791 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
792 mH.sendMessageDelayed(msg, 5000);
793 } catch (RemoteException e) {
794 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
795 return true;
796 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700797 if (myPid != touchedWin.mSession.mPid) {
798 evt.recycle();
799 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700800 }
Chris Tated4533f142010-10-19 15:15:08 -0700801 mToken = token;
802 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700803 }
804
805 // Find the visible, touch-deliverable window under the given point
806 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
807 WindowState touchedWin = null;
808 final int x = (int) xf;
809 final int y = (int) yf;
810 final ArrayList<WindowState> windows = mWindows;
811 final int N = windows.size();
812 for (int i = N - 1; i >= 0; i--) {
813 WindowState child = windows.get(i);
814 final int flags = child.mAttrs.flags;
815 if (!child.isVisibleLw()) {
816 // not visible == don't tell about drags
817 continue;
818 }
819 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
820 // not touchable == don't tell about drags
821 continue;
822 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800823
824 child.getTouchableRegion(mTmpRegion);
825
Christopher Tatea53146c2010-09-07 11:57:52 -0700826 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800827 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
828 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
829 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700830 // Found it
831 touchedWin = child;
832 break;
833 }
834 }
835
836 return touchedWin;
837 }
Christopher Tateccd24de2011-01-12 15:02:55 -0800838
839 void setDeferredRotation(int rotation, int animFlags) {
840 mRotation = rotation;
841 mAnimFlags = animFlags;
842 mPerformDeferredRotation = true;
843 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700844 }
845
846 DragState mDragState = null;
847 private final InputHandler mDragInputHandler = new BaseInputHandler() {
848 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700849 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
850 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700851 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700852 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
853 && mDragState != null) {
854 boolean endDrag = false;
855 final float newX = event.getRawX();
856 final float newY = event.getRawY();
857
Christopher Tatea53146c2010-09-07 11:57:52 -0700858 switch (event.getAction()) {
859 case MotionEvent.ACTION_DOWN: {
860 if (DEBUG_DRAG) {
861 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
862 }
863 } break;
864
865 case MotionEvent.ACTION_MOVE: {
866 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700867 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700868 mDragState.notifyMoveLw(newX, newY);
869 }
870 } break;
871
872 case MotionEvent.ACTION_UP: {
873 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
874 + newX + "," + newY);
875 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700876 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700877 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700878 } break;
879
880 case MotionEvent.ACTION_CANCEL: {
881 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
882 endDrag = true;
883 } break;
884 }
885
886 if (endDrag) {
887 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
888 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700889 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700890 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700891 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700892 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700893
894 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700895 }
896 } catch (Exception e) {
897 Slog.e(TAG, "Exception caught by drag handleMotion", e);
898 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700899 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700900 }
901 }
902 };
903
904 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 * Whether the UI is currently running in touch mode (not showing
906 * navigational focus because the user is directly pressing the screen).
907 */
908 boolean mInTouchMode = false;
909
910 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700911 private ArrayList<WindowChangeListener> mWindowChangeListeners =
912 new ArrayList<WindowChangeListener>();
913 private boolean mWindowsChanged = false;
914
915 public interface WindowChangeListener {
916 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700917 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919
Dianne Hackbornc485a602009-03-24 22:39:49 -0700920 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700921 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700922
923 // The frame use to limit the size of the app running in compatibility mode.
924 Rect mCompatibleScreenFrame = new Rect();
925 // The surface used to fill the outer rim of the app running in compatibility mode.
926 Surface mBackgroundFillerSurface = null;
927 boolean mBackgroundFillerShown = false;
928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 public static WindowManagerService main(Context context,
930 PowerManagerService pm, boolean haveInputMethods) {
931 WMThread thr = new WMThread(context, pm, haveInputMethods);
932 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 synchronized (thr) {
935 while (thr.mService == null) {
936 try {
937 thr.wait();
938 } catch (InterruptedException e) {
939 }
940 }
941 }
Romain Guy06882f82009-06-10 13:36:04 -0700942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 return thr.mService;
944 }
Romain Guy06882f82009-06-10 13:36:04 -0700945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 static class WMThread extends Thread {
947 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 private final Context mContext;
950 private final PowerManagerService mPM;
951 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 public WMThread(Context context, PowerManagerService pm,
954 boolean haveInputMethods) {
955 super("WindowManager");
956 mContext = context;
957 mPM = pm;
958 mHaveInputMethods = haveInputMethods;
959 }
Romain Guy06882f82009-06-10 13:36:04 -0700960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 public void run() {
962 Looper.prepare();
963 WindowManagerService s = new WindowManagerService(mContext, mPM,
964 mHaveInputMethods);
965 android.os.Process.setThreadPriority(
966 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700967 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 synchronized (this) {
970 mService = s;
971 notifyAll();
972 }
Romain Guy06882f82009-06-10 13:36:04 -0700973
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700974 // For debug builds, log event loop stalls to dropbox for analysis.
975 if (StrictMode.conditionallyEnableDebugLogging()) {
976 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
977 }
978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 Looper.loop();
980 }
981 }
982
983 static class PolicyThread extends Thread {
984 private final WindowManagerPolicy mPolicy;
985 private final WindowManagerService mService;
986 private final Context mContext;
987 private final PowerManagerService mPM;
988 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 public PolicyThread(WindowManagerPolicy policy,
991 WindowManagerService service, Context context,
992 PowerManagerService pm) {
993 super("WindowManagerPolicy");
994 mPolicy = policy;
995 mService = service;
996 mContext = context;
997 mPM = pm;
998 }
Romain Guy06882f82009-06-10 13:36:04 -0700999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 public void run() {
1001 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -08001002 WindowManagerPolicyThread.set(this, Looper.myLooper());
1003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -08001005 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 android.os.Process.setThreadPriority(
1007 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -07001008 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -07001010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 synchronized (this) {
1012 mRunning = true;
1013 notifyAll();
1014 }
Romain Guy06882f82009-06-10 13:36:04 -07001015
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001016 // For debug builds, log event loop stalls to dropbox for analysis.
1017 if (StrictMode.conditionallyEnableDebugLogging()) {
1018 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1019 }
1020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 Looper.loop();
1022 }
1023 }
1024
1025 private WindowManagerService(Context context, PowerManagerService pm,
1026 boolean haveInputMethods) {
1027 mContext = context;
1028 mHaveInputMethods = haveInputMethods;
1029 mLimitedAlphaCompositing = context.getResources().getBoolean(
1030 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 mPowerManager = pm;
1033 mPowerManager.setPolicy(mPolicy);
1034 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1035 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1036 "SCREEN_FROZEN");
1037 mScreenFrozenLock.setReferenceCounted(false);
1038
1039 mActivityManager = ActivityManagerNative.getDefault();
1040 mBatteryStats = BatteryStatsService.getService();
1041
1042 // Get persisted window scale setting
1043 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1044 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1045 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1046 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001047
Jim Miller284b62e2010-06-08 14:27:42 -07001048 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1049 IntentFilter filter = new IntentFilter();
1050 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1051 mContext.registerReceiver(mBroadcastReceiver, filter);
1052
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001053 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1054 "KEEP_SCREEN_ON_FLAG");
1055 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056
Jeff Browne33348b2010-07-15 23:54:05 -07001057 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1060 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 synchronized (thr) {
1063 while (!thr.mRunning) {
1064 try {
1065 thr.wait();
1066 } catch (InterruptedException e) {
1067 }
1068 }
1069 }
Romain Guy06882f82009-06-10 13:36:04 -07001070
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001071 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 // Add ourself to the Watchdog monitors.
1074 Watchdog.getInstance().addMonitor(this);
1075 }
1076
1077 @Override
1078 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1079 throws RemoteException {
1080 try {
1081 return super.onTransact(code, data, reply, flags);
1082 } catch (RuntimeException e) {
1083 // The window manager only throws security exceptions, so let's
1084 // log all others.
1085 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001086 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 }
1088 throw e;
1089 }
1090 }
1091
Jeff Browne33348b2010-07-15 23:54:05 -07001092 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001094 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 TAG, "Adding window " + window + " at "
1096 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1097 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001098 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 }
1100
Jeff Browne33348b2010-07-15 23:54:05 -07001101 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001103 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 TAG, "Adding window " + window + " at "
1105 + i + " of " + mWindows.size() + " (before " + pos + ")");
1106 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001107 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 }
1109
1110 //This method finds out the index of a window that has the same app token as
1111 //win. used for z ordering the windows in mWindows
1112 private int findIdxBasedOnAppTokens(WindowState win) {
1113 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001114 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 int jmax = localmWindows.size();
1116 if(jmax == 0) {
1117 return -1;
1118 }
1119 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001120 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 if(wentry.mAppToken == win.mAppToken) {
1122 return j;
1123 }
1124 }
1125 return -1;
1126 }
Romain Guy06882f82009-06-10 13:36:04 -07001127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1129 final IWindow client = win.mClient;
1130 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001131 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 final int N = localmWindows.size();
1134 final WindowState attached = win.mAttachedWindow;
1135 int i;
1136 if (attached == null) {
1137 int tokenWindowsPos = token.windows.size();
1138 if (token.appWindowToken != null) {
1139 int index = tokenWindowsPos-1;
1140 if (index >= 0) {
1141 // If this application has existing windows, we
1142 // simply place the new window on top of them... but
1143 // keep the starting window on top.
1144 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1145 // Base windows go behind everything else.
1146 placeWindowBefore(token.windows.get(0), win);
1147 tokenWindowsPos = 0;
1148 } else {
1149 AppWindowToken atoken = win.mAppToken;
1150 if (atoken != null &&
1151 token.windows.get(index) == atoken.startingWindow) {
1152 placeWindowBefore(token.windows.get(index), win);
1153 tokenWindowsPos--;
1154 } else {
1155 int newIdx = findIdxBasedOnAppTokens(win);
1156 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001157 //there is a window above this one associated with the same
1158 //apptoken note that the window could be a floating window
1159 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001161 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1162 Slog.v(TAG, "Adding window " + win + " at "
1163 + (newIdx+1) + " of " + N);
1164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001166 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 }
1169 }
1170 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001171 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 TAG, "Figuring out where to add app window "
1173 + client.asBinder() + " (token=" + token + ")");
1174 // Figure out where the window should go, based on the
1175 // order of applications.
1176 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001177 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 for (i=NA-1; i>=0; i--) {
1179 AppWindowToken t = mAppTokens.get(i);
1180 if (t == token) {
1181 i--;
1182 break;
1183 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001184
Dianne Hackborna8f60182009-09-01 19:01:50 -07001185 // We haven't reached the token yet; if this token
1186 // is not going to the bottom and has windows, we can
1187 // use it as an anchor for when we do reach the token.
1188 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 pos = t.windows.get(0);
1190 }
1191 }
1192 // We now know the index into the apps. If we found
1193 // an app window above, that gives us the position; else
1194 // we need to look some more.
1195 if (pos != null) {
1196 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001197 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 if (atoken != null) {
1199 final int NC = atoken.windows.size();
1200 if (NC > 0) {
1201 WindowState bottom = atoken.windows.get(0);
1202 if (bottom.mSubLayer < 0) {
1203 pos = bottom;
1204 }
1205 }
1206 }
1207 placeWindowBefore(pos, win);
1208 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001209 // Continue looking down until we find the first
1210 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 while (i >= 0) {
1212 AppWindowToken t = mAppTokens.get(i);
1213 final int NW = t.windows.size();
1214 if (NW > 0) {
1215 pos = t.windows.get(NW-1);
1216 break;
1217 }
1218 i--;
1219 }
1220 if (pos != null) {
1221 // Move in front of any windows attached to this
1222 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001223 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 if (atoken != null) {
1225 final int NC = atoken.windows.size();
1226 if (NC > 0) {
1227 WindowState top = atoken.windows.get(NC-1);
1228 if (top.mSubLayer >= 0) {
1229 pos = top;
1230 }
1231 }
1232 }
1233 placeWindowAfter(pos, win);
1234 } else {
1235 // Just search for the start of this layer.
1236 final int myLayer = win.mBaseLayer;
1237 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001238 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 if (w.mBaseLayer > myLayer) {
1240 break;
1241 }
1242 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001243 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1244 Slog.v(TAG, "Adding window " + win + " at "
1245 + i + " of " + N);
1246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001248 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 }
1250 }
1251 }
1252 } else {
1253 // Figure out where window should go, based on layer.
1254 final int myLayer = win.mBaseLayer;
1255 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001256 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 i++;
1258 break;
1259 }
1260 }
1261 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001262 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001263 TAG, "Adding window " + win + " at "
1264 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001266 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 }
1268 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001269 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 token.windows.add(tokenWindowsPos, win);
1271 }
1272
1273 } else {
1274 // Figure out this window's ordering relative to the window
1275 // it is attached to.
1276 final int NA = token.windows.size();
1277 final int sublayer = win.mSubLayer;
1278 int largestSublayer = Integer.MIN_VALUE;
1279 WindowState windowWithLargestSublayer = null;
1280 for (i=0; i<NA; i++) {
1281 WindowState w = token.windows.get(i);
1282 final int wSublayer = w.mSubLayer;
1283 if (wSublayer >= largestSublayer) {
1284 largestSublayer = wSublayer;
1285 windowWithLargestSublayer = w;
1286 }
1287 if (sublayer < 0) {
1288 // For negative sublayers, we go below all windows
1289 // in the same sublayer.
1290 if (wSublayer >= sublayer) {
1291 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001292 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 token.windows.add(i, win);
1294 }
1295 placeWindowBefore(
1296 wSublayer >= 0 ? attached : w, win);
1297 break;
1298 }
1299 } else {
1300 // For positive sublayers, we go above all windows
1301 // in the same sublayer.
1302 if (wSublayer > sublayer) {
1303 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001304 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 token.windows.add(i, win);
1306 }
1307 placeWindowBefore(w, win);
1308 break;
1309 }
1310 }
1311 }
1312 if (i >= NA) {
1313 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001314 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 token.windows.add(win);
1316 }
1317 if (sublayer < 0) {
1318 placeWindowBefore(attached, win);
1319 } else {
1320 placeWindowAfter(largestSublayer >= 0
1321 ? windowWithLargestSublayer
1322 : attached,
1323 win);
1324 }
1325 }
1326 }
Romain Guy06882f82009-06-10 13:36:04 -07001327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 if (win.mAppToken != null && addToToken) {
1329 win.mAppToken.allAppWindows.add(win);
1330 }
1331 }
Romain Guy06882f82009-06-10 13:36:04 -07001332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 static boolean canBeImeTarget(WindowState w) {
1334 final int fl = w.mAttrs.flags
1335 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1336 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1337 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
Joe Onorato8a9b2202010-02-26 18:56:32 -08001351 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 // + Integer.toHexString(w.mAttrs.flags));
1353 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 Hackborn7eab0942011-01-01 13:21:50 -08001374 // Now, a special case -- if the last target's window is in the
1375 // process of exiting, and is above the new target, keep on the
1376 // last target to avoid flicker. Consider for example a Dialog with
1377 // the IME shown: when the Dialog is dismissed, we want to keep
1378 // the IME above it until it is completely gone so it doesn't drop
1379 // behind the dialog or its full-screen scrim.
1380 if (mInputMethodTarget != null && w != null
1381 && mInputMethodTarget.isDisplayedLw()
1382 && mInputMethodTarget.mExiting) {
1383 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1384 w = mInputMethodTarget;
1385 i = localmWindows.indexOf(w);
1386 }
1387 }
Romain Guy06882f82009-06-10 13:36:04 -07001388
Joe Onorato8a9b2202010-02-26 18:56:32 -08001389 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 if (willMove && w != null) {
1393 final WindowState curTarget = mInputMethodTarget;
1394 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 // Now some fun for dealing with window animations that
1397 // modify the Z order. We need to look at all windows below
1398 // the current target that are in this app, finding the highest
1399 // visible one in layering.
1400 AppWindowToken token = curTarget.mAppToken;
1401 WindowState highestTarget = null;
1402 int highestPos = 0;
1403 if (token.animating || token.animation != null) {
1404 int pos = 0;
1405 pos = localmWindows.indexOf(curTarget);
1406 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001407 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 if (win.mAppToken != token) {
1409 break;
1410 }
1411 if (!win.mRemoved) {
1412 if (highestTarget == null || win.mAnimLayer >
1413 highestTarget.mAnimLayer) {
1414 highestTarget = win;
1415 highestPos = pos;
1416 }
1417 }
1418 pos--;
1419 }
1420 }
Romain Guy06882f82009-06-10 13:36:04 -07001421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001423 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 + mNextAppTransition + " " + highestTarget
1425 + " animating=" + highestTarget.isAnimating()
1426 + " layer=" + highestTarget.mAnimLayer
1427 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001428
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001429 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 // If we are currently setting up for an animation,
1431 // hold everything until we can find out what will happen.
1432 mInputMethodTargetWaitingAnim = true;
1433 mInputMethodTarget = highestTarget;
1434 return highestPos + 1;
1435 } else if (highestTarget.isAnimating() &&
1436 highestTarget.mAnimLayer > w.mAnimLayer) {
1437 // If the window we are currently targeting is involved
1438 // with an animation, and it is on top of the next target
1439 // we will be over, then hold off on moving until
1440 // that is done.
1441 mInputMethodTarget = highestTarget;
1442 return highestPos + 1;
1443 }
1444 }
1445 }
1446 }
Romain Guy06882f82009-06-10 13:36:04 -07001447
Joe Onorato8a9b2202010-02-26 18:56:32 -08001448 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 if (w != null) {
1450 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001451 if (DEBUG_INPUT_METHOD) {
1452 RuntimeException e = null;
1453 if (!HIDE_STACK_CRAWLS) {
1454 e = new RuntimeException();
1455 e.fillInStackTrace();
1456 }
1457 Slog.w(TAG, "Moving IM target from "
1458 + mInputMethodTarget + " to " + w, e);
1459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 mInputMethodTarget = w;
1461 if (w.mAppToken != null) {
1462 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1463 } else {
1464 setInputMethodAnimLayerAdjustment(0);
1465 }
1466 }
1467 return i+1;
1468 }
1469 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001470 if (DEBUG_INPUT_METHOD) {
1471 RuntimeException e = null;
1472 if (!HIDE_STACK_CRAWLS) {
1473 e = new RuntimeException();
1474 e.fillInStackTrace();
1475 }
1476 Slog.w(TAG, "Moving IM target from "
1477 + mInputMethodTarget + " to null", e);
1478 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 mInputMethodTarget = null;
1480 setInputMethodAnimLayerAdjustment(0);
1481 }
1482 return -1;
1483 }
Romain Guy06882f82009-06-10 13:36:04 -07001484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 void addInputMethodWindowToListLocked(WindowState win) {
1486 int pos = findDesiredInputMethodWindowIndexLocked(true);
1487 if (pos >= 0) {
1488 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001489 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001490 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001492 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 moveInputMethodDialogsLocked(pos+1);
1494 return;
1495 }
1496 win.mTargetAppToken = null;
1497 addWindowToListInOrderLocked(win, true);
1498 moveInputMethodDialogsLocked(pos);
1499 }
Romain Guy06882f82009-06-10 13:36:04 -07001500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001502 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 mInputMethodAnimLayerAdjustment = adj;
1504 WindowState imw = mInputMethodWindow;
1505 if (imw != null) {
1506 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 + " anim layer: " + imw.mAnimLayer);
1509 int wi = imw.mChildWindows.size();
1510 while (wi > 0) {
1511 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001512 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001514 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 + " anim layer: " + cw.mAnimLayer);
1516 }
1517 }
1518 int di = mInputMethodDialogs.size();
1519 while (di > 0) {
1520 di --;
1521 imw = mInputMethodDialogs.get(di);
1522 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001523 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 + " anim layer: " + imw.mAnimLayer);
1525 }
1526 }
Romain Guy06882f82009-06-10 13:36:04 -07001527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1529 int wpos = mWindows.indexOf(win);
1530 if (wpos >= 0) {
1531 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001532 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001534 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 int NC = win.mChildWindows.size();
1536 while (NC > 0) {
1537 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001538 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 int cpos = mWindows.indexOf(cw);
1540 if (cpos >= 0) {
1541 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001542 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001543 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 mWindows.remove(cpos);
1545 }
1546 }
1547 }
1548 return interestingPos;
1549 }
Romain Guy06882f82009-06-10 13:36:04 -07001550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 private void reAddWindowToListInOrderLocked(WindowState win) {
1552 addWindowToListInOrderLocked(win, false);
1553 // This is a hack to get all of the child windows added as well
1554 // at the right position. Child windows should be rare and
1555 // this case should be rare, so it shouldn't be that big a deal.
1556 int wpos = mWindows.indexOf(win);
1557 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001558 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001559 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001561 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 reAddWindowLocked(wpos, win);
1563 }
1564 }
Romain Guy06882f82009-06-10 13:36:04 -07001565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 void logWindowList(String prefix) {
1567 int N = mWindows.size();
1568 while (N > 0) {
1569 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001570 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 }
1572 }
Romain Guy06882f82009-06-10 13:36:04 -07001573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 void moveInputMethodDialogsLocked(int pos) {
1575 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001578 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 for (int i=0; i<N; i++) {
1580 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1581 }
1582 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001583 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 logWindowList(" ");
1585 }
Romain Guy06882f82009-06-10 13:36:04 -07001586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 if (pos >= 0) {
1588 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1589 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001590 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 if (wp == mInputMethodWindow) {
1592 pos++;
1593 }
1594 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001595 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 for (int i=0; i<N; i++) {
1597 WindowState win = dialogs.get(i);
1598 win.mTargetAppToken = targetAppToken;
1599 pos = reAddWindowLocked(pos, win);
1600 }
1601 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001602 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 logWindowList(" ");
1604 }
1605 return;
1606 }
1607 for (int i=0; i<N; i++) {
1608 WindowState win = dialogs.get(i);
1609 win.mTargetAppToken = null;
1610 reAddWindowToListInOrderLocked(win);
1611 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001612 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 logWindowList(" ");
1614 }
1615 }
1616 }
Romain Guy06882f82009-06-10 13:36:04 -07001617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1619 final WindowState imWin = mInputMethodWindow;
1620 final int DN = mInputMethodDialogs.size();
1621 if (imWin == null && DN == 0) {
1622 return false;
1623 }
Romain Guy06882f82009-06-10 13:36:04 -07001624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1626 if (imPos >= 0) {
1627 // In this case, the input method windows are to be placed
1628 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 // First check to see if the input method windows are already
1631 // located here, and contiguous.
1632 final int N = mWindows.size();
1633 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001634 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 // Figure out the actual input method window that should be
1637 // at the bottom of their stack.
1638 WindowState baseImWin = imWin != null
1639 ? imWin : mInputMethodDialogs.get(0);
1640 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001641 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 if (cw.mSubLayer < 0) baseImWin = cw;
1643 }
Romain Guy06882f82009-06-10 13:36:04 -07001644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 if (firstImWin == baseImWin) {
1646 // The windows haven't moved... but are they still contiguous?
1647 // First find the top IM window.
1648 int pos = imPos+1;
1649 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001650 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 break;
1652 }
1653 pos++;
1654 }
1655 pos++;
1656 // Now there should be no more input method windows above.
1657 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001658 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 break;
1660 }
1661 pos++;
1662 }
1663 if (pos >= N) {
1664 // All is good!
1665 return false;
1666 }
1667 }
Romain Guy06882f82009-06-10 13:36:04 -07001668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 if (imWin != null) {
1670 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001671 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 logWindowList(" ");
1673 }
1674 imPos = tmpRemoveWindowLocked(imPos, imWin);
1675 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001676 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 logWindowList(" ");
1678 }
1679 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1680 reAddWindowLocked(imPos, imWin);
1681 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001682 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 logWindowList(" ");
1684 }
1685 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1686 } else {
1687 moveInputMethodDialogsLocked(imPos);
1688 }
Romain Guy06882f82009-06-10 13:36:04 -07001689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 } else {
1691 // In this case, the input method windows go in a fixed layer,
1692 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001695 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001696 tmpRemoveWindowLocked(0, imWin);
1697 imWin.mTargetAppToken = null;
1698 reAddWindowToListInOrderLocked(imWin);
1699 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 logWindowList(" ");
1702 }
1703 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1704 } else {
1705 moveInputMethodDialogsLocked(-1);;
1706 }
Romain Guy06882f82009-06-10 13:36:04 -07001707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 }
Romain Guy06882f82009-06-10 13:36:04 -07001709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 if (needAssignLayers) {
1711 assignLayersLocked();
1712 }
Romain Guy06882f82009-06-10 13:36:04 -07001713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 return true;
1715 }
Romain Guy06882f82009-06-10 13:36:04 -07001716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 void adjustInputMethodDialogsLocked() {
1718 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1719 }
Romain Guy06882f82009-06-10 13:36:04 -07001720
Dianne Hackborn25994b42009-09-04 14:21:19 -07001721 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001722 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001723 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1724 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1725 ? wallpaperTarget.mAppToken.animation : null)
1726 + " upper=" + mUpperWallpaperTarget
1727 + " lower=" + mLowerWallpaperTarget);
1728 return (wallpaperTarget != null
1729 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1730 && wallpaperTarget.mAppToken.animation != null)))
1731 || mUpperWallpaperTarget != null
1732 || mLowerWallpaperTarget != null;
1733 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001734
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001735 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1736 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001737
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001738 int adjustWallpaperWindowsLocked() {
1739 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001740
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 final int dw = mDisplay.getWidth();
1742 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001743
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001744 // First find top-most window that has asked to be on top of the
1745 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001746 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001747 int N = localmWindows.size();
1748 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001749 WindowState foundW = null;
1750 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001751 WindowState topCurW = null;
1752 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001753 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001754 int i = N;
1755 while (i > 0) {
1756 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001757 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001758 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1759 if (topCurW == null) {
1760 topCurW = w;
1761 topCurI = i;
1762 }
1763 continue;
1764 }
1765 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001766 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001767 // If this window's app token is hidden and not animating,
1768 // it is of no interest to us.
1769 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001770 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001771 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001772 continue;
1773 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001774 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001775 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001776 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1777 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001778 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001779 && (mWallpaperTarget == w
1780 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001781 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001782 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001783 foundW = w;
1784 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001785 if (w == mWallpaperTarget && ((w.mAppToken != null
1786 && w.mAppToken.animation != null)
1787 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001788 // The current wallpaper target is animating, so we'll
1789 // look behind it for another possible target and figure
1790 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001791 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001792 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001793 continue;
1794 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001795 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001796 } else if (w == mWindowDetachedWallpaper) {
1797 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001798 }
1799 }
1800
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001801 if (foundW == null && windowDetachedI >= 0) {
1802 if (DEBUG_WALLPAPER) Slog.v(TAG,
1803 "Found animating detached wallpaper activity: #" + i + "=" + w);
1804 foundW = w;
1805 foundI = windowDetachedI;
1806 }
1807
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001808 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001809 // If we are currently waiting for an app transition, and either
1810 // the current target or the next target are involved with it,
1811 // then hold off on doing anything with the wallpaper.
1812 // Note that we are checking here for just whether the target
1813 // is part of an app token... which is potentially overly aggressive
1814 // (the app token may not be involved in the transition), but good
1815 // enough (we'll just wait until whatever transition is pending
1816 // executes).
1817 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001818 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001819 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001820 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001821 }
1822 if (foundW != null && foundW.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 found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001825 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001826 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001827 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001828
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001829 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001830 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001831 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001832 + " oldTarget: " + mWallpaperTarget);
1833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001834
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001835 mLowerWallpaperTarget = null;
1836 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001837
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001838 WindowState oldW = mWallpaperTarget;
1839 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001840
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001841 // Now what is happening... if the current and new targets are
1842 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001843 if (foundW != null && oldW != null) {
1844 boolean oldAnim = oldW.mAnimation != null
1845 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1846 boolean foundAnim = foundW.mAnimation != null
1847 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001848 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001849 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001850 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001851 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001852 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001853 int oldI = localmWindows.indexOf(oldW);
1854 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001855 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001856 }
1857 if (oldI >= 0) {
1858 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001859 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001860 + "=" + oldW + "; new#" + foundI
1861 + "=" + foundW);
1862 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001863
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001864 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001865 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001866 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001867 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001868 }
1869 mWallpaperTarget = oldW;
1870 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001871
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001872 // Now set the upper and lower wallpaper targets
1873 // correctly, and make sure that we are positioning
1874 // the wallpaper below the lower.
1875 if (foundI > oldI) {
1876 // The new target is on top of the old one.
1877 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001878 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001879 }
1880 mUpperWallpaperTarget = foundW;
1881 mLowerWallpaperTarget = oldW;
1882 foundW = oldW;
1883 foundI = oldI;
1884 } else {
1885 // The new target is below the old one.
1886 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001887 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001888 }
1889 mUpperWallpaperTarget = oldW;
1890 mLowerWallpaperTarget = foundW;
1891 }
1892 }
1893 }
1894 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001895
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001896 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001897 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001898 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1899 || (mLowerWallpaperTarget.mAppToken != null
1900 && mLowerWallpaperTarget.mAppToken.animation != null);
1901 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1902 || (mUpperWallpaperTarget.mAppToken != null
1903 && mUpperWallpaperTarget.mAppToken.animation != null);
1904 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001905 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001906 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001907 }
1908 mLowerWallpaperTarget = null;
1909 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001910 }
1911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001912
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001913 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001914 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001915 // The window is visible to the compositor... but is it visible
1916 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001917 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001918 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001919
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001920 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001921 // its layer adjustment. Only do this if we are not transfering
1922 // between two wallpaper targets.
1923 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001924 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001925 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001926
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001927 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1928 * TYPE_LAYER_MULTIPLIER
1929 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001930
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001931 // Now w is the window we are supposed to be behind... but we
1932 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001933 // AND any starting window associated with it, AND below the
1934 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001935 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001936 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001937 if (wb.mBaseLayer < maxLayer &&
1938 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001939 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001940 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001941 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001942 // This window is not related to the previous one in any
1943 // interesting way, so stop here.
1944 break;
1945 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001946 foundW = wb;
1947 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001948 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001949 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001950 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001951 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001952
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001953 if (foundW == null && topCurW != null) {
1954 // There is no wallpaper target, so it goes at the bottom.
1955 // We will assume it is the same place as last time, if known.
1956 foundW = topCurW;
1957 foundI = topCurI+1;
1958 } else {
1959 // Okay i is the position immediately above the wallpaper. Look at
1960 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001961 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001962 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001963
Dianne Hackborn284ac932009-08-28 10:34:25 -07001964 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001965 if (mWallpaperTarget.mWallpaperX >= 0) {
1966 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001967 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001968 }
1969 if (mWallpaperTarget.mWallpaperY >= 0) {
1970 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001971 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001972 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001973 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001974
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001975 // Start stepping backwards from here, ensuring that our wallpaper windows
1976 // are correctly placed.
1977 int curTokenIndex = mWallpaperTokens.size();
1978 while (curTokenIndex > 0) {
1979 curTokenIndex--;
1980 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001981 if (token.hidden == visible) {
1982 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1983 token.hidden = !visible;
1984 // Need to do a layout to ensure the wallpaper now has the
1985 // correct size.
1986 mLayoutNeeded = true;
1987 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001989 int curWallpaperIndex = token.windows.size();
1990 while (curWallpaperIndex > 0) {
1991 curWallpaperIndex--;
1992 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001993
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001994 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001995 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001996 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001997
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001998 // First, make sure the client has the current visibility
1999 // state.
2000 if (wallpaper.mWallpaperVisible != visible) {
2001 wallpaper.mWallpaperVisible = visible;
2002 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002003 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002004 "Setting visibility of wallpaper " + wallpaper
2005 + ": " + visible);
2006 wallpaper.mClient.dispatchAppVisibility(visible);
2007 } catch (RemoteException e) {
2008 }
2009 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002010
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002011 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002012 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002013 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002014
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002015 // First, if this window is at the current index, then all
2016 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002017 if (wallpaper == foundW) {
2018 foundI--;
2019 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002020 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002021 continue;
2022 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002023
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002024 // The window didn't match... the current wallpaper window,
2025 // wherever it is, is in the wrong place, so make sure it is
2026 // not in the list.
2027 int oldIndex = localmWindows.indexOf(wallpaper);
2028 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002029 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002030 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002031 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002032 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002033 if (oldIndex < foundI) {
2034 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002035 }
2036 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002037
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002038 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002039 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2040 Slog.v(TAG, "Moving wallpaper " + wallpaper
2041 + " from " + oldIndex + " to " + foundI);
2042 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002043
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002044 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002045 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002046 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002047 }
2048 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002049
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002050 return changed;
2051 }
2052
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002053 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002054 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002055 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002056 mWallpaperAnimLayerAdjustment = adj;
2057 int curTokenIndex = mWallpaperTokens.size();
2058 while (curTokenIndex > 0) {
2059 curTokenIndex--;
2060 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2061 int curWallpaperIndex = token.windows.size();
2062 while (curWallpaperIndex > 0) {
2063 curWallpaperIndex--;
2064 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2065 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002066 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002067 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002068 }
2069 }
2070 }
2071
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002072 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2073 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002074 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002075 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002076 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002077 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002078 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2079 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2080 changed = wallpaperWin.mXOffset != offset;
2081 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002082 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002083 + wallpaperWin + " x: " + offset);
2084 wallpaperWin.mXOffset = offset;
2085 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002086 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002087 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002088 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002089 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002090 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002091
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002092 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002093 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002094 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2095 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2096 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002097 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002098 + wallpaperWin + " y: " + offset);
2099 changed = true;
2100 wallpaperWin.mYOffset = offset;
2101 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002102 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002103 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002104 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002105 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002106 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002107
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002108 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002109 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002110 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002111 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2112 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002113 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002114 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002115 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002116 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002117 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2118 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002119 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002120 if (mWaitingOnWallpaper != null) {
2121 long start = SystemClock.uptimeMillis();
2122 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2123 < start) {
2124 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002125 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002126 "Waiting for offset complete...");
2127 mWindowMap.wait(WALLPAPER_TIMEOUT);
2128 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002129 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002130 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002131 if ((start+WALLPAPER_TIMEOUT)
2132 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002133 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002134 + wallpaperWin);
2135 mLastWallpaperTimeoutTime = start;
2136 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002137 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002138 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002139 }
2140 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002141 } catch (RemoteException e) {
2142 }
2143 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002144
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002145 return changed;
2146 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002147
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002148 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002149 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002150 if (mWaitingOnWallpaper != null &&
2151 mWaitingOnWallpaper.mClient.asBinder() == window) {
2152 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002153 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002154 }
2155 }
2156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002157
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002158 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002159 final int dw = mDisplay.getWidth();
2160 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002161
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002162 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002163
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002164 WindowState target = mWallpaperTarget;
2165 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002166 if (target.mWallpaperX >= 0) {
2167 mLastWallpaperX = target.mWallpaperX;
2168 } else if (changingTarget.mWallpaperX >= 0) {
2169 mLastWallpaperX = changingTarget.mWallpaperX;
2170 }
2171 if (target.mWallpaperY >= 0) {
2172 mLastWallpaperY = target.mWallpaperY;
2173 } else if (changingTarget.mWallpaperY >= 0) {
2174 mLastWallpaperY = changingTarget.mWallpaperY;
2175 }
2176 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002177
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002178 int curTokenIndex = mWallpaperTokens.size();
2179 while (curTokenIndex > 0) {
2180 curTokenIndex--;
2181 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2182 int curWallpaperIndex = token.windows.size();
2183 while (curWallpaperIndex > 0) {
2184 curWallpaperIndex--;
2185 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2186 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2187 wallpaper.computeShownFrameLocked();
2188 changed = true;
2189 // We only want to be synchronous with one wallpaper.
2190 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002191 }
2192 }
2193 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002194
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002195 return changed;
2196 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002197
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002198 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002199 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002200 final int dw = mDisplay.getWidth();
2201 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002202
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002203 int curTokenIndex = mWallpaperTokens.size();
2204 while (curTokenIndex > 0) {
2205 curTokenIndex--;
2206 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002207 if (token.hidden == visible) {
2208 token.hidden = !visible;
2209 // Need to do a layout to ensure the wallpaper now has the
2210 // correct size.
2211 mLayoutNeeded = true;
2212 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002213
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002214 int curWallpaperIndex = token.windows.size();
2215 while (curWallpaperIndex > 0) {
2216 curWallpaperIndex--;
2217 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2218 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002219 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002220 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002221
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002222 if (wallpaper.mWallpaperVisible != visible) {
2223 wallpaper.mWallpaperVisible = visible;
2224 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002225 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002226 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002227 + ": " + visible);
2228 wallpaper.mClient.dispatchAppVisibility(visible);
2229 } catch (RemoteException e) {
2230 }
2231 }
2232 }
2233 }
2234 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 public int addWindow(Session session, IWindow client,
2237 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002238 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 int res = mPolicy.checkAddPermission(attrs);
2240 if (res != WindowManagerImpl.ADD_OKAY) {
2241 return res;
2242 }
Romain Guy06882f82009-06-10 13:36:04 -07002243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 boolean reportNewConfig = false;
2245 WindowState attachedWindow = null;
2246 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002247 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002251 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 }
Romain Guy06882f82009-06-10 13:36:04 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002255 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2257 }
2258
2259 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002260 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002262 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 + attrs.token + ". Aborting.");
2264 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2265 }
2266 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2267 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002268 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 + attrs.token + ". Aborting.");
2270 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2271 }
2272 }
2273
2274 boolean addToken = false;
2275 WindowToken token = mTokenMap.get(attrs.token);
2276 if (token == null) {
2277 if (attrs.type >= FIRST_APPLICATION_WINDOW
2278 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002279 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 + attrs.token + ". Aborting.");
2281 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2282 }
2283 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002284 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 + attrs.token + ". Aborting.");
2286 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2287 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002288 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002289 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002290 + attrs.token + ". Aborting.");
2291 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 token = new WindowToken(attrs.token, -1, false);
2294 addToken = true;
2295 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2296 && attrs.type <= LAST_APPLICATION_WINDOW) {
2297 AppWindowToken atoken = token.appWindowToken;
2298 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002299 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 + token + ". Aborting.");
2301 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2302 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002303 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 + token + ". Aborting.");
2305 return WindowManagerImpl.ADD_APP_EXITING;
2306 }
2307 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2308 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002309 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2311 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2312 }
2313 } else if (attrs.type == TYPE_INPUT_METHOD) {
2314 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002315 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 + attrs.token + ". Aborting.");
2317 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2318 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002319 } else if (attrs.type == TYPE_WALLPAPER) {
2320 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002321 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002322 + attrs.token + ". Aborting.");
2323 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2324 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 }
2326
2327 win = new WindowState(session, client, token,
2328 attachedWindow, attrs, viewVisibility);
2329 if (win.mDeathRecipient == null) {
2330 // Client has apparently died, so there is no reason to
2331 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002332 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002333 + " that is dead, aborting.");
2334 return WindowManagerImpl.ADD_APP_EXITING;
2335 }
2336
2337 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 res = mPolicy.prepareAddWindowLw(win, attrs);
2340 if (res != WindowManagerImpl.ADD_OKAY) {
2341 return res;
2342 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002343
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002344 if (outInputChannel != null) {
2345 String name = win.makeInputChannelName();
2346 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2347 win.mInputChannel = inputChannels[0];
2348 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2349
Jeff Brown928e0542011-01-10 11:17:36 -08002350 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352
2353 // From now on, no exceptions or errors allowed!
2354
2355 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002356
Dianne Hackborn5132b372010-07-29 12:51:35 -07002357 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 if (addToken) {
2360 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 }
2362 win.attach();
2363 mWindowMap.put(client.asBinder(), win);
2364
2365 if (attrs.type == TYPE_APPLICATION_STARTING &&
2366 token.appWindowToken != null) {
2367 token.appWindowToken.startingWindow = win;
2368 }
2369
2370 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 if (attrs.type == TYPE_INPUT_METHOD) {
2373 mInputMethodWindow = win;
2374 addInputMethodWindowToListLocked(win);
2375 imMayMove = false;
2376 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2377 mInputMethodDialogs.add(win);
2378 addWindowToListInOrderLocked(win, true);
2379 adjustInputMethodDialogsLocked();
2380 imMayMove = false;
2381 } else {
2382 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002383 if (attrs.type == TYPE_WALLPAPER) {
2384 mLastWallpaperTimeoutTime = 0;
2385 adjustWallpaperWindowsLocked();
2386 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002387 adjustWallpaperWindowsLocked();
2388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 }
Romain Guy06882f82009-06-10 13:36:04 -07002390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 if (mInTouchMode) {
2396 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2397 }
2398 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2399 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2400 }
Romain Guy06882f82009-06-10 13:36:04 -07002401
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002402 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002404 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2405 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 imMayMove = false;
2407 }
2408 }
Romain Guy06882f82009-06-10 13:36:04 -07002409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002411 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 }
Romain Guy06882f82009-06-10 13:36:04 -07002413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 assignLayersLocked();
2415 // Don't do layout here, the window must call
2416 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 //dump();
2419
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002420 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002421 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002422 }
Jeff Brown349703e2010-06-22 01:27:15 -07002423
Joe Onorato8a9b2202010-02-26 18:56:32 -08002424 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 TAG, "New client " + client.asBinder()
2426 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002427
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002428 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002429 reportNewConfig = true;
2430 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 }
2432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 if (reportNewConfig) {
2434 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 return res;
2440 }
Romain Guy06882f82009-06-10 13:36:04 -07002441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 public void removeWindow(Session session, IWindow client) {
2443 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002444 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 if (win == null) {
2446 return;
2447 }
2448 removeWindowLocked(session, win);
2449 }
2450 }
Romain Guy06882f82009-06-10 13:36:04 -07002451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 public void removeWindowLocked(Session session, WindowState win) {
2453
Joe Onorato8a9b2202010-02-26 18:56:32 -08002454 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 TAG, "Remove " + win + " client="
2456 + Integer.toHexString(System.identityHashCode(
2457 win.mClient.asBinder()))
2458 + ", surface=" + win.mSurface);
2459
2460 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002461
2462 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002463
Joe Onorato8a9b2202010-02-26 18:56:32 -08002464 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2466 + " mExiting=" + win.mExiting
2467 + " isAnimating=" + win.isAnimating()
2468 + " app-animation="
2469 + (win.mAppToken != null ? win.mAppToken.animation : null)
2470 + " inPendingTransaction="
2471 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2472 + " mDisplayFrozen=" + mDisplayFrozen);
2473 // Visibility of the removed window. Will be used later to update orientation later on.
2474 boolean wasVisible = false;
2475 // First, see if we need to run an animation. If we do, we have
2476 // to hold off on removing the window until the animation is done.
2477 // If the display is frozen, just remove immediately, since the
2478 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002479 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 // If we are not currently running the exit animation, we
2481 // need to see about starting one.
2482 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2485 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2486 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2487 }
2488 // Try starting an animation.
2489 if (applyAnimationLocked(win, transit, false)) {
2490 win.mExiting = true;
2491 }
2492 }
2493 if (win.mExiting || win.isAnimating()) {
2494 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002495 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 win.mExiting = true;
2497 win.mRemoveOnExit = true;
2498 mLayoutNeeded = true;
2499 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2500 performLayoutAndPlaceSurfacesLocked();
2501 if (win.mAppToken != null) {
2502 win.mAppToken.updateReportedVisibilityLocked();
2503 }
2504 //dump();
2505 Binder.restoreCallingIdentity(origId);
2506 return;
2507 }
2508 }
2509
2510 removeWindowInnerLocked(session, win);
2511 // Removing a visible window will effect the computed orientation
2512 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002513 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002514 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002515 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002516 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 }
2518 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2519 Binder.restoreCallingIdentity(origId);
2520 }
Romain Guy06882f82009-06-10 13:36:04 -07002521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002523 if (win.mRemoved) {
2524 // Nothing to do.
2525 return;
2526 }
2527
2528 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2529 WindowState cwin = win.mChildWindows.get(i);
2530 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2531 + win);
2532 removeWindowInnerLocked(cwin.mSession, cwin);
2533 }
2534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 if (mInputMethodTarget == win) {
2538 moveInputMethodWindowsIfNeededLocked(false);
2539 }
Romain Guy06882f82009-06-10 13:36:04 -07002540
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002541 if (false) {
2542 RuntimeException e = new RuntimeException("here");
2543 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002544 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002545 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 mPolicy.removeWindowLw(win);
2548 win.removeLocked();
2549
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002550 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 mWindowMap.remove(win.mClient.asBinder());
2552 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002553 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002554 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002555 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556
2557 if (mInputMethodWindow == win) {
2558 mInputMethodWindow = null;
2559 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2560 mInputMethodDialogs.remove(win);
2561 }
Romain Guy06882f82009-06-10 13:36:04 -07002562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 final WindowToken token = win.mToken;
2564 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002565 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 token.windows.remove(win);
2567 if (atoken != null) {
2568 atoken.allAppWindows.remove(win);
2569 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002570 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 TAG, "**** Removing window " + win + ": count="
2572 + token.windows.size());
2573 if (token.windows.size() == 0) {
2574 if (!token.explicit) {
2575 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 } else if (atoken != null) {
2577 atoken.firstWindowDrawn = false;
2578 }
2579 }
2580
2581 if (atoken != null) {
2582 if (atoken.startingWindow == win) {
2583 atoken.startingWindow = null;
2584 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2585 // If this is the last window and we had requested a starting
2586 // transition window, well there is no point now.
2587 atoken.startingData = null;
2588 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2589 // If this is the last window except for a starting transition
2590 // window, we need to get rid of the starting transition.
2591 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002592 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 + ": no more real windows");
2594 }
2595 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2596 mH.sendMessage(m);
2597 }
2598 }
Romain Guy06882f82009-06-10 13:36:04 -07002599
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002600 if (win.mAttrs.type == TYPE_WALLPAPER) {
2601 mLastWallpaperTimeoutTime = 0;
2602 adjustWallpaperWindowsLocked();
2603 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002604 adjustWallpaperWindowsLocked();
2605 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 if (!mInLayout) {
2608 assignLayersLocked();
2609 mLayoutNeeded = true;
2610 performLayoutAndPlaceSurfacesLocked();
2611 if (win.mAppToken != null) {
2612 win.mAppToken.updateReportedVisibilityLocked();
2613 }
2614 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002615
2616 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 }
2618
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002619 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2620 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2621 + ": " + msg + " / " + w.mAttrs.getTitle();
2622 if (where != null) {
2623 Slog.i(TAG, str, where);
2624 } else {
2625 Slog.i(TAG, str);
2626 }
2627 }
2628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2630 long origId = Binder.clearCallingIdentity();
2631 try {
2632 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002633 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002634 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002635 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2636 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637 Surface.openTransaction();
2638 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002639 if (SHOW_TRANSACTIONS) logSurface(w,
2640 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 w.mSurface.setTransparentRegionHint(region);
2642 } finally {
2643 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002644 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2645 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 }
2647 }
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(origId);
2651 }
2652 }
2653
2654 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002655 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002656 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 long origId = Binder.clearCallingIdentity();
2658 try {
2659 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002660 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 if (w != null) {
2662 w.mGivenInsetsPending = false;
2663 w.mGivenContentInsets.set(contentInsets);
2664 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002665 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 w.mTouchableInsets = touchableInsets;
2667 mLayoutNeeded = true;
2668 performLayoutAndPlaceSurfacesLocked();
2669 }
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(origId);
2673 }
2674 }
Romain Guy06882f82009-06-10 13:36:04 -07002675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 public void getWindowDisplayFrame(Session session, IWindow client,
2677 Rect outDisplayFrame) {
2678 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002679 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002680 if (win == null) {
2681 outDisplayFrame.setEmpty();
2682 return;
2683 }
2684 outDisplayFrame.set(win.mDisplayFrame);
2685 }
2686 }
2687
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002688 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2689 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002690 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2691 window.mWallpaperX = x;
2692 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002693 window.mWallpaperXStep = xStep;
2694 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002695 if (updateWallpaperOffsetLocked(window, true)) {
2696 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002697 }
2698 }
2699 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002700
Dianne Hackborn75804932009-10-20 20:15:20 -07002701 void wallpaperCommandComplete(IBinder window, Bundle result) {
2702 synchronized (mWindowMap) {
2703 if (mWaitingOnWallpaper != null &&
2704 mWaitingOnWallpaper.mClient.asBinder() == window) {
2705 mWaitingOnWallpaper = null;
2706 mWindowMap.notifyAll();
2707 }
2708 }
2709 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002710
Dianne Hackborn75804932009-10-20 20:15:20 -07002711 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2712 String action, int x, int y, int z, Bundle extras, boolean sync) {
2713 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2714 || window == mUpperWallpaperTarget) {
2715 boolean doWait = sync;
2716 int curTokenIndex = mWallpaperTokens.size();
2717 while (curTokenIndex > 0) {
2718 curTokenIndex--;
2719 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2720 int curWallpaperIndex = token.windows.size();
2721 while (curWallpaperIndex > 0) {
2722 curWallpaperIndex--;
2723 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2724 try {
2725 wallpaper.mClient.dispatchWallpaperCommand(action,
2726 x, y, z, extras, sync);
2727 // We only want to be synchronous with one wallpaper.
2728 sync = false;
2729 } catch (RemoteException e) {
2730 }
2731 }
2732 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002733
Dianne Hackborn75804932009-10-20 20:15:20 -07002734 if (doWait) {
2735 // XXX Need to wait for result.
2736 }
2737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002738
Dianne Hackborn75804932009-10-20 20:15:20 -07002739 return null;
2740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 public int relayoutWindow(Session session, IWindow client,
2743 WindowManager.LayoutParams attrs, int requestedWidth,
2744 int requestedHeight, int viewVisibility, boolean insetsPending,
2745 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002746 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 boolean displayed = false;
2748 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002749 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002753 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 if (win == null) {
2755 return 0;
2756 }
2757 win.mRequestedWidth = requestedWidth;
2758 win.mRequestedHeight = requestedHeight;
2759
2760 if (attrs != null) {
2761 mPolicy.adjustWindowParamsLw(attrs);
2762 }
Romain Guy06882f82009-06-10 13:36:04 -07002763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002764 int attrChanges = 0;
2765 int flagChanges = 0;
2766 if (attrs != null) {
2767 flagChanges = win.mAttrs.flags ^= attrs.flags;
2768 attrChanges = win.mAttrs.copyFrom(attrs);
2769 }
2770
Joe Onorato8a9b2202010-02-26 18:56:32 -08002771 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002772
2773 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2774 win.mAlpha = attrs.alpha;
2775 }
2776
2777 final boolean scaledWindow =
2778 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2779
2780 if (scaledWindow) {
2781 // requested{Width|Height} Surface's physical size
2782 // attrs.{width|height} Size on screen
2783 win.mHScale = (attrs.width != requestedWidth) ?
2784 (attrs.width / (float)requestedWidth) : 1.0f;
2785 win.mVScale = (attrs.height != requestedHeight) ?
2786 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002787 } else {
2788 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 }
2790
2791 boolean imMayMove = (flagChanges&(
2792 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2793 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 boolean focusMayChange = win.mViewVisibility != viewVisibility
2796 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2797 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002798
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002799 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2800 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 win.mRelayoutCalled = true;
2803 final int oldVisibility = win.mViewVisibility;
2804 win.mViewVisibility = viewVisibility;
2805 if (viewVisibility == View.VISIBLE &&
2806 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2807 displayed = !win.isVisibleLw();
2808 if (win.mExiting) {
2809 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002810 if (win.mAnimation != null) {
2811 win.mAnimation.cancel();
2812 win.mAnimation = null;
2813 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 }
2815 if (win.mDestroying) {
2816 win.mDestroying = false;
2817 mDestroySurface.remove(win);
2818 }
2819 if (oldVisibility == View.GONE) {
2820 win.mEnterAnimationPending = true;
2821 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002822 if (displayed) {
2823 if (win.mSurface != null && !win.mDrawPending
2824 && !win.mCommitDrawPending && !mDisplayFrozen
2825 && mPolicy.isScreenOn()) {
2826 applyEnterAnimationLocked(win);
2827 }
2828 if ((win.mAttrs.flags
2829 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2830 if (DEBUG_VISIBILITY) Slog.v(TAG,
2831 "Relayout window turning screen on: " + win);
2832 win.mTurnOnScreen = true;
2833 }
2834 int diff = 0;
2835 if (win.mConfiguration != mCurConfiguration
2836 && (win.mConfiguration == null
2837 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2838 win.mConfiguration = mCurConfiguration;
2839 if (DEBUG_CONFIGURATION) {
2840 Slog.i(TAG, "Window " + win + " visible with new config: "
2841 + win.mConfiguration + " / 0x"
2842 + Integer.toHexString(diff));
2843 }
2844 outConfig.setTo(mCurConfiguration);
2845 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2848 // To change the format, we need to re-build the surface.
2849 win.destroySurfaceLocked();
2850 displayed = true;
2851 }
2852 try {
2853 Surface surface = win.createSurfaceLocked();
2854 if (surface != null) {
2855 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002856 win.mReportDestroySurface = false;
2857 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002858 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002859 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002861 // For some reason there isn't a surface. Clear the
2862 // caller's object so they see the same state.
2863 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 }
2865 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002866 mInputMonitor.updateInputWindowsLw();
2867
Joe Onorato8a9b2202010-02-26 18:56:32 -08002868 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002869 + client + " (" + win.mAttrs.getTitle() + ")",
2870 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 Binder.restoreCallingIdentity(origId);
2872 return 0;
2873 }
2874 if (displayed) {
2875 focusMayChange = true;
2876 }
2877 if (win.mAttrs.type == TYPE_INPUT_METHOD
2878 && mInputMethodWindow == null) {
2879 mInputMethodWindow = win;
2880 imMayMove = true;
2881 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002882 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2883 && win.mAppToken != null
2884 && win.mAppToken.startingWindow != null) {
2885 // Special handling of starting window over the base
2886 // window of the app: propagate lock screen flags to it,
2887 // to provide the correct semantics while starting.
2888 final int mask =
2889 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002890 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2891 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002892 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2893 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 } else {
2896 win.mEnterAnimationPending = false;
2897 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002898 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002899 + ": mExiting=" + win.mExiting
2900 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 // If we are not currently running the exit animation, we
2902 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002903 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 // Try starting an animation; if there isn't one, we
2905 // can destroy the surface right away.
2906 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2907 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2908 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2909 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002910 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002912 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 } else if (win.isAnimating()) {
2915 // Currently in a hide animation... turn this into
2916 // an exit.
2917 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002918 } else if (win == mWallpaperTarget) {
2919 // If the wallpaper is currently behind this
2920 // window, we need to change both of them inside
2921 // of a transaction to avoid artifacts.
2922 win.mExiting = true;
2923 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 } else {
2925 if (mInputMethodWindow == win) {
2926 mInputMethodWindow = null;
2927 }
2928 win.destroySurfaceLocked();
2929 }
2930 }
2931 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002932
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002933 if (win.mSurface == null || (win.getAttrs().flags
2934 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2935 || win.mSurfacePendingDestroy) {
2936 // We are being called from a local process, which
2937 // means outSurface holds its current surface. Ensure the
2938 // surface object is cleared, but we don't want it actually
2939 // destroyed at this point.
2940 win.mSurfacePendingDestroy = false;
2941 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002942 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002943 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002944 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002945 "Keeping surface, will report destroy: " + win);
2946 win.mReportDestroySurface = true;
2947 outSurface.copyFrom(win.mSurface);
2948 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 }
2950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 if (focusMayChange) {
2952 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2953 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 imMayMove = false;
2955 }
2956 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2957 }
Romain Guy06882f82009-06-10 13:36:04 -07002958
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002959 // updateFocusedWindowLocked() already assigned layers so we only need to
2960 // reassign them at this point if the IM window state gets shuffled
2961 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002964 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2965 // Little hack here -- we -should- be able to rely on the
2966 // function to return true if the IME has moved and needs
2967 // its layer recomputed. However, if the IME was hidden
2968 // and isn't actually moved in the list, its layer may be
2969 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002970 assignLayers = true;
2971 }
2972 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002973 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002974 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002975 assignLayers = true;
2976 }
2977 }
Romain Guy06882f82009-06-10 13:36:04 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 mLayoutNeeded = true;
2980 win.mGivenInsetsPending = insetsPending;
2981 if (assignLayers) {
2982 assignLayersLocked();
2983 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002984 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002986 if (displayed && win.mIsWallpaper) {
2987 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002988 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002989 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002990 if (win.mAppToken != null) {
2991 win.mAppToken.updateReportedVisibilityLocked();
2992 }
2993 outFrame.set(win.mFrame);
2994 outContentInsets.set(win.mContentInsets);
2995 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002996 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002998 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 + ", requestedHeight=" + requestedHeight
3000 + ", viewVisibility=" + viewVisibility
3001 + "\nRelayout returning frame=" + outFrame
3002 + ", surface=" + outSurface);
3003
Joe Onorato8a9b2202010-02-26 18:56:32 -08003004 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3006
3007 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003008
3009 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 }
3011
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003012 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 sendNewConfiguration();
3014 }
Romain Guy06882f82009-06-10 13:36:04 -07003015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3019 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3020 }
3021
3022 public void finishDrawingWindow(Session session, IWindow client) {
3023 final long origId = Binder.clearCallingIdentity();
3024 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003025 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003027 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3028 adjustWallpaperWindowsLocked();
3029 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 mLayoutNeeded = true;
3031 performLayoutAndPlaceSurfacesLocked();
3032 }
3033 }
3034 Binder.restoreCallingIdentity(origId);
3035 }
3036
3037 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003038 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 + (lp != null ? lp.packageName : null)
3040 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3041 if (lp != null && lp.windowAnimations != 0) {
3042 // If this is a system resource, don't try to load it from the
3043 // application resources. It is nice to avoid loading application
3044 // resources if we can.
3045 String packageName = lp.packageName != null ? lp.packageName : "android";
3046 int resId = lp.windowAnimations;
3047 if ((resId&0xFF000000) == 0x01000000) {
3048 packageName = "android";
3049 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003050 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051 + packageName);
3052 return AttributeCache.instance().get(packageName, resId,
3053 com.android.internal.R.styleable.WindowAnimation);
3054 }
3055 return null;
3056 }
Romain Guy06882f82009-06-10 13:36:04 -07003057
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003058 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003059 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003060 + packageName + " resId=0x" + Integer.toHexString(resId));
3061 if (packageName != null) {
3062 if ((resId&0xFF000000) == 0x01000000) {
3063 packageName = "android";
3064 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003065 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003066 + packageName);
3067 return AttributeCache.instance().get(packageName, resId,
3068 com.android.internal.R.styleable.WindowAnimation);
3069 }
3070 return null;
3071 }
3072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 private void applyEnterAnimationLocked(WindowState win) {
3074 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3075 if (win.mEnterAnimationPending) {
3076 win.mEnterAnimationPending = false;
3077 transit = WindowManagerPolicy.TRANSIT_ENTER;
3078 }
3079
3080 applyAnimationLocked(win, transit, true);
3081 }
3082
3083 private boolean applyAnimationLocked(WindowState win,
3084 int transit, boolean isEntrance) {
3085 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3086 // If we are trying to apply an animation, but already running
3087 // an animation of the same type, then just leave that one alone.
3088 return true;
3089 }
Romain Guy06882f82009-06-10 13:36:04 -07003090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003091 // Only apply an animation if the display isn't frozen. If it is
3092 // frozen, there is no reason to animate and it can cause strange
3093 // artifacts when we unfreeze the display if some different animation
3094 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003095 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003096 int anim = mPolicy.selectAnimationLw(win, transit);
3097 int attr = -1;
3098 Animation a = null;
3099 if (anim != 0) {
3100 a = AnimationUtils.loadAnimation(mContext, anim);
3101 } else {
3102 switch (transit) {
3103 case WindowManagerPolicy.TRANSIT_ENTER:
3104 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3105 break;
3106 case WindowManagerPolicy.TRANSIT_EXIT:
3107 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3108 break;
3109 case WindowManagerPolicy.TRANSIT_SHOW:
3110 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3111 break;
3112 case WindowManagerPolicy.TRANSIT_HIDE:
3113 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3114 break;
3115 }
3116 if (attr >= 0) {
3117 a = loadAnimation(win.mAttrs, attr);
3118 }
3119 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003120 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003121 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3122 + " mAnimation=" + win.mAnimation
3123 + " isEntrance=" + isEntrance);
3124 if (a != null) {
3125 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003126 RuntimeException e = null;
3127 if (!HIDE_STACK_CRAWLS) {
3128 e = new RuntimeException();
3129 e.fillInStackTrace();
3130 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003131 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003132 }
3133 win.setAnimation(a);
3134 win.mAnimationIsEntrance = isEntrance;
3135 }
3136 } else {
3137 win.clearAnimation();
3138 }
3139
3140 return win.mAnimation != null;
3141 }
3142
3143 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3144 int anim = 0;
3145 Context context = mContext;
3146 if (animAttr >= 0) {
3147 AttributeCache.Entry ent = getCachedAnimations(lp);
3148 if (ent != null) {
3149 context = ent.context;
3150 anim = ent.array.getResourceId(animAttr, 0);
3151 }
3152 }
3153 if (anim != 0) {
3154 return AnimationUtils.loadAnimation(context, anim);
3155 }
3156 return null;
3157 }
Romain Guy06882f82009-06-10 13:36:04 -07003158
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003159 private Animation loadAnimation(String packageName, int resId) {
3160 int anim = 0;
3161 Context context = mContext;
3162 if (resId >= 0) {
3163 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3164 if (ent != null) {
3165 context = ent.context;
3166 anim = resId;
3167 }
3168 }
3169 if (anim != 0) {
3170 return AnimationUtils.loadAnimation(context, anim);
3171 }
3172 return null;
3173 }
3174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175 private boolean applyAnimationLocked(AppWindowToken wtoken,
3176 WindowManager.LayoutParams lp, int transit, boolean enter) {
3177 // Only apply an animation if the display isn't frozen. If it is
3178 // frozen, there is no reason to animate and it can cause strange
3179 // artifacts when we unfreeze the display if some different animation
3180 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003181 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003182 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003183 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003184 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003185 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003186 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003187 } else if (mNextAppTransitionPackage != null) {
3188 a = loadAnimation(mNextAppTransitionPackage, enter ?
3189 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003190 } else {
3191 int animAttr = 0;
3192 switch (transit) {
3193 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3194 animAttr = enter
3195 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3196 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3197 break;
3198 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3199 animAttr = enter
3200 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3201 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3202 break;
3203 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3204 animAttr = enter
3205 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3206 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3207 break;
3208 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3209 animAttr = enter
3210 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3211 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3212 break;
3213 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3214 animAttr = enter
3215 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3216 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3217 break;
3218 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3219 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003220 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003221 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3222 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003223 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003224 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003225 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3226 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003227 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003228 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003229 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003230 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3231 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3232 break;
3233 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3234 animAttr = enter
3235 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3236 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3237 break;
3238 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3239 animAttr = enter
3240 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3241 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003242 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003243 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003244 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003245 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003246 + " anim=" + a
3247 + " animAttr=0x" + Integer.toHexString(animAttr)
3248 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003249 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 if (a != null) {
3251 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003252 RuntimeException e = null;
3253 if (!HIDE_STACK_CRAWLS) {
3254 e = new RuntimeException();
3255 e.fillInStackTrace();
3256 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003257 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 }
3259 wtoken.setAnimation(a);
3260 }
3261 } else {
3262 wtoken.clearAnimation();
3263 }
3264
3265 return wtoken.animation != null;
3266 }
3267
3268 // -------------------------------------------------------------
3269 // Application Window Tokens
3270 // -------------------------------------------------------------
3271
3272 public void validateAppTokens(List tokens) {
3273 int v = tokens.size()-1;
3274 int m = mAppTokens.size()-1;
3275 while (v >= 0 && m >= 0) {
3276 AppWindowToken wtoken = mAppTokens.get(m);
3277 if (wtoken.removed) {
3278 m--;
3279 continue;
3280 }
3281 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003282 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003283 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3284 }
3285 v--;
3286 m--;
3287 }
3288 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003289 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003290 v--;
3291 }
3292 while (m >= 0) {
3293 AppWindowToken wtoken = mAppTokens.get(m);
3294 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003295 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 }
3297 m--;
3298 }
3299 }
3300
3301 boolean checkCallingPermission(String permission, String func) {
3302 // Quick check: if the calling permission is me, it's all okay.
3303 if (Binder.getCallingPid() == Process.myPid()) {
3304 return true;
3305 }
Romain Guy06882f82009-06-10 13:36:04 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 if (mContext.checkCallingPermission(permission)
3308 == PackageManager.PERMISSION_GRANTED) {
3309 return true;
3310 }
3311 String msg = "Permission Denial: " + func + " from pid="
3312 + Binder.getCallingPid()
3313 + ", uid=" + Binder.getCallingUid()
3314 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003315 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 return false;
3317 }
Romain Guy06882f82009-06-10 13:36:04 -07003318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 AppWindowToken findAppWindowToken(IBinder token) {
3320 WindowToken wtoken = mTokenMap.get(token);
3321 if (wtoken == null) {
3322 return null;
3323 }
3324 return wtoken.appWindowToken;
3325 }
Romain Guy06882f82009-06-10 13:36:04 -07003326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 public void addWindowToken(IBinder token, int type) {
3328 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3329 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003330 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 }
Romain Guy06882f82009-06-10 13:36:04 -07003332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 synchronized(mWindowMap) {
3334 WindowToken wtoken = mTokenMap.get(token);
3335 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003336 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 return;
3338 }
3339 wtoken = new WindowToken(token, type, true);
3340 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003341 if (type == TYPE_WALLPAPER) {
3342 mWallpaperTokens.add(wtoken);
3343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 }
3345 }
Romain Guy06882f82009-06-10 13:36:04 -07003346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 public void removeWindowToken(IBinder token) {
3348 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3349 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003350 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003351 }
3352
3353 final long origId = Binder.clearCallingIdentity();
3354 synchronized(mWindowMap) {
3355 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 if (wtoken != null) {
3357 boolean delayed = false;
3358 if (!wtoken.hidden) {
3359 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003361 final int N = wtoken.windows.size();
3362 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 for (int i=0; i<N; i++) {
3365 WindowState win = wtoken.windows.get(i);
3366
3367 if (win.isAnimating()) {
3368 delayed = true;
3369 }
Romain Guy06882f82009-06-10 13:36:04 -07003370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 if (win.isVisibleNow()) {
3372 applyAnimationLocked(win,
3373 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 changed = true;
3375 }
3376 }
3377
3378 if (changed) {
3379 mLayoutNeeded = true;
3380 performLayoutAndPlaceSurfacesLocked();
3381 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3382 }
Romain Guy06882f82009-06-10 13:36:04 -07003383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 if (delayed) {
3385 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003386 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3387 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003388 }
3389 }
Romain Guy06882f82009-06-10 13:36:04 -07003390
Jeff Brownc5ed5912010-07-14 18:48:53 -07003391 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003393 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003394 }
3395 }
3396 Binder.restoreCallingIdentity(origId);
3397 }
3398
3399 public void addAppToken(int addPos, IApplicationToken token,
3400 int groupId, int requestedOrientation, boolean fullscreen) {
3401 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3402 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003403 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 }
Jeff Brown349703e2010-06-22 01:27:15 -07003405
3406 // Get the dispatching timeout here while we are not holding any locks so that it
3407 // can be cached by the AppWindowToken. The timeout value is used later by the
3408 // input dispatcher in code that does hold locks. If we did not cache the value
3409 // here we would run the chance of introducing a deadlock between the window manager
3410 // (which holds locks while updating the input dispatcher state) and the activity manager
3411 // (which holds locks while querying the application token).
3412 long inputDispatchingTimeoutNanos;
3413 try {
3414 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3415 } catch (RemoteException ex) {
3416 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3417 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3418 }
Romain Guy06882f82009-06-10 13:36:04 -07003419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 synchronized(mWindowMap) {
3421 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3422 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003423 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 return;
3425 }
3426 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003427 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 wtoken.groupId = groupId;
3429 wtoken.appFullscreen = fullscreen;
3430 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003431 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003432 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 // Application tokens start out hidden.
3436 wtoken.hidden = true;
3437 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 //dump();
3440 }
3441 }
Romain Guy06882f82009-06-10 13:36:04 -07003442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443 public void setAppGroupId(IBinder token, int groupId) {
3444 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3445 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003446 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 }
3448
3449 synchronized(mWindowMap) {
3450 AppWindowToken wtoken = findAppWindowToken(token);
3451 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003452 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003453 return;
3454 }
3455 wtoken.groupId = groupId;
3456 }
3457 }
Romain Guy06882f82009-06-10 13:36:04 -07003458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003459 public int getOrientationFromWindowsLocked() {
3460 int pos = mWindows.size() - 1;
3461 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003462 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 pos--;
3464 if (wtoken.mAppToken != null) {
3465 // We hit an application window. so the orientation will be determined by the
3466 // app window. No point in continuing further.
3467 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3468 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003469 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 continue;
3471 }
3472 int req = wtoken.mAttrs.screenOrientation;
3473 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3474 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3475 continue;
3476 } else {
3477 return req;
3478 }
3479 }
3480 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3481 }
Romain Guy06882f82009-06-10 13:36:04 -07003482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003484 int pos = mAppTokens.size() - 1;
3485 int curGroup = 0;
3486 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3487 boolean findingBehind = false;
3488 boolean haveGroup = false;
3489 boolean lastFullscreen = false;
3490 while (pos >= 0) {
3491 AppWindowToken wtoken = mAppTokens.get(pos);
3492 pos--;
3493 // if we're about to tear down this window and not seek for
3494 // the behind activity, don't use it for orientation
3495 if (!findingBehind
3496 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3497 continue;
3498 }
3499
3500 if (!haveGroup) {
3501 // We ignore any hidden applications on the top.
3502 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003503 continue;
3504 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003505 haveGroup = true;
3506 curGroup = wtoken.groupId;
3507 lastOrientation = wtoken.requestedOrientation;
3508 } else if (curGroup != wtoken.groupId) {
3509 // If we have hit a new application group, and the bottom
3510 // of the previous group didn't explicitly say to use
3511 // the orientation behind it, and the last app was
3512 // full screen, then we'll stick with the
3513 // user's orientation.
3514 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3515 && lastFullscreen) {
3516 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003519 int or = wtoken.requestedOrientation;
3520 // If this application is fullscreen, and didn't explicitly say
3521 // to use the orientation behind it, then just take whatever
3522 // orientation it has and ignores whatever is under it.
3523 lastFullscreen = wtoken.appFullscreen;
3524 if (lastFullscreen
3525 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3526 return or;
3527 }
3528 // If this application has requested an explicit orientation,
3529 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003530 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3531 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003532 return or;
3533 }
3534 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3535 }
3536 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 }
Romain Guy06882f82009-06-10 13:36:04 -07003538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003540 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003541 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3542 "updateOrientationFromAppTokens()")) {
3543 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3544 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003545
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003546 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003548
3549 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003550 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003551 if (freezeThisOneIfNeeded != null) {
3552 AppWindowToken wtoken = findAppWindowToken(
3553 freezeThisOneIfNeeded);
3554 if (wtoken != null) {
3555 startAppFreezingScreenLocked(wtoken,
3556 ActivityInfo.CONFIG_ORIENTATION);
3557 }
3558 }
3559 config = computeNewConfigurationLocked();
3560
3561 } else if (currentConfig != null) {
3562 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003563 // state mismatches the activity manager's, update it,
3564 // disregarding font scale, which should remain set to
3565 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003566 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003567 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003568 if (computeNewConfigurationLocked(mTempConfiguration)) {
3569 if (currentConfig.diff(mTempConfiguration) != 0) {
3570 mWaitingForConfig = true;
3571 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003572 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003573 config = new Configuration(mTempConfiguration);
3574 }
3575 }
3576 }
3577 }
3578
Dianne Hackborncfaef692009-06-15 14:24:44 -07003579 Binder.restoreCallingIdentity(ident);
3580 return config;
3581 }
3582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003584 * Determine the new desired orientation of the display, returning
3585 * a non-null new Configuration if it has changed from the current
3586 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3587 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3588 * SCREEN. This will typically be done for you if you call
3589 * sendNewConfiguration().
3590 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 * The orientation is computed from non-application windows first. If none of
3592 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003593 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003594 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3595 * android.os.IBinder)
3596 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003597 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3598 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003599 // If the display is frozen, some activities may be in the middle
3600 // of restarting, and thus have removed their old window. If the
3601 // window has the flag to hide the lock screen, then the lock screen
3602 // can re-appear and inflict its own orientation on us. Keep the
3603 // orientation stable until this all settles down.
3604 return false;
3605 }
3606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 long ident = Binder.clearCallingIdentity();
3609 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003610 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 mForcedAppOrientation = req;
3614 //send a message to Policy indicating orientation change to take
3615 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003616 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003617 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003618 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3619 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003620 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 }
3622 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003623
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003624 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 } finally {
3626 Binder.restoreCallingIdentity(ident);
3627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 }
Romain Guy06882f82009-06-10 13:36:04 -07003629
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003630 int computeForcedAppOrientationLocked() {
3631 int req = getOrientationFromWindowsLocked();
3632 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3633 req = getOrientationFromAppTokensLocked();
3634 }
3635 return req;
3636 }
Romain Guy06882f82009-06-10 13:36:04 -07003637
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003638 public void setNewConfiguration(Configuration config) {
3639 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3640 "setNewConfiguration()")) {
3641 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3642 }
3643
3644 synchronized(mWindowMap) {
3645 mCurConfiguration = new Configuration(config);
3646 mWaitingForConfig = false;
3647 performLayoutAndPlaceSurfacesLocked();
3648 }
3649 }
3650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3652 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3653 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003654 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 }
Romain Guy06882f82009-06-10 13:36:04 -07003656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 synchronized(mWindowMap) {
3658 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3659 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003660 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 return;
3662 }
Romain Guy06882f82009-06-10 13:36:04 -07003663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 wtoken.requestedOrientation = requestedOrientation;
3665 }
3666 }
Romain Guy06882f82009-06-10 13:36:04 -07003667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 public int getAppOrientation(IApplicationToken token) {
3669 synchronized(mWindowMap) {
3670 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3671 if (wtoken == null) {
3672 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3673 }
Romain Guy06882f82009-06-10 13:36:04 -07003674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 return wtoken.requestedOrientation;
3676 }
3677 }
Romain Guy06882f82009-06-10 13:36:04 -07003678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3680 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3681 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003682 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 }
3684
3685 synchronized(mWindowMap) {
3686 boolean changed = false;
3687 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003688 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003689 changed = mFocusedApp != null;
3690 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003691 if (changed) {
3692 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003693 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 } else {
3695 AppWindowToken newFocus = findAppWindowToken(token);
3696 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003697 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 return;
3699 }
3700 changed = mFocusedApp != newFocus;
3701 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003702 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003703 if (changed) {
3704 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003705 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 }
3707
3708 if (moveFocusNow && changed) {
3709 final long origId = Binder.clearCallingIdentity();
3710 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3711 Binder.restoreCallingIdentity(origId);
3712 }
3713 }
3714 }
3715
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003716 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3718 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003719 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 }
Romain Guy06882f82009-06-10 13:36:04 -07003721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003723 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 TAG, "Prepare app transition: transit=" + transit
3725 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003726 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003727 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3728 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003730 } else if (!alwaysKeepCurrent) {
3731 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3732 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3733 // Opening a new task always supersedes a close for the anim.
3734 mNextAppTransition = transit;
3735 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3736 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3737 // Opening a new activity always supersedes a close for the anim.
3738 mNextAppTransition = transit;
3739 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 }
3741 mAppTransitionReady = false;
3742 mAppTransitionTimeout = false;
3743 mStartingIconInTransition = false;
3744 mSkipAppTransitionAnimation = false;
3745 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3746 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3747 5000);
3748 }
3749 }
3750 }
3751
3752 public int getPendingAppTransition() {
3753 return mNextAppTransition;
3754 }
Romain Guy06882f82009-06-10 13:36:04 -07003755
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003756 public void overridePendingAppTransition(String packageName,
3757 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003758 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003759 mNextAppTransitionPackage = packageName;
3760 mNextAppTransitionEnter = enterAnim;
3761 mNextAppTransitionExit = exitAnim;
3762 }
3763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003765 public void executeAppTransition() {
3766 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3767 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003768 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003769 }
Romain Guy06882f82009-06-10 13:36:04 -07003770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003772 if (DEBUG_APP_TRANSITIONS) {
3773 RuntimeException e = new RuntimeException("here");
3774 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003775 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003776 + mNextAppTransition, e);
3777 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003778 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 mAppTransitionReady = true;
3780 final long origId = Binder.clearCallingIdentity();
3781 performLayoutAndPlaceSurfacesLocked();
3782 Binder.restoreCallingIdentity(origId);
3783 }
3784 }
3785 }
3786
3787 public void setAppStartingWindow(IBinder token, String pkg,
3788 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003789 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3791 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003792 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 }
3794
3795 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003796 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3798 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 AppWindowToken wtoken = findAppWindowToken(token);
3801 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003802 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 return;
3804 }
3805
3806 // If the display is frozen, we won't do anything until the
3807 // actual window is displayed so there is no reason to put in
3808 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003809 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 return;
3811 }
Romain Guy06882f82009-06-10 13:36:04 -07003812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 if (wtoken.startingData != null) {
3814 return;
3815 }
Romain Guy06882f82009-06-10 13:36:04 -07003816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003817 if (transferFrom != null) {
3818 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3819 if (ttoken != null) {
3820 WindowState startingWindow = ttoken.startingWindow;
3821 if (startingWindow != null) {
3822 if (mStartingIconInTransition) {
3823 // In this case, the starting icon has already
3824 // been displayed, so start letting windows get
3825 // shown immediately without any more transitions.
3826 mSkipAppTransitionAnimation = true;
3827 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003828 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 "Moving existing starting from " + ttoken
3830 + " to " + wtoken);
3831 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 // Transfer the starting window over to the new
3834 // token.
3835 wtoken.startingData = ttoken.startingData;
3836 wtoken.startingView = ttoken.startingView;
3837 wtoken.startingWindow = startingWindow;
3838 ttoken.startingData = null;
3839 ttoken.startingView = null;
3840 ttoken.startingWindow = null;
3841 ttoken.startingMoved = true;
3842 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003843 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003845 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003846 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003848 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003849 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3850 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 ttoken.windows.remove(startingWindow);
3852 ttoken.allAppWindows.remove(startingWindow);
3853 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 // Propagate other interesting state between the
3856 // tokens. If the old token is displayed, we should
3857 // immediately force the new one to be displayed. If
3858 // it is animating, we need to move that animation to
3859 // the new one.
3860 if (ttoken.allDrawn) {
3861 wtoken.allDrawn = true;
3862 }
3863 if (ttoken.firstWindowDrawn) {
3864 wtoken.firstWindowDrawn = true;
3865 }
3866 if (!ttoken.hidden) {
3867 wtoken.hidden = false;
3868 wtoken.hiddenRequested = false;
3869 wtoken.willBeHidden = false;
3870 }
3871 if (wtoken.clientHidden != ttoken.clientHidden) {
3872 wtoken.clientHidden = ttoken.clientHidden;
3873 wtoken.sendAppVisibilityToClients();
3874 }
3875 if (ttoken.animation != null) {
3876 wtoken.animation = ttoken.animation;
3877 wtoken.animating = ttoken.animating;
3878 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3879 ttoken.animation = null;
3880 ttoken.animLayerAdjustment = 0;
3881 wtoken.updateLayers();
3882 ttoken.updateLayers();
3883 }
Romain Guy06882f82009-06-10 13:36:04 -07003884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 mLayoutNeeded = true;
3887 performLayoutAndPlaceSurfacesLocked();
3888 Binder.restoreCallingIdentity(origId);
3889 return;
3890 } else if (ttoken.startingData != null) {
3891 // The previous app was getting ready to show a
3892 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003893 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 "Moving pending starting from " + ttoken
3895 + " to " + wtoken);
3896 wtoken.startingData = ttoken.startingData;
3897 ttoken.startingData = null;
3898 ttoken.startingMoved = true;
3899 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3900 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3901 // want to process the message ASAP, before any other queued
3902 // messages.
3903 mH.sendMessageAtFrontOfQueue(m);
3904 return;
3905 }
3906 }
3907 }
3908
3909 // There is no existing starting window, and the caller doesn't
3910 // want us to create one, so that's it!
3911 if (!createIfNeeded) {
3912 return;
3913 }
Romain Guy06882f82009-06-10 13:36:04 -07003914
Dianne Hackborn284ac932009-08-28 10:34:25 -07003915 // If this is a translucent or wallpaper window, then don't
3916 // show a starting window -- the current effect (a full-screen
3917 // opaque starting window that fades away to the real contents
3918 // when it is ready) does not work for this.
3919 if (theme != 0) {
3920 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3921 com.android.internal.R.styleable.Window);
3922 if (ent.array.getBoolean(
3923 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3924 return;
3925 }
3926 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003927 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3928 return;
3929 }
3930 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003931 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3932 return;
3933 }
3934 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003936 mStartingIconInTransition = true;
3937 wtoken.startingData = new StartingData(
3938 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003939 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3941 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3942 // want to process the message ASAP, before any other queued
3943 // messages.
3944 mH.sendMessageAtFrontOfQueue(m);
3945 }
3946 }
3947
3948 public void setAppWillBeHidden(IBinder token) {
3949 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3950 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003951 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 }
3953
3954 AppWindowToken wtoken;
3955
3956 synchronized(mWindowMap) {
3957 wtoken = findAppWindowToken(token);
3958 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003959 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 -08003960 return;
3961 }
3962 wtoken.willBeHidden = true;
3963 }
3964 }
Romain Guy06882f82009-06-10 13:36:04 -07003965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3967 boolean visible, int transit, boolean performLayout) {
3968 boolean delayed = false;
3969
3970 if (wtoken.clientHidden == visible) {
3971 wtoken.clientHidden = !visible;
3972 wtoken.sendAppVisibilityToClients();
3973 }
Romain Guy06882f82009-06-10 13:36:04 -07003974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 wtoken.willBeHidden = false;
3976 if (wtoken.hidden == visible) {
3977 final int N = wtoken.allAppWindows.size();
3978 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003979 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3981 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003984
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003985 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 if (wtoken.animation == sDummyAnimation) {
3987 wtoken.animation = null;
3988 }
3989 applyAnimationLocked(wtoken, lp, transit, visible);
3990 changed = true;
3991 if (wtoken.animation != null) {
3992 delayed = runningAppAnimation = true;
3993 }
3994 }
Romain Guy06882f82009-06-10 13:36:04 -07003995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 for (int i=0; i<N; i++) {
3997 WindowState win = wtoken.allAppWindows.get(i);
3998 if (win == wtoken.startingWindow) {
3999 continue;
4000 }
4001
4002 if (win.isAnimating()) {
4003 delayed = true;
4004 }
Romain Guy06882f82009-06-10 13:36:04 -07004005
Joe Onorato8a9b2202010-02-26 18:56:32 -08004006 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 //win.dump(" ");
4008 if (visible) {
4009 if (!win.isVisibleNow()) {
4010 if (!runningAppAnimation) {
4011 applyAnimationLocked(win,
4012 WindowManagerPolicy.TRANSIT_ENTER, true);
4013 }
4014 changed = true;
4015 }
4016 } else if (win.isVisibleNow()) {
4017 if (!runningAppAnimation) {
4018 applyAnimationLocked(win,
4019 WindowManagerPolicy.TRANSIT_EXIT, false);
4020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004021 changed = true;
4022 }
4023 }
4024
4025 wtoken.hidden = wtoken.hiddenRequested = !visible;
4026 if (!visible) {
4027 unsetAppFreezingScreenLocked(wtoken, true, true);
4028 } else {
4029 // If we are being set visible, and the starting window is
4030 // not yet displayed, then make sure it doesn't get displayed.
4031 WindowState swin = wtoken.startingWindow;
4032 if (swin != null && (swin.mDrawPending
4033 || swin.mCommitDrawPending)) {
4034 swin.mPolicyVisibility = false;
4035 swin.mPolicyVisibilityAfterAnim = false;
4036 }
4037 }
Romain Guy06882f82009-06-10 13:36:04 -07004038
Joe Onorato8a9b2202010-02-26 18:56:32 -08004039 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4041 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004042
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004043 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004044 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004045 if (performLayout) {
4046 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
4047 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07004048 } else {
4049 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004050 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004051 }
4052 }
4053
4054 if (wtoken.animation != null) {
4055 delayed = true;
4056 }
Romain Guy06882f82009-06-10 13:36:04 -07004057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004058 return delayed;
4059 }
4060
4061 public void setAppVisibility(IBinder token, boolean visible) {
4062 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4063 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004064 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004065 }
4066
4067 AppWindowToken wtoken;
4068
4069 synchronized(mWindowMap) {
4070 wtoken = findAppWindowToken(token);
4071 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004072 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004073 return;
4074 }
4075
4076 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004077 RuntimeException e = null;
4078 if (!HIDE_STACK_CRAWLS) {
4079 e = new RuntimeException();
4080 e.fillInStackTrace();
4081 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004082 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 + "): mNextAppTransition=" + mNextAppTransition
4084 + " hidden=" + wtoken.hidden
4085 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4086 }
Romain Guy06882f82009-06-10 13:36:04 -07004087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 // If we are preparing an app transition, then delay changing
4089 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004090 if (!mDisplayFrozen && mPolicy.isScreenOn()
4091 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 // Already in requested state, don't do anything more.
4093 if (wtoken.hiddenRequested != visible) {
4094 return;
4095 }
4096 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004097
Joe Onorato8a9b2202010-02-26 18:56:32 -08004098 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 TAG, "Setting dummy animation on: " + wtoken);
4100 wtoken.setDummyAnimation();
4101 mOpeningApps.remove(wtoken);
4102 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004103 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004104 wtoken.inPendingTransaction = true;
4105 if (visible) {
4106 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004107 wtoken.startingDisplayed = false;
4108 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004109
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004110 // If the token is currently hidden (should be the
4111 // common case), then we need to set up to wait for
4112 // its windows to be ready.
4113 if (wtoken.hidden) {
4114 wtoken.allDrawn = false;
4115 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004116
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004117 if (wtoken.clientHidden) {
4118 // In the case where we are making an app visible
4119 // but holding off for a transition, we still need
4120 // to tell the client to make its windows visible so
4121 // they get drawn. Otherwise, we will wait on
4122 // performing the transition until all windows have
4123 // been drawn, they never will be, and we are sad.
4124 wtoken.clientHidden = false;
4125 wtoken.sendAppVisibilityToClients();
4126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 }
4128 } else {
4129 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004130
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004131 // If the token is currently visible (should be the
4132 // common case), then set up to wait for it to be hidden.
4133 if (!wtoken.hidden) {
4134 wtoken.waitingToHide = true;
4135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 }
4137 return;
4138 }
Romain Guy06882f82009-06-10 13:36:04 -07004139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004141 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004142 wtoken.updateReportedVisibilityLocked();
4143 Binder.restoreCallingIdentity(origId);
4144 }
4145 }
4146
4147 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4148 boolean unfreezeSurfaceNow, boolean force) {
4149 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004150 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 + " force=" + force);
4152 final int N = wtoken.allAppWindows.size();
4153 boolean unfrozeWindows = false;
4154 for (int i=0; i<N; i++) {
4155 WindowState w = wtoken.allAppWindows.get(i);
4156 if (w.mAppFreezing) {
4157 w.mAppFreezing = false;
4158 if (w.mSurface != null && !w.mOrientationChanging) {
4159 w.mOrientationChanging = true;
4160 }
4161 unfrozeWindows = true;
4162 }
4163 }
4164 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004165 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 wtoken.freezingScreen = false;
4167 mAppsFreezingScreen--;
4168 }
4169 if (unfreezeSurfaceNow) {
4170 if (unfrozeWindows) {
4171 mLayoutNeeded = true;
4172 performLayoutAndPlaceSurfacesLocked();
4173 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004174 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 }
4176 }
4177 }
Romain Guy06882f82009-06-10 13:36:04 -07004178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4180 int configChanges) {
4181 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004182 RuntimeException e = null;
4183 if (!HIDE_STACK_CRAWLS) {
4184 e = new RuntimeException();
4185 e.fillInStackTrace();
4186 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004187 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 + ": hidden=" + wtoken.hidden + " freezing="
4189 + wtoken.freezingScreen, e);
4190 }
4191 if (!wtoken.hiddenRequested) {
4192 if (!wtoken.freezingScreen) {
4193 wtoken.freezingScreen = true;
4194 mAppsFreezingScreen++;
4195 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004196 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4198 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4199 5000);
4200 }
4201 }
4202 final int N = wtoken.allAppWindows.size();
4203 for (int i=0; i<N; i++) {
4204 WindowState w = wtoken.allAppWindows.get(i);
4205 w.mAppFreezing = true;
4206 }
4207 }
4208 }
Romain Guy06882f82009-06-10 13:36:04 -07004209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 public void startAppFreezingScreen(IBinder token, int configChanges) {
4211 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4212 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004213 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004214 }
4215
4216 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004217 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004218 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 return;
4220 }
Romain Guy06882f82009-06-10 13:36:04 -07004221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 AppWindowToken wtoken = findAppWindowToken(token);
4223 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004224 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 return;
4226 }
4227 final long origId = Binder.clearCallingIdentity();
4228 startAppFreezingScreenLocked(wtoken, configChanges);
4229 Binder.restoreCallingIdentity(origId);
4230 }
4231 }
Romain Guy06882f82009-06-10 13:36:04 -07004232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004233 public void stopAppFreezingScreen(IBinder token, boolean force) {
4234 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4235 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004236 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004237 }
4238
4239 synchronized(mWindowMap) {
4240 AppWindowToken wtoken = findAppWindowToken(token);
4241 if (wtoken == null || wtoken.appToken == null) {
4242 return;
4243 }
4244 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004245 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4247 unsetAppFreezingScreenLocked(wtoken, true, force);
4248 Binder.restoreCallingIdentity(origId);
4249 }
4250 }
Romain Guy06882f82009-06-10 13:36:04 -07004251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 public void removeAppToken(IBinder token) {
4253 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4254 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004255 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004256 }
4257
4258 AppWindowToken wtoken = null;
4259 AppWindowToken startingToken = null;
4260 boolean delayed = false;
4261
4262 final long origId = Binder.clearCallingIdentity();
4263 synchronized(mWindowMap) {
4264 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004266 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004267 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 wtoken.inPendingTransaction = false;
4269 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004270 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 if (mClosingApps.contains(wtoken)) {
4272 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004273 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004274 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004275 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 delayed = true;
4277 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004278 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 TAG, "Removing app " + wtoken + " delayed=" + delayed
4280 + " animation=" + wtoken.animation
4281 + " animating=" + wtoken.animating);
4282 if (delayed) {
4283 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004284 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4285 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004287 } else {
4288 // Make sure there is no animation running on this token,
4289 // so any windows associated with it will be removed as
4290 // soon as their animations are complete
4291 wtoken.animation = null;
4292 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004294 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4295 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 mAppTokens.remove(wtoken);
4297 wtoken.removed = true;
4298 if (wtoken.startingData != null) {
4299 startingToken = wtoken;
4300 }
4301 unsetAppFreezingScreenLocked(wtoken, true, true);
4302 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004303 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 mFocusedApp = null;
4305 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004306 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 }
4308 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004309 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 }
Romain Guy06882f82009-06-10 13:36:04 -07004311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 if (!delayed && wtoken != null) {
4313 wtoken.updateReportedVisibilityLocked();
4314 }
4315 }
4316 Binder.restoreCallingIdentity(origId);
4317
4318 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004319 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 + startingToken + ": app token removed");
4321 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4322 mH.sendMessage(m);
4323 }
4324 }
4325
4326 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4327 final int NW = token.windows.size();
4328 for (int i=0; i<NW; i++) {
4329 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004330 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004332 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 int j = win.mChildWindows.size();
4334 while (j > 0) {
4335 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004336 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004337 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004338 "Tmp removing child window " + cwin);
4339 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004340 }
4341 }
4342 return NW > 0;
4343 }
4344
4345 void dumpAppTokensLocked() {
4346 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004347 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004348 }
4349 }
Romain Guy06882f82009-06-10 13:36:04 -07004350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 void dumpWindowsLocked() {
4352 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004353 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 }
4355 }
Romain Guy06882f82009-06-10 13:36:04 -07004356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 private int findWindowOffsetLocked(int tokenPos) {
4358 final int NW = mWindows.size();
4359
4360 if (tokenPos >= mAppTokens.size()) {
4361 int i = NW;
4362 while (i > 0) {
4363 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004364 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 if (win.getAppToken() != null) {
4366 return i+1;
4367 }
4368 }
4369 }
4370
4371 while (tokenPos > 0) {
4372 // Find the first app token below the new position that has
4373 // a window displayed.
4374 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004375 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004377 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004378 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004379 "Skipping token -- currently sending to bottom");
4380 tokenPos--;
4381 continue;
4382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 int i = wtoken.windows.size();
4384 while (i > 0) {
4385 i--;
4386 WindowState win = wtoken.windows.get(i);
4387 int j = win.mChildWindows.size();
4388 while (j > 0) {
4389 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004390 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004391 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004392 for (int pos=NW-1; pos>=0; pos--) {
4393 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004394 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 "Found child win @" + (pos+1));
4396 return pos+1;
4397 }
4398 }
4399 }
4400 }
4401 for (int pos=NW-1; pos>=0; pos--) {
4402 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004403 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404 return pos+1;
4405 }
4406 }
4407 }
4408 tokenPos--;
4409 }
4410
4411 return 0;
4412 }
4413
4414 private final int reAddWindowLocked(int index, WindowState win) {
4415 final int NCW = win.mChildWindows.size();
4416 boolean added = false;
4417 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004418 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004419 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004420 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004421 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004422 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 mWindows.add(index, win);
4424 index++;
4425 added = true;
4426 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004427 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004428 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004429 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004430 mWindows.add(index, cwin);
4431 index++;
4432 }
4433 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004434 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004435 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004436 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 mWindows.add(index, win);
4438 index++;
4439 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004440 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 return index;
4442 }
Romain Guy06882f82009-06-10 13:36:04 -07004443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4445 final int NW = token.windows.size();
4446 for (int i=0; i<NW; i++) {
4447 index = reAddWindowLocked(index, token.windows.get(i));
4448 }
4449 return index;
4450 }
4451
4452 public void moveAppToken(int index, IBinder token) {
4453 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4454 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004455 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
4457
4458 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004459 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004460 if (DEBUG_REORDER) dumpAppTokensLocked();
4461 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004462 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4463 "Start moving token " + wtoken + " initially at "
4464 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004465 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004466 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 + token + " (" + wtoken + ")");
4468 return;
4469 }
4470 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004471 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004472 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004476 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 if (DEBUG_REORDER) dumpWindowsLocked();
4478 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004479 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 if (DEBUG_REORDER) dumpWindowsLocked();
4481 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004482 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 if (DEBUG_REORDER) dumpWindowsLocked();
4484 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 mLayoutNeeded = true;
4486 performLayoutAndPlaceSurfacesLocked();
4487 }
4488 Binder.restoreCallingIdentity(origId);
4489 }
4490 }
4491
4492 private void removeAppTokensLocked(List<IBinder> tokens) {
4493 // XXX This should be done more efficiently!
4494 // (take advantage of the fact that both lists should be
4495 // ordered in the same way.)
4496 int N = tokens.size();
4497 for (int i=0; i<N; i++) {
4498 IBinder token = tokens.get(i);
4499 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004500 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4501 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004503 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004504 + token + " (" + wtoken + ")");
4505 i--;
4506 N--;
4507 }
4508 }
4509 }
4510
Dianne Hackborna8f60182009-09-01 19:01:50 -07004511 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4512 boolean updateFocusAndLayout) {
4513 // First remove all of the windows from the list.
4514 tmpRemoveAppWindowsLocked(wtoken);
4515
4516 // Where to start adding?
4517 int pos = findWindowOffsetLocked(tokenPos);
4518
4519 // And now add them back at the correct place.
4520 pos = reAddAppWindowsLocked(pos, wtoken);
4521
4522 if (updateFocusAndLayout) {
4523 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4524 assignLayersLocked();
4525 }
4526 mLayoutNeeded = true;
4527 performLayoutAndPlaceSurfacesLocked();
4528 }
4529 }
4530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4532 // First remove all of the windows from the list.
4533 final int N = tokens.size();
4534 int i;
4535 for (i=0; i<N; i++) {
4536 WindowToken token = mTokenMap.get(tokens.get(i));
4537 if (token != null) {
4538 tmpRemoveAppWindowsLocked(token);
4539 }
4540 }
4541
4542 // Where to start adding?
4543 int pos = findWindowOffsetLocked(tokenPos);
4544
4545 // And now add them back at the correct place.
4546 for (i=0; i<N; i++) {
4547 WindowToken token = mTokenMap.get(tokens.get(i));
4548 if (token != null) {
4549 pos = reAddAppWindowsLocked(pos, token);
4550 }
4551 }
4552
Dianne Hackborna8f60182009-09-01 19:01:50 -07004553 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4554 assignLayersLocked();
4555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004556 mLayoutNeeded = true;
4557 performLayoutAndPlaceSurfacesLocked();
4558
4559 //dump();
4560 }
4561
4562 public void moveAppTokensToTop(List<IBinder> tokens) {
4563 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4564 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004565 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004566 }
4567
4568 final long origId = Binder.clearCallingIdentity();
4569 synchronized(mWindowMap) {
4570 removeAppTokensLocked(tokens);
4571 final int N = tokens.size();
4572 for (int i=0; i<N; i++) {
4573 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4574 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004575 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4576 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004577 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004578 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004579 mToTopApps.remove(wt);
4580 mToBottomApps.remove(wt);
4581 mToTopApps.add(wt);
4582 wt.sendingToBottom = false;
4583 wt.sendingToTop = true;
4584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004585 }
4586 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004587
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004588 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004589 moveAppWindowsLocked(tokens, mAppTokens.size());
4590 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004591 }
4592 Binder.restoreCallingIdentity(origId);
4593 }
4594
4595 public void moveAppTokensToBottom(List<IBinder> tokens) {
4596 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4597 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004598 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004599 }
4600
4601 final long origId = Binder.clearCallingIdentity();
4602 synchronized(mWindowMap) {
4603 removeAppTokensLocked(tokens);
4604 final int N = tokens.size();
4605 int pos = 0;
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) Slog.v(TAG,
4610 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004611 mAppTokens.add(pos, 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 mToBottomApps.add(i, wt);
4616 wt.sendingToTop = false;
4617 wt.sendingToBottom = true;
4618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004619 pos++;
4620 }
4621 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004622
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004623 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004624 moveAppWindowsLocked(tokens, 0);
4625 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004626 }
4627 Binder.restoreCallingIdentity(origId);
4628 }
4629
4630 // -------------------------------------------------------------
4631 // Misc IWindowSession methods
4632 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004633
Jim Miller284b62e2010-06-08 14:27:42 -07004634 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004635 {
Jim Miller284b62e2010-06-08 14:27:42 -07004636 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4637 // called before DevicePolicyManagerService has started.
4638 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4639 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4640 Context.DEVICE_POLICY_SERVICE);
4641 if (dpm != null) {
4642 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4643 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4644 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4645 }
Jim Millerd6b57052010-06-07 17:52:42 -07004646 }
Jim Miller284b62e2010-06-08 14:27:42 -07004647 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004648 }
4649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004650 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004651 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004652 != PackageManager.PERMISSION_GRANTED) {
4653 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4654 }
Jim Millerd6b57052010-06-07 17:52:42 -07004655
Jim Miller284b62e2010-06-08 14:27:42 -07004656 synchronized (mKeyguardTokenWatcher) {
4657 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 }
4660
4661 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004662 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004663 != PackageManager.PERMISSION_GRANTED) {
4664 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4665 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666
Jim Miller284b62e2010-06-08 14:27:42 -07004667 synchronized (mKeyguardTokenWatcher) {
4668 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004669
Jim Miller284b62e2010-06-08 14:27:42 -07004670 if (!mKeyguardTokenWatcher.isAcquired()) {
4671 // If we are the last one to reenable the keyguard wait until
4672 // we have actually finished reenabling until returning.
4673 // It is possible that reenableKeyguard() can be called before
4674 // the previous disableKeyguard() is handled, in which case
4675 // neither mKeyguardTokenWatcher.acquired() or released() would
4676 // be called. In that case mKeyguardDisabled will be false here
4677 // and we have nothing to wait for.
4678 while (mKeyguardDisabled) {
4679 try {
4680 mKeyguardTokenWatcher.wait();
4681 } catch (InterruptedException e) {
4682 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 }
4684 }
4685 }
4686 }
4687 }
4688
4689 /**
4690 * @see android.app.KeyguardManager#exitKeyguardSecurely
4691 */
4692 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004693 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004694 != PackageManager.PERMISSION_GRANTED) {
4695 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4696 }
4697 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4698 public void onKeyguardExitResult(boolean success) {
4699 try {
4700 callback.onKeyguardExitResult(success);
4701 } catch (RemoteException e) {
4702 // Client has died, we don't care.
4703 }
4704 }
4705 });
4706 }
4707
4708 public boolean inKeyguardRestrictedInputMode() {
4709 return mPolicy.inKeyguardRestrictedKeyInputMode();
4710 }
Romain Guy06882f82009-06-10 13:36:04 -07004711
Dianne Hackbornffa42482009-09-23 22:20:11 -07004712 public void closeSystemDialogs(String reason) {
4713 synchronized(mWindowMap) {
4714 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004715 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004716 if (w.mSurface != null) {
4717 try {
4718 w.mClient.closeSystemDialogs(reason);
4719 } catch (RemoteException e) {
4720 }
4721 }
4722 }
4723 }
4724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004726 static float fixScale(float scale) {
4727 if (scale < 0) scale = 0;
4728 else if (scale > 20) scale = 20;
4729 return Math.abs(scale);
4730 }
Romain Guy06882f82009-06-10 13:36:04 -07004731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 public void setAnimationScale(int which, float scale) {
4733 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4734 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004735 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004736 }
4737
4738 if (scale < 0) scale = 0;
4739 else if (scale > 20) scale = 20;
4740 scale = Math.abs(scale);
4741 switch (which) {
4742 case 0: mWindowAnimationScale = fixScale(scale); break;
4743 case 1: mTransitionAnimationScale = fixScale(scale); break;
4744 }
Romain Guy06882f82009-06-10 13:36:04 -07004745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004746 // Persist setting
4747 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4748 }
Romain Guy06882f82009-06-10 13:36:04 -07004749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004750 public void setAnimationScales(float[] scales) {
4751 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4752 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004753 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004754 }
4755
4756 if (scales != null) {
4757 if (scales.length >= 1) {
4758 mWindowAnimationScale = fixScale(scales[0]);
4759 }
4760 if (scales.length >= 2) {
4761 mTransitionAnimationScale = fixScale(scales[1]);
4762 }
4763 }
Romain Guy06882f82009-06-10 13:36:04 -07004764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004765 // Persist setting
4766 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4767 }
Romain Guy06882f82009-06-10 13:36:04 -07004768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 public float getAnimationScale(int which) {
4770 switch (which) {
4771 case 0: return mWindowAnimationScale;
4772 case 1: return mTransitionAnimationScale;
4773 }
4774 return 0;
4775 }
Romain Guy06882f82009-06-10 13:36:04 -07004776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004777 public float[] getAnimationScales() {
4778 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4779 }
Romain Guy06882f82009-06-10 13:36:04 -07004780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004781 public int getSwitchState(int sw) {
4782 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4783 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004784 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004785 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004786 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004787 }
Romain Guy06882f82009-06-10 13:36:04 -07004788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 public int getSwitchStateForDevice(int devid, int sw) {
4790 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4791 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004792 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004793 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004794 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 }
Romain Guy06882f82009-06-10 13:36:04 -07004796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 public int getScancodeState(int sw) {
4798 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4799 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004800 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004802 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004803 }
Romain Guy06882f82009-06-10 13:36:04 -07004804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 public int getScancodeStateForDevice(int devid, int sw) {
4806 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4807 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004808 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004809 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004810 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 }
Romain Guy06882f82009-06-10 13:36:04 -07004812
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004813 public int getTrackballScancodeState(int sw) {
4814 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4815 "getTrackballScancodeState()")) {
4816 throw new SecurityException("Requires READ_INPUT_STATE permission");
4817 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004818 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004819 }
4820
4821 public int getDPadScancodeState(int sw) {
4822 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4823 "getDPadScancodeState()")) {
4824 throw new SecurityException("Requires READ_INPUT_STATE permission");
4825 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004826 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004827 }
4828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 public int getKeycodeState(int sw) {
4830 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4831 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004832 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004833 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004834 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 }
Romain Guy06882f82009-06-10 13:36:04 -07004836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 public int getKeycodeStateForDevice(int devid, int sw) {
4838 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4839 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004840 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004841 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004842 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 }
Romain Guy06882f82009-06-10 13:36:04 -07004844
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004845 public int getTrackballKeycodeState(int sw) {
4846 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4847 "getTrackballKeycodeState()")) {
4848 throw new SecurityException("Requires READ_INPUT_STATE permission");
4849 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004850 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004851 }
4852
4853 public int getDPadKeycodeState(int sw) {
4854 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4855 "getDPadKeycodeState()")) {
4856 throw new SecurityException("Requires READ_INPUT_STATE permission");
4857 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004858 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004859 }
Jeff Browna41ca772010-08-11 14:46:32 -07004860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004861 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004862 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 }
Romain Guy06882f82009-06-10 13:36:04 -07004864
Jeff Browna41ca772010-08-11 14:46:32 -07004865 public InputChannel monitorInput(String inputChannelName) {
4866 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4867 "monitorInput()")) {
4868 throw new SecurityException("Requires READ_INPUT_STATE permission");
4869 }
4870 return mInputManager.monitorInput(inputChannelName);
4871 }
4872
Jeff Brown8d608662010-08-30 03:02:23 -07004873 public InputDevice getInputDevice(int deviceId) {
4874 return mInputManager.getInputDevice(deviceId);
4875 }
4876
4877 public int[] getInputDeviceIds() {
4878 return mInputManager.getInputDeviceIds();
4879 }
4880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 public void enableScreenAfterBoot() {
4882 synchronized(mWindowMap) {
4883 if (mSystemBooted) {
4884 return;
4885 }
4886 mSystemBooted = true;
4887 }
Romain Guy06882f82009-06-10 13:36:04 -07004888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004889 performEnableScreen();
4890 }
Romain Guy06882f82009-06-10 13:36:04 -07004891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004892 public void enableScreenIfNeededLocked() {
4893 if (mDisplayEnabled) {
4894 return;
4895 }
4896 if (!mSystemBooted) {
4897 return;
4898 }
4899 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4900 }
Romain Guy06882f82009-06-10 13:36:04 -07004901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 public void performEnableScreen() {
4903 synchronized(mWindowMap) {
4904 if (mDisplayEnabled) {
4905 return;
4906 }
4907 if (!mSystemBooted) {
4908 return;
4909 }
Romain Guy06882f82009-06-10 13:36:04 -07004910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 // Don't enable the screen until all existing windows
4912 // have been drawn.
4913 final int N = mWindows.size();
4914 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004915 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004916 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 return;
4918 }
4919 }
Romain Guy06882f82009-06-10 13:36:04 -07004920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 mDisplayEnabled = true;
4922 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004923 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004924 StringWriter sw = new StringWriter();
4925 PrintWriter pw = new PrintWriter(sw);
4926 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004927 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 }
4929 try {
4930 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4931 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004932 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004933 Parcel data = Parcel.obtain();
4934 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4935 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4936 data, null, 0);
4937 data.recycle();
4938 }
4939 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004940 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004941 }
4942 }
Romain Guy06882f82009-06-10 13:36:04 -07004943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004944 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004946 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004947 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4948 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004949 }
Romain Guy06882f82009-06-10 13:36:04 -07004950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004951 public void setInTouchMode(boolean mode) {
4952 synchronized(mWindowMap) {
4953 mInTouchMode = mode;
4954 }
4955 }
4956
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004957 // TODO: more accounting of which pid(s) turned it on, keep count,
4958 // only allow disables from pids which have count on, etc.
4959 public void showStrictModeViolation(boolean on) {
4960 int pid = Binder.getCallingPid();
4961 synchronized(mWindowMap) {
4962 // Ignoring requests to enable the red border from clients
4963 // which aren't on screen. (e.g. Broadcast Receivers in
4964 // the background..)
4965 if (on) {
4966 boolean isVisible = false;
4967 for (WindowState ws : mWindows) {
4968 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4969 isVisible = true;
4970 break;
4971 }
4972 }
4973 if (!isVisible) {
4974 return;
4975 }
4976 }
4977
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004978 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004979 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004980 try {
4981 if (mStrictModeFlash == null) {
4982 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4983 }
4984 mStrictModeFlash.setVisibility(on);
4985 } finally {
4986 Surface.closeTransaction();
4987 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004988 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004989 }
4990 }
4991
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004992 public void setStrictModeVisualIndicatorPreference(String value) {
4993 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4994 }
4995
Dianne Hackbornd2835932010-12-13 16:28:46 -08004996 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004997 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4998 "screenshotApplications()")) {
4999 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5000 }
5001
5002 Bitmap rawss;
5003
Dianne Hackbornd2835932010-12-13 16:28:46 -08005004 int maxLayer = 0;
5005 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005006 final Rect frame = new Rect();
5007
5008 float scale;
5009 int sw, sh, dw, dh;
5010 int rot;
5011
5012 synchronized(mWindowMap) {
5013 long ident = Binder.clearCallingIdentity();
5014
5015 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5016 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5017 + TYPE_LAYER_OFFSET;
5018 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5019
5020 // Figure out the part of the screen that is actually the app.
5021 for (int i=0; i<mWindows.size(); i++) {
5022 WindowState ws = mWindows.get(i);
5023 if (ws.mSurface == null) {
5024 continue;
5025 }
5026 if (ws.mLayer >= aboveAppLayer) {
5027 break;
5028 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005029 if (appToken != null && (ws.mAppToken == null
5030 || ws.mAppToken.token != appToken)) {
5031 continue;
5032 }
5033 if (maxLayer < ws.mAnimLayer) {
5034 maxLayer = ws.mAnimLayer;
5035 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005036 final Rect wf = ws.mFrame;
5037 final Rect cr = ws.mContentInsets;
5038 int left = wf.left + cr.left;
5039 int top = wf.top + cr.top;
5040 int right = wf.right - cr.right;
5041 int bottom = wf.bottom - cr.bottom;
5042 frame.union(left, top, right, bottom);
5043 }
5044 Binder.restoreCallingIdentity(ident);
5045
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005046 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005047 return null;
5048 }
5049
5050 // The screenshot API does not apply the current screen rotation.
5051 rot = mDisplay.getRotation();
5052 int fw = frame.width();
5053 int fh = frame.height();
5054
5055 // First try reducing to fit in x dimension.
5056 scale = maxWidth/(float)fw;
5057 sw = maxWidth;
5058 sh = (int)(fh*scale);
5059 if (sh > maxHeight) {
5060 // y dimension became too long; constrain by that.
5061 scale = maxHeight/(float)fh;
5062 sw = (int)(fw*scale);
5063 sh = maxHeight;
5064 }
5065
5066 // The screen shot will contain the entire screen.
5067 dw = (int)(mDisplay.getWidth()*scale);
5068 dh = (int)(mDisplay.getHeight()*scale);
5069 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5070 int tmp = dw;
5071 dw = dh;
5072 dh = tmp;
5073 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5074 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005075 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005076 }
5077
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005078 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005079 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5080 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005081 return null;
5082 }
5083
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005084 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5085 Matrix matrix = new Matrix();
5086 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5087 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5088 Canvas canvas = new Canvas(bm);
5089 canvas.drawBitmap(rawss, matrix, null);
5090
5091 rawss.recycle();
5092 return bm;
5093 }
5094
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005095 public void freezeRotation() {
5096 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5097 "setRotation()")) {
5098 throw new SecurityException("Requires SET_ORIENTATION permission");
5099 }
5100
5101 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5102 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5103 }
5104
5105 public void thawRotation() {
5106 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5107 "setRotation()")) {
5108 throw new SecurityException("Requires SET_ORIENTATION permission");
5109 }
5110
5111 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5112 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5113 }
5114
Romain Guy06882f82009-06-10 13:36:04 -07005115 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005116 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005117 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005118 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005119 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005120 }
5121
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005122 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005123 }
Romain Guy06882f82009-06-10 13:36:04 -07005124
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005125 public void setRotationUnchecked(int rotation,
5126 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005127 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005128 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005130 long origId = Binder.clearCallingIdentity();
5131 boolean changed;
5132 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005133 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005134 }
Romain Guy06882f82009-06-10 13:36:04 -07005135
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005136 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005137 sendNewConfiguration();
5138 }
Romain Guy06882f82009-06-10 13:36:04 -07005139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005140 Binder.restoreCallingIdentity(origId);
5141 }
Romain Guy06882f82009-06-10 13:36:04 -07005142
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005143 /**
5144 * Apply a new rotation to the screen, respecting the requests of
5145 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5146 * re-evaluate the desired rotation.
5147 *
5148 * Returns null if the rotation has been changed. In this case YOU
5149 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5150 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005151 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005152 if (mDragState != null) {
5153 // Potential rotation during a drag. Don't do the rotation now, but make
5154 // a note to perform the rotation later.
5155 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation during drag");
5156 mDragState.setDeferredRotation(rotation, animFlags);
5157 return false;
5158 }
5159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005160 boolean changed;
5161 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5162 rotation = mRequestedRotation;
5163 } else {
5164 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005165 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005166 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005167 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005168 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005169 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005170 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005171 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005173 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005174 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005175 "Rotation changed to " + rotation
5176 + " from " + mRotation
5177 + " (forceApp=" + mForcedAppOrientation
5178 + ", req=" + mRequestedRotation + ")");
5179 mRotation = rotation;
5180 mWindowsFreezingScreen = true;
5181 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5182 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5183 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005184 mWaitingForConfig = true;
5185 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005186 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005187 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005188 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005190 if (CUSTOM_SCREEN_ROTATION) {
5191 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005192 if (!inTransaction) {
5193 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5194 ">>> OPEN TRANSACTION setRotationUnchecked");
5195 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005196 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005197 try {
5198 if (mScreenRotationAnimation != null) {
5199 mScreenRotationAnimation.setRotation(rotation);
5200 }
5201 } finally {
5202 if (!inTransaction) {
5203 Surface.closeTransaction();
5204 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5205 "<<< CLOSE TRANSACTION setRotationUnchecked");
5206 }
5207 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005208 Surface.setOrientation(0, rotation, animFlags);
5209 Surface.unfreezeDisplay(0);
5210 } else {
5211 Surface.setOrientation(0, rotation, animFlags);
5212 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005213 }
5214 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005215 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005216 if (w.mSurface != null) {
5217 w.mOrientationChanging = true;
5218 }
5219 }
5220 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5221 try {
5222 mRotationWatchers.get(i).onRotationChanged(rotation);
5223 } catch (RemoteException e) {
5224 }
5225 }
5226 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228 return changed;
5229 }
Romain Guy06882f82009-06-10 13:36:04 -07005230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231 public int getRotation() {
5232 return mRotation;
5233 }
5234
5235 public int watchRotation(IRotationWatcher watcher) {
5236 final IBinder watcherBinder = watcher.asBinder();
5237 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5238 public void binderDied() {
5239 synchronized (mWindowMap) {
5240 for (int i=0; i<mRotationWatchers.size(); i++) {
5241 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005242 IRotationWatcher removed = mRotationWatchers.remove(i);
5243 if (removed != null) {
5244 removed.asBinder().unlinkToDeath(this, 0);
5245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005246 i--;
5247 }
5248 }
5249 }
5250 }
5251 };
Romain Guy06882f82009-06-10 13:36:04 -07005252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005253 synchronized (mWindowMap) {
5254 try {
5255 watcher.asBinder().linkToDeath(dr, 0);
5256 mRotationWatchers.add(watcher);
5257 } catch (RemoteException e) {
5258 // Client died, no cleanup needed.
5259 }
Romain Guy06882f82009-06-10 13:36:04 -07005260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005261 return mRotation;
5262 }
5263 }
5264
5265 /**
5266 * Starts the view server on the specified port.
5267 *
5268 * @param port The port to listener to.
5269 *
5270 * @return True if the server was successfully started, false otherwise.
5271 *
5272 * @see com.android.server.ViewServer
5273 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5274 */
5275 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005276 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005277 return false;
5278 }
5279
5280 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5281 return false;
5282 }
5283
5284 if (port < 1024) {
5285 return false;
5286 }
5287
5288 if (mViewServer != null) {
5289 if (!mViewServer.isRunning()) {
5290 try {
5291 return mViewServer.start();
5292 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005293 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005294 }
5295 }
5296 return false;
5297 }
5298
5299 try {
5300 mViewServer = new ViewServer(this, port);
5301 return mViewServer.start();
5302 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005303 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005304 }
5305 return false;
5306 }
5307
Romain Guy06882f82009-06-10 13:36:04 -07005308 private boolean isSystemSecure() {
5309 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5310 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5311 }
5312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 /**
5314 * Stops the view server if it exists.
5315 *
5316 * @return True if the server stopped, false if it wasn't started or
5317 * couldn't be stopped.
5318 *
5319 * @see com.android.server.ViewServer
5320 */
5321 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005322 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 return false;
5324 }
5325
5326 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5327 return false;
5328 }
5329
5330 if (mViewServer != null) {
5331 return mViewServer.stop();
5332 }
5333 return false;
5334 }
5335
5336 /**
5337 * Indicates whether the view server is running.
5338 *
5339 * @return True if the server is running, false otherwise.
5340 *
5341 * @see com.android.server.ViewServer
5342 */
5343 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005344 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345 return false;
5346 }
5347
5348 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5349 return false;
5350 }
5351
5352 return mViewServer != null && mViewServer.isRunning();
5353 }
5354
5355 /**
5356 * Lists all availble windows in the system. The listing is written in the
5357 * specified Socket's output stream with the following syntax:
5358 * windowHashCodeInHexadecimal windowName
5359 * Each line of the ouput represents a different window.
5360 *
5361 * @param client The remote client to send the listing to.
5362 * @return False if an error occured, true otherwise.
5363 */
5364 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005365 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005366 return false;
5367 }
5368
5369 boolean result = true;
5370
Jeff Browne33348b2010-07-15 23:54:05 -07005371 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005372 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005373 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005374 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005375 }
5376
5377 BufferedWriter out = null;
5378
5379 // Any uncaught exception will crash the system process
5380 try {
5381 OutputStream clientStream = client.getOutputStream();
5382 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5383
5384 final int count = windows.length;
5385 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005386 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005387 out.write(Integer.toHexString(System.identityHashCode(w)));
5388 out.write(' ');
5389 out.append(w.mAttrs.getTitle());
5390 out.write('\n');
5391 }
5392
5393 out.write("DONE.\n");
5394 out.flush();
5395 } catch (Exception e) {
5396 result = false;
5397 } finally {
5398 if (out != null) {
5399 try {
5400 out.close();
5401 } catch (IOException e) {
5402 result = false;
5403 }
5404 }
5405 }
5406
5407 return result;
5408 }
5409
5410 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005411 * Returns the focused window in the following format:
5412 * windowHashCodeInHexadecimal windowName
5413 *
5414 * @param client The remote client to send the listing to.
5415 * @return False if an error occurred, true otherwise.
5416 */
5417 boolean viewServerGetFocusedWindow(Socket client) {
5418 if (isSystemSecure()) {
5419 return false;
5420 }
5421
5422 boolean result = true;
5423
5424 WindowState focusedWindow = getFocusedWindow();
5425
5426 BufferedWriter out = null;
5427
5428 // Any uncaught exception will crash the system process
5429 try {
5430 OutputStream clientStream = client.getOutputStream();
5431 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5432
5433 if(focusedWindow != null) {
5434 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5435 out.write(' ');
5436 out.append(focusedWindow.mAttrs.getTitle());
5437 }
5438 out.write('\n');
5439 out.flush();
5440 } catch (Exception e) {
5441 result = false;
5442 } finally {
5443 if (out != null) {
5444 try {
5445 out.close();
5446 } catch (IOException e) {
5447 result = false;
5448 }
5449 }
5450 }
5451
5452 return result;
5453 }
5454
5455 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005456 * Sends a command to a target window. The result of the command, if any, will be
5457 * written in the output stream of the specified socket.
5458 *
5459 * The parameters must follow this syntax:
5460 * windowHashcode extra
5461 *
5462 * Where XX is the length in characeters of the windowTitle.
5463 *
5464 * The first parameter is the target window. The window with the specified hashcode
5465 * will be the target. If no target can be found, nothing happens. The extra parameters
5466 * will be delivered to the target window and as parameters to the command itself.
5467 *
5468 * @param client The remote client to sent the result, if any, to.
5469 * @param command The command to execute.
5470 * @param parameters The command parameters.
5471 *
5472 * @return True if the command was successfully delivered, false otherwise. This does
5473 * not indicate whether the command itself was successful.
5474 */
5475 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005476 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005477 return false;
5478 }
5479
5480 boolean success = true;
5481 Parcel data = null;
5482 Parcel reply = null;
5483
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005484 BufferedWriter out = null;
5485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005486 // Any uncaught exception will crash the system process
5487 try {
5488 // Find the hashcode of the window
5489 int index = parameters.indexOf(' ');
5490 if (index == -1) {
5491 index = parameters.length();
5492 }
5493 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005494 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005495
5496 // Extract the command's parameter after the window description
5497 if (index < parameters.length()) {
5498 parameters = parameters.substring(index + 1);
5499 } else {
5500 parameters = "";
5501 }
5502
5503 final WindowManagerService.WindowState window = findWindow(hashCode);
5504 if (window == null) {
5505 return false;
5506 }
5507
5508 data = Parcel.obtain();
5509 data.writeInterfaceToken("android.view.IWindow");
5510 data.writeString(command);
5511 data.writeString(parameters);
5512 data.writeInt(1);
5513 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5514
5515 reply = Parcel.obtain();
5516
5517 final IBinder binder = window.mClient.asBinder();
5518 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5519 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5520
5521 reply.readException();
5522
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005523 if (!client.isOutputShutdown()) {
5524 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5525 out.write("DONE\n");
5526 out.flush();
5527 }
5528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005529 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005530 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005531 success = false;
5532 } finally {
5533 if (data != null) {
5534 data.recycle();
5535 }
5536 if (reply != null) {
5537 reply.recycle();
5538 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005539 if (out != null) {
5540 try {
5541 out.close();
5542 } catch (IOException e) {
5543
5544 }
5545 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005546 }
5547
5548 return success;
5549 }
5550
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005551 public void addWindowChangeListener(WindowChangeListener listener) {
5552 synchronized(mWindowMap) {
5553 mWindowChangeListeners.add(listener);
5554 }
5555 }
5556
5557 public void removeWindowChangeListener(WindowChangeListener listener) {
5558 synchronized(mWindowMap) {
5559 mWindowChangeListeners.remove(listener);
5560 }
5561 }
5562
5563 private void notifyWindowsChanged() {
5564 WindowChangeListener[] windowChangeListeners;
5565 synchronized(mWindowMap) {
5566 if(mWindowChangeListeners.isEmpty()) {
5567 return;
5568 }
5569 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5570 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5571 }
5572 int N = windowChangeListeners.length;
5573 for(int i = 0; i < N; i++) {
5574 windowChangeListeners[i].windowsChanged();
5575 }
5576 }
5577
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005578 private void notifyFocusChanged() {
5579 WindowChangeListener[] windowChangeListeners;
5580 synchronized(mWindowMap) {
5581 if(mWindowChangeListeners.isEmpty()) {
5582 return;
5583 }
5584 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5585 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5586 }
5587 int N = windowChangeListeners.length;
5588 for(int i = 0; i < N; i++) {
5589 windowChangeListeners[i].focusChanged();
5590 }
5591 }
5592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005593 private WindowState findWindow(int hashCode) {
5594 if (hashCode == -1) {
5595 return getFocusedWindow();
5596 }
5597
5598 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005599 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005600 final int count = windows.size();
5601
5602 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005603 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005604 if (System.identityHashCode(w) == hashCode) {
5605 return w;
5606 }
5607 }
5608 }
5609
5610 return null;
5611 }
5612
5613 /*
5614 * Instruct the Activity Manager to fetch the current configuration and broadcast
5615 * that to config-changed listeners if appropriate.
5616 */
5617 void sendNewConfiguration() {
5618 try {
5619 mActivityManager.updateConfiguration(null);
5620 } catch (RemoteException e) {
5621 }
5622 }
Romain Guy06882f82009-06-10 13:36:04 -07005623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005624 public Configuration computeNewConfiguration() {
5625 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005626 Configuration config = computeNewConfigurationLocked();
5627 if (config == null && mWaitingForConfig) {
5628 // Nothing changed but we are waiting for something... stop that!
5629 mWaitingForConfig = false;
5630 performLayoutAndPlaceSurfacesLocked();
5631 }
5632 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005633 }
5634 }
Romain Guy06882f82009-06-10 13:36:04 -07005635
Dianne Hackbornc485a602009-03-24 22:39:49 -07005636 Configuration computeNewConfigurationLocked() {
5637 Configuration config = new Configuration();
5638 if (!computeNewConfigurationLocked(config)) {
5639 return null;
5640 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005641 return config;
5642 }
Romain Guy06882f82009-06-10 13:36:04 -07005643
Dianne Hackbornc485a602009-03-24 22:39:49 -07005644 boolean computeNewConfigurationLocked(Configuration config) {
5645 if (mDisplay == null) {
5646 return false;
5647 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005648
5649 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005650
5651 // Use the effective "visual" dimensions based on current rotation
5652 final boolean rotated = (mRotation == Surface.ROTATION_90
5653 || mRotation == Surface.ROTATION_270);
5654 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5655 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5656
Dianne Hackbornc485a602009-03-24 22:39:49 -07005657 int orientation = Configuration.ORIENTATION_SQUARE;
5658 if (dw < dh) {
5659 orientation = Configuration.ORIENTATION_PORTRAIT;
5660 } else if (dw > dh) {
5661 orientation = Configuration.ORIENTATION_LANDSCAPE;
5662 }
5663 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005664
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005665 DisplayMetrics dm = new DisplayMetrics();
5666 mDisplay.getMetrics(dm);
5667 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5668
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005669 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005670 // Note we only do this once because at this point we don't
5671 // expect the screen to change in this way at runtime, and want
5672 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005673 int longSize = dw;
5674 int shortSize = dh;
5675 if (longSize < shortSize) {
5676 int tmp = longSize;
5677 longSize = shortSize;
5678 shortSize = tmp;
5679 }
5680 longSize = (int)(longSize/dm.density);
5681 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005682
Dianne Hackborn723738c2009-06-25 19:48:04 -07005683 // These semi-magic numbers define our compatibility modes for
5684 // applications with different screens. Don't change unless you
5685 // make sure to test lots and lots of apps!
5686 if (longSize < 470) {
5687 // This is shorter than an HVGA normal density screen (which
5688 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005689 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5690 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005691 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005692 // What size is this screen screen?
5693 if (longSize >= 800 && shortSize >= 600) {
5694 // SVGA or larger screens at medium density are the point
5695 // at which we consider it to be an extra large screen.
5696 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005697 } else if (longSize >= 530 && shortSize >= 400) {
5698 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005699 // at which we consider it to be a large screen.
5700 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5701 } else {
5702 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005703
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005704 // If this screen is wider than normal HVGA, or taller
5705 // than FWVGA, then for old apps we want to run in size
5706 // compatibility mode.
5707 if (shortSize > 321 || longSize > 570) {
5708 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5709 }
5710 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005711
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005712 // Is this a long screen?
5713 if (((longSize*3)/5) >= (shortSize-1)) {
5714 // Anything wider than WVGA (5:3) is considering to be long.
5715 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5716 } else {
5717 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5718 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005719 }
5720 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005721 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005722
Dianne Hackbornc485a602009-03-24 22:39:49 -07005723 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5724 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5725 mPolicy.adjustConfigurationLw(config);
5726 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005727 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005728
5729 // -------------------------------------------------------------
5730 // Drag and drop
5731 // -------------------------------------------------------------
5732
5733 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005734 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005735 if (DEBUG_DRAG) {
5736 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005737 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005738 + " asbinder=" + window.asBinder());
5739 }
5740
5741 final int callerPid = Binder.getCallingPid();
5742 final long origId = Binder.clearCallingIdentity();
5743 IBinder token = null;
5744
5745 try {
5746 synchronized (mWindowMap) {
5747 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005748 if (mDragState == null) {
5749 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5750 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5751 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005752 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005753 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005754 // TODO: preserve flags param in DragState
5755 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005756 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005757 token = mDragState.mToken = new Binder();
5758
5759 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005760 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5761 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005762 mH.sendMessageDelayed(msg, 5000);
5763 } else {
5764 Slog.w(TAG, "Drag already in progress");
5765 }
5766 } catch (Surface.OutOfResourcesException e) {
5767 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5768 if (mDragState != null) {
5769 mDragState.reset();
5770 mDragState = null;
5771 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005772 }
5773 }
5774 } finally {
5775 Binder.restoreCallingIdentity(origId);
5776 }
5777
5778 return token;
5779 }
5780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005781 // -------------------------------------------------------------
5782 // Input Events and Focus Management
5783 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005784
Jeff Brown349703e2010-06-22 01:27:15 -07005785 InputMonitor mInputMonitor = new InputMonitor();
5786
5787 /* Tracks the progress of input dispatch and ensures that input dispatch state
5788 * is kept in sync with changes in window focus, visibility, registration, and
5789 * other relevant Window Manager state transitions. */
5790 final class InputMonitor {
5791 // Current window with input focus for keys and other non-touch events. May be null.
5792 private WindowState mInputFocus;
5793
5794 // When true, prevents input dispatch from proceeding until set to false again.
5795 private boolean mInputDispatchFrozen;
5796
5797 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5798 private boolean mInputDispatchEnabled = true;
5799
5800 // Temporary list of windows information to provide to the input dispatcher.
5801 private InputWindowList mTempInputWindows = new InputWindowList();
5802
5803 // Temporary input application object to provide to the input dispatcher.
5804 private InputApplication mTempInputApplication = new InputApplication();
5805
Jeff Brownb09abc12011-01-13 21:08:27 -08005806 // Set to true when the first input device configuration change notification
5807 // is received to indicate that the input devices are ready.
5808 private final Object mInputDevicesReadyMonitor = new Object();
5809 private boolean mInputDevicesReady;
5810
Jeff Brown349703e2010-06-22 01:27:15 -07005811 /* Notifies the window manager about a broken input channel.
5812 *
5813 * Called by the InputManager.
5814 */
Jeff Brown928e0542011-01-10 11:17:36 -08005815 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5816 if (inputWindowHandle == null) {
5817 return;
5818 }
5819
Jeff Brown349703e2010-06-22 01:27:15 -07005820 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005821 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005822 Slog.i(TAG, "WINDOW DIED " + windowState);
5823 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005824 }
5825 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005826
Jeff Brown519e0242010-09-15 15:18:56 -07005827 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005828 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005829 *
5830 * Called by the InputManager.
5831 */
Jeff Brown928e0542011-01-10 11:17:36 -08005832 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5833 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005834 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005835 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005836 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005837 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005838 if (windowState != null) {
5839 Slog.i(TAG, "Input event dispatching timed out sending to "
5840 + windowState.mAttrs.getTitle());
5841 appWindowToken = windowState.mAppToken;
5842 }
Jeff Brown349703e2010-06-22 01:27:15 -07005843 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005844 }
5845
Jeff Brown928e0542011-01-10 11:17:36 -08005846 if (appWindowToken == null && inputApplicationHandle != null) {
5847 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005848 Slog.i(TAG, "Input event dispatching timed out sending to application "
5849 + appWindowToken.stringName);
5850 }
Jeff Brown349703e2010-06-22 01:27:15 -07005851
Jeff Brown519e0242010-09-15 15:18:56 -07005852 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005853 try {
5854 // Notify the activity manager about the timeout and let it decide whether
5855 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005856 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005857 if (! abort) {
5858 // The activity manager declined to abort dispatching.
5859 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005860 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005861 }
Jeff Brown349703e2010-06-22 01:27:15 -07005862 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005863 }
5864 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005865 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005866 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005867
Chris Tatea32dcf72010-10-14 12:13:50 -07005868 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005869 final InputWindow inputWindow = windowList.add();
5870 inputWindow.inputChannel = mDragState.mServerChannel;
5871 inputWindow.name = "drag";
Jeff Brownfbf09772011-01-16 14:06:57 -08005872 inputWindow.layoutParamsFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Christopher Tatea53146c2010-09-07 11:57:52 -07005873 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5874 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5875 inputWindow.visible = true;
5876 inputWindow.canReceiveKeys = false;
5877 inputWindow.hasFocus = true;
5878 inputWindow.hasWallpaper = false;
5879 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005880 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005881 inputWindow.ownerPid = Process.myPid();
5882 inputWindow.ownerUid = Process.myUid();
5883
5884 // The drag window covers the entire display
5885 inputWindow.frameLeft = 0;
5886 inputWindow.frameTop = 0;
5887 inputWindow.frameRight = mDisplay.getWidth();
5888 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005889
Jeff Brownfbf09772011-01-16 14:06:57 -08005890 // The drag window cannot receive new touches.
5891 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07005892 }
5893
Jeff Brown349703e2010-06-22 01:27:15 -07005894 /* Updates the cached window information provided to the input dispatcher. */
5895 public void updateInputWindowsLw() {
5896 // Populate the input window list with information about all of the windows that
5897 // could potentially receive input.
5898 // As an optimization, we could try to prune the list of windows but this turns
5899 // out to be difficult because only the native code knows for sure which window
5900 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005901 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005902
5903 // If there's a drag in flight, provide a pseudowindow to catch drag input
5904 final boolean inDrag = (mDragState != null);
5905 if (inDrag) {
5906 if (DEBUG_DRAG) {
5907 Log.d(TAG, "Inserting drag window");
5908 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005909 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005910 }
5911
Jeff Brown7fbdc842010-06-17 20:52:56 -07005912 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005913 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005914 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005915 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005916 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005917 continue;
5918 }
5919
Jeff Brown349703e2010-06-22 01:27:15 -07005920 final int flags = child.mAttrs.flags;
5921 final int type = child.mAttrs.type;
5922
5923 final boolean hasFocus = (child == mInputFocus);
5924 final boolean isVisible = child.isVisibleLw();
5925 final boolean hasWallpaper = (child == mWallpaperTarget)
5926 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005927
5928 // If there's a drag in progress and 'child' is a potential drop target,
5929 // make sure it's been told about the drag
5930 if (inDrag && isVisible) {
5931 mDragState.sendDragStartedIfNeededLw(child);
5932 }
5933
Jeff Brown349703e2010-06-22 01:27:15 -07005934 // Add a window to our list of input windows.
5935 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005936 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005937 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005938 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005939 inputWindow.layoutParamsFlags = flags;
5940 inputWindow.layoutParamsType = type;
5941 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5942 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005943 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005944 inputWindow.hasFocus = hasFocus;
5945 inputWindow.hasWallpaper = hasWallpaper;
5946 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005947 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005948 inputWindow.ownerPid = child.mSession.mPid;
5949 inputWindow.ownerUid = child.mSession.mUid;
5950
5951 final Rect frame = child.mFrame;
5952 inputWindow.frameLeft = frame.left;
5953 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005954 inputWindow.frameRight = frame.right;
5955 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08005956
5957 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005958 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005959
Jeff Brown349703e2010-06-22 01:27:15 -07005960 // Send windows to native code.
5961 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005962
Jeff Brown349703e2010-06-22 01:27:15 -07005963 // Clear the list in preparation for the next round.
5964 // Also avoids keeping InputChannel objects referenced unnecessarily.
5965 mTempInputWindows.clear();
5966 }
Jeff Brownb09abc12011-01-13 21:08:27 -08005967
5968 /* Notifies that the input device configuration has changed. */
5969 public void notifyConfigurationChanged() {
5970 sendNewConfiguration();
5971
5972 synchronized (mInputDevicesReadyMonitor) {
5973 if (!mInputDevicesReady) {
5974 mInputDevicesReady = true;
5975 mInputDevicesReadyMonitor.notifyAll();
5976 }
5977 }
5978 }
5979
5980 /* Waits until the built-in input devices have been configured. */
5981 public boolean waitForInputDevicesReady(long timeoutMillis) {
5982 synchronized (mInputDevicesReadyMonitor) {
5983 if (!mInputDevicesReady) {
5984 try {
5985 mInputDevicesReadyMonitor.wait(timeoutMillis);
5986 } catch (InterruptedException ex) {
5987 }
5988 }
5989 return mInputDevicesReady;
5990 }
5991 }
5992
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005993 /* Notifies that the lid switch changed state. */
5994 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5995 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5996 }
5997
Jeff Brown349703e2010-06-22 01:27:15 -07005998 /* Provides an opportunity for the window manager policy to intercept early key
5999 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006000 public int interceptKeyBeforeQueueing(
6001 KeyEvent event, int policyFlags, boolean isScreenOn) {
6002 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006003 }
6004
6005 /* Provides an opportunity for the window manager policy to process a key before
6006 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006007 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006008 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006009 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006010 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006011 }
6012
Jeff Brown3915bb82010-11-05 15:02:16 -07006013 /* Provides an opportunity for the window manager policy to process a key that
6014 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006015 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006016 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006017 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006018 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006019 }
6020
Jeff Brown349703e2010-06-22 01:27:15 -07006021 /* Called when the current input focus changes.
6022 * Layer assignment is assumed to be complete by the time this is called.
6023 */
6024 public void setInputFocusLw(WindowState newWindow) {
6025 if (DEBUG_INPUT) {
6026 Slog.d(TAG, "Input focus has changed to " + newWindow);
6027 }
6028
6029 if (newWindow != mInputFocus) {
6030 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006031 // Displaying a window implicitly causes dispatching to be unpaused.
6032 // This is to protect against bugs if someone pauses dispatching but
6033 // forgets to resume.
6034 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006035 }
Jeff Brown349703e2010-06-22 01:27:15 -07006036
6037 mInputFocus = newWindow;
6038 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006039 }
6040 }
6041
Jeff Brown349703e2010-06-22 01:27:15 -07006042 public void setFocusedAppLw(AppWindowToken newApp) {
6043 // Focused app has changed.
6044 if (newApp == null) {
6045 mInputManager.setFocusedApplication(null);
6046 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006047 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006048 mTempInputApplication.name = newApp.toString();
6049 mTempInputApplication.dispatchingTimeoutNanos =
6050 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006051
Jeff Brown349703e2010-06-22 01:27:15 -07006052 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006053
6054 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006055 }
6056 }
6057
Jeff Brown349703e2010-06-22 01:27:15 -07006058 public void pauseDispatchingLw(WindowToken window) {
6059 if (! window.paused) {
6060 if (DEBUG_INPUT) {
6061 Slog.v(TAG, "Pausing WindowToken " + window);
6062 }
6063
6064 window.paused = true;
6065 updateInputWindowsLw();
6066 }
6067 }
6068
6069 public void resumeDispatchingLw(WindowToken window) {
6070 if (window.paused) {
6071 if (DEBUG_INPUT) {
6072 Slog.v(TAG, "Resuming WindowToken " + window);
6073 }
6074
6075 window.paused = false;
6076 updateInputWindowsLw();
6077 }
6078 }
6079
6080 public void freezeInputDispatchingLw() {
6081 if (! mInputDispatchFrozen) {
6082 if (DEBUG_INPUT) {
6083 Slog.v(TAG, "Freezing input dispatching");
6084 }
6085
6086 mInputDispatchFrozen = true;
6087 updateInputDispatchModeLw();
6088 }
6089 }
6090
6091 public void thawInputDispatchingLw() {
6092 if (mInputDispatchFrozen) {
6093 if (DEBUG_INPUT) {
6094 Slog.v(TAG, "Thawing input dispatching");
6095 }
6096
6097 mInputDispatchFrozen = false;
6098 updateInputDispatchModeLw();
6099 }
6100 }
6101
6102 public void setEventDispatchingLw(boolean enabled) {
6103 if (mInputDispatchEnabled != enabled) {
6104 if (DEBUG_INPUT) {
6105 Slog.v(TAG, "Setting event dispatching to " + enabled);
6106 }
6107
6108 mInputDispatchEnabled = enabled;
6109 updateInputDispatchModeLw();
6110 }
6111 }
6112
6113 private void updateInputDispatchModeLw() {
6114 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6115 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 public void pauseKeyDispatching(IBinder _token) {
6119 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6120 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006121 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 }
6123
6124 synchronized (mWindowMap) {
6125 WindowToken token = mTokenMap.get(_token);
6126 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006127 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 }
6129 }
6130 }
6131
6132 public void resumeKeyDispatching(IBinder _token) {
6133 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6134 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006135 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006136 }
6137
6138 synchronized (mWindowMap) {
6139 WindowToken token = mTokenMap.get(_token);
6140 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006141 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006142 }
6143 }
6144 }
6145
6146 public void setEventDispatching(boolean enabled) {
6147 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6148 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006149 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 }
6151
6152 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006153 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 }
6155 }
Romain Guy06882f82009-06-10 13:36:04 -07006156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006157 /**
6158 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006159 * Even when sync is false, this method may block while waiting for current
6160 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006161 *
6162 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006163 * {@link SystemClock#uptimeMillis()} as the timebase.)
6164 * @param sync If true, wait for the event to be completed before returning to the caller.
6165 * @return Returns true if event was dispatched, false if it was dropped for any reason
6166 */
6167 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6168 long downTime = ev.getDownTime();
6169 long eventTime = ev.getEventTime();
6170
6171 int action = ev.getAction();
6172 int code = ev.getKeyCode();
6173 int repeatCount = ev.getRepeatCount();
6174 int metaState = ev.getMetaState();
6175 int deviceId = ev.getDeviceId();
6176 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006177 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006178 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006179
6180 if (source == InputDevice.SOURCE_UNKNOWN) {
6181 source = InputDevice.SOURCE_KEYBOARD;
6182 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006183
6184 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6185 if (downTime == 0) downTime = eventTime;
6186
6187 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006188 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006189
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006190 final int pid = Binder.getCallingPid();
6191 final int uid = Binder.getCallingUid();
6192 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006193
Jeff Brownbbda99d2010-07-28 15:48:59 -07006194 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6195 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6196 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6197 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006198
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006199 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006200 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006201 }
6202
6203 /**
6204 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006205 * Even when sync is false, this method may block while waiting for current
6206 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006207 *
6208 * @param ev A motion event describing the pointer (touch) action. (As noted in
6209 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006210 * {@link SystemClock#uptimeMillis()} as the timebase.)
6211 * @param sync If true, wait for the event to be completed before returning to the caller.
6212 * @return Returns true if event was dispatched, false if it was dropped for any reason
6213 */
6214 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006215 final int pid = Binder.getCallingPid();
6216 final int uid = Binder.getCallingUid();
6217 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006218
Jeff Brownc5ed5912010-07-14 18:48:53 -07006219 MotionEvent newEvent = MotionEvent.obtain(ev);
6220 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6221 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6222 }
6223
Jeff Brownbbda99d2010-07-28 15:48:59 -07006224 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6225 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6226 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6227 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006228
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006229 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006230 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006231 }
Romain Guy06882f82009-06-10 13:36:04 -07006232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006233 /**
6234 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006235 * Even when sync is false, this method may block while waiting for current
6236 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006237 *
6238 * @param ev A motion event describing the trackball action. (As noted in
6239 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006240 * {@link SystemClock#uptimeMillis()} as the timebase.)
6241 * @param sync If true, wait for the event to be completed before returning to the caller.
6242 * @return Returns true if event was dispatched, false if it was dropped for any reason
6243 */
6244 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006245 final int pid = Binder.getCallingPid();
6246 final int uid = Binder.getCallingUid();
6247 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006248
Jeff Brownc5ed5912010-07-14 18:48:53 -07006249 MotionEvent newEvent = MotionEvent.obtain(ev);
6250 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6251 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6252 }
6253
Jeff Brownbbda99d2010-07-28 15:48:59 -07006254 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6255 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6256 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6257 INJECTION_TIMEOUT_MILLIS);
6258
6259 Binder.restoreCallingIdentity(ident);
6260 return reportInjectionResult(result);
6261 }
6262
6263 /**
6264 * Inject an input event into the UI without waiting for dispatch to commence.
6265 * This variant is useful for fire-and-forget input event injection. It does not
6266 * block any longer than it takes to enqueue the input event.
6267 *
6268 * @param ev An input event. (Be sure to set the input source correctly.)
6269 * @return Returns true if event was dispatched, false if it was dropped for any reason
6270 */
6271 public boolean injectInputEventNoWait(InputEvent ev) {
6272 final int pid = Binder.getCallingPid();
6273 final int uid = Binder.getCallingUid();
6274 final long ident = Binder.clearCallingIdentity();
6275
6276 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6277 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6278 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006279
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006280 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006281 return reportInjectionResult(result);
6282 }
6283
6284 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006285 switch (result) {
6286 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6287 Slog.w(TAG, "Input event injection permission denied.");
6288 throw new SecurityException(
6289 "Injecting to another application requires INJECT_EVENTS permission");
6290 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006291 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006292 return true;
6293 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6294 Slog.w(TAG, "Input event injection timed out.");
6295 return false;
6296 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6297 default:
6298 Slog.w(TAG, "Input event injection failed.");
6299 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006301 }
Romain Guy06882f82009-06-10 13:36:04 -07006302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006303 private WindowState getFocusedWindow() {
6304 synchronized (mWindowMap) {
6305 return getFocusedWindowLocked();
6306 }
6307 }
6308
6309 private WindowState getFocusedWindowLocked() {
6310 return mCurrentFocus;
6311 }
Romain Guy06882f82009-06-10 13:36:04 -07006312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006314 if (!mInputMonitor.waitForInputDevicesReady(
6315 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6316 Slog.w(TAG, "Devices still not ready after waiting "
6317 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6318 + " milliseconds before attempting to detect safe mode.");
6319 }
6320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006321 mSafeMode = mPolicy.detectSafeMode();
6322 return mSafeMode;
6323 }
Romain Guy06882f82009-06-10 13:36:04 -07006324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006325 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006326 synchronized(mWindowMap) {
6327 if (mDisplay != null) {
6328 throw new IllegalStateException("Display already initialized");
6329 }
6330 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6331 mDisplay = wm.getDefaultDisplay();
6332 mInitialDisplayWidth = mDisplay.getWidth();
6333 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006334 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6335 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006336 }
6337
6338 try {
6339 mActivityManager.updateConfiguration(null);
6340 } catch (RemoteException e) {
6341 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006342
6343 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006344 }
6345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006346 // -------------------------------------------------------------
6347 // Client Session State
6348 // -------------------------------------------------------------
6349
6350 private final class Session extends IWindowSession.Stub
6351 implements IBinder.DeathRecipient {
6352 final IInputMethodClient mClient;
6353 final IInputContext mInputContext;
6354 final int mUid;
6355 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006356 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006357 SurfaceSession mSurfaceSession;
6358 int mNumWindow = 0;
6359 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006361 public Session(IInputMethodClient client, IInputContext inputContext) {
6362 mClient = client;
6363 mInputContext = inputContext;
6364 mUid = Binder.getCallingUid();
6365 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006366 StringBuilder sb = new StringBuilder();
6367 sb.append("Session{");
6368 sb.append(Integer.toHexString(System.identityHashCode(this)));
6369 sb.append(" uid ");
6370 sb.append(mUid);
6371 sb.append("}");
6372 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 synchronized (mWindowMap) {
6375 if (mInputMethodManager == null && mHaveInputMethods) {
6376 IBinder b = ServiceManager.getService(
6377 Context.INPUT_METHOD_SERVICE);
6378 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6379 }
6380 }
6381 long ident = Binder.clearCallingIdentity();
6382 try {
6383 // Note: it is safe to call in to the input method manager
6384 // here because we are not holding our lock.
6385 if (mInputMethodManager != null) {
6386 mInputMethodManager.addClient(client, inputContext,
6387 mUid, mPid);
6388 } else {
6389 client.setUsingInputMethod(false);
6390 }
6391 client.asBinder().linkToDeath(this, 0);
6392 } catch (RemoteException e) {
6393 // The caller has died, so we can just forget about this.
6394 try {
6395 if (mInputMethodManager != null) {
6396 mInputMethodManager.removeClient(client);
6397 }
6398 } catch (RemoteException ee) {
6399 }
6400 } finally {
6401 Binder.restoreCallingIdentity(ident);
6402 }
6403 }
Romain Guy06882f82009-06-10 13:36:04 -07006404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006405 @Override
6406 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6407 throws RemoteException {
6408 try {
6409 return super.onTransact(code, data, reply, flags);
6410 } catch (RuntimeException e) {
6411 // Log all 'real' exceptions thrown to the caller
6412 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006413 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 }
6415 throw e;
6416 }
6417 }
6418
6419 public void binderDied() {
6420 // Note: it is safe to call in to the input method manager
6421 // here because we are not holding our lock.
6422 try {
6423 if (mInputMethodManager != null) {
6424 mInputMethodManager.removeClient(mClient);
6425 }
6426 } catch (RemoteException e) {
6427 }
6428 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006429 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006430 mClientDead = true;
6431 killSessionLocked();
6432 }
6433 }
6434
6435 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006436 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6437 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6438 outInputChannel);
6439 }
6440
6441 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006443 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
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 public void remove(IWindow window) {
6447 removeWindow(this, window);
6448 }
Romain Guy06882f82009-06-10 13:36:04 -07006449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006450 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6451 int requestedWidth, int requestedHeight, int viewFlags,
6452 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006453 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006454 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6455 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006457 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006458 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6459 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 }
Romain Guy06882f82009-06-10 13:36:04 -07006461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 public void setTransparentRegion(IWindow window, Region region) {
6463 setTransparentRegionWindow(this, window, region);
6464 }
Romain Guy06882f82009-06-10 13:36:04 -07006465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006467 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006468 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006469 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 }
Romain Guy06882f82009-06-10 13:36:04 -07006471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6473 getWindowDisplayFrame(this, window, outDisplayFrame);
6474 }
Romain Guy06882f82009-06-10 13:36:04 -07006475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006477 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006478 TAG, "IWindow finishDrawing called for " + window);
6479 finishDrawingWindow(this, window);
6480 }
6481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 public void setInTouchMode(boolean mode) {
6483 synchronized(mWindowMap) {
6484 mInTouchMode = mode;
6485 }
6486 }
6487
6488 public boolean getInTouchMode() {
6489 synchronized(mWindowMap) {
6490 return mInTouchMode;
6491 }
6492 }
6493
6494 public boolean performHapticFeedback(IWindow window, int effectId,
6495 boolean always) {
6496 synchronized(mWindowMap) {
6497 long ident = Binder.clearCallingIdentity();
6498 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006499 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006500 windowForClientLocked(this, window, true),
6501 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 } finally {
6503 Binder.restoreCallingIdentity(ident);
6504 }
6505 }
6506 }
Romain Guy06882f82009-06-10 13:36:04 -07006507
Christopher Tatea53146c2010-09-07 11:57:52 -07006508 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006509 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006510 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006511 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006512 width, height, outSurface);
6513 }
6514
6515 public boolean performDrag(IWindow window, IBinder dragToken,
6516 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6517 ClipData data) {
6518 if (DEBUG_DRAG) {
6519 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6520 }
6521
6522 synchronized (mWindowMap) {
6523 if (mDragState == null) {
6524 Slog.w(TAG, "No drag prepared");
6525 throw new IllegalStateException("performDrag() without prepareDrag()");
6526 }
6527
6528 if (dragToken != mDragState.mToken) {
6529 Slog.w(TAG, "Performing mismatched drag");
6530 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6531 }
6532
6533 WindowState callingWin = windowForClientLocked(null, window, false);
6534 if (callingWin == null) {
6535 Slog.w(TAG, "Bad requesting window " + window);
6536 return false; // !!! TODO: throw here?
6537 }
6538
6539 // !!! TODO: if input is not still focused on the initiating window, fail
6540 // the drag initiation (e.g. an alarm window popped up just as the application
6541 // called performDrag()
6542
6543 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6544
Christopher Tate2c095f32010-10-04 14:13:40 -07006545 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6546 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006547
Chris Tateb478f462010-10-15 16:02:26 -07006548 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6549 // the actual drag event dispatch stuff in the dragstate
6550
Christopher Tatea53146c2010-09-07 11:57:52 -07006551 mDragState.register();
6552 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006553 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6554 mDragState.mServerChannel)) {
6555 Slog.e(TAG, "Unable to transfer touch focus");
6556 mDragState.unregister();
6557 mDragState = null;
6558 mInputMonitor.updateInputWindowsLw();
6559 return false;
6560 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006561
6562 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006563 mDragState.mCurrentX = touchX;
6564 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006565 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006566
6567 // remember the thumb offsets for later
6568 mDragState.mThumbOffsetX = thumbCenterX;
6569 mDragState.mThumbOffsetY = thumbCenterY;
6570
6571 // Make the surface visible at the proper location
6572 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006573 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006574 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006575 try {
6576 surface.setPosition((int)(touchX - thumbCenterX),
6577 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006578 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006579 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006580 surface.show();
6581 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006582 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006583 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006584 }
6585 }
6586
6587 return true; // success!
6588 }
6589
Chris Tated4533f142010-10-19 15:15:08 -07006590 public void reportDropResult(IWindow window, boolean consumed) {
6591 IBinder token = window.asBinder();
6592 if (DEBUG_DRAG) {
6593 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6594 }
6595
6596 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006597 long ident = Binder.clearCallingIdentity();
6598 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006599 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006600 Slog.w(TAG, "Invalid drop-result claim by " + window);
6601 throw new IllegalStateException("reportDropResult() by non-recipient");
6602 }
6603
6604 // The right window has responded, even if it's no longer around,
6605 // so be sure to halt the timeout even if the later WindowState
6606 // lookup fails.
6607 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6608 WindowState callingWin = windowForClientLocked(null, window, false);
6609 if (callingWin == null) {
6610 Slog.w(TAG, "Bad result-reporting window " + window);
6611 return; // !!! TODO: throw here?
6612 }
6613
6614 mDragState.mDragResult = consumed;
6615 mDragState.endDragLw();
6616 } finally {
6617 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006618 }
Chris Tated4533f142010-10-19 15:15:08 -07006619 }
6620 }
6621
Christopher Tatea53146c2010-09-07 11:57:52 -07006622 public void dragRecipientEntered(IWindow window) {
6623 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006624 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006625 }
6626 }
6627
6628 public void dragRecipientExited(IWindow window) {
6629 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006630 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006631 }
6632 }
6633
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006634 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006635 synchronized(mWindowMap) {
6636 long ident = Binder.clearCallingIdentity();
6637 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006638 setWindowWallpaperPositionLocked(
6639 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006640 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006641 } finally {
6642 Binder.restoreCallingIdentity(ident);
6643 }
6644 }
6645 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006646
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006647 public void wallpaperOffsetsComplete(IBinder window) {
6648 WindowManagerService.this.wallpaperOffsetsComplete(window);
6649 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006650
Dianne Hackborn75804932009-10-20 20:15:20 -07006651 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6652 int z, Bundle extras, boolean sync) {
6653 synchronized(mWindowMap) {
6654 long ident = Binder.clearCallingIdentity();
6655 try {
6656 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006657 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006658 action, x, y, z, extras, sync);
6659 } finally {
6660 Binder.restoreCallingIdentity(ident);
6661 }
6662 }
6663 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006664
Dianne Hackborn75804932009-10-20 20:15:20 -07006665 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6666 WindowManagerService.this.wallpaperCommandComplete(window, result);
6667 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006669 void windowAddedLocked() {
6670 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006671 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006672 TAG, "First window added to " + this + ", creating SurfaceSession");
6673 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006674 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006675 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 mSessions.add(this);
6677 }
6678 mNumWindow++;
6679 }
6680
6681 void windowRemovedLocked() {
6682 mNumWindow--;
6683 killSessionLocked();
6684 }
Romain Guy06882f82009-06-10 13:36:04 -07006685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 void killSessionLocked() {
6687 if (mNumWindow <= 0 && mClientDead) {
6688 mSessions.remove(this);
6689 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006690 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006691 TAG, "Last window removed from " + this
6692 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006693 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006694 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006695 try {
6696 mSurfaceSession.kill();
6697 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006698 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 + mSurfaceSession + " in session " + this
6700 + ": " + e.toString());
6701 }
6702 mSurfaceSession = null;
6703 }
6704 }
6705 }
Romain Guy06882f82009-06-10 13:36:04 -07006706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006707 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006708 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6709 pw.print(" mClientDead="); pw.print(mClientDead);
6710 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006711 }
6712
6713 @Override
6714 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006715 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 }
6717 }
6718
6719 // -------------------------------------------------------------
6720 // Client Window State
6721 // -------------------------------------------------------------
6722
6723 private final class WindowState implements WindowManagerPolicy.WindowState {
6724 final Session mSession;
6725 final IWindow mClient;
6726 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006727 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 AppWindowToken mAppToken;
6729 AppWindowToken mTargetAppToken;
6730 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6731 final DeathRecipient mDeathRecipient;
6732 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006733 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 final int mBaseLayer;
6735 final int mSubLayer;
6736 final boolean mLayoutAttached;
6737 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006738 final boolean mIsWallpaper;
6739 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006740 int mViewVisibility;
6741 boolean mPolicyVisibility = true;
6742 boolean mPolicyVisibilityAfterAnim = true;
6743 boolean mAppFreezing;
6744 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006745 boolean mReportDestroySurface;
6746 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 boolean mAttachedHidden; // is our parent window hidden?
6748 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006749 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 int mRequestedWidth;
6751 int mRequestedHeight;
6752 int mLastRequestedWidth;
6753 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006754 int mLayer;
6755 int mAnimLayer;
6756 int mLastLayer;
6757 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006758 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006759 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006761 int mLayoutSeq = -1;
6762
6763 Configuration mConfiguration = null;
6764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 // Actual frame shown on-screen (may be modified by animation)
6766 final Rect mShownFrame = new Rect();
6767 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006770 * Set when we have changed the size of the surface, to know that
6771 * we must tell them application to resize (and thus redraw itself).
6772 */
6773 boolean mSurfaceResized;
6774
6775 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 * Insets that determine the actually visible area
6777 */
6778 final Rect mVisibleInsets = new Rect();
6779 final Rect mLastVisibleInsets = new Rect();
6780 boolean mVisibleInsetsChanged;
6781
6782 /**
6783 * Insets that are covered by system windows
6784 */
6785 final Rect mContentInsets = new Rect();
6786 final Rect mLastContentInsets = new Rect();
6787 boolean mContentInsetsChanged;
6788
6789 /**
6790 * Set to true if we are waiting for this window to receive its
6791 * given internal insets before laying out other windows based on it.
6792 */
6793 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006795 /**
6796 * These are the content insets that were given during layout for
6797 * this window, to be applied to windows behind it.
6798 */
6799 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006801 /**
6802 * These are the visible insets that were given during layout for
6803 * this window, to be applied to windows behind it.
6804 */
6805 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006808 * This is the given touchable area relative to the window frame, or null if none.
6809 */
6810 final Region mGivenTouchableRegion = new Region();
6811
6812 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006813 * Flag indicating whether the touchable region should be adjusted by
6814 * the visible insets; if false the area outside the visible insets is
6815 * NOT touchable, so we must use those to adjust the frame during hit
6816 * tests.
6817 */
6818 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006820 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006821 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006822 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6823 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6824 float mHScale=1, mVScale=1;
6825 float mLastHScale=1, mLastVScale=1;
6826 final Matrix mTmpMatrix = new Matrix();
6827
6828 // "Real" frame that the application sees.
6829 final Rect mFrame = new Rect();
6830 final Rect mLastFrame = new Rect();
6831
6832 final Rect mContainingFrame = new Rect();
6833 final Rect mDisplayFrame = new Rect();
6834 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006835 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 final Rect mVisibleFrame = new Rect();
6837
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006838 boolean mContentChanged;
6839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 float mShownAlpha = 1;
6841 float mAlpha = 1;
6842 float mLastAlpha = 1;
6843
6844 // Set to true if, when the window gets displayed, it should perform
6845 // an enter animation.
6846 boolean mEnterAnimationPending;
6847
6848 // Currently running animation.
6849 boolean mAnimating;
6850 boolean mLocalAnimating;
6851 Animation mAnimation;
6852 boolean mAnimationIsEntrance;
6853 boolean mHasTransformation;
6854 boolean mHasLocalTransformation;
6855 final Transformation mTransformation = new Transformation();
6856
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006857 // If a window showing a wallpaper: the requested offset for the
6858 // wallpaper; if a wallpaper window: the currently applied offset.
6859 float mWallpaperX = -1;
6860 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006861
6862 // If a window showing a wallpaper: what fraction of the offset
6863 // range corresponds to a full virtual screen.
6864 float mWallpaperXStep = -1;
6865 float mWallpaperYStep = -1;
6866
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006867 // Wallpaper windows: pixels offset based on above variables.
6868 int mXOffset;
6869 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 // This is set after IWindowSession.relayout() has been called at
6872 // least once for the window. It allows us to detect the situation
6873 // where we don't yet have a surface, but should have one soon, so
6874 // we can give the window focus before waiting for the relayout.
6875 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 // This is set after the Surface has been created but before the
6878 // window has been drawn. During this time the surface is hidden.
6879 boolean mDrawPending;
6880
6881 // This is set after the window has finished drawing for the first
6882 // time but before its surface is shown. The surface will be
6883 // displayed when the next layout is run.
6884 boolean mCommitDrawPending;
6885
6886 // This is set during the time after the window's drawing has been
6887 // committed, and before its surface is actually shown. It is used
6888 // to delay showing the surface until all windows in a token are ready
6889 // to be shown.
6890 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006892 // Set when the window has been shown in the screen the first time.
6893 boolean mHasDrawn;
6894
6895 // Currently running an exit animation?
6896 boolean mExiting;
6897
6898 // Currently on the mDestroySurface list?
6899 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 // Completely remove from window manager after exit animation?
6902 boolean mRemoveOnExit;
6903
6904 // Set when the orientation is changing and this window has not yet
6905 // been updated for the new orientation.
6906 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006908 // Is this window now (or just being) removed?
6909 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006910
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006911 // Temp for keeping track of windows that have been removed when
6912 // rebuilding window list.
6913 boolean mRebuilding;
6914
Dianne Hackborn16064f92010-03-25 00:47:24 -07006915 // For debugging, this is the last information given to the surface flinger.
6916 boolean mSurfaceShown;
6917 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6918 int mSurfaceLayer;
6919 float mSurfaceAlpha;
6920
Jeff Brown928e0542011-01-10 11:17:36 -08006921 // Input channel and input window handle used by the input dispatcher.
6922 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006923 InputChannel mInputChannel;
6924
Mattias Petersson1622eee2010-12-21 10:15:11 +01006925 // Used to improve performance of toString()
6926 String mStringNameCache;
6927 CharSequence mLastTitle;
6928 boolean mWasPaused;
6929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006930 WindowState(Session s, IWindow c, WindowToken token,
6931 WindowState attachedWindow, WindowManager.LayoutParams a,
6932 int viewVisibility) {
6933 mSession = s;
6934 mClient = c;
6935 mToken = token;
6936 mAttrs.copyFrom(a);
6937 mViewVisibility = viewVisibility;
6938 DeathRecipient deathRecipient = new DeathRecipient();
6939 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006940 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 TAG, "Window " + this + " client=" + c.asBinder()
6942 + " token=" + token + " (" + mAttrs.token + ")");
6943 try {
6944 c.asBinder().linkToDeath(deathRecipient, 0);
6945 } catch (RemoteException e) {
6946 mDeathRecipient = null;
6947 mAttachedWindow = null;
6948 mLayoutAttached = false;
6949 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006950 mIsWallpaper = false;
6951 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 mBaseLayer = 0;
6953 mSubLayer = 0;
6954 return;
6955 }
6956 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6959 mAttrs.type <= LAST_SUB_WINDOW)) {
6960 // The multiplier here is to reserve space for multiple
6961 // windows in the same type layer.
6962 mBaseLayer = mPolicy.windowTypeToLayerLw(
6963 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6964 + TYPE_LAYER_OFFSET;
6965 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6966 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006967 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 mAttachedWindow.mChildWindows.add(this);
6969 mLayoutAttached = mAttrs.type !=
6970 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6971 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6972 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006973 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6974 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 } else {
6976 // The multiplier here is to reserve space for multiple
6977 // windows in the same type layer.
6978 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6979 * TYPE_LAYER_MULTIPLIER
6980 + TYPE_LAYER_OFFSET;
6981 mSubLayer = 0;
6982 mAttachedWindow = null;
6983 mLayoutAttached = false;
6984 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6985 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006986 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6987 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006988 }
6989
6990 WindowState appWin = this;
6991 while (appWin.mAttachedWindow != null) {
6992 appWin = mAttachedWindow;
6993 }
6994 WindowToken appToken = appWin.mToken;
6995 while (appToken.appWindowToken == null) {
6996 WindowToken parent = mTokenMap.get(appToken.token);
6997 if (parent == null || appToken == parent) {
6998 break;
6999 }
7000 appToken = parent;
7001 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007002 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 mAppToken = appToken.appWindowToken;
7004
7005 mSurface = null;
7006 mRequestedWidth = 0;
7007 mRequestedHeight = 0;
7008 mLastRequestedWidth = 0;
7009 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007010 mXOffset = 0;
7011 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 mLayer = 0;
7013 mAnimLayer = 0;
7014 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007015 mInputWindowHandle = new InputWindowHandle(
7016 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007017 }
7018
7019 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007020 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007021 TAG, "Attaching " + this + " token=" + mToken
7022 + ", list=" + mToken.windows);
7023 mSession.windowAddedLocked();
7024 }
7025
7026 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7027 mHaveFrame = true;
7028
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007029 final Rect container = mContainingFrame;
7030 container.set(pf);
7031
7032 final Rect display = mDisplayFrame;
7033 display.set(df);
7034
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007035 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007036 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007037 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7038 display.intersect(mCompatibleScreenFrame);
7039 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007040 }
7041
7042 final int pw = container.right - container.left;
7043 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044
7045 int w,h;
7046 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7047 w = mAttrs.width < 0 ? pw : mAttrs.width;
7048 h = mAttrs.height< 0 ? ph : mAttrs.height;
7049 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007050 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7051 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007052 }
Romain Guy06882f82009-06-10 13:36:04 -07007053
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007054 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007055 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7056 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007057 mParentFrame.set(pf);
7058 mContentChanged = true;
7059 }
7060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 final Rect content = mContentFrame;
7062 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007064 final Rect visible = mVisibleFrame;
7065 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007068 final int fw = frame.width();
7069 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007071 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7072 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7073
7074 Gravity.apply(mAttrs.gravity, w, h, container,
7075 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7076 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7077
7078 //System.out.println("Out: " + mFrame);
7079
7080 // Now make sure the window fits in the overall display.
7081 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 // Make sure the content and visible frames are inside of the
7084 // final window frame.
7085 if (content.left < frame.left) content.left = frame.left;
7086 if (content.top < frame.top) content.top = frame.top;
7087 if (content.right > frame.right) content.right = frame.right;
7088 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7089 if (visible.left < frame.left) visible.left = frame.left;
7090 if (visible.top < frame.top) visible.top = frame.top;
7091 if (visible.right > frame.right) visible.right = frame.right;
7092 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 final Rect contentInsets = mContentInsets;
7095 contentInsets.left = content.left-frame.left;
7096 contentInsets.top = content.top-frame.top;
7097 contentInsets.right = frame.right-content.right;
7098 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007100 final Rect visibleInsets = mVisibleInsets;
7101 visibleInsets.left = visible.left-frame.left;
7102 visibleInsets.top = visible.top-frame.top;
7103 visibleInsets.right = frame.right-visible.right;
7104 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007105
Dianne Hackborn284ac932009-08-28 10:34:25 -07007106 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7107 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007108 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007109 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 if (localLOGV) {
7112 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7113 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007114 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 + mRequestedWidth + ", mRequestedheight="
7116 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7117 + "): frame=" + mFrame.toShortString()
7118 + " ci=" + contentInsets.toShortString()
7119 + " vi=" + visibleInsets.toShortString());
7120 //}
7121 }
7122 }
Romain Guy06882f82009-06-10 13:36:04 -07007123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007124 public Rect getFrameLw() {
7125 return mFrame;
7126 }
7127
7128 public Rect getShownFrameLw() {
7129 return mShownFrame;
7130 }
7131
7132 public Rect getDisplayFrameLw() {
7133 return mDisplayFrame;
7134 }
7135
7136 public Rect getContentFrameLw() {
7137 return mContentFrame;
7138 }
7139
7140 public Rect getVisibleFrameLw() {
7141 return mVisibleFrame;
7142 }
7143
7144 public boolean getGivenInsetsPendingLw() {
7145 return mGivenInsetsPending;
7146 }
7147
7148 public Rect getGivenContentInsetsLw() {
7149 return mGivenContentInsets;
7150 }
Romain Guy06882f82009-06-10 13:36:04 -07007151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 public Rect getGivenVisibleInsetsLw() {
7153 return mGivenVisibleInsets;
7154 }
Romain Guy06882f82009-06-10 13:36:04 -07007155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007156 public WindowManager.LayoutParams getAttrs() {
7157 return mAttrs;
7158 }
7159
7160 public int getSurfaceLayer() {
7161 return mLayer;
7162 }
Romain Guy06882f82009-06-10 13:36:04 -07007163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007164 public IApplicationToken getAppToken() {
7165 return mAppToken != null ? mAppToken.appToken : null;
7166 }
Jeff Brown349703e2010-06-22 01:27:15 -07007167
7168 public long getInputDispatchingTimeoutNanos() {
7169 return mAppToken != null
7170 ? mAppToken.inputDispatchingTimeoutNanos
7171 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7172 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007173
7174 public boolean hasAppShownWindows() {
7175 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7176 }
7177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007178 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007179 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007180 TAG, "Setting animation in " + this + ": " + anim);
7181 mAnimating = false;
7182 mLocalAnimating = false;
7183 mAnimation = anim;
7184 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7185 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7186 }
7187
7188 public void clearAnimation() {
7189 if (mAnimation != null) {
7190 mAnimating = true;
7191 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007192 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 mAnimation = null;
7194 }
7195 }
Romain Guy06882f82009-06-10 13:36:04 -07007196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007197 Surface createSurfaceLocked() {
7198 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007199 mReportDestroySurface = false;
7200 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007201 mDrawPending = true;
7202 mCommitDrawPending = false;
7203 mReadyToShow = false;
7204 if (mAppToken != null) {
7205 mAppToken.allDrawn = false;
7206 }
7207
7208 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007209
7210 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7211 flags |= Surface.SECURE;
7212 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007213 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007214 TAG, "Creating surface in session "
7215 + mSession.mSurfaceSession + " window " + this
7216 + " w=" + mFrame.width()
7217 + " h=" + mFrame.height() + " format="
7218 + mAttrs.format + " flags=" + flags);
7219
7220 int w = mFrame.width();
7221 int h = mFrame.height();
7222 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7223 // for a scaled surface, we always want the requested
7224 // size.
7225 w = mRequestedWidth;
7226 h = mRequestedHeight;
7227 }
7228
Romain Guy9825ec62009-10-01 00:58:09 -07007229 // Something is wrong and SurfaceFlinger will not like this,
7230 // try to revert to sane values
7231 if (w <= 0) w = 1;
7232 if (h <= 0) h = 1;
7233
Dianne Hackborn16064f92010-03-25 00:47:24 -07007234 mSurfaceShown = false;
7235 mSurfaceLayer = 0;
7236 mSurfaceAlpha = 1;
7237 mSurfaceX = 0;
7238 mSurfaceY = 0;
7239 mSurfaceW = w;
7240 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007241 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007242 final boolean isHwAccelerated = (mAttrs.flags &
7243 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7244 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7245 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7246 flags |= Surface.OPAQUE;
7247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007249 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007250 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007251 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007252 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007253 + mSurface + " IN SESSION "
7254 + mSession.mSurfaceSession
7255 + ": pid=" + mSession.mPid + " format="
7256 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007257 + Integer.toHexString(flags)
7258 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007260 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 reclaimSomeSurfaceMemoryLocked(this, "create");
7262 return null;
7263 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007264 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007265 return null;
7266 }
Romain Guy06882f82009-06-10 13:36:04 -07007267
Joe Onorato8a9b2202010-02-26 18:56:32 -08007268 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007269 TAG, "Got surface: " + mSurface
7270 + ", set left=" + mFrame.left + " top=" + mFrame.top
7271 + ", animLayer=" + mAnimLayer);
7272 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007273 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7274 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007275 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7276 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007277 }
7278 Surface.openTransaction();
7279 try {
7280 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007281 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007282 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007283 mSurface.setPosition(mSurfaceX, mSurfaceY);
7284 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007285 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007286 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 mSurface.hide();
7288 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007289 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 mSurface.setFlags(Surface.SURFACE_DITHER,
7291 Surface.SURFACE_DITHER);
7292 }
7293 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007294 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7296 }
7297 mLastHidden = true;
7298 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007300 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007302 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007303 TAG, "Created surface " + this);
7304 }
7305 return mSurface;
7306 }
Romain Guy06882f82009-06-10 13:36:04 -07007307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007308 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007309 if (mAppToken != null && this == mAppToken.startingWindow) {
7310 mAppToken.startingDisplayed = false;
7311 }
Romain Guy06882f82009-06-10 13:36:04 -07007312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007313 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007314 mDrawPending = false;
7315 mCommitDrawPending = false;
7316 mReadyToShow = false;
7317
7318 int i = mChildWindows.size();
7319 while (i > 0) {
7320 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007321 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007322 c.mAttachedHidden = true;
7323 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007324
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007325 if (mReportDestroySurface) {
7326 mReportDestroySurface = false;
7327 mSurfacePendingDestroy = true;
7328 try {
7329 mClient.dispatchGetNewSurface();
7330 // We'll really destroy on the next time around.
7331 return;
7332 } catch (RemoteException e) {
7333 }
7334 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007337 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007338 RuntimeException e = null;
7339 if (!HIDE_STACK_CRAWLS) {
7340 e = new RuntimeException();
7341 e.fillInStackTrace();
7342 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007343 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007344 + mSurface + ", session " + mSession, e);
7345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007347 RuntimeException e = null;
7348 if (!HIDE_STACK_CRAWLS) {
7349 e = new RuntimeException();
7350 e.fillInStackTrace();
7351 }
7352 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007354 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007355 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007356 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007357 + " surface " + mSurface + " session " + mSession
7358 + ": " + e.toString());
7359 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007360
Dianne Hackborn16064f92010-03-25 00:47:24 -07007361 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007363 }
7364 }
7365
7366 boolean finishDrawingLocked() {
7367 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007368 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 TAG, "finishDrawingLocked: " + mSurface);
7370 mCommitDrawPending = true;
7371 mDrawPending = false;
7372 return true;
7373 }
7374 return false;
7375 }
7376
7377 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007378 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007379 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007380 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007381 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 }
7383 mCommitDrawPending = false;
7384 mReadyToShow = true;
7385 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7386 final AppWindowToken atoken = mAppToken;
7387 if (atoken == null || atoken.allDrawn || starting) {
7388 performShowLocked();
7389 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007390 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007391 }
7392
7393 // This must be called while inside a transaction.
7394 boolean performShowLocked() {
7395 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007396 RuntimeException e = null;
7397 if (!HIDE_STACK_CRAWLS) {
7398 e = new RuntimeException();
7399 e.fillInStackTrace();
7400 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007401 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7403 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7404 }
7405 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007406 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7407 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007408 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 + " during animation: policyVis=" + mPolicyVisibility
7410 + " attHidden=" + mAttachedHidden
7411 + " tok.hiddenRequested="
7412 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007413 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007414 + (mAppToken != null ? mAppToken.hidden : false)
7415 + " animating=" + mAnimating
7416 + " tok animating="
7417 + (mAppToken != null ? mAppToken.animating : false));
7418 if (!showSurfaceRobustlyLocked(this)) {
7419 return false;
7420 }
7421 mLastAlpha = -1;
7422 mHasDrawn = true;
7423 mLastHidden = false;
7424 mReadyToShow = false;
7425 enableScreenIfNeededLocked();
7426
7427 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 int i = mChildWindows.size();
7430 while (i > 0) {
7431 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007432 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007433 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007434 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007435 if (c.mSurface != null) {
7436 c.performShowLocked();
7437 // It hadn't been shown, which means layout not
7438 // performed on it, so now we want to make sure to
7439 // do a layout. If called from within the transaction
7440 // loop, this will cause it to restart with a new
7441 // layout.
7442 mLayoutNeeded = true;
7443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 }
7445 }
Romain Guy06882f82009-06-10 13:36:04 -07007446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 if (mAttrs.type != TYPE_APPLICATION_STARTING
7448 && mAppToken != null) {
7449 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007450
Dianne Hackborn248b1882009-09-16 16:46:44 -07007451 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007452 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007453 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007455 // If this initial window is animating, stop it -- we
7456 // will do an animation to reveal it from behind the
7457 // starting window, so there is no need for it to also
7458 // be doing its own stuff.
7459 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007460 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007461 mAnimation = null;
7462 // Make sure we clean up the animation.
7463 mAnimating = true;
7464 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007465 mFinishedStarting.add(mAppToken);
7466 mH.sendEmptyMessage(H.FINISHED_STARTING);
7467 }
7468 mAppToken.updateReportedVisibilityLocked();
7469 }
7470 }
7471 return true;
7472 }
Romain Guy06882f82009-06-10 13:36:04 -07007473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 // This must be called while inside a transaction. Returns true if
7475 // there is more animation to run.
7476 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007477 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7481 mHasTransformation = true;
7482 mHasLocalTransformation = true;
7483 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007484 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007485 TAG, "Starting animation in " + this +
7486 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7487 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7488 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7489 mAnimation.setStartTime(currentTime);
7490 mLocalAnimating = true;
7491 mAnimating = true;
7492 }
7493 mTransformation.clear();
7494 final boolean more = mAnimation.getTransformation(
7495 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007496 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 TAG, "Stepped animation in " + this +
7498 ": more=" + more + ", xform=" + mTransformation);
7499 if (more) {
7500 // we're not done!
7501 return true;
7502 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007503 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007504 TAG, "Finished animation in " + this +
7505 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007506
7507 if (mAnimation != null) {
7508 mAnimation.cancel();
7509 mAnimation = null;
7510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 //WindowManagerService.this.dump();
7512 }
7513 mHasLocalTransformation = false;
7514 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007515 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 // When our app token is animating, we kind-of pretend like
7517 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7518 // part of this check means that we will only do this if
7519 // our window is not currently exiting, or it is not
7520 // locally animating itself. The idea being that one that
7521 // is exiting and doing a local animation should be removed
7522 // once that animation is done.
7523 mAnimating = true;
7524 mHasTransformation = true;
7525 mTransformation.clear();
7526 return false;
7527 } else if (mHasTransformation) {
7528 // Little trick to get through the path below to act like
7529 // we have finished an animation.
7530 mAnimating = true;
7531 } else if (isAnimating()) {
7532 mAnimating = true;
7533 }
7534 } else if (mAnimation != null) {
7535 // If the display is frozen, and there is a pending animation,
7536 // clear it and make sure we run the cleanup code.
7537 mAnimating = true;
7538 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007539 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 mAnimation = null;
7541 }
Romain Guy06882f82009-06-10 13:36:04 -07007542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 if (!mAnimating && !mLocalAnimating) {
7544 return false;
7545 }
7546
Joe Onorato8a9b2202010-02-26 18:56:32 -08007547 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007548 TAG, "Animation done in " + this + ": exiting=" + mExiting
7549 + ", reportedVisible="
7550 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007552 mAnimating = false;
7553 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007554 if (mAnimation != null) {
7555 mAnimation.cancel();
7556 mAnimation = null;
7557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 mAnimLayer = mLayer;
7559 if (mIsImWindow) {
7560 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007561 } else if (mIsWallpaper) {
7562 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007564 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 + " anim layer: " + mAnimLayer);
7566 mHasTransformation = false;
7567 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007568 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7569 if (DEBUG_VISIBILITY) {
7570 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7571 + mPolicyVisibilityAfterAnim);
7572 }
7573 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7574 if (!mPolicyVisibility) {
7575 if (mCurrentFocus == this) {
7576 mFocusMayChange = true;
7577 }
7578 // Window is no longer visible -- make sure if we were waiting
7579 // for it to be displayed before enabling the display, that
7580 // we allow the display to be enabled now.
7581 enableScreenIfNeededLocked();
7582 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 mTransformation.clear();
7585 if (mHasDrawn
7586 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7587 && mAppToken != null
7588 && mAppToken.firstWindowDrawn
7589 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007590 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 + mToken + ": first real window done animating");
7592 mFinishedStarting.add(mAppToken);
7593 mH.sendEmptyMessage(H.FINISHED_STARTING);
7594 }
Romain Guy06882f82009-06-10 13:36:04 -07007595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596 finishExit();
7597
7598 if (mAppToken != null) {
7599 mAppToken.updateReportedVisibilityLocked();
7600 }
7601
7602 return false;
7603 }
7604
7605 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007606 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 TAG, "finishExit in " + this
7608 + ": exiting=" + mExiting
7609 + " remove=" + mRemoveOnExit
7610 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 final int N = mChildWindows.size();
7613 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007614 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007615 }
Romain Guy06882f82009-06-10 13:36:04 -07007616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 if (!mExiting) {
7618 return;
7619 }
Romain Guy06882f82009-06-10 13:36:04 -07007620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 if (isWindowAnimating()) {
7622 return;
7623 }
7624
Joe Onorato8a9b2202010-02-26 18:56:32 -08007625 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 TAG, "Exit animation finished in " + this
7627 + ": remove=" + mRemoveOnExit);
7628 if (mSurface != null) {
7629 mDestroySurface.add(this);
7630 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007631 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007632 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007633 try {
7634 mSurface.hide();
7635 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007636 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007637 }
7638 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 }
7640 mExiting = false;
7641 if (mRemoveOnExit) {
7642 mPendingRemove.add(this);
7643 mRemoveOnExit = false;
7644 }
7645 }
Romain Guy06882f82009-06-10 13:36:04 -07007646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007647 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7648 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7649 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7650 if (dtdx < -.000001f || dtdx > .000001f) return false;
7651 if (dsdy < -.000001f || dsdy > .000001f) return false;
7652 return true;
7653 }
Romain Guy06882f82009-06-10 13:36:04 -07007654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007655 void computeShownFrameLocked() {
7656 final boolean selfTransformation = mHasLocalTransformation;
7657 Transformation attachedTransformation =
7658 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7659 ? mAttachedWindow.mTransformation : null;
7660 Transformation appTransformation =
7661 (mAppToken != null && mAppToken.hasTransformation)
7662 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007663
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007664 // Wallpapers are animated based on the "real" window they
7665 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007666 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007667 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007668 if (mWallpaperTarget.mHasLocalTransformation &&
7669 mWallpaperTarget.mAnimation != null &&
7670 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007671 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007672 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007673 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007674 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007675 }
7676 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007677 mWallpaperTarget.mAppToken.hasTransformation &&
7678 mWallpaperTarget.mAppToken.animation != null &&
7679 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007680 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007681 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007682 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007683 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007684 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007685 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007686
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007687 final boolean screenAnimation = mScreenRotationAnimation != null
7688 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007690 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007691 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007692 final Rect frame = mFrame;
7693 final float tmpFloats[] = mTmpFloats;
7694 final Matrix tmpMatrix = mTmpMatrix;
7695
7696 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007697 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007699 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007700 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007701 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007703 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 }
7705 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007706 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007707 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007708 if (screenAnimation) {
7709 tmpMatrix.postConcat(
7710 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7711 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007712
7713 // "convert" it into SurfaceFlinger's format
7714 // (a 2x2 matrix + an offset)
7715 // Here we must not transform the position of the surface
7716 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007717 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007718
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007719 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007720 tmpMatrix.getValues(tmpFloats);
7721 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007722 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7723 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007725 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7726 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007727 int w = frame.width();
7728 int h = frame.height();
7729 mShownFrame.set(x, y, x+w, y+h);
7730
7731 // Now set the alpha... but because our current hardware
7732 // can't do alpha transformation on a non-opaque surface,
7733 // turn it off if we are running an animation that is also
7734 // transforming since it is more important to have that
7735 // animation be smooth.
7736 mShownAlpha = mAlpha;
7737 if (!mLimitedAlphaCompositing
7738 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7739 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7740 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007741 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007742 if (selfTransformation) {
7743 mShownAlpha *= mTransformation.getAlpha();
7744 }
7745 if (attachedTransformation != null) {
7746 mShownAlpha *= attachedTransformation.getAlpha();
7747 }
7748 if (appTransformation != null) {
7749 mShownAlpha *= appTransformation.getAlpha();
7750 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007751 if (screenAnimation) {
7752 mShownAlpha *=
7753 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7754 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007755 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007756 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007757 }
Romain Guy06882f82009-06-10 13:36:04 -07007758
Joe Onorato8a9b2202010-02-26 18:56:32 -08007759 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007760 TAG, "Continuing animation in " + this +
7761 ": " + mShownFrame +
7762 ", alpha=" + mTransformation.getAlpha());
7763 return;
7764 }
Romain Guy06882f82009-06-10 13:36:04 -07007765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007766 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007767 if (mXOffset != 0 || mYOffset != 0) {
7768 mShownFrame.offset(mXOffset, mYOffset);
7769 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007771 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007772 mDsDx = 1;
7773 mDtDx = 0;
7774 mDsDy = 0;
7775 mDtDy = 1;
7776 }
Romain Guy06882f82009-06-10 13:36:04 -07007777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007778 /**
7779 * Is this window visible? It is not visible if there is no
7780 * surface, or we are in the process of running an exit animation
7781 * that will remove the surface, or its app token has been hidden.
7782 */
7783 public boolean isVisibleLw() {
7784 final AppWindowToken atoken = mAppToken;
7785 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7786 && (atoken == null || !atoken.hiddenRequested)
7787 && !mExiting && !mDestroying;
7788 }
7789
7790 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007791 * Like {@link #isVisibleLw}, but also counts a window that is currently
7792 * "hidden" behind the keyguard as visible. This allows us to apply
7793 * things like window flags that impact the keyguard.
7794 * XXX I am starting to think we need to have ANOTHER visibility flag
7795 * for this "hidden behind keyguard" state rather than overloading
7796 * mPolicyVisibility. Ungh.
7797 */
7798 public boolean isVisibleOrBehindKeyguardLw() {
7799 final AppWindowToken atoken = mAppToken;
7800 return mSurface != null && !mAttachedHidden
7801 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007802 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007803 && !mExiting && !mDestroying;
7804 }
7805
7806 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 * Is this window visible, ignoring its app token? It is not visible
7808 * if there is no surface, or we are in the process of running an exit animation
7809 * that will remove the surface.
7810 */
7811 public boolean isWinVisibleLw() {
7812 final AppWindowToken atoken = mAppToken;
7813 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7814 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7815 && !mExiting && !mDestroying;
7816 }
7817
7818 /**
7819 * The same as isVisible(), but follows the current hidden state of
7820 * the associated app token, not the pending requested hidden state.
7821 */
7822 boolean isVisibleNow() {
7823 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007824 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007825 }
7826
7827 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007828 * Can this window possibly be a drag/drop target? The test here is
7829 * a combination of the above "visible now" with the check that the
7830 * Input Manager uses when discarding windows from input consideration.
7831 */
7832 boolean isPotentialDragTarget() {
7833 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7834 }
7835
7836 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007837 * Same as isVisible(), but we also count it as visible between the
7838 * call to IWindowSession.add() and the first relayout().
7839 */
7840 boolean isVisibleOrAdding() {
7841 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007842 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007843 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7844 && mPolicyVisibility && !mAttachedHidden
7845 && (atoken == null || !atoken.hiddenRequested)
7846 && !mExiting && !mDestroying;
7847 }
7848
7849 /**
7850 * Is this window currently on-screen? It is on-screen either if it
7851 * is visible or it is currently running an animation before no longer
7852 * being visible.
7853 */
7854 boolean isOnScreen() {
7855 final AppWindowToken atoken = mAppToken;
7856 if (atoken != null) {
7857 return mSurface != null && mPolicyVisibility && !mDestroying
7858 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007859 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007860 } else {
7861 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007862 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007863 }
7864 }
Romain Guy06882f82009-06-10 13:36:04 -07007865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 /**
7867 * Like isOnScreen(), but we don't return true if the window is part
7868 * of a transition that has not yet been started.
7869 */
7870 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007871 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007872 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007873 return false;
7874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007875 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007876 final boolean animating = atoken != null
7877 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007878 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007879 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7880 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007881 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007882 }
7883
7884 /** Is the window or its container currently animating? */
7885 boolean isAnimating() {
7886 final WindowState attached = mAttachedWindow;
7887 final AppWindowToken atoken = mAppToken;
7888 return mAnimation != null
7889 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007890 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007891 (atoken.animation != null
7892 || atoken.inPendingTransaction));
7893 }
7894
7895 /** Is this window currently animating? */
7896 boolean isWindowAnimating() {
7897 return mAnimation != null;
7898 }
7899
7900 /**
7901 * Like isOnScreen, but returns false if the surface hasn't yet
7902 * been drawn.
7903 */
7904 public boolean isDisplayedLw() {
7905 final AppWindowToken atoken = mAppToken;
7906 return mSurface != null && mPolicyVisibility && !mDestroying
7907 && !mDrawPending && !mCommitDrawPending
7908 && ((!mAttachedHidden &&
7909 (atoken == null || !atoken.hiddenRequested))
7910 || mAnimating);
7911 }
7912
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007913 /**
7914 * Returns true if the window has a surface that it has drawn a
7915 * complete UI in to.
7916 */
7917 public boolean isDrawnLw() {
7918 final AppWindowToken atoken = mAppToken;
7919 return mSurface != null && !mDestroying
7920 && !mDrawPending && !mCommitDrawPending;
7921 }
7922
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007923 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007924 * Return true if the window is opaque and fully drawn. This indicates
7925 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007926 */
7927 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007928 return (mAttrs.format == PixelFormat.OPAQUE
7929 || mAttrs.type == TYPE_WALLPAPER)
7930 && mSurface != null && mAnimation == null
7931 && (mAppToken == null || mAppToken.animation == null)
7932 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007933 }
7934
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007935 /**
7936 * Return whether this window is wanting to have a translation
7937 * animation applied to it for an in-progress move. (Only makes
7938 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7939 */
7940 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007941 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007942 && (mFrame.top != mLastFrame.top
7943 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007944 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007945 && mPolicy.isScreenOn();
7946 }
7947
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007948 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7949 return
7950 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007951 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7952 // only if it's visible
7953 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007954 // and only if the application fills the compatible screen
7955 mFrame.left <= mCompatibleScreenFrame.left &&
7956 mFrame.top <= mCompatibleScreenFrame.top &&
7957 mFrame.right >= mCompatibleScreenFrame.right &&
7958 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007959 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007960 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007961 }
7962
7963 boolean isFullscreen(int screenWidth, int screenHeight) {
7964 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007965 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007966 }
7967
7968 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007969 disposeInputChannel();
7970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007971 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007972 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 mAttachedWindow.mChildWindows.remove(this);
7974 }
7975 destroySurfaceLocked();
7976 mSession.windowRemovedLocked();
7977 try {
7978 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7979 } catch (RuntimeException e) {
7980 // Ignore if it has already been removed (usually because
7981 // we are doing this as part of processing a death note.)
7982 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007983 }
7984
7985 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007986 if (mInputChannel != null) {
7987 mInputManager.unregisterInputChannel(mInputChannel);
7988
7989 mInputChannel.dispose();
7990 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007991 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007992 }
7993
7994 private class DeathRecipient implements IBinder.DeathRecipient {
7995 public void binderDied() {
7996 try {
7997 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007998 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007999 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008000 if (win != null) {
8001 removeWindowLocked(mSession, win);
8002 }
8003 }
8004 } catch (IllegalArgumentException ex) {
8005 // This will happen if the window has already been
8006 // removed.
8007 }
8008 }
8009 }
8010
8011 /** Returns true if this window desires key events. */
8012 public final boolean canReceiveKeys() {
8013 return isVisibleOrAdding()
8014 && (mViewVisibility == View.VISIBLE)
8015 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8016 }
8017
8018 public boolean hasDrawnLw() {
8019 return mHasDrawn;
8020 }
8021
8022 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008023 return showLw(doAnimation, true);
8024 }
8025
8026 boolean showLw(boolean doAnimation, boolean requestAnim) {
8027 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8028 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008029 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008030 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008031 if (doAnimation) {
8032 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8033 + mPolicyVisibility + " mAnimation=" + mAnimation);
8034 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8035 doAnimation = false;
8036 } else if (mPolicyVisibility && mAnimation == null) {
8037 // Check for the case where we are currently visible and
8038 // not animating; we do not want to do animation at such a
8039 // point to become visible when we already are.
8040 doAnimation = false;
8041 }
8042 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008043 mPolicyVisibility = true;
8044 mPolicyVisibilityAfterAnim = true;
8045 if (doAnimation) {
8046 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8047 }
8048 if (requestAnim) {
8049 requestAnimationLocked(0);
8050 }
8051 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008052 }
8053
8054 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008055 return hideLw(doAnimation, true);
8056 }
8057
8058 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008059 if (doAnimation) {
8060 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8061 doAnimation = false;
8062 }
8063 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008064 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8065 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008066 if (!current) {
8067 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008068 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008069 if (doAnimation) {
8070 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8071 if (mAnimation == null) {
8072 doAnimation = false;
8073 }
8074 }
8075 if (doAnimation) {
8076 mPolicyVisibilityAfterAnim = false;
8077 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008078 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008079 mPolicyVisibilityAfterAnim = false;
8080 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008081 // Window is no longer visible -- make sure if we were waiting
8082 // for it to be displayed before enabling the display, that
8083 // we allow the display to be enabled now.
8084 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008085 if (mCurrentFocus == this) {
8086 mFocusMayChange = true;
8087 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008088 }
8089 if (requestAnim) {
8090 requestAnimationLocked(0);
8091 }
8092 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008093 }
8094
Jeff Brownfbf09772011-01-16 14:06:57 -08008095 public void getTouchableRegion(Region outRegion) {
8096 final Rect frame = mFrame;
8097 switch (mTouchableInsets) {
8098 default:
8099 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8100 outRegion.set(frame);
8101 break;
8102 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8103 final Rect inset = mGivenContentInsets;
8104 outRegion.set(
8105 frame.left + inset.left, frame.top + inset.top,
8106 frame.right - inset.right, frame.bottom - inset.bottom);
8107 break;
8108 }
8109 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8110 final Rect inset = mGivenVisibleInsets;
8111 outRegion.set(
8112 frame.left + inset.left, frame.top + inset.top,
8113 frame.right - inset.right, frame.bottom - inset.bottom);
8114 break;
8115 }
8116 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8117 final Region givenTouchableRegion = mGivenTouchableRegion;
8118 outRegion.set(givenTouchableRegion);
8119 outRegion.translate(frame.left, frame.top);
8120 break;
8121 }
8122 }
8123 }
8124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008126 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8127 pw.print(" mClient="); pw.println(mClient.asBinder());
8128 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8129 if (mAttachedWindow != null || mLayoutAttached) {
8130 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8131 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8132 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008133 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8134 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8135 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008136 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8137 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008138 }
8139 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8140 pw.print(" mSubLayer="); pw.print(mSubLayer);
8141 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8142 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8143 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8144 pw.print("="); pw.print(mAnimLayer);
8145 pw.print(" mLastLayer="); pw.println(mLastLayer);
8146 if (mSurface != null) {
8147 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008148 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8149 pw.print(" layer="); pw.print(mSurfaceLayer);
8150 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8151 pw.print(" rect=("); pw.print(mSurfaceX);
8152 pw.print(","); pw.print(mSurfaceY);
8153 pw.print(") "); pw.print(mSurfaceW);
8154 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008155 }
8156 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8157 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8158 if (mAppToken != null) {
8159 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8160 }
8161 if (mTargetAppToken != null) {
8162 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8163 }
8164 pw.print(prefix); pw.print("mViewVisibility=0x");
8165 pw.print(Integer.toHexString(mViewVisibility));
8166 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008167 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8168 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008169 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8170 pw.print(prefix); pw.print("mPolicyVisibility=");
8171 pw.print(mPolicyVisibility);
8172 pw.print(" mPolicyVisibilityAfterAnim=");
8173 pw.print(mPolicyVisibilityAfterAnim);
8174 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8175 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008176 if (!mRelayoutCalled) {
8177 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8178 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008179 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008180 pw.print(" h="); pw.print(mRequestedHeight);
8181 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008182 if (mXOffset != 0 || mYOffset != 0) {
8183 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8184 pw.print(" y="); pw.println(mYOffset);
8185 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008186 pw.print(prefix); pw.print("mGivenContentInsets=");
8187 mGivenContentInsets.printShortString(pw);
8188 pw.print(" mGivenVisibleInsets=");
8189 mGivenVisibleInsets.printShortString(pw);
8190 pw.println();
8191 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8192 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8193 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8194 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008195 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008196 pw.print(prefix); pw.print("mShownFrame=");
8197 mShownFrame.printShortString(pw);
8198 pw.print(" last="); mLastShownFrame.printShortString(pw);
8199 pw.println();
8200 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8201 pw.print(" last="); mLastFrame.printShortString(pw);
8202 pw.println();
8203 pw.print(prefix); pw.print("mContainingFrame=");
8204 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008205 pw.print(" mParentFrame=");
8206 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008207 pw.print(" mDisplayFrame=");
8208 mDisplayFrame.printShortString(pw);
8209 pw.println();
8210 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8211 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8212 pw.println();
8213 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8214 pw.print(" last="); mLastContentInsets.printShortString(pw);
8215 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8216 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8217 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008218 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8219 || mAnimation != null) {
8220 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8221 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8222 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8223 pw.print(" mAnimation="); pw.println(mAnimation);
8224 }
8225 if (mHasTransformation || mHasLocalTransformation) {
8226 pw.print(prefix); pw.print("XForm: has=");
8227 pw.print(mHasTransformation);
8228 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8229 pw.print(" "); mTransformation.printShortString(pw);
8230 pw.println();
8231 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008232 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8233 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8234 pw.print(" mAlpha="); pw.print(mAlpha);
8235 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8236 }
8237 if (mHaveMatrix) {
8238 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8239 pw.print(" mDtDx="); pw.print(mDtDx);
8240 pw.print(" mDsDy="); pw.print(mDsDy);
8241 pw.print(" mDtDy="); pw.println(mDtDy);
8242 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008243 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8244 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8245 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8246 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8247 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8248 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8249 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8250 pw.print(" mDestroying="); pw.print(mDestroying);
8251 pw.print(" mRemoved="); pw.println(mRemoved);
8252 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008253 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008254 pw.print(prefix); pw.print("mOrientationChanging=");
8255 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008256 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8257 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008258 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008259 if (mHScale != 1 || mVScale != 1) {
8260 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8261 pw.print(" mVScale="); pw.println(mVScale);
8262 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008263 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008264 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8265 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8266 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008267 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8268 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8269 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8270 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008271 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008272
8273 String makeInputChannelName() {
8274 return Integer.toHexString(System.identityHashCode(this))
8275 + " " + mAttrs.getTitle();
8276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008277
8278 @Override
8279 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008280 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8281 || mWasPaused != mToken.paused) {
8282 mLastTitle = mAttrs.getTitle();
8283 mWasPaused = mToken.paused;
8284 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8285 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8286 }
8287 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008288 }
8289 }
Romain Guy06882f82009-06-10 13:36:04 -07008290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008291 // -------------------------------------------------------------
8292 // Window Token State
8293 // -------------------------------------------------------------
8294
8295 class WindowToken {
8296 // The actual token.
8297 final IBinder token;
8298
8299 // The type of window this token is for, as per WindowManager.LayoutParams.
8300 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008302 // Set if this token was explicitly added by a client, so should
8303 // not be removed when all windows are removed.
8304 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008305
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008306 // For printing.
8307 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008309 // If this is an AppWindowToken, this is non-null.
8310 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008312 // All of the windows associated with this token.
8313 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8314
8315 // Is key dispatching paused for this token?
8316 boolean paused = false;
8317
8318 // Should this token's windows be hidden?
8319 boolean hidden;
8320
8321 // Temporary for finding which tokens no longer have visible windows.
8322 boolean hasVisible;
8323
Dianne Hackborna8f60182009-09-01 19:01:50 -07008324 // Set to true when this token is in a pending transaction where it
8325 // will be shown.
8326 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008327
Dianne Hackborna8f60182009-09-01 19:01:50 -07008328 // Set to true when this token is in a pending transaction where it
8329 // will be hidden.
8330 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008331
Dianne Hackborna8f60182009-09-01 19:01:50 -07008332 // Set to true when this token is in a pending transaction where its
8333 // windows will be put to the bottom of the list.
8334 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008335
Dianne Hackborna8f60182009-09-01 19:01:50 -07008336 // Set to true when this token is in a pending transaction where its
8337 // windows will be put to the top of the list.
8338 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 WindowToken(IBinder _token, int type, boolean _explicit) {
8341 token = _token;
8342 windowType = type;
8343 explicit = _explicit;
8344 }
8345
8346 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008347 pw.print(prefix); pw.print("token="); pw.println(token);
8348 pw.print(prefix); pw.print("windows="); pw.println(windows);
8349 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8350 pw.print(" hidden="); pw.print(hidden);
8351 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008352 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8353 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8354 pw.print(" waitingToHide="); pw.print(waitingToHide);
8355 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8356 pw.print(" sendingToTop="); pw.println(sendingToTop);
8357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008358 }
8359
8360 @Override
8361 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008362 if (stringName == null) {
8363 StringBuilder sb = new StringBuilder();
8364 sb.append("WindowToken{");
8365 sb.append(Integer.toHexString(System.identityHashCode(this)));
8366 sb.append(" token="); sb.append(token); sb.append('}');
8367 stringName = sb.toString();
8368 }
8369 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008370 }
8371 };
8372
8373 class AppWindowToken extends WindowToken {
8374 // Non-null only for application tokens.
8375 final IApplicationToken appToken;
8376
8377 // All of the windows and child windows that are included in this
8378 // application token. Note this list is NOT sorted!
8379 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8380
8381 int groupId = -1;
8382 boolean appFullscreen;
8383 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008384
8385 // The input dispatching timeout for this application token in nanoseconds.
8386 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008388 // These are used for determining when all windows associated with
8389 // an activity have been drawn, so they can be made visible together
8390 // at the same time.
8391 int lastTransactionSequence = mTransactionSequence-1;
8392 int numInterestingWindows;
8393 int numDrawnWindows;
8394 boolean inPendingTransaction;
8395 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 // Is this token going to be hidden in a little while? If so, it
8398 // won't be taken into account for setting the screen orientation.
8399 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008401 // Is this window's surface needed? This is almost like hidden, except
8402 // it will sometimes be true a little earlier: when the token has
8403 // been shown, but is still waiting for its app transition to execute
8404 // before making its windows shown.
8405 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008407 // Have we told the window clients to hide themselves?
8408 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008410 // Last visibility state we reported to the app token.
8411 boolean reportedVisible;
8412
8413 // Set to true when the token has been removed from the window mgr.
8414 boolean removed;
8415
8416 // Have we been asked to have this token keep the screen frozen?
8417 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008419 boolean animating;
8420 Animation animation;
8421 boolean hasTransformation;
8422 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008424 // Offset to the window of all layers in the token, for use by
8425 // AppWindowToken animations.
8426 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008428 // Information about an application starting window if displayed.
8429 StartingData startingData;
8430 WindowState startingWindow;
8431 View startingView;
8432 boolean startingDisplayed;
8433 boolean startingMoved;
8434 boolean firstWindowDrawn;
8435
Jeff Brown928e0542011-01-10 11:17:36 -08008436 // Input application handle used by the input dispatcher.
8437 InputApplicationHandle mInputApplicationHandle;
8438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008439 AppWindowToken(IApplicationToken _token) {
8440 super(_token.asBinder(),
8441 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8442 appWindowToken = this;
8443 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008444 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008445 }
Romain Guy06882f82009-06-10 13:36:04 -07008446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008448 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008449 TAG, "Setting animation in " + this + ": " + anim);
8450 animation = anim;
8451 animating = false;
8452 anim.restrictDuration(MAX_ANIMATION_DURATION);
8453 anim.scaleCurrentDuration(mTransitionAnimationScale);
8454 int zorder = anim.getZAdjustment();
8455 int adj = 0;
8456 if (zorder == Animation.ZORDER_TOP) {
8457 adj = TYPE_LAYER_OFFSET;
8458 } else if (zorder == Animation.ZORDER_BOTTOM) {
8459 adj = -TYPE_LAYER_OFFSET;
8460 }
Romain Guy06882f82009-06-10 13:36:04 -07008461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 if (animLayerAdjustment != adj) {
8463 animLayerAdjustment = adj;
8464 updateLayers();
8465 }
8466 }
Romain Guy06882f82009-06-10 13:36:04 -07008467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008468 public void setDummyAnimation() {
8469 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008470 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008471 TAG, "Setting dummy animation in " + this);
8472 animation = sDummyAnimation;
8473 }
8474 }
8475
8476 public void clearAnimation() {
8477 if (animation != null) {
8478 animation = null;
8479 animating = true;
8480 }
8481 }
Romain Guy06882f82009-06-10 13:36:04 -07008482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008483 void updateLayers() {
8484 final int N = allAppWindows.size();
8485 final int adj = animLayerAdjustment;
8486 for (int i=0; i<N; i++) {
8487 WindowState w = allAppWindows.get(i);
8488 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008489 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008490 + w.mAnimLayer);
8491 if (w == mInputMethodTarget) {
8492 setInputMethodAnimLayerAdjustment(adj);
8493 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008494 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008495 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008496 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008497 }
8498 }
Romain Guy06882f82009-06-10 13:36:04 -07008499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008500 void sendAppVisibilityToClients() {
8501 final int N = allAppWindows.size();
8502 for (int i=0; i<N; i++) {
8503 WindowState win = allAppWindows.get(i);
8504 if (win == startingWindow && clientHidden) {
8505 // Don't hide the starting window.
8506 continue;
8507 }
8508 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008509 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008510 "Setting visibility of " + win + ": " + (!clientHidden));
8511 win.mClient.dispatchAppVisibility(!clientHidden);
8512 } catch (RemoteException e) {
8513 }
8514 }
8515 }
Romain Guy06882f82009-06-10 13:36:04 -07008516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008517 void showAllWindowsLocked() {
8518 final int NW = allAppWindows.size();
8519 for (int i=0; i<NW; i++) {
8520 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008521 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008522 "performing show on: " + w);
8523 w.performShowLocked();
8524 }
8525 }
Romain Guy06882f82009-06-10 13:36:04 -07008526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527 // This must be called while inside a transaction.
8528 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008529 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008532 if (animation == sDummyAnimation) {
8533 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008534 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 // when it is really time to animate, this will be set to
8536 // a real animation and the next call will execute normally.
8537 return false;
8538 }
Romain Guy06882f82009-06-10 13:36:04 -07008539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8541 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008542 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008543 TAG, "Starting animation in " + this +
8544 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8545 + " scale=" + mTransitionAnimationScale
8546 + " allDrawn=" + allDrawn + " animating=" + animating);
8547 animation.initialize(dw, dh, dw, dh);
8548 animation.setStartTime(currentTime);
8549 animating = true;
8550 }
8551 transformation.clear();
8552 final boolean more = animation.getTransformation(
8553 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008554 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008555 TAG, "Stepped animation in " + this +
8556 ": more=" + more + ", xform=" + transformation);
8557 if (more) {
8558 // we're done!
8559 hasTransformation = true;
8560 return true;
8561 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008562 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008563 TAG, "Finished animation in " + this +
8564 " @ " + currentTime);
8565 animation = null;
8566 }
8567 } else if (animation != null) {
8568 // If the display is frozen, and there is a pending animation,
8569 // clear it and make sure we run the cleanup code.
8570 animating = true;
8571 animation = null;
8572 }
8573
8574 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008576 if (!animating) {
8577 return false;
8578 }
8579
8580 clearAnimation();
8581 animating = false;
8582 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8583 moveInputMethodWindowsIfNeededLocked(true);
8584 }
Romain Guy06882f82009-06-10 13:36:04 -07008585
Joe Onorato8a9b2202010-02-26 18:56:32 -08008586 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 TAG, "Animation done in " + this
8588 + ": reportedVisible=" + reportedVisible);
8589
8590 transformation.clear();
8591 if (animLayerAdjustment != 0) {
8592 animLayerAdjustment = 0;
8593 updateLayers();
8594 }
Romain Guy06882f82009-06-10 13:36:04 -07008595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 final int N = windows.size();
8597 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008598 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 }
8600 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008602 return false;
8603 }
8604
8605 void updateReportedVisibilityLocked() {
8606 if (appToken == null) {
8607 return;
8608 }
Romain Guy06882f82009-06-10 13:36:04 -07008609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008610 int numInteresting = 0;
8611 int numVisible = 0;
8612 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008613
Joe Onorato8a9b2202010-02-26 18:56:32 -08008614 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008615 final int N = allAppWindows.size();
8616 for (int i=0; i<N; i++) {
8617 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008618 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008619 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008620 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8621 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008622 continue;
8623 }
8624 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008625 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008626 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008628 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008629 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 + " pv=" + win.mPolicyVisibility
8631 + " dp=" + win.mDrawPending
8632 + " cdp=" + win.mCommitDrawPending
8633 + " ah=" + win.mAttachedHidden
8634 + " th="
8635 + (win.mAppToken != null
8636 ? win.mAppToken.hiddenRequested : false)
8637 + " a=" + win.mAnimating);
8638 }
8639 }
8640 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008641 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008642 if (!win.isAnimating()) {
8643 numVisible++;
8644 }
8645 nowGone = false;
8646 } else if (win.isAnimating()) {
8647 nowGone = false;
8648 }
8649 }
Romain Guy06882f82009-06-10 13:36:04 -07008650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008651 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008652 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 + numInteresting + " visible=" + numVisible);
8654 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008655 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008656 TAG, "Visibility changed in " + this
8657 + ": vis=" + nowVisible);
8658 reportedVisible = nowVisible;
8659 Message m = mH.obtainMessage(
8660 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8661 nowVisible ? 1 : 0,
8662 nowGone ? 1 : 0,
8663 this);
8664 mH.sendMessage(m);
8665 }
8666 }
Romain Guy06882f82009-06-10 13:36:04 -07008667
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008668 WindowState findMainWindow() {
8669 int j = windows.size();
8670 while (j > 0) {
8671 j--;
8672 WindowState win = windows.get(j);
8673 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8674 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8675 return win;
8676 }
8677 }
8678 return null;
8679 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 void dump(PrintWriter pw, String prefix) {
8682 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008683 if (appToken != null) {
8684 pw.print(prefix); pw.println("app=true");
8685 }
8686 if (allAppWindows.size() > 0) {
8687 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8688 }
8689 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008690 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008691 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8692 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8693 pw.print(" clientHidden="); pw.print(clientHidden);
8694 pw.print(" willBeHidden="); pw.print(willBeHidden);
8695 pw.print(" reportedVisible="); pw.println(reportedVisible);
8696 if (paused || freezingScreen) {
8697 pw.print(prefix); pw.print("paused="); pw.print(paused);
8698 pw.print(" freezingScreen="); pw.println(freezingScreen);
8699 }
8700 if (numInterestingWindows != 0 || numDrawnWindows != 0
8701 || inPendingTransaction || allDrawn) {
8702 pw.print(prefix); pw.print("numInterestingWindows=");
8703 pw.print(numInterestingWindows);
8704 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8705 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8706 pw.print(" allDrawn="); pw.println(allDrawn);
8707 }
8708 if (animating || animation != null) {
8709 pw.print(prefix); pw.print("animating="); pw.print(animating);
8710 pw.print(" animation="); pw.println(animation);
8711 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008712 if (hasTransformation) {
8713 pw.print(prefix); pw.print("XForm: ");
8714 transformation.printShortString(pw);
8715 pw.println();
8716 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008717 if (animLayerAdjustment != 0) {
8718 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8719 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008720 if (startingData != null || removed || firstWindowDrawn) {
8721 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8722 pw.print(" removed="); pw.print(removed);
8723 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8724 }
8725 if (startingWindow != null || startingView != null
8726 || startingDisplayed || startingMoved) {
8727 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8728 pw.print(" startingView="); pw.print(startingView);
8729 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8730 pw.print(" startingMoved"); pw.println(startingMoved);
8731 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008732 }
8733
8734 @Override
8735 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008736 if (stringName == null) {
8737 StringBuilder sb = new StringBuilder();
8738 sb.append("AppWindowToken{");
8739 sb.append(Integer.toHexString(System.identityHashCode(this)));
8740 sb.append(" token="); sb.append(token); sb.append('}');
8741 stringName = sb.toString();
8742 }
8743 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008744 }
8745 }
Romain Guy06882f82009-06-10 13:36:04 -07008746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008747 // -------------------------------------------------------------
8748 // DummyAnimation
8749 // -------------------------------------------------------------
8750
8751 // This is an animation that does nothing: it just immediately finishes
8752 // itself every time it is called. It is used as a stub animation in cases
8753 // where we want to synchronize multiple things that may be animating.
8754 static final class DummyAnimation extends Animation {
8755 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8756 return false;
8757 }
8758 }
8759 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008761 // -------------------------------------------------------------
8762 // Async Handler
8763 // -------------------------------------------------------------
8764
8765 static final class StartingData {
8766 final String pkg;
8767 final int theme;
8768 final CharSequence nonLocalizedLabel;
8769 final int labelRes;
8770 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008771 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008773 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008774 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008775 pkg = _pkg;
8776 theme = _theme;
8777 nonLocalizedLabel = _nonLocalizedLabel;
8778 labelRes = _labelRes;
8779 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008780 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008781 }
8782 }
8783
8784 private final class H extends Handler {
8785 public static final int REPORT_FOCUS_CHANGE = 2;
8786 public static final int REPORT_LOSING_FOCUS = 3;
8787 public static final int ANIMATE = 4;
8788 public static final int ADD_STARTING = 5;
8789 public static final int REMOVE_STARTING = 6;
8790 public static final int FINISHED_STARTING = 7;
8791 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8793 public static final int HOLD_SCREEN_CHANGED = 12;
8794 public static final int APP_TRANSITION_TIMEOUT = 13;
8795 public static final int PERSIST_ANIMATION_SCALE = 14;
8796 public static final int FORCE_GC = 15;
8797 public static final int ENABLE_SCREEN = 16;
8798 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008799 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008800 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008801 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008802 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008806 public H() {
8807 }
Romain Guy06882f82009-06-10 13:36:04 -07008808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008809 @Override
8810 public void handleMessage(Message msg) {
8811 switch (msg.what) {
8812 case REPORT_FOCUS_CHANGE: {
8813 WindowState lastFocus;
8814 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008816 synchronized(mWindowMap) {
8817 lastFocus = mLastFocus;
8818 newFocus = mCurrentFocus;
8819 if (lastFocus == newFocus) {
8820 // Focus is not changing, so nothing to do.
8821 return;
8822 }
8823 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008824 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008825 // + " to " + newFocus);
8826 if (newFocus != null && lastFocus != null
8827 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008828 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008829 mLosingFocus.add(lastFocus);
8830 lastFocus = null;
8831 }
8832 }
8833
8834 if (lastFocus != newFocus) {
8835 //System.out.println("Changing focus from " + lastFocus
8836 // + " to " + newFocus);
8837 if (newFocus != null) {
8838 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008839 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008840 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8841 } catch (RemoteException e) {
8842 // Ignore if process has died.
8843 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008844 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008845 }
8846
8847 if (lastFocus != null) {
8848 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008849 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008850 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8851 } catch (RemoteException e) {
8852 // Ignore if process has died.
8853 }
8854 }
8855 }
8856 } break;
8857
8858 case REPORT_LOSING_FOCUS: {
8859 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008861 synchronized(mWindowMap) {
8862 losers = mLosingFocus;
8863 mLosingFocus = new ArrayList<WindowState>();
8864 }
8865
8866 final int N = losers.size();
8867 for (int i=0; i<N; i++) {
8868 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008869 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008870 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8871 } catch (RemoteException e) {
8872 // Ignore if process has died.
8873 }
8874 }
8875 } break;
8876
8877 case ANIMATE: {
8878 synchronized(mWindowMap) {
8879 mAnimationPending = false;
8880 performLayoutAndPlaceSurfacesLocked();
8881 }
8882 } break;
8883
8884 case ADD_STARTING: {
8885 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8886 final StartingData sd = wtoken.startingData;
8887
8888 if (sd == null) {
8889 // Animation has been canceled... do nothing.
8890 return;
8891 }
Romain Guy06882f82009-06-10 13:36:04 -07008892
Joe Onorato8a9b2202010-02-26 18:56:32 -08008893 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008894 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008896 View view = null;
8897 try {
8898 view = mPolicy.addStartingWindow(
8899 wtoken.token, sd.pkg,
8900 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008901 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008902 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008903 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008904 }
8905
8906 if (view != null) {
8907 boolean abort = false;
8908
8909 synchronized(mWindowMap) {
8910 if (wtoken.removed || wtoken.startingData == null) {
8911 // If the window was successfully added, then
8912 // we need to remove it.
8913 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008914 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008915 "Aborted starting " + wtoken
8916 + ": removed=" + wtoken.removed
8917 + " startingData=" + wtoken.startingData);
8918 wtoken.startingWindow = null;
8919 wtoken.startingData = null;
8920 abort = true;
8921 }
8922 } else {
8923 wtoken.startingView = view;
8924 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008925 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008926 "Added starting " + wtoken
8927 + ": startingWindow="
8928 + wtoken.startingWindow + " startingView="
8929 + wtoken.startingView);
8930 }
8931
8932 if (abort) {
8933 try {
8934 mPolicy.removeStartingWindow(wtoken.token, view);
8935 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008936 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008937 }
8938 }
8939 }
8940 } break;
8941
8942 case REMOVE_STARTING: {
8943 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8944 IBinder token = null;
8945 View view = null;
8946 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008947 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008948 + wtoken + ": startingWindow="
8949 + wtoken.startingWindow + " startingView="
8950 + wtoken.startingView);
8951 if (wtoken.startingWindow != null) {
8952 view = wtoken.startingView;
8953 token = wtoken.token;
8954 wtoken.startingData = null;
8955 wtoken.startingView = null;
8956 wtoken.startingWindow = null;
8957 }
8958 }
8959 if (view != null) {
8960 try {
8961 mPolicy.removeStartingWindow(token, view);
8962 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008963 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008964 }
8965 }
8966 } break;
8967
8968 case FINISHED_STARTING: {
8969 IBinder token = null;
8970 View view = null;
8971 while (true) {
8972 synchronized (mWindowMap) {
8973 final int N = mFinishedStarting.size();
8974 if (N <= 0) {
8975 break;
8976 }
8977 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8978
Joe Onorato8a9b2202010-02-26 18:56:32 -08008979 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008980 "Finished starting " + wtoken
8981 + ": startingWindow=" + wtoken.startingWindow
8982 + " startingView=" + wtoken.startingView);
8983
8984 if (wtoken.startingWindow == null) {
8985 continue;
8986 }
8987
8988 view = wtoken.startingView;
8989 token = wtoken.token;
8990 wtoken.startingData = null;
8991 wtoken.startingView = null;
8992 wtoken.startingWindow = null;
8993 }
8994
8995 try {
8996 mPolicy.removeStartingWindow(token, view);
8997 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008998 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008999 }
9000 }
9001 } break;
9002
9003 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9004 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9005
9006 boolean nowVisible = msg.arg1 != 0;
9007 boolean nowGone = msg.arg2 != 0;
9008
9009 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009010 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009011 TAG, "Reporting visible in " + wtoken
9012 + " visible=" + nowVisible
9013 + " gone=" + nowGone);
9014 if (nowVisible) {
9015 wtoken.appToken.windowsVisible();
9016 } else {
9017 wtoken.appToken.windowsGone();
9018 }
9019 } catch (RemoteException ex) {
9020 }
9021 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009023 case WINDOW_FREEZE_TIMEOUT: {
9024 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009025 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009026 int i = mWindows.size();
9027 while (i > 0) {
9028 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009029 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009030 if (w.mOrientationChanging) {
9031 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009032 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009033 }
9034 }
9035 performLayoutAndPlaceSurfacesLocked();
9036 }
9037 break;
9038 }
Romain Guy06882f82009-06-10 13:36:04 -07009039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009040 case HOLD_SCREEN_CHANGED: {
9041 Session oldHold;
9042 Session newHold;
9043 synchronized (mWindowMap) {
9044 oldHold = mLastReportedHold;
9045 newHold = (Session)msg.obj;
9046 mLastReportedHold = newHold;
9047 }
Romain Guy06882f82009-06-10 13:36:04 -07009048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009049 if (oldHold != newHold) {
9050 try {
9051 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009052 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009053 "window",
9054 BatteryStats.WAKE_TYPE_WINDOW);
9055 }
9056 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009057 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009058 "window",
9059 BatteryStats.WAKE_TYPE_WINDOW);
9060 }
9061 } catch (RemoteException e) {
9062 }
9063 }
9064 break;
9065 }
Romain Guy06882f82009-06-10 13:36:04 -07009066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009067 case APP_TRANSITION_TIMEOUT: {
9068 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009069 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009070 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009071 "*** APP TRANSITION TIMEOUT");
9072 mAppTransitionReady = true;
9073 mAppTransitionTimeout = true;
9074 performLayoutAndPlaceSurfacesLocked();
9075 }
9076 }
9077 break;
9078 }
Romain Guy06882f82009-06-10 13:36:04 -07009079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009080 case PERSIST_ANIMATION_SCALE: {
9081 Settings.System.putFloat(mContext.getContentResolver(),
9082 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9083 Settings.System.putFloat(mContext.getContentResolver(),
9084 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9085 break;
9086 }
Romain Guy06882f82009-06-10 13:36:04 -07009087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009088 case FORCE_GC: {
9089 synchronized(mWindowMap) {
9090 if (mAnimationPending) {
9091 // If we are animating, don't do the gc now but
9092 // delay a bit so we don't interrupt the animation.
9093 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9094 2000);
9095 return;
9096 }
9097 // If we are currently rotating the display, it will
9098 // schedule a new message when done.
9099 if (mDisplayFrozen) {
9100 return;
9101 }
9102 mFreezeGcPending = 0;
9103 }
9104 Runtime.getRuntime().gc();
9105 break;
9106 }
Romain Guy06882f82009-06-10 13:36:04 -07009107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009108 case ENABLE_SCREEN: {
9109 performEnableScreen();
9110 break;
9111 }
Romain Guy06882f82009-06-10 13:36:04 -07009112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009113 case APP_FREEZE_TIMEOUT: {
9114 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009115 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009116 int i = mAppTokens.size();
9117 while (i > 0) {
9118 i--;
9119 AppWindowToken tok = mAppTokens.get(i);
9120 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009121 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009122 unsetAppFreezingScreenLocked(tok, true, true);
9123 }
9124 }
9125 }
9126 break;
9127 }
Romain Guy06882f82009-06-10 13:36:04 -07009128
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009129 case SEND_NEW_CONFIGURATION: {
9130 removeMessages(SEND_NEW_CONFIGURATION);
9131 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009132 break;
9133 }
Romain Guy06882f82009-06-10 13:36:04 -07009134
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009135 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009136 if (mWindowsChanged) {
9137 synchronized (mWindowMap) {
9138 mWindowsChanged = false;
9139 }
9140 notifyWindowsChanged();
9141 }
9142 break;
9143 }
9144
Christopher Tatea53146c2010-09-07 11:57:52 -07009145 case DRAG_START_TIMEOUT: {
9146 IBinder win = (IBinder)msg.obj;
9147 if (DEBUG_DRAG) {
9148 Slog.w(TAG, "Timeout starting drag by win " + win);
9149 }
9150 synchronized (mWindowMap) {
9151 // !!! TODO: ANR the app that has failed to start the drag in time
9152 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009153 mDragState.unregister();
9154 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009155 mDragState.reset();
9156 mDragState = null;
9157 }
9158 }
Chris Tated4533f142010-10-19 15:15:08 -07009159 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009160 }
9161
Chris Tated4533f142010-10-19 15:15:08 -07009162 case DRAG_END_TIMEOUT: {
9163 IBinder win = (IBinder)msg.obj;
9164 if (DEBUG_DRAG) {
9165 Slog.w(TAG, "Timeout ending drag to win " + win);
9166 }
9167 synchronized (mWindowMap) {
9168 // !!! TODO: ANR the drag-receiving app
9169 mDragState.mDragResult = false;
9170 mDragState.endDragLw();
9171 }
9172 break;
9173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 }
9175 }
9176 }
9177
9178 // -------------------------------------------------------------
9179 // IWindowManager API
9180 // -------------------------------------------------------------
9181
9182 public IWindowSession openSession(IInputMethodClient client,
9183 IInputContext inputContext) {
9184 if (client == null) throw new IllegalArgumentException("null client");
9185 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009186 Session session = new Session(client, inputContext);
9187 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009188 }
9189
9190 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9191 synchronized (mWindowMap) {
9192 // The focus for the client is the window immediately below
9193 // where we would place the input method window.
9194 int idx = findDesiredInputMethodWindowIndexLocked(false);
9195 WindowState imFocus;
9196 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009197 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009198 if (imFocus != null) {
9199 if (imFocus.mSession.mClient != null &&
9200 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9201 return true;
9202 }
9203 }
9204 }
9205 }
9206 return false;
9207 }
Romain Guy06882f82009-06-10 13:36:04 -07009208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009209 // -------------------------------------------------------------
9210 // Internals
9211 // -------------------------------------------------------------
9212
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009213 final WindowState windowForClientLocked(Session session, IWindow client,
9214 boolean throwOnError) {
9215 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009216 }
Romain Guy06882f82009-06-10 13:36:04 -07009217
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009218 final WindowState windowForClientLocked(Session session, IBinder client,
9219 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009220 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009221 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 TAG, "Looking up client " + client + ": " + win);
9223 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009224 RuntimeException ex = new IllegalArgumentException(
9225 "Requested window " + client + " does not exist");
9226 if (throwOnError) {
9227 throw ex;
9228 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009229 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009230 return null;
9231 }
9232 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009233 RuntimeException ex = new IllegalArgumentException(
9234 "Requested window " + client + " is in session " +
9235 win.mSession + ", not " + session);
9236 if (throwOnError) {
9237 throw ex;
9238 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009239 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009240 return null;
9241 }
9242
9243 return win;
9244 }
9245
Dianne Hackborna8f60182009-09-01 19:01:50 -07009246 final void rebuildAppWindowListLocked() {
9247 int NW = mWindows.size();
9248 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009249 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009250 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009251
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009252 if (mRebuildTmp.length < NW) {
9253 mRebuildTmp = new WindowState[NW+10];
9254 }
9255
Dianne Hackborna8f60182009-09-01 19:01:50 -07009256 // First remove all existing app windows.
9257 i=0;
9258 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009259 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009260 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009261 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009262 win.mRebuilding = true;
9263 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009264 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009265 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009266 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009267 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009268 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009269 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009270 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9271 && lastWallpaper == i-1) {
9272 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009273 }
9274 i++;
9275 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009276
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009277 // The wallpaper window(s) typically live at the bottom of the stack,
9278 // so skip them before adding app tokens.
9279 lastWallpaper++;
9280 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009281
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009282 // First add all of the exiting app tokens... these are no longer
9283 // in the main app list, but still have windows shown. We put them
9284 // in the back because now that the animation is over we no longer
9285 // will care about them.
9286 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009287 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009288 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9289 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009290
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009291 // And add in the still active app tokens in Z order.
9292 NT = mAppTokens.size();
9293 for (int j=0; j<NT; j++) {
9294 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009295 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009296
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009297 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009298 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009299 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009300 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009301 for (i=0; i<numRemoved; i++) {
9302 WindowState ws = mRebuildTmp[i];
9303 if (ws.mRebuilding) {
9304 StringWriter sw = new StringWriter();
9305 PrintWriter pw = new PrintWriter(sw);
9306 ws.dump(pw, "");
9307 pw.flush();
9308 Slog.w(TAG, "This window was lost: " + ws);
9309 Slog.w(TAG, sw.toString());
9310 }
9311 }
9312 Slog.w(TAG, "Current app token list:");
9313 dumpAppTokensLocked();
9314 Slog.w(TAG, "Final window list:");
9315 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009316 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009317 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009319 private final void assignLayersLocked() {
9320 int N = mWindows.size();
9321 int curBaseLayer = 0;
9322 int curLayer = 0;
9323 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009324
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009325 if (DEBUG_LAYERS) {
9326 RuntimeException here = new RuntimeException("here");
9327 here.fillInStackTrace();
9328 Log.v(TAG, "Assigning layers", here);
9329 }
9330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009331 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009332 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009333 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9334 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335 curLayer += WINDOW_LAYER_MULTIPLIER;
9336 w.mLayer = curLayer;
9337 } else {
9338 curBaseLayer = curLayer = w.mBaseLayer;
9339 w.mLayer = curLayer;
9340 }
9341 if (w.mTargetAppToken != null) {
9342 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9343 } else if (w.mAppToken != null) {
9344 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9345 } else {
9346 w.mAnimLayer = w.mLayer;
9347 }
9348 if (w.mIsImWindow) {
9349 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009350 } else if (w.mIsWallpaper) {
9351 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009352 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009353 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354 + w.mAnimLayer);
9355 //System.out.println(
9356 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9357 }
9358 }
9359
9360 private boolean mInLayout = false;
9361 private final void performLayoutAndPlaceSurfacesLocked() {
9362 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009363 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009364 throw new RuntimeException("Recursive call!");
9365 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009366 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009367 return;
9368 }
9369
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009370 if (mWaitingForConfig) {
9371 // Our configuration has changed (most likely rotation), but we
9372 // don't yet have the complete configuration to report to
9373 // applications. Don't do any window layout until we have it.
9374 return;
9375 }
9376
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009377 if (mDisplay == null) {
9378 // Not yet initialized, nothing to do.
9379 return;
9380 }
9381
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009382 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009384
9385 try {
9386 if (mForceRemoves != null) {
9387 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009388 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009389 for (int i=0; i<mForceRemoves.size(); i++) {
9390 WindowState ws = mForceRemoves.get(i);
9391 Slog.i(TAG, "Force removing: " + ws);
9392 removeWindowInnerLocked(ws.mSession, ws);
9393 }
9394 mForceRemoves = null;
9395 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9396 Object tmp = new Object();
9397 synchronized (tmp) {
9398 try {
9399 tmp.wait(250);
9400 } catch (InterruptedException e) {
9401 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009402 }
9403 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009404 } catch (RuntimeException e) {
9405 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009406 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009408 try {
9409 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009410
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009411 int N = mPendingRemove.size();
9412 if (N > 0) {
9413 if (mPendingRemoveTmp.length < N) {
9414 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009415 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009416 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009418 for (int i=0; i<N; i++) {
9419 WindowState w = mPendingRemoveTmp[i];
9420 removeWindowInnerLocked(w.mSession, w);
9421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422
9423 mInLayout = false;
9424 assignLayersLocked();
9425 mLayoutNeeded = true;
9426 performLayoutAndPlaceSurfacesLocked();
9427
9428 } else {
9429 mInLayout = false;
9430 if (mLayoutNeeded) {
9431 requestAnimationLocked(0);
9432 }
9433 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009434 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009435 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9436 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009437 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009438 } catch (RuntimeException e) {
9439 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009440 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009441 }
9442 }
9443
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009444 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009445 if (!mLayoutNeeded) {
9446 return 0;
9447 }
9448
9449 mLayoutNeeded = false;
9450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009451 final int dw = mDisplay.getWidth();
9452 final int dh = mDisplay.getHeight();
9453
9454 final int N = mWindows.size();
9455 int i;
9456
Joe Onorato8a9b2202010-02-26 18:56:32 -08009457 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009458 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9459
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009460 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009461
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009462 int seq = mLayoutSeq+1;
9463 if (seq < 0) seq = 0;
9464 mLayoutSeq = seq;
9465
9466 // First perform layout of any root windows (not attached
9467 // to another window).
9468 int topAttached = -1;
9469 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009470 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009471
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009472 // Don't do layout of a window if it is not visible, or
9473 // soon won't be visible, to avoid wasting time and funky
9474 // changes while a window is animating away.
9475 final AppWindowToken atoken = win.mAppToken;
9476 final boolean gone = win.mViewVisibility == View.GONE
9477 || !win.mRelayoutCalled
9478 || win.mRootToken.hidden
9479 || (atoken != null && atoken.hiddenRequested)
9480 || win.mAttachedHidden
9481 || win.mExiting || win.mDestroying;
9482
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009483 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9484 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009485 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9486 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009487 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009488 + win.mViewVisibility + " mRelayoutCalled="
9489 + win.mRelayoutCalled + " hidden="
9490 + win.mRootToken.hidden + " hiddenRequested="
9491 + (atoken != null && atoken.hiddenRequested)
9492 + " mAttachedHidden=" + win.mAttachedHidden);
9493 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009494
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009495 // If this view is GONE, then skip it -- keep the current
9496 // frame, and let the caller know so they can ignore it
9497 // if they want. (We do the normal layout for INVISIBLE
9498 // windows, since that means "perform layout as normal,
9499 // just don't display").
9500 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009501 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009502 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009503 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009504 win.mContentChanged = false;
9505 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009506 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9507 win.mLayoutSeq = seq;
9508 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9509 + win.mFrame + " mContainingFrame="
9510 + win.mContainingFrame + " mDisplayFrame="
9511 + win.mDisplayFrame);
9512 } else {
9513 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009514 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009517
9518 // Now perform layout of attached windows, which usually
9519 // depend on the position of the window they are attached to.
9520 // XXX does not deal with windows that are attached to windows
9521 // that are themselves attached.
9522 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009523 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009524
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009525 if (win.mLayoutAttached) {
9526 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9527 + " mHaveFrame=" + win.mHaveFrame
9528 + " mViewVisibility=" + win.mViewVisibility
9529 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009530 // If this view is GONE, then skip it -- keep the current
9531 // frame, and let the caller know so they can ignore it
9532 // if they want. (We do the normal layout for INVISIBLE
9533 // windows, since that means "perform layout as normal,
9534 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009535 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9536 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009537 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009538 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009539 win.mContentChanged = false;
9540 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009541 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9542 win.mLayoutSeq = seq;
9543 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9544 + win.mFrame + " mContainingFrame="
9545 + win.mContainingFrame + " mDisplayFrame="
9546 + win.mDisplayFrame);
9547 }
9548 }
9549 }
Jeff Brown349703e2010-06-22 01:27:15 -07009550
9551 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009552 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009553
9554 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009555 }
Romain Guy06882f82009-06-10 13:36:04 -07009556
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009557 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 private final void performLayoutAndPlaceSurfacesLockedInner(
9559 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009560 if (mDisplay == null) {
9561 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9562 return;
9563 }
9564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 final long currentTime = SystemClock.uptimeMillis();
9566 final int dw = mDisplay.getWidth();
9567 final int dh = mDisplay.getHeight();
9568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009569 int i;
9570
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009571 if (mFocusMayChange) {
9572 mFocusMayChange = false;
9573 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9574 }
9575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009576 // Initialize state of exiting tokens.
9577 for (i=mExitingTokens.size()-1; i>=0; i--) {
9578 mExitingTokens.get(i).hasVisible = false;
9579 }
9580
9581 // Initialize state of exiting applications.
9582 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9583 mExitingAppTokens.get(i).hasVisible = false;
9584 }
9585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 boolean orientationChangeComplete = true;
9587 Session holdScreen = null;
9588 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009589 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009590 boolean focusDisplayed = false;
9591 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009592 boolean createWatermark = false;
9593
9594 if (mFxSession == null) {
9595 mFxSession = new SurfaceSession();
9596 createWatermark = true;
9597 }
9598
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009599 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600
9601 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009602
9603 if (createWatermark) {
9604 createWatermark();
9605 }
9606 if (mWatermark != null) {
9607 mWatermark.positionSurface(dw, dh);
9608 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009609 if (mStrictModeFlash != null) {
9610 mStrictModeFlash.positionSurface(dw, dh);
9611 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009614 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009615 int repeats = 0;
9616 int changes = 0;
9617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009618 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009619 repeats++;
9620 if (repeats > 6) {
9621 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9622 mLayoutNeeded = false;
9623 break;
9624 }
9625
9626 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9627 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9628 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9629 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9630 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9631 assignLayersLocked();
9632 mLayoutNeeded = true;
9633 }
9634 }
9635 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9636 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009637 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009638 mLayoutNeeded = true;
9639 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9640 }
9641 }
9642 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9643 mLayoutNeeded = true;
9644 }
9645 }
9646
9647 // FIRST LOOP: Perform a layout, if needed.
9648 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009649 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009650 if (changes != 0) {
9651 continue;
9652 }
9653 } else {
9654 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9655 changes = 0;
9656 }
9657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009658 final int transactionSequence = ++mTransactionSequence;
9659
9660 // Update animations of all applications, including those
9661 // associated with exiting/removed apps
9662 boolean tokensAnimating = false;
9663 final int NAT = mAppTokens.size();
9664 for (i=0; i<NAT; i++) {
9665 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9666 tokensAnimating = true;
9667 }
9668 }
9669 final int NEAT = mExitingAppTokens.size();
9670 for (i=0; i<NEAT; i++) {
9671 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9672 tokensAnimating = true;
9673 }
9674 }
9675
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009676 // SECOND LOOP: Execute animations and update visibility of windows.
9677
Joe Onorato8a9b2202010-02-26 18:56:32 -08009678 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009679 + transactionSequence + " tokensAnimating="
9680 + tokensAnimating);
9681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009682 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009683
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009684 if (mScreenRotationAnimation != null) {
9685 if (mScreenRotationAnimation.isAnimating()) {
9686 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9687 animating = true;
9688 } else {
9689 mScreenRotationAnimation = null;
9690 }
9691 }
9692 }
9693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009694 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009695 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009696 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009697 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009698
9699 mPolicy.beginAnimationLw(dw, dh);
9700
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009701 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009703 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009704 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009705
9706 final WindowManager.LayoutParams attrs = w.mAttrs;
9707
9708 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009709 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009710 if (w.commitFinishDrawingLocked(currentTime)) {
9711 if ((w.mAttrs.flags
9712 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009713 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009714 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009715 wallpaperMayChange = true;
9716 }
9717 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009718
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009719 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009720
9721 int animDw = dw;
9722 int animDh = dh;
9723
9724 // If the window has moved due to its containing
9725 // content frame changing, then we'd like to animate
9726 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009727 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009728 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009729 // Frame has moved, containing content frame
9730 // has also moved, and we're not currently animating...
9731 // let's do something.
9732 Animation a = AnimationUtils.loadAnimation(mContext,
9733 com.android.internal.R.anim.window_move_from_decor);
9734 w.setAnimation(a);
9735 animDw = w.mLastFrame.left - w.mFrame.left;
9736 animDh = w.mLastFrame.top - w.mFrame.top;
9737 }
9738
9739 // Execute animation.
9740 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9741 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009742
9743 // If this window is animating, make a note that we have
9744 // an animating window and take care of a request to run
9745 // a detached wallpaper animation.
9746 if (nowAnimating) {
9747 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9748 windowDetachedWallpaper = w;
9749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009750 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009751 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009752
9753 // If this window's app token is running a detached wallpaper
9754 // animation, make a note so we can ensure the wallpaper is
9755 // displayed behind it.
9756 if (w.mAppToken != null && w.mAppToken.animation != null
9757 && w.mAppToken.animation.getDetachWallpaper()) {
9758 windowDetachedWallpaper = w;
9759 }
9760
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009761 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9762 wallpaperMayChange = true;
9763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009764
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009765 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009766 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009767 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009768 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009769 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009770 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009771 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009772 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9773 forceHiding = true;
9774 }
9775 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9776 boolean changed;
9777 if (forceHiding) {
9778 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009779 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9780 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009781 } else {
9782 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009783 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9784 "Now policy shown: " + w);
9785 if (changed) {
9786 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009787 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009788 // Assume we will need to animate. If
9789 // we don't (because the wallpaper will
9790 // stay with the lock screen), then we will
9791 // clean up later.
9792 Animation a = mPolicy.createForceHideEnterAnimation();
9793 if (a != null) {
9794 w.setAnimation(a);
9795 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009796 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009797 if (mCurrentFocus == null ||
9798 mCurrentFocus.mLayer < w.mLayer) {
9799 // We are showing on to of the current
9800 // focus, so re-evaluate focus to make
9801 // sure it is correct.
9802 mFocusMayChange = true;
9803 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009804 }
9805 }
9806 if (changed && (attrs.flags
9807 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9808 wallpaperMayChange = true;
9809 }
9810 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 mPolicy.animatingWindowLw(w, attrs);
9813 }
9814
9815 final AppWindowToken atoken = w.mAppToken;
9816 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9817 if (atoken.lastTransactionSequence != transactionSequence) {
9818 atoken.lastTransactionSequence = transactionSequence;
9819 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9820 atoken.startingDisplayed = false;
9821 }
9822 if ((w.isOnScreen() || w.mAttrs.type
9823 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9824 && !w.mExiting && !w.mDestroying) {
9825 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009826 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009827 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009828 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009829 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009830 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009831 + " pv=" + w.mPolicyVisibility
9832 + " dp=" + w.mDrawPending
9833 + " cdp=" + w.mCommitDrawPending
9834 + " ah=" + w.mAttachedHidden
9835 + " th=" + atoken.hiddenRequested
9836 + " a=" + w.mAnimating);
9837 }
9838 }
9839 if (w != atoken.startingWindow) {
9840 if (!atoken.freezingScreen || !w.mAppFreezing) {
9841 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009842 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009843 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009844 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009845 "tokenMayBeDrawn: " + atoken
9846 + " freezingScreen=" + atoken.freezingScreen
9847 + " mAppFreezing=" + w.mAppFreezing);
9848 tokenMayBeDrawn = true;
9849 }
9850 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009851 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009852 atoken.startingDisplayed = true;
9853 }
9854 }
9855 } else if (w.mReadyToShow) {
9856 w.performShowLocked();
9857 }
9858 }
9859
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009860 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009861
9862 if (tokenMayBeDrawn) {
9863 // See if any windows have been drawn, so they (and others
9864 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009865 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009866 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009867 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 if (wtoken.freezingScreen) {
9869 int numInteresting = wtoken.numInterestingWindows;
9870 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009871 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 "allDrawn: " + wtoken
9873 + " interesting=" + numInteresting
9874 + " drawn=" + wtoken.numDrawnWindows);
9875 wtoken.showAllWindowsLocked();
9876 unsetAppFreezingScreenLocked(wtoken, false, true);
9877 orientationChangeComplete = true;
9878 }
9879 } else if (!wtoken.allDrawn) {
9880 int numInteresting = wtoken.numInterestingWindows;
9881 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009882 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883 "allDrawn: " + wtoken
9884 + " interesting=" + numInteresting
9885 + " drawn=" + wtoken.numDrawnWindows);
9886 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009887 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009888
9889 // We can now show all of the drawn windows!
9890 if (!mOpeningApps.contains(wtoken)) {
9891 wtoken.showAllWindowsLocked();
9892 }
9893 }
9894 }
9895 }
9896 }
9897
9898 // If we are ready to perform an app transition, check through
9899 // all of the app tokens to be shown and see if they are ready
9900 // to go.
9901 if (mAppTransitionReady) {
9902 int NN = mOpeningApps.size();
9903 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009904 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 "Checking " + NN + " opening apps (frozen="
9906 + mDisplayFrozen + " timeout="
9907 + mAppTransitionTimeout + ")...");
9908 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9909 // If the display isn't frozen, wait to do anything until
9910 // all of the apps are ready. Otherwise just go because
9911 // we'll unfreeze the display when everyone is ready.
9912 for (i=0; i<NN && goodToGo; i++) {
9913 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009914 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 "Check opening app" + wtoken + ": allDrawn="
9916 + wtoken.allDrawn + " startingDisplayed="
9917 + wtoken.startingDisplayed);
9918 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9919 && !wtoken.startingMoved) {
9920 goodToGo = false;
9921 }
9922 }
9923 }
9924 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009925 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009926 int transit = mNextAppTransition;
9927 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009928 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009930 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009931 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009932 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009933 mAppTransitionTimeout = false;
9934 mStartingIconInTransition = false;
9935 mSkipAppTransitionAnimation = false;
9936
9937 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9938
Dianne Hackborna8f60182009-09-01 19:01:50 -07009939 // If there are applications waiting to come to the
9940 // top of the stack, now is the time to move their windows.
9941 // (Note that we don't do apps going to the bottom
9942 // here -- we want to keep their windows in the old
9943 // Z-order until the animation completes.)
9944 if (mToTopApps.size() > 0) {
9945 NN = mAppTokens.size();
9946 for (i=0; i<NN; i++) {
9947 AppWindowToken wtoken = mAppTokens.get(i);
9948 if (wtoken.sendingToTop) {
9949 wtoken.sendingToTop = false;
9950 moveAppWindowsLocked(wtoken, NN, false);
9951 }
9952 }
9953 mToTopApps.clear();
9954 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009955
Dianne Hackborn25994b42009-09-04 14:21:19 -07009956 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009957
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009958 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009959 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009960
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009961 // The top-most window will supply the layout params,
9962 // and we will determine it below.
9963 LayoutParams animLp = null;
9964 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08009965 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009966
Joe Onorato8a9b2202010-02-26 18:56:32 -08009967 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009968 "New wallpaper target=" + mWallpaperTarget
9969 + ", lower target=" + mLowerWallpaperTarget
9970 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009971 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009972 // Do a first pass through the tokens for two
9973 // things:
9974 // (1) Determine if both the closing and opening
9975 // app token sets are wallpaper targets, in which
9976 // case special animations are needed
9977 // (since the wallpaper needs to stay static
9978 // behind them).
9979 // (2) Find the layout params of the top-most
9980 // application window in the tokens, which is
9981 // what will control the animation theme.
9982 final int NC = mClosingApps.size();
9983 NN = NC + mOpeningApps.size();
9984 for (i=0; i<NN; i++) {
9985 AppWindowToken wtoken;
9986 int mode;
9987 if (i < NC) {
9988 wtoken = mClosingApps.get(i);
9989 mode = 1;
9990 } else {
9991 wtoken = mOpeningApps.get(i-NC);
9992 mode = 2;
9993 }
9994 if (mLowerWallpaperTarget != null) {
9995 if (mLowerWallpaperTarget.mAppToken == wtoken
9996 || mUpperWallpaperTarget.mAppToken == wtoken) {
9997 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009998 }
9999 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010000 if (wtoken.appFullscreen) {
10001 WindowState ws = wtoken.findMainWindow();
10002 if (ws != null) {
10003 // If this is a compatibility mode
10004 // window, we will always use its anim.
10005 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10006 animLp = ws.mAttrs;
10007 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010008 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010009 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010010 bestAnimLayer = ws.mLayer;
10011 }
10012 fullscreenAnim = true;
10013 }
10014 } else if (!fullscreenAnim) {
10015 WindowState ws = wtoken.findMainWindow();
10016 if (ws != null) {
10017 if (ws.mLayer > bestAnimLayer) {
10018 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010019 bestAnimLayer = ws.mLayer;
10020 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010021 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010022 }
10023 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010024
Dianne Hackborn25994b42009-09-04 14:21:19 -070010025 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010026 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010027 "Wallpaper animation!");
10028 switch (transit) {
10029 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10030 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10031 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10032 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10033 break;
10034 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10035 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10036 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10037 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10038 break;
10039 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010040 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010041 "New transit: " + transit);
10042 } else if (oldWallpaper != null) {
10043 // We are transitioning from an activity with
10044 // a wallpaper to one without.
10045 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010046 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010047 "New transit away from wallpaper: " + transit);
10048 } else if (mWallpaperTarget != null) {
10049 // We are transitioning from an activity without
10050 // a wallpaper to now showing the wallpaper
10051 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010052 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010053 "New transit into wallpaper: " + transit);
10054 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010055
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010056 // If all closing windows are obscured, then there is
10057 // no need to do an animation. This is the case, for
10058 // example, when this transition is being done behind
10059 // the lock screen.
10060 if (!mPolicy.allowAppAnimationsLw()) {
10061 animLp = null;
10062 }
10063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010064 NN = mOpeningApps.size();
10065 for (i=0; i<NN; i++) {
10066 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010067 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010068 "Now opening app" + wtoken);
10069 wtoken.reportedVisible = false;
10070 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010071 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010072 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010073 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010074 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075 wtoken.showAllWindowsLocked();
10076 }
10077 NN = mClosingApps.size();
10078 for (i=0; i<NN; i++) {
10079 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010080 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 "Now closing app" + wtoken);
10082 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010083 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010084 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010085 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010086 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 // Force the allDrawn flag, because we want to start
10088 // this guy's animations regardless of whether it's
10089 // gotten drawn.
10090 wtoken.allDrawn = true;
10091 }
10092
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010093 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010095 mOpeningApps.clear();
10096 mClosingApps.clear();
10097
10098 // This has changed the visibility of windows, so perform
10099 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010100 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10101 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010102 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010103 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10104 assignLayersLocked();
10105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010107 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010108 }
10109 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010110
Dianne Hackborn16064f92010-03-25 00:47:24 -070010111 int adjResult = 0;
10112
Dianne Hackborna8f60182009-09-01 19:01:50 -070010113 if (!animating && mAppTransitionRunning) {
10114 // We have finished the animation of an app transition. To do
10115 // this, we have delayed a lot of operations like showing and
10116 // hiding apps, moving apps in Z-order, etc. The app token list
10117 // reflects the correct Z-order, but the window list may now
10118 // be out of sync with it. So here we will just rebuild the
10119 // entire app window list. Fun!
10120 mAppTransitionRunning = false;
10121 // Clear information about apps that were moving.
10122 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010123
Dianne Hackborna8f60182009-09-01 19:01:50 -070010124 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010125 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010126 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010127 moveInputMethodWindowsIfNeededLocked(false);
10128 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010129 // Since the window list has been rebuilt, focus might
10130 // have to be recomputed since the actual order of windows
10131 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010132 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010133 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010134
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010135 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010136 // At this point, there was a window with a wallpaper that
10137 // was force hiding other windows behind it, but now it
10138 // is going away. This may be simple -- just animate
10139 // away the wallpaper and its window -- or it may be
10140 // hard -- the wallpaper now needs to be shown behind
10141 // something that was hidden.
10142 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010143 if (mLowerWallpaperTarget != null
10144 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010145 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010146 "wallpaperForceHiding changed with lower="
10147 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010148 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010149 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10150 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10151 if (mLowerWallpaperTarget.mAppToken.hidden) {
10152 // The lower target has become hidden before we
10153 // actually started the animation... let's completely
10154 // re-evaluate everything.
10155 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010156 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010157 }
10158 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010159 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010160 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010161 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010162 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010163 + " NEW: " + mWallpaperTarget
10164 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010165 if (mLowerWallpaperTarget == null) {
10166 // Whoops, we don't need a special wallpaper animation.
10167 // Clear them out.
10168 forceHiding = false;
10169 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010170 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010171 if (w.mSurface != null) {
10172 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010173 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010174 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010175 forceHiding = true;
10176 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10177 if (!w.mAnimating) {
10178 // We set the animation above so it
10179 // is not yet running.
10180 w.clearAnimation();
10181 }
10182 }
10183 }
10184 }
10185 }
10186 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010187
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010188 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10189 if (DEBUG_WALLPAPER) Slog.v(TAG,
10190 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10191 + windowDetachedWallpaper);
10192 mWindowDetachedWallpaper = windowDetachedWallpaper;
10193 wallpaperMayChange = true;
10194 }
10195
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010196 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010197 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010198 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010199 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010200 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010201
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010202 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010203 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010204 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010205 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010206 assignLayersLocked();
10207 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010208 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010209 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010210 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010211 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010212
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010213 if (mFocusMayChange) {
10214 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010215 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010216 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010217 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010218 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010219 }
10220
10221 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010222 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010223 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010224
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010225 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10226 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010227
Jeff Browne33348b2010-07-15 23:54:05 -070010228 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010229 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010230
10231 // THIRD LOOP: Update the surfaces of all windows.
10232
10233 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10234
10235 boolean obscured = false;
10236 boolean blurring = false;
10237 boolean dimming = false;
10238 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010239 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010240 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010241
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010242 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010244 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010245 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010246
10247 boolean displayed = false;
10248 final WindowManager.LayoutParams attrs = w.mAttrs;
10249 final int attrFlags = attrs.flags;
10250
10251 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010252 // XXX NOTE: The logic here could be improved. We have
10253 // the decision about whether to resize a window separated
10254 // from whether to hide the surface. This can cause us to
10255 // resize a surface even if we are going to hide it. You
10256 // can see this by (1) holding device in landscape mode on
10257 // home screen; (2) tapping browser icon (device will rotate
10258 // to landscape; (3) tap home. The wallpaper will be resized
10259 // in step 2 but then immediately hidden, causing us to
10260 // have to resize and then redraw it again in step 3. It
10261 // would be nice to figure out how to avoid this, but it is
10262 // difficult because we do need to resize surfaces in some
10263 // cases while they are hidden such as when first showing a
10264 // window.
10265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010267 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 TAG, "Placing surface #" + i + " " + w.mSurface
10269 + ": new=" + w.mShownFrame + ", old="
10270 + w.mLastShownFrame);
10271
10272 boolean resize;
10273 int width, height;
10274 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10275 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10276 w.mLastRequestedHeight != w.mRequestedHeight;
10277 // for a scaled surface, we just want to use
10278 // the requested size.
10279 width = w.mRequestedWidth;
10280 height = w.mRequestedHeight;
10281 w.mLastRequestedWidth = width;
10282 w.mLastRequestedHeight = height;
10283 w.mLastShownFrame.set(w.mShownFrame);
10284 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010285 if (SHOW_TRANSACTIONS) logSurface(w,
10286 "POS " + w.mShownFrame.left
10287 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010288 w.mSurfaceX = w.mShownFrame.left;
10289 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10291 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010292 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 if (!recoveringMemory) {
10294 reclaimSomeSurfaceMemoryLocked(w, "position");
10295 }
10296 }
10297 } else {
10298 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10299 width = w.mShownFrame.width();
10300 height = w.mShownFrame.height();
10301 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010302 }
10303
10304 if (resize) {
10305 if (width < 1) width = 1;
10306 if (height < 1) height = 1;
10307 if (w.mSurface != null) {
10308 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010309 if (SHOW_TRANSACTIONS) logSurface(w,
10310 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010311 + w.mShownFrame.top + " SIZE "
10312 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010313 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010314 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010315 w.mSurfaceW = width;
10316 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010317 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010318 w.mSurfaceX = w.mShownFrame.left;
10319 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010320 w.mSurface.setPosition(w.mShownFrame.left,
10321 w.mShownFrame.top);
10322 } catch (RuntimeException e) {
10323 // If something goes wrong with the surface (such
10324 // as running out of memory), don't take down the
10325 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010326 Slog.e(TAG, "Failure updating surface of " + w
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010327 + " size=(" + width + "x" + height
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010328 + "), pos=(" + w.mShownFrame.left
10329 + "," + w.mShownFrame.top + ")", e);
10330 if (!recoveringMemory) {
10331 reclaimSomeSurfaceMemoryLocked(w, "size");
10332 }
10333 }
10334 }
10335 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010336 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010337 w.mContentInsetsChanged =
10338 !w.mLastContentInsets.equals(w.mContentInsets);
10339 w.mVisibleInsetsChanged =
10340 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010341 boolean configChanged =
10342 w.mConfiguration != mCurConfiguration
10343 && (w.mConfiguration == null
10344 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010345 if (DEBUG_CONFIGURATION && configChanged) {
10346 Slog.v(TAG, "Win " + w + " config changed: "
10347 + mCurConfiguration);
10348 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010349 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010350 + ": configChanged=" + configChanged
10351 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010352 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010354 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010355 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010356 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010357 w.mLastFrame.set(w.mFrame);
10358 w.mLastContentInsets.set(w.mContentInsets);
10359 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010360 // If the screen is currently frozen, then keep
10361 // it frozen until this window draws at its new
10362 // orientation.
10363 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010364 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010365 "Resizing while display frozen: " + w);
10366 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010367 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010368 mWindowsFreezingScreen = true;
10369 // XXX should probably keep timeout from
10370 // when we first froze the display.
10371 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10372 mH.sendMessageDelayed(mH.obtainMessage(
10373 H.WINDOW_FREEZE_TIMEOUT), 2000);
10374 }
10375 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010376 // If the orientation is changing, then we need to
10377 // hold off on unfreezing the display until this
10378 // window has been redrawn; to do that, we need
10379 // to go through the process of getting informed
10380 // by the application when it has finished drawing.
10381 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010382 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010383 "Orientation start waiting for draw in "
10384 + w + ", surface " + w.mSurface);
10385 w.mDrawPending = true;
10386 w.mCommitDrawPending = false;
10387 w.mReadyToShow = false;
10388 if (w.mAppToken != null) {
10389 w.mAppToken.allDrawn = false;
10390 }
10391 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010392 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 "Resizing window " + w + " to " + w.mFrame);
10394 mResizingWindows.add(w);
10395 } else if (w.mOrientationChanging) {
10396 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010397 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 "Orientation not waiting for draw in "
10399 + w + ", surface " + w.mSurface);
10400 w.mOrientationChanging = false;
10401 }
10402 }
10403 }
10404
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010405 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010406 if (!w.mLastHidden) {
10407 //dump();
10408 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010409 if (SHOW_TRANSACTIONS) logSurface(w,
10410 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010411 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010412 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 try {
10414 w.mSurface.hide();
10415 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010416 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417 }
10418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010419 }
10420 // If we are waiting for this window to handle an
10421 // orientation change, well, it is hidden, so
10422 // doesn't really matter. Note that this does
10423 // introduce a potential glitch if the window
10424 // becomes unhidden before it has drawn for the
10425 // new orientation.
10426 if (w.mOrientationChanging) {
10427 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010428 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429 "Orientation change skips hidden " + w);
10430 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010431 } else if (w.mLastLayer != w.mAnimLayer
10432 || w.mLastAlpha != w.mShownAlpha
10433 || w.mLastDsDx != w.mDsDx
10434 || w.mLastDtDx != w.mDtDx
10435 || w.mLastDsDy != w.mDsDy
10436 || w.mLastDtDy != w.mDtDy
10437 || w.mLastHScale != w.mHScale
10438 || w.mLastVScale != w.mVScale
10439 || w.mLastHidden) {
10440 displayed = true;
10441 w.mLastAlpha = w.mShownAlpha;
10442 w.mLastLayer = w.mAnimLayer;
10443 w.mLastDsDx = w.mDsDx;
10444 w.mLastDtDx = w.mDtDx;
10445 w.mLastDsDy = w.mDsDy;
10446 w.mLastDtDy = w.mDtDy;
10447 w.mLastHScale = w.mHScale;
10448 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010449 if (SHOW_TRANSACTIONS) logSurface(w,
10450 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010451 + " matrix=[" + (w.mDsDx*w.mHScale)
10452 + "," + (w.mDtDx*w.mVScale)
10453 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010454 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 if (w.mSurface != null) {
10456 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010457 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010458 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010459 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 w.mSurface.setLayer(w.mAnimLayer);
10461 w.mSurface.setMatrix(
10462 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10463 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10464 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010465 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 if (!recoveringMemory) {
10467 reclaimSomeSurfaceMemoryLocked(w, "update");
10468 }
10469 }
10470 }
10471
10472 if (w.mLastHidden && !w.mDrawPending
10473 && !w.mCommitDrawPending
10474 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010475 if (SHOW_TRANSACTIONS) logSurface(w,
10476 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010477 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 + " during relayout");
10479 if (showSurfaceRobustlyLocked(w)) {
10480 w.mHasDrawn = true;
10481 w.mLastHidden = false;
10482 } else {
10483 w.mOrientationChanging = false;
10484 }
10485 }
10486 if (w.mSurface != null) {
10487 w.mToken.hasVisible = true;
10488 }
10489 } else {
10490 displayed = true;
10491 }
10492
10493 if (displayed) {
10494 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010495 if (attrs.width == LayoutParams.MATCH_PARENT
10496 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010497 covered = true;
10498 }
10499 }
10500 if (w.mOrientationChanging) {
10501 if (w.mDrawPending || w.mCommitDrawPending) {
10502 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010503 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 "Orientation continue waiting for draw in " + w);
10505 } else {
10506 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010507 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010508 "Orientation change complete in " + w);
10509 }
10510 }
10511 w.mToken.hasVisible = true;
10512 }
10513 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010514 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 "Orientation change skips hidden " + w);
10516 w.mOrientationChanging = false;
10517 }
10518
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010519 if (w.mContentChanged) {
10520 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10521 w.mContentChanged = false;
10522 }
10523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524 final boolean canBeSeen = w.isDisplayedLw();
10525
10526 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10527 focusDisplayed = true;
10528 }
10529
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010530 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010533 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 if (w.mSurface != null) {
10535 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10536 holdScreen = w.mSession;
10537 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010538 if (!syswin && w.mAttrs.screenBrightness >= 0
10539 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010540 screenBrightness = w.mAttrs.screenBrightness;
10541 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010542 if (!syswin && w.mAttrs.buttonBrightness >= 0
10543 && buttonBrightness < 0) {
10544 buttonBrightness = w.mAttrs.buttonBrightness;
10545 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010546 if (canBeSeen
10547 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10548 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10549 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010550 syswin = true;
10551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010552 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010553
Dianne Hackborn25994b42009-09-04 14:21:19 -070010554 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10555 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010556 // This window completely covers everything behind it,
10557 // so we want to leave all of them as unblurred (for
10558 // performance reasons).
10559 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010560 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010561 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010562 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010563 obscured = true;
10564 if (mBackgroundFillerSurface == null) {
10565 try {
10566 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010567 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010568 0, dw, dh,
10569 PixelFormat.OPAQUE,
10570 Surface.FX_SURFACE_NORMAL);
10571 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010572 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010573 }
10574 }
10575 try {
10576 mBackgroundFillerSurface.setPosition(0, 0);
10577 mBackgroundFillerSurface.setSize(dw, dh);
10578 // Using the same layer as Dim because they will never be shown at the
10579 // same time.
10580 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10581 mBackgroundFillerSurface.show();
10582 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010583 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010584 }
10585 backgroundFillerShown = true;
10586 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010587 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010589 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010590 + ": blurring=" + blurring
10591 + " obscured=" + obscured
10592 + " displayed=" + displayed);
10593 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10594 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010595 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010596 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010597 if (mDimAnimator == null) {
10598 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010600 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010601 mDimAnimator.updateParameters(mContext.getResources(),
10602 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010604 }
10605 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10606 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010607 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010608 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010609 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010610 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 + mBlurSurface + ": CREATE");
10612 try {
Romain Guy06882f82009-06-10 13:36:04 -070010613 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010614 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010615 -1, 16, 16,
10616 PixelFormat.OPAQUE,
10617 Surface.FX_SURFACE_BLUR);
10618 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010619 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 }
10621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010622 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010623 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10624 + mBlurSurface + ": pos=(0,0) (" +
10625 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010626 mBlurSurface.setPosition(0, 0);
10627 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010628 mBlurSurface.setLayer(w.mAnimLayer-2);
10629 if (!mBlurShown) {
10630 try {
10631 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10632 + mBlurSurface + ": SHOW");
10633 mBlurSurface.show();
10634 } catch (RuntimeException e) {
10635 Slog.w(TAG, "Failure showing blur surface", e);
10636 }
10637 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010638 }
10639 }
10640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010641 }
10642 }
10643 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010644
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010645 if (obscuredChanged && mWallpaperTarget == w) {
10646 // This is the wallpaper target and its obscured state
10647 // changed... make sure the current wallaper's visibility
10648 // has been updated accordingly.
10649 updateWallpaperVisibilityLocked();
10650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010651 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010652
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010653 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10654 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010655 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010656 try {
10657 mBackgroundFillerSurface.hide();
10658 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010659 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010660 }
10661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010663 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010664 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10665 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 }
Romain Guy06882f82009-06-10 13:36:04 -070010667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010668 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010669 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010670 + ": HIDE");
10671 try {
10672 mBlurSurface.hide();
10673 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010674 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010675 }
10676 mBlurShown = false;
10677 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010678 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010679 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010680 }
10681
Jeff Browne33348b2010-07-15 23:54:05 -070010682 mInputMonitor.updateInputWindowsLw();
10683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010684 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010685
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010686 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10687
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010688 if (mWatermark != null) {
10689 mWatermark.drawIfNeeded();
10690 }
10691
Joe Onorato8a9b2202010-02-26 18:56:32 -080010692 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010693 "With display frozen, orientationChangeComplete="
10694 + orientationChangeComplete);
10695 if (orientationChangeComplete) {
10696 if (mWindowsFreezingScreen) {
10697 mWindowsFreezingScreen = false;
10698 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10699 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010700 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010701 }
Romain Guy06882f82009-06-10 13:36:04 -070010702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010703 i = mResizingWindows.size();
10704 if (i > 0) {
10705 do {
10706 i--;
10707 WindowState win = mResizingWindows.get(i);
10708 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010709 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10710 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010711 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010712 boolean configChanged =
10713 win.mConfiguration != mCurConfiguration
10714 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010715 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10716 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10717 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010718 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010719 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010720 + " / " + mCurConfiguration + " / 0x"
10721 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010722 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010723 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010724 win.mClient.resized(win.mFrame.width(),
10725 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010726 win.mLastVisibleInsets, win.mDrawPending,
10727 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010728 win.mContentInsetsChanged = false;
10729 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010730 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010731 } catch (RemoteException e) {
10732 win.mOrientationChanging = false;
10733 }
10734 } while (i > 0);
10735 mResizingWindows.clear();
10736 }
Romain Guy06882f82009-06-10 13:36:04 -070010737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010739 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010740 i = mDestroySurface.size();
10741 if (i > 0) {
10742 do {
10743 i--;
10744 WindowState win = mDestroySurface.get(i);
10745 win.mDestroying = false;
10746 if (mInputMethodWindow == win) {
10747 mInputMethodWindow = null;
10748 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010749 if (win == mWallpaperTarget) {
10750 wallpaperDestroyed = true;
10751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010752 win.destroySurfaceLocked();
10753 } while (i > 0);
10754 mDestroySurface.clear();
10755 }
10756
10757 // Time to remove any exiting tokens?
10758 for (i=mExitingTokens.size()-1; i>=0; i--) {
10759 WindowToken token = mExitingTokens.get(i);
10760 if (!token.hasVisible) {
10761 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010762 if (token.windowType == TYPE_WALLPAPER) {
10763 mWallpaperTokens.remove(token);
10764 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010765 }
10766 }
10767
10768 // Time to remove any exiting applications?
10769 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10770 AppWindowToken token = mExitingAppTokens.get(i);
10771 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010772 // Make sure there is no animation running on this token,
10773 // so any windows associated with it will be removed as
10774 // soon as their animations are complete
10775 token.animation = null;
10776 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010777 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10778 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 mAppTokens.remove(token);
10780 mExitingAppTokens.remove(i);
10781 }
10782 }
10783
Dianne Hackborna8f60182009-09-01 19:01:50 -070010784 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010785
Dianne Hackborna8f60182009-09-01 19:01:50 -070010786 if (!animating && mAppTransitionRunning) {
10787 // We have finished the animation of an app transition. To do
10788 // this, we have delayed a lot of operations like showing and
10789 // hiding apps, moving apps in Z-order, etc. The app token list
10790 // reflects the correct Z-order, but the window list may now
10791 // be out of sync with it. So here we will just rebuild the
10792 // entire app window list. Fun!
10793 mAppTransitionRunning = false;
10794 needRelayout = true;
10795 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010796 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010797 // Clear information about apps that were moving.
10798 mToBottomApps.clear();
10799 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010801 if (focusDisplayed) {
10802 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10803 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010804 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010805 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010806 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010807 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010808 requestAnimationLocked(0);
10809 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10811 }
Jeff Browneb857f12010-07-16 10:06:33 -070010812
Jeff Browne33348b2010-07-15 23:54:05 -070010813 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010814
Jeff Brown8e03b752010-06-13 19:16:55 -070010815 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010816 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10817 mPowerManager.setScreenBrightnessOverride(-1);
10818 } else {
10819 mPowerManager.setScreenBrightnessOverride((int)
10820 (screenBrightness * Power.BRIGHTNESS_ON));
10821 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010822 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10823 mPowerManager.setButtonBrightnessOverride(-1);
10824 } else {
10825 mPowerManager.setButtonBrightnessOverride((int)
10826 (buttonBrightness * Power.BRIGHTNESS_ON));
10827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010828 if (holdScreen != mHoldingScreenOn) {
10829 mHoldingScreenOn = holdScreen;
10830 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10831 mH.sendMessage(m);
10832 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010833
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010834 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010835 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010836 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10837 LocalPowerManager.BUTTON_EVENT, true);
10838 mTurnOnScreen = false;
10839 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010840
10841 // Check to see if we are now in a state where the screen should
10842 // be enabled, because the window obscured flags have changed.
10843 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010844 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010845
10846 /**
10847 * Must be called with the main window manager lock held.
10848 */
10849 void setHoldScreenLocked(boolean holding) {
10850 boolean state = mHoldingScreenWakeLock.isHeld();
10851 if (holding != state) {
10852 if (holding) {
10853 mHoldingScreenWakeLock.acquire();
10854 } else {
10855 mPolicy.screenOnStoppedLw();
10856 mHoldingScreenWakeLock.release();
10857 }
10858 }
10859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010860
10861 void requestAnimationLocked(long delay) {
10862 if (!mAnimationPending) {
10863 mAnimationPending = true;
10864 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10865 }
10866 }
Romain Guy06882f82009-06-10 13:36:04 -070010867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010868 /**
10869 * Have the surface flinger show a surface, robustly dealing with
10870 * error conditions. In particular, if there is not enough memory
10871 * to show the surface, then we will try to get rid of other surfaces
10872 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010873 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010874 * @return Returns true if the surface was successfully shown.
10875 */
10876 boolean showSurfaceRobustlyLocked(WindowState win) {
10877 try {
10878 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010879 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010880 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010881 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010882 if (DEBUG_VISIBILITY) Slog.v(TAG,
10883 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010884 win.mTurnOnScreen = false;
10885 mTurnOnScreen = true;
10886 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010887 }
10888 return true;
10889 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010890 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010891 }
Romain Guy06882f82009-06-10 13:36:04 -070010892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010893 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010895 return false;
10896 }
Romain Guy06882f82009-06-10 13:36:04 -070010897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10899 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010900
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010901 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010902 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904 if (mForceRemoves == null) {
10905 mForceRemoves = new ArrayList<WindowState>();
10906 }
Romain Guy06882f82009-06-10 13:36:04 -070010907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010908 long callingIdentity = Binder.clearCallingIdentity();
10909 try {
10910 // There was some problem... first, do a sanity check of the
10911 // window list to make sure we haven't left any dangling surfaces
10912 // around.
10913 int N = mWindows.size();
10914 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010915 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010916 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010917 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010918 if (ws.mSurface != null) {
10919 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010920 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010921 + ws + " surface=" + ws.mSurface
10922 + " token=" + win.mToken
10923 + " pid=" + ws.mSession.mPid
10924 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010925 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010926 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010927 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010928 ws.mSurface = null;
10929 mForceRemoves.add(ws);
10930 i--;
10931 N--;
10932 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010933 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010934 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010935 + ws + " surface=" + ws.mSurface
10936 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010937 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010938 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010939 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010940 ws.mSurface = null;
10941 leakedSurface = true;
10942 }
10943 }
10944 }
Romain Guy06882f82009-06-10 13:36:04 -070010945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010946 boolean killedApps = false;
10947 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010948 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010949 SparseIntArray pidCandidates = new SparseIntArray();
10950 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010951 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010952 if (ws.mSurface != null) {
10953 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10954 }
10955 }
10956 if (pidCandidates.size() > 0) {
10957 int[] pids = new int[pidCandidates.size()];
10958 for (int i=0; i<pids.length; i++) {
10959 pids[i] = pidCandidates.keyAt(i);
10960 }
10961 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010962 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010963 killedApps = true;
10964 }
10965 } catch (RemoteException e) {
10966 }
10967 }
10968 }
Romain Guy06882f82009-06-10 13:36:04 -070010969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010970 if (leakedSurface || killedApps) {
10971 // We managed to reclaim some memory, so get rid of the trouble
10972 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010973 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010974 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010975 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010976 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010977 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010978 win.mSurface = null;
10979 }
Romain Guy06882f82009-06-10 13:36:04 -070010980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010981 try {
10982 win.mClient.dispatchGetNewSurface();
10983 } catch (RemoteException e) {
10984 }
10985 }
10986 } finally {
10987 Binder.restoreCallingIdentity(callingIdentity);
10988 }
10989 }
Romain Guy06882f82009-06-10 13:36:04 -070010990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010991 private boolean updateFocusedWindowLocked(int mode) {
10992 WindowState newFocus = computeFocusedWindowLocked();
10993 if (mCurrentFocus != newFocus) {
10994 // This check makes sure that we don't already have the focus
10995 // change message pending.
10996 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10997 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010998 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010999 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11000 final WindowState oldFocus = mCurrentFocus;
11001 mCurrentFocus = newFocus;
11002 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011004 final WindowState imWindow = mInputMethodWindow;
11005 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011006 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011008 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11009 mLayoutNeeded = true;
11010 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011011 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080011012 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011013 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11014 // Client will do the layout, but we need to assign layers
11015 // for handleNewWindowLocked() below.
11016 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011017 }
11018 }
Jeff Brown349703e2010-06-22 01:27:15 -070011019
11020 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11021 // If we defer assigning layers, then the caller is responsible for
11022 // doing this part.
11023 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011025 return true;
11026 }
11027 return false;
11028 }
Jeff Brown349703e2010-06-22 01:27:15 -070011029
11030 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011031 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070011032 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011033
11034 private WindowState computeFocusedWindowLocked() {
11035 WindowState result = null;
11036 WindowState win;
11037
11038 int i = mWindows.size() - 1;
11039 int nextAppIndex = mAppTokens.size()-1;
11040 WindowToken nextApp = nextAppIndex >= 0
11041 ? mAppTokens.get(nextAppIndex) : null;
11042
11043 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011044 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011045
Joe Onorato8a9b2202010-02-26 18:56:32 -080011046 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011047 TAG, "Looking for focus: " + i
11048 + " = " + win
11049 + ", flags=" + win.mAttrs.flags
11050 + ", canReceive=" + win.canReceiveKeys());
11051
11052 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011054 // If this window's application has been removed, just skip it.
11055 if (thisApp != null && thisApp.removed) {
11056 i--;
11057 continue;
11058 }
Romain Guy06882f82009-06-10 13:36:04 -070011059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011060 // If there is a focused app, don't allow focus to go to any
11061 // windows below it. If this is an application window, step
11062 // through the app tokens until we find its app.
11063 if (thisApp != null && nextApp != null && thisApp != nextApp
11064 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11065 int origAppIndex = nextAppIndex;
11066 while (nextAppIndex > 0) {
11067 if (nextApp == mFocusedApp) {
11068 // Whoops, we are below the focused app... no focus
11069 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011070 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011071 TAG, "Reached focused app: " + mFocusedApp);
11072 return null;
11073 }
11074 nextAppIndex--;
11075 nextApp = mAppTokens.get(nextAppIndex);
11076 if (nextApp == thisApp) {
11077 break;
11078 }
11079 }
11080 if (thisApp != nextApp) {
11081 // Uh oh, the app token doesn't exist! This shouldn't
11082 // happen, but if it does we can get totally hosed...
11083 // so restart at the original app.
11084 nextAppIndex = origAppIndex;
11085 nextApp = mAppTokens.get(nextAppIndex);
11086 }
11087 }
11088
11089 // Dispatch to this window if it is wants key events.
11090 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011091 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011092 TAG, "Found focus @ " + i + " = " + win);
11093 result = win;
11094 break;
11095 }
11096
11097 i--;
11098 }
11099
11100 return result;
11101 }
11102
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011103 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011104 if (mDisplayFrozen) {
11105 return;
11106 }
Romain Guy06882f82009-06-10 13:36:04 -070011107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011108 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011110 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011111 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011112 if (mFreezeGcPending != 0) {
11113 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011114 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 mH.removeMessages(H.FORCE_GC);
11116 Runtime.getRuntime().gc();
11117 mFreezeGcPending = now;
11118 }
11119 } else {
11120 mFreezeGcPending = now;
11121 }
Romain Guy06882f82009-06-10 13:36:04 -070011122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011123 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011124
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011125 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011126
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011127 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11128 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011129 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011130 mAppTransitionReady = true;
11131 }
Romain Guy06882f82009-06-10 13:36:04 -070011132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011133 if (PROFILE_ORIENTATION) {
11134 File file = new File("/data/system/frozen");
11135 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11136 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011137
11138 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011139 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11140 mScreenRotationAnimation.kill();
11141 mScreenRotationAnimation = null;
11142 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011143 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011144 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011145 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011146 }
11147 } else {
11148 Surface.freezeDisplay(0);
11149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011150 }
Romain Guy06882f82009-06-10 13:36:04 -070011151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011152 private void stopFreezingDisplayLocked() {
11153 if (!mDisplayFrozen) {
11154 return;
11155 }
Romain Guy06882f82009-06-10 13:36:04 -070011156
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011157 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11158 return;
11159 }
11160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011161 mDisplayFrozen = false;
11162 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11163 if (PROFILE_ORIENTATION) {
11164 Debug.stopMethodTracing();
11165 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011166
11167 if (CUSTOM_SCREEN_ROTATION) {
11168 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011169 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11170 mTransitionAnimationScale)) {
11171 requestAnimationLocked(0);
11172 } else {
11173 mScreenRotationAnimation = null;
11174 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011175 }
11176 } else {
11177 Surface.unfreezeDisplay(0);
11178 }
Romain Guy06882f82009-06-10 13:36:04 -070011179
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011180 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011181
Christopher Tateb696aee2010-04-02 19:08:30 -070011182 // While the display is frozen we don't re-compute the orientation
11183 // to avoid inconsistent states. However, something interesting
11184 // could have actually changed during that time so re-evaluate it
11185 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011186 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011187 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11188 }
11189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011190 // A little kludge: a lot could have happened while the
11191 // display was frozen, so now that we are coming back we
11192 // do a gc so that any remote references the system
11193 // processes holds on others can be released if they are
11194 // no longer needed.
11195 mH.removeMessages(H.FORCE_GC);
11196 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11197 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011199 mScreenFrozenLock.release();
11200 }
Romain Guy06882f82009-06-10 13:36:04 -070011201
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011202 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11203 DisplayMetrics dm) {
11204 if (index < tokens.length) {
11205 String str = tokens[index];
11206 if (str != null && str.length() > 0) {
11207 try {
11208 int val = Integer.parseInt(str);
11209 return val;
11210 } catch (Exception e) {
11211 }
11212 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011213 }
11214 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11215 return defDps;
11216 }
11217 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11218 return val;
11219 }
11220
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011221 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011222 final String[] mTokens;
11223 final String mText;
11224 final Paint mTextPaint;
11225 final int mTextWidth;
11226 final int mTextHeight;
11227 final int mTextAscent;
11228 final int mTextDescent;
11229 final int mDeltaX;
11230 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011231
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011232 Surface mSurface;
11233 int mLastDW;
11234 int mLastDH;
11235 boolean mDrawNeeded;
11236
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011237 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011238 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011239 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011240
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011241 if (false) {
11242 Log.i(TAG, "*********************** WATERMARK");
11243 for (int i=0; i<tokens.length; i++) {
11244 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11245 }
11246 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011247
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011248 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011249
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011250 StringBuilder builder = new StringBuilder(32);
11251 int len = mTokens[0].length();
11252 len = len & ~1;
11253 for (int i=0; i<len; i+=2) {
11254 int c1 = mTokens[0].charAt(i);
11255 int c2 = mTokens[0].charAt(i+1);
11256 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11257 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11258 else c1 -= '0';
11259 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11260 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11261 else c2 -= '0';
11262 builder.append((char)(255-((c1*16)+c2)));
11263 }
11264 mText = builder.toString();
11265 if (false) {
11266 Log.i(TAG, "Final text: " + mText);
11267 }
11268
11269 int fontSize = getPropertyInt(tokens, 1,
11270 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11271
11272 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11273 mTextPaint.setTextSize(fontSize);
11274 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11275
11276 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11277 mTextWidth = (int)mTextPaint.measureText(mText);
11278 mTextAscent = fm.ascent;
11279 mTextDescent = fm.descent;
11280 mTextHeight = fm.descent - fm.ascent;
11281
11282 mDeltaX = getPropertyInt(tokens, 2,
11283 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11284 mDeltaY = getPropertyInt(tokens, 3,
11285 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11286 int shadowColor = getPropertyInt(tokens, 4,
11287 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11288 int color = getPropertyInt(tokens, 5,
11289 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11290 int shadowRadius = getPropertyInt(tokens, 6,
11291 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11292 int shadowDx = getPropertyInt(tokens, 8,
11293 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11294 int shadowDy = getPropertyInt(tokens, 9,
11295 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11296
11297 mTextPaint.setColor(color);
11298 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011299
11300 try {
11301 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011302 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011303 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011304 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011305 mSurface.show();
11306 } catch (OutOfResourcesException e) {
11307 }
11308 }
11309
11310 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011311 if (mLastDW != dw || mLastDH != dh) {
11312 mLastDW = dw;
11313 mLastDH = dh;
11314 mSurface.setSize(dw, dh);
11315 mDrawNeeded = true;
11316 }
11317 }
11318
11319 void drawIfNeeded() {
11320 if (mDrawNeeded) {
11321 final int dw = mLastDW;
11322 final int dh = mLastDH;
11323
11324 mDrawNeeded = false;
11325 Rect dirty = new Rect(0, 0, dw, dh);
11326 Canvas c = null;
11327 try {
11328 c = mSurface.lockCanvas(dirty);
11329 } catch (IllegalArgumentException e) {
11330 } catch (OutOfResourcesException e) {
11331 }
11332 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011333 c.drawColor(0, PorterDuff.Mode.CLEAR);
11334
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011335 int deltaX = mDeltaX;
11336 int deltaY = mDeltaY;
11337
11338 // deltaX shouldn't be close to a round fraction of our
11339 // x step, or else things will line up too much.
11340 int div = (dw+mTextWidth)/deltaX;
11341 int rem = (dw+mTextWidth) - (div*deltaX);
11342 int qdelta = deltaX/4;
11343 if (rem < qdelta || rem > (deltaX-qdelta)) {
11344 deltaX += deltaX/3;
11345 }
11346
11347 int y = -mTextHeight;
11348 int x = -mTextWidth;
11349 while (y < (dh+mTextHeight)) {
11350 c.drawText(mText, x, y, mTextPaint);
11351 x += deltaX;
11352 if (x >= dw) {
11353 x -= (dw+mTextWidth);
11354 y += deltaY;
11355 }
11356 }
11357 mSurface.unlockCanvasAndPost(c);
11358 }
11359 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011360 }
11361 }
11362
11363 void createWatermark() {
11364 if (mWatermark != null) {
11365 return;
11366 }
11367
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011368 File file = new File("/system/etc/setup.conf");
11369 FileInputStream in = null;
11370 try {
11371 in = new FileInputStream(file);
11372 DataInputStream ind = new DataInputStream(in);
11373 String line = ind.readLine();
11374 if (line != null) {
11375 String[] toks = line.split("%");
11376 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011377 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011378 }
11379 }
11380 } catch (FileNotFoundException e) {
11381 } catch (IOException e) {
11382 } finally {
11383 if (in != null) {
11384 try {
11385 in.close();
11386 } catch (IOException e) {
11387 }
11388 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011389 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011390 }
11391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011392 @Override
11393 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11394 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11395 != PackageManager.PERMISSION_GRANTED) {
11396 pw.println("Permission Denial: can't dump WindowManager from from pid="
11397 + Binder.getCallingPid()
11398 + ", uid=" + Binder.getCallingUid());
11399 return;
11400 }
Romain Guy06882f82009-06-10 13:36:04 -070011401
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011402 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011403 pw.println(" ");
11404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011405 synchronized(mWindowMap) {
11406 pw.println("Current Window Manager state:");
11407 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011408 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011409 pw.print(" Window #"); pw.print(i); pw.print(' ');
11410 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011411 w.dump(pw, " ");
11412 }
11413 if (mInputMethodDialogs.size() > 0) {
11414 pw.println(" ");
11415 pw.println(" Input method dialogs:");
11416 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11417 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011418 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011419 }
11420 }
11421 if (mPendingRemove.size() > 0) {
11422 pw.println(" ");
11423 pw.println(" Remove pending for:");
11424 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11425 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011426 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11427 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011428 w.dump(pw, " ");
11429 }
11430 }
11431 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11432 pw.println(" ");
11433 pw.println(" Windows force removing:");
11434 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11435 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011436 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11437 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011438 w.dump(pw, " ");
11439 }
11440 }
11441 if (mDestroySurface.size() > 0) {
11442 pw.println(" ");
11443 pw.println(" Windows waiting to destroy their surface:");
11444 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11445 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011446 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11447 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011448 w.dump(pw, " ");
11449 }
11450 }
11451 if (mLosingFocus.size() > 0) {
11452 pw.println(" ");
11453 pw.println(" Windows losing focus:");
11454 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11455 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011456 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11457 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011458 w.dump(pw, " ");
11459 }
11460 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011461 if (mResizingWindows.size() > 0) {
11462 pw.println(" ");
11463 pw.println(" Windows waiting to resize:");
11464 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11465 WindowState w = mResizingWindows.get(i);
11466 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11467 pw.print(w); pw.println(":");
11468 w.dump(pw, " ");
11469 }
11470 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011471 if (mSessions.size() > 0) {
11472 pw.println(" ");
11473 pw.println(" All active sessions:");
11474 Iterator<Session> it = mSessions.iterator();
11475 while (it.hasNext()) {
11476 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011477 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011478 s.dump(pw, " ");
11479 }
11480 }
11481 if (mTokenMap.size() > 0) {
11482 pw.println(" ");
11483 pw.println(" All tokens:");
11484 Iterator<WindowToken> it = mTokenMap.values().iterator();
11485 while (it.hasNext()) {
11486 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011487 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011488 token.dump(pw, " ");
11489 }
11490 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011491 if (mWallpaperTokens.size() > 0) {
11492 pw.println(" ");
11493 pw.println(" Wallpaper tokens:");
11494 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11495 WindowToken token = mWallpaperTokens.get(i);
11496 pw.print(" Wallpaper #"); pw.print(i);
11497 pw.print(' '); pw.print(token); pw.println(':');
11498 token.dump(pw, " ");
11499 }
11500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011501 if (mAppTokens.size() > 0) {
11502 pw.println(" ");
11503 pw.println(" Application tokens in Z order:");
11504 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011505 pw.print(" App #"); pw.print(i); pw.print(": ");
11506 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011507 }
11508 }
11509 if (mFinishedStarting.size() > 0) {
11510 pw.println(" ");
11511 pw.println(" Finishing start of application tokens:");
11512 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11513 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011514 pw.print(" Finished Starting #"); pw.print(i);
11515 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011516 token.dump(pw, " ");
11517 }
11518 }
11519 if (mExitingTokens.size() > 0) {
11520 pw.println(" ");
11521 pw.println(" Exiting tokens:");
11522 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11523 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011524 pw.print(" Exiting #"); pw.print(i);
11525 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011526 token.dump(pw, " ");
11527 }
11528 }
11529 if (mExitingAppTokens.size() > 0) {
11530 pw.println(" ");
11531 pw.println(" Exiting application tokens:");
11532 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11533 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011534 pw.print(" Exiting App #"); pw.print(i);
11535 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011536 token.dump(pw, " ");
11537 }
11538 }
11539 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011540 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11541 pw.print(" mLastFocus="); pw.println(mLastFocus);
11542 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11543 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11544 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011545 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011546 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11547 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11548 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11549 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011550 if (mWindowDetachedWallpaper != null) {
11551 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11552 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011553 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11554 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11555 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011556 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11557 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11558 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11559 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011560 if (mDimAnimator != null) {
11561 mDimAnimator.printTo(pw);
11562 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011563 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011564 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011565 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011566 pw.print(mInputMethodAnimLayerAdjustment);
11567 pw.print(" mWallpaperAnimLayerAdjustment=");
11568 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011569 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11570 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011571 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11572 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011573 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11574 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011575 pw.print(" mRotation="); pw.print(mRotation);
11576 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11577 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11578 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11579 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11580 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11581 pw.print(" mNextAppTransition=0x");
11582 pw.print(Integer.toHexString(mNextAppTransition));
11583 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011584 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011585 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011586 if (mNextAppTransitionPackage != null) {
11587 pw.print(" mNextAppTransitionPackage=");
11588 pw.print(mNextAppTransitionPackage);
11589 pw.print(", mNextAppTransitionEnter=0x");
11590 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11591 pw.print(", mNextAppTransitionExit=0x");
11592 pw.print(Integer.toHexString(mNextAppTransitionExit));
11593 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011594 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11595 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11596 if (mOpeningApps.size() > 0) {
11597 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11598 }
11599 if (mClosingApps.size() > 0) {
11600 pw.print(" mClosingApps="); pw.println(mClosingApps);
11601 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011602 if (mToTopApps.size() > 0) {
11603 pw.print(" mToTopApps="); pw.println(mToTopApps);
11604 }
11605 if (mToBottomApps.size() > 0) {
11606 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11607 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011608 if (mDisplay != null) {
11609 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11610 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11611 } else {
11612 pw.println(" NO DISPLAY");
11613 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011614 pw.println(" Policy:");
11615 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011616 }
11617 }
11618
Jeff Brown349703e2010-06-22 01:27:15 -070011619 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011620 public void monitor() {
11621 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011622 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011623 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011624
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011625 /**
11626 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011627 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011628 */
11629 private static class DimAnimator {
11630 Surface mDimSurface;
11631 boolean mDimShown = false;
11632 float mDimCurrentAlpha;
11633 float mDimTargetAlpha;
11634 float mDimDeltaPerMs;
11635 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011636
11637 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011638
11639 DimAnimator (SurfaceSession session) {
11640 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011641 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011642 + mDimSurface + ": CREATE");
11643 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011644 mDimSurface = new Surface(session, 0,
11645 "DimSurface",
11646 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011647 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011648 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011649 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011650 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011651 }
11652 }
11653 }
11654
11655 /**
11656 * Show the dim surface.
11657 */
11658 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011659 if (!mDimShown) {
11660 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11661 dw + "x" + dh + ")");
11662 mDimShown = true;
11663 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011664 mLastDimWidth = dw;
11665 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011666 mDimSurface.setPosition(0, 0);
11667 mDimSurface.setSize(dw, dh);
11668 mDimSurface.show();
11669 } catch (RuntimeException e) {
11670 Slog.w(TAG, "Failure showing dim surface", e);
11671 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011672 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11673 mLastDimWidth = dw;
11674 mLastDimHeight = dh;
11675 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011676 }
11677 }
11678
11679 /**
11680 * Set's the dim surface's layer and update dim parameters that will be used in
11681 * {@link updateSurface} after all windows are examined.
11682 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011683 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011684 mDimSurface.setLayer(w.mAnimLayer-1);
11685
11686 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011687 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011688 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011689 if (mDimTargetAlpha != target) {
11690 // If the desired dim level has changed, then
11691 // start an animation to it.
11692 mLastDimAnimTime = currentTime;
11693 long duration = (w.mAnimating && w.mAnimation != null)
11694 ? w.mAnimation.computeDurationHint()
11695 : DEFAULT_DIM_DURATION;
11696 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011697 TypedValue tv = new TypedValue();
11698 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11699 tv, true);
11700 if (tv.type == TypedValue.TYPE_FRACTION) {
11701 duration = (long)tv.getFraction((float)duration, (float)duration);
11702 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11703 && tv.type <= TypedValue.TYPE_LAST_INT) {
11704 duration = tv.data;
11705 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011706 }
11707 if (duration < 1) {
11708 // Don't divide by zero
11709 duration = 1;
11710 }
11711 mDimTargetAlpha = target;
11712 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11713 }
11714 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011715
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011716 /**
11717 * Updating the surface's alpha. Returns true if the animation continues, or returns
11718 * false when the animation is finished and the dim surface is hidden.
11719 */
11720 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11721 if (!dimming) {
11722 if (mDimTargetAlpha != 0) {
11723 mLastDimAnimTime = currentTime;
11724 mDimTargetAlpha = 0;
11725 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11726 }
11727 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011728
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011729 boolean animating = false;
11730 if (mLastDimAnimTime != 0) {
11731 mDimCurrentAlpha += mDimDeltaPerMs
11732 * (currentTime-mLastDimAnimTime);
11733 boolean more = true;
11734 if (displayFrozen) {
11735 // If the display is frozen, there is no reason to animate.
11736 more = false;
11737 } else if (mDimDeltaPerMs > 0) {
11738 if (mDimCurrentAlpha > mDimTargetAlpha) {
11739 more = false;
11740 }
11741 } else if (mDimDeltaPerMs < 0) {
11742 if (mDimCurrentAlpha < mDimTargetAlpha) {
11743 more = false;
11744 }
11745 } else {
11746 more = false;
11747 }
11748
11749 // Do we need to continue animating?
11750 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011751 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011752 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11753 mLastDimAnimTime = currentTime;
11754 mDimSurface.setAlpha(mDimCurrentAlpha);
11755 animating = true;
11756 } else {
11757 mDimCurrentAlpha = mDimTargetAlpha;
11758 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011759 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011760 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11761 mDimSurface.setAlpha(mDimCurrentAlpha);
11762 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011763 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011764 + ": HIDE");
11765 try {
11766 mDimSurface.hide();
11767 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011768 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011769 }
11770 mDimShown = false;
11771 }
11772 }
11773 }
11774 return animating;
11775 }
11776
11777 public void printTo(PrintWriter pw) {
11778 pw.print(" mDimShown="); pw.print(mDimShown);
11779 pw.print(" current="); pw.print(mDimCurrentAlpha);
11780 pw.print(" target="); pw.print(mDimTargetAlpha);
11781 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11782 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11783 }
11784 }
11785
11786 /**
11787 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11788 * This is used for opening/closing transition for apps in compatible mode.
11789 */
11790 private static class FadeInOutAnimation extends Animation {
11791 int mWidth;
11792 boolean mFadeIn;
11793
11794 public FadeInOutAnimation(boolean fadeIn) {
11795 setInterpolator(new AccelerateInterpolator());
11796 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11797 mFadeIn = fadeIn;
11798 }
11799
11800 @Override
11801 protected void applyTransformation(float interpolatedTime, Transformation t) {
11802 float x = interpolatedTime;
11803 if (!mFadeIn) {
11804 x = 1.0f - x; // reverse the interpolation for fade out
11805 }
11806 if (x < 0.5) {
11807 // move the window out of the screen.
11808 t.getMatrix().setTranslate(mWidth, 0);
11809 } else {
11810 t.getMatrix().setTranslate(0, 0);// show
11811 t.setAlpha((x - 0.5f) * 2);
11812 }
11813 }
11814
11815 @Override
11816 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11817 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11818 mWidth = width;
11819 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011820
11821 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011822 public int getZAdjustment() {
11823 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011824 }
11825 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011826}