blob: bdc779c3e11e9bc85e7c26052f7136496a269696 [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
Christopher Tatea53146c2010-09-07 11:57:52 -0700523 private final Rect tmpRect = new Rect();
524
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.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700586 mDataDescription = mData.getDescription();
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 Tate2c095f32010-10-04 14:13:40 -0700711 mSurface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800712 try {
713 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
714 } finally {
715 mSurface.closeTransaction();
716 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 Tate02d2b3b2011-01-10 20:43:53 -0800721 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700722 final IBinder touchedBinder = touchedWin.mClient.asBinder();
723 if (touchedBinder != mLocalWin) {
724 // This drag is pinned only to the originating window, but the drag
725 // point is outside that window. Pretend it's over empty space.
726 touchedWin = null;
727 }
728 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700729 try {
730 // have we dragged over a new window?
731 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
732 if (DEBUG_DRAG) {
733 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
734 }
735 // force DRAG_EXITED_EVENT if appropriate
736 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700737 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800738 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700739 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700740 if (myPid != mTargetWindow.mSession.mPid) {
741 evt.recycle();
742 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 }
744 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700745 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700746 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
747 }
748 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700749 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800750 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700751 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700752 if (myPid != touchedWin.mSession.mPid) {
753 evt.recycle();
754 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700755 }
756 } catch (RemoteException e) {
757 Slog.w(TAG, "can't send drag notification to windows");
758 }
759 mTargetWindow = touchedWin;
760 }
761
Chris Tated4533f142010-10-19 15:15:08 -0700762 // Tell the drop target about the data. Returns 'true' if we can immediately
763 // dispatch the global drag-ended message, 'false' if we need to wait for a
764 // result from the recipient.
765 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700766 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700767 if (touchedWin == null) {
768 // "drop" outside a valid window -- no recipient to apply a
769 // timeout to, and we can send the drag-ended message immediately.
770 mDragResult = false;
771 return true;
772 }
773
774 if (DEBUG_DRAG) {
775 Slog.d(TAG, "sending DROP to " + touchedWin);
776 }
777 final int myPid = Process.myPid();
778 final IBinder token = touchedWin.mClient.asBinder();
779 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
780 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800781 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700782 try {
783 touchedWin.mClient.dispatchDragEvent(evt);
784
785 // 5 second timeout for this window to respond to the drop
786 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
787 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
788 mH.sendMessageDelayed(msg, 5000);
789 } catch (RemoteException e) {
790 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
791 return true;
792 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700793 if (myPid != touchedWin.mSession.mPid) {
794 evt.recycle();
795 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700796 }
Chris Tated4533f142010-10-19 15:15:08 -0700797 mToken = token;
798 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700799 }
800
801 // Find the visible, touch-deliverable window under the given point
802 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
803 WindowState touchedWin = null;
804 final int x = (int) xf;
805 final int y = (int) yf;
806 final ArrayList<WindowState> windows = mWindows;
807 final int N = windows.size();
808 for (int i = N - 1; i >= 0; i--) {
809 WindowState child = windows.get(i);
810 final int flags = child.mAttrs.flags;
811 if (!child.isVisibleLw()) {
812 // not visible == don't tell about drags
813 continue;
814 }
815 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
816 // not touchable == don't tell about drags
817 continue;
818 }
819 // account for the window's decor etc
820 tmpRect.set(child.mFrame);
821 if (child.mTouchableInsets == ViewTreeObserver
822 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
823 // The point is inside of the window if it is
824 // inside the frame, AND the content part of that
825 // frame that was given by the application.
826 tmpRect.left += child.mGivenContentInsets.left;
827 tmpRect.top += child.mGivenContentInsets.top;
828 tmpRect.right -= child.mGivenContentInsets.right;
829 tmpRect.bottom -= child.mGivenContentInsets.bottom;
830 } else if (child.mTouchableInsets == ViewTreeObserver
831 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
832 // The point is inside of the window if it is
833 // inside the frame, AND the visible part of that
834 // frame that was given by the application.
835 tmpRect.left += child.mGivenVisibleInsets.left;
836 tmpRect.top += child.mGivenVisibleInsets.top;
837 tmpRect.right -= child.mGivenVisibleInsets.right;
838 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
839 }
840 final int touchFlags = flags &
841 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
842 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
843 if (tmpRect.contains(x, y) || touchFlags == 0) {
844 // Found it
845 touchedWin = child;
846 break;
847 }
848 }
849
850 return touchedWin;
851 }
Christopher Tateccd24de2011-01-12 15:02:55 -0800852
853 void setDeferredRotation(int rotation, int animFlags) {
854 mRotation = rotation;
855 mAnimFlags = animFlags;
856 mPerformDeferredRotation = true;
857 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700858 }
859
860 DragState mDragState = null;
861 private final InputHandler mDragInputHandler = new BaseInputHandler() {
862 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700863 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
864 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700865 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700866 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
867 && mDragState != null) {
868 boolean endDrag = false;
869 final float newX = event.getRawX();
870 final float newY = event.getRawY();
871
Christopher Tatea53146c2010-09-07 11:57:52 -0700872 switch (event.getAction()) {
873 case MotionEvent.ACTION_DOWN: {
874 if (DEBUG_DRAG) {
875 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
876 }
877 } break;
878
879 case MotionEvent.ACTION_MOVE: {
880 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700881 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700882 mDragState.notifyMoveLw(newX, newY);
883 }
884 } break;
885
886 case MotionEvent.ACTION_UP: {
887 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
888 + newX + "," + newY);
889 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700890 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700891 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700892 } break;
893
894 case MotionEvent.ACTION_CANCEL: {
895 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
896 endDrag = true;
897 } break;
898 }
899
900 if (endDrag) {
901 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
902 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700903 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700904 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700905 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700906 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700907
908 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700909 }
910 } catch (Exception e) {
911 Slog.e(TAG, "Exception caught by drag handleMotion", e);
912 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700913 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700914 }
915 }
916 };
917
918 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 * Whether the UI is currently running in touch mode (not showing
920 * navigational focus because the user is directly pressing the screen).
921 */
922 boolean mInTouchMode = false;
923
924 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700925 private ArrayList<WindowChangeListener> mWindowChangeListeners =
926 new ArrayList<WindowChangeListener>();
927 private boolean mWindowsChanged = false;
928
929 public interface WindowChangeListener {
930 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700931 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700932 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933
Dianne Hackbornc485a602009-03-24 22:39:49 -0700934 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700935 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700936
937 // The frame use to limit the size of the app running in compatibility mode.
938 Rect mCompatibleScreenFrame = new Rect();
939 // The surface used to fill the outer rim of the app running in compatibility mode.
940 Surface mBackgroundFillerSurface = null;
941 boolean mBackgroundFillerShown = false;
942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 public static WindowManagerService main(Context context,
944 PowerManagerService pm, boolean haveInputMethods) {
945 WMThread thr = new WMThread(context, pm, haveInputMethods);
946 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 synchronized (thr) {
949 while (thr.mService == null) {
950 try {
951 thr.wait();
952 } catch (InterruptedException e) {
953 }
954 }
955 }
Romain Guy06882f82009-06-10 13:36:04 -0700956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 return thr.mService;
958 }
Romain Guy06882f82009-06-10 13:36:04 -0700959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 static class WMThread extends Thread {
961 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 private final Context mContext;
964 private final PowerManagerService mPM;
965 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 public WMThread(Context context, PowerManagerService pm,
968 boolean haveInputMethods) {
969 super("WindowManager");
970 mContext = context;
971 mPM = pm;
972 mHaveInputMethods = haveInputMethods;
973 }
Romain Guy06882f82009-06-10 13:36:04 -0700974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 public void run() {
976 Looper.prepare();
977 WindowManagerService s = new WindowManagerService(mContext, mPM,
978 mHaveInputMethods);
979 android.os.Process.setThreadPriority(
980 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700981 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 synchronized (this) {
984 mService = s;
985 notifyAll();
986 }
Romain Guy06882f82009-06-10 13:36:04 -0700987
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700988 // For debug builds, log event loop stalls to dropbox for analysis.
989 if (StrictMode.conditionallyEnableDebugLogging()) {
990 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
991 }
992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 Looper.loop();
994 }
995 }
996
997 static class PolicyThread extends Thread {
998 private final WindowManagerPolicy mPolicy;
999 private final WindowManagerService mService;
1000 private final Context mContext;
1001 private final PowerManagerService mPM;
1002 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -07001003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 public PolicyThread(WindowManagerPolicy policy,
1005 WindowManagerService service, Context context,
1006 PowerManagerService pm) {
1007 super("WindowManagerPolicy");
1008 mPolicy = policy;
1009 mService = service;
1010 mContext = context;
1011 mPM = pm;
1012 }
Romain Guy06882f82009-06-10 13:36:04 -07001013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 public void run() {
1015 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -08001016 WindowManagerPolicyThread.set(this, Looper.myLooper());
1017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -08001019 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 android.os.Process.setThreadPriority(
1021 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -07001022 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -07001024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 synchronized (this) {
1026 mRunning = true;
1027 notifyAll();
1028 }
Romain Guy06882f82009-06-10 13:36:04 -07001029
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001030 // For debug builds, log event loop stalls to dropbox for analysis.
1031 if (StrictMode.conditionallyEnableDebugLogging()) {
1032 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1033 }
1034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 Looper.loop();
1036 }
1037 }
1038
1039 private WindowManagerService(Context context, PowerManagerService pm,
1040 boolean haveInputMethods) {
1041 mContext = context;
1042 mHaveInputMethods = haveInputMethods;
1043 mLimitedAlphaCompositing = context.getResources().getBoolean(
1044 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 mPowerManager = pm;
1047 mPowerManager.setPolicy(mPolicy);
1048 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1049 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1050 "SCREEN_FROZEN");
1051 mScreenFrozenLock.setReferenceCounted(false);
1052
1053 mActivityManager = ActivityManagerNative.getDefault();
1054 mBatteryStats = BatteryStatsService.getService();
1055
1056 // Get persisted window scale setting
1057 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1058 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1059 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1060 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001061
Jim Miller284b62e2010-06-08 14:27:42 -07001062 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1063 IntentFilter filter = new IntentFilter();
1064 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1065 mContext.registerReceiver(mBroadcastReceiver, filter);
1066
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001067 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1068 "KEEP_SCREEN_ON_FLAG");
1069 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070
Jeff Browne33348b2010-07-15 23:54:05 -07001071 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1074 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 synchronized (thr) {
1077 while (!thr.mRunning) {
1078 try {
1079 thr.wait();
1080 } catch (InterruptedException e) {
1081 }
1082 }
1083 }
Romain Guy06882f82009-06-10 13:36:04 -07001084
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001085 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 // Add ourself to the Watchdog monitors.
1088 Watchdog.getInstance().addMonitor(this);
1089 }
1090
1091 @Override
1092 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1093 throws RemoteException {
1094 try {
1095 return super.onTransact(code, data, reply, flags);
1096 } catch (RuntimeException e) {
1097 // The window manager only throws security exceptions, so let's
1098 // log all others.
1099 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001100 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 }
1102 throw e;
1103 }
1104 }
1105
Jeff Browne33348b2010-07-15 23:54:05 -07001106 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001108 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 TAG, "Adding window " + window + " at "
1110 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1111 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001112 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114
Jeff Browne33348b2010-07-15 23:54:05 -07001115 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001117 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 TAG, "Adding window " + window + " at "
1119 + i + " of " + mWindows.size() + " (before " + pos + ")");
1120 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001121 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 }
1123
1124 //This method finds out the index of a window that has the same app token as
1125 //win. used for z ordering the windows in mWindows
1126 private int findIdxBasedOnAppTokens(WindowState win) {
1127 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001128 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 int jmax = localmWindows.size();
1130 if(jmax == 0) {
1131 return -1;
1132 }
1133 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001134 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 if(wentry.mAppToken == win.mAppToken) {
1136 return j;
1137 }
1138 }
1139 return -1;
1140 }
Romain Guy06882f82009-06-10 13:36:04 -07001141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1143 final IWindow client = win.mClient;
1144 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001145 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 final int N = localmWindows.size();
1148 final WindowState attached = win.mAttachedWindow;
1149 int i;
1150 if (attached == null) {
1151 int tokenWindowsPos = token.windows.size();
1152 if (token.appWindowToken != null) {
1153 int index = tokenWindowsPos-1;
1154 if (index >= 0) {
1155 // If this application has existing windows, we
1156 // simply place the new window on top of them... but
1157 // keep the starting window on top.
1158 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1159 // Base windows go behind everything else.
1160 placeWindowBefore(token.windows.get(0), win);
1161 tokenWindowsPos = 0;
1162 } else {
1163 AppWindowToken atoken = win.mAppToken;
1164 if (atoken != null &&
1165 token.windows.get(index) == atoken.startingWindow) {
1166 placeWindowBefore(token.windows.get(index), win);
1167 tokenWindowsPos--;
1168 } else {
1169 int newIdx = findIdxBasedOnAppTokens(win);
1170 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001171 //there is a window above this one associated with the same
1172 //apptoken note that the window could be a floating window
1173 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001175 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1176 Slog.v(TAG, "Adding window " + win + " at "
1177 + (newIdx+1) + " of " + N);
1178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001180 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 }
1183 }
1184 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001185 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 TAG, "Figuring out where to add app window "
1187 + client.asBinder() + " (token=" + token + ")");
1188 // Figure out where the window should go, based on the
1189 // order of applications.
1190 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001191 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 for (i=NA-1; i>=0; i--) {
1193 AppWindowToken t = mAppTokens.get(i);
1194 if (t == token) {
1195 i--;
1196 break;
1197 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001198
Dianne Hackborna8f60182009-09-01 19:01:50 -07001199 // We haven't reached the token yet; if this token
1200 // is not going to the bottom and has windows, we can
1201 // use it as an anchor for when we do reach the token.
1202 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 pos = t.windows.get(0);
1204 }
1205 }
1206 // We now know the index into the apps. If we found
1207 // an app window above, that gives us the position; else
1208 // we need to look some more.
1209 if (pos != null) {
1210 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001211 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 if (atoken != null) {
1213 final int NC = atoken.windows.size();
1214 if (NC > 0) {
1215 WindowState bottom = atoken.windows.get(0);
1216 if (bottom.mSubLayer < 0) {
1217 pos = bottom;
1218 }
1219 }
1220 }
1221 placeWindowBefore(pos, win);
1222 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001223 // Continue looking down until we find the first
1224 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 while (i >= 0) {
1226 AppWindowToken t = mAppTokens.get(i);
1227 final int NW = t.windows.size();
1228 if (NW > 0) {
1229 pos = t.windows.get(NW-1);
1230 break;
1231 }
1232 i--;
1233 }
1234 if (pos != null) {
1235 // Move in front of any windows attached to this
1236 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001237 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 if (atoken != null) {
1239 final int NC = atoken.windows.size();
1240 if (NC > 0) {
1241 WindowState top = atoken.windows.get(NC-1);
1242 if (top.mSubLayer >= 0) {
1243 pos = top;
1244 }
1245 }
1246 }
1247 placeWindowAfter(pos, win);
1248 } else {
1249 // Just search for the start of this layer.
1250 final int myLayer = win.mBaseLayer;
1251 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001252 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 if (w.mBaseLayer > myLayer) {
1254 break;
1255 }
1256 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001257 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1258 Slog.v(TAG, "Adding window " + win + " at "
1259 + i + " of " + N);
1260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001262 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 }
1264 }
1265 }
1266 } else {
1267 // Figure out where window should go, based on layer.
1268 final int myLayer = win.mBaseLayer;
1269 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001270 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 i++;
1272 break;
1273 }
1274 }
1275 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001276 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001277 TAG, "Adding window " + win + " at "
1278 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001280 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 }
1282 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001283 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 token.windows.add(tokenWindowsPos, win);
1285 }
1286
1287 } else {
1288 // Figure out this window's ordering relative to the window
1289 // it is attached to.
1290 final int NA = token.windows.size();
1291 final int sublayer = win.mSubLayer;
1292 int largestSublayer = Integer.MIN_VALUE;
1293 WindowState windowWithLargestSublayer = null;
1294 for (i=0; i<NA; i++) {
1295 WindowState w = token.windows.get(i);
1296 final int wSublayer = w.mSubLayer;
1297 if (wSublayer >= largestSublayer) {
1298 largestSublayer = wSublayer;
1299 windowWithLargestSublayer = w;
1300 }
1301 if (sublayer < 0) {
1302 // For negative sublayers, we go below all windows
1303 // in the same sublayer.
1304 if (wSublayer >= sublayer) {
1305 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001306 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 token.windows.add(i, win);
1308 }
1309 placeWindowBefore(
1310 wSublayer >= 0 ? attached : w, win);
1311 break;
1312 }
1313 } else {
1314 // For positive sublayers, we go above all windows
1315 // in the same sublayer.
1316 if (wSublayer > sublayer) {
1317 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001318 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 token.windows.add(i, win);
1320 }
1321 placeWindowBefore(w, win);
1322 break;
1323 }
1324 }
1325 }
1326 if (i >= NA) {
1327 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001328 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 token.windows.add(win);
1330 }
1331 if (sublayer < 0) {
1332 placeWindowBefore(attached, win);
1333 } else {
1334 placeWindowAfter(largestSublayer >= 0
1335 ? windowWithLargestSublayer
1336 : attached,
1337 win);
1338 }
1339 }
1340 }
Romain Guy06882f82009-06-10 13:36:04 -07001341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 if (win.mAppToken != null && addToToken) {
1343 win.mAppToken.allAppWindows.add(win);
1344 }
1345 }
Romain Guy06882f82009-06-10 13:36:04 -07001346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 static boolean canBeImeTarget(WindowState w) {
1348 final int fl = w.mAttrs.flags
1349 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1350 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1351 return w.isVisibleOrAdding();
1352 }
1353 return false;
1354 }
Romain Guy06882f82009-06-10 13:36:04 -07001355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001357 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 final int N = localmWindows.size();
1359 WindowState w = null;
1360 int i = N;
1361 while (i > 0) {
1362 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001363 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001364
Joe Onorato8a9b2202010-02-26 18:56:32 -08001365 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 // + Integer.toHexString(w.mAttrs.flags));
1367 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001368 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 // Yet more tricksyness! If this window is a "starting"
1371 // window, we do actually want to be on top of it, but
1372 // it is not -really- where input will go. So if the caller
1373 // is not actually looking to move the IME, look down below
1374 // for a real window to target...
1375 if (!willMove
1376 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1377 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001378 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1380 i--;
1381 w = wb;
1382 }
1383 }
1384 break;
1385 }
1386 }
Romain Guy06882f82009-06-10 13:36:04 -07001387
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001388 // Now, a special case -- if the last target's window is in the
1389 // process of exiting, and is above the new target, keep on the
1390 // last target to avoid flicker. Consider for example a Dialog with
1391 // the IME shown: when the Dialog is dismissed, we want to keep
1392 // the IME above it until it is completely gone so it doesn't drop
1393 // behind the dialog or its full-screen scrim.
1394 if (mInputMethodTarget != null && w != null
1395 && mInputMethodTarget.isDisplayedLw()
1396 && mInputMethodTarget.mExiting) {
1397 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1398 w = mInputMethodTarget;
1399 i = localmWindows.indexOf(w);
1400 }
1401 }
Romain Guy06882f82009-06-10 13:36:04 -07001402
Joe Onorato8a9b2202010-02-26 18:56:32 -08001403 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 if (willMove && w != null) {
1407 final WindowState curTarget = mInputMethodTarget;
1408 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 // Now some fun for dealing with window animations that
1411 // modify the Z order. We need to look at all windows below
1412 // the current target that are in this app, finding the highest
1413 // visible one in layering.
1414 AppWindowToken token = curTarget.mAppToken;
1415 WindowState highestTarget = null;
1416 int highestPos = 0;
1417 if (token.animating || token.animation != null) {
1418 int pos = 0;
1419 pos = localmWindows.indexOf(curTarget);
1420 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001421 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 if (win.mAppToken != token) {
1423 break;
1424 }
1425 if (!win.mRemoved) {
1426 if (highestTarget == null || win.mAnimLayer >
1427 highestTarget.mAnimLayer) {
1428 highestTarget = win;
1429 highestPos = pos;
1430 }
1431 }
1432 pos--;
1433 }
1434 }
Romain Guy06882f82009-06-10 13:36:04 -07001435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001437 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 + mNextAppTransition + " " + highestTarget
1439 + " animating=" + highestTarget.isAnimating()
1440 + " layer=" + highestTarget.mAnimLayer
1441 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001442
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001443 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 // If we are currently setting up for an animation,
1445 // hold everything until we can find out what will happen.
1446 mInputMethodTargetWaitingAnim = true;
1447 mInputMethodTarget = highestTarget;
1448 return highestPos + 1;
1449 } else if (highestTarget.isAnimating() &&
1450 highestTarget.mAnimLayer > w.mAnimLayer) {
1451 // If the window we are currently targeting is involved
1452 // with an animation, and it is on top of the next target
1453 // we will be over, then hold off on moving until
1454 // that is done.
1455 mInputMethodTarget = highestTarget;
1456 return highestPos + 1;
1457 }
1458 }
1459 }
1460 }
Romain Guy06882f82009-06-10 13:36:04 -07001461
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 if (w != null) {
1464 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001465 if (DEBUG_INPUT_METHOD) {
1466 RuntimeException e = null;
1467 if (!HIDE_STACK_CRAWLS) {
1468 e = new RuntimeException();
1469 e.fillInStackTrace();
1470 }
1471 Slog.w(TAG, "Moving IM target from "
1472 + mInputMethodTarget + " to " + w, e);
1473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 mInputMethodTarget = w;
1475 if (w.mAppToken != null) {
1476 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1477 } else {
1478 setInputMethodAnimLayerAdjustment(0);
1479 }
1480 }
1481 return i+1;
1482 }
1483 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001484 if (DEBUG_INPUT_METHOD) {
1485 RuntimeException e = null;
1486 if (!HIDE_STACK_CRAWLS) {
1487 e = new RuntimeException();
1488 e.fillInStackTrace();
1489 }
1490 Slog.w(TAG, "Moving IM target from "
1491 + mInputMethodTarget + " to null", e);
1492 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 mInputMethodTarget = null;
1494 setInputMethodAnimLayerAdjustment(0);
1495 }
1496 return -1;
1497 }
Romain Guy06882f82009-06-10 13:36:04 -07001498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 void addInputMethodWindowToListLocked(WindowState win) {
1500 int pos = findDesiredInputMethodWindowIndexLocked(true);
1501 if (pos >= 0) {
1502 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001503 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001504 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001506 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 moveInputMethodDialogsLocked(pos+1);
1508 return;
1509 }
1510 win.mTargetAppToken = null;
1511 addWindowToListInOrderLocked(win, true);
1512 moveInputMethodDialogsLocked(pos);
1513 }
Romain Guy06882f82009-06-10 13:36:04 -07001514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001516 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 mInputMethodAnimLayerAdjustment = adj;
1518 WindowState imw = mInputMethodWindow;
1519 if (imw != null) {
1520 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001521 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 + " anim layer: " + imw.mAnimLayer);
1523 int wi = imw.mChildWindows.size();
1524 while (wi > 0) {
1525 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001526 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001528 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 + " anim layer: " + cw.mAnimLayer);
1530 }
1531 }
1532 int di = mInputMethodDialogs.size();
1533 while (di > 0) {
1534 di --;
1535 imw = mInputMethodDialogs.get(di);
1536 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001537 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 + " anim layer: " + imw.mAnimLayer);
1539 }
1540 }
Romain Guy06882f82009-06-10 13:36:04 -07001541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1543 int wpos = mWindows.indexOf(win);
1544 if (wpos >= 0) {
1545 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001546 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001548 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 int NC = win.mChildWindows.size();
1550 while (NC > 0) {
1551 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001552 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 int cpos = mWindows.indexOf(cw);
1554 if (cpos >= 0) {
1555 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001556 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001557 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 mWindows.remove(cpos);
1559 }
1560 }
1561 }
1562 return interestingPos;
1563 }
Romain Guy06882f82009-06-10 13:36:04 -07001564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 private void reAddWindowToListInOrderLocked(WindowState win) {
1566 addWindowToListInOrderLocked(win, false);
1567 // This is a hack to get all of the child windows added as well
1568 // at the right position. Child windows should be rare and
1569 // this case should be rare, so it shouldn't be that big a deal.
1570 int wpos = mWindows.indexOf(win);
1571 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001572 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001573 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001575 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 reAddWindowLocked(wpos, win);
1577 }
1578 }
Romain Guy06882f82009-06-10 13:36:04 -07001579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 void logWindowList(String prefix) {
1581 int N = mWindows.size();
1582 while (N > 0) {
1583 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001584 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 }
1586 }
Romain Guy06882f82009-06-10 13:36:04 -07001587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 void moveInputMethodDialogsLocked(int pos) {
1589 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001592 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593 for (int i=0; i<N; i++) {
1594 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1595 }
1596 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001597 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 logWindowList(" ");
1599 }
Romain Guy06882f82009-06-10 13:36:04 -07001600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 if (pos >= 0) {
1602 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1603 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001604 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 if (wp == mInputMethodWindow) {
1606 pos++;
1607 }
1608 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001609 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 for (int i=0; i<N; i++) {
1611 WindowState win = dialogs.get(i);
1612 win.mTargetAppToken = targetAppToken;
1613 pos = reAddWindowLocked(pos, win);
1614 }
1615 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001616 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 logWindowList(" ");
1618 }
1619 return;
1620 }
1621 for (int i=0; i<N; i++) {
1622 WindowState win = dialogs.get(i);
1623 win.mTargetAppToken = null;
1624 reAddWindowToListInOrderLocked(win);
1625 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 logWindowList(" ");
1628 }
1629 }
1630 }
Romain Guy06882f82009-06-10 13:36:04 -07001631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1633 final WindowState imWin = mInputMethodWindow;
1634 final int DN = mInputMethodDialogs.size();
1635 if (imWin == null && DN == 0) {
1636 return false;
1637 }
Romain Guy06882f82009-06-10 13:36:04 -07001638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1640 if (imPos >= 0) {
1641 // In this case, the input method windows are to be placed
1642 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001644 // First check to see if the input method windows are already
1645 // located here, and contiguous.
1646 final int N = mWindows.size();
1647 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001648 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 // Figure out the actual input method window that should be
1651 // at the bottom of their stack.
1652 WindowState baseImWin = imWin != null
1653 ? imWin : mInputMethodDialogs.get(0);
1654 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001655 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 if (cw.mSubLayer < 0) baseImWin = cw;
1657 }
Romain Guy06882f82009-06-10 13:36:04 -07001658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 if (firstImWin == baseImWin) {
1660 // The windows haven't moved... but are they still contiguous?
1661 // First find the top IM window.
1662 int pos = imPos+1;
1663 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001664 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 break;
1666 }
1667 pos++;
1668 }
1669 pos++;
1670 // Now there should be no more input method windows above.
1671 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001672 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 break;
1674 }
1675 pos++;
1676 }
1677 if (pos >= N) {
1678 // All is good!
1679 return false;
1680 }
1681 }
Romain Guy06882f82009-06-10 13:36:04 -07001682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 if (imWin != null) {
1684 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001685 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686 logWindowList(" ");
1687 }
1688 imPos = tmpRemoveWindowLocked(imPos, imWin);
1689 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001690 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 logWindowList(" ");
1692 }
1693 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1694 reAddWindowLocked(imPos, imWin);
1695 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001696 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 logWindowList(" ");
1698 }
1699 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1700 } else {
1701 moveInputMethodDialogsLocked(imPos);
1702 }
Romain Guy06882f82009-06-10 13:36:04 -07001703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 } else {
1705 // In this case, the input method windows go in a fixed layer,
1706 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001709 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 tmpRemoveWindowLocked(0, imWin);
1711 imWin.mTargetAppToken = null;
1712 reAddWindowToListInOrderLocked(imWin);
1713 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001714 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 logWindowList(" ");
1716 }
1717 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1718 } else {
1719 moveInputMethodDialogsLocked(-1);;
1720 }
Romain Guy06882f82009-06-10 13:36:04 -07001721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 }
Romain Guy06882f82009-06-10 13:36:04 -07001723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 if (needAssignLayers) {
1725 assignLayersLocked();
1726 }
Romain Guy06882f82009-06-10 13:36:04 -07001727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 return true;
1729 }
Romain Guy06882f82009-06-10 13:36:04 -07001730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001731 void adjustInputMethodDialogsLocked() {
1732 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1733 }
Romain Guy06882f82009-06-10 13:36:04 -07001734
Dianne Hackborn25994b42009-09-04 14:21:19 -07001735 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001736 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001737 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1738 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1739 ? wallpaperTarget.mAppToken.animation : null)
1740 + " upper=" + mUpperWallpaperTarget
1741 + " lower=" + mLowerWallpaperTarget);
1742 return (wallpaperTarget != null
1743 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1744 && wallpaperTarget.mAppToken.animation != null)))
1745 || mUpperWallpaperTarget != null
1746 || mLowerWallpaperTarget != null;
1747 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001749 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1750 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001751
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001752 int adjustWallpaperWindowsLocked() {
1753 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001754
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001755 final int dw = mDisplay.getWidth();
1756 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001757
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001758 // First find top-most window that has asked to be on top of the
1759 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001760 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001761 int N = localmWindows.size();
1762 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001763 WindowState foundW = null;
1764 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001765 WindowState topCurW = null;
1766 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001767 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001768 int i = N;
1769 while (i > 0) {
1770 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001771 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001772 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1773 if (topCurW == null) {
1774 topCurW = w;
1775 topCurI = i;
1776 }
1777 continue;
1778 }
1779 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001780 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001781 // If this window's app token is hidden and not animating,
1782 // it is of no interest to us.
1783 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001784 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001785 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001786 continue;
1787 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001788 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001789 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001790 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1791 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001792 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001793 && (mWallpaperTarget == w
1794 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001795 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001796 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001797 foundW = w;
1798 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001799 if (w == mWallpaperTarget && ((w.mAppToken != null
1800 && w.mAppToken.animation != null)
1801 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001802 // The current wallpaper target is animating, so we'll
1803 // look behind it for another possible target and figure
1804 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001805 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001807 continue;
1808 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001809 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001810 } else if (w == mWindowDetachedWallpaper) {
1811 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001812 }
1813 }
1814
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001815 if (foundW == null && windowDetachedI >= 0) {
1816 if (DEBUG_WALLPAPER) Slog.v(TAG,
1817 "Found animating detached wallpaper activity: #" + i + "=" + w);
1818 foundW = w;
1819 foundI = windowDetachedI;
1820 }
1821
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001822 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001823 // If we are currently waiting for an app transition, and either
1824 // the current target or the next target are involved with it,
1825 // then hold off on doing anything with the wallpaper.
1826 // Note that we are checking here for just whether the target
1827 // is part of an app token... which is potentially overly aggressive
1828 // (the app token may not be involved in the transition), but good
1829 // enough (we'll just wait until whatever transition is pending
1830 // executes).
1831 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001833 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001834 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001835 }
1836 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001837 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001838 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001839 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001840 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001841 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001842
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001843 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001844 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001845 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001846 + " oldTarget: " + mWallpaperTarget);
1847 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001848
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001849 mLowerWallpaperTarget = null;
1850 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001851
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001852 WindowState oldW = mWallpaperTarget;
1853 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001854
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001855 // Now what is happening... if the current and new targets are
1856 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001857 if (foundW != null && oldW != null) {
1858 boolean oldAnim = oldW.mAnimation != null
1859 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1860 boolean foundAnim = foundW.mAnimation != null
1861 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001862 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001864 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001865 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001866 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001867 int oldI = localmWindows.indexOf(oldW);
1868 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 }
1871 if (oldI >= 0) {
1872 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001873 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001874 + "=" + oldW + "; new#" + foundI
1875 + "=" + foundW);
1876 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001877
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001878 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001879 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001880 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001881 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001882 }
1883 mWallpaperTarget = oldW;
1884 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001885
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001886 // Now set the upper and lower wallpaper targets
1887 // correctly, and make sure that we are positioning
1888 // the wallpaper below the lower.
1889 if (foundI > oldI) {
1890 // The new target is on top of the old one.
1891 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001892 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001893 }
1894 mUpperWallpaperTarget = foundW;
1895 mLowerWallpaperTarget = oldW;
1896 foundW = oldW;
1897 foundI = oldI;
1898 } else {
1899 // The new target is below the old one.
1900 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001901 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001902 }
1903 mUpperWallpaperTarget = oldW;
1904 mLowerWallpaperTarget = foundW;
1905 }
1906 }
1907 }
1908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001909
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001910 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001911 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001912 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1913 || (mLowerWallpaperTarget.mAppToken != null
1914 && mLowerWallpaperTarget.mAppToken.animation != null);
1915 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1916 || (mUpperWallpaperTarget.mAppToken != null
1917 && mUpperWallpaperTarget.mAppToken.animation != null);
1918 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001919 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001920 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001921 }
1922 mLowerWallpaperTarget = null;
1923 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001924 }
1925 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001926
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001927 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001928 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001929 // The window is visible to the compositor... but is it visible
1930 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001931 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001932 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001933
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001934 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001935 // its layer adjustment. Only do this if we are not transfering
1936 // between two wallpaper targets.
1937 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001938 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001939 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001940
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001941 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1942 * TYPE_LAYER_MULTIPLIER
1943 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001944
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001945 // Now w is the window we are supposed to be behind... but we
1946 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001947 // AND any starting window associated with it, AND below the
1948 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001949 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001950 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001951 if (wb.mBaseLayer < maxLayer &&
1952 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001953 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001954 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001955 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001956 // This window is not related to the previous one in any
1957 // interesting way, so stop here.
1958 break;
1959 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001960 foundW = wb;
1961 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001962 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001963 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001964 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001966
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001967 if (foundW == null && topCurW != null) {
1968 // There is no wallpaper target, so it goes at the bottom.
1969 // We will assume it is the same place as last time, if known.
1970 foundW = topCurW;
1971 foundI = topCurI+1;
1972 } else {
1973 // Okay i is the position immediately above the wallpaper. Look at
1974 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001975 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001976 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001977
Dianne Hackborn284ac932009-08-28 10:34:25 -07001978 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001979 if (mWallpaperTarget.mWallpaperX >= 0) {
1980 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001981 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001982 }
1983 if (mWallpaperTarget.mWallpaperY >= 0) {
1984 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001985 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001986 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001987 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001989 // Start stepping backwards from here, ensuring that our wallpaper windows
1990 // are correctly placed.
1991 int curTokenIndex = mWallpaperTokens.size();
1992 while (curTokenIndex > 0) {
1993 curTokenIndex--;
1994 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001995 if (token.hidden == visible) {
1996 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1997 token.hidden = !visible;
1998 // Need to do a layout to ensure the wallpaper now has the
1999 // correct size.
2000 mLayoutNeeded = true;
2001 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002002
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002003 int curWallpaperIndex = token.windows.size();
2004 while (curWallpaperIndex > 0) {
2005 curWallpaperIndex--;
2006 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002007
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002008 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002009 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002010 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002011
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002012 // First, make sure the client has the current visibility
2013 // state.
2014 if (wallpaper.mWallpaperVisible != visible) {
2015 wallpaper.mWallpaperVisible = visible;
2016 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002017 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002018 "Setting visibility of wallpaper " + wallpaper
2019 + ": " + visible);
2020 wallpaper.mClient.dispatchAppVisibility(visible);
2021 } catch (RemoteException e) {
2022 }
2023 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002024
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002025 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002026 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002027 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002028
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002029 // First, if this window is at the current index, then all
2030 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002031 if (wallpaper == foundW) {
2032 foundI--;
2033 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002034 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002035 continue;
2036 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002037
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002038 // The window didn't match... the current wallpaper window,
2039 // wherever it is, is in the wrong place, so make sure it is
2040 // not in the list.
2041 int oldIndex = localmWindows.indexOf(wallpaper);
2042 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002043 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002044 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002045 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002046 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002047 if (oldIndex < foundI) {
2048 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002049 }
2050 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002051
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002052 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002053 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2054 Slog.v(TAG, "Moving wallpaper " + wallpaper
2055 + " from " + oldIndex + " to " + foundI);
2056 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002057
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002058 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002059 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002060 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002061 }
2062 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002063
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002064 return changed;
2065 }
2066
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002067 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002068 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002069 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002070 mWallpaperAnimLayerAdjustment = adj;
2071 int curTokenIndex = mWallpaperTokens.size();
2072 while (curTokenIndex > 0) {
2073 curTokenIndex--;
2074 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2075 int curWallpaperIndex = token.windows.size();
2076 while (curWallpaperIndex > 0) {
2077 curWallpaperIndex--;
2078 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2079 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002080 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002081 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002082 }
2083 }
2084 }
2085
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002086 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2087 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002088 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002089 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002090 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002091 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002092 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2093 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2094 changed = wallpaperWin.mXOffset != offset;
2095 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002096 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002097 + wallpaperWin + " x: " + offset);
2098 wallpaperWin.mXOffset = offset;
2099 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002100 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002101 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002102 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002103 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002104 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002105
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002106 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002107 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002108 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2109 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2110 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002111 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002112 + wallpaperWin + " y: " + offset);
2113 changed = true;
2114 wallpaperWin.mYOffset = offset;
2115 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002116 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002117 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002118 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002119 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002120 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002121
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002122 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002123 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002124 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002125 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2126 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002127 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002128 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002129 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002130 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002131 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2132 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002133 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002134 if (mWaitingOnWallpaper != null) {
2135 long start = SystemClock.uptimeMillis();
2136 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2137 < start) {
2138 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002139 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002140 "Waiting for offset complete...");
2141 mWindowMap.wait(WALLPAPER_TIMEOUT);
2142 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002143 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002144 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002145 if ((start+WALLPAPER_TIMEOUT)
2146 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002147 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002148 + wallpaperWin);
2149 mLastWallpaperTimeoutTime = start;
2150 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002151 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002152 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002153 }
2154 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002155 } catch (RemoteException e) {
2156 }
2157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002158
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002159 return changed;
2160 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002161
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002162 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002163 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002164 if (mWaitingOnWallpaper != null &&
2165 mWaitingOnWallpaper.mClient.asBinder() == window) {
2166 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002167 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002168 }
2169 }
2170 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002171
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002172 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002173 final int dw = mDisplay.getWidth();
2174 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002175
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002176 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002177
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002178 WindowState target = mWallpaperTarget;
2179 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002180 if (target.mWallpaperX >= 0) {
2181 mLastWallpaperX = target.mWallpaperX;
2182 } else if (changingTarget.mWallpaperX >= 0) {
2183 mLastWallpaperX = changingTarget.mWallpaperX;
2184 }
2185 if (target.mWallpaperY >= 0) {
2186 mLastWallpaperY = target.mWallpaperY;
2187 } else if (changingTarget.mWallpaperY >= 0) {
2188 mLastWallpaperY = changingTarget.mWallpaperY;
2189 }
2190 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002191
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002192 int curTokenIndex = mWallpaperTokens.size();
2193 while (curTokenIndex > 0) {
2194 curTokenIndex--;
2195 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2196 int curWallpaperIndex = token.windows.size();
2197 while (curWallpaperIndex > 0) {
2198 curWallpaperIndex--;
2199 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2200 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2201 wallpaper.computeShownFrameLocked();
2202 changed = true;
2203 // We only want to be synchronous with one wallpaper.
2204 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002205 }
2206 }
2207 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002208
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002209 return changed;
2210 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002211
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002212 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002213 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002214 final int dw = mDisplay.getWidth();
2215 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002216
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002217 int curTokenIndex = mWallpaperTokens.size();
2218 while (curTokenIndex > 0) {
2219 curTokenIndex--;
2220 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002221 if (token.hidden == visible) {
2222 token.hidden = !visible;
2223 // Need to do a layout to ensure the wallpaper now has the
2224 // correct size.
2225 mLayoutNeeded = true;
2226 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002227
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002228 int curWallpaperIndex = token.windows.size();
2229 while (curWallpaperIndex > 0) {
2230 curWallpaperIndex--;
2231 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2232 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002233 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002234 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002235
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002236 if (wallpaper.mWallpaperVisible != visible) {
2237 wallpaper.mWallpaperVisible = visible;
2238 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002239 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002240 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002241 + ": " + visible);
2242 wallpaper.mClient.dispatchAppVisibility(visible);
2243 } catch (RemoteException e) {
2244 }
2245 }
2246 }
2247 }
2248 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 public int addWindow(Session session, IWindow client,
2251 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002252 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 int res = mPolicy.checkAddPermission(attrs);
2254 if (res != WindowManagerImpl.ADD_OKAY) {
2255 return res;
2256 }
Romain Guy06882f82009-06-10 13:36:04 -07002257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 boolean reportNewConfig = false;
2259 WindowState attachedWindow = null;
2260 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002261 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002265 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 }
Romain Guy06882f82009-06-10 13:36:04 -07002267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002269 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2271 }
2272
2273 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002274 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002276 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 + attrs.token + ". Aborting.");
2278 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2279 }
2280 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2281 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002282 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 + attrs.token + ". Aborting.");
2284 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2285 }
2286 }
2287
2288 boolean addToken = false;
2289 WindowToken token = mTokenMap.get(attrs.token);
2290 if (token == null) {
2291 if (attrs.type >= FIRST_APPLICATION_WINDOW
2292 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002293 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 + attrs.token + ". Aborting.");
2295 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2296 }
2297 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002298 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 + attrs.token + ". Aborting.");
2300 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2301 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002302 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002303 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002304 + attrs.token + ". Aborting.");
2305 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 token = new WindowToken(attrs.token, -1, false);
2308 addToken = true;
2309 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2310 && attrs.type <= LAST_APPLICATION_WINDOW) {
2311 AppWindowToken atoken = token.appWindowToken;
2312 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002313 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 + token + ". Aborting.");
2315 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2316 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002317 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 + token + ". Aborting.");
2319 return WindowManagerImpl.ADD_APP_EXITING;
2320 }
2321 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2322 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002323 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2325 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2326 }
2327 } else if (attrs.type == TYPE_INPUT_METHOD) {
2328 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002329 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 + attrs.token + ". Aborting.");
2331 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2332 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002333 } else if (attrs.type == TYPE_WALLPAPER) {
2334 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002335 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002336 + attrs.token + ". Aborting.");
2337 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2338 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 }
2340
2341 win = new WindowState(session, client, token,
2342 attachedWindow, attrs, viewVisibility);
2343 if (win.mDeathRecipient == null) {
2344 // Client has apparently died, so there is no reason to
2345 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002346 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 + " that is dead, aborting.");
2348 return WindowManagerImpl.ADD_APP_EXITING;
2349 }
2350
2351 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 res = mPolicy.prepareAddWindowLw(win, attrs);
2354 if (res != WindowManagerImpl.ADD_OKAY) {
2355 return res;
2356 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002357
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002358 if (outInputChannel != null) {
2359 String name = win.makeInputChannelName();
2360 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2361 win.mInputChannel = inputChannels[0];
2362 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2363
Jeff Brown928e0542011-01-10 11:17:36 -08002364 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002365 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366
2367 // From now on, no exceptions or errors allowed!
2368
2369 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002370
Dianne Hackborn5132b372010-07-29 12:51:35 -07002371 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 if (addToken) {
2374 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 }
2376 win.attach();
2377 mWindowMap.put(client.asBinder(), win);
2378
2379 if (attrs.type == TYPE_APPLICATION_STARTING &&
2380 token.appWindowToken != null) {
2381 token.appWindowToken.startingWindow = win;
2382 }
2383
2384 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 if (attrs.type == TYPE_INPUT_METHOD) {
2387 mInputMethodWindow = win;
2388 addInputMethodWindowToListLocked(win);
2389 imMayMove = false;
2390 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2391 mInputMethodDialogs.add(win);
2392 addWindowToListInOrderLocked(win, true);
2393 adjustInputMethodDialogsLocked();
2394 imMayMove = false;
2395 } else {
2396 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002397 if (attrs.type == TYPE_WALLPAPER) {
2398 mLastWallpaperTimeoutTime = 0;
2399 adjustWallpaperWindowsLocked();
2400 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002401 adjustWallpaperWindowsLocked();
2402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 }
Romain Guy06882f82009-06-10 13:36:04 -07002404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409 if (mInTouchMode) {
2410 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2411 }
2412 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2413 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2414 }
Romain Guy06882f82009-06-10 13:36:04 -07002415
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002416 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002418 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2419 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 imMayMove = false;
2421 }
2422 }
Romain Guy06882f82009-06-10 13:36:04 -07002423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002425 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 }
Romain Guy06882f82009-06-10 13:36:04 -07002427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 assignLayersLocked();
2429 // Don't do layout here, the window must call
2430 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 //dump();
2433
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002434 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002435 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002436 }
Jeff Brown349703e2010-06-22 01:27:15 -07002437
Joe Onorato8a9b2202010-02-26 18:56:32 -08002438 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 TAG, "New client " + client.asBinder()
2440 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002441
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002442 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002443 reportNewConfig = true;
2444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 }
2446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 if (reportNewConfig) {
2448 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 return res;
2454 }
Romain Guy06882f82009-06-10 13:36:04 -07002455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 public void removeWindow(Session session, IWindow client) {
2457 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002458 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 if (win == null) {
2460 return;
2461 }
2462 removeWindowLocked(session, win);
2463 }
2464 }
Romain Guy06882f82009-06-10 13:36:04 -07002465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 public void removeWindowLocked(Session session, WindowState win) {
2467
Joe Onorato8a9b2202010-02-26 18:56:32 -08002468 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 TAG, "Remove " + win + " client="
2470 + Integer.toHexString(System.identityHashCode(
2471 win.mClient.asBinder()))
2472 + ", surface=" + win.mSurface);
2473
2474 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002475
2476 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002477
Joe Onorato8a9b2202010-02-26 18:56:32 -08002478 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2480 + " mExiting=" + win.mExiting
2481 + " isAnimating=" + win.isAnimating()
2482 + " app-animation="
2483 + (win.mAppToken != null ? win.mAppToken.animation : null)
2484 + " inPendingTransaction="
2485 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2486 + " mDisplayFrozen=" + mDisplayFrozen);
2487 // Visibility of the removed window. Will be used later to update orientation later on.
2488 boolean wasVisible = false;
2489 // First, see if we need to run an animation. If we do, we have
2490 // to hold off on removing the window until the animation is done.
2491 // If the display is frozen, just remove immediately, since the
2492 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002493 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 // If we are not currently running the exit animation, we
2495 // need to see about starting one.
2496 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2499 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2500 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2501 }
2502 // Try starting an animation.
2503 if (applyAnimationLocked(win, transit, false)) {
2504 win.mExiting = true;
2505 }
2506 }
2507 if (win.mExiting || win.isAnimating()) {
2508 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002509 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 win.mExiting = true;
2511 win.mRemoveOnExit = true;
2512 mLayoutNeeded = true;
2513 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2514 performLayoutAndPlaceSurfacesLocked();
2515 if (win.mAppToken != null) {
2516 win.mAppToken.updateReportedVisibilityLocked();
2517 }
2518 //dump();
2519 Binder.restoreCallingIdentity(origId);
2520 return;
2521 }
2522 }
2523
2524 removeWindowInnerLocked(session, win);
2525 // Removing a visible window will effect the computed orientation
2526 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002527 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002528 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002529 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002530 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 }
2532 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2533 Binder.restoreCallingIdentity(origId);
2534 }
Romain Guy06882f82009-06-10 13:36:04 -07002535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002537 if (win.mRemoved) {
2538 // Nothing to do.
2539 return;
2540 }
2541
2542 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2543 WindowState cwin = win.mChildWindows.get(i);
2544 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2545 + win);
2546 removeWindowInnerLocked(cwin.mSession, cwin);
2547 }
2548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 if (mInputMethodTarget == win) {
2552 moveInputMethodWindowsIfNeededLocked(false);
2553 }
Romain Guy06882f82009-06-10 13:36:04 -07002554
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002555 if (false) {
2556 RuntimeException e = new RuntimeException("here");
2557 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002558 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002559 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 mPolicy.removeWindowLw(win);
2562 win.removeLocked();
2563
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002564 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 mWindowMap.remove(win.mClient.asBinder());
2566 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002567 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002568 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002569 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570
2571 if (mInputMethodWindow == win) {
2572 mInputMethodWindow = null;
2573 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2574 mInputMethodDialogs.remove(win);
2575 }
Romain Guy06882f82009-06-10 13:36:04 -07002576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 final WindowToken token = win.mToken;
2578 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002579 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 token.windows.remove(win);
2581 if (atoken != null) {
2582 atoken.allAppWindows.remove(win);
2583 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002584 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 TAG, "**** Removing window " + win + ": count="
2586 + token.windows.size());
2587 if (token.windows.size() == 0) {
2588 if (!token.explicit) {
2589 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 } else if (atoken != null) {
2591 atoken.firstWindowDrawn = false;
2592 }
2593 }
2594
2595 if (atoken != null) {
2596 if (atoken.startingWindow == win) {
2597 atoken.startingWindow = null;
2598 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2599 // If this is the last window and we had requested a starting
2600 // transition window, well there is no point now.
2601 atoken.startingData = null;
2602 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2603 // If this is the last window except for a starting transition
2604 // window, we need to get rid of the starting transition.
2605 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002606 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 + ": no more real windows");
2608 }
2609 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2610 mH.sendMessage(m);
2611 }
2612 }
Romain Guy06882f82009-06-10 13:36:04 -07002613
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002614 if (win.mAttrs.type == TYPE_WALLPAPER) {
2615 mLastWallpaperTimeoutTime = 0;
2616 adjustWallpaperWindowsLocked();
2617 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002618 adjustWallpaperWindowsLocked();
2619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 if (!mInLayout) {
2622 assignLayersLocked();
2623 mLayoutNeeded = true;
2624 performLayoutAndPlaceSurfacesLocked();
2625 if (win.mAppToken != null) {
2626 win.mAppToken.updateReportedVisibilityLocked();
2627 }
2628 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002629
2630 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002631 }
2632
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002633 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2634 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2635 + ": " + msg + " / " + w.mAttrs.getTitle();
2636 if (where != null) {
2637 Slog.i(TAG, str, where);
2638 } else {
2639 Slog.i(TAG, str);
2640 }
2641 }
2642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2644 long origId = Binder.clearCallingIdentity();
2645 try {
2646 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002647 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002649 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2650 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 Surface.openTransaction();
2652 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002653 if (SHOW_TRANSACTIONS) logSurface(w,
2654 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 w.mSurface.setTransparentRegionHint(region);
2656 } finally {
2657 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002658 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2659 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 }
2661 }
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(origId);
2665 }
2666 }
2667
2668 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002669 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 Rect visibleInsets) {
2671 long origId = Binder.clearCallingIdentity();
2672 try {
2673 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002674 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675 if (w != null) {
2676 w.mGivenInsetsPending = false;
2677 w.mGivenContentInsets.set(contentInsets);
2678 w.mGivenVisibleInsets.set(visibleInsets);
2679 w.mTouchableInsets = touchableInsets;
2680 mLayoutNeeded = true;
2681 performLayoutAndPlaceSurfacesLocked();
2682 }
2683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(origId);
2686 }
2687 }
Romain Guy06882f82009-06-10 13:36:04 -07002688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 public void getWindowDisplayFrame(Session session, IWindow client,
2690 Rect outDisplayFrame) {
2691 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002692 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 if (win == null) {
2694 outDisplayFrame.setEmpty();
2695 return;
2696 }
2697 outDisplayFrame.set(win.mDisplayFrame);
2698 }
2699 }
2700
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002701 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2702 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002703 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2704 window.mWallpaperX = x;
2705 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002706 window.mWallpaperXStep = xStep;
2707 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002708 if (updateWallpaperOffsetLocked(window, true)) {
2709 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002710 }
2711 }
2712 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002713
Dianne Hackborn75804932009-10-20 20:15:20 -07002714 void wallpaperCommandComplete(IBinder window, Bundle result) {
2715 synchronized (mWindowMap) {
2716 if (mWaitingOnWallpaper != null &&
2717 mWaitingOnWallpaper.mClient.asBinder() == window) {
2718 mWaitingOnWallpaper = null;
2719 mWindowMap.notifyAll();
2720 }
2721 }
2722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002723
Dianne Hackborn75804932009-10-20 20:15:20 -07002724 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2725 String action, int x, int y, int z, Bundle extras, boolean sync) {
2726 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2727 || window == mUpperWallpaperTarget) {
2728 boolean doWait = sync;
2729 int curTokenIndex = mWallpaperTokens.size();
2730 while (curTokenIndex > 0) {
2731 curTokenIndex--;
2732 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2733 int curWallpaperIndex = token.windows.size();
2734 while (curWallpaperIndex > 0) {
2735 curWallpaperIndex--;
2736 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2737 try {
2738 wallpaper.mClient.dispatchWallpaperCommand(action,
2739 x, y, z, extras, sync);
2740 // We only want to be synchronous with one wallpaper.
2741 sync = false;
2742 } catch (RemoteException e) {
2743 }
2744 }
2745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002746
Dianne Hackborn75804932009-10-20 20:15:20 -07002747 if (doWait) {
2748 // XXX Need to wait for result.
2749 }
2750 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002751
Dianne Hackborn75804932009-10-20 20:15:20 -07002752 return null;
2753 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 public int relayoutWindow(Session session, IWindow client,
2756 WindowManager.LayoutParams attrs, int requestedWidth,
2757 int requestedHeight, int viewVisibility, boolean insetsPending,
2758 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002759 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002760 boolean displayed = false;
2761 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002762 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002766 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002767 if (win == null) {
2768 return 0;
2769 }
2770 win.mRequestedWidth = requestedWidth;
2771 win.mRequestedHeight = requestedHeight;
2772
2773 if (attrs != null) {
2774 mPolicy.adjustWindowParamsLw(attrs);
2775 }
Romain Guy06882f82009-06-10 13:36:04 -07002776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 int attrChanges = 0;
2778 int flagChanges = 0;
2779 if (attrs != null) {
2780 flagChanges = win.mAttrs.flags ^= attrs.flags;
2781 attrChanges = win.mAttrs.copyFrom(attrs);
2782 }
2783
Joe Onorato8a9b2202010-02-26 18:56:32 -08002784 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785
2786 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2787 win.mAlpha = attrs.alpha;
2788 }
2789
2790 final boolean scaledWindow =
2791 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2792
2793 if (scaledWindow) {
2794 // requested{Width|Height} Surface's physical size
2795 // attrs.{width|height} Size on screen
2796 win.mHScale = (attrs.width != requestedWidth) ?
2797 (attrs.width / (float)requestedWidth) : 1.0f;
2798 win.mVScale = (attrs.height != requestedHeight) ?
2799 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002800 } else {
2801 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 }
2803
2804 boolean imMayMove = (flagChanges&(
2805 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2806 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 boolean focusMayChange = win.mViewVisibility != viewVisibility
2809 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2810 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002811
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002812 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2813 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 win.mRelayoutCalled = true;
2816 final int oldVisibility = win.mViewVisibility;
2817 win.mViewVisibility = viewVisibility;
2818 if (viewVisibility == View.VISIBLE &&
2819 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2820 displayed = !win.isVisibleLw();
2821 if (win.mExiting) {
2822 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002823 if (win.mAnimation != null) {
2824 win.mAnimation.cancel();
2825 win.mAnimation = null;
2826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 }
2828 if (win.mDestroying) {
2829 win.mDestroying = false;
2830 mDestroySurface.remove(win);
2831 }
2832 if (oldVisibility == View.GONE) {
2833 win.mEnterAnimationPending = true;
2834 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002835 if (displayed) {
2836 if (win.mSurface != null && !win.mDrawPending
2837 && !win.mCommitDrawPending && !mDisplayFrozen
2838 && mPolicy.isScreenOn()) {
2839 applyEnterAnimationLocked(win);
2840 }
2841 if ((win.mAttrs.flags
2842 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2843 if (DEBUG_VISIBILITY) Slog.v(TAG,
2844 "Relayout window turning screen on: " + win);
2845 win.mTurnOnScreen = true;
2846 }
2847 int diff = 0;
2848 if (win.mConfiguration != mCurConfiguration
2849 && (win.mConfiguration == null
2850 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2851 win.mConfiguration = mCurConfiguration;
2852 if (DEBUG_CONFIGURATION) {
2853 Slog.i(TAG, "Window " + win + " visible with new config: "
2854 + win.mConfiguration + " / 0x"
2855 + Integer.toHexString(diff));
2856 }
2857 outConfig.setTo(mCurConfiguration);
2858 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2861 // To change the format, we need to re-build the surface.
2862 win.destroySurfaceLocked();
2863 displayed = true;
2864 }
2865 try {
2866 Surface surface = win.createSurfaceLocked();
2867 if (surface != null) {
2868 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002869 win.mReportDestroySurface = false;
2870 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002871 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002872 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002874 // For some reason there isn't a surface. Clear the
2875 // caller's object so they see the same state.
2876 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 }
2878 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002879 mInputMonitor.updateInputWindowsLw();
2880
Joe Onorato8a9b2202010-02-26 18:56:32 -08002881 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002882 + client + " (" + win.mAttrs.getTitle() + ")",
2883 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 Binder.restoreCallingIdentity(origId);
2885 return 0;
2886 }
2887 if (displayed) {
2888 focusMayChange = true;
2889 }
2890 if (win.mAttrs.type == TYPE_INPUT_METHOD
2891 && mInputMethodWindow == null) {
2892 mInputMethodWindow = win;
2893 imMayMove = true;
2894 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002895 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2896 && win.mAppToken != null
2897 && win.mAppToken.startingWindow != null) {
2898 // Special handling of starting window over the base
2899 // window of the app: propagate lock screen flags to it,
2900 // to provide the correct semantics while starting.
2901 final int mask =
2902 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002903 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2904 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002905 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2906 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 } else {
2909 win.mEnterAnimationPending = false;
2910 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002911 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002912 + ": mExiting=" + win.mExiting
2913 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 // If we are not currently running the exit animation, we
2915 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002916 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 // Try starting an animation; if there isn't one, we
2918 // can destroy the surface right away.
2919 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2920 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2921 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2922 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002923 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002925 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 } else if (win.isAnimating()) {
2928 // Currently in a hide animation... turn this into
2929 // an exit.
2930 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002931 } else if (win == mWallpaperTarget) {
2932 // If the wallpaper is currently behind this
2933 // window, we need to change both of them inside
2934 // of a transaction to avoid artifacts.
2935 win.mExiting = true;
2936 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 } else {
2938 if (mInputMethodWindow == win) {
2939 mInputMethodWindow = null;
2940 }
2941 win.destroySurfaceLocked();
2942 }
2943 }
2944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002945
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002946 if (win.mSurface == null || (win.getAttrs().flags
2947 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2948 || win.mSurfacePendingDestroy) {
2949 // We are being called from a local process, which
2950 // means outSurface holds its current surface. Ensure the
2951 // surface object is cleared, but we don't want it actually
2952 // destroyed at this point.
2953 win.mSurfacePendingDestroy = false;
2954 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002955 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002956 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002957 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002958 "Keeping surface, will report destroy: " + win);
2959 win.mReportDestroySurface = true;
2960 outSurface.copyFrom(win.mSurface);
2961 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 }
2963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 if (focusMayChange) {
2965 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2966 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 imMayMove = false;
2968 }
2969 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2970 }
Romain Guy06882f82009-06-10 13:36:04 -07002971
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002972 // updateFocusedWindowLocked() already assigned layers so we only need to
2973 // reassign them at this point if the IM window state gets shuffled
2974 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002977 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2978 // Little hack here -- we -should- be able to rely on the
2979 // function to return true if the IME has moved and needs
2980 // its layer recomputed. However, if the IME was hidden
2981 // and isn't actually moved in the list, its layer may be
2982 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 assignLayers = true;
2984 }
2985 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002986 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002987 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002988 assignLayers = true;
2989 }
2990 }
Romain Guy06882f82009-06-10 13:36:04 -07002991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 mLayoutNeeded = true;
2993 win.mGivenInsetsPending = insetsPending;
2994 if (assignLayers) {
2995 assignLayersLocked();
2996 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002997 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002999 if (displayed && win.mIsWallpaper) {
3000 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07003001 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07003002 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003 if (win.mAppToken != null) {
3004 win.mAppToken.updateReportedVisibilityLocked();
3005 }
3006 outFrame.set(win.mFrame);
3007 outContentInsets.set(win.mContentInsets);
3008 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003009 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07003011 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 + ", requestedHeight=" + requestedHeight
3013 + ", viewVisibility=" + viewVisibility
3014 + "\nRelayout returning frame=" + outFrame
3015 + ", surface=" + outSurface);
3016
Joe Onorato8a9b2202010-02-26 18:56:32 -08003017 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3019
3020 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003021
3022 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 }
3024
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003025 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 sendNewConfiguration();
3027 }
Romain Guy06882f82009-06-10 13:36:04 -07003028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003029 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003031 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3032 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3033 }
3034
3035 public void finishDrawingWindow(Session session, IWindow client) {
3036 final long origId = Binder.clearCallingIdentity();
3037 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003038 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003040 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3041 adjustWallpaperWindowsLocked();
3042 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 mLayoutNeeded = true;
3044 performLayoutAndPlaceSurfacesLocked();
3045 }
3046 }
3047 Binder.restoreCallingIdentity(origId);
3048 }
3049
3050 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003051 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003052 + (lp != null ? lp.packageName : null)
3053 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3054 if (lp != null && lp.windowAnimations != 0) {
3055 // If this is a system resource, don't try to load it from the
3056 // application resources. It is nice to avoid loading application
3057 // resources if we can.
3058 String packageName = lp.packageName != null ? lp.packageName : "android";
3059 int resId = lp.windowAnimations;
3060 if ((resId&0xFF000000) == 0x01000000) {
3061 packageName = "android";
3062 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003063 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 + packageName);
3065 return AttributeCache.instance().get(packageName, resId,
3066 com.android.internal.R.styleable.WindowAnimation);
3067 }
3068 return null;
3069 }
Romain Guy06882f82009-06-10 13:36:04 -07003070
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003071 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003072 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003073 + packageName + " resId=0x" + Integer.toHexString(resId));
3074 if (packageName != null) {
3075 if ((resId&0xFF000000) == 0x01000000) {
3076 packageName = "android";
3077 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003078 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003079 + packageName);
3080 return AttributeCache.instance().get(packageName, resId,
3081 com.android.internal.R.styleable.WindowAnimation);
3082 }
3083 return null;
3084 }
3085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003086 private void applyEnterAnimationLocked(WindowState win) {
3087 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3088 if (win.mEnterAnimationPending) {
3089 win.mEnterAnimationPending = false;
3090 transit = WindowManagerPolicy.TRANSIT_ENTER;
3091 }
3092
3093 applyAnimationLocked(win, transit, true);
3094 }
3095
3096 private boolean applyAnimationLocked(WindowState win,
3097 int transit, boolean isEntrance) {
3098 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3099 // If we are trying to apply an animation, but already running
3100 // an animation of the same type, then just leave that one alone.
3101 return true;
3102 }
Romain Guy06882f82009-06-10 13:36:04 -07003103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 // Only apply an animation if the display isn't frozen. If it is
3105 // frozen, there is no reason to animate and it can cause strange
3106 // artifacts when we unfreeze the display if some different animation
3107 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003108 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 int anim = mPolicy.selectAnimationLw(win, transit);
3110 int attr = -1;
3111 Animation a = null;
3112 if (anim != 0) {
3113 a = AnimationUtils.loadAnimation(mContext, anim);
3114 } else {
3115 switch (transit) {
3116 case WindowManagerPolicy.TRANSIT_ENTER:
3117 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3118 break;
3119 case WindowManagerPolicy.TRANSIT_EXIT:
3120 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3121 break;
3122 case WindowManagerPolicy.TRANSIT_SHOW:
3123 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3124 break;
3125 case WindowManagerPolicy.TRANSIT_HIDE:
3126 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3127 break;
3128 }
3129 if (attr >= 0) {
3130 a = loadAnimation(win.mAttrs, attr);
3131 }
3132 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003133 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3135 + " mAnimation=" + win.mAnimation
3136 + " isEntrance=" + isEntrance);
3137 if (a != null) {
3138 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003139 RuntimeException e = null;
3140 if (!HIDE_STACK_CRAWLS) {
3141 e = new RuntimeException();
3142 e.fillInStackTrace();
3143 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003144 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 }
3146 win.setAnimation(a);
3147 win.mAnimationIsEntrance = isEntrance;
3148 }
3149 } else {
3150 win.clearAnimation();
3151 }
3152
3153 return win.mAnimation != null;
3154 }
3155
3156 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3157 int anim = 0;
3158 Context context = mContext;
3159 if (animAttr >= 0) {
3160 AttributeCache.Entry ent = getCachedAnimations(lp);
3161 if (ent != null) {
3162 context = ent.context;
3163 anim = ent.array.getResourceId(animAttr, 0);
3164 }
3165 }
3166 if (anim != 0) {
3167 return AnimationUtils.loadAnimation(context, anim);
3168 }
3169 return null;
3170 }
Romain Guy06882f82009-06-10 13:36:04 -07003171
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003172 private Animation loadAnimation(String packageName, int resId) {
3173 int anim = 0;
3174 Context context = mContext;
3175 if (resId >= 0) {
3176 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3177 if (ent != null) {
3178 context = ent.context;
3179 anim = resId;
3180 }
3181 }
3182 if (anim != 0) {
3183 return AnimationUtils.loadAnimation(context, anim);
3184 }
3185 return null;
3186 }
3187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 private boolean applyAnimationLocked(AppWindowToken wtoken,
3189 WindowManager.LayoutParams lp, int transit, boolean enter) {
3190 // Only apply an animation if the display isn't frozen. If it is
3191 // frozen, there is no reason to animate and it can cause strange
3192 // artifacts when we unfreeze the display if some different animation
3193 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003194 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003195 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003196 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003197 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003198 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003199 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003200 } else if (mNextAppTransitionPackage != null) {
3201 a = loadAnimation(mNextAppTransitionPackage, enter ?
3202 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003203 } else {
3204 int animAttr = 0;
3205 switch (transit) {
3206 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3207 animAttr = enter
3208 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3209 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3210 break;
3211 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3212 animAttr = enter
3213 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3214 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3215 break;
3216 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3217 animAttr = enter
3218 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3219 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3220 break;
3221 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3222 animAttr = enter
3223 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3224 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3225 break;
3226 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3227 animAttr = enter
3228 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3229 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3230 break;
3231 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3232 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003233 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003234 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3235 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003236 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003237 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003238 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3239 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003240 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003241 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003242 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003243 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3244 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3245 break;
3246 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3247 animAttr = enter
3248 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3249 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3250 break;
3251 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3252 animAttr = enter
3253 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3254 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003255 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003256 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003257 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003258 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003259 + " anim=" + a
3260 + " animAttr=0x" + Integer.toHexString(animAttr)
3261 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 if (a != null) {
3264 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003265 RuntimeException e = null;
3266 if (!HIDE_STACK_CRAWLS) {
3267 e = new RuntimeException();
3268 e.fillInStackTrace();
3269 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003270 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003271 }
3272 wtoken.setAnimation(a);
3273 }
3274 } else {
3275 wtoken.clearAnimation();
3276 }
3277
3278 return wtoken.animation != null;
3279 }
3280
3281 // -------------------------------------------------------------
3282 // Application Window Tokens
3283 // -------------------------------------------------------------
3284
3285 public void validateAppTokens(List tokens) {
3286 int v = tokens.size()-1;
3287 int m = mAppTokens.size()-1;
3288 while (v >= 0 && m >= 0) {
3289 AppWindowToken wtoken = mAppTokens.get(m);
3290 if (wtoken.removed) {
3291 m--;
3292 continue;
3293 }
3294 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003295 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3297 }
3298 v--;
3299 m--;
3300 }
3301 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003302 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 v--;
3304 }
3305 while (m >= 0) {
3306 AppWindowToken wtoken = mAppTokens.get(m);
3307 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003308 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 }
3310 m--;
3311 }
3312 }
3313
3314 boolean checkCallingPermission(String permission, String func) {
3315 // Quick check: if the calling permission is me, it's all okay.
3316 if (Binder.getCallingPid() == Process.myPid()) {
3317 return true;
3318 }
Romain Guy06882f82009-06-10 13:36:04 -07003319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 if (mContext.checkCallingPermission(permission)
3321 == PackageManager.PERMISSION_GRANTED) {
3322 return true;
3323 }
3324 String msg = "Permission Denial: " + func + " from pid="
3325 + Binder.getCallingPid()
3326 + ", uid=" + Binder.getCallingUid()
3327 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003328 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 return false;
3330 }
Romain Guy06882f82009-06-10 13:36:04 -07003331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 AppWindowToken findAppWindowToken(IBinder token) {
3333 WindowToken wtoken = mTokenMap.get(token);
3334 if (wtoken == null) {
3335 return null;
3336 }
3337 return wtoken.appWindowToken;
3338 }
Romain Guy06882f82009-06-10 13:36:04 -07003339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 public void addWindowToken(IBinder token, int type) {
3341 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3342 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003343 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 }
Romain Guy06882f82009-06-10 13:36:04 -07003345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 synchronized(mWindowMap) {
3347 WindowToken wtoken = mTokenMap.get(token);
3348 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003349 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 return;
3351 }
3352 wtoken = new WindowToken(token, type, true);
3353 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003354 if (type == TYPE_WALLPAPER) {
3355 mWallpaperTokens.add(wtoken);
3356 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 }
3358 }
Romain Guy06882f82009-06-10 13:36:04 -07003359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 public void removeWindowToken(IBinder token) {
3361 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3362 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003363 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 }
3365
3366 final long origId = Binder.clearCallingIdentity();
3367 synchronized(mWindowMap) {
3368 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 if (wtoken != null) {
3370 boolean delayed = false;
3371 if (!wtoken.hidden) {
3372 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 final int N = wtoken.windows.size();
3375 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 for (int i=0; i<N; i++) {
3378 WindowState win = wtoken.windows.get(i);
3379
3380 if (win.isAnimating()) {
3381 delayed = true;
3382 }
Romain Guy06882f82009-06-10 13:36:04 -07003383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 if (win.isVisibleNow()) {
3385 applyAnimationLocked(win,
3386 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 changed = true;
3388 }
3389 }
3390
3391 if (changed) {
3392 mLayoutNeeded = true;
3393 performLayoutAndPlaceSurfacesLocked();
3394 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3395 }
Romain Guy06882f82009-06-10 13:36:04 -07003396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 if (delayed) {
3398 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003399 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3400 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003401 }
3402 }
Romain Guy06882f82009-06-10 13:36:04 -07003403
Jeff Brownc5ed5912010-07-14 18:48:53 -07003404 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003406 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 }
3408 }
3409 Binder.restoreCallingIdentity(origId);
3410 }
3411
3412 public void addAppToken(int addPos, IApplicationToken token,
3413 int groupId, int requestedOrientation, boolean fullscreen) {
3414 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3415 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003416 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417 }
Jeff Brown349703e2010-06-22 01:27:15 -07003418
3419 // Get the dispatching timeout here while we are not holding any locks so that it
3420 // can be cached by the AppWindowToken. The timeout value is used later by the
3421 // input dispatcher in code that does hold locks. If we did not cache the value
3422 // here we would run the chance of introducing a deadlock between the window manager
3423 // (which holds locks while updating the input dispatcher state) and the activity manager
3424 // (which holds locks while querying the application token).
3425 long inputDispatchingTimeoutNanos;
3426 try {
3427 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3428 } catch (RemoteException ex) {
3429 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3430 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3431 }
Romain Guy06882f82009-06-10 13:36:04 -07003432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433 synchronized(mWindowMap) {
3434 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3435 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003436 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 return;
3438 }
3439 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003440 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 wtoken.groupId = groupId;
3442 wtoken.appFullscreen = fullscreen;
3443 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003444 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003445 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 // Application tokens start out hidden.
3449 wtoken.hidden = true;
3450 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003452 //dump();
3453 }
3454 }
Romain Guy06882f82009-06-10 13:36:04 -07003455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 public void setAppGroupId(IBinder token, int groupId) {
3457 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3458 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003459 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 }
3461
3462 synchronized(mWindowMap) {
3463 AppWindowToken wtoken = findAppWindowToken(token);
3464 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003465 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 return;
3467 }
3468 wtoken.groupId = groupId;
3469 }
3470 }
Romain Guy06882f82009-06-10 13:36:04 -07003471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 public int getOrientationFromWindowsLocked() {
3473 int pos = mWindows.size() - 1;
3474 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003475 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 pos--;
3477 if (wtoken.mAppToken != null) {
3478 // We hit an application window. so the orientation will be determined by the
3479 // app window. No point in continuing further.
3480 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3481 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003482 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 continue;
3484 }
3485 int req = wtoken.mAttrs.screenOrientation;
3486 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3487 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3488 continue;
3489 } else {
3490 return req;
3491 }
3492 }
3493 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3494 }
Romain Guy06882f82009-06-10 13:36:04 -07003495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003497 int pos = mAppTokens.size() - 1;
3498 int curGroup = 0;
3499 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3500 boolean findingBehind = false;
3501 boolean haveGroup = false;
3502 boolean lastFullscreen = false;
3503 while (pos >= 0) {
3504 AppWindowToken wtoken = mAppTokens.get(pos);
3505 pos--;
3506 // if we're about to tear down this window and not seek for
3507 // the behind activity, don't use it for orientation
3508 if (!findingBehind
3509 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3510 continue;
3511 }
3512
3513 if (!haveGroup) {
3514 // We ignore any hidden applications on the top.
3515 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003516 continue;
3517 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003518 haveGroup = true;
3519 curGroup = wtoken.groupId;
3520 lastOrientation = wtoken.requestedOrientation;
3521 } else if (curGroup != wtoken.groupId) {
3522 // If we have hit a new application group, and the bottom
3523 // of the previous group didn't explicitly say to use
3524 // the orientation behind it, and the last app was
3525 // full screen, then we'll stick with the
3526 // user's orientation.
3527 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3528 && lastFullscreen) {
3529 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003532 int or = wtoken.requestedOrientation;
3533 // If this application is fullscreen, and didn't explicitly say
3534 // to use the orientation behind it, then just take whatever
3535 // orientation it has and ignores whatever is under it.
3536 lastFullscreen = wtoken.appFullscreen;
3537 if (lastFullscreen
3538 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3539 return or;
3540 }
3541 // If this application has requested an explicit orientation,
3542 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003543 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3544 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003545 return or;
3546 }
3547 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3548 }
3549 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 }
Romain Guy06882f82009-06-10 13:36:04 -07003551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003553 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003554 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3555 "updateOrientationFromAppTokens()")) {
3556 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003558
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003559 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003561
3562 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003563 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003564 if (freezeThisOneIfNeeded != null) {
3565 AppWindowToken wtoken = findAppWindowToken(
3566 freezeThisOneIfNeeded);
3567 if (wtoken != null) {
3568 startAppFreezingScreenLocked(wtoken,
3569 ActivityInfo.CONFIG_ORIENTATION);
3570 }
3571 }
3572 config = computeNewConfigurationLocked();
3573
3574 } else if (currentConfig != null) {
3575 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003576 // state mismatches the activity manager's, update it,
3577 // disregarding font scale, which should remain set to
3578 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003579 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003580 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003581 if (computeNewConfigurationLocked(mTempConfiguration)) {
3582 if (currentConfig.diff(mTempConfiguration) != 0) {
3583 mWaitingForConfig = true;
3584 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003585 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003586 config = new Configuration(mTempConfiguration);
3587 }
3588 }
3589 }
3590 }
3591
Dianne Hackborncfaef692009-06-15 14:24:44 -07003592 Binder.restoreCallingIdentity(ident);
3593 return config;
3594 }
3595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003597 * Determine the new desired orientation of the display, returning
3598 * a non-null new Configuration if it has changed from the current
3599 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3600 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3601 * SCREEN. This will typically be done for you if you call
3602 * sendNewConfiguration().
3603 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 * The orientation is computed from non-application windows first. If none of
3605 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003606 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3608 * android.os.IBinder)
3609 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003610 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3611 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003612 // If the display is frozen, some activities may be in the middle
3613 // of restarting, and thus have removed their old window. If the
3614 // window has the flag to hide the lock screen, then the lock screen
3615 // can re-appear and inflict its own orientation on us. Keep the
3616 // orientation stable until this all settles down.
3617 return false;
3618 }
3619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 long ident = Binder.clearCallingIdentity();
3622 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003623 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 mForcedAppOrientation = req;
3627 //send a message to Policy indicating orientation change to take
3628 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003629 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003630 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003631 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3632 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003633 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 }
3635 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003636
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003637 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 } finally {
3639 Binder.restoreCallingIdentity(ident);
3640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 }
Romain Guy06882f82009-06-10 13:36:04 -07003642
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003643 int computeForcedAppOrientationLocked() {
3644 int req = getOrientationFromWindowsLocked();
3645 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3646 req = getOrientationFromAppTokensLocked();
3647 }
3648 return req;
3649 }
Romain Guy06882f82009-06-10 13:36:04 -07003650
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003651 public void setNewConfiguration(Configuration config) {
3652 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3653 "setNewConfiguration()")) {
3654 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3655 }
3656
3657 synchronized(mWindowMap) {
3658 mCurConfiguration = new Configuration(config);
3659 mWaitingForConfig = false;
3660 performLayoutAndPlaceSurfacesLocked();
3661 }
3662 }
3663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3665 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3666 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003667 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 }
Romain Guy06882f82009-06-10 13:36:04 -07003669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 synchronized(mWindowMap) {
3671 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3672 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003673 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 return;
3675 }
Romain Guy06882f82009-06-10 13:36:04 -07003676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 wtoken.requestedOrientation = requestedOrientation;
3678 }
3679 }
Romain Guy06882f82009-06-10 13:36:04 -07003680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 public int getAppOrientation(IApplicationToken token) {
3682 synchronized(mWindowMap) {
3683 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3684 if (wtoken == null) {
3685 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3686 }
Romain Guy06882f82009-06-10 13:36:04 -07003687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 return wtoken.requestedOrientation;
3689 }
3690 }
Romain Guy06882f82009-06-10 13:36:04 -07003691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3693 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3694 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003695 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 }
3697
3698 synchronized(mWindowMap) {
3699 boolean changed = false;
3700 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003701 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 changed = mFocusedApp != null;
3703 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003704 if (changed) {
3705 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003706 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 } else {
3708 AppWindowToken newFocus = findAppWindowToken(token);
3709 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003710 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 return;
3712 }
3713 changed = mFocusedApp != newFocus;
3714 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003715 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003716 if (changed) {
3717 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003718 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 }
3720
3721 if (moveFocusNow && changed) {
3722 final long origId = Binder.clearCallingIdentity();
3723 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3724 Binder.restoreCallingIdentity(origId);
3725 }
3726 }
3727 }
3728
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003729 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3731 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003732 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 }
Romain Guy06882f82009-06-10 13:36:04 -07003734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003736 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 TAG, "Prepare app transition: transit=" + transit
3738 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003739 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003740 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3741 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003743 } else if (!alwaysKeepCurrent) {
3744 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3745 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3746 // Opening a new task always supersedes a close for the anim.
3747 mNextAppTransition = transit;
3748 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3749 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3750 // Opening a new activity always supersedes a close for the anim.
3751 mNextAppTransition = transit;
3752 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 }
3754 mAppTransitionReady = false;
3755 mAppTransitionTimeout = false;
3756 mStartingIconInTransition = false;
3757 mSkipAppTransitionAnimation = false;
3758 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3759 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3760 5000);
3761 }
3762 }
3763 }
3764
3765 public int getPendingAppTransition() {
3766 return mNextAppTransition;
3767 }
Romain Guy06882f82009-06-10 13:36:04 -07003768
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003769 public void overridePendingAppTransition(String packageName,
3770 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003771 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003772 mNextAppTransitionPackage = packageName;
3773 mNextAppTransitionEnter = enterAnim;
3774 mNextAppTransitionExit = exitAnim;
3775 }
3776 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 public void executeAppTransition() {
3779 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3780 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003781 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 }
Romain Guy06882f82009-06-10 13:36:04 -07003783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003785 if (DEBUG_APP_TRANSITIONS) {
3786 RuntimeException e = new RuntimeException("here");
3787 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003788 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003789 + mNextAppTransition, e);
3790 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003791 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 mAppTransitionReady = true;
3793 final long origId = Binder.clearCallingIdentity();
3794 performLayoutAndPlaceSurfacesLocked();
3795 Binder.restoreCallingIdentity(origId);
3796 }
3797 }
3798 }
3799
3800 public void setAppStartingWindow(IBinder token, String pkg,
3801 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003802 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3804 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003805 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 }
3807
3808 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003809 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3811 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 AppWindowToken wtoken = findAppWindowToken(token);
3814 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003815 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 return;
3817 }
3818
3819 // If the display is frozen, we won't do anything until the
3820 // actual window is displayed so there is no reason to put in
3821 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003822 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 return;
3824 }
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 if (wtoken.startingData != null) {
3827 return;
3828 }
Romain Guy06882f82009-06-10 13:36:04 -07003829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 if (transferFrom != null) {
3831 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3832 if (ttoken != null) {
3833 WindowState startingWindow = ttoken.startingWindow;
3834 if (startingWindow != null) {
3835 if (mStartingIconInTransition) {
3836 // In this case, the starting icon has already
3837 // been displayed, so start letting windows get
3838 // shown immediately without any more transitions.
3839 mSkipAppTransitionAnimation = true;
3840 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003841 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 "Moving existing starting from " + ttoken
3843 + " to " + wtoken);
3844 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 // Transfer the starting window over to the new
3847 // token.
3848 wtoken.startingData = ttoken.startingData;
3849 wtoken.startingView = ttoken.startingView;
3850 wtoken.startingWindow = startingWindow;
3851 ttoken.startingData = null;
3852 ttoken.startingView = null;
3853 ttoken.startingWindow = null;
3854 ttoken.startingMoved = true;
3855 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003856 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003858 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003859 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003861 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003862 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3863 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 ttoken.windows.remove(startingWindow);
3865 ttoken.allAppWindows.remove(startingWindow);
3866 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 // Propagate other interesting state between the
3869 // tokens. If the old token is displayed, we should
3870 // immediately force the new one to be displayed. If
3871 // it is animating, we need to move that animation to
3872 // the new one.
3873 if (ttoken.allDrawn) {
3874 wtoken.allDrawn = true;
3875 }
3876 if (ttoken.firstWindowDrawn) {
3877 wtoken.firstWindowDrawn = true;
3878 }
3879 if (!ttoken.hidden) {
3880 wtoken.hidden = false;
3881 wtoken.hiddenRequested = false;
3882 wtoken.willBeHidden = false;
3883 }
3884 if (wtoken.clientHidden != ttoken.clientHidden) {
3885 wtoken.clientHidden = ttoken.clientHidden;
3886 wtoken.sendAppVisibilityToClients();
3887 }
3888 if (ttoken.animation != null) {
3889 wtoken.animation = ttoken.animation;
3890 wtoken.animating = ttoken.animating;
3891 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3892 ttoken.animation = null;
3893 ttoken.animLayerAdjustment = 0;
3894 wtoken.updateLayers();
3895 ttoken.updateLayers();
3896 }
Romain Guy06882f82009-06-10 13:36:04 -07003897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003898 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 mLayoutNeeded = true;
3900 performLayoutAndPlaceSurfacesLocked();
3901 Binder.restoreCallingIdentity(origId);
3902 return;
3903 } else if (ttoken.startingData != null) {
3904 // The previous app was getting ready to show a
3905 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 "Moving pending starting from " + ttoken
3908 + " to " + wtoken);
3909 wtoken.startingData = ttoken.startingData;
3910 ttoken.startingData = null;
3911 ttoken.startingMoved = true;
3912 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3913 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3914 // want to process the message ASAP, before any other queued
3915 // messages.
3916 mH.sendMessageAtFrontOfQueue(m);
3917 return;
3918 }
3919 }
3920 }
3921
3922 // There is no existing starting window, and the caller doesn't
3923 // want us to create one, so that's it!
3924 if (!createIfNeeded) {
3925 return;
3926 }
Romain Guy06882f82009-06-10 13:36:04 -07003927
Dianne Hackborn284ac932009-08-28 10:34:25 -07003928 // If this is a translucent or wallpaper window, then don't
3929 // show a starting window -- the current effect (a full-screen
3930 // opaque starting window that fades away to the real contents
3931 // when it is ready) does not work for this.
3932 if (theme != 0) {
3933 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3934 com.android.internal.R.styleable.Window);
3935 if (ent.array.getBoolean(
3936 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3937 return;
3938 }
3939 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003940 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3941 return;
3942 }
3943 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003944 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3945 return;
3946 }
3947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 mStartingIconInTransition = true;
3950 wtoken.startingData = new StartingData(
3951 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003952 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003953 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3954 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3955 // want to process the message ASAP, before any other queued
3956 // messages.
3957 mH.sendMessageAtFrontOfQueue(m);
3958 }
3959 }
3960
3961 public void setAppWillBeHidden(IBinder token) {
3962 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3963 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003964 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 }
3966
3967 AppWindowToken wtoken;
3968
3969 synchronized(mWindowMap) {
3970 wtoken = findAppWindowToken(token);
3971 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003972 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 -08003973 return;
3974 }
3975 wtoken.willBeHidden = true;
3976 }
3977 }
Romain Guy06882f82009-06-10 13:36:04 -07003978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003979 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3980 boolean visible, int transit, boolean performLayout) {
3981 boolean delayed = false;
3982
3983 if (wtoken.clientHidden == visible) {
3984 wtoken.clientHidden = !visible;
3985 wtoken.sendAppVisibilityToClients();
3986 }
Romain Guy06882f82009-06-10 13:36:04 -07003987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 wtoken.willBeHidden = false;
3989 if (wtoken.hidden == visible) {
3990 final int N = wtoken.allAppWindows.size();
3991 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003992 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3994 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003997
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003998 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 if (wtoken.animation == sDummyAnimation) {
4000 wtoken.animation = null;
4001 }
4002 applyAnimationLocked(wtoken, lp, transit, visible);
4003 changed = true;
4004 if (wtoken.animation != null) {
4005 delayed = runningAppAnimation = true;
4006 }
4007 }
Romain Guy06882f82009-06-10 13:36:04 -07004008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 for (int i=0; i<N; i++) {
4010 WindowState win = wtoken.allAppWindows.get(i);
4011 if (win == wtoken.startingWindow) {
4012 continue;
4013 }
4014
4015 if (win.isAnimating()) {
4016 delayed = true;
4017 }
Romain Guy06882f82009-06-10 13:36:04 -07004018
Joe Onorato8a9b2202010-02-26 18:56:32 -08004019 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 //win.dump(" ");
4021 if (visible) {
4022 if (!win.isVisibleNow()) {
4023 if (!runningAppAnimation) {
4024 applyAnimationLocked(win,
4025 WindowManagerPolicy.TRANSIT_ENTER, true);
4026 }
4027 changed = true;
4028 }
4029 } else if (win.isVisibleNow()) {
4030 if (!runningAppAnimation) {
4031 applyAnimationLocked(win,
4032 WindowManagerPolicy.TRANSIT_EXIT, false);
4033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 changed = true;
4035 }
4036 }
4037
4038 wtoken.hidden = wtoken.hiddenRequested = !visible;
4039 if (!visible) {
4040 unsetAppFreezingScreenLocked(wtoken, true, true);
4041 } else {
4042 // If we are being set visible, and the starting window is
4043 // not yet displayed, then make sure it doesn't get displayed.
4044 WindowState swin = wtoken.startingWindow;
4045 if (swin != null && (swin.mDrawPending
4046 || swin.mCommitDrawPending)) {
4047 swin.mPolicyVisibility = false;
4048 swin.mPolicyVisibilityAfterAnim = false;
4049 }
4050 }
Romain Guy06882f82009-06-10 13:36:04 -07004051
Joe Onorato8a9b2202010-02-26 18:56:32 -08004052 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004053 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4054 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004055
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004056 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004057 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004058 if (performLayout) {
4059 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
4060 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07004061 } else {
4062 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004063 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 }
4065 }
4066
4067 if (wtoken.animation != null) {
4068 delayed = true;
4069 }
Romain Guy06882f82009-06-10 13:36:04 -07004070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004071 return delayed;
4072 }
4073
4074 public void setAppVisibility(IBinder token, boolean visible) {
4075 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4076 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004077 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 }
4079
4080 AppWindowToken wtoken;
4081
4082 synchronized(mWindowMap) {
4083 wtoken = findAppWindowToken(token);
4084 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004085 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 return;
4087 }
4088
4089 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004090 RuntimeException e = null;
4091 if (!HIDE_STACK_CRAWLS) {
4092 e = new RuntimeException();
4093 e.fillInStackTrace();
4094 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004095 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 + "): mNextAppTransition=" + mNextAppTransition
4097 + " hidden=" + wtoken.hidden
4098 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4099 }
Romain Guy06882f82009-06-10 13:36:04 -07004100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 // If we are preparing an app transition, then delay changing
4102 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004103 if (!mDisplayFrozen && mPolicy.isScreenOn()
4104 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004105 // Already in requested state, don't do anything more.
4106 if (wtoken.hiddenRequested != visible) {
4107 return;
4108 }
4109 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004110
Joe Onorato8a9b2202010-02-26 18:56:32 -08004111 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 TAG, "Setting dummy animation on: " + wtoken);
4113 wtoken.setDummyAnimation();
4114 mOpeningApps.remove(wtoken);
4115 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004116 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 wtoken.inPendingTransaction = true;
4118 if (visible) {
4119 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004120 wtoken.startingDisplayed = false;
4121 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004122
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004123 // If the token is currently hidden (should be the
4124 // common case), then we need to set up to wait for
4125 // its windows to be ready.
4126 if (wtoken.hidden) {
4127 wtoken.allDrawn = false;
4128 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004129
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004130 if (wtoken.clientHidden) {
4131 // In the case where we are making an app visible
4132 // but holding off for a transition, we still need
4133 // to tell the client to make its windows visible so
4134 // they get drawn. Otherwise, we will wait on
4135 // performing the transition until all windows have
4136 // been drawn, they never will be, and we are sad.
4137 wtoken.clientHidden = false;
4138 wtoken.sendAppVisibilityToClients();
4139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 }
4141 } else {
4142 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004143
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004144 // If the token is currently visible (should be the
4145 // common case), then set up to wait for it to be hidden.
4146 if (!wtoken.hidden) {
4147 wtoken.waitingToHide = true;
4148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 }
4150 return;
4151 }
Romain Guy06882f82009-06-10 13:36:04 -07004152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004154 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004155 wtoken.updateReportedVisibilityLocked();
4156 Binder.restoreCallingIdentity(origId);
4157 }
4158 }
4159
4160 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4161 boolean unfreezeSurfaceNow, boolean force) {
4162 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004163 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 + " force=" + force);
4165 final int N = wtoken.allAppWindows.size();
4166 boolean unfrozeWindows = false;
4167 for (int i=0; i<N; i++) {
4168 WindowState w = wtoken.allAppWindows.get(i);
4169 if (w.mAppFreezing) {
4170 w.mAppFreezing = false;
4171 if (w.mSurface != null && !w.mOrientationChanging) {
4172 w.mOrientationChanging = true;
4173 }
4174 unfrozeWindows = true;
4175 }
4176 }
4177 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004178 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 wtoken.freezingScreen = false;
4180 mAppsFreezingScreen--;
4181 }
4182 if (unfreezeSurfaceNow) {
4183 if (unfrozeWindows) {
4184 mLayoutNeeded = true;
4185 performLayoutAndPlaceSurfacesLocked();
4186 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004187 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 }
4189 }
4190 }
Romain Guy06882f82009-06-10 13:36:04 -07004191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4193 int configChanges) {
4194 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004195 RuntimeException e = null;
4196 if (!HIDE_STACK_CRAWLS) {
4197 e = new RuntimeException();
4198 e.fillInStackTrace();
4199 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004200 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 + ": hidden=" + wtoken.hidden + " freezing="
4202 + wtoken.freezingScreen, e);
4203 }
4204 if (!wtoken.hiddenRequested) {
4205 if (!wtoken.freezingScreen) {
4206 wtoken.freezingScreen = true;
4207 mAppsFreezingScreen++;
4208 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004209 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4211 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4212 5000);
4213 }
4214 }
4215 final int N = wtoken.allAppWindows.size();
4216 for (int i=0; i<N; i++) {
4217 WindowState w = wtoken.allAppWindows.get(i);
4218 w.mAppFreezing = true;
4219 }
4220 }
4221 }
Romain Guy06882f82009-06-10 13:36:04 -07004222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 public void startAppFreezingScreen(IBinder token, int configChanges) {
4224 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4225 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004226 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004227 }
4228
4229 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004230 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004231 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004232 return;
4233 }
Romain Guy06882f82009-06-10 13:36:04 -07004234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004235 AppWindowToken wtoken = findAppWindowToken(token);
4236 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004237 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 return;
4239 }
4240 final long origId = Binder.clearCallingIdentity();
4241 startAppFreezingScreenLocked(wtoken, configChanges);
4242 Binder.restoreCallingIdentity(origId);
4243 }
4244 }
Romain Guy06882f82009-06-10 13:36:04 -07004245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 public void stopAppFreezingScreen(IBinder token, boolean force) {
4247 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4248 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004249 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 }
4251
4252 synchronized(mWindowMap) {
4253 AppWindowToken wtoken = findAppWindowToken(token);
4254 if (wtoken == null || wtoken.appToken == null) {
4255 return;
4256 }
4257 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004258 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004259 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4260 unsetAppFreezingScreenLocked(wtoken, true, force);
4261 Binder.restoreCallingIdentity(origId);
4262 }
4263 }
Romain Guy06882f82009-06-10 13:36:04 -07004264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 public void removeAppToken(IBinder token) {
4266 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4267 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004268 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 }
4270
4271 AppWindowToken wtoken = null;
4272 AppWindowToken startingToken = null;
4273 boolean delayed = false;
4274
4275 final long origId = Binder.clearCallingIdentity();
4276 synchronized(mWindowMap) {
4277 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004279 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004280 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 wtoken.inPendingTransaction = false;
4282 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004283 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 if (mClosingApps.contains(wtoken)) {
4285 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004286 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004288 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 delayed = true;
4290 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004291 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 TAG, "Removing app " + wtoken + " delayed=" + delayed
4293 + " animation=" + wtoken.animation
4294 + " animating=" + wtoken.animating);
4295 if (delayed) {
4296 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004297 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4298 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004300 } else {
4301 // Make sure there is no animation running on this token,
4302 // so any windows associated with it will be removed as
4303 // soon as their animations are complete
4304 wtoken.animation = null;
4305 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004307 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4308 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 mAppTokens.remove(wtoken);
4310 wtoken.removed = true;
4311 if (wtoken.startingData != null) {
4312 startingToken = wtoken;
4313 }
4314 unsetAppFreezingScreenLocked(wtoken, true, true);
4315 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004316 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 mFocusedApp = null;
4318 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004319 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 }
4321 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004322 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 }
Romain Guy06882f82009-06-10 13:36:04 -07004324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 if (!delayed && wtoken != null) {
4326 wtoken.updateReportedVisibilityLocked();
4327 }
4328 }
4329 Binder.restoreCallingIdentity(origId);
4330
4331 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004332 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 + startingToken + ": app token removed");
4334 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4335 mH.sendMessage(m);
4336 }
4337 }
4338
4339 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4340 final int NW = token.windows.size();
4341 for (int i=0; i<NW; i++) {
4342 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004343 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004345 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 int j = win.mChildWindows.size();
4347 while (j > 0) {
4348 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004349 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004350 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004351 "Tmp removing child window " + cwin);
4352 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004353 }
4354 }
4355 return NW > 0;
4356 }
4357
4358 void dumpAppTokensLocked() {
4359 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004360 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 }
4362 }
Romain Guy06882f82009-06-10 13:36:04 -07004363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 void dumpWindowsLocked() {
4365 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004366 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 }
4368 }
Romain Guy06882f82009-06-10 13:36:04 -07004369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 private int findWindowOffsetLocked(int tokenPos) {
4371 final int NW = mWindows.size();
4372
4373 if (tokenPos >= mAppTokens.size()) {
4374 int i = NW;
4375 while (i > 0) {
4376 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004377 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 if (win.getAppToken() != null) {
4379 return i+1;
4380 }
4381 }
4382 }
4383
4384 while (tokenPos > 0) {
4385 // Find the first app token below the new position that has
4386 // a window displayed.
4387 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004388 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004390 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004391 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004392 "Skipping token -- currently sending to bottom");
4393 tokenPos--;
4394 continue;
4395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 int i = wtoken.windows.size();
4397 while (i > 0) {
4398 i--;
4399 WindowState win = wtoken.windows.get(i);
4400 int j = win.mChildWindows.size();
4401 while (j > 0) {
4402 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004403 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004404 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004405 for (int pos=NW-1; pos>=0; pos--) {
4406 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004407 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 "Found child win @" + (pos+1));
4409 return pos+1;
4410 }
4411 }
4412 }
4413 }
4414 for (int pos=NW-1; pos>=0; pos--) {
4415 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004416 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 return pos+1;
4418 }
4419 }
4420 }
4421 tokenPos--;
4422 }
4423
4424 return 0;
4425 }
4426
4427 private final int reAddWindowLocked(int index, WindowState win) {
4428 final int NCW = win.mChildWindows.size();
4429 boolean added = false;
4430 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004431 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004433 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004434 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004435 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 mWindows.add(index, win);
4437 index++;
4438 added = true;
4439 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004440 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004441 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004442 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 mWindows.add(index, cwin);
4444 index++;
4445 }
4446 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004448 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004449 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004450 mWindows.add(index, win);
4451 index++;
4452 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004453 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 return index;
4455 }
Romain Guy06882f82009-06-10 13:36:04 -07004456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004457 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4458 final int NW = token.windows.size();
4459 for (int i=0; i<NW; i++) {
4460 index = reAddWindowLocked(index, token.windows.get(i));
4461 }
4462 return index;
4463 }
4464
4465 public void moveAppToken(int index, IBinder token) {
4466 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4467 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004468 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
4470
4471 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004472 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 if (DEBUG_REORDER) dumpAppTokensLocked();
4474 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004475 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4476 "Start moving token " + wtoken + " initially at "
4477 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004479 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 + token + " (" + wtoken + ")");
4481 return;
4482 }
4483 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004484 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004485 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004489 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 if (DEBUG_REORDER) dumpWindowsLocked();
4491 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004492 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004493 if (DEBUG_REORDER) dumpWindowsLocked();
4494 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004495 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004496 if (DEBUG_REORDER) dumpWindowsLocked();
4497 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 mLayoutNeeded = true;
4499 performLayoutAndPlaceSurfacesLocked();
4500 }
4501 Binder.restoreCallingIdentity(origId);
4502 }
4503 }
4504
4505 private void removeAppTokensLocked(List<IBinder> tokens) {
4506 // XXX This should be done more efficiently!
4507 // (take advantage of the fact that both lists should be
4508 // ordered in the same way.)
4509 int N = tokens.size();
4510 for (int i=0; i<N; i++) {
4511 IBinder token = tokens.get(i);
4512 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004513 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4514 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004516 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 + token + " (" + wtoken + ")");
4518 i--;
4519 N--;
4520 }
4521 }
4522 }
4523
Dianne Hackborna8f60182009-09-01 19:01:50 -07004524 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4525 boolean updateFocusAndLayout) {
4526 // First remove all of the windows from the list.
4527 tmpRemoveAppWindowsLocked(wtoken);
4528
4529 // Where to start adding?
4530 int pos = findWindowOffsetLocked(tokenPos);
4531
4532 // And now add them back at the correct place.
4533 pos = reAddAppWindowsLocked(pos, wtoken);
4534
4535 if (updateFocusAndLayout) {
4536 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4537 assignLayersLocked();
4538 }
4539 mLayoutNeeded = true;
4540 performLayoutAndPlaceSurfacesLocked();
4541 }
4542 }
4543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004544 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4545 // First remove all of the windows from the list.
4546 final int N = tokens.size();
4547 int i;
4548 for (i=0; i<N; i++) {
4549 WindowToken token = mTokenMap.get(tokens.get(i));
4550 if (token != null) {
4551 tmpRemoveAppWindowsLocked(token);
4552 }
4553 }
4554
4555 // Where to start adding?
4556 int pos = findWindowOffsetLocked(tokenPos);
4557
4558 // And now add them back at the correct place.
4559 for (i=0; i<N; i++) {
4560 WindowToken token = mTokenMap.get(tokens.get(i));
4561 if (token != null) {
4562 pos = reAddAppWindowsLocked(pos, token);
4563 }
4564 }
4565
Dianne Hackborna8f60182009-09-01 19:01:50 -07004566 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4567 assignLayersLocked();
4568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004569 mLayoutNeeded = true;
4570 performLayoutAndPlaceSurfacesLocked();
4571
4572 //dump();
4573 }
4574
4575 public void moveAppTokensToTop(List<IBinder> tokens) {
4576 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4577 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004578 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 }
4580
4581 final long origId = Binder.clearCallingIdentity();
4582 synchronized(mWindowMap) {
4583 removeAppTokensLocked(tokens);
4584 final int N = tokens.size();
4585 for (int i=0; i<N; i++) {
4586 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4587 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004588 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4589 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004590 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004591 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004592 mToTopApps.remove(wt);
4593 mToBottomApps.remove(wt);
4594 mToTopApps.add(wt);
4595 wt.sendingToBottom = false;
4596 wt.sendingToTop = true;
4597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 }
4599 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004600
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004601 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004602 moveAppWindowsLocked(tokens, mAppTokens.size());
4603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004604 }
4605 Binder.restoreCallingIdentity(origId);
4606 }
4607
4608 public void moveAppTokensToBottom(List<IBinder> tokens) {
4609 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4610 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004611 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 }
4613
4614 final long origId = Binder.clearCallingIdentity();
4615 synchronized(mWindowMap) {
4616 removeAppTokensLocked(tokens);
4617 final int N = tokens.size();
4618 int pos = 0;
4619 for (int i=0; i<N; i++) {
4620 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4621 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004622 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4623 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004624 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004625 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004626 mToTopApps.remove(wt);
4627 mToBottomApps.remove(wt);
4628 mToBottomApps.add(i, wt);
4629 wt.sendingToTop = false;
4630 wt.sendingToBottom = true;
4631 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632 pos++;
4633 }
4634 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004635
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004636 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004637 moveAppWindowsLocked(tokens, 0);
4638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 }
4640 Binder.restoreCallingIdentity(origId);
4641 }
4642
4643 // -------------------------------------------------------------
4644 // Misc IWindowSession methods
4645 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004646
Jim Miller284b62e2010-06-08 14:27:42 -07004647 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004648 {
Jim Miller284b62e2010-06-08 14:27:42 -07004649 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4650 // called before DevicePolicyManagerService has started.
4651 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4652 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4653 Context.DEVICE_POLICY_SERVICE);
4654 if (dpm != null) {
4655 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4656 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4657 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4658 }
Jim Millerd6b57052010-06-07 17:52:42 -07004659 }
Jim Miller284b62e2010-06-08 14:27:42 -07004660 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004661 }
4662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004663 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004664 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 != PackageManager.PERMISSION_GRANTED) {
4666 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4667 }
Jim Millerd6b57052010-06-07 17:52:42 -07004668
Jim Miller284b62e2010-06-08 14:27:42 -07004669 synchronized (mKeyguardTokenWatcher) {
4670 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004671 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 }
4673
4674 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004675 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004676 != PackageManager.PERMISSION_GRANTED) {
4677 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4678 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679
Jim Miller284b62e2010-06-08 14:27:42 -07004680 synchronized (mKeyguardTokenWatcher) {
4681 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004682
Jim Miller284b62e2010-06-08 14:27:42 -07004683 if (!mKeyguardTokenWatcher.isAcquired()) {
4684 // If we are the last one to reenable the keyguard wait until
4685 // we have actually finished reenabling until returning.
4686 // It is possible that reenableKeyguard() can be called before
4687 // the previous disableKeyguard() is handled, in which case
4688 // neither mKeyguardTokenWatcher.acquired() or released() would
4689 // be called. In that case mKeyguardDisabled will be false here
4690 // and we have nothing to wait for.
4691 while (mKeyguardDisabled) {
4692 try {
4693 mKeyguardTokenWatcher.wait();
4694 } catch (InterruptedException e) {
4695 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 }
4697 }
4698 }
4699 }
4700 }
4701
4702 /**
4703 * @see android.app.KeyguardManager#exitKeyguardSecurely
4704 */
4705 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004706 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 != PackageManager.PERMISSION_GRANTED) {
4708 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4709 }
4710 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4711 public void onKeyguardExitResult(boolean success) {
4712 try {
4713 callback.onKeyguardExitResult(success);
4714 } catch (RemoteException e) {
4715 // Client has died, we don't care.
4716 }
4717 }
4718 });
4719 }
4720
4721 public boolean inKeyguardRestrictedInputMode() {
4722 return mPolicy.inKeyguardRestrictedKeyInputMode();
4723 }
Romain Guy06882f82009-06-10 13:36:04 -07004724
Dianne Hackbornffa42482009-09-23 22:20:11 -07004725 public void closeSystemDialogs(String reason) {
4726 synchronized(mWindowMap) {
4727 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004728 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004729 if (w.mSurface != null) {
4730 try {
4731 w.mClient.closeSystemDialogs(reason);
4732 } catch (RemoteException e) {
4733 }
4734 }
4735 }
4736 }
4737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004739 static float fixScale(float scale) {
4740 if (scale < 0) scale = 0;
4741 else if (scale > 20) scale = 20;
4742 return Math.abs(scale);
4743 }
Romain Guy06882f82009-06-10 13:36:04 -07004744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004745 public void setAnimationScale(int which, float scale) {
4746 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4747 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004748 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004749 }
4750
4751 if (scale < 0) scale = 0;
4752 else if (scale > 20) scale = 20;
4753 scale = Math.abs(scale);
4754 switch (which) {
4755 case 0: mWindowAnimationScale = fixScale(scale); break;
4756 case 1: mTransitionAnimationScale = fixScale(scale); break;
4757 }
Romain Guy06882f82009-06-10 13:36:04 -07004758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004759 // Persist setting
4760 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4761 }
Romain Guy06882f82009-06-10 13:36:04 -07004762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004763 public void setAnimationScales(float[] scales) {
4764 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4765 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004766 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 }
4768
4769 if (scales != null) {
4770 if (scales.length >= 1) {
4771 mWindowAnimationScale = fixScale(scales[0]);
4772 }
4773 if (scales.length >= 2) {
4774 mTransitionAnimationScale = fixScale(scales[1]);
4775 }
4776 }
Romain Guy06882f82009-06-10 13:36:04 -07004777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 // Persist setting
4779 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4780 }
Romain Guy06882f82009-06-10 13:36:04 -07004781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004782 public float getAnimationScale(int which) {
4783 switch (which) {
4784 case 0: return mWindowAnimationScale;
4785 case 1: return mTransitionAnimationScale;
4786 }
4787 return 0;
4788 }
Romain Guy06882f82009-06-10 13:36:04 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 public float[] getAnimationScales() {
4791 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4792 }
Romain Guy06882f82009-06-10 13:36:04 -07004793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 public int getSwitchState(int sw) {
4795 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4796 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004797 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004799 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004800 }
Romain Guy06882f82009-06-10 13:36:04 -07004801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004802 public int getSwitchStateForDevice(int devid, int sw) {
4803 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4804 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004805 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004806 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004807 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 }
Romain Guy06882f82009-06-10 13:36:04 -07004809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 public int getScancodeState(int sw) {
4811 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4812 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004813 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004814 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004815 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004816 }
Romain Guy06882f82009-06-10 13:36:04 -07004817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 public int getScancodeStateForDevice(int devid, int sw) {
4819 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4820 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004821 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004823 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004824 }
Romain Guy06882f82009-06-10 13:36:04 -07004825
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004826 public int getTrackballScancodeState(int sw) {
4827 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4828 "getTrackballScancodeState()")) {
4829 throw new SecurityException("Requires READ_INPUT_STATE permission");
4830 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004831 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004832 }
4833
4834 public int getDPadScancodeState(int sw) {
4835 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4836 "getDPadScancodeState()")) {
4837 throw new SecurityException("Requires READ_INPUT_STATE permission");
4838 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004839 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004840 }
4841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 public int getKeycodeState(int sw) {
4843 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4844 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004845 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004846 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004847 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 }
Romain Guy06882f82009-06-10 13:36:04 -07004849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 public int getKeycodeStateForDevice(int devid, int sw) {
4851 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4852 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004853 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004854 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004855 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 }
Romain Guy06882f82009-06-10 13:36:04 -07004857
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004858 public int getTrackballKeycodeState(int sw) {
4859 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4860 "getTrackballKeycodeState()")) {
4861 throw new SecurityException("Requires READ_INPUT_STATE permission");
4862 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004863 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004864 }
4865
4866 public int getDPadKeycodeState(int sw) {
4867 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4868 "getDPadKeycodeState()")) {
4869 throw new SecurityException("Requires READ_INPUT_STATE permission");
4870 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004871 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004872 }
Jeff Browna41ca772010-08-11 14:46:32 -07004873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004874 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004875 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 }
Romain Guy06882f82009-06-10 13:36:04 -07004877
Jeff Browna41ca772010-08-11 14:46:32 -07004878 public InputChannel monitorInput(String inputChannelName) {
4879 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4880 "monitorInput()")) {
4881 throw new SecurityException("Requires READ_INPUT_STATE permission");
4882 }
4883 return mInputManager.monitorInput(inputChannelName);
4884 }
4885
Jeff Brown8d608662010-08-30 03:02:23 -07004886 public InputDevice getInputDevice(int deviceId) {
4887 return mInputManager.getInputDevice(deviceId);
4888 }
4889
4890 public int[] getInputDeviceIds() {
4891 return mInputManager.getInputDeviceIds();
4892 }
4893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004894 public void enableScreenAfterBoot() {
4895 synchronized(mWindowMap) {
4896 if (mSystemBooted) {
4897 return;
4898 }
4899 mSystemBooted = true;
4900 }
Romain Guy06882f82009-06-10 13:36:04 -07004901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 performEnableScreen();
4903 }
Romain Guy06882f82009-06-10 13:36:04 -07004904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004905 public void enableScreenIfNeededLocked() {
4906 if (mDisplayEnabled) {
4907 return;
4908 }
4909 if (!mSystemBooted) {
4910 return;
4911 }
4912 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4913 }
Romain Guy06882f82009-06-10 13:36:04 -07004914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 public void performEnableScreen() {
4916 synchronized(mWindowMap) {
4917 if (mDisplayEnabled) {
4918 return;
4919 }
4920 if (!mSystemBooted) {
4921 return;
4922 }
Romain Guy06882f82009-06-10 13:36:04 -07004923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004924 // Don't enable the screen until all existing windows
4925 // have been drawn.
4926 final int N = mWindows.size();
4927 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004928 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004929 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 return;
4931 }
4932 }
Romain Guy06882f82009-06-10 13:36:04 -07004933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004934 mDisplayEnabled = true;
4935 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004936 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 StringWriter sw = new StringWriter();
4938 PrintWriter pw = new PrintWriter(sw);
4939 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004940 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004941 }
4942 try {
4943 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4944 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004945 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004946 Parcel data = Parcel.obtain();
4947 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4948 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4949 data, null, 0);
4950 data.recycle();
4951 }
4952 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004953 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004954 }
4955 }
Romain Guy06882f82009-06-10 13:36:04 -07004956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004957 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004960 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4961 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 }
Romain Guy06882f82009-06-10 13:36:04 -07004963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 public void setInTouchMode(boolean mode) {
4965 synchronized(mWindowMap) {
4966 mInTouchMode = mode;
4967 }
4968 }
4969
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004970 // TODO: more accounting of which pid(s) turned it on, keep count,
4971 // only allow disables from pids which have count on, etc.
4972 public void showStrictModeViolation(boolean on) {
4973 int pid = Binder.getCallingPid();
4974 synchronized(mWindowMap) {
4975 // Ignoring requests to enable the red border from clients
4976 // which aren't on screen. (e.g. Broadcast Receivers in
4977 // the background..)
4978 if (on) {
4979 boolean isVisible = false;
4980 for (WindowState ws : mWindows) {
4981 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4982 isVisible = true;
4983 break;
4984 }
4985 }
4986 if (!isVisible) {
4987 return;
4988 }
4989 }
4990
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004991 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004992 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004993 try {
4994 if (mStrictModeFlash == null) {
4995 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4996 }
4997 mStrictModeFlash.setVisibility(on);
4998 } finally {
4999 Surface.closeTransaction();
5000 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005001 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005002 }
5003 }
5004
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08005005 public void setStrictModeVisualIndicatorPreference(String value) {
5006 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
5007 }
5008
Dianne Hackbornd2835932010-12-13 16:28:46 -08005009 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005010 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5011 "screenshotApplications()")) {
5012 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5013 }
5014
5015 Bitmap rawss;
5016
Dianne Hackbornd2835932010-12-13 16:28:46 -08005017 int maxLayer = 0;
5018 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005019 final Rect frame = new Rect();
5020
5021 float scale;
5022 int sw, sh, dw, dh;
5023 int rot;
5024
5025 synchronized(mWindowMap) {
5026 long ident = Binder.clearCallingIdentity();
5027
5028 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5029 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5030 + TYPE_LAYER_OFFSET;
5031 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5032
5033 // Figure out the part of the screen that is actually the app.
5034 for (int i=0; i<mWindows.size(); i++) {
5035 WindowState ws = mWindows.get(i);
5036 if (ws.mSurface == null) {
5037 continue;
5038 }
5039 if (ws.mLayer >= aboveAppLayer) {
5040 break;
5041 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005042 if (appToken != null && (ws.mAppToken == null
5043 || ws.mAppToken.token != appToken)) {
5044 continue;
5045 }
5046 if (maxLayer < ws.mAnimLayer) {
5047 maxLayer = ws.mAnimLayer;
5048 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005049 final Rect wf = ws.mFrame;
5050 final Rect cr = ws.mContentInsets;
5051 int left = wf.left + cr.left;
5052 int top = wf.top + cr.top;
5053 int right = wf.right - cr.right;
5054 int bottom = wf.bottom - cr.bottom;
5055 frame.union(left, top, right, bottom);
5056 }
5057 Binder.restoreCallingIdentity(ident);
5058
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005059 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005060 return null;
5061 }
5062
5063 // The screenshot API does not apply the current screen rotation.
5064 rot = mDisplay.getRotation();
5065 int fw = frame.width();
5066 int fh = frame.height();
5067
5068 // First try reducing to fit in x dimension.
5069 scale = maxWidth/(float)fw;
5070 sw = maxWidth;
5071 sh = (int)(fh*scale);
5072 if (sh > maxHeight) {
5073 // y dimension became too long; constrain by that.
5074 scale = maxHeight/(float)fh;
5075 sw = (int)(fw*scale);
5076 sh = maxHeight;
5077 }
5078
5079 // The screen shot will contain the entire screen.
5080 dw = (int)(mDisplay.getWidth()*scale);
5081 dh = (int)(mDisplay.getHeight()*scale);
5082 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5083 int tmp = dw;
5084 dw = dh;
5085 dh = tmp;
5086 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5087 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005088 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005089 }
5090
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005091 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005092 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5093 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005094 return null;
5095 }
5096
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005097 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5098 Matrix matrix = new Matrix();
5099 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5100 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5101 Canvas canvas = new Canvas(bm);
5102 canvas.drawBitmap(rawss, matrix, null);
5103
5104 rawss.recycle();
5105 return bm;
5106 }
5107
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005108 public void freezeRotation() {
5109 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5110 "setRotation()")) {
5111 throw new SecurityException("Requires SET_ORIENTATION permission");
5112 }
5113
5114 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5115 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5116 }
5117
5118 public void thawRotation() {
5119 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5120 "setRotation()")) {
5121 throw new SecurityException("Requires SET_ORIENTATION permission");
5122 }
5123
5124 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5125 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5126 }
5127
Romain Guy06882f82009-06-10 13:36:04 -07005128 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005129 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005130 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005131 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005132 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005133 }
5134
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005135 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 }
Romain Guy06882f82009-06-10 13:36:04 -07005137
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005138 public void setRotationUnchecked(int rotation,
5139 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005140 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005141 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005143 long origId = Binder.clearCallingIdentity();
5144 boolean changed;
5145 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005146 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005147 }
Romain Guy06882f82009-06-10 13:36:04 -07005148
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005149 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005150 sendNewConfiguration();
5151 }
Romain Guy06882f82009-06-10 13:36:04 -07005152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005153 Binder.restoreCallingIdentity(origId);
5154 }
Romain Guy06882f82009-06-10 13:36:04 -07005155
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005156 /**
5157 * Apply a new rotation to the screen, respecting the requests of
5158 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5159 * re-evaluate the desired rotation.
5160 *
5161 * Returns null if the rotation has been changed. In this case YOU
5162 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5163 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005164 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005165 if (mDragState != null) {
5166 // Potential rotation during a drag. Don't do the rotation now, but make
5167 // a note to perform the rotation later.
5168 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation during drag");
5169 mDragState.setDeferredRotation(rotation, animFlags);
5170 return false;
5171 }
5172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005173 boolean changed;
5174 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5175 rotation = mRequestedRotation;
5176 } else {
5177 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005178 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005180 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005181 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005182 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005183 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005186 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005187 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005188 "Rotation changed to " + rotation
5189 + " from " + mRotation
5190 + " (forceApp=" + mForcedAppOrientation
5191 + ", req=" + mRequestedRotation + ")");
5192 mRotation = rotation;
5193 mWindowsFreezingScreen = true;
5194 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5195 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5196 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005197 mWaitingForConfig = true;
5198 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005199 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005200 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005201 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005202 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005203 if (CUSTOM_SCREEN_ROTATION) {
5204 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005205 if (!inTransaction) {
5206 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5207 ">>> OPEN TRANSACTION setRotationUnchecked");
5208 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005209 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005210 try {
5211 if (mScreenRotationAnimation != null) {
5212 mScreenRotationAnimation.setRotation(rotation);
5213 }
5214 } finally {
5215 if (!inTransaction) {
5216 Surface.closeTransaction();
5217 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5218 "<<< CLOSE TRANSACTION setRotationUnchecked");
5219 }
5220 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005221 Surface.setOrientation(0, rotation, animFlags);
5222 Surface.unfreezeDisplay(0);
5223 } else {
5224 Surface.setOrientation(0, rotation, animFlags);
5225 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005226 }
5227 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005228 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005229 if (w.mSurface != null) {
5230 w.mOrientationChanging = true;
5231 }
5232 }
5233 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5234 try {
5235 mRotationWatchers.get(i).onRotationChanged(rotation);
5236 } catch (RemoteException e) {
5237 }
5238 }
5239 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 return changed;
5242 }
Romain Guy06882f82009-06-10 13:36:04 -07005243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005244 public int getRotation() {
5245 return mRotation;
5246 }
5247
5248 public int watchRotation(IRotationWatcher watcher) {
5249 final IBinder watcherBinder = watcher.asBinder();
5250 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5251 public void binderDied() {
5252 synchronized (mWindowMap) {
5253 for (int i=0; i<mRotationWatchers.size(); i++) {
5254 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005255 IRotationWatcher removed = mRotationWatchers.remove(i);
5256 if (removed != null) {
5257 removed.asBinder().unlinkToDeath(this, 0);
5258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005259 i--;
5260 }
5261 }
5262 }
5263 }
5264 };
Romain Guy06882f82009-06-10 13:36:04 -07005265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005266 synchronized (mWindowMap) {
5267 try {
5268 watcher.asBinder().linkToDeath(dr, 0);
5269 mRotationWatchers.add(watcher);
5270 } catch (RemoteException e) {
5271 // Client died, no cleanup needed.
5272 }
Romain Guy06882f82009-06-10 13:36:04 -07005273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005274 return mRotation;
5275 }
5276 }
5277
5278 /**
5279 * Starts the view server on the specified port.
5280 *
5281 * @param port The port to listener to.
5282 *
5283 * @return True if the server was successfully started, false otherwise.
5284 *
5285 * @see com.android.server.ViewServer
5286 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5287 */
5288 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005289 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005290 return false;
5291 }
5292
5293 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5294 return false;
5295 }
5296
5297 if (port < 1024) {
5298 return false;
5299 }
5300
5301 if (mViewServer != null) {
5302 if (!mViewServer.isRunning()) {
5303 try {
5304 return mViewServer.start();
5305 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005306 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005307 }
5308 }
5309 return false;
5310 }
5311
5312 try {
5313 mViewServer = new ViewServer(this, port);
5314 return mViewServer.start();
5315 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005316 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005317 }
5318 return false;
5319 }
5320
Romain Guy06882f82009-06-10 13:36:04 -07005321 private boolean isSystemSecure() {
5322 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5323 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5324 }
5325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005326 /**
5327 * Stops the view server if it exists.
5328 *
5329 * @return True if the server stopped, false if it wasn't started or
5330 * couldn't be stopped.
5331 *
5332 * @see com.android.server.ViewServer
5333 */
5334 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005335 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005336 return false;
5337 }
5338
5339 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5340 return false;
5341 }
5342
5343 if (mViewServer != null) {
5344 return mViewServer.stop();
5345 }
5346 return false;
5347 }
5348
5349 /**
5350 * Indicates whether the view server is running.
5351 *
5352 * @return True if the server is running, false otherwise.
5353 *
5354 * @see com.android.server.ViewServer
5355 */
5356 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005357 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005358 return false;
5359 }
5360
5361 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5362 return false;
5363 }
5364
5365 return mViewServer != null && mViewServer.isRunning();
5366 }
5367
5368 /**
5369 * Lists all availble windows in the system. The listing is written in the
5370 * specified Socket's output stream with the following syntax:
5371 * windowHashCodeInHexadecimal windowName
5372 * Each line of the ouput represents a different window.
5373 *
5374 * @param client The remote client to send the listing to.
5375 * @return False if an error occured, true otherwise.
5376 */
5377 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005378 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005379 return false;
5380 }
5381
5382 boolean result = true;
5383
Jeff Browne33348b2010-07-15 23:54:05 -07005384 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005386 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005387 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005388 }
5389
5390 BufferedWriter out = null;
5391
5392 // Any uncaught exception will crash the system process
5393 try {
5394 OutputStream clientStream = client.getOutputStream();
5395 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5396
5397 final int count = windows.length;
5398 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005399 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005400 out.write(Integer.toHexString(System.identityHashCode(w)));
5401 out.write(' ');
5402 out.append(w.mAttrs.getTitle());
5403 out.write('\n');
5404 }
5405
5406 out.write("DONE.\n");
5407 out.flush();
5408 } catch (Exception e) {
5409 result = false;
5410 } finally {
5411 if (out != null) {
5412 try {
5413 out.close();
5414 } catch (IOException e) {
5415 result = false;
5416 }
5417 }
5418 }
5419
5420 return result;
5421 }
5422
5423 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005424 * Returns the focused window in the following format:
5425 * windowHashCodeInHexadecimal windowName
5426 *
5427 * @param client The remote client to send the listing to.
5428 * @return False if an error occurred, true otherwise.
5429 */
5430 boolean viewServerGetFocusedWindow(Socket client) {
5431 if (isSystemSecure()) {
5432 return false;
5433 }
5434
5435 boolean result = true;
5436
5437 WindowState focusedWindow = getFocusedWindow();
5438
5439 BufferedWriter out = null;
5440
5441 // Any uncaught exception will crash the system process
5442 try {
5443 OutputStream clientStream = client.getOutputStream();
5444 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5445
5446 if(focusedWindow != null) {
5447 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5448 out.write(' ');
5449 out.append(focusedWindow.mAttrs.getTitle());
5450 }
5451 out.write('\n');
5452 out.flush();
5453 } catch (Exception e) {
5454 result = false;
5455 } finally {
5456 if (out != null) {
5457 try {
5458 out.close();
5459 } catch (IOException e) {
5460 result = false;
5461 }
5462 }
5463 }
5464
5465 return result;
5466 }
5467
5468 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005469 * Sends a command to a target window. The result of the command, if any, will be
5470 * written in the output stream of the specified socket.
5471 *
5472 * The parameters must follow this syntax:
5473 * windowHashcode extra
5474 *
5475 * Where XX is the length in characeters of the windowTitle.
5476 *
5477 * The first parameter is the target window. The window with the specified hashcode
5478 * will be the target. If no target can be found, nothing happens. The extra parameters
5479 * will be delivered to the target window and as parameters to the command itself.
5480 *
5481 * @param client The remote client to sent the result, if any, to.
5482 * @param command The command to execute.
5483 * @param parameters The command parameters.
5484 *
5485 * @return True if the command was successfully delivered, false otherwise. This does
5486 * not indicate whether the command itself was successful.
5487 */
5488 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005489 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005490 return false;
5491 }
5492
5493 boolean success = true;
5494 Parcel data = null;
5495 Parcel reply = null;
5496
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005497 BufferedWriter out = null;
5498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005499 // Any uncaught exception will crash the system process
5500 try {
5501 // Find the hashcode of the window
5502 int index = parameters.indexOf(' ');
5503 if (index == -1) {
5504 index = parameters.length();
5505 }
5506 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005507 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005508
5509 // Extract the command's parameter after the window description
5510 if (index < parameters.length()) {
5511 parameters = parameters.substring(index + 1);
5512 } else {
5513 parameters = "";
5514 }
5515
5516 final WindowManagerService.WindowState window = findWindow(hashCode);
5517 if (window == null) {
5518 return false;
5519 }
5520
5521 data = Parcel.obtain();
5522 data.writeInterfaceToken("android.view.IWindow");
5523 data.writeString(command);
5524 data.writeString(parameters);
5525 data.writeInt(1);
5526 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5527
5528 reply = Parcel.obtain();
5529
5530 final IBinder binder = window.mClient.asBinder();
5531 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5532 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5533
5534 reply.readException();
5535
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005536 if (!client.isOutputShutdown()) {
5537 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5538 out.write("DONE\n");
5539 out.flush();
5540 }
5541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005542 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005543 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005544 success = false;
5545 } finally {
5546 if (data != null) {
5547 data.recycle();
5548 }
5549 if (reply != null) {
5550 reply.recycle();
5551 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005552 if (out != null) {
5553 try {
5554 out.close();
5555 } catch (IOException e) {
5556
5557 }
5558 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005559 }
5560
5561 return success;
5562 }
5563
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005564 public void addWindowChangeListener(WindowChangeListener listener) {
5565 synchronized(mWindowMap) {
5566 mWindowChangeListeners.add(listener);
5567 }
5568 }
5569
5570 public void removeWindowChangeListener(WindowChangeListener listener) {
5571 synchronized(mWindowMap) {
5572 mWindowChangeListeners.remove(listener);
5573 }
5574 }
5575
5576 private void notifyWindowsChanged() {
5577 WindowChangeListener[] windowChangeListeners;
5578 synchronized(mWindowMap) {
5579 if(mWindowChangeListeners.isEmpty()) {
5580 return;
5581 }
5582 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5583 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5584 }
5585 int N = windowChangeListeners.length;
5586 for(int i = 0; i < N; i++) {
5587 windowChangeListeners[i].windowsChanged();
5588 }
5589 }
5590
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005591 private void notifyFocusChanged() {
5592 WindowChangeListener[] windowChangeListeners;
5593 synchronized(mWindowMap) {
5594 if(mWindowChangeListeners.isEmpty()) {
5595 return;
5596 }
5597 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5598 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5599 }
5600 int N = windowChangeListeners.length;
5601 for(int i = 0; i < N; i++) {
5602 windowChangeListeners[i].focusChanged();
5603 }
5604 }
5605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005606 private WindowState findWindow(int hashCode) {
5607 if (hashCode == -1) {
5608 return getFocusedWindow();
5609 }
5610
5611 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005612 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005613 final int count = windows.size();
5614
5615 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005616 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005617 if (System.identityHashCode(w) == hashCode) {
5618 return w;
5619 }
5620 }
5621 }
5622
5623 return null;
5624 }
5625
5626 /*
5627 * Instruct the Activity Manager to fetch the current configuration and broadcast
5628 * that to config-changed listeners if appropriate.
5629 */
5630 void sendNewConfiguration() {
5631 try {
5632 mActivityManager.updateConfiguration(null);
5633 } catch (RemoteException e) {
5634 }
5635 }
Romain Guy06882f82009-06-10 13:36:04 -07005636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005637 public Configuration computeNewConfiguration() {
5638 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005639 Configuration config = computeNewConfigurationLocked();
5640 if (config == null && mWaitingForConfig) {
5641 // Nothing changed but we are waiting for something... stop that!
5642 mWaitingForConfig = false;
5643 performLayoutAndPlaceSurfacesLocked();
5644 }
5645 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005646 }
5647 }
Romain Guy06882f82009-06-10 13:36:04 -07005648
Dianne Hackbornc485a602009-03-24 22:39:49 -07005649 Configuration computeNewConfigurationLocked() {
5650 Configuration config = new Configuration();
5651 if (!computeNewConfigurationLocked(config)) {
5652 return null;
5653 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005654 return config;
5655 }
Romain Guy06882f82009-06-10 13:36:04 -07005656
Dianne Hackbornc485a602009-03-24 22:39:49 -07005657 boolean computeNewConfigurationLocked(Configuration config) {
5658 if (mDisplay == null) {
5659 return false;
5660 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005661
5662 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005663
5664 // Use the effective "visual" dimensions based on current rotation
5665 final boolean rotated = (mRotation == Surface.ROTATION_90
5666 || mRotation == Surface.ROTATION_270);
5667 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5668 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5669
Dianne Hackbornc485a602009-03-24 22:39:49 -07005670 int orientation = Configuration.ORIENTATION_SQUARE;
5671 if (dw < dh) {
5672 orientation = Configuration.ORIENTATION_PORTRAIT;
5673 } else if (dw > dh) {
5674 orientation = Configuration.ORIENTATION_LANDSCAPE;
5675 }
5676 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005677
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005678 DisplayMetrics dm = new DisplayMetrics();
5679 mDisplay.getMetrics(dm);
5680 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5681
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005682 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005683 // Note we only do this once because at this point we don't
5684 // expect the screen to change in this way at runtime, and want
5685 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005686 int longSize = dw;
5687 int shortSize = dh;
5688 if (longSize < shortSize) {
5689 int tmp = longSize;
5690 longSize = shortSize;
5691 shortSize = tmp;
5692 }
5693 longSize = (int)(longSize/dm.density);
5694 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005695
Dianne Hackborn723738c2009-06-25 19:48:04 -07005696 // These semi-magic numbers define our compatibility modes for
5697 // applications with different screens. Don't change unless you
5698 // make sure to test lots and lots of apps!
5699 if (longSize < 470) {
5700 // This is shorter than an HVGA normal density screen (which
5701 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005702 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5703 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005704 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005705 // What size is this screen screen?
5706 if (longSize >= 800 && shortSize >= 600) {
5707 // SVGA or larger screens at medium density are the point
5708 // at which we consider it to be an extra large screen.
5709 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005710 } else if (longSize >= 530 && shortSize >= 400) {
5711 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005712 // at which we consider it to be a large screen.
5713 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5714 } else {
5715 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005716
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005717 // If this screen is wider than normal HVGA, or taller
5718 // than FWVGA, then for old apps we want to run in size
5719 // compatibility mode.
5720 if (shortSize > 321 || longSize > 570) {
5721 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5722 }
5723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005724
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005725 // Is this a long screen?
5726 if (((longSize*3)/5) >= (shortSize-1)) {
5727 // Anything wider than WVGA (5:3) is considering to be long.
5728 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5729 } else {
5730 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5731 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005732 }
5733 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005734 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005735
Dianne Hackbornc485a602009-03-24 22:39:49 -07005736 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5737 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5738 mPolicy.adjustConfigurationLw(config);
5739 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005740 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005741
5742 // -------------------------------------------------------------
5743 // Drag and drop
5744 // -------------------------------------------------------------
5745
5746 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005747 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005748 if (DEBUG_DRAG) {
5749 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005750 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005751 + " asbinder=" + window.asBinder());
5752 }
5753
5754 final int callerPid = Binder.getCallingPid();
5755 final long origId = Binder.clearCallingIdentity();
5756 IBinder token = null;
5757
5758 try {
5759 synchronized (mWindowMap) {
5760 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005761 if (mDragState == null) {
5762 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5763 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5764 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005765 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005766 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005767 // TODO: preserve flags param in DragState
5768 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005769 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005770 token = mDragState.mToken = new Binder();
5771
5772 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005773 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5774 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005775 mH.sendMessageDelayed(msg, 5000);
5776 } else {
5777 Slog.w(TAG, "Drag already in progress");
5778 }
5779 } catch (Surface.OutOfResourcesException e) {
5780 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5781 if (mDragState != null) {
5782 mDragState.reset();
5783 mDragState = null;
5784 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005785 }
5786 }
5787 } finally {
5788 Binder.restoreCallingIdentity(origId);
5789 }
5790
5791 return token;
5792 }
5793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005794 // -------------------------------------------------------------
5795 // Input Events and Focus Management
5796 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005797
Jeff Brown349703e2010-06-22 01:27:15 -07005798 InputMonitor mInputMonitor = new InputMonitor();
5799
5800 /* Tracks the progress of input dispatch and ensures that input dispatch state
5801 * is kept in sync with changes in window focus, visibility, registration, and
5802 * other relevant Window Manager state transitions. */
5803 final class InputMonitor {
5804 // Current window with input focus for keys and other non-touch events. May be null.
5805 private WindowState mInputFocus;
5806
5807 // When true, prevents input dispatch from proceeding until set to false again.
5808 private boolean mInputDispatchFrozen;
5809
5810 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5811 private boolean mInputDispatchEnabled = true;
5812
5813 // Temporary list of windows information to provide to the input dispatcher.
5814 private InputWindowList mTempInputWindows = new InputWindowList();
5815
5816 // Temporary input application object to provide to the input dispatcher.
5817 private InputApplication mTempInputApplication = new InputApplication();
5818
Jeff Brownb09abc12011-01-13 21:08:27 -08005819 // Set to true when the first input device configuration change notification
5820 // is received to indicate that the input devices are ready.
5821 private final Object mInputDevicesReadyMonitor = new Object();
5822 private boolean mInputDevicesReady;
5823
Jeff Brown349703e2010-06-22 01:27:15 -07005824 /* Notifies the window manager about a broken input channel.
5825 *
5826 * Called by the InputManager.
5827 */
Jeff Brown928e0542011-01-10 11:17:36 -08005828 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5829 if (inputWindowHandle == null) {
5830 return;
5831 }
5832
Jeff Brown349703e2010-06-22 01:27:15 -07005833 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005834 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005835 Slog.i(TAG, "WINDOW DIED " + windowState);
5836 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005837 }
5838 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005839
Jeff Brown519e0242010-09-15 15:18:56 -07005840 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005841 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005842 *
5843 * Called by the InputManager.
5844 */
Jeff Brown928e0542011-01-10 11:17:36 -08005845 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5846 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005847 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005848 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005849 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005850 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005851 if (windowState != null) {
5852 Slog.i(TAG, "Input event dispatching timed out sending to "
5853 + windowState.mAttrs.getTitle());
5854 appWindowToken = windowState.mAppToken;
5855 }
Jeff Brown349703e2010-06-22 01:27:15 -07005856 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005857 }
5858
Jeff Brown928e0542011-01-10 11:17:36 -08005859 if (appWindowToken == null && inputApplicationHandle != null) {
5860 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005861 Slog.i(TAG, "Input event dispatching timed out sending to application "
5862 + appWindowToken.stringName);
5863 }
Jeff Brown349703e2010-06-22 01:27:15 -07005864
Jeff Brown519e0242010-09-15 15:18:56 -07005865 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005866 try {
5867 // Notify the activity manager about the timeout and let it decide whether
5868 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005869 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005870 if (! abort) {
5871 // The activity manager declined to abort dispatching.
5872 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005873 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005874 }
Jeff Brown349703e2010-06-22 01:27:15 -07005875 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005876 }
5877 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005878 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005879 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005880
Chris Tatea32dcf72010-10-14 12:13:50 -07005881 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005882 final InputWindow inputWindow = windowList.add();
5883 inputWindow.inputChannel = mDragState.mServerChannel;
5884 inputWindow.name = "drag";
5885 inputWindow.layoutParamsFlags = 0;
5886 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5887 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5888 inputWindow.visible = true;
5889 inputWindow.canReceiveKeys = false;
5890 inputWindow.hasFocus = true;
5891 inputWindow.hasWallpaper = false;
5892 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005893 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005894 inputWindow.ownerPid = Process.myPid();
5895 inputWindow.ownerUid = Process.myUid();
5896
5897 // The drag window covers the entire display
5898 inputWindow.frameLeft = 0;
5899 inputWindow.frameTop = 0;
5900 inputWindow.frameRight = mDisplay.getWidth();
5901 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005902
Christopher Tatea53146c2010-09-07 11:57:52 -07005903 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5904 inputWindow.visibleFrameTop = inputWindow.frameTop;
5905 inputWindow.visibleFrameRight = inputWindow.frameRight;
5906 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5907
5908 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5909 inputWindow.touchableAreaTop = inputWindow.frameTop;
5910 inputWindow.touchableAreaRight = inputWindow.frameRight;
5911 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5912 }
5913
Jeff Brown349703e2010-06-22 01:27:15 -07005914 /* Updates the cached window information provided to the input dispatcher. */
5915 public void updateInputWindowsLw() {
5916 // Populate the input window list with information about all of the windows that
5917 // could potentially receive input.
5918 // As an optimization, we could try to prune the list of windows but this turns
5919 // out to be difficult because only the native code knows for sure which window
5920 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005921 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005922
5923 // If there's a drag in flight, provide a pseudowindow to catch drag input
5924 final boolean inDrag = (mDragState != null);
5925 if (inDrag) {
5926 if (DEBUG_DRAG) {
5927 Log.d(TAG, "Inserting drag window");
5928 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005929 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005930 }
5931
Jeff Brown7fbdc842010-06-17 20:52:56 -07005932 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005933 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005934 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005935 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005936 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005937 continue;
5938 }
5939
Jeff Brown349703e2010-06-22 01:27:15 -07005940 final int flags = child.mAttrs.flags;
5941 final int type = child.mAttrs.type;
5942
5943 final boolean hasFocus = (child == mInputFocus);
5944 final boolean isVisible = child.isVisibleLw();
5945 final boolean hasWallpaper = (child == mWallpaperTarget)
5946 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005947
5948 // If there's a drag in progress and 'child' is a potential drop target,
5949 // make sure it's been told about the drag
5950 if (inDrag && isVisible) {
5951 mDragState.sendDragStartedIfNeededLw(child);
5952 }
5953
Jeff Brown349703e2010-06-22 01:27:15 -07005954 // Add a window to our list of input windows.
5955 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005956 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005957 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005958 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005959 inputWindow.layoutParamsFlags = flags;
5960 inputWindow.layoutParamsType = type;
5961 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5962 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005963 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005964 inputWindow.hasFocus = hasFocus;
5965 inputWindow.hasWallpaper = hasWallpaper;
5966 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005967 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005968 inputWindow.ownerPid = child.mSession.mPid;
5969 inputWindow.ownerUid = child.mSession.mUid;
5970
5971 final Rect frame = child.mFrame;
5972 inputWindow.frameLeft = frame.left;
5973 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005974 inputWindow.frameRight = frame.right;
5975 inputWindow.frameBottom = frame.bottom;
5976
5977 final Rect visibleFrame = child.mVisibleFrame;
5978 inputWindow.visibleFrameLeft = visibleFrame.left;
5979 inputWindow.visibleFrameTop = visibleFrame.top;
5980 inputWindow.visibleFrameRight = visibleFrame.right;
5981 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005982
5983 switch (child.mTouchableInsets) {
5984 default:
5985 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5986 inputWindow.touchableAreaLeft = frame.left;
5987 inputWindow.touchableAreaTop = frame.top;
5988 inputWindow.touchableAreaRight = frame.right;
5989 inputWindow.touchableAreaBottom = frame.bottom;
5990 break;
5991
5992 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5993 Rect inset = child.mGivenContentInsets;
5994 inputWindow.touchableAreaLeft = frame.left + inset.left;
5995 inputWindow.touchableAreaTop = frame.top + inset.top;
5996 inputWindow.touchableAreaRight = frame.right - inset.right;
5997 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5998 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005999 }
Jeff Brown349703e2010-06-22 01:27:15 -07006000
6001 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
6002 Rect inset = child.mGivenVisibleInsets;
6003 inputWindow.touchableAreaLeft = frame.left + inset.left;
6004 inputWindow.touchableAreaTop = frame.top + inset.top;
6005 inputWindow.touchableAreaRight = frame.right - inset.right;
6006 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006007 break;
6008 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006009 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006010 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006011
Jeff Brown349703e2010-06-22 01:27:15 -07006012 // Send windows to native code.
6013 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006014
Jeff Brown349703e2010-06-22 01:27:15 -07006015 // Clear the list in preparation for the next round.
6016 // Also avoids keeping InputChannel objects referenced unnecessarily.
6017 mTempInputWindows.clear();
6018 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006019
6020 /* Notifies that the input device configuration has changed. */
6021 public void notifyConfigurationChanged() {
6022 sendNewConfiguration();
6023
6024 synchronized (mInputDevicesReadyMonitor) {
6025 if (!mInputDevicesReady) {
6026 mInputDevicesReady = true;
6027 mInputDevicesReadyMonitor.notifyAll();
6028 }
6029 }
6030 }
6031
6032 /* Waits until the built-in input devices have been configured. */
6033 public boolean waitForInputDevicesReady(long timeoutMillis) {
6034 synchronized (mInputDevicesReadyMonitor) {
6035 if (!mInputDevicesReady) {
6036 try {
6037 mInputDevicesReadyMonitor.wait(timeoutMillis);
6038 } catch (InterruptedException ex) {
6039 }
6040 }
6041 return mInputDevicesReady;
6042 }
6043 }
6044
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006045 /* Notifies that the lid switch changed state. */
6046 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6047 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6048 }
6049
Jeff Brown349703e2010-06-22 01:27:15 -07006050 /* Provides an opportunity for the window manager policy to intercept early key
6051 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006052 public int interceptKeyBeforeQueueing(
6053 KeyEvent event, int policyFlags, boolean isScreenOn) {
6054 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006055 }
6056
6057 /* Provides an opportunity for the window manager policy to process a key before
6058 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006059 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006060 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006061 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006062 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006063 }
6064
Jeff Brown3915bb82010-11-05 15:02:16 -07006065 /* Provides an opportunity for the window manager policy to process a key that
6066 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006067 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006068 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006069 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006070 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006071 }
6072
Jeff Brown349703e2010-06-22 01:27:15 -07006073 /* Called when the current input focus changes.
6074 * Layer assignment is assumed to be complete by the time this is called.
6075 */
6076 public void setInputFocusLw(WindowState newWindow) {
6077 if (DEBUG_INPUT) {
6078 Slog.d(TAG, "Input focus has changed to " + newWindow);
6079 }
6080
6081 if (newWindow != mInputFocus) {
6082 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006083 // Displaying a window implicitly causes dispatching to be unpaused.
6084 // This is to protect against bugs if someone pauses dispatching but
6085 // forgets to resume.
6086 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006087 }
Jeff Brown349703e2010-06-22 01:27:15 -07006088
6089 mInputFocus = newWindow;
6090 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006091 }
6092 }
6093
Jeff Brown349703e2010-06-22 01:27:15 -07006094 public void setFocusedAppLw(AppWindowToken newApp) {
6095 // Focused app has changed.
6096 if (newApp == null) {
6097 mInputManager.setFocusedApplication(null);
6098 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006099 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006100 mTempInputApplication.name = newApp.toString();
6101 mTempInputApplication.dispatchingTimeoutNanos =
6102 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006103
Jeff Brown349703e2010-06-22 01:27:15 -07006104 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006105
6106 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006107 }
6108 }
6109
Jeff Brown349703e2010-06-22 01:27:15 -07006110 public void pauseDispatchingLw(WindowToken window) {
6111 if (! window.paused) {
6112 if (DEBUG_INPUT) {
6113 Slog.v(TAG, "Pausing WindowToken " + window);
6114 }
6115
6116 window.paused = true;
6117 updateInputWindowsLw();
6118 }
6119 }
6120
6121 public void resumeDispatchingLw(WindowToken window) {
6122 if (window.paused) {
6123 if (DEBUG_INPUT) {
6124 Slog.v(TAG, "Resuming WindowToken " + window);
6125 }
6126
6127 window.paused = false;
6128 updateInputWindowsLw();
6129 }
6130 }
6131
6132 public void freezeInputDispatchingLw() {
6133 if (! mInputDispatchFrozen) {
6134 if (DEBUG_INPUT) {
6135 Slog.v(TAG, "Freezing input dispatching");
6136 }
6137
6138 mInputDispatchFrozen = true;
6139 updateInputDispatchModeLw();
6140 }
6141 }
6142
6143 public void thawInputDispatchingLw() {
6144 if (mInputDispatchFrozen) {
6145 if (DEBUG_INPUT) {
6146 Slog.v(TAG, "Thawing input dispatching");
6147 }
6148
6149 mInputDispatchFrozen = false;
6150 updateInputDispatchModeLw();
6151 }
6152 }
6153
6154 public void setEventDispatchingLw(boolean enabled) {
6155 if (mInputDispatchEnabled != enabled) {
6156 if (DEBUG_INPUT) {
6157 Slog.v(TAG, "Setting event dispatching to " + enabled);
6158 }
6159
6160 mInputDispatchEnabled = enabled;
6161 updateInputDispatchModeLw();
6162 }
6163 }
6164
6165 private void updateInputDispatchModeLw() {
6166 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6167 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 public void pauseKeyDispatching(IBinder _token) {
6171 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6172 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006173 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006174 }
6175
6176 synchronized (mWindowMap) {
6177 WindowToken token = mTokenMap.get(_token);
6178 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006179 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006180 }
6181 }
6182 }
6183
6184 public void resumeKeyDispatching(IBinder _token) {
6185 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6186 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006187 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006188 }
6189
6190 synchronized (mWindowMap) {
6191 WindowToken token = mTokenMap.get(_token);
6192 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006193 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006194 }
6195 }
6196 }
6197
6198 public void setEventDispatching(boolean enabled) {
6199 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6200 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006201 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006202 }
6203
6204 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006205 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 }
6207 }
Romain Guy06882f82009-06-10 13:36:04 -07006208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209 /**
6210 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006211 * Even when sync is false, this method may block while waiting for current
6212 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006213 *
6214 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006215 * {@link SystemClock#uptimeMillis()} as the timebase.)
6216 * @param sync If true, wait for the event to be completed before returning to the caller.
6217 * @return Returns true if event was dispatched, false if it was dropped for any reason
6218 */
6219 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6220 long downTime = ev.getDownTime();
6221 long eventTime = ev.getEventTime();
6222
6223 int action = ev.getAction();
6224 int code = ev.getKeyCode();
6225 int repeatCount = ev.getRepeatCount();
6226 int metaState = ev.getMetaState();
6227 int deviceId = ev.getDeviceId();
6228 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006229 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006230 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006231
6232 if (source == InputDevice.SOURCE_UNKNOWN) {
6233 source = InputDevice.SOURCE_KEYBOARD;
6234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006235
6236 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6237 if (downTime == 0) downTime = eventTime;
6238
6239 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006240 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006241
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006242 final int pid = Binder.getCallingPid();
6243 final int uid = Binder.getCallingUid();
6244 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006245
Jeff Brownbbda99d2010-07-28 15:48:59 -07006246 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6247 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6248 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6249 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006250
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006251 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006252 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006253 }
6254
6255 /**
6256 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006257 * Even when sync is false, this method may block while waiting for current
6258 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006259 *
6260 * @param ev A motion event describing the pointer (touch) action. (As noted in
6261 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006262 * {@link SystemClock#uptimeMillis()} as the timebase.)
6263 * @param sync If true, wait for the event to be completed before returning to the caller.
6264 * @return Returns true if event was dispatched, false if it was dropped for any reason
6265 */
6266 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006267 final int pid = Binder.getCallingPid();
6268 final int uid = Binder.getCallingUid();
6269 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006270
Jeff Brownc5ed5912010-07-14 18:48:53 -07006271 MotionEvent newEvent = MotionEvent.obtain(ev);
6272 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6273 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6274 }
6275
Jeff Brownbbda99d2010-07-28 15:48:59 -07006276 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6277 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6278 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6279 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006280
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006281 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006282 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006283 }
Romain Guy06882f82009-06-10 13:36:04 -07006284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 /**
6286 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006287 * Even when sync is false, this method may block while waiting for current
6288 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006289 *
6290 * @param ev A motion event describing the trackball action. (As noted in
6291 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 * {@link SystemClock#uptimeMillis()} as the timebase.)
6293 * @param sync If true, wait for the event to be completed before returning to the caller.
6294 * @return Returns true if event was dispatched, false if it was dropped for any reason
6295 */
6296 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006297 final int pid = Binder.getCallingPid();
6298 final int uid = Binder.getCallingUid();
6299 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006300
Jeff Brownc5ed5912010-07-14 18:48:53 -07006301 MotionEvent newEvent = MotionEvent.obtain(ev);
6302 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6303 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6304 }
6305
Jeff Brownbbda99d2010-07-28 15:48:59 -07006306 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6307 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6308 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6309 INJECTION_TIMEOUT_MILLIS);
6310
6311 Binder.restoreCallingIdentity(ident);
6312 return reportInjectionResult(result);
6313 }
6314
6315 /**
6316 * Inject an input event into the UI without waiting for dispatch to commence.
6317 * This variant is useful for fire-and-forget input event injection. It does not
6318 * block any longer than it takes to enqueue the input event.
6319 *
6320 * @param ev An input event. (Be sure to set the input source correctly.)
6321 * @return Returns true if event was dispatched, false if it was dropped for any reason
6322 */
6323 public boolean injectInputEventNoWait(InputEvent ev) {
6324 final int pid = Binder.getCallingPid();
6325 final int uid = Binder.getCallingUid();
6326 final long ident = Binder.clearCallingIdentity();
6327
6328 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6329 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6330 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006331
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006332 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006333 return reportInjectionResult(result);
6334 }
6335
6336 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006337 switch (result) {
6338 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6339 Slog.w(TAG, "Input event injection permission denied.");
6340 throw new SecurityException(
6341 "Injecting to another application requires INJECT_EVENTS permission");
6342 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006343 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006344 return true;
6345 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6346 Slog.w(TAG, "Input event injection timed out.");
6347 return false;
6348 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6349 default:
6350 Slog.w(TAG, "Input event injection failed.");
6351 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006353 }
Romain Guy06882f82009-06-10 13:36:04 -07006354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006355 private WindowState getFocusedWindow() {
6356 synchronized (mWindowMap) {
6357 return getFocusedWindowLocked();
6358 }
6359 }
6360
6361 private WindowState getFocusedWindowLocked() {
6362 return mCurrentFocus;
6363 }
Romain Guy06882f82009-06-10 13:36:04 -07006364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006365 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006366 if (!mInputMonitor.waitForInputDevicesReady(
6367 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6368 Slog.w(TAG, "Devices still not ready after waiting "
6369 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6370 + " milliseconds before attempting to detect safe mode.");
6371 }
6372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006373 mSafeMode = mPolicy.detectSafeMode();
6374 return mSafeMode;
6375 }
Romain Guy06882f82009-06-10 13:36:04 -07006376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006377 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006378 synchronized(mWindowMap) {
6379 if (mDisplay != null) {
6380 throw new IllegalStateException("Display already initialized");
6381 }
6382 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6383 mDisplay = wm.getDefaultDisplay();
6384 mInitialDisplayWidth = mDisplay.getWidth();
6385 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006386 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6387 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006388 }
6389
6390 try {
6391 mActivityManager.updateConfiguration(null);
6392 } catch (RemoteException e) {
6393 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006394
6395 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006396 }
6397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 // -------------------------------------------------------------
6399 // Client Session State
6400 // -------------------------------------------------------------
6401
6402 private final class Session extends IWindowSession.Stub
6403 implements IBinder.DeathRecipient {
6404 final IInputMethodClient mClient;
6405 final IInputContext mInputContext;
6406 final int mUid;
6407 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006408 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 SurfaceSession mSurfaceSession;
6410 int mNumWindow = 0;
6411 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006413 public Session(IInputMethodClient client, IInputContext inputContext) {
6414 mClient = client;
6415 mInputContext = inputContext;
6416 mUid = Binder.getCallingUid();
6417 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006418 StringBuilder sb = new StringBuilder();
6419 sb.append("Session{");
6420 sb.append(Integer.toHexString(System.identityHashCode(this)));
6421 sb.append(" uid ");
6422 sb.append(mUid);
6423 sb.append("}");
6424 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006426 synchronized (mWindowMap) {
6427 if (mInputMethodManager == null && mHaveInputMethods) {
6428 IBinder b = ServiceManager.getService(
6429 Context.INPUT_METHOD_SERVICE);
6430 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6431 }
6432 }
6433 long ident = Binder.clearCallingIdentity();
6434 try {
6435 // Note: it is safe to call in to the input method manager
6436 // here because we are not holding our lock.
6437 if (mInputMethodManager != null) {
6438 mInputMethodManager.addClient(client, inputContext,
6439 mUid, mPid);
6440 } else {
6441 client.setUsingInputMethod(false);
6442 }
6443 client.asBinder().linkToDeath(this, 0);
6444 } catch (RemoteException e) {
6445 // The caller has died, so we can just forget about this.
6446 try {
6447 if (mInputMethodManager != null) {
6448 mInputMethodManager.removeClient(client);
6449 }
6450 } catch (RemoteException ee) {
6451 }
6452 } finally {
6453 Binder.restoreCallingIdentity(ident);
6454 }
6455 }
Romain Guy06882f82009-06-10 13:36:04 -07006456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006457 @Override
6458 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6459 throws RemoteException {
6460 try {
6461 return super.onTransact(code, data, reply, flags);
6462 } catch (RuntimeException e) {
6463 // Log all 'real' exceptions thrown to the caller
6464 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006465 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 }
6467 throw e;
6468 }
6469 }
6470
6471 public void binderDied() {
6472 // Note: it is safe to call in to the input method manager
6473 // here because we are not holding our lock.
6474 try {
6475 if (mInputMethodManager != null) {
6476 mInputMethodManager.removeClient(mClient);
6477 }
6478 } catch (RemoteException e) {
6479 }
6480 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006481 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 mClientDead = true;
6483 killSessionLocked();
6484 }
6485 }
6486
6487 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006488 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6489 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6490 outInputChannel);
6491 }
6492
6493 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006495 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 }
Romain Guy06882f82009-06-10 13:36:04 -07006497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 public void remove(IWindow window) {
6499 removeWindow(this, window);
6500 }
Romain Guy06882f82009-06-10 13:36:04 -07006501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6503 int requestedWidth, int requestedHeight, int viewFlags,
6504 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006505 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006506 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6507 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006509 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006510 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6511 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006512 }
Romain Guy06882f82009-06-10 13:36:04 -07006513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006514 public void setTransparentRegion(IWindow window, Region region) {
6515 setTransparentRegionWindow(this, window, region);
6516 }
Romain Guy06882f82009-06-10 13:36:04 -07006517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006518 public void setInsets(IWindow window, int touchableInsets,
6519 Rect contentInsets, Rect visibleInsets) {
6520 setInsetsWindow(this, window, touchableInsets, contentInsets,
6521 visibleInsets);
6522 }
Romain Guy06882f82009-06-10 13:36:04 -07006523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006524 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6525 getWindowDisplayFrame(this, window, outDisplayFrame);
6526 }
Romain Guy06882f82009-06-10 13:36:04 -07006527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006528 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006529 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006530 TAG, "IWindow finishDrawing called for " + window);
6531 finishDrawingWindow(this, window);
6532 }
6533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006534 public void setInTouchMode(boolean mode) {
6535 synchronized(mWindowMap) {
6536 mInTouchMode = mode;
6537 }
6538 }
6539
6540 public boolean getInTouchMode() {
6541 synchronized(mWindowMap) {
6542 return mInTouchMode;
6543 }
6544 }
6545
6546 public boolean performHapticFeedback(IWindow window, int effectId,
6547 boolean always) {
6548 synchronized(mWindowMap) {
6549 long ident = Binder.clearCallingIdentity();
6550 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006551 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006552 windowForClientLocked(this, window, true),
6553 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006554 } finally {
6555 Binder.restoreCallingIdentity(ident);
6556 }
6557 }
6558 }
Romain Guy06882f82009-06-10 13:36:04 -07006559
Christopher Tatea53146c2010-09-07 11:57:52 -07006560 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006561 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006562 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006563 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006564 width, height, outSurface);
6565 }
6566
6567 public boolean performDrag(IWindow window, IBinder dragToken,
6568 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6569 ClipData data) {
6570 if (DEBUG_DRAG) {
6571 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6572 }
6573
6574 synchronized (mWindowMap) {
6575 if (mDragState == null) {
6576 Slog.w(TAG, "No drag prepared");
6577 throw new IllegalStateException("performDrag() without prepareDrag()");
6578 }
6579
6580 if (dragToken != mDragState.mToken) {
6581 Slog.w(TAG, "Performing mismatched drag");
6582 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6583 }
6584
6585 WindowState callingWin = windowForClientLocked(null, window, false);
6586 if (callingWin == null) {
6587 Slog.w(TAG, "Bad requesting window " + window);
6588 return false; // !!! TODO: throw here?
6589 }
6590
6591 // !!! TODO: if input is not still focused on the initiating window, fail
6592 // the drag initiation (e.g. an alarm window popped up just as the application
6593 // called performDrag()
6594
6595 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6596
Christopher Tate2c095f32010-10-04 14:13:40 -07006597 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6598 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006599
Chris Tateb478f462010-10-15 16:02:26 -07006600 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6601 // the actual drag event dispatch stuff in the dragstate
6602
Christopher Tatea53146c2010-09-07 11:57:52 -07006603 mDragState.register();
6604 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006605 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6606 mDragState.mServerChannel)) {
6607 Slog.e(TAG, "Unable to transfer touch focus");
6608 mDragState.unregister();
6609 mDragState = null;
6610 mInputMonitor.updateInputWindowsLw();
6611 return false;
6612 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006613
6614 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006615 mDragState.mCurrentX = touchX;
6616 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006617 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006618
6619 // remember the thumb offsets for later
6620 mDragState.mThumbOffsetX = thumbCenterX;
6621 mDragState.mThumbOffsetY = thumbCenterY;
6622
6623 // Make the surface visible at the proper location
6624 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006625 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006626 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006627 try {
6628 surface.setPosition((int)(touchX - thumbCenterX),
6629 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006630 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006631 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006632 surface.show();
6633 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006634 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006635 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006636 }
6637 }
6638
6639 return true; // success!
6640 }
6641
Chris Tated4533f142010-10-19 15:15:08 -07006642 public void reportDropResult(IWindow window, boolean consumed) {
6643 IBinder token = window.asBinder();
6644 if (DEBUG_DRAG) {
6645 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6646 }
6647
6648 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006649 long ident = Binder.clearCallingIdentity();
6650 try {
6651 if (mDragState.mToken != token) {
6652 Slog.w(TAG, "Invalid drop-result claim by " + window);
6653 throw new IllegalStateException("reportDropResult() by non-recipient");
6654 }
6655
6656 // The right window has responded, even if it's no longer around,
6657 // so be sure to halt the timeout even if the later WindowState
6658 // lookup fails.
6659 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6660 WindowState callingWin = windowForClientLocked(null, window, false);
6661 if (callingWin == null) {
6662 Slog.w(TAG, "Bad result-reporting window " + window);
6663 return; // !!! TODO: throw here?
6664 }
6665
6666 mDragState.mDragResult = consumed;
6667 mDragState.endDragLw();
6668 } finally {
6669 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006670 }
Chris Tated4533f142010-10-19 15:15:08 -07006671 }
6672 }
6673
Christopher Tatea53146c2010-09-07 11:57:52 -07006674 public void dragRecipientEntered(IWindow window) {
6675 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006676 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006677 }
6678 }
6679
6680 public void dragRecipientExited(IWindow window) {
6681 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006682 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006683 }
6684 }
6685
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006686 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006687 synchronized(mWindowMap) {
6688 long ident = Binder.clearCallingIdentity();
6689 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006690 setWindowWallpaperPositionLocked(
6691 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006692 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006693 } finally {
6694 Binder.restoreCallingIdentity(ident);
6695 }
6696 }
6697 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006698
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006699 public void wallpaperOffsetsComplete(IBinder window) {
6700 WindowManagerService.this.wallpaperOffsetsComplete(window);
6701 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006702
Dianne Hackborn75804932009-10-20 20:15:20 -07006703 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6704 int z, Bundle extras, boolean sync) {
6705 synchronized(mWindowMap) {
6706 long ident = Binder.clearCallingIdentity();
6707 try {
6708 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006709 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006710 action, x, y, z, extras, sync);
6711 } finally {
6712 Binder.restoreCallingIdentity(ident);
6713 }
6714 }
6715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006716
Dianne Hackborn75804932009-10-20 20:15:20 -07006717 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6718 WindowManagerService.this.wallpaperCommandComplete(window, result);
6719 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006721 void windowAddedLocked() {
6722 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006723 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006724 TAG, "First window added to " + this + ", creating SurfaceSession");
6725 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006726 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006727 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 mSessions.add(this);
6729 }
6730 mNumWindow++;
6731 }
6732
6733 void windowRemovedLocked() {
6734 mNumWindow--;
6735 killSessionLocked();
6736 }
Romain Guy06882f82009-06-10 13:36:04 -07006737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 void killSessionLocked() {
6739 if (mNumWindow <= 0 && mClientDead) {
6740 mSessions.remove(this);
6741 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006742 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006743 TAG, "Last window removed from " + this
6744 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006745 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006746 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 try {
6748 mSurfaceSession.kill();
6749 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006750 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006751 + mSurfaceSession + " in session " + this
6752 + ": " + e.toString());
6753 }
6754 mSurfaceSession = null;
6755 }
6756 }
6757 }
Romain Guy06882f82009-06-10 13:36:04 -07006758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006759 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006760 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6761 pw.print(" mClientDead="); pw.print(mClientDead);
6762 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006763 }
6764
6765 @Override
6766 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006767 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006768 }
6769 }
6770
6771 // -------------------------------------------------------------
6772 // Client Window State
6773 // -------------------------------------------------------------
6774
6775 private final class WindowState implements WindowManagerPolicy.WindowState {
6776 final Session mSession;
6777 final IWindow mClient;
6778 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006779 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 AppWindowToken mAppToken;
6781 AppWindowToken mTargetAppToken;
6782 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6783 final DeathRecipient mDeathRecipient;
6784 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006785 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006786 final int mBaseLayer;
6787 final int mSubLayer;
6788 final boolean mLayoutAttached;
6789 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006790 final boolean mIsWallpaper;
6791 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006792 int mViewVisibility;
6793 boolean mPolicyVisibility = true;
6794 boolean mPolicyVisibilityAfterAnim = true;
6795 boolean mAppFreezing;
6796 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006797 boolean mReportDestroySurface;
6798 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006799 boolean mAttachedHidden; // is our parent window hidden?
6800 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006801 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006802 int mRequestedWidth;
6803 int mRequestedHeight;
6804 int mLastRequestedWidth;
6805 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 int mLayer;
6807 int mAnimLayer;
6808 int mLastLayer;
6809 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006810 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006811 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006813 int mLayoutSeq = -1;
6814
6815 Configuration mConfiguration = null;
6816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006817 // Actual frame shown on-screen (may be modified by animation)
6818 final Rect mShownFrame = new Rect();
6819 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006821 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006822 * Set when we have changed the size of the surface, to know that
6823 * we must tell them application to resize (and thus redraw itself).
6824 */
6825 boolean mSurfaceResized;
6826
6827 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006828 * Insets that determine the actually visible area
6829 */
6830 final Rect mVisibleInsets = new Rect();
6831 final Rect mLastVisibleInsets = new Rect();
6832 boolean mVisibleInsetsChanged;
6833
6834 /**
6835 * Insets that are covered by system windows
6836 */
6837 final Rect mContentInsets = new Rect();
6838 final Rect mLastContentInsets = new Rect();
6839 boolean mContentInsetsChanged;
6840
6841 /**
6842 * Set to true if we are waiting for this window to receive its
6843 * given internal insets before laying out other windows based on it.
6844 */
6845 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006847 /**
6848 * These are the content insets that were given during layout for
6849 * this window, to be applied to windows behind it.
6850 */
6851 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 /**
6854 * These are the visible insets that were given during layout for
6855 * this window, to be applied to windows behind it.
6856 */
6857 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006859 /**
6860 * Flag indicating whether the touchable region should be adjusted by
6861 * the visible insets; if false the area outside the visible insets is
6862 * NOT touchable, so we must use those to adjust the frame during hit
6863 * tests.
6864 */
6865 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006868 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6870 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6871 float mHScale=1, mVScale=1;
6872 float mLastHScale=1, mLastVScale=1;
6873 final Matrix mTmpMatrix = new Matrix();
6874
6875 // "Real" frame that the application sees.
6876 final Rect mFrame = new Rect();
6877 final Rect mLastFrame = new Rect();
6878
6879 final Rect mContainingFrame = new Rect();
6880 final Rect mDisplayFrame = new Rect();
6881 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006882 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 final Rect mVisibleFrame = new Rect();
6884
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006885 boolean mContentChanged;
6886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 float mShownAlpha = 1;
6888 float mAlpha = 1;
6889 float mLastAlpha = 1;
6890
6891 // Set to true if, when the window gets displayed, it should perform
6892 // an enter animation.
6893 boolean mEnterAnimationPending;
6894
6895 // Currently running animation.
6896 boolean mAnimating;
6897 boolean mLocalAnimating;
6898 Animation mAnimation;
6899 boolean mAnimationIsEntrance;
6900 boolean mHasTransformation;
6901 boolean mHasLocalTransformation;
6902 final Transformation mTransformation = new Transformation();
6903
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006904 // If a window showing a wallpaper: the requested offset for the
6905 // wallpaper; if a wallpaper window: the currently applied offset.
6906 float mWallpaperX = -1;
6907 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006908
6909 // If a window showing a wallpaper: what fraction of the offset
6910 // range corresponds to a full virtual screen.
6911 float mWallpaperXStep = -1;
6912 float mWallpaperYStep = -1;
6913
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006914 // Wallpaper windows: pixels offset based on above variables.
6915 int mXOffset;
6916 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006918 // This is set after IWindowSession.relayout() has been called at
6919 // least once for the window. It allows us to detect the situation
6920 // where we don't yet have a surface, but should have one soon, so
6921 // we can give the window focus before waiting for the relayout.
6922 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006924 // This is set after the Surface has been created but before the
6925 // window has been drawn. During this time the surface is hidden.
6926 boolean mDrawPending;
6927
6928 // This is set after the window has finished drawing for the first
6929 // time but before its surface is shown. The surface will be
6930 // displayed when the next layout is run.
6931 boolean mCommitDrawPending;
6932
6933 // This is set during the time after the window's drawing has been
6934 // committed, and before its surface is actually shown. It is used
6935 // to delay showing the surface until all windows in a token are ready
6936 // to be shown.
6937 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 // Set when the window has been shown in the screen the first time.
6940 boolean mHasDrawn;
6941
6942 // Currently running an exit animation?
6943 boolean mExiting;
6944
6945 // Currently on the mDestroySurface list?
6946 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 // Completely remove from window manager after exit animation?
6949 boolean mRemoveOnExit;
6950
6951 // Set when the orientation is changing and this window has not yet
6952 // been updated for the new orientation.
6953 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 // Is this window now (or just being) removed?
6956 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006957
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006958 // Temp for keeping track of windows that have been removed when
6959 // rebuilding window list.
6960 boolean mRebuilding;
6961
Dianne Hackborn16064f92010-03-25 00:47:24 -07006962 // For debugging, this is the last information given to the surface flinger.
6963 boolean mSurfaceShown;
6964 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6965 int mSurfaceLayer;
6966 float mSurfaceAlpha;
6967
Jeff Brown928e0542011-01-10 11:17:36 -08006968 // Input channel and input window handle used by the input dispatcher.
6969 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006970 InputChannel mInputChannel;
6971
Mattias Petersson1622eee2010-12-21 10:15:11 +01006972 // Used to improve performance of toString()
6973 String mStringNameCache;
6974 CharSequence mLastTitle;
6975 boolean mWasPaused;
6976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 WindowState(Session s, IWindow c, WindowToken token,
6978 WindowState attachedWindow, WindowManager.LayoutParams a,
6979 int viewVisibility) {
6980 mSession = s;
6981 mClient = c;
6982 mToken = token;
6983 mAttrs.copyFrom(a);
6984 mViewVisibility = viewVisibility;
6985 DeathRecipient deathRecipient = new DeathRecipient();
6986 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006987 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006988 TAG, "Window " + this + " client=" + c.asBinder()
6989 + " token=" + token + " (" + mAttrs.token + ")");
6990 try {
6991 c.asBinder().linkToDeath(deathRecipient, 0);
6992 } catch (RemoteException e) {
6993 mDeathRecipient = null;
6994 mAttachedWindow = null;
6995 mLayoutAttached = false;
6996 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006997 mIsWallpaper = false;
6998 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 mBaseLayer = 0;
7000 mSubLayer = 0;
7001 return;
7002 }
7003 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007005 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7006 mAttrs.type <= LAST_SUB_WINDOW)) {
7007 // The multiplier here is to reserve space for multiple
7008 // windows in the same type layer.
7009 mBaseLayer = mPolicy.windowTypeToLayerLw(
7010 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7011 + TYPE_LAYER_OFFSET;
7012 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7013 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007014 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007015 mAttachedWindow.mChildWindows.add(this);
7016 mLayoutAttached = mAttrs.type !=
7017 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7018 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7019 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007020 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7021 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 } else {
7023 // The multiplier here is to reserve space for multiple
7024 // windows in the same type layer.
7025 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7026 * TYPE_LAYER_MULTIPLIER
7027 + TYPE_LAYER_OFFSET;
7028 mSubLayer = 0;
7029 mAttachedWindow = null;
7030 mLayoutAttached = false;
7031 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7032 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007033 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7034 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 }
7036
7037 WindowState appWin = this;
7038 while (appWin.mAttachedWindow != null) {
7039 appWin = mAttachedWindow;
7040 }
7041 WindowToken appToken = appWin.mToken;
7042 while (appToken.appWindowToken == null) {
7043 WindowToken parent = mTokenMap.get(appToken.token);
7044 if (parent == null || appToken == parent) {
7045 break;
7046 }
7047 appToken = parent;
7048 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007049 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007050 mAppToken = appToken.appWindowToken;
7051
7052 mSurface = null;
7053 mRequestedWidth = 0;
7054 mRequestedHeight = 0;
7055 mLastRequestedWidth = 0;
7056 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007057 mXOffset = 0;
7058 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007059 mLayer = 0;
7060 mAnimLayer = 0;
7061 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007062 mInputWindowHandle = new InputWindowHandle(
7063 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007064 }
7065
7066 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007067 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007068 TAG, "Attaching " + this + " token=" + mToken
7069 + ", list=" + mToken.windows);
7070 mSession.windowAddedLocked();
7071 }
7072
7073 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7074 mHaveFrame = true;
7075
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007076 final Rect container = mContainingFrame;
7077 container.set(pf);
7078
7079 final Rect display = mDisplayFrame;
7080 display.set(df);
7081
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007082 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007083 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007084 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7085 display.intersect(mCompatibleScreenFrame);
7086 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007087 }
7088
7089 final int pw = container.right - container.left;
7090 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091
7092 int w,h;
7093 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7094 w = mAttrs.width < 0 ? pw : mAttrs.width;
7095 h = mAttrs.height< 0 ? ph : mAttrs.height;
7096 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007097 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7098 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 }
Romain Guy06882f82009-06-10 13:36:04 -07007100
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007101 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007102 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7103 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007104 mParentFrame.set(pf);
7105 mContentChanged = true;
7106 }
7107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 final Rect content = mContentFrame;
7109 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 final Rect visible = mVisibleFrame;
7112 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007114 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007115 final int fw = frame.width();
7116 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007118 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7119 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7120
7121 Gravity.apply(mAttrs.gravity, w, h, container,
7122 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7123 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7124
7125 //System.out.println("Out: " + mFrame);
7126
7127 // Now make sure the window fits in the overall display.
7128 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 // Make sure the content and visible frames are inside of the
7131 // final window frame.
7132 if (content.left < frame.left) content.left = frame.left;
7133 if (content.top < frame.top) content.top = frame.top;
7134 if (content.right > frame.right) content.right = frame.right;
7135 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7136 if (visible.left < frame.left) visible.left = frame.left;
7137 if (visible.top < frame.top) visible.top = frame.top;
7138 if (visible.right > frame.right) visible.right = frame.right;
7139 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007141 final Rect contentInsets = mContentInsets;
7142 contentInsets.left = content.left-frame.left;
7143 contentInsets.top = content.top-frame.top;
7144 contentInsets.right = frame.right-content.right;
7145 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007147 final Rect visibleInsets = mVisibleInsets;
7148 visibleInsets.left = visible.left-frame.left;
7149 visibleInsets.top = visible.top-frame.top;
7150 visibleInsets.right = frame.right-visible.right;
7151 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007152
Dianne Hackborn284ac932009-08-28 10:34:25 -07007153 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7154 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007155 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007158 if (localLOGV) {
7159 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7160 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007161 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 + mRequestedWidth + ", mRequestedheight="
7163 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7164 + "): frame=" + mFrame.toShortString()
7165 + " ci=" + contentInsets.toShortString()
7166 + " vi=" + visibleInsets.toShortString());
7167 //}
7168 }
7169 }
Romain Guy06882f82009-06-10 13:36:04 -07007170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007171 public Rect getFrameLw() {
7172 return mFrame;
7173 }
7174
7175 public Rect getShownFrameLw() {
7176 return mShownFrame;
7177 }
7178
7179 public Rect getDisplayFrameLw() {
7180 return mDisplayFrame;
7181 }
7182
7183 public Rect getContentFrameLw() {
7184 return mContentFrame;
7185 }
7186
7187 public Rect getVisibleFrameLw() {
7188 return mVisibleFrame;
7189 }
7190
7191 public boolean getGivenInsetsPendingLw() {
7192 return mGivenInsetsPending;
7193 }
7194
7195 public Rect getGivenContentInsetsLw() {
7196 return mGivenContentInsets;
7197 }
Romain Guy06882f82009-06-10 13:36:04 -07007198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 public Rect getGivenVisibleInsetsLw() {
7200 return mGivenVisibleInsets;
7201 }
Romain Guy06882f82009-06-10 13:36:04 -07007202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 public WindowManager.LayoutParams getAttrs() {
7204 return mAttrs;
7205 }
7206
7207 public int getSurfaceLayer() {
7208 return mLayer;
7209 }
Romain Guy06882f82009-06-10 13:36:04 -07007210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007211 public IApplicationToken getAppToken() {
7212 return mAppToken != null ? mAppToken.appToken : null;
7213 }
Jeff Brown349703e2010-06-22 01:27:15 -07007214
7215 public long getInputDispatchingTimeoutNanos() {
7216 return mAppToken != null
7217 ? mAppToken.inputDispatchingTimeoutNanos
7218 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7219 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007220
7221 public boolean hasAppShownWindows() {
7222 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7223 }
7224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007225 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007226 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007227 TAG, "Setting animation in " + this + ": " + anim);
7228 mAnimating = false;
7229 mLocalAnimating = false;
7230 mAnimation = anim;
7231 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7232 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7233 }
7234
7235 public void clearAnimation() {
7236 if (mAnimation != null) {
7237 mAnimating = true;
7238 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007239 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007240 mAnimation = null;
7241 }
7242 }
Romain Guy06882f82009-06-10 13:36:04 -07007243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007244 Surface createSurfaceLocked() {
7245 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007246 mReportDestroySurface = false;
7247 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 mDrawPending = true;
7249 mCommitDrawPending = false;
7250 mReadyToShow = false;
7251 if (mAppToken != null) {
7252 mAppToken.allDrawn = false;
7253 }
7254
7255 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007256
7257 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7258 flags |= Surface.SECURE;
7259 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007260 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 TAG, "Creating surface in session "
7262 + mSession.mSurfaceSession + " window " + this
7263 + " w=" + mFrame.width()
7264 + " h=" + mFrame.height() + " format="
7265 + mAttrs.format + " flags=" + flags);
7266
7267 int w = mFrame.width();
7268 int h = mFrame.height();
7269 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7270 // for a scaled surface, we always want the requested
7271 // size.
7272 w = mRequestedWidth;
7273 h = mRequestedHeight;
7274 }
7275
Romain Guy9825ec62009-10-01 00:58:09 -07007276 // Something is wrong and SurfaceFlinger will not like this,
7277 // try to revert to sane values
7278 if (w <= 0) w = 1;
7279 if (h <= 0) h = 1;
7280
Dianne Hackborn16064f92010-03-25 00:47:24 -07007281 mSurfaceShown = false;
7282 mSurfaceLayer = 0;
7283 mSurfaceAlpha = 1;
7284 mSurfaceX = 0;
7285 mSurfaceY = 0;
7286 mSurfaceW = w;
7287 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007288 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007289 final boolean isHwAccelerated = (mAttrs.flags &
7290 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7291 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7292 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7293 flags |= Surface.OPAQUE;
7294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007296 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007297 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007298 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007299 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007300 + mSurface + " IN SESSION "
7301 + mSession.mSurfaceSession
7302 + ": pid=" + mSession.mPid + " format="
7303 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007304 + Integer.toHexString(flags)
7305 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007306 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007307 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007308 reclaimSomeSurfaceMemoryLocked(this, "create");
7309 return null;
7310 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007311 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007312 return null;
7313 }
Romain Guy06882f82009-06-10 13:36:04 -07007314
Joe Onorato8a9b2202010-02-26 18:56:32 -08007315 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 TAG, "Got surface: " + mSurface
7317 + ", set left=" + mFrame.left + " top=" + mFrame.top
7318 + ", animLayer=" + mAnimLayer);
7319 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007320 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7321 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007322 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7323 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007324 }
7325 Surface.openTransaction();
7326 try {
7327 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007328 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007329 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007330 mSurface.setPosition(mSurfaceX, mSurfaceY);
7331 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007333 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 mSurface.hide();
7335 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007336 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007337 mSurface.setFlags(Surface.SURFACE_DITHER,
7338 Surface.SURFACE_DITHER);
7339 }
7340 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007341 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7343 }
7344 mLastHidden = true;
7345 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007347 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007348 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007349 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 TAG, "Created surface " + this);
7351 }
7352 return mSurface;
7353 }
Romain Guy06882f82009-06-10 13:36:04 -07007354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007355 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007356 if (mAppToken != null && this == mAppToken.startingWindow) {
7357 mAppToken.startingDisplayed = false;
7358 }
Romain Guy06882f82009-06-10 13:36:04 -07007359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007360 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007361 mDrawPending = false;
7362 mCommitDrawPending = false;
7363 mReadyToShow = false;
7364
7365 int i = mChildWindows.size();
7366 while (i > 0) {
7367 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007368 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007369 c.mAttachedHidden = true;
7370 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007371
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007372 if (mReportDestroySurface) {
7373 mReportDestroySurface = false;
7374 mSurfacePendingDestroy = true;
7375 try {
7376 mClient.dispatchGetNewSurface();
7377 // We'll really destroy on the next time around.
7378 return;
7379 } catch (RemoteException e) {
7380 }
7381 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007384 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007385 RuntimeException e = null;
7386 if (!HIDE_STACK_CRAWLS) {
7387 e = new RuntimeException();
7388 e.fillInStackTrace();
7389 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007390 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007391 + mSurface + ", session " + mSession, e);
7392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007393 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007394 RuntimeException e = null;
7395 if (!HIDE_STACK_CRAWLS) {
7396 e = new RuntimeException();
7397 e.fillInStackTrace();
7398 }
7399 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007400 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007401 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007403 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 + " surface " + mSurface + " session " + mSession
7405 + ": " + e.toString());
7406 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007407
Dianne Hackborn16064f92010-03-25 00:47:24 -07007408 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 }
7411 }
7412
7413 boolean finishDrawingLocked() {
7414 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007415 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007416 TAG, "finishDrawingLocked: " + mSurface);
7417 mCommitDrawPending = true;
7418 mDrawPending = false;
7419 return true;
7420 }
7421 return false;
7422 }
7423
7424 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007425 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007426 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007428 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 }
7430 mCommitDrawPending = false;
7431 mReadyToShow = true;
7432 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7433 final AppWindowToken atoken = mAppToken;
7434 if (atoken == null || atoken.allDrawn || starting) {
7435 performShowLocked();
7436 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007437 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 }
7439
7440 // This must be called while inside a transaction.
7441 boolean performShowLocked() {
7442 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007443 RuntimeException e = null;
7444 if (!HIDE_STACK_CRAWLS) {
7445 e = new RuntimeException();
7446 e.fillInStackTrace();
7447 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007448 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7450 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7451 }
7452 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007453 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7454 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007455 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 + " during animation: policyVis=" + mPolicyVisibility
7457 + " attHidden=" + mAttachedHidden
7458 + " tok.hiddenRequested="
7459 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007460 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 + (mAppToken != null ? mAppToken.hidden : false)
7462 + " animating=" + mAnimating
7463 + " tok animating="
7464 + (mAppToken != null ? mAppToken.animating : false));
7465 if (!showSurfaceRobustlyLocked(this)) {
7466 return false;
7467 }
7468 mLastAlpha = -1;
7469 mHasDrawn = true;
7470 mLastHidden = false;
7471 mReadyToShow = false;
7472 enableScreenIfNeededLocked();
7473
7474 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 int i = mChildWindows.size();
7477 while (i > 0) {
7478 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007479 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007480 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007482 if (c.mSurface != null) {
7483 c.performShowLocked();
7484 // It hadn't been shown, which means layout not
7485 // performed on it, so now we want to make sure to
7486 // do a layout. If called from within the transaction
7487 // loop, this will cause it to restart with a new
7488 // layout.
7489 mLayoutNeeded = true;
7490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 }
7492 }
Romain Guy06882f82009-06-10 13:36:04 -07007493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 if (mAttrs.type != TYPE_APPLICATION_STARTING
7495 && mAppToken != null) {
7496 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007497
Dianne Hackborn248b1882009-09-16 16:46:44 -07007498 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007499 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007500 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007502 // If this initial window is animating, stop it -- we
7503 // will do an animation to reveal it from behind the
7504 // starting window, so there is no need for it to also
7505 // be doing its own stuff.
7506 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007507 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007508 mAnimation = null;
7509 // Make sure we clean up the animation.
7510 mAnimating = true;
7511 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 mFinishedStarting.add(mAppToken);
7513 mH.sendEmptyMessage(H.FINISHED_STARTING);
7514 }
7515 mAppToken.updateReportedVisibilityLocked();
7516 }
7517 }
7518 return true;
7519 }
Romain Guy06882f82009-06-10 13:36:04 -07007520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007521 // This must be called while inside a transaction. Returns true if
7522 // there is more animation to run.
7523 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007524 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7528 mHasTransformation = true;
7529 mHasLocalTransformation = true;
7530 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007531 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 TAG, "Starting animation in " + this +
7533 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7534 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7535 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7536 mAnimation.setStartTime(currentTime);
7537 mLocalAnimating = true;
7538 mAnimating = true;
7539 }
7540 mTransformation.clear();
7541 final boolean more = mAnimation.getTransformation(
7542 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007543 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007544 TAG, "Stepped animation in " + this +
7545 ": more=" + more + ", xform=" + mTransformation);
7546 if (more) {
7547 // we're not done!
7548 return true;
7549 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007550 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007551 TAG, "Finished animation in " + this +
7552 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007553
7554 if (mAnimation != null) {
7555 mAnimation.cancel();
7556 mAnimation = null;
7557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 //WindowManagerService.this.dump();
7559 }
7560 mHasLocalTransformation = false;
7561 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007562 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 // When our app token is animating, we kind-of pretend like
7564 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7565 // part of this check means that we will only do this if
7566 // our window is not currently exiting, or it is not
7567 // locally animating itself. The idea being that one that
7568 // is exiting and doing a local animation should be removed
7569 // once that animation is done.
7570 mAnimating = true;
7571 mHasTransformation = true;
7572 mTransformation.clear();
7573 return false;
7574 } else if (mHasTransformation) {
7575 // Little trick to get through the path below to act like
7576 // we have finished an animation.
7577 mAnimating = true;
7578 } else if (isAnimating()) {
7579 mAnimating = true;
7580 }
7581 } else if (mAnimation != null) {
7582 // If the display is frozen, and there is a pending animation,
7583 // clear it and make sure we run the cleanup code.
7584 mAnimating = true;
7585 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007586 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 mAnimation = null;
7588 }
Romain Guy06882f82009-06-10 13:36:04 -07007589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007590 if (!mAnimating && !mLocalAnimating) {
7591 return false;
7592 }
7593
Joe Onorato8a9b2202010-02-26 18:56:32 -08007594 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007595 TAG, "Animation done in " + this + ": exiting=" + mExiting
7596 + ", reportedVisible="
7597 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 mAnimating = false;
7600 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007601 if (mAnimation != null) {
7602 mAnimation.cancel();
7603 mAnimation = null;
7604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 mAnimLayer = mLayer;
7606 if (mIsImWindow) {
7607 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007608 } else if (mIsWallpaper) {
7609 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007610 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007611 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 + " anim layer: " + mAnimLayer);
7613 mHasTransformation = false;
7614 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007615 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7616 if (DEBUG_VISIBILITY) {
7617 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7618 + mPolicyVisibilityAfterAnim);
7619 }
7620 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7621 if (!mPolicyVisibility) {
7622 if (mCurrentFocus == this) {
7623 mFocusMayChange = true;
7624 }
7625 // Window is no longer visible -- make sure if we were waiting
7626 // for it to be displayed before enabling the display, that
7627 // we allow the display to be enabled now.
7628 enableScreenIfNeededLocked();
7629 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007630 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007631 mTransformation.clear();
7632 if (mHasDrawn
7633 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7634 && mAppToken != null
7635 && mAppToken.firstWindowDrawn
7636 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007637 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 + mToken + ": first real window done animating");
7639 mFinishedStarting.add(mAppToken);
7640 mH.sendEmptyMessage(H.FINISHED_STARTING);
7641 }
Romain Guy06882f82009-06-10 13:36:04 -07007642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 finishExit();
7644
7645 if (mAppToken != null) {
7646 mAppToken.updateReportedVisibilityLocked();
7647 }
7648
7649 return false;
7650 }
7651
7652 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007653 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007654 TAG, "finishExit in " + this
7655 + ": exiting=" + mExiting
7656 + " remove=" + mRemoveOnExit
7657 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 final int N = mChildWindows.size();
7660 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007661 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007662 }
Romain Guy06882f82009-06-10 13:36:04 -07007663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007664 if (!mExiting) {
7665 return;
7666 }
Romain Guy06882f82009-06-10 13:36:04 -07007667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007668 if (isWindowAnimating()) {
7669 return;
7670 }
7671
Joe Onorato8a9b2202010-02-26 18:56:32 -08007672 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007673 TAG, "Exit animation finished in " + this
7674 + ": remove=" + mRemoveOnExit);
7675 if (mSurface != null) {
7676 mDestroySurface.add(this);
7677 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007678 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007679 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007680 try {
7681 mSurface.hide();
7682 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007683 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007684 }
7685 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 }
7687 mExiting = false;
7688 if (mRemoveOnExit) {
7689 mPendingRemove.add(this);
7690 mRemoveOnExit = false;
7691 }
7692 }
Romain Guy06882f82009-06-10 13:36:04 -07007693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7695 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7696 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7697 if (dtdx < -.000001f || dtdx > .000001f) return false;
7698 if (dsdy < -.000001f || dsdy > .000001f) return false;
7699 return true;
7700 }
Romain Guy06882f82009-06-10 13:36:04 -07007701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 void computeShownFrameLocked() {
7703 final boolean selfTransformation = mHasLocalTransformation;
7704 Transformation attachedTransformation =
7705 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7706 ? mAttachedWindow.mTransformation : null;
7707 Transformation appTransformation =
7708 (mAppToken != null && mAppToken.hasTransformation)
7709 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007710
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007711 // Wallpapers are animated based on the "real" window they
7712 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007713 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007714 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007715 if (mWallpaperTarget.mHasLocalTransformation &&
7716 mWallpaperTarget.mAnimation != null &&
7717 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007718 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007719 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007720 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007721 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007722 }
7723 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007724 mWallpaperTarget.mAppToken.hasTransformation &&
7725 mWallpaperTarget.mAppToken.animation != null &&
7726 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007727 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007728 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007729 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007730 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007731 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007732 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007733
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007734 final boolean screenAnimation = mScreenRotationAnimation != null
7735 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007736 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007737 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007738 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007739 final Rect frame = mFrame;
7740 final float tmpFloats[] = mTmpFloats;
7741 final Matrix tmpMatrix = mTmpMatrix;
7742
7743 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007744 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007745 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007746 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007747 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007748 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007749 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007750 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007751 }
7752 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007753 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007754 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007755 if (screenAnimation) {
7756 tmpMatrix.postConcat(
7757 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7758 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759
7760 // "convert" it into SurfaceFlinger's format
7761 // (a 2x2 matrix + an offset)
7762 // Here we must not transform the position of the surface
7763 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007764 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007765
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007766 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 tmpMatrix.getValues(tmpFloats);
7768 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007769 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7770 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007771 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007772 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7773 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 int w = frame.width();
7775 int h = frame.height();
7776 mShownFrame.set(x, y, x+w, y+h);
7777
7778 // Now set the alpha... but because our current hardware
7779 // can't do alpha transformation on a non-opaque surface,
7780 // turn it off if we are running an animation that is also
7781 // transforming since it is more important to have that
7782 // animation be smooth.
7783 mShownAlpha = mAlpha;
7784 if (!mLimitedAlphaCompositing
7785 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7786 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7787 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007788 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007789 if (selfTransformation) {
7790 mShownAlpha *= mTransformation.getAlpha();
7791 }
7792 if (attachedTransformation != null) {
7793 mShownAlpha *= attachedTransformation.getAlpha();
7794 }
7795 if (appTransformation != null) {
7796 mShownAlpha *= appTransformation.getAlpha();
7797 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007798 if (screenAnimation) {
7799 mShownAlpha *=
7800 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7801 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007802 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007803 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007804 }
Romain Guy06882f82009-06-10 13:36:04 -07007805
Joe Onorato8a9b2202010-02-26 18:56:32 -08007806 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 TAG, "Continuing animation in " + this +
7808 ": " + mShownFrame +
7809 ", alpha=" + mTransformation.getAlpha());
7810 return;
7811 }
Romain Guy06882f82009-06-10 13:36:04 -07007812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007813 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007814 if (mXOffset != 0 || mYOffset != 0) {
7815 mShownFrame.offset(mXOffset, mYOffset);
7816 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007817 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007818 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007819 mDsDx = 1;
7820 mDtDx = 0;
7821 mDsDy = 0;
7822 mDtDy = 1;
7823 }
Romain Guy06882f82009-06-10 13:36:04 -07007824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007825 /**
7826 * Is this window visible? It is not visible if there is no
7827 * surface, or we are in the process of running an exit animation
7828 * that will remove the surface, or its app token has been hidden.
7829 */
7830 public boolean isVisibleLw() {
7831 final AppWindowToken atoken = mAppToken;
7832 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7833 && (atoken == null || !atoken.hiddenRequested)
7834 && !mExiting && !mDestroying;
7835 }
7836
7837 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007838 * Like {@link #isVisibleLw}, but also counts a window that is currently
7839 * "hidden" behind the keyguard as visible. This allows us to apply
7840 * things like window flags that impact the keyguard.
7841 * XXX I am starting to think we need to have ANOTHER visibility flag
7842 * for this "hidden behind keyguard" state rather than overloading
7843 * mPolicyVisibility. Ungh.
7844 */
7845 public boolean isVisibleOrBehindKeyguardLw() {
7846 final AppWindowToken atoken = mAppToken;
7847 return mSurface != null && !mAttachedHidden
7848 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007849 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007850 && !mExiting && !mDestroying;
7851 }
7852
7853 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007854 * Is this window visible, ignoring its app token? It is not visible
7855 * if there is no surface, or we are in the process of running an exit animation
7856 * that will remove the surface.
7857 */
7858 public boolean isWinVisibleLw() {
7859 final AppWindowToken atoken = mAppToken;
7860 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7861 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7862 && !mExiting && !mDestroying;
7863 }
7864
7865 /**
7866 * The same as isVisible(), but follows the current hidden state of
7867 * the associated app token, not the pending requested hidden state.
7868 */
7869 boolean isVisibleNow() {
7870 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007871 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007872 }
7873
7874 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007875 * Can this window possibly be a drag/drop target? The test here is
7876 * a combination of the above "visible now" with the check that the
7877 * Input Manager uses when discarding windows from input consideration.
7878 */
7879 boolean isPotentialDragTarget() {
7880 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7881 }
7882
7883 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007884 * Same as isVisible(), but we also count it as visible between the
7885 * call to IWindowSession.add() and the first relayout().
7886 */
7887 boolean isVisibleOrAdding() {
7888 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007889 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007890 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7891 && mPolicyVisibility && !mAttachedHidden
7892 && (atoken == null || !atoken.hiddenRequested)
7893 && !mExiting && !mDestroying;
7894 }
7895
7896 /**
7897 * Is this window currently on-screen? It is on-screen either if it
7898 * is visible or it is currently running an animation before no longer
7899 * being visible.
7900 */
7901 boolean isOnScreen() {
7902 final AppWindowToken atoken = mAppToken;
7903 if (atoken != null) {
7904 return mSurface != null && mPolicyVisibility && !mDestroying
7905 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007906 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007907 } else {
7908 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007909 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007910 }
7911 }
Romain Guy06882f82009-06-10 13:36:04 -07007912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 /**
7914 * Like isOnScreen(), but we don't return true if the window is part
7915 * of a transition that has not yet been started.
7916 */
7917 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007918 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007919 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007920 return false;
7921 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007922 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007923 final boolean animating = atoken != null
7924 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007926 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7927 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007928 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 }
7930
7931 /** Is the window or its container currently animating? */
7932 boolean isAnimating() {
7933 final WindowState attached = mAttachedWindow;
7934 final AppWindowToken atoken = mAppToken;
7935 return mAnimation != null
7936 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007937 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007938 (atoken.animation != null
7939 || atoken.inPendingTransaction));
7940 }
7941
7942 /** Is this window currently animating? */
7943 boolean isWindowAnimating() {
7944 return mAnimation != null;
7945 }
7946
7947 /**
7948 * Like isOnScreen, but returns false if the surface hasn't yet
7949 * been drawn.
7950 */
7951 public boolean isDisplayedLw() {
7952 final AppWindowToken atoken = mAppToken;
7953 return mSurface != null && mPolicyVisibility && !mDestroying
7954 && !mDrawPending && !mCommitDrawPending
7955 && ((!mAttachedHidden &&
7956 (atoken == null || !atoken.hiddenRequested))
7957 || mAnimating);
7958 }
7959
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007960 /**
7961 * Returns true if the window has a surface that it has drawn a
7962 * complete UI in to.
7963 */
7964 public boolean isDrawnLw() {
7965 final AppWindowToken atoken = mAppToken;
7966 return mSurface != null && !mDestroying
7967 && !mDrawPending && !mCommitDrawPending;
7968 }
7969
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007970 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007971 * Return true if the window is opaque and fully drawn. This indicates
7972 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007973 */
7974 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007975 return (mAttrs.format == PixelFormat.OPAQUE
7976 || mAttrs.type == TYPE_WALLPAPER)
7977 && mSurface != null && mAnimation == null
7978 && (mAppToken == null || mAppToken.animation == null)
7979 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007980 }
7981
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007982 /**
7983 * Return whether this window is wanting to have a translation
7984 * animation applied to it for an in-progress move. (Only makes
7985 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7986 */
7987 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007988 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007989 && (mFrame.top != mLastFrame.top
7990 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007991 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007992 && mPolicy.isScreenOn();
7993 }
7994
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007995 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7996 return
7997 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007998 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7999 // only if it's visible
8000 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008001 // and only if the application fills the compatible screen
8002 mFrame.left <= mCompatibleScreenFrame.left &&
8003 mFrame.top <= mCompatibleScreenFrame.top &&
8004 mFrame.right >= mCompatibleScreenFrame.right &&
8005 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008006 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008007 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008008 }
8009
8010 boolean isFullscreen(int screenWidth, int screenHeight) {
8011 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008012 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008013 }
8014
8015 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008016 disposeInputChannel();
8017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008018 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008019 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008020 mAttachedWindow.mChildWindows.remove(this);
8021 }
8022 destroySurfaceLocked();
8023 mSession.windowRemovedLocked();
8024 try {
8025 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8026 } catch (RuntimeException e) {
8027 // Ignore if it has already been removed (usually because
8028 // we are doing this as part of processing a death note.)
8029 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008030 }
8031
8032 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008033 if (mInputChannel != null) {
8034 mInputManager.unregisterInputChannel(mInputChannel);
8035
8036 mInputChannel.dispose();
8037 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008038 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008039 }
8040
8041 private class DeathRecipient implements IBinder.DeathRecipient {
8042 public void binderDied() {
8043 try {
8044 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008045 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008046 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 if (win != null) {
8048 removeWindowLocked(mSession, win);
8049 }
8050 }
8051 } catch (IllegalArgumentException ex) {
8052 // This will happen if the window has already been
8053 // removed.
8054 }
8055 }
8056 }
8057
8058 /** Returns true if this window desires key events. */
8059 public final boolean canReceiveKeys() {
8060 return isVisibleOrAdding()
8061 && (mViewVisibility == View.VISIBLE)
8062 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8063 }
8064
8065 public boolean hasDrawnLw() {
8066 return mHasDrawn;
8067 }
8068
8069 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008070 return showLw(doAnimation, true);
8071 }
8072
8073 boolean showLw(boolean doAnimation, boolean requestAnim) {
8074 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8075 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008077 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008078 if (doAnimation) {
8079 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8080 + mPolicyVisibility + " mAnimation=" + mAnimation);
8081 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8082 doAnimation = false;
8083 } else if (mPolicyVisibility && mAnimation == null) {
8084 // Check for the case where we are currently visible and
8085 // not animating; we do not want to do animation at such a
8086 // point to become visible when we already are.
8087 doAnimation = false;
8088 }
8089 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008090 mPolicyVisibility = true;
8091 mPolicyVisibilityAfterAnim = true;
8092 if (doAnimation) {
8093 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8094 }
8095 if (requestAnim) {
8096 requestAnimationLocked(0);
8097 }
8098 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 }
8100
8101 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008102 return hideLw(doAnimation, true);
8103 }
8104
8105 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008106 if (doAnimation) {
8107 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8108 doAnimation = false;
8109 }
8110 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8112 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008113 if (!current) {
8114 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008115 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008116 if (doAnimation) {
8117 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8118 if (mAnimation == null) {
8119 doAnimation = false;
8120 }
8121 }
8122 if (doAnimation) {
8123 mPolicyVisibilityAfterAnim = false;
8124 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008125 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008126 mPolicyVisibilityAfterAnim = false;
8127 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008128 // Window is no longer visible -- make sure if we were waiting
8129 // for it to be displayed before enabling the display, that
8130 // we allow the display to be enabled now.
8131 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008132 if (mCurrentFocus == this) {
8133 mFocusMayChange = true;
8134 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008135 }
8136 if (requestAnim) {
8137 requestAnimationLocked(0);
8138 }
8139 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 }
8141
8142 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008143 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8144 pw.print(" mClient="); pw.println(mClient.asBinder());
8145 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8146 if (mAttachedWindow != null || mLayoutAttached) {
8147 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8148 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8149 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008150 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8151 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8152 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008153 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8154 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008155 }
8156 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8157 pw.print(" mSubLayer="); pw.print(mSubLayer);
8158 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8159 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8160 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8161 pw.print("="); pw.print(mAnimLayer);
8162 pw.print(" mLastLayer="); pw.println(mLastLayer);
8163 if (mSurface != null) {
8164 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008165 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8166 pw.print(" layer="); pw.print(mSurfaceLayer);
8167 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8168 pw.print(" rect=("); pw.print(mSurfaceX);
8169 pw.print(","); pw.print(mSurfaceY);
8170 pw.print(") "); pw.print(mSurfaceW);
8171 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008172 }
8173 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8174 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8175 if (mAppToken != null) {
8176 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8177 }
8178 if (mTargetAppToken != null) {
8179 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8180 }
8181 pw.print(prefix); pw.print("mViewVisibility=0x");
8182 pw.print(Integer.toHexString(mViewVisibility));
8183 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008184 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8185 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008186 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8187 pw.print(prefix); pw.print("mPolicyVisibility=");
8188 pw.print(mPolicyVisibility);
8189 pw.print(" mPolicyVisibilityAfterAnim=");
8190 pw.print(mPolicyVisibilityAfterAnim);
8191 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8192 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008193 if (!mRelayoutCalled) {
8194 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8195 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008196 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008197 pw.print(" h="); pw.print(mRequestedHeight);
8198 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008199 if (mXOffset != 0 || mYOffset != 0) {
8200 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8201 pw.print(" y="); pw.println(mYOffset);
8202 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008203 pw.print(prefix); pw.print("mGivenContentInsets=");
8204 mGivenContentInsets.printShortString(pw);
8205 pw.print(" mGivenVisibleInsets=");
8206 mGivenVisibleInsets.printShortString(pw);
8207 pw.println();
8208 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8209 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8210 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8211 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008212 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008213 pw.print(prefix); pw.print("mShownFrame=");
8214 mShownFrame.printShortString(pw);
8215 pw.print(" last="); mLastShownFrame.printShortString(pw);
8216 pw.println();
8217 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8218 pw.print(" last="); mLastFrame.printShortString(pw);
8219 pw.println();
8220 pw.print(prefix); pw.print("mContainingFrame=");
8221 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008222 pw.print(" mParentFrame=");
8223 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008224 pw.print(" mDisplayFrame=");
8225 mDisplayFrame.printShortString(pw);
8226 pw.println();
8227 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8228 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8229 pw.println();
8230 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8231 pw.print(" last="); mLastContentInsets.printShortString(pw);
8232 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8233 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8234 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008235 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8236 || mAnimation != null) {
8237 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8238 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8239 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8240 pw.print(" mAnimation="); pw.println(mAnimation);
8241 }
8242 if (mHasTransformation || mHasLocalTransformation) {
8243 pw.print(prefix); pw.print("XForm: has=");
8244 pw.print(mHasTransformation);
8245 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8246 pw.print(" "); mTransformation.printShortString(pw);
8247 pw.println();
8248 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008249 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8250 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8251 pw.print(" mAlpha="); pw.print(mAlpha);
8252 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8253 }
8254 if (mHaveMatrix) {
8255 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8256 pw.print(" mDtDx="); pw.print(mDtDx);
8257 pw.print(" mDsDy="); pw.print(mDsDy);
8258 pw.print(" mDtDy="); pw.println(mDtDy);
8259 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008260 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8261 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8262 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8263 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8264 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8265 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8266 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8267 pw.print(" mDestroying="); pw.print(mDestroying);
8268 pw.print(" mRemoved="); pw.println(mRemoved);
8269 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008270 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008271 pw.print(prefix); pw.print("mOrientationChanging=");
8272 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008273 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8274 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008275 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008276 if (mHScale != 1 || mVScale != 1) {
8277 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8278 pw.print(" mVScale="); pw.println(mVScale);
8279 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008280 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008281 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8282 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8283 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008284 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8285 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8286 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8287 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008288 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008289
8290 String makeInputChannelName() {
8291 return Integer.toHexString(System.identityHashCode(this))
8292 + " " + mAttrs.getTitle();
8293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008294
8295 @Override
8296 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008297 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8298 || mWasPaused != mToken.paused) {
8299 mLastTitle = mAttrs.getTitle();
8300 mWasPaused = mToken.paused;
8301 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8302 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8303 }
8304 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008305 }
8306 }
Romain Guy06882f82009-06-10 13:36:04 -07008307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008308 // -------------------------------------------------------------
8309 // Window Token State
8310 // -------------------------------------------------------------
8311
8312 class WindowToken {
8313 // The actual token.
8314 final IBinder token;
8315
8316 // The type of window this token is for, as per WindowManager.LayoutParams.
8317 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008319 // Set if this token was explicitly added by a client, so should
8320 // not be removed when all windows are removed.
8321 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008322
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008323 // For printing.
8324 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008326 // If this is an AppWindowToken, this is non-null.
8327 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008329 // All of the windows associated with this token.
8330 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8331
8332 // Is key dispatching paused for this token?
8333 boolean paused = false;
8334
8335 // Should this token's windows be hidden?
8336 boolean hidden;
8337
8338 // Temporary for finding which tokens no longer have visible windows.
8339 boolean hasVisible;
8340
Dianne Hackborna8f60182009-09-01 19:01:50 -07008341 // Set to true when this token is in a pending transaction where it
8342 // will be shown.
8343 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008344
Dianne Hackborna8f60182009-09-01 19:01:50 -07008345 // Set to true when this token is in a pending transaction where it
8346 // will be hidden.
8347 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008348
Dianne Hackborna8f60182009-09-01 19:01:50 -07008349 // Set to true when this token is in a pending transaction where its
8350 // windows will be put to the bottom of the list.
8351 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008352
Dianne Hackborna8f60182009-09-01 19:01:50 -07008353 // Set to true when this token is in a pending transaction where its
8354 // windows will be put to the top of the list.
8355 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008357 WindowToken(IBinder _token, int type, boolean _explicit) {
8358 token = _token;
8359 windowType = type;
8360 explicit = _explicit;
8361 }
8362
8363 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008364 pw.print(prefix); pw.print("token="); pw.println(token);
8365 pw.print(prefix); pw.print("windows="); pw.println(windows);
8366 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8367 pw.print(" hidden="); pw.print(hidden);
8368 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008369 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8370 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8371 pw.print(" waitingToHide="); pw.print(waitingToHide);
8372 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8373 pw.print(" sendingToTop="); pw.println(sendingToTop);
8374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008375 }
8376
8377 @Override
8378 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008379 if (stringName == null) {
8380 StringBuilder sb = new StringBuilder();
8381 sb.append("WindowToken{");
8382 sb.append(Integer.toHexString(System.identityHashCode(this)));
8383 sb.append(" token="); sb.append(token); sb.append('}');
8384 stringName = sb.toString();
8385 }
8386 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008387 }
8388 };
8389
8390 class AppWindowToken extends WindowToken {
8391 // Non-null only for application tokens.
8392 final IApplicationToken appToken;
8393
8394 // All of the windows and child windows that are included in this
8395 // application token. Note this list is NOT sorted!
8396 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8397
8398 int groupId = -1;
8399 boolean appFullscreen;
8400 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008401
8402 // The input dispatching timeout for this application token in nanoseconds.
8403 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008405 // These are used for determining when all windows associated with
8406 // an activity have been drawn, so they can be made visible together
8407 // at the same time.
8408 int lastTransactionSequence = mTransactionSequence-1;
8409 int numInterestingWindows;
8410 int numDrawnWindows;
8411 boolean inPendingTransaction;
8412 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 // Is this token going to be hidden in a little while? If so, it
8415 // won't be taken into account for setting the screen orientation.
8416 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418 // Is this window's surface needed? This is almost like hidden, except
8419 // it will sometimes be true a little earlier: when the token has
8420 // been shown, but is still waiting for its app transition to execute
8421 // before making its windows shown.
8422 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008424 // Have we told the window clients to hide themselves?
8425 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 // Last visibility state we reported to the app token.
8428 boolean reportedVisible;
8429
8430 // Set to true when the token has been removed from the window mgr.
8431 boolean removed;
8432
8433 // Have we been asked to have this token keep the screen frozen?
8434 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 boolean animating;
8437 Animation animation;
8438 boolean hasTransformation;
8439 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 // Offset to the window of all layers in the token, for use by
8442 // AppWindowToken animations.
8443 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008445 // Information about an application starting window if displayed.
8446 StartingData startingData;
8447 WindowState startingWindow;
8448 View startingView;
8449 boolean startingDisplayed;
8450 boolean startingMoved;
8451 boolean firstWindowDrawn;
8452
Jeff Brown928e0542011-01-10 11:17:36 -08008453 // Input application handle used by the input dispatcher.
8454 InputApplicationHandle mInputApplicationHandle;
8455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008456 AppWindowToken(IApplicationToken _token) {
8457 super(_token.asBinder(),
8458 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8459 appWindowToken = this;
8460 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008461 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 }
Romain Guy06882f82009-06-10 13:36:04 -07008463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008464 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008465 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 TAG, "Setting animation in " + this + ": " + anim);
8467 animation = anim;
8468 animating = false;
8469 anim.restrictDuration(MAX_ANIMATION_DURATION);
8470 anim.scaleCurrentDuration(mTransitionAnimationScale);
8471 int zorder = anim.getZAdjustment();
8472 int adj = 0;
8473 if (zorder == Animation.ZORDER_TOP) {
8474 adj = TYPE_LAYER_OFFSET;
8475 } else if (zorder == Animation.ZORDER_BOTTOM) {
8476 adj = -TYPE_LAYER_OFFSET;
8477 }
Romain Guy06882f82009-06-10 13:36:04 -07008478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 if (animLayerAdjustment != adj) {
8480 animLayerAdjustment = adj;
8481 updateLayers();
8482 }
8483 }
Romain Guy06882f82009-06-10 13:36:04 -07008484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008485 public void setDummyAnimation() {
8486 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008487 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008488 TAG, "Setting dummy animation in " + this);
8489 animation = sDummyAnimation;
8490 }
8491 }
8492
8493 public void clearAnimation() {
8494 if (animation != null) {
8495 animation = null;
8496 animating = true;
8497 }
8498 }
Romain Guy06882f82009-06-10 13:36:04 -07008499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008500 void updateLayers() {
8501 final int N = allAppWindows.size();
8502 final int adj = animLayerAdjustment;
8503 for (int i=0; i<N; i++) {
8504 WindowState w = allAppWindows.get(i);
8505 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008506 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008507 + w.mAnimLayer);
8508 if (w == mInputMethodTarget) {
8509 setInputMethodAnimLayerAdjustment(adj);
8510 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008511 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008512 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008514 }
8515 }
Romain Guy06882f82009-06-10 13:36:04 -07008516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008517 void sendAppVisibilityToClients() {
8518 final int N = allAppWindows.size();
8519 for (int i=0; i<N; i++) {
8520 WindowState win = allAppWindows.get(i);
8521 if (win == startingWindow && clientHidden) {
8522 // Don't hide the starting window.
8523 continue;
8524 }
8525 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008526 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527 "Setting visibility of " + win + ": " + (!clientHidden));
8528 win.mClient.dispatchAppVisibility(!clientHidden);
8529 } catch (RemoteException e) {
8530 }
8531 }
8532 }
Romain Guy06882f82009-06-10 13:36:04 -07008533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 void showAllWindowsLocked() {
8535 final int NW = allAppWindows.size();
8536 for (int i=0; i<NW; i++) {
8537 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008538 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 "performing show on: " + w);
8540 w.performShowLocked();
8541 }
8542 }
Romain Guy06882f82009-06-10 13:36:04 -07008543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 // This must be called while inside a transaction.
8545 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008546 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 if (animation == sDummyAnimation) {
8550 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008551 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 // when it is really time to animate, this will be set to
8553 // a real animation and the next call will execute normally.
8554 return false;
8555 }
Romain Guy06882f82009-06-10 13:36:04 -07008556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008557 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8558 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008559 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008560 TAG, "Starting animation in " + this +
8561 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8562 + " scale=" + mTransitionAnimationScale
8563 + " allDrawn=" + allDrawn + " animating=" + animating);
8564 animation.initialize(dw, dh, dw, dh);
8565 animation.setStartTime(currentTime);
8566 animating = true;
8567 }
8568 transformation.clear();
8569 final boolean more = animation.getTransformation(
8570 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008571 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008572 TAG, "Stepped animation in " + this +
8573 ": more=" + more + ", xform=" + transformation);
8574 if (more) {
8575 // we're done!
8576 hasTransformation = true;
8577 return true;
8578 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008579 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008580 TAG, "Finished animation in " + this +
8581 " @ " + currentTime);
8582 animation = null;
8583 }
8584 } else if (animation != null) {
8585 // If the display is frozen, and there is a pending animation,
8586 // clear it and make sure we run the cleanup code.
8587 animating = true;
8588 animation = null;
8589 }
8590
8591 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008593 if (!animating) {
8594 return false;
8595 }
8596
8597 clearAnimation();
8598 animating = false;
8599 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8600 moveInputMethodWindowsIfNeededLocked(true);
8601 }
Romain Guy06882f82009-06-10 13:36:04 -07008602
Joe Onorato8a9b2202010-02-26 18:56:32 -08008603 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008604 TAG, "Animation done in " + this
8605 + ": reportedVisible=" + reportedVisible);
8606
8607 transformation.clear();
8608 if (animLayerAdjustment != 0) {
8609 animLayerAdjustment = 0;
8610 updateLayers();
8611 }
Romain Guy06882f82009-06-10 13:36:04 -07008612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008613 final int N = windows.size();
8614 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008615 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008616 }
8617 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 return false;
8620 }
8621
8622 void updateReportedVisibilityLocked() {
8623 if (appToken == null) {
8624 return;
8625 }
Romain Guy06882f82009-06-10 13:36:04 -07008626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 int numInteresting = 0;
8628 int numVisible = 0;
8629 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008630
Joe Onorato8a9b2202010-02-26 18:56:32 -08008631 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008632 final int N = allAppWindows.size();
8633 for (int i=0; i<N; i++) {
8634 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008635 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008636 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008637 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8638 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008639 continue;
8640 }
8641 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008642 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008643 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008645 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008646 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008647 + " pv=" + win.mPolicyVisibility
8648 + " dp=" + win.mDrawPending
8649 + " cdp=" + win.mCommitDrawPending
8650 + " ah=" + win.mAttachedHidden
8651 + " th="
8652 + (win.mAppToken != null
8653 ? win.mAppToken.hiddenRequested : false)
8654 + " a=" + win.mAnimating);
8655 }
8656 }
8657 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008658 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 if (!win.isAnimating()) {
8660 numVisible++;
8661 }
8662 nowGone = false;
8663 } else if (win.isAnimating()) {
8664 nowGone = false;
8665 }
8666 }
Romain Guy06882f82009-06-10 13:36:04 -07008667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008669 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008670 + numInteresting + " visible=" + numVisible);
8671 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008672 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 TAG, "Visibility changed in " + this
8674 + ": vis=" + nowVisible);
8675 reportedVisible = nowVisible;
8676 Message m = mH.obtainMessage(
8677 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8678 nowVisible ? 1 : 0,
8679 nowGone ? 1 : 0,
8680 this);
8681 mH.sendMessage(m);
8682 }
8683 }
Romain Guy06882f82009-06-10 13:36:04 -07008684
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008685 WindowState findMainWindow() {
8686 int j = windows.size();
8687 while (j > 0) {
8688 j--;
8689 WindowState win = windows.get(j);
8690 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8691 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8692 return win;
8693 }
8694 }
8695 return null;
8696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698 void dump(PrintWriter pw, String prefix) {
8699 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008700 if (appToken != null) {
8701 pw.print(prefix); pw.println("app=true");
8702 }
8703 if (allAppWindows.size() > 0) {
8704 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8705 }
8706 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008707 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008708 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8709 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8710 pw.print(" clientHidden="); pw.print(clientHidden);
8711 pw.print(" willBeHidden="); pw.print(willBeHidden);
8712 pw.print(" reportedVisible="); pw.println(reportedVisible);
8713 if (paused || freezingScreen) {
8714 pw.print(prefix); pw.print("paused="); pw.print(paused);
8715 pw.print(" freezingScreen="); pw.println(freezingScreen);
8716 }
8717 if (numInterestingWindows != 0 || numDrawnWindows != 0
8718 || inPendingTransaction || allDrawn) {
8719 pw.print(prefix); pw.print("numInterestingWindows=");
8720 pw.print(numInterestingWindows);
8721 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8722 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8723 pw.print(" allDrawn="); pw.println(allDrawn);
8724 }
8725 if (animating || animation != null) {
8726 pw.print(prefix); pw.print("animating="); pw.print(animating);
8727 pw.print(" animation="); pw.println(animation);
8728 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008729 if (hasTransformation) {
8730 pw.print(prefix); pw.print("XForm: ");
8731 transformation.printShortString(pw);
8732 pw.println();
8733 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008734 if (animLayerAdjustment != 0) {
8735 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8736 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008737 if (startingData != null || removed || firstWindowDrawn) {
8738 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8739 pw.print(" removed="); pw.print(removed);
8740 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8741 }
8742 if (startingWindow != null || startingView != null
8743 || startingDisplayed || startingMoved) {
8744 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8745 pw.print(" startingView="); pw.print(startingView);
8746 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8747 pw.print(" startingMoved"); pw.println(startingMoved);
8748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008749 }
8750
8751 @Override
8752 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008753 if (stringName == null) {
8754 StringBuilder sb = new StringBuilder();
8755 sb.append("AppWindowToken{");
8756 sb.append(Integer.toHexString(System.identityHashCode(this)));
8757 sb.append(" token="); sb.append(token); sb.append('}');
8758 stringName = sb.toString();
8759 }
8760 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008761 }
8762 }
Romain Guy06882f82009-06-10 13:36:04 -07008763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008764 // -------------------------------------------------------------
8765 // DummyAnimation
8766 // -------------------------------------------------------------
8767
8768 // This is an animation that does nothing: it just immediately finishes
8769 // itself every time it is called. It is used as a stub animation in cases
8770 // where we want to synchronize multiple things that may be animating.
8771 static final class DummyAnimation extends Animation {
8772 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8773 return false;
8774 }
8775 }
8776 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008778 // -------------------------------------------------------------
8779 // Async Handler
8780 // -------------------------------------------------------------
8781
8782 static final class StartingData {
8783 final String pkg;
8784 final int theme;
8785 final CharSequence nonLocalizedLabel;
8786 final int labelRes;
8787 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008788 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008790 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008791 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 pkg = _pkg;
8793 theme = _theme;
8794 nonLocalizedLabel = _nonLocalizedLabel;
8795 labelRes = _labelRes;
8796 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008797 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008798 }
8799 }
8800
8801 private final class H extends Handler {
8802 public static final int REPORT_FOCUS_CHANGE = 2;
8803 public static final int REPORT_LOSING_FOCUS = 3;
8804 public static final int ANIMATE = 4;
8805 public static final int ADD_STARTING = 5;
8806 public static final int REMOVE_STARTING = 6;
8807 public static final int FINISHED_STARTING = 7;
8808 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008809 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8810 public static final int HOLD_SCREEN_CHANGED = 12;
8811 public static final int APP_TRANSITION_TIMEOUT = 13;
8812 public static final int PERSIST_ANIMATION_SCALE = 14;
8813 public static final int FORCE_GC = 15;
8814 public static final int ENABLE_SCREEN = 16;
8815 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008816 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008817 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008818 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008819 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008821 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008823 public H() {
8824 }
Romain Guy06882f82009-06-10 13:36:04 -07008825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008826 @Override
8827 public void handleMessage(Message msg) {
8828 switch (msg.what) {
8829 case REPORT_FOCUS_CHANGE: {
8830 WindowState lastFocus;
8831 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008833 synchronized(mWindowMap) {
8834 lastFocus = mLastFocus;
8835 newFocus = mCurrentFocus;
8836 if (lastFocus == newFocus) {
8837 // Focus is not changing, so nothing to do.
8838 return;
8839 }
8840 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008841 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008842 // + " to " + newFocus);
8843 if (newFocus != null && lastFocus != null
8844 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008845 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008846 mLosingFocus.add(lastFocus);
8847 lastFocus = null;
8848 }
8849 }
8850
8851 if (lastFocus != newFocus) {
8852 //System.out.println("Changing focus from " + lastFocus
8853 // + " to " + newFocus);
8854 if (newFocus != null) {
8855 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008856 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008857 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8858 } catch (RemoteException e) {
8859 // Ignore if process has died.
8860 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008861 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008862 }
8863
8864 if (lastFocus != null) {
8865 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008866 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008867 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8868 } catch (RemoteException e) {
8869 // Ignore if process has died.
8870 }
8871 }
8872 }
8873 } break;
8874
8875 case REPORT_LOSING_FOCUS: {
8876 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008878 synchronized(mWindowMap) {
8879 losers = mLosingFocus;
8880 mLosingFocus = new ArrayList<WindowState>();
8881 }
8882
8883 final int N = losers.size();
8884 for (int i=0; i<N; i++) {
8885 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008886 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008887 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8888 } catch (RemoteException e) {
8889 // Ignore if process has died.
8890 }
8891 }
8892 } break;
8893
8894 case ANIMATE: {
8895 synchronized(mWindowMap) {
8896 mAnimationPending = false;
8897 performLayoutAndPlaceSurfacesLocked();
8898 }
8899 } break;
8900
8901 case ADD_STARTING: {
8902 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8903 final StartingData sd = wtoken.startingData;
8904
8905 if (sd == null) {
8906 // Animation has been canceled... do nothing.
8907 return;
8908 }
Romain Guy06882f82009-06-10 13:36:04 -07008909
Joe Onorato8a9b2202010-02-26 18:56:32 -08008910 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008911 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008913 View view = null;
8914 try {
8915 view = mPolicy.addStartingWindow(
8916 wtoken.token, sd.pkg,
8917 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008918 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008919 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008920 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008921 }
8922
8923 if (view != null) {
8924 boolean abort = false;
8925
8926 synchronized(mWindowMap) {
8927 if (wtoken.removed || wtoken.startingData == null) {
8928 // If the window was successfully added, then
8929 // we need to remove it.
8930 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008931 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 "Aborted starting " + wtoken
8933 + ": removed=" + wtoken.removed
8934 + " startingData=" + wtoken.startingData);
8935 wtoken.startingWindow = null;
8936 wtoken.startingData = null;
8937 abort = true;
8938 }
8939 } else {
8940 wtoken.startingView = view;
8941 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008942 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943 "Added starting " + wtoken
8944 + ": startingWindow="
8945 + wtoken.startingWindow + " startingView="
8946 + wtoken.startingView);
8947 }
8948
8949 if (abort) {
8950 try {
8951 mPolicy.removeStartingWindow(wtoken.token, view);
8952 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 }
8955 }
8956 }
8957 } break;
8958
8959 case REMOVE_STARTING: {
8960 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8961 IBinder token = null;
8962 View view = null;
8963 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008964 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008965 + wtoken + ": startingWindow="
8966 + wtoken.startingWindow + " startingView="
8967 + wtoken.startingView);
8968 if (wtoken.startingWindow != null) {
8969 view = wtoken.startingView;
8970 token = wtoken.token;
8971 wtoken.startingData = null;
8972 wtoken.startingView = null;
8973 wtoken.startingWindow = null;
8974 }
8975 }
8976 if (view != null) {
8977 try {
8978 mPolicy.removeStartingWindow(token, view);
8979 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008980 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008981 }
8982 }
8983 } break;
8984
8985 case FINISHED_STARTING: {
8986 IBinder token = null;
8987 View view = null;
8988 while (true) {
8989 synchronized (mWindowMap) {
8990 final int N = mFinishedStarting.size();
8991 if (N <= 0) {
8992 break;
8993 }
8994 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8995
Joe Onorato8a9b2202010-02-26 18:56:32 -08008996 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 "Finished starting " + wtoken
8998 + ": startingWindow=" + wtoken.startingWindow
8999 + " startingView=" + wtoken.startingView);
9000
9001 if (wtoken.startingWindow == null) {
9002 continue;
9003 }
9004
9005 view = wtoken.startingView;
9006 token = wtoken.token;
9007 wtoken.startingData = null;
9008 wtoken.startingView = null;
9009 wtoken.startingWindow = null;
9010 }
9011
9012 try {
9013 mPolicy.removeStartingWindow(token, view);
9014 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009015 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009016 }
9017 }
9018 } break;
9019
9020 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9021 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9022
9023 boolean nowVisible = msg.arg1 != 0;
9024 boolean nowGone = msg.arg2 != 0;
9025
9026 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009027 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009028 TAG, "Reporting visible in " + wtoken
9029 + " visible=" + nowVisible
9030 + " gone=" + nowGone);
9031 if (nowVisible) {
9032 wtoken.appToken.windowsVisible();
9033 } else {
9034 wtoken.appToken.windowsGone();
9035 }
9036 } catch (RemoteException ex) {
9037 }
9038 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009040 case WINDOW_FREEZE_TIMEOUT: {
9041 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009042 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 int i = mWindows.size();
9044 while (i > 0) {
9045 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009046 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009047 if (w.mOrientationChanging) {
9048 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009049 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009050 }
9051 }
9052 performLayoutAndPlaceSurfacesLocked();
9053 }
9054 break;
9055 }
Romain Guy06882f82009-06-10 13:36:04 -07009056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009057 case HOLD_SCREEN_CHANGED: {
9058 Session oldHold;
9059 Session newHold;
9060 synchronized (mWindowMap) {
9061 oldHold = mLastReportedHold;
9062 newHold = (Session)msg.obj;
9063 mLastReportedHold = newHold;
9064 }
Romain Guy06882f82009-06-10 13:36:04 -07009065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009066 if (oldHold != newHold) {
9067 try {
9068 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009069 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009070 "window",
9071 BatteryStats.WAKE_TYPE_WINDOW);
9072 }
9073 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009074 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009075 "window",
9076 BatteryStats.WAKE_TYPE_WINDOW);
9077 }
9078 } catch (RemoteException e) {
9079 }
9080 }
9081 break;
9082 }
Romain Guy06882f82009-06-10 13:36:04 -07009083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 case APP_TRANSITION_TIMEOUT: {
9085 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009086 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009087 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009088 "*** APP TRANSITION TIMEOUT");
9089 mAppTransitionReady = true;
9090 mAppTransitionTimeout = true;
9091 performLayoutAndPlaceSurfacesLocked();
9092 }
9093 }
9094 break;
9095 }
Romain Guy06882f82009-06-10 13:36:04 -07009096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009097 case PERSIST_ANIMATION_SCALE: {
9098 Settings.System.putFloat(mContext.getContentResolver(),
9099 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9100 Settings.System.putFloat(mContext.getContentResolver(),
9101 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9102 break;
9103 }
Romain Guy06882f82009-06-10 13:36:04 -07009104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009105 case FORCE_GC: {
9106 synchronized(mWindowMap) {
9107 if (mAnimationPending) {
9108 // If we are animating, don't do the gc now but
9109 // delay a bit so we don't interrupt the animation.
9110 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9111 2000);
9112 return;
9113 }
9114 // If we are currently rotating the display, it will
9115 // schedule a new message when done.
9116 if (mDisplayFrozen) {
9117 return;
9118 }
9119 mFreezeGcPending = 0;
9120 }
9121 Runtime.getRuntime().gc();
9122 break;
9123 }
Romain Guy06882f82009-06-10 13:36:04 -07009124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009125 case ENABLE_SCREEN: {
9126 performEnableScreen();
9127 break;
9128 }
Romain Guy06882f82009-06-10 13:36:04 -07009129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009130 case APP_FREEZE_TIMEOUT: {
9131 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009132 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009133 int i = mAppTokens.size();
9134 while (i > 0) {
9135 i--;
9136 AppWindowToken tok = mAppTokens.get(i);
9137 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009138 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009139 unsetAppFreezingScreenLocked(tok, true, true);
9140 }
9141 }
9142 }
9143 break;
9144 }
Romain Guy06882f82009-06-10 13:36:04 -07009145
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009146 case SEND_NEW_CONFIGURATION: {
9147 removeMessages(SEND_NEW_CONFIGURATION);
9148 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009149 break;
9150 }
Romain Guy06882f82009-06-10 13:36:04 -07009151
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009152 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009153 if (mWindowsChanged) {
9154 synchronized (mWindowMap) {
9155 mWindowsChanged = false;
9156 }
9157 notifyWindowsChanged();
9158 }
9159 break;
9160 }
9161
Christopher Tatea53146c2010-09-07 11:57:52 -07009162 case DRAG_START_TIMEOUT: {
9163 IBinder win = (IBinder)msg.obj;
9164 if (DEBUG_DRAG) {
9165 Slog.w(TAG, "Timeout starting drag by win " + win);
9166 }
9167 synchronized (mWindowMap) {
9168 // !!! TODO: ANR the app that has failed to start the drag in time
9169 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009170 mDragState.unregister();
9171 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009172 mDragState.reset();
9173 mDragState = null;
9174 }
9175 }
Chris Tated4533f142010-10-19 15:15:08 -07009176 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009177 }
9178
Chris Tated4533f142010-10-19 15:15:08 -07009179 case DRAG_END_TIMEOUT: {
9180 IBinder win = (IBinder)msg.obj;
9181 if (DEBUG_DRAG) {
9182 Slog.w(TAG, "Timeout ending drag to win " + win);
9183 }
9184 synchronized (mWindowMap) {
9185 // !!! TODO: ANR the drag-receiving app
9186 mDragState.mDragResult = false;
9187 mDragState.endDragLw();
9188 }
9189 break;
9190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009191 }
9192 }
9193 }
9194
9195 // -------------------------------------------------------------
9196 // IWindowManager API
9197 // -------------------------------------------------------------
9198
9199 public IWindowSession openSession(IInputMethodClient client,
9200 IInputContext inputContext) {
9201 if (client == null) throw new IllegalArgumentException("null client");
9202 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009203 Session session = new Session(client, inputContext);
9204 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 }
9206
9207 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9208 synchronized (mWindowMap) {
9209 // The focus for the client is the window immediately below
9210 // where we would place the input method window.
9211 int idx = findDesiredInputMethodWindowIndexLocked(false);
9212 WindowState imFocus;
9213 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009214 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009215 if (imFocus != null) {
9216 if (imFocus.mSession.mClient != null &&
9217 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9218 return true;
9219 }
9220 }
9221 }
9222 }
9223 return false;
9224 }
Romain Guy06882f82009-06-10 13:36:04 -07009225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 // -------------------------------------------------------------
9227 // Internals
9228 // -------------------------------------------------------------
9229
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009230 final WindowState windowForClientLocked(Session session, IWindow client,
9231 boolean throwOnError) {
9232 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009233 }
Romain Guy06882f82009-06-10 13:36:04 -07009234
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009235 final WindowState windowForClientLocked(Session session, IBinder client,
9236 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009237 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009238 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009239 TAG, "Looking up client " + client + ": " + win);
9240 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009241 RuntimeException ex = new IllegalArgumentException(
9242 "Requested window " + client + " does not exist");
9243 if (throwOnError) {
9244 throw ex;
9245 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009246 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 return null;
9248 }
9249 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009250 RuntimeException ex = new IllegalArgumentException(
9251 "Requested window " + client + " is in session " +
9252 win.mSession + ", not " + session);
9253 if (throwOnError) {
9254 throw ex;
9255 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009256 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 return null;
9258 }
9259
9260 return win;
9261 }
9262
Dianne Hackborna8f60182009-09-01 19:01:50 -07009263 final void rebuildAppWindowListLocked() {
9264 int NW = mWindows.size();
9265 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009266 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009267 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009268
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009269 if (mRebuildTmp.length < NW) {
9270 mRebuildTmp = new WindowState[NW+10];
9271 }
9272
Dianne Hackborna8f60182009-09-01 19:01:50 -07009273 // First remove all existing app windows.
9274 i=0;
9275 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009276 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009277 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009278 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009279 win.mRebuilding = true;
9280 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009281 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009282 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009283 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009284 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009285 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009286 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009287 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9288 && lastWallpaper == i-1) {
9289 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009290 }
9291 i++;
9292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009293
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009294 // The wallpaper window(s) typically live at the bottom of the stack,
9295 // so skip them before adding app tokens.
9296 lastWallpaper++;
9297 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009298
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009299 // First add all of the exiting app tokens... these are no longer
9300 // in the main app list, but still have windows shown. We put them
9301 // in the back because now that the animation is over we no longer
9302 // will care about them.
9303 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009304 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009305 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009307
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009308 // And add in the still active app tokens in Z order.
9309 NT = mAppTokens.size();
9310 for (int j=0; j<NT; j++) {
9311 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009313
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009314 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009315 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009316 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009317 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009318 for (i=0; i<numRemoved; i++) {
9319 WindowState ws = mRebuildTmp[i];
9320 if (ws.mRebuilding) {
9321 StringWriter sw = new StringWriter();
9322 PrintWriter pw = new PrintWriter(sw);
9323 ws.dump(pw, "");
9324 pw.flush();
9325 Slog.w(TAG, "This window was lost: " + ws);
9326 Slog.w(TAG, sw.toString());
9327 }
9328 }
9329 Slog.w(TAG, "Current app token list:");
9330 dumpAppTokensLocked();
9331 Slog.w(TAG, "Final window list:");
9332 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009333 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009334 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009336 private final void assignLayersLocked() {
9337 int N = mWindows.size();
9338 int curBaseLayer = 0;
9339 int curLayer = 0;
9340 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009341
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009342 if (DEBUG_LAYERS) {
9343 RuntimeException here = new RuntimeException("here");
9344 here.fillInStackTrace();
9345 Log.v(TAG, "Assigning layers", here);
9346 }
9347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009348 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009349 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009350 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9351 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009352 curLayer += WINDOW_LAYER_MULTIPLIER;
9353 w.mLayer = curLayer;
9354 } else {
9355 curBaseLayer = curLayer = w.mBaseLayer;
9356 w.mLayer = curLayer;
9357 }
9358 if (w.mTargetAppToken != null) {
9359 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9360 } else if (w.mAppToken != null) {
9361 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9362 } else {
9363 w.mAnimLayer = w.mLayer;
9364 }
9365 if (w.mIsImWindow) {
9366 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009367 } else if (w.mIsWallpaper) {
9368 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009369 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009370 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009371 + w.mAnimLayer);
9372 //System.out.println(
9373 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9374 }
9375 }
9376
9377 private boolean mInLayout = false;
9378 private final void performLayoutAndPlaceSurfacesLocked() {
9379 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009380 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009381 throw new RuntimeException("Recursive call!");
9382 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009383 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 return;
9385 }
9386
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009387 if (mWaitingForConfig) {
9388 // Our configuration has changed (most likely rotation), but we
9389 // don't yet have the complete configuration to report to
9390 // applications. Don't do any window layout until we have it.
9391 return;
9392 }
9393
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009394 if (mDisplay == null) {
9395 // Not yet initialized, nothing to do.
9396 return;
9397 }
9398
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009399 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009400 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009401
9402 try {
9403 if (mForceRemoves != null) {
9404 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009405 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009406 for (int i=0; i<mForceRemoves.size(); i++) {
9407 WindowState ws = mForceRemoves.get(i);
9408 Slog.i(TAG, "Force removing: " + ws);
9409 removeWindowInnerLocked(ws.mSession, ws);
9410 }
9411 mForceRemoves = null;
9412 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9413 Object tmp = new Object();
9414 synchronized (tmp) {
9415 try {
9416 tmp.wait(250);
9417 } catch (InterruptedException e) {
9418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009419 }
9420 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009421 } catch (RuntimeException e) {
9422 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009423 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009425 try {
9426 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009427
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009428 int N = mPendingRemove.size();
9429 if (N > 0) {
9430 if (mPendingRemoveTmp.length < N) {
9431 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009432 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009433 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009435 for (int i=0; i<N; i++) {
9436 WindowState w = mPendingRemoveTmp[i];
9437 removeWindowInnerLocked(w.mSession, w);
9438 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009439
9440 mInLayout = false;
9441 assignLayersLocked();
9442 mLayoutNeeded = true;
9443 performLayoutAndPlaceSurfacesLocked();
9444
9445 } else {
9446 mInLayout = false;
9447 if (mLayoutNeeded) {
9448 requestAnimationLocked(0);
9449 }
9450 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009451 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009452 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9453 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009454 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009455 } catch (RuntimeException e) {
9456 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009457 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009458 }
9459 }
9460
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009461 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009462 if (!mLayoutNeeded) {
9463 return 0;
9464 }
9465
9466 mLayoutNeeded = false;
9467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009468 final int dw = mDisplay.getWidth();
9469 final int dh = mDisplay.getHeight();
9470
9471 final int N = mWindows.size();
9472 int i;
9473
Joe Onorato8a9b2202010-02-26 18:56:32 -08009474 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009475 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9476
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009477 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009478
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009479 int seq = mLayoutSeq+1;
9480 if (seq < 0) seq = 0;
9481 mLayoutSeq = seq;
9482
9483 // First perform layout of any root windows (not attached
9484 // to another window).
9485 int topAttached = -1;
9486 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009487 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009488
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009489 // Don't do layout of a window if it is not visible, or
9490 // soon won't be visible, to avoid wasting time and funky
9491 // changes while a window is animating away.
9492 final AppWindowToken atoken = win.mAppToken;
9493 final boolean gone = win.mViewVisibility == View.GONE
9494 || !win.mRelayoutCalled
9495 || win.mRootToken.hidden
9496 || (atoken != null && atoken.hiddenRequested)
9497 || win.mAttachedHidden
9498 || win.mExiting || win.mDestroying;
9499
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009500 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9501 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009502 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9503 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009504 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009505 + win.mViewVisibility + " mRelayoutCalled="
9506 + win.mRelayoutCalled + " hidden="
9507 + win.mRootToken.hidden + " hiddenRequested="
9508 + (atoken != null && atoken.hiddenRequested)
9509 + " mAttachedHidden=" + win.mAttachedHidden);
9510 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009511
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009512 // If this view is GONE, then skip it -- keep the current
9513 // frame, and let the caller know so they can ignore it
9514 // if they want. (We do the normal layout for INVISIBLE
9515 // windows, since that means "perform layout as normal,
9516 // just don't display").
9517 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009518 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009519 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009520 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009521 win.mContentChanged = false;
9522 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009523 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9524 win.mLayoutSeq = seq;
9525 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9526 + win.mFrame + " mContainingFrame="
9527 + win.mContainingFrame + " mDisplayFrame="
9528 + win.mDisplayFrame);
9529 } else {
9530 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009531 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009533 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009534
9535 // Now perform layout of attached windows, which usually
9536 // depend on the position of the window they are attached to.
9537 // XXX does not deal with windows that are attached to windows
9538 // that are themselves attached.
9539 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009540 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009541
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009542 if (win.mLayoutAttached) {
9543 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9544 + " mHaveFrame=" + win.mHaveFrame
9545 + " mViewVisibility=" + win.mViewVisibility
9546 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009547 // If this view is GONE, then skip it -- keep the current
9548 // frame, and let the caller know so they can ignore it
9549 // if they want. (We do the normal layout for INVISIBLE
9550 // windows, since that means "perform layout as normal,
9551 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009552 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9553 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009554 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009555 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009556 win.mContentChanged = false;
9557 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009558 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9559 win.mLayoutSeq = seq;
9560 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9561 + win.mFrame + " mContainingFrame="
9562 + win.mContainingFrame + " mDisplayFrame="
9563 + win.mDisplayFrame);
9564 }
9565 }
9566 }
Jeff Brown349703e2010-06-22 01:27:15 -07009567
9568 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009569 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009570
9571 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 }
Romain Guy06882f82009-06-10 13:36:04 -07009573
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009574 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009575 private final void performLayoutAndPlaceSurfacesLockedInner(
9576 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009577 if (mDisplay == null) {
9578 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9579 return;
9580 }
9581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009582 final long currentTime = SystemClock.uptimeMillis();
9583 final int dw = mDisplay.getWidth();
9584 final int dh = mDisplay.getHeight();
9585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 int i;
9587
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009588 if (mFocusMayChange) {
9589 mFocusMayChange = false;
9590 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9591 }
9592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 // Initialize state of exiting tokens.
9594 for (i=mExitingTokens.size()-1; i>=0; i--) {
9595 mExitingTokens.get(i).hasVisible = false;
9596 }
9597
9598 // Initialize state of exiting applications.
9599 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9600 mExitingAppTokens.get(i).hasVisible = false;
9601 }
9602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 boolean orientationChangeComplete = true;
9604 Session holdScreen = null;
9605 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009606 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009607 boolean focusDisplayed = false;
9608 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009609 boolean createWatermark = false;
9610
9611 if (mFxSession == null) {
9612 mFxSession = new SurfaceSession();
9613 createWatermark = true;
9614 }
9615
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009616 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009617
9618 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009619
9620 if (createWatermark) {
9621 createWatermark();
9622 }
9623 if (mWatermark != null) {
9624 mWatermark.positionSurface(dw, dh);
9625 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009626 if (mStrictModeFlash != null) {
9627 mStrictModeFlash.positionSurface(dw, dh);
9628 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009630 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009631 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009632 int repeats = 0;
9633 int changes = 0;
9634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009635 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009636 repeats++;
9637 if (repeats > 6) {
9638 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9639 mLayoutNeeded = false;
9640 break;
9641 }
9642
9643 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9644 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9645 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9646 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9647 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9648 assignLayersLocked();
9649 mLayoutNeeded = true;
9650 }
9651 }
9652 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9653 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009654 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009655 mLayoutNeeded = true;
9656 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9657 }
9658 }
9659 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9660 mLayoutNeeded = true;
9661 }
9662 }
9663
9664 // FIRST LOOP: Perform a layout, if needed.
9665 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009666 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009667 if (changes != 0) {
9668 continue;
9669 }
9670 } else {
9671 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9672 changes = 0;
9673 }
9674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009675 final int transactionSequence = ++mTransactionSequence;
9676
9677 // Update animations of all applications, including those
9678 // associated with exiting/removed apps
9679 boolean tokensAnimating = false;
9680 final int NAT = mAppTokens.size();
9681 for (i=0; i<NAT; i++) {
9682 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9683 tokensAnimating = true;
9684 }
9685 }
9686 final int NEAT = mExitingAppTokens.size();
9687 for (i=0; i<NEAT; i++) {
9688 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9689 tokensAnimating = true;
9690 }
9691 }
9692
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009693 // SECOND LOOP: Execute animations and update visibility of windows.
9694
Joe Onorato8a9b2202010-02-26 18:56:32 -08009695 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009696 + transactionSequence + " tokensAnimating="
9697 + tokensAnimating);
9698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009699 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009700
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009701 if (mScreenRotationAnimation != null) {
9702 if (mScreenRotationAnimation.isAnimating()) {
9703 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9704 animating = true;
9705 } else {
9706 mScreenRotationAnimation = null;
9707 }
9708 }
9709 }
9710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009711 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009712 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009713 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009714 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009715
9716 mPolicy.beginAnimationLw(dw, dh);
9717
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009718 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009720 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009721 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009722
9723 final WindowManager.LayoutParams attrs = w.mAttrs;
9724
9725 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009726 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009727 if (w.commitFinishDrawingLocked(currentTime)) {
9728 if ((w.mAttrs.flags
9729 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009730 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009731 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009732 wallpaperMayChange = true;
9733 }
9734 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009735
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009736 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009737
9738 int animDw = dw;
9739 int animDh = dh;
9740
9741 // If the window has moved due to its containing
9742 // content frame changing, then we'd like to animate
9743 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009744 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009745 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009746 // Frame has moved, containing content frame
9747 // has also moved, and we're not currently animating...
9748 // let's do something.
9749 Animation a = AnimationUtils.loadAnimation(mContext,
9750 com.android.internal.R.anim.window_move_from_decor);
9751 w.setAnimation(a);
9752 animDw = w.mLastFrame.left - w.mFrame.left;
9753 animDh = w.mLastFrame.top - w.mFrame.top;
9754 }
9755
9756 // Execute animation.
9757 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9758 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009759
9760 // If this window is animating, make a note that we have
9761 // an animating window and take care of a request to run
9762 // a detached wallpaper animation.
9763 if (nowAnimating) {
9764 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9765 windowDetachedWallpaper = w;
9766 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009768 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009769
9770 // If this window's app token is running a detached wallpaper
9771 // animation, make a note so we can ensure the wallpaper is
9772 // displayed behind it.
9773 if (w.mAppToken != null && w.mAppToken.animation != null
9774 && w.mAppToken.animation.getDetachWallpaper()) {
9775 windowDetachedWallpaper = w;
9776 }
9777
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009778 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9779 wallpaperMayChange = true;
9780 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009781
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009782 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009783 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009784 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009785 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009786 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009787 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009788 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009789 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9790 forceHiding = true;
9791 }
9792 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9793 boolean changed;
9794 if (forceHiding) {
9795 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009796 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9797 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009798 } else {
9799 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009800 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9801 "Now policy shown: " + w);
9802 if (changed) {
9803 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009804 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009805 // Assume we will need to animate. If
9806 // we don't (because the wallpaper will
9807 // stay with the lock screen), then we will
9808 // clean up later.
9809 Animation a = mPolicy.createForceHideEnterAnimation();
9810 if (a != null) {
9811 w.setAnimation(a);
9812 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009813 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009814 if (mCurrentFocus == null ||
9815 mCurrentFocus.mLayer < w.mLayer) {
9816 // We are showing on to of the current
9817 // focus, so re-evaluate focus to make
9818 // sure it is correct.
9819 mFocusMayChange = true;
9820 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009821 }
9822 }
9823 if (changed && (attrs.flags
9824 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9825 wallpaperMayChange = true;
9826 }
9827 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 mPolicy.animatingWindowLw(w, attrs);
9830 }
9831
9832 final AppWindowToken atoken = w.mAppToken;
9833 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9834 if (atoken.lastTransactionSequence != transactionSequence) {
9835 atoken.lastTransactionSequence = transactionSequence;
9836 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9837 atoken.startingDisplayed = false;
9838 }
9839 if ((w.isOnScreen() || w.mAttrs.type
9840 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9841 && !w.mExiting && !w.mDestroying) {
9842 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009843 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009844 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009845 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009846 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009847 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 + " pv=" + w.mPolicyVisibility
9849 + " dp=" + w.mDrawPending
9850 + " cdp=" + w.mCommitDrawPending
9851 + " ah=" + w.mAttachedHidden
9852 + " th=" + atoken.hiddenRequested
9853 + " a=" + w.mAnimating);
9854 }
9855 }
9856 if (w != atoken.startingWindow) {
9857 if (!atoken.freezingScreen || !w.mAppFreezing) {
9858 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009859 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009860 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009861 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009862 "tokenMayBeDrawn: " + atoken
9863 + " freezingScreen=" + atoken.freezingScreen
9864 + " mAppFreezing=" + w.mAppFreezing);
9865 tokenMayBeDrawn = true;
9866 }
9867 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009868 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009869 atoken.startingDisplayed = true;
9870 }
9871 }
9872 } else if (w.mReadyToShow) {
9873 w.performShowLocked();
9874 }
9875 }
9876
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009877 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009878
9879 if (tokenMayBeDrawn) {
9880 // See if any windows have been drawn, so they (and others
9881 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009882 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009884 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 if (wtoken.freezingScreen) {
9886 int numInteresting = wtoken.numInterestingWindows;
9887 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009888 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009889 "allDrawn: " + wtoken
9890 + " interesting=" + numInteresting
9891 + " drawn=" + wtoken.numDrawnWindows);
9892 wtoken.showAllWindowsLocked();
9893 unsetAppFreezingScreenLocked(wtoken, false, true);
9894 orientationChangeComplete = true;
9895 }
9896 } else if (!wtoken.allDrawn) {
9897 int numInteresting = wtoken.numInterestingWindows;
9898 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009899 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900 "allDrawn: " + wtoken
9901 + " interesting=" + numInteresting
9902 + " drawn=" + wtoken.numDrawnWindows);
9903 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009904 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905
9906 // We can now show all of the drawn windows!
9907 if (!mOpeningApps.contains(wtoken)) {
9908 wtoken.showAllWindowsLocked();
9909 }
9910 }
9911 }
9912 }
9913 }
9914
9915 // If we are ready to perform an app transition, check through
9916 // all of the app tokens to be shown and see if they are ready
9917 // to go.
9918 if (mAppTransitionReady) {
9919 int NN = mOpeningApps.size();
9920 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009921 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 "Checking " + NN + " opening apps (frozen="
9923 + mDisplayFrozen + " timeout="
9924 + mAppTransitionTimeout + ")...");
9925 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9926 // If the display isn't frozen, wait to do anything until
9927 // all of the apps are ready. Otherwise just go because
9928 // we'll unfreeze the display when everyone is ready.
9929 for (i=0; i<NN && goodToGo; i++) {
9930 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009931 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009932 "Check opening app" + wtoken + ": allDrawn="
9933 + wtoken.allDrawn + " startingDisplayed="
9934 + wtoken.startingDisplayed);
9935 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9936 && !wtoken.startingMoved) {
9937 goodToGo = false;
9938 }
9939 }
9940 }
9941 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009942 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009943 int transit = mNextAppTransition;
9944 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009945 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009946 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009947 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009948 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009949 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009950 mAppTransitionTimeout = false;
9951 mStartingIconInTransition = false;
9952 mSkipAppTransitionAnimation = false;
9953
9954 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9955
Dianne Hackborna8f60182009-09-01 19:01:50 -07009956 // If there are applications waiting to come to the
9957 // top of the stack, now is the time to move their windows.
9958 // (Note that we don't do apps going to the bottom
9959 // here -- we want to keep their windows in the old
9960 // Z-order until the animation completes.)
9961 if (mToTopApps.size() > 0) {
9962 NN = mAppTokens.size();
9963 for (i=0; i<NN; i++) {
9964 AppWindowToken wtoken = mAppTokens.get(i);
9965 if (wtoken.sendingToTop) {
9966 wtoken.sendingToTop = false;
9967 moveAppWindowsLocked(wtoken, NN, false);
9968 }
9969 }
9970 mToTopApps.clear();
9971 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009972
Dianne Hackborn25994b42009-09-04 14:21:19 -07009973 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009974
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009975 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009976 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009977
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009978 // The top-most window will supply the layout params,
9979 // and we will determine it below.
9980 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009981 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009982 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009983
Joe Onorato8a9b2202010-02-26 18:56:32 -08009984 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009985 "New wallpaper target=" + mWallpaperTarget
9986 + ", lower target=" + mLowerWallpaperTarget
9987 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009988 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009989 // Do a first pass through the tokens for two
9990 // things:
9991 // (1) Determine if both the closing and opening
9992 // app token sets are wallpaper targets, in which
9993 // case special animations are needed
9994 // (since the wallpaper needs to stay static
9995 // behind them).
9996 // (2) Find the layout params of the top-most
9997 // application window in the tokens, which is
9998 // what will control the animation theme.
9999 final int NC = mClosingApps.size();
10000 NN = NC + mOpeningApps.size();
10001 for (i=0; i<NN; i++) {
10002 AppWindowToken wtoken;
10003 int mode;
10004 if (i < NC) {
10005 wtoken = mClosingApps.get(i);
10006 mode = 1;
10007 } else {
10008 wtoken = mOpeningApps.get(i-NC);
10009 mode = 2;
10010 }
10011 if (mLowerWallpaperTarget != null) {
10012 if (mLowerWallpaperTarget.mAppToken == wtoken
10013 || mUpperWallpaperTarget.mAppToken == wtoken) {
10014 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010015 }
10016 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010017 if (wtoken.appFullscreen) {
10018 WindowState ws = wtoken.findMainWindow();
10019 if (ws != null) {
10020 // If this is a compatibility mode
10021 // window, we will always use its anim.
10022 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10023 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010024 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010025 bestAnimLayer = Integer.MAX_VALUE;
10026 } else if (ws.mLayer > bestAnimLayer) {
10027 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010028 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010029 bestAnimLayer = ws.mLayer;
10030 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010031 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010032 }
10033 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010034
Dianne Hackborn25994b42009-09-04 14:21:19 -070010035 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010036 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010037 "Wallpaper animation!");
10038 switch (transit) {
10039 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10040 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10041 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10042 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10043 break;
10044 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10045 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10046 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10047 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10048 break;
10049 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010050 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010051 "New transit: " + transit);
10052 } else if (oldWallpaper != null) {
10053 // We are transitioning from an activity with
10054 // a wallpaper to one without.
10055 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010056 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010057 "New transit away from wallpaper: " + transit);
10058 } else if (mWallpaperTarget != null) {
10059 // We are transitioning from an activity without
10060 // a wallpaper to now showing the wallpaper
10061 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010062 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010063 "New transit into wallpaper: " + transit);
10064 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010065
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010066 // If all closing windows are obscured, then there is
10067 // no need to do an animation. This is the case, for
10068 // example, when this transition is being done behind
10069 // the lock screen.
10070 if (!mPolicy.allowAppAnimationsLw()) {
10071 animLp = null;
10072 }
10073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010074 NN = mOpeningApps.size();
10075 for (i=0; i<NN; i++) {
10076 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010077 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010078 "Now opening app" + wtoken);
10079 wtoken.reportedVisible = false;
10080 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010081 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010082 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010083 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010084 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010085 wtoken.showAllWindowsLocked();
10086 }
10087 NN = mClosingApps.size();
10088 for (i=0; i<NN; i++) {
10089 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010090 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010091 "Now closing app" + wtoken);
10092 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010093 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010094 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010095 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010096 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010097 // Force the allDrawn flag, because we want to start
10098 // this guy's animations regardless of whether it's
10099 // gotten drawn.
10100 wtoken.allDrawn = true;
10101 }
10102
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010103 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010105 mOpeningApps.clear();
10106 mClosingApps.clear();
10107
10108 // This has changed the visibility of windows, so perform
10109 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010110 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10111 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010113 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10114 assignLayersLocked();
10115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010116 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010117 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010118 }
10119 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010120
Dianne Hackborn16064f92010-03-25 00:47:24 -070010121 int adjResult = 0;
10122
Dianne Hackborna8f60182009-09-01 19:01:50 -070010123 if (!animating && mAppTransitionRunning) {
10124 // We have finished the animation of an app transition. To do
10125 // this, we have delayed a lot of operations like showing and
10126 // hiding apps, moving apps in Z-order, etc. The app token list
10127 // reflects the correct Z-order, but the window list may now
10128 // be out of sync with it. So here we will just rebuild the
10129 // entire app window list. Fun!
10130 mAppTransitionRunning = false;
10131 // Clear information about apps that were moving.
10132 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010133
Dianne Hackborna8f60182009-09-01 19:01:50 -070010134 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010135 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010136 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010137 moveInputMethodWindowsIfNeededLocked(false);
10138 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010139 // Since the window list has been rebuilt, focus might
10140 // have to be recomputed since the actual order of windows
10141 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010142 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010143 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010144
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010145 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010146 // At this point, there was a window with a wallpaper that
10147 // was force hiding other windows behind it, but now it
10148 // is going away. This may be simple -- just animate
10149 // away the wallpaper and its window -- or it may be
10150 // hard -- the wallpaper now needs to be shown behind
10151 // something that was hidden.
10152 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010153 if (mLowerWallpaperTarget != null
10154 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010155 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010156 "wallpaperForceHiding changed with lower="
10157 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010158 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010159 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10160 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10161 if (mLowerWallpaperTarget.mAppToken.hidden) {
10162 // The lower target has become hidden before we
10163 // actually started the animation... let's completely
10164 // re-evaluate everything.
10165 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010166 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010167 }
10168 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010169 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010170 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010171 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010172 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010173 + " NEW: " + mWallpaperTarget
10174 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010175 if (mLowerWallpaperTarget == null) {
10176 // Whoops, we don't need a special wallpaper animation.
10177 // Clear them out.
10178 forceHiding = false;
10179 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010180 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010181 if (w.mSurface != null) {
10182 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010183 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010184 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010185 forceHiding = true;
10186 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10187 if (!w.mAnimating) {
10188 // We set the animation above so it
10189 // is not yet running.
10190 w.clearAnimation();
10191 }
10192 }
10193 }
10194 }
10195 }
10196 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010197
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010198 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10199 if (DEBUG_WALLPAPER) Slog.v(TAG,
10200 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10201 + windowDetachedWallpaper);
10202 mWindowDetachedWallpaper = windowDetachedWallpaper;
10203 wallpaperMayChange = true;
10204 }
10205
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010206 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010207 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010208 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010209 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010210 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010211
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010212 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010213 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010214 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010215 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010216 assignLayersLocked();
10217 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010218 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010219 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010220 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010222
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010223 if (mFocusMayChange) {
10224 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010225 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010226 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010227 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010228 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010229 }
10230
10231 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010232 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010233 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010234
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010235 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10236 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010237
Jeff Browne33348b2010-07-15 23:54:05 -070010238 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010239 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010240
10241 // THIRD LOOP: Update the surfaces of all windows.
10242
10243 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10244
10245 boolean obscured = false;
10246 boolean blurring = false;
10247 boolean dimming = false;
10248 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010249 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010250 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010251
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010252 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010254 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010255 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010256
10257 boolean displayed = false;
10258 final WindowManager.LayoutParams attrs = w.mAttrs;
10259 final int attrFlags = attrs.flags;
10260
10261 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010262 // XXX NOTE: The logic here could be improved. We have
10263 // the decision about whether to resize a window separated
10264 // from whether to hide the surface. This can cause us to
10265 // resize a surface even if we are going to hide it. You
10266 // can see this by (1) holding device in landscape mode on
10267 // home screen; (2) tapping browser icon (device will rotate
10268 // to landscape; (3) tap home. The wallpaper will be resized
10269 // in step 2 but then immediately hidden, causing us to
10270 // have to resize and then redraw it again in step 3. It
10271 // would be nice to figure out how to avoid this, but it is
10272 // difficult because we do need to resize surfaces in some
10273 // cases while they are hidden such as when first showing a
10274 // window.
10275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010276 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010277 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278 TAG, "Placing surface #" + i + " " + w.mSurface
10279 + ": new=" + w.mShownFrame + ", old="
10280 + w.mLastShownFrame);
10281
10282 boolean resize;
10283 int width, height;
10284 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10285 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10286 w.mLastRequestedHeight != w.mRequestedHeight;
10287 // for a scaled surface, we just want to use
10288 // the requested size.
10289 width = w.mRequestedWidth;
10290 height = w.mRequestedHeight;
10291 w.mLastRequestedWidth = width;
10292 w.mLastRequestedHeight = height;
10293 w.mLastShownFrame.set(w.mShownFrame);
10294 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010295 if (SHOW_TRANSACTIONS) logSurface(w,
10296 "POS " + w.mShownFrame.left
10297 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010298 w.mSurfaceX = w.mShownFrame.left;
10299 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010300 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10301 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010302 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010303 if (!recoveringMemory) {
10304 reclaimSomeSurfaceMemoryLocked(w, "position");
10305 }
10306 }
10307 } else {
10308 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10309 width = w.mShownFrame.width();
10310 height = w.mShownFrame.height();
10311 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010312 }
10313
10314 if (resize) {
10315 if (width < 1) width = 1;
10316 if (height < 1) height = 1;
10317 if (w.mSurface != null) {
10318 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010319 if (SHOW_TRANSACTIONS) logSurface(w,
10320 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010321 + w.mShownFrame.top + " SIZE "
10322 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010323 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010324 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010325 w.mSurfaceW = width;
10326 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010328 w.mSurfaceX = w.mShownFrame.left;
10329 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 w.mSurface.setPosition(w.mShownFrame.left,
10331 w.mShownFrame.top);
10332 } catch (RuntimeException e) {
10333 // If something goes wrong with the surface (such
10334 // as running out of memory), don't take down the
10335 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010336 Slog.e(TAG, "Failure updating surface of " + w
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010337 + " size=(" + width + "x" + height
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010338 + "), pos=(" + w.mShownFrame.left
10339 + "," + w.mShownFrame.top + ")", e);
10340 if (!recoveringMemory) {
10341 reclaimSomeSurfaceMemoryLocked(w, "size");
10342 }
10343 }
10344 }
10345 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010346 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 w.mContentInsetsChanged =
10348 !w.mLastContentInsets.equals(w.mContentInsets);
10349 w.mVisibleInsetsChanged =
10350 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010351 boolean configChanged =
10352 w.mConfiguration != mCurConfiguration
10353 && (w.mConfiguration == null
10354 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010355 if (DEBUG_CONFIGURATION && configChanged) {
10356 Slog.v(TAG, "Win " + w + " config changed: "
10357 + mCurConfiguration);
10358 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010359 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010360 + ": configChanged=" + configChanged
10361 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010362 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010364 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010365 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010366 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 w.mLastFrame.set(w.mFrame);
10368 w.mLastContentInsets.set(w.mContentInsets);
10369 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010370 // If the screen is currently frozen, then keep
10371 // it frozen until this window draws at its new
10372 // orientation.
10373 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010374 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010375 "Resizing while display frozen: " + w);
10376 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010377 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010378 mWindowsFreezingScreen = true;
10379 // XXX should probably keep timeout from
10380 // when we first froze the display.
10381 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10382 mH.sendMessageDelayed(mH.obtainMessage(
10383 H.WINDOW_FREEZE_TIMEOUT), 2000);
10384 }
10385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010386 // If the orientation is changing, then we need to
10387 // hold off on unfreezing the display until this
10388 // window has been redrawn; to do that, we need
10389 // to go through the process of getting informed
10390 // by the application when it has finished drawing.
10391 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010392 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 "Orientation start waiting for draw in "
10394 + w + ", surface " + w.mSurface);
10395 w.mDrawPending = true;
10396 w.mCommitDrawPending = false;
10397 w.mReadyToShow = false;
10398 if (w.mAppToken != null) {
10399 w.mAppToken.allDrawn = false;
10400 }
10401 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010402 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403 "Resizing window " + w + " to " + w.mFrame);
10404 mResizingWindows.add(w);
10405 } else if (w.mOrientationChanging) {
10406 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010407 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010408 "Orientation not waiting for draw in "
10409 + w + ", surface " + w.mSurface);
10410 w.mOrientationChanging = false;
10411 }
10412 }
10413 }
10414
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010415 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010416 if (!w.mLastHidden) {
10417 //dump();
10418 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010419 if (SHOW_TRANSACTIONS) logSurface(w,
10420 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010422 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423 try {
10424 w.mSurface.hide();
10425 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010426 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427 }
10428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429 }
10430 // If we are waiting for this window to handle an
10431 // orientation change, well, it is hidden, so
10432 // doesn't really matter. Note that this does
10433 // introduce a potential glitch if the window
10434 // becomes unhidden before it has drawn for the
10435 // new orientation.
10436 if (w.mOrientationChanging) {
10437 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010438 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010439 "Orientation change skips hidden " + w);
10440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010441 } else if (w.mLastLayer != w.mAnimLayer
10442 || w.mLastAlpha != w.mShownAlpha
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
10449 || w.mLastHidden) {
10450 displayed = true;
10451 w.mLastAlpha = w.mShownAlpha;
10452 w.mLastLayer = w.mAnimLayer;
10453 w.mLastDsDx = w.mDsDx;
10454 w.mLastDtDx = w.mDtDx;
10455 w.mLastDsDy = w.mDsDy;
10456 w.mLastDtDy = w.mDtDy;
10457 w.mLastHScale = w.mHScale;
10458 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010459 if (SHOW_TRANSACTIONS) logSurface(w,
10460 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010461 + " matrix=[" + (w.mDsDx*w.mHScale)
10462 + "," + (w.mDtDx*w.mVScale)
10463 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010464 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010465 if (w.mSurface != null) {
10466 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010467 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010468 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010469 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010470 w.mSurface.setLayer(w.mAnimLayer);
10471 w.mSurface.setMatrix(
10472 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10473 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10474 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010475 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010476 if (!recoveringMemory) {
10477 reclaimSomeSurfaceMemoryLocked(w, "update");
10478 }
10479 }
10480 }
10481
10482 if (w.mLastHidden && !w.mDrawPending
10483 && !w.mCommitDrawPending
10484 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010485 if (SHOW_TRANSACTIONS) logSurface(w,
10486 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010487 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010488 + " during relayout");
10489 if (showSurfaceRobustlyLocked(w)) {
10490 w.mHasDrawn = true;
10491 w.mLastHidden = false;
10492 } else {
10493 w.mOrientationChanging = false;
10494 }
10495 }
10496 if (w.mSurface != null) {
10497 w.mToken.hasVisible = true;
10498 }
10499 } else {
10500 displayed = true;
10501 }
10502
10503 if (displayed) {
10504 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010505 if (attrs.width == LayoutParams.MATCH_PARENT
10506 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 covered = true;
10508 }
10509 }
10510 if (w.mOrientationChanging) {
10511 if (w.mDrawPending || w.mCommitDrawPending) {
10512 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010513 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 "Orientation continue waiting for draw in " + w);
10515 } else {
10516 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010517 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 "Orientation change complete in " + w);
10519 }
10520 }
10521 w.mToken.hasVisible = true;
10522 }
10523 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010524 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 "Orientation change skips hidden " + w);
10526 w.mOrientationChanging = false;
10527 }
10528
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010529 if (w.mContentChanged) {
10530 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10531 w.mContentChanged = false;
10532 }
10533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 final boolean canBeSeen = w.isDisplayedLw();
10535
10536 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10537 focusDisplayed = true;
10538 }
10539
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010540 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010542 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010543 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010544 if (w.mSurface != null) {
10545 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10546 holdScreen = w.mSession;
10547 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010548 if (!syswin && w.mAttrs.screenBrightness >= 0
10549 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010550 screenBrightness = w.mAttrs.screenBrightness;
10551 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010552 if (!syswin && w.mAttrs.buttonBrightness >= 0
10553 && buttonBrightness < 0) {
10554 buttonBrightness = w.mAttrs.buttonBrightness;
10555 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010556 if (canBeSeen
10557 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10558 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10559 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010560 syswin = true;
10561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010562 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010563
Dianne Hackborn25994b42009-09-04 14:21:19 -070010564 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10565 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010566 // This window completely covers everything behind it,
10567 // so we want to leave all of them as unblurred (for
10568 // performance reasons).
10569 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010570 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010571 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010572 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010573 obscured = true;
10574 if (mBackgroundFillerSurface == null) {
10575 try {
10576 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010577 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010578 0, dw, dh,
10579 PixelFormat.OPAQUE,
10580 Surface.FX_SURFACE_NORMAL);
10581 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010582 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010583 }
10584 }
10585 try {
10586 mBackgroundFillerSurface.setPosition(0, 0);
10587 mBackgroundFillerSurface.setSize(dw, dh);
10588 // Using the same layer as Dim because they will never be shown at the
10589 // same time.
10590 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10591 mBackgroundFillerSurface.show();
10592 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010593 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010594 }
10595 backgroundFillerShown = true;
10596 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010597 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010598 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010599 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010600 + ": blurring=" + blurring
10601 + " obscured=" + obscured
10602 + " displayed=" + displayed);
10603 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10604 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010605 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010606 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010607 if (mDimAnimator == null) {
10608 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010609 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010610 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010611 mDimAnimator.updateParameters(mContext.getResources(),
10612 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010614 }
10615 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10616 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010617 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010618 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010619 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010620 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010621 + mBlurSurface + ": CREATE");
10622 try {
Romain Guy06882f82009-06-10 13:36:04 -070010623 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010624 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010625 -1, 16, 16,
10626 PixelFormat.OPAQUE,
10627 Surface.FX_SURFACE_BLUR);
10628 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010629 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010630 }
10631 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010633 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10634 + mBlurSurface + ": pos=(0,0) (" +
10635 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010636 mBlurSurface.setPosition(0, 0);
10637 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010638 mBlurSurface.setLayer(w.mAnimLayer-2);
10639 if (!mBlurShown) {
10640 try {
10641 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10642 + mBlurSurface + ": SHOW");
10643 mBlurSurface.show();
10644 } catch (RuntimeException e) {
10645 Slog.w(TAG, "Failure showing blur surface", e);
10646 }
10647 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010648 }
10649 }
10650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010651 }
10652 }
10653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010654
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010655 if (obscuredChanged && mWallpaperTarget == w) {
10656 // This is the wallpaper target and its obscured state
10657 // changed... make sure the current wallaper's visibility
10658 // has been updated accordingly.
10659 updateWallpaperVisibilityLocked();
10660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010661 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010662
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010663 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10664 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010665 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010666 try {
10667 mBackgroundFillerSurface.hide();
10668 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010669 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010670 }
10671 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010672
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010673 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010674 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10675 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010676 }
Romain Guy06882f82009-06-10 13:36:04 -070010677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010678 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010679 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010680 + ": HIDE");
10681 try {
10682 mBlurSurface.hide();
10683 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010684 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010685 }
10686 mBlurShown = false;
10687 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010688 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010689 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010690 }
10691
Jeff Browne33348b2010-07-15 23:54:05 -070010692 mInputMonitor.updateInputWindowsLw();
10693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010694 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010695
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010696 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10697
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010698 if (mWatermark != null) {
10699 mWatermark.drawIfNeeded();
10700 }
10701
Joe Onorato8a9b2202010-02-26 18:56:32 -080010702 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010703 "With display frozen, orientationChangeComplete="
10704 + orientationChangeComplete);
10705 if (orientationChangeComplete) {
10706 if (mWindowsFreezingScreen) {
10707 mWindowsFreezingScreen = false;
10708 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10709 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010710 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010711 }
Romain Guy06882f82009-06-10 13:36:04 -070010712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010713 i = mResizingWindows.size();
10714 if (i > 0) {
10715 do {
10716 i--;
10717 WindowState win = mResizingWindows.get(i);
10718 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010719 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10720 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010721 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010722 boolean configChanged =
10723 win.mConfiguration != mCurConfiguration
10724 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010725 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10726 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10727 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010728 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010729 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010730 + " / " + mCurConfiguration + " / 0x"
10731 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010732 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010733 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010734 win.mClient.resized(win.mFrame.width(),
10735 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010736 win.mLastVisibleInsets, win.mDrawPending,
10737 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 win.mContentInsetsChanged = false;
10739 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010740 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010741 } catch (RemoteException e) {
10742 win.mOrientationChanging = false;
10743 }
10744 } while (i > 0);
10745 mResizingWindows.clear();
10746 }
Romain Guy06882f82009-06-10 13:36:04 -070010747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010748 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010749 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010750 i = mDestroySurface.size();
10751 if (i > 0) {
10752 do {
10753 i--;
10754 WindowState win = mDestroySurface.get(i);
10755 win.mDestroying = false;
10756 if (mInputMethodWindow == win) {
10757 mInputMethodWindow = null;
10758 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010759 if (win == mWallpaperTarget) {
10760 wallpaperDestroyed = true;
10761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010762 win.destroySurfaceLocked();
10763 } while (i > 0);
10764 mDestroySurface.clear();
10765 }
10766
10767 // Time to remove any exiting tokens?
10768 for (i=mExitingTokens.size()-1; i>=0; i--) {
10769 WindowToken token = mExitingTokens.get(i);
10770 if (!token.hasVisible) {
10771 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010772 if (token.windowType == TYPE_WALLPAPER) {
10773 mWallpaperTokens.remove(token);
10774 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010775 }
10776 }
10777
10778 // Time to remove any exiting applications?
10779 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10780 AppWindowToken token = mExitingAppTokens.get(i);
10781 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010782 // Make sure there is no animation running on this token,
10783 // so any windows associated with it will be removed as
10784 // soon as their animations are complete
10785 token.animation = null;
10786 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010787 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10788 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010789 mAppTokens.remove(token);
10790 mExitingAppTokens.remove(i);
10791 }
10792 }
10793
Dianne Hackborna8f60182009-09-01 19:01:50 -070010794 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010795
Dianne Hackborna8f60182009-09-01 19:01:50 -070010796 if (!animating && mAppTransitionRunning) {
10797 // We have finished the animation of an app transition. To do
10798 // this, we have delayed a lot of operations like showing and
10799 // hiding apps, moving apps in Z-order, etc. The app token list
10800 // reflects the correct Z-order, but the window list may now
10801 // be out of sync with it. So here we will just rebuild the
10802 // entire app window list. Fun!
10803 mAppTransitionRunning = false;
10804 needRelayout = true;
10805 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010806 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010807 // Clear information about apps that were moving.
10808 mToBottomApps.clear();
10809 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010811 if (focusDisplayed) {
10812 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10813 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010814 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010815 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010816 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010817 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010818 requestAnimationLocked(0);
10819 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010820 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10821 }
Jeff Browneb857f12010-07-16 10:06:33 -070010822
Jeff Browne33348b2010-07-15 23:54:05 -070010823 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010824
Jeff Brown8e03b752010-06-13 19:16:55 -070010825 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010826 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10827 mPowerManager.setScreenBrightnessOverride(-1);
10828 } else {
10829 mPowerManager.setScreenBrightnessOverride((int)
10830 (screenBrightness * Power.BRIGHTNESS_ON));
10831 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010832 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10833 mPowerManager.setButtonBrightnessOverride(-1);
10834 } else {
10835 mPowerManager.setButtonBrightnessOverride((int)
10836 (buttonBrightness * Power.BRIGHTNESS_ON));
10837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010838 if (holdScreen != mHoldingScreenOn) {
10839 mHoldingScreenOn = holdScreen;
10840 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10841 mH.sendMessage(m);
10842 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010843
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010844 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010845 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010846 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10847 LocalPowerManager.BUTTON_EVENT, true);
10848 mTurnOnScreen = false;
10849 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010850
10851 // Check to see if we are now in a state where the screen should
10852 // be enabled, because the window obscured flags have changed.
10853 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010854 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010855
10856 /**
10857 * Must be called with the main window manager lock held.
10858 */
10859 void setHoldScreenLocked(boolean holding) {
10860 boolean state = mHoldingScreenWakeLock.isHeld();
10861 if (holding != state) {
10862 if (holding) {
10863 mHoldingScreenWakeLock.acquire();
10864 } else {
10865 mPolicy.screenOnStoppedLw();
10866 mHoldingScreenWakeLock.release();
10867 }
10868 }
10869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010870
10871 void requestAnimationLocked(long delay) {
10872 if (!mAnimationPending) {
10873 mAnimationPending = true;
10874 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10875 }
10876 }
Romain Guy06882f82009-06-10 13:36:04 -070010877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010878 /**
10879 * Have the surface flinger show a surface, robustly dealing with
10880 * error conditions. In particular, if there is not enough memory
10881 * to show the surface, then we will try to get rid of other surfaces
10882 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010883 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 * @return Returns true if the surface was successfully shown.
10885 */
10886 boolean showSurfaceRobustlyLocked(WindowState win) {
10887 try {
10888 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010889 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010890 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010891 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010892 if (DEBUG_VISIBILITY) Slog.v(TAG,
10893 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010894 win.mTurnOnScreen = false;
10895 mTurnOnScreen = true;
10896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010897 }
10898 return true;
10899 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010900 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010901 }
Romain Guy06882f82009-06-10 13:36:04 -070010902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010903 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010905 return false;
10906 }
Romain Guy06882f82009-06-10 13:36:04 -070010907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010908 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10909 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010910
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010911 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010912 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010914 if (mForceRemoves == null) {
10915 mForceRemoves = new ArrayList<WindowState>();
10916 }
Romain Guy06882f82009-06-10 13:36:04 -070010917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010918 long callingIdentity = Binder.clearCallingIdentity();
10919 try {
10920 // There was some problem... first, do a sanity check of the
10921 // window list to make sure we haven't left any dangling surfaces
10922 // around.
10923 int N = mWindows.size();
10924 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010925 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010926 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010927 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010928 if (ws.mSurface != null) {
10929 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010930 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010931 + ws + " surface=" + ws.mSurface
10932 + " token=" + win.mToken
10933 + " pid=" + ws.mSession.mPid
10934 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010935 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010936 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010937 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010938 ws.mSurface = null;
10939 mForceRemoves.add(ws);
10940 i--;
10941 N--;
10942 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010943 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010944 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010945 + ws + " surface=" + ws.mSurface
10946 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010947 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010948 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010949 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010950 ws.mSurface = null;
10951 leakedSurface = true;
10952 }
10953 }
10954 }
Romain Guy06882f82009-06-10 13:36:04 -070010955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010956 boolean killedApps = false;
10957 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010958 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010959 SparseIntArray pidCandidates = new SparseIntArray();
10960 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010961 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010962 if (ws.mSurface != null) {
10963 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10964 }
10965 }
10966 if (pidCandidates.size() > 0) {
10967 int[] pids = new int[pidCandidates.size()];
10968 for (int i=0; i<pids.length; i++) {
10969 pids[i] = pidCandidates.keyAt(i);
10970 }
10971 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010972 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010973 killedApps = true;
10974 }
10975 } catch (RemoteException e) {
10976 }
10977 }
10978 }
Romain Guy06882f82009-06-10 13:36:04 -070010979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 if (leakedSurface || killedApps) {
10981 // We managed to reclaim some memory, so get rid of the trouble
10982 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010983 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010984 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010985 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010986 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010987 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010988 win.mSurface = null;
10989 }
Romain Guy06882f82009-06-10 13:36:04 -070010990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010991 try {
10992 win.mClient.dispatchGetNewSurface();
10993 } catch (RemoteException e) {
10994 }
10995 }
10996 } finally {
10997 Binder.restoreCallingIdentity(callingIdentity);
10998 }
10999 }
Romain Guy06882f82009-06-10 13:36:04 -070011000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011001 private boolean updateFocusedWindowLocked(int mode) {
11002 WindowState newFocus = computeFocusedWindowLocked();
11003 if (mCurrentFocus != newFocus) {
11004 // This check makes sure that we don't already have the focus
11005 // change message pending.
11006 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11007 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011008 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011009 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11010 final WindowState oldFocus = mCurrentFocus;
11011 mCurrentFocus = newFocus;
11012 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011014 final WindowState imWindow = mInputMethodWindow;
11015 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011016 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011017 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011018 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11019 mLayoutNeeded = true;
11020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011021 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080011022 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011023 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11024 // Client will do the layout, but we need to assign layers
11025 // for handleNewWindowLocked() below.
11026 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011027 }
11028 }
Jeff Brown349703e2010-06-22 01:27:15 -070011029
11030 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11031 // If we defer assigning layers, then the caller is responsible for
11032 // doing this part.
11033 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011035 return true;
11036 }
11037 return false;
11038 }
Jeff Brown349703e2010-06-22 01:27:15 -070011039
11040 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011041 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070011042 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011043
11044 private WindowState computeFocusedWindowLocked() {
11045 WindowState result = null;
11046 WindowState win;
11047
11048 int i = mWindows.size() - 1;
11049 int nextAppIndex = mAppTokens.size()-1;
11050 WindowToken nextApp = nextAppIndex >= 0
11051 ? mAppTokens.get(nextAppIndex) : null;
11052
11053 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011054 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011055
Joe Onorato8a9b2202010-02-26 18:56:32 -080011056 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011057 TAG, "Looking for focus: " + i
11058 + " = " + win
11059 + ", flags=" + win.mAttrs.flags
11060 + ", canReceive=" + win.canReceiveKeys());
11061
11062 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011064 // If this window's application has been removed, just skip it.
11065 if (thisApp != null && thisApp.removed) {
11066 i--;
11067 continue;
11068 }
Romain Guy06882f82009-06-10 13:36:04 -070011069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011070 // If there is a focused app, don't allow focus to go to any
11071 // windows below it. If this is an application window, step
11072 // through the app tokens until we find its app.
11073 if (thisApp != null && nextApp != null && thisApp != nextApp
11074 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11075 int origAppIndex = nextAppIndex;
11076 while (nextAppIndex > 0) {
11077 if (nextApp == mFocusedApp) {
11078 // Whoops, we are below the focused app... no focus
11079 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011080 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011081 TAG, "Reached focused app: " + mFocusedApp);
11082 return null;
11083 }
11084 nextAppIndex--;
11085 nextApp = mAppTokens.get(nextAppIndex);
11086 if (nextApp == thisApp) {
11087 break;
11088 }
11089 }
11090 if (thisApp != nextApp) {
11091 // Uh oh, the app token doesn't exist! This shouldn't
11092 // happen, but if it does we can get totally hosed...
11093 // so restart at the original app.
11094 nextAppIndex = origAppIndex;
11095 nextApp = mAppTokens.get(nextAppIndex);
11096 }
11097 }
11098
11099 // Dispatch to this window if it is wants key events.
11100 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011101 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011102 TAG, "Found focus @ " + i + " = " + win);
11103 result = win;
11104 break;
11105 }
11106
11107 i--;
11108 }
11109
11110 return result;
11111 }
11112
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011113 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011114 if (mDisplayFrozen) {
11115 return;
11116 }
Romain Guy06882f82009-06-10 13:36:04 -070011117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011118 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011120 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011121 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011122 if (mFreezeGcPending != 0) {
11123 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011124 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011125 mH.removeMessages(H.FORCE_GC);
11126 Runtime.getRuntime().gc();
11127 mFreezeGcPending = now;
11128 }
11129 } else {
11130 mFreezeGcPending = now;
11131 }
Romain Guy06882f82009-06-10 13:36:04 -070011132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011133 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011134
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011135 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011136
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011137 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11138 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011139 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011140 mAppTransitionReady = true;
11141 }
Romain Guy06882f82009-06-10 13:36:04 -070011142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011143 if (PROFILE_ORIENTATION) {
11144 File file = new File("/data/system/frozen");
11145 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11146 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011147
11148 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011149 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11150 mScreenRotationAnimation.kill();
11151 mScreenRotationAnimation = null;
11152 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011153 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011154 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011155 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011156 }
11157 } else {
11158 Surface.freezeDisplay(0);
11159 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011160 }
Romain Guy06882f82009-06-10 13:36:04 -070011161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011162 private void stopFreezingDisplayLocked() {
11163 if (!mDisplayFrozen) {
11164 return;
11165 }
Romain Guy06882f82009-06-10 13:36:04 -070011166
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011167 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11168 return;
11169 }
11170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011171 mDisplayFrozen = false;
11172 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11173 if (PROFILE_ORIENTATION) {
11174 Debug.stopMethodTracing();
11175 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011176
11177 if (CUSTOM_SCREEN_ROTATION) {
11178 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011179 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11180 mTransitionAnimationScale)) {
11181 requestAnimationLocked(0);
11182 } else {
11183 mScreenRotationAnimation = null;
11184 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011185 }
11186 } else {
11187 Surface.unfreezeDisplay(0);
11188 }
Romain Guy06882f82009-06-10 13:36:04 -070011189
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011190 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011191
Christopher Tateb696aee2010-04-02 19:08:30 -070011192 // While the display is frozen we don't re-compute the orientation
11193 // to avoid inconsistent states. However, something interesting
11194 // could have actually changed during that time so re-evaluate it
11195 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011196 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011197 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11198 }
11199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011200 // A little kludge: a lot could have happened while the
11201 // display was frozen, so now that we are coming back we
11202 // do a gc so that any remote references the system
11203 // processes holds on others can be released if they are
11204 // no longer needed.
11205 mH.removeMessages(H.FORCE_GC);
11206 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11207 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011209 mScreenFrozenLock.release();
11210 }
Romain Guy06882f82009-06-10 13:36:04 -070011211
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011212 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11213 DisplayMetrics dm) {
11214 if (index < tokens.length) {
11215 String str = tokens[index];
11216 if (str != null && str.length() > 0) {
11217 try {
11218 int val = Integer.parseInt(str);
11219 return val;
11220 } catch (Exception e) {
11221 }
11222 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011223 }
11224 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11225 return defDps;
11226 }
11227 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11228 return val;
11229 }
11230
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011231 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011232 final String[] mTokens;
11233 final String mText;
11234 final Paint mTextPaint;
11235 final int mTextWidth;
11236 final int mTextHeight;
11237 final int mTextAscent;
11238 final int mTextDescent;
11239 final int mDeltaX;
11240 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011241
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011242 Surface mSurface;
11243 int mLastDW;
11244 int mLastDH;
11245 boolean mDrawNeeded;
11246
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011247 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011248 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011249 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011250
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011251 if (false) {
11252 Log.i(TAG, "*********************** WATERMARK");
11253 for (int i=0; i<tokens.length; i++) {
11254 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11255 }
11256 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011257
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011258 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011259
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011260 StringBuilder builder = new StringBuilder(32);
11261 int len = mTokens[0].length();
11262 len = len & ~1;
11263 for (int i=0; i<len; i+=2) {
11264 int c1 = mTokens[0].charAt(i);
11265 int c2 = mTokens[0].charAt(i+1);
11266 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11267 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11268 else c1 -= '0';
11269 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11270 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11271 else c2 -= '0';
11272 builder.append((char)(255-((c1*16)+c2)));
11273 }
11274 mText = builder.toString();
11275 if (false) {
11276 Log.i(TAG, "Final text: " + mText);
11277 }
11278
11279 int fontSize = getPropertyInt(tokens, 1,
11280 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11281
11282 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11283 mTextPaint.setTextSize(fontSize);
11284 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11285
11286 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11287 mTextWidth = (int)mTextPaint.measureText(mText);
11288 mTextAscent = fm.ascent;
11289 mTextDescent = fm.descent;
11290 mTextHeight = fm.descent - fm.ascent;
11291
11292 mDeltaX = getPropertyInt(tokens, 2,
11293 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11294 mDeltaY = getPropertyInt(tokens, 3,
11295 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11296 int shadowColor = getPropertyInt(tokens, 4,
11297 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11298 int color = getPropertyInt(tokens, 5,
11299 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11300 int shadowRadius = getPropertyInt(tokens, 6,
11301 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11302 int shadowDx = getPropertyInt(tokens, 8,
11303 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11304 int shadowDy = getPropertyInt(tokens, 9,
11305 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11306
11307 mTextPaint.setColor(color);
11308 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011309
11310 try {
11311 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011312 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011313 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011314 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011315 mSurface.show();
11316 } catch (OutOfResourcesException e) {
11317 }
11318 }
11319
11320 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011321 if (mLastDW != dw || mLastDH != dh) {
11322 mLastDW = dw;
11323 mLastDH = dh;
11324 mSurface.setSize(dw, dh);
11325 mDrawNeeded = true;
11326 }
11327 }
11328
11329 void drawIfNeeded() {
11330 if (mDrawNeeded) {
11331 final int dw = mLastDW;
11332 final int dh = mLastDH;
11333
11334 mDrawNeeded = false;
11335 Rect dirty = new Rect(0, 0, dw, dh);
11336 Canvas c = null;
11337 try {
11338 c = mSurface.lockCanvas(dirty);
11339 } catch (IllegalArgumentException e) {
11340 } catch (OutOfResourcesException e) {
11341 }
11342 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011343 c.drawColor(0, PorterDuff.Mode.CLEAR);
11344
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011345 int deltaX = mDeltaX;
11346 int deltaY = mDeltaY;
11347
11348 // deltaX shouldn't be close to a round fraction of our
11349 // x step, or else things will line up too much.
11350 int div = (dw+mTextWidth)/deltaX;
11351 int rem = (dw+mTextWidth) - (div*deltaX);
11352 int qdelta = deltaX/4;
11353 if (rem < qdelta || rem > (deltaX-qdelta)) {
11354 deltaX += deltaX/3;
11355 }
11356
11357 int y = -mTextHeight;
11358 int x = -mTextWidth;
11359 while (y < (dh+mTextHeight)) {
11360 c.drawText(mText, x, y, mTextPaint);
11361 x += deltaX;
11362 if (x >= dw) {
11363 x -= (dw+mTextWidth);
11364 y += deltaY;
11365 }
11366 }
11367 mSurface.unlockCanvasAndPost(c);
11368 }
11369 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011370 }
11371 }
11372
11373 void createWatermark() {
11374 if (mWatermark != null) {
11375 return;
11376 }
11377
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011378 File file = new File("/system/etc/setup.conf");
11379 FileInputStream in = null;
11380 try {
11381 in = new FileInputStream(file);
11382 DataInputStream ind = new DataInputStream(in);
11383 String line = ind.readLine();
11384 if (line != null) {
11385 String[] toks = line.split("%");
11386 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011387 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011388 }
11389 }
11390 } catch (FileNotFoundException e) {
11391 } catch (IOException e) {
11392 } finally {
11393 if (in != null) {
11394 try {
11395 in.close();
11396 } catch (IOException e) {
11397 }
11398 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011399 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011400 }
11401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011402 @Override
11403 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11404 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11405 != PackageManager.PERMISSION_GRANTED) {
11406 pw.println("Permission Denial: can't dump WindowManager from from pid="
11407 + Binder.getCallingPid()
11408 + ", uid=" + Binder.getCallingUid());
11409 return;
11410 }
Romain Guy06882f82009-06-10 13:36:04 -070011411
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011412 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011413 pw.println(" ");
11414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011415 synchronized(mWindowMap) {
11416 pw.println("Current Window Manager state:");
11417 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011418 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011419 pw.print(" Window #"); pw.print(i); pw.print(' ');
11420 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011421 w.dump(pw, " ");
11422 }
11423 if (mInputMethodDialogs.size() > 0) {
11424 pw.println(" ");
11425 pw.println(" Input method dialogs:");
11426 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11427 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011428 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011429 }
11430 }
11431 if (mPendingRemove.size() > 0) {
11432 pw.println(" ");
11433 pw.println(" Remove pending for:");
11434 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11435 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011436 pw.print(" Remove #"); 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 (mForceRemoves != null && mForceRemoves.size() > 0) {
11442 pw.println(" ");
11443 pw.println(" Windows force removing:");
11444 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11445 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011446 pw.print(" Removing #"); 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 (mDestroySurface.size() > 0) {
11452 pw.println(" ");
11453 pw.println(" Windows waiting to destroy their surface:");
11454 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11455 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011456 pw.print(" Destroy #"); 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 }
11461 if (mLosingFocus.size() > 0) {
11462 pw.println(" ");
11463 pw.println(" Windows losing focus:");
11464 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11465 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011466 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11467 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011468 w.dump(pw, " ");
11469 }
11470 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011471 if (mResizingWindows.size() > 0) {
11472 pw.println(" ");
11473 pw.println(" Windows waiting to resize:");
11474 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11475 WindowState w = mResizingWindows.get(i);
11476 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11477 pw.print(w); pw.println(":");
11478 w.dump(pw, " ");
11479 }
11480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011481 if (mSessions.size() > 0) {
11482 pw.println(" ");
11483 pw.println(" All active sessions:");
11484 Iterator<Session> it = mSessions.iterator();
11485 while (it.hasNext()) {
11486 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011487 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011488 s.dump(pw, " ");
11489 }
11490 }
11491 if (mTokenMap.size() > 0) {
11492 pw.println(" ");
11493 pw.println(" All tokens:");
11494 Iterator<WindowToken> it = mTokenMap.values().iterator();
11495 while (it.hasNext()) {
11496 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011497 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011498 token.dump(pw, " ");
11499 }
11500 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011501 if (mWallpaperTokens.size() > 0) {
11502 pw.println(" ");
11503 pw.println(" Wallpaper tokens:");
11504 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11505 WindowToken token = mWallpaperTokens.get(i);
11506 pw.print(" Wallpaper #"); pw.print(i);
11507 pw.print(' '); pw.print(token); pw.println(':');
11508 token.dump(pw, " ");
11509 }
11510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011511 if (mAppTokens.size() > 0) {
11512 pw.println(" ");
11513 pw.println(" Application tokens in Z order:");
11514 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011515 pw.print(" App #"); pw.print(i); pw.print(": ");
11516 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011517 }
11518 }
11519 if (mFinishedStarting.size() > 0) {
11520 pw.println(" ");
11521 pw.println(" Finishing start of application tokens:");
11522 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11523 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011524 pw.print(" Finished Starting #"); 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 (mExitingTokens.size() > 0) {
11530 pw.println(" ");
11531 pw.println(" Exiting tokens:");
11532 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11533 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011534 pw.print(" Exiting #"); 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 if (mExitingAppTokens.size() > 0) {
11540 pw.println(" ");
11541 pw.println(" Exiting application tokens:");
11542 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11543 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011544 pw.print(" Exiting App #"); pw.print(i);
11545 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011546 token.dump(pw, " ");
11547 }
11548 }
11549 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011550 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11551 pw.print(" mLastFocus="); pw.println(mLastFocus);
11552 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11553 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11554 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011555 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011556 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11557 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11558 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11559 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011560 if (mWindowDetachedWallpaper != null) {
11561 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11562 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011563 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11564 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11565 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011566 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11567 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11568 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11569 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011570 if (mDimAnimator != null) {
11571 mDimAnimator.printTo(pw);
11572 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011573 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011574 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011575 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011576 pw.print(mInputMethodAnimLayerAdjustment);
11577 pw.print(" mWallpaperAnimLayerAdjustment=");
11578 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011579 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11580 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011581 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11582 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011583 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11584 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011585 pw.print(" mRotation="); pw.print(mRotation);
11586 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11587 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11588 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11589 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11590 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11591 pw.print(" mNextAppTransition=0x");
11592 pw.print(Integer.toHexString(mNextAppTransition));
11593 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011594 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011595 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011596 if (mNextAppTransitionPackage != null) {
11597 pw.print(" mNextAppTransitionPackage=");
11598 pw.print(mNextAppTransitionPackage);
11599 pw.print(", mNextAppTransitionEnter=0x");
11600 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11601 pw.print(", mNextAppTransitionExit=0x");
11602 pw.print(Integer.toHexString(mNextAppTransitionExit));
11603 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011604 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11605 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11606 if (mOpeningApps.size() > 0) {
11607 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11608 }
11609 if (mClosingApps.size() > 0) {
11610 pw.print(" mClosingApps="); pw.println(mClosingApps);
11611 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011612 if (mToTopApps.size() > 0) {
11613 pw.print(" mToTopApps="); pw.println(mToTopApps);
11614 }
11615 if (mToBottomApps.size() > 0) {
11616 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11617 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011618 if (mDisplay != null) {
11619 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11620 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11621 } else {
11622 pw.println(" NO DISPLAY");
11623 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011624 pw.println(" Policy:");
11625 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011626 }
11627 }
11628
Jeff Brown349703e2010-06-22 01:27:15 -070011629 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011630 public void monitor() {
11631 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011632 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011633 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011634
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011635 /**
11636 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011637 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011638 */
11639 private static class DimAnimator {
11640 Surface mDimSurface;
11641 boolean mDimShown = false;
11642 float mDimCurrentAlpha;
11643 float mDimTargetAlpha;
11644 float mDimDeltaPerMs;
11645 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011646
11647 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011648
11649 DimAnimator (SurfaceSession session) {
11650 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011651 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011652 + mDimSurface + ": CREATE");
11653 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011654 mDimSurface = new Surface(session, 0,
11655 "DimSurface",
11656 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011657 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011658 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011659 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011660 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011661 }
11662 }
11663 }
11664
11665 /**
11666 * Show the dim surface.
11667 */
11668 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011669 if (!mDimShown) {
11670 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11671 dw + "x" + dh + ")");
11672 mDimShown = true;
11673 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011674 mLastDimWidth = dw;
11675 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011676 mDimSurface.setPosition(0, 0);
11677 mDimSurface.setSize(dw, dh);
11678 mDimSurface.show();
11679 } catch (RuntimeException e) {
11680 Slog.w(TAG, "Failure showing dim surface", e);
11681 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011682 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11683 mLastDimWidth = dw;
11684 mLastDimHeight = dh;
11685 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011686 }
11687 }
11688
11689 /**
11690 * Set's the dim surface's layer and update dim parameters that will be used in
11691 * {@link updateSurface} after all windows are examined.
11692 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011693 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011694 mDimSurface.setLayer(w.mAnimLayer-1);
11695
11696 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011697 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011698 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011699 if (mDimTargetAlpha != target) {
11700 // If the desired dim level has changed, then
11701 // start an animation to it.
11702 mLastDimAnimTime = currentTime;
11703 long duration = (w.mAnimating && w.mAnimation != null)
11704 ? w.mAnimation.computeDurationHint()
11705 : DEFAULT_DIM_DURATION;
11706 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011707 TypedValue tv = new TypedValue();
11708 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11709 tv, true);
11710 if (tv.type == TypedValue.TYPE_FRACTION) {
11711 duration = (long)tv.getFraction((float)duration, (float)duration);
11712 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11713 && tv.type <= TypedValue.TYPE_LAST_INT) {
11714 duration = tv.data;
11715 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011716 }
11717 if (duration < 1) {
11718 // Don't divide by zero
11719 duration = 1;
11720 }
11721 mDimTargetAlpha = target;
11722 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11723 }
11724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011725
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011726 /**
11727 * Updating the surface's alpha. Returns true if the animation continues, or returns
11728 * false when the animation is finished and the dim surface is hidden.
11729 */
11730 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11731 if (!dimming) {
11732 if (mDimTargetAlpha != 0) {
11733 mLastDimAnimTime = currentTime;
11734 mDimTargetAlpha = 0;
11735 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11736 }
11737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011738
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011739 boolean animating = false;
11740 if (mLastDimAnimTime != 0) {
11741 mDimCurrentAlpha += mDimDeltaPerMs
11742 * (currentTime-mLastDimAnimTime);
11743 boolean more = true;
11744 if (displayFrozen) {
11745 // If the display is frozen, there is no reason to animate.
11746 more = false;
11747 } else if (mDimDeltaPerMs > 0) {
11748 if (mDimCurrentAlpha > mDimTargetAlpha) {
11749 more = false;
11750 }
11751 } else if (mDimDeltaPerMs < 0) {
11752 if (mDimCurrentAlpha < mDimTargetAlpha) {
11753 more = false;
11754 }
11755 } else {
11756 more = false;
11757 }
11758
11759 // Do we need to continue animating?
11760 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011761 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011762 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11763 mLastDimAnimTime = currentTime;
11764 mDimSurface.setAlpha(mDimCurrentAlpha);
11765 animating = true;
11766 } else {
11767 mDimCurrentAlpha = mDimTargetAlpha;
11768 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011769 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011770 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11771 mDimSurface.setAlpha(mDimCurrentAlpha);
11772 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011773 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011774 + ": HIDE");
11775 try {
11776 mDimSurface.hide();
11777 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011778 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011779 }
11780 mDimShown = false;
11781 }
11782 }
11783 }
11784 return animating;
11785 }
11786
11787 public void printTo(PrintWriter pw) {
11788 pw.print(" mDimShown="); pw.print(mDimShown);
11789 pw.print(" current="); pw.print(mDimCurrentAlpha);
11790 pw.print(" target="); pw.print(mDimTargetAlpha);
11791 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11792 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11793 }
11794 }
11795
11796 /**
11797 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11798 * This is used for opening/closing transition for apps in compatible mode.
11799 */
11800 private static class FadeInOutAnimation extends Animation {
11801 int mWidth;
11802 boolean mFadeIn;
11803
11804 public FadeInOutAnimation(boolean fadeIn) {
11805 setInterpolator(new AccelerateInterpolator());
11806 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11807 mFadeIn = fadeIn;
11808 }
11809
11810 @Override
11811 protected void applyTransformation(float interpolatedTime, Transformation t) {
11812 float x = interpolatedTime;
11813 if (!mFadeIn) {
11814 x = 1.0f - x; // reverse the interpolation for fade out
11815 }
11816 if (x < 0.5) {
11817 // move the window out of the screen.
11818 t.getMatrix().setTranslate(mWidth, 0);
11819 } else {
11820 t.getMatrix().setTranslate(0, 0);// show
11821 t.setAlpha((x - 0.5f) * 2);
11822 }
11823 }
11824
11825 @Override
11826 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11827 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11828 mWidth = width;
11829 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011830
11831 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011832 public int getZAdjustment() {
11833 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011834 }
11835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011836}