blob: 1be74d3b327d1534b774229b50bb8448e04ae8d2 [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;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070043import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import com.android.internal.view.IInputContext;
45import com.android.internal.view.IInputMethodClient;
46import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080047import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import com.android.server.am.BatteryStatsService;
49
50import android.Manifest;
51import android.app.ActivityManagerNative;
52import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070055import android.content.ClipData;
56import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070058import android.content.Intent;
59import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.pm.ActivityInfo;
61import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070068import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.graphics.Rect;
70import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070071import android.graphics.Typeface;
72import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.BatteryStats;
74import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070075import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.Debug;
77import android.os.Handler;
78import android.os.IBinder;
79import android.os.LocalPowerManager;
80import android.os.Looper;
81import android.os.Message;
82import android.os.Parcel;
83import android.os.ParcelFileDescriptor;
84import android.os.Power;
85import android.os.PowerManager;
86import android.os.Process;
87import android.os.RemoteException;
88import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070089import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.os.SystemClock;
91import android.os.SystemProperties;
92import android.os.TokenWatcher;
93import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070094import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070096import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080097import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070099import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700101import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700103import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104import android.view.IApplicationToken;
105import android.view.IOnKeyguardExitResult;
106import android.view.IRotationWatcher;
107import android.view.IWindow;
108import android.view.IWindowManager;
109import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700110import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700111import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700112import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700113import android.view.InputHandler;
114import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.KeyEvent;
116import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117import android.view.Surface;
118import android.view.SurfaceSession;
119import android.view.View;
120import android.view.ViewTreeObserver;
121import android.view.WindowManager;
122import android.view.WindowManagerImpl;
123import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700124import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700126import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127import android.view.animation.Animation;
128import android.view.animation.AnimationUtils;
129import android.view.animation.Transformation;
130
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134import java.io.File;
135import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700136import java.io.FileInputStream;
137import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138import java.io.IOException;
139import java.io.OutputStream;
140import java.io.OutputStreamWriter;
141import java.io.PrintWriter;
142import java.io.StringWriter;
143import java.net.Socket;
144import java.util.ArrayList;
145import java.util.HashMap;
146import java.util.HashSet;
147import java.util.Iterator;
148import java.util.List;
149
150/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700151public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700152 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final String TAG = "WindowManager";
154 static final boolean DEBUG = false;
155 static final boolean DEBUG_FOCUS = false;
156 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800157 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800158 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 static final boolean DEBUG_LAYERS = false;
160 static final boolean DEBUG_INPUT = false;
161 static final boolean DEBUG_INPUT_METHOD = false;
162 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700163 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700165 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 static final boolean DEBUG_APP_TRANSITIONS = false;
167 static final boolean DEBUG_STARTING_WINDOW = false;
168 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700169 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700170 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700172 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 static final boolean PROFILE_ORIENTATION = false;
175 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700176 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to multiply the policy's type layer, to reserve room
179 * for multiple windows of the same type and Z-ordering adjustment
180 * with TYPE_LAYER_OFFSET. */
181 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
184 * or below others in the same layer. */
185 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 /** How much to increment the layer for each window, to reserve room
188 * for effect surfaces between them.
189 */
190 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 /** The maximum length we will accept for a loaded animation duration:
193 * this is 10 seconds.
194 */
195 static final int MAX_ANIMATION_DURATION = 10*1000;
196
197 /** Amount of time (in milliseconds) to animate the dim surface from one
198 * value to another, when no window animation is driving it.
199 */
200 static final int DEFAULT_DIM_DURATION = 200;
201
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700202 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
203 * compatible windows.
204 */
205 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 /** Adjustment to time to perform a dim, to make it more dramatic.
208 */
209 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700210
211 // Maximum number of milliseconds to wait for input event injection.
212 // FIXME is this value reasonable?
213 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700214
215 // Default input dispatching timeout in nanoseconds.
216 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 static final int UPDATE_FOCUS_NORMAL = 0;
219 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
220 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
221 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700224 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225
226 /**
227 * Condition waited on by {@link #reenableKeyguard} to know the call to
228 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 * This is set to true only if mKeyguardTokenWatcher.acquired() has
230 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500232 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233
Jim Miller284b62e2010-06-08 14:27:42 -0700234 private static final int ALLOW_DISABLE_YES = 1;
235 private static final int ALLOW_DISABLE_NO = 0;
236 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
237 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
238
Mike Lockwood983ee092009-11-22 01:42:24 -0500239 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
240 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700242 if (shouldAllowDisableKeyguard()) {
243 mPolicy.enableKeyguard(false);
244 mKeyguardDisabled = true;
245 } else {
246 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 }
249 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700250 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500251 synchronized (mKeyguardTokenWatcher) {
252 mKeyguardDisabled = false;
253 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
255 }
256 };
257
Jim Miller284b62e2010-06-08 14:27:42 -0700258 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
259 @Override
260 public void onReceive(Context context, Intent intent) {
261 mPolicy.enableKeyguard(true);
262 synchronized(mKeyguardTokenWatcher) {
263 // lazily evaluate this next time we're asked to disable keyguard
264 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
265 mKeyguardDisabled = false;
266 }
267 }
268 };
269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final Context mContext;
271
272 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
277
278 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 /**
283 * All currently active sessions with clients.
284 */
285 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 /**
288 * Mapping from an IWindow IBinder to the server's Window object.
289 * This is also used as the lock for all of our state.
290 */
291 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
292
293 /**
294 * Mapping from a token IBinder to a WindowToken object.
295 */
296 final HashMap<IBinder, WindowToken> mTokenMap =
297 new HashMap<IBinder, WindowToken>();
298
299 /**
300 * The same tokens as mTokenMap, stored in a list for efficient iteration
301 * over them.
302 */
303 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 /**
306 * Window tokens that are in the process of exiting, but still
307 * on screen for animations.
308 */
309 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
310
311 /**
312 * Z-ordered (bottom-most first) list of all application tokens, for
313 * controlling the ordering of windows in different applications. This
314 * contains WindowToken objects.
315 */
316 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
317
318 /**
319 * Application tokens that are in the process of exiting, but still
320 * on screen for animations.
321 */
322 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
323
324 /**
325 * List of window tokens that have finished starting their application,
326 * and now need to have the policy remove their windows.
327 */
328 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
329
330 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700331 * This was the app token that was used to retrieve the last enter
332 * animation. It will be used for the next exit animation.
333 */
334 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800335
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700336 /**
337 * These were the layout params used to retrieve the last enter animation.
338 * They will be used for the next exit animation.
339 */
340 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800341
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700342 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 * Z-ordered (bottom-most first) list of all Window objects.
344 */
Jeff Browne33348b2010-07-15 23:54:05 -0700345 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346
347 /**
348 * Windows that are being resized. Used so we can tell the client about
349 * the resize after closing the transaction in which we resized the
350 * underlying surface.
351 */
352 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
353
354 /**
355 * Windows whose animations have ended and now must be removed.
356 */
357 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
358
359 /**
360 * Windows whose surface should be destroyed.
361 */
362 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
363
364 /**
365 * Windows that have lost input focus and are waiting for the new
366 * focus window to be displayed before they are told about this.
367 */
368 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
369
370 /**
371 * This is set when we have run out of memory, and will either be an empty
372 * list or contain windows that need to be force removed.
373 */
374 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700379 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 Surface mBlurSurface;
381 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700382 Watermark mWatermark;
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;
449 WindowState mUpcomingInputMethodTarget = null;
450 boolean mInputMethodTargetWaitingAnim;
451 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 WindowState mInputMethodWindow = null;
454 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
455
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700456 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800457
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700458 // If non-null, this is the currently visible window that is associated
459 // with the wallpaper.
460 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700461 // If non-null, we are in the middle of animating from one wallpaper target
462 // to another, and this is the lower one in Z-order.
463 WindowState mLowerWallpaperTarget = null;
464 // If non-null, we are in the middle of animating from one wallpaper target
465 // to another, and this is the higher one in Z-order.
466 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700467 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700468 float mLastWallpaperX = -1;
469 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800470 float mLastWallpaperXStep = -1;
471 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700472 // This is set when we are waiting for a wallpaper to tell us it is done
473 // changing its scroll position.
474 WindowState mWaitingOnWallpaper;
475 // The last time we had a timeout when waiting for a wallpaper.
476 long mLastWallpaperTimeoutTime;
477 // We give a wallpaper up to 150ms to finish scrolling.
478 static final long WALLPAPER_TIMEOUT = 150;
479 // Time we wait after a timeout before trying to wait again.
480 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 AppWindowToken mFocusedApp = null;
483
484 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 float mWindowAnimationScale = 1.0f;
487 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700488
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700489 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490
491 // Who is holding the screen on.
492 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700493 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700494
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700495 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700498 * Drag/drop state
499 */
500 class DragState {
501 IBinder mToken;
502 Surface mSurface;
503 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700504 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700505 ClipData mData;
506 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700507 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700508 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 float mThumbOffsetX, mThumbOffsetY;
510 InputChannel mServerChannel, mClientChannel;
511 WindowState mTargetWindow;
512 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700513 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700514
515 private final Rect tmpRect = new Rect();
516
Chris Tate7b362e42010-11-04 16:02:52 -0700517 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700518 mToken = token;
519 mSurface = surface;
520 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700521 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700522 mNotifiedWindows = new ArrayList<WindowState>();
523 }
524
525 void reset() {
526 if (mSurface != null) {
527 mSurface.destroy();
528 }
529 mSurface = null;
530 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700531 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700532 mToken = null;
533 mData = null;
534 mThumbOffsetX = mThumbOffsetY = 0;
535 mNotifiedWindows = null;
536 }
537
538 void register() {
539 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
540 if (mClientChannel != null) {
541 Slog.e(TAG, "Duplicate register of drag input channel");
542 } else {
543 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
544 mServerChannel = channels[0];
545 mClientChannel = channels[1];
546 mInputManager.registerInputChannel(mServerChannel);
547 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
548 mH.getLooper().getQueue());
549 }
550 }
551
552 void unregister() {
553 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
554 if (mClientChannel == null) {
555 Slog.e(TAG, "Unregister of nonexistent drag input channel");
556 } else {
557 mInputManager.unregisterInputChannel(mServerChannel);
558 InputQueue.unregisterInputChannel(mClientChannel);
559 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700560 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700561 mClientChannel = null;
562 mServerChannel = null;
563 }
564 }
565
Chris Tatea32dcf72010-10-14 12:13:50 -0700566 int getDragLayerLw() {
567 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
568 * TYPE_LAYER_MULTIPLIER
569 + TYPE_LAYER_OFFSET;
570 }
571
Christopher Tatea53146c2010-09-07 11:57:52 -0700572 /* call out to each visible window/session informing it about the drag
573 */
Chris Tateb8203e92010-10-12 14:23:21 -0700574 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700575 // Cache a base-class instance of the clip metadata so that parceling
576 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700577 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700579 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700580
581 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700582 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 }
584
Christopher Tate2c095f32010-10-04 14:13:40 -0700585 final int N = mWindows.size();
586 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700587 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
590
591 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
592 * designated window is potentially a drop recipient. There are race situations
593 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
594 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700595 *
596 * This method clones the 'event' parameter if it's being delivered to the same
597 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 */
Chris Tateb478f462010-10-15 16:02:26 -0700599 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
600 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700601 // Don't actually send the event if the drag is supposed to be pinned
602 // to the originating window but 'newWin' is not that window.
603 if (mLocalOnly) {
604 final IBinder winBinder = newWin.mClient.asBinder();
605 if (winBinder != mLocalWin) {
606 if (DEBUG_DRAG) {
607 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
608 }
609 return;
610 }
611 }
612
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700613 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700614 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
615 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700616 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700617 try {
618 newWin.mClient.dispatchDragEvent(event);
619 // track each window that we've notified that the drag is starting
620 mNotifiedWindows.add(newWin);
621 } catch (RemoteException e) {
622 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700623 } finally {
624 // if the callee was local, the dispatch has already recycled the event
625 if (Process.myPid() != newWin.mSession.mPid) {
626 event.recycle();
627 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700628 }
629 }
630 }
631
632 /* helper - construct and send a DRAG_STARTED event only if the window has not
633 * previously been notified, i.e. it became visible after the drag operation
634 * was begun. This is a rare case.
635 */
636 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700637 if (mDragInProgress) {
638 // If we have sent the drag-started, we needn't do so again
639 for (WindowState ws : mNotifiedWindows) {
640 if (ws == newWin) {
641 return;
642 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700643 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700644 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700645 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700646 }
Chris Tateb478f462010-10-15 16:02:26 -0700647 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700648 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
650
Chris Tated4533f142010-10-19 15:15:08 -0700651 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700652 if (DEBUG_DRAG) {
653 Slog.d(TAG, "broadcasting DRAG_ENDED");
654 }
Chris Tated4533f142010-10-19 15:15:08 -0700655 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
656 0, 0, null, null, mDragResult);
657 for (WindowState ws: mNotifiedWindows) {
658 try {
659 ws.mClient.dispatchDragEvent(evt);
660 } catch (RemoteException e) {
661 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700662 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 }
Chris Tated4533f142010-10-19 15:15:08 -0700664 mNotifiedWindows.clear();
665 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700666 evt.recycle();
667 }
668
Chris Tated4533f142010-10-19 15:15:08 -0700669 void endDragLw() {
670 mDragState.broadcastDragEndedLw();
671
672 // stop intercepting input
673 mDragState.unregister();
674 mInputMonitor.updateInputWindowsLw();
675
676 // free our resources and drop all the object references
677 mDragState.reset();
678 mDragState = null;
679 }
680
Christopher Tatea53146c2010-09-07 11:57:52 -0700681 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700682 final int myPid = Process.myPid();
683
684 // Move the surface to the given touch
685 mSurface.openTransaction();
686 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
687 mSurface.closeTransaction();
688
689 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700690 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700691 if (mLocalOnly) {
692 final IBinder touchedBinder = touchedWin.mClient.asBinder();
693 if (touchedBinder != mLocalWin) {
694 // This drag is pinned only to the originating window, but the drag
695 // point is outside that window. Pretend it's over empty space.
696 touchedWin = null;
697 }
698 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700699 try {
700 // have we dragged over a new window?
701 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
702 if (DEBUG_DRAG) {
703 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
704 }
705 // force DRAG_EXITED_EVENT if appropriate
706 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700707 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700708 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700709 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700710 if (myPid != mTargetWindow.mSession.mPid) {
711 evt.recycle();
712 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700713 }
714 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700715 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700716 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
717 }
718 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700719 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700720 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700721 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700722 if (myPid != touchedWin.mSession.mPid) {
723 evt.recycle();
724 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700725 }
726 } catch (RemoteException e) {
727 Slog.w(TAG, "can't send drag notification to windows");
728 }
729 mTargetWindow = touchedWin;
730 }
731
Chris Tated4533f142010-10-19 15:15:08 -0700732 // Tell the drop target about the data. Returns 'true' if we can immediately
733 // dispatch the global drag-ended message, 'false' if we need to wait for a
734 // result from the recipient.
735 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700736 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700737 if (touchedWin == null) {
738 // "drop" outside a valid window -- no recipient to apply a
739 // timeout to, and we can send the drag-ended message immediately.
740 mDragResult = false;
741 return true;
742 }
743
744 if (DEBUG_DRAG) {
745 Slog.d(TAG, "sending DROP to " + touchedWin);
746 }
747 final int myPid = Process.myPid();
748 final IBinder token = touchedWin.mClient.asBinder();
749 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
750 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
751 null, mData, false);
752 try {
753 touchedWin.mClient.dispatchDragEvent(evt);
754
755 // 5 second timeout for this window to respond to the drop
756 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
757 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
758 mH.sendMessageDelayed(msg, 5000);
759 } catch (RemoteException e) {
760 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
761 return true;
762 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700763 if (myPid != touchedWin.mSession.mPid) {
764 evt.recycle();
765 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700766 }
Chris Tated4533f142010-10-19 15:15:08 -0700767 mToken = token;
768 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700769 }
770
771 // Find the visible, touch-deliverable window under the given point
772 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
773 WindowState touchedWin = null;
774 final int x = (int) xf;
775 final int y = (int) yf;
776 final ArrayList<WindowState> windows = mWindows;
777 final int N = windows.size();
778 for (int i = N - 1; i >= 0; i--) {
779 WindowState child = windows.get(i);
780 final int flags = child.mAttrs.flags;
781 if (!child.isVisibleLw()) {
782 // not visible == don't tell about drags
783 continue;
784 }
785 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
786 // not touchable == don't tell about drags
787 continue;
788 }
789 // account for the window's decor etc
790 tmpRect.set(child.mFrame);
791 if (child.mTouchableInsets == ViewTreeObserver
792 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
793 // The point is inside of the window if it is
794 // inside the frame, AND the content part of that
795 // frame that was given by the application.
796 tmpRect.left += child.mGivenContentInsets.left;
797 tmpRect.top += child.mGivenContentInsets.top;
798 tmpRect.right -= child.mGivenContentInsets.right;
799 tmpRect.bottom -= child.mGivenContentInsets.bottom;
800 } else if (child.mTouchableInsets == ViewTreeObserver
801 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
802 // The point is inside of the window if it is
803 // inside the frame, AND the visible part of that
804 // frame that was given by the application.
805 tmpRect.left += child.mGivenVisibleInsets.left;
806 tmpRect.top += child.mGivenVisibleInsets.top;
807 tmpRect.right -= child.mGivenVisibleInsets.right;
808 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
809 }
810 final int touchFlags = flags &
811 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
812 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
813 if (tmpRect.contains(x, y) || touchFlags == 0) {
814 // Found it
815 touchedWin = child;
816 break;
817 }
818 }
819
820 return touchedWin;
821 }
822 }
823
824 DragState mDragState = null;
825 private final InputHandler mDragInputHandler = new BaseInputHandler() {
826 @Override
827 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
828 boolean endDrag = false;
829 final float newX = event.getRawX();
830 final float newY = event.getRawY();
831
832 try {
833 if (mDragState != null) {
834 switch (event.getAction()) {
835 case MotionEvent.ACTION_DOWN: {
836 if (DEBUG_DRAG) {
837 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
838 }
839 } break;
840
841 case MotionEvent.ACTION_MOVE: {
842 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700843 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700844 mDragState.notifyMoveLw(newX, newY);
845 }
846 } break;
847
848 case MotionEvent.ACTION_UP: {
849 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
850 + newX + "," + newY);
851 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700852 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700853 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700854 } break;
855
856 case MotionEvent.ACTION_CANCEL: {
857 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
858 endDrag = true;
859 } break;
860 }
861
862 if (endDrag) {
863 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
864 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700865 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700866 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700867 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700868 }
869 }
870 } catch (Exception e) {
871 Slog.e(TAG, "Exception caught by drag handleMotion", e);
872 } finally {
873 finishedCallback.run();
874 }
875 }
876 };
877
878 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 * Whether the UI is currently running in touch mode (not showing
880 * navigational focus because the user is directly pressing the screen).
881 */
882 boolean mInTouchMode = false;
883
884 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700885 private ArrayList<WindowChangeListener> mWindowChangeListeners =
886 new ArrayList<WindowChangeListener>();
887 private boolean mWindowsChanged = false;
888
889 public interface WindowChangeListener {
890 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700891 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893
Dianne Hackbornc485a602009-03-24 22:39:49 -0700894 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700895 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700896
897 // The frame use to limit the size of the app running in compatibility mode.
898 Rect mCompatibleScreenFrame = new Rect();
899 // The surface used to fill the outer rim of the app running in compatibility mode.
900 Surface mBackgroundFillerSurface = null;
901 boolean mBackgroundFillerShown = false;
902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 public static WindowManagerService main(Context context,
904 PowerManagerService pm, boolean haveInputMethods) {
905 WMThread thr = new WMThread(context, pm, haveInputMethods);
906 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 synchronized (thr) {
909 while (thr.mService == null) {
910 try {
911 thr.wait();
912 } catch (InterruptedException e) {
913 }
914 }
915 }
Romain Guy06882f82009-06-10 13:36:04 -0700916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 return thr.mService;
918 }
Romain Guy06882f82009-06-10 13:36:04 -0700919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 static class WMThread extends Thread {
921 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 private final Context mContext;
924 private final PowerManagerService mPM;
925 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 public WMThread(Context context, PowerManagerService pm,
928 boolean haveInputMethods) {
929 super("WindowManager");
930 mContext = context;
931 mPM = pm;
932 mHaveInputMethods = haveInputMethods;
933 }
Romain Guy06882f82009-06-10 13:36:04 -0700934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 public void run() {
936 Looper.prepare();
937 WindowManagerService s = new WindowManagerService(mContext, mPM,
938 mHaveInputMethods);
939 android.os.Process.setThreadPriority(
940 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700941 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 synchronized (this) {
944 mService = s;
945 notifyAll();
946 }
Romain Guy06882f82009-06-10 13:36:04 -0700947
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700948 // For debug builds, log event loop stalls to dropbox for analysis.
949 if (StrictMode.conditionallyEnableDebugLogging()) {
950 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
951 }
952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 Looper.loop();
954 }
955 }
956
957 static class PolicyThread extends Thread {
958 private final WindowManagerPolicy mPolicy;
959 private final WindowManagerService mService;
960 private final Context mContext;
961 private final PowerManagerService mPM;
962 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 public PolicyThread(WindowManagerPolicy policy,
965 WindowManagerService service, Context context,
966 PowerManagerService pm) {
967 super("WindowManagerPolicy");
968 mPolicy = policy;
969 mService = service;
970 mContext = context;
971 mPM = pm;
972 }
Romain Guy06882f82009-06-10 13:36:04 -0700973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 public void run() {
975 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800976 WindowManagerPolicyThread.set(this, Looper.myLooper());
977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800979 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 android.os.Process.setThreadPriority(
981 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700982 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 synchronized (this) {
986 mRunning = true;
987 notifyAll();
988 }
Romain Guy06882f82009-06-10 13:36:04 -0700989
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700990 // For debug builds, log event loop stalls to dropbox for analysis.
991 if (StrictMode.conditionallyEnableDebugLogging()) {
992 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
993 }
994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 Looper.loop();
996 }
997 }
998
999 private WindowManagerService(Context context, PowerManagerService pm,
1000 boolean haveInputMethods) {
1001 mContext = context;
1002 mHaveInputMethods = haveInputMethods;
1003 mLimitedAlphaCompositing = context.getResources().getBoolean(
1004 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 mPowerManager = pm;
1007 mPowerManager.setPolicy(mPolicy);
1008 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1009 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1010 "SCREEN_FROZEN");
1011 mScreenFrozenLock.setReferenceCounted(false);
1012
1013 mActivityManager = ActivityManagerNative.getDefault();
1014 mBatteryStats = BatteryStatsService.getService();
1015
1016 // Get persisted window scale setting
1017 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1018 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1019 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1020 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001021
Jim Miller284b62e2010-06-08 14:27:42 -07001022 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1023 IntentFilter filter = new IntentFilter();
1024 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1025 mContext.registerReceiver(mBroadcastReceiver, filter);
1026
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001027 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1028 "KEEP_SCREEN_ON_FLAG");
1029 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030
Jeff Browne33348b2010-07-15 23:54:05 -07001031 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1034 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 synchronized (thr) {
1037 while (!thr.mRunning) {
1038 try {
1039 thr.wait();
1040 } catch (InterruptedException e) {
1041 }
1042 }
1043 }
Romain Guy06882f82009-06-10 13:36:04 -07001044
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001045 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 // Add ourself to the Watchdog monitors.
1048 Watchdog.getInstance().addMonitor(this);
1049 }
1050
1051 @Override
1052 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1053 throws RemoteException {
1054 try {
1055 return super.onTransact(code, data, reply, flags);
1056 } catch (RuntimeException e) {
1057 // The window manager only throws security exceptions, so let's
1058 // log all others.
1059 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001060 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 }
1062 throw e;
1063 }
1064 }
1065
Jeff Browne33348b2010-07-15 23:54:05 -07001066 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 TAG, "Adding window " + window + " at "
1070 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1071 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001072 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 }
1074
Jeff Browne33348b2010-07-15 23:54:05 -07001075 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001077 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 TAG, "Adding window " + window + " at "
1079 + i + " of " + mWindows.size() + " (before " + pos + ")");
1080 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001081 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 }
1083
1084 //This method finds out the index of a window that has the same app token as
1085 //win. used for z ordering the windows in mWindows
1086 private int findIdxBasedOnAppTokens(WindowState win) {
1087 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001088 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 int jmax = localmWindows.size();
1090 if(jmax == 0) {
1091 return -1;
1092 }
1093 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001094 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 if(wentry.mAppToken == win.mAppToken) {
1096 return j;
1097 }
1098 }
1099 return -1;
1100 }
Romain Guy06882f82009-06-10 13:36:04 -07001101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1103 final IWindow client = win.mClient;
1104 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001105 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 final int N = localmWindows.size();
1108 final WindowState attached = win.mAttachedWindow;
1109 int i;
1110 if (attached == null) {
1111 int tokenWindowsPos = token.windows.size();
1112 if (token.appWindowToken != null) {
1113 int index = tokenWindowsPos-1;
1114 if (index >= 0) {
1115 // If this application has existing windows, we
1116 // simply place the new window on top of them... but
1117 // keep the starting window on top.
1118 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1119 // Base windows go behind everything else.
1120 placeWindowBefore(token.windows.get(0), win);
1121 tokenWindowsPos = 0;
1122 } else {
1123 AppWindowToken atoken = win.mAppToken;
1124 if (atoken != null &&
1125 token.windows.get(index) == atoken.startingWindow) {
1126 placeWindowBefore(token.windows.get(index), win);
1127 tokenWindowsPos--;
1128 } else {
1129 int newIdx = findIdxBasedOnAppTokens(win);
1130 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001131 //there is a window above this one associated with the same
1132 //apptoken note that the window could be a floating window
1133 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001135 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001136 TAG, "Adding window " + win + " at "
1137 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001139 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 }
1142 }
1143 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001144 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 TAG, "Figuring out where to add app window "
1146 + client.asBinder() + " (token=" + token + ")");
1147 // Figure out where the window should go, based on the
1148 // order of applications.
1149 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001150 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 for (i=NA-1; i>=0; i--) {
1152 AppWindowToken t = mAppTokens.get(i);
1153 if (t == token) {
1154 i--;
1155 break;
1156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001157
Dianne Hackborna8f60182009-09-01 19:01:50 -07001158 // We haven't reached the token yet; if this token
1159 // is not going to the bottom and has windows, we can
1160 // use it as an anchor for when we do reach the token.
1161 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 pos = t.windows.get(0);
1163 }
1164 }
1165 // We now know the index into the apps. If we found
1166 // an app window above, that gives us the position; else
1167 // we need to look some more.
1168 if (pos != null) {
1169 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001170 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 if (atoken != null) {
1172 final int NC = atoken.windows.size();
1173 if (NC > 0) {
1174 WindowState bottom = atoken.windows.get(0);
1175 if (bottom.mSubLayer < 0) {
1176 pos = bottom;
1177 }
1178 }
1179 }
1180 placeWindowBefore(pos, win);
1181 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001182 // Continue looking down until we find the first
1183 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 while (i >= 0) {
1185 AppWindowToken t = mAppTokens.get(i);
1186 final int NW = t.windows.size();
1187 if (NW > 0) {
1188 pos = t.windows.get(NW-1);
1189 break;
1190 }
1191 i--;
1192 }
1193 if (pos != null) {
1194 // Move in front of any windows attached to this
1195 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001196 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 if (atoken != null) {
1198 final int NC = atoken.windows.size();
1199 if (NC > 0) {
1200 WindowState top = atoken.windows.get(NC-1);
1201 if (top.mSubLayer >= 0) {
1202 pos = top;
1203 }
1204 }
1205 }
1206 placeWindowAfter(pos, win);
1207 } else {
1208 // Just search for the start of this layer.
1209 final int myLayer = win.mBaseLayer;
1210 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001211 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 if (w.mBaseLayer > myLayer) {
1213 break;
1214 }
1215 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001216 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001217 TAG, "Adding window " + win + " at "
1218 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001220 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 }
1222 }
1223 }
1224 } else {
1225 // Figure out where window should go, based on layer.
1226 final int myLayer = win.mBaseLayer;
1227 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001228 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 i++;
1230 break;
1231 }
1232 }
1233 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001234 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001235 TAG, "Adding window " + win + " at "
1236 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001238 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 }
1240 if (addToToken) {
1241 token.windows.add(tokenWindowsPos, win);
1242 }
1243
1244 } else {
1245 // Figure out this window's ordering relative to the window
1246 // it is attached to.
1247 final int NA = token.windows.size();
1248 final int sublayer = win.mSubLayer;
1249 int largestSublayer = Integer.MIN_VALUE;
1250 WindowState windowWithLargestSublayer = null;
1251 for (i=0; i<NA; i++) {
1252 WindowState w = token.windows.get(i);
1253 final int wSublayer = w.mSubLayer;
1254 if (wSublayer >= largestSublayer) {
1255 largestSublayer = wSublayer;
1256 windowWithLargestSublayer = w;
1257 }
1258 if (sublayer < 0) {
1259 // For negative sublayers, we go below all windows
1260 // in the same sublayer.
1261 if (wSublayer >= sublayer) {
1262 if (addToToken) {
1263 token.windows.add(i, win);
1264 }
1265 placeWindowBefore(
1266 wSublayer >= 0 ? attached : w, win);
1267 break;
1268 }
1269 } else {
1270 // For positive sublayers, we go above all windows
1271 // in the same sublayer.
1272 if (wSublayer > sublayer) {
1273 if (addToToken) {
1274 token.windows.add(i, win);
1275 }
1276 placeWindowBefore(w, win);
1277 break;
1278 }
1279 }
1280 }
1281 if (i >= NA) {
1282 if (addToToken) {
1283 token.windows.add(win);
1284 }
1285 if (sublayer < 0) {
1286 placeWindowBefore(attached, win);
1287 } else {
1288 placeWindowAfter(largestSublayer >= 0
1289 ? windowWithLargestSublayer
1290 : attached,
1291 win);
1292 }
1293 }
1294 }
Romain Guy06882f82009-06-10 13:36:04 -07001295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 if (win.mAppToken != null && addToToken) {
1297 win.mAppToken.allAppWindows.add(win);
1298 }
1299 }
Romain Guy06882f82009-06-10 13:36:04 -07001300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 static boolean canBeImeTarget(WindowState w) {
1302 final int fl = w.mAttrs.flags
1303 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1304 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1305 return w.isVisibleOrAdding();
1306 }
1307 return false;
1308 }
Romain Guy06882f82009-06-10 13:36:04 -07001309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001311 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 final int N = localmWindows.size();
1313 WindowState w = null;
1314 int i = N;
1315 while (i > 0) {
1316 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001317 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001318
Joe Onorato8a9b2202010-02-26 18:56:32 -08001319 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 // + Integer.toHexString(w.mAttrs.flags));
1321 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001322 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 // Yet more tricksyness! If this window is a "starting"
1325 // window, we do actually want to be on top of it, but
1326 // it is not -really- where input will go. So if the caller
1327 // is not actually looking to move the IME, look down below
1328 // for a real window to target...
1329 if (!willMove
1330 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1331 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001332 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1334 i--;
1335 w = wb;
1336 }
1337 }
1338 break;
1339 }
1340 }
Romain Guy06882f82009-06-10 13:36:04 -07001341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001343
Joe Onorato8a9b2202010-02-26 18:56:32 -08001344 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 if (willMove && w != null) {
1348 final WindowState curTarget = mInputMethodTarget;
1349 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 // Now some fun for dealing with window animations that
1352 // modify the Z order. We need to look at all windows below
1353 // the current target that are in this app, finding the highest
1354 // visible one in layering.
1355 AppWindowToken token = curTarget.mAppToken;
1356 WindowState highestTarget = null;
1357 int highestPos = 0;
1358 if (token.animating || token.animation != null) {
1359 int pos = 0;
1360 pos = localmWindows.indexOf(curTarget);
1361 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001362 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363 if (win.mAppToken != token) {
1364 break;
1365 }
1366 if (!win.mRemoved) {
1367 if (highestTarget == null || win.mAnimLayer >
1368 highestTarget.mAnimLayer) {
1369 highestTarget = win;
1370 highestPos = pos;
1371 }
1372 }
1373 pos--;
1374 }
1375 }
Romain Guy06882f82009-06-10 13:36:04 -07001376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001378 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 + mNextAppTransition + " " + highestTarget
1380 + " animating=" + highestTarget.isAnimating()
1381 + " layer=" + highestTarget.mAnimLayer
1382 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001383
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001384 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 // If we are currently setting up for an animation,
1386 // hold everything until we can find out what will happen.
1387 mInputMethodTargetWaitingAnim = true;
1388 mInputMethodTarget = highestTarget;
1389 return highestPos + 1;
1390 } else if (highestTarget.isAnimating() &&
1391 highestTarget.mAnimLayer > w.mAnimLayer) {
1392 // If the window we are currently targeting is involved
1393 // with an animation, and it is on top of the next target
1394 // we will be over, then hold off on moving until
1395 // that is done.
1396 mInputMethodTarget = highestTarget;
1397 return highestPos + 1;
1398 }
1399 }
1400 }
1401 }
Romain Guy06882f82009-06-10 13:36:04 -07001402
Joe Onorato8a9b2202010-02-26 18:56:32 -08001403 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 if (w != null) {
1405 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001406 if (DEBUG_INPUT_METHOD) {
1407 RuntimeException e = null;
1408 if (!HIDE_STACK_CRAWLS) {
1409 e = new RuntimeException();
1410 e.fillInStackTrace();
1411 }
1412 Slog.w(TAG, "Moving IM target from "
1413 + mInputMethodTarget + " to " + w, e);
1414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 mInputMethodTarget = w;
1416 if (w.mAppToken != null) {
1417 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1418 } else {
1419 setInputMethodAnimLayerAdjustment(0);
1420 }
1421 }
1422 return i+1;
1423 }
1424 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001425 if (DEBUG_INPUT_METHOD) {
1426 RuntimeException e = null;
1427 if (!HIDE_STACK_CRAWLS) {
1428 e = new RuntimeException();
1429 e.fillInStackTrace();
1430 }
1431 Slog.w(TAG, "Moving IM target from "
1432 + mInputMethodTarget + " to null", e);
1433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 mInputMethodTarget = null;
1435 setInputMethodAnimLayerAdjustment(0);
1436 }
1437 return -1;
1438 }
Romain Guy06882f82009-06-10 13:36:04 -07001439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 void addInputMethodWindowToListLocked(WindowState win) {
1441 int pos = findDesiredInputMethodWindowIndexLocked(true);
1442 if (pos >= 0) {
1443 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001444 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001445 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001447 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 moveInputMethodDialogsLocked(pos+1);
1449 return;
1450 }
1451 win.mTargetAppToken = null;
1452 addWindowToListInOrderLocked(win, true);
1453 moveInputMethodDialogsLocked(pos);
1454 }
Romain Guy06882f82009-06-10 13:36:04 -07001455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001457 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 mInputMethodAnimLayerAdjustment = adj;
1459 WindowState imw = mInputMethodWindow;
1460 if (imw != null) {
1461 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 + " anim layer: " + imw.mAnimLayer);
1464 int wi = imw.mChildWindows.size();
1465 while (wi > 0) {
1466 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001467 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001469 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 + " anim layer: " + cw.mAnimLayer);
1471 }
1472 }
1473 int di = mInputMethodDialogs.size();
1474 while (di > 0) {
1475 di --;
1476 imw = mInputMethodDialogs.get(di);
1477 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001478 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 + " anim layer: " + imw.mAnimLayer);
1480 }
1481 }
Romain Guy06882f82009-06-10 13:36:04 -07001482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1484 int wpos = mWindows.indexOf(win);
1485 if (wpos >= 0) {
1486 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001487 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001489 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 int NC = win.mChildWindows.size();
1491 while (NC > 0) {
1492 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001493 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 int cpos = mWindows.indexOf(cw);
1495 if (cpos >= 0) {
1496 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001497 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001498 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 mWindows.remove(cpos);
1500 }
1501 }
1502 }
1503 return interestingPos;
1504 }
Romain Guy06882f82009-06-10 13:36:04 -07001505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 private void reAddWindowToListInOrderLocked(WindowState win) {
1507 addWindowToListInOrderLocked(win, false);
1508 // This is a hack to get all of the child windows added as well
1509 // at the right position. Child windows should be rare and
1510 // this case should be rare, so it shouldn't be that big a deal.
1511 int wpos = mWindows.indexOf(win);
1512 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001513 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001514 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001516 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 reAddWindowLocked(wpos, win);
1518 }
1519 }
Romain Guy06882f82009-06-10 13:36:04 -07001520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 void logWindowList(String prefix) {
1522 int N = mWindows.size();
1523 while (N > 0) {
1524 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001525 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 }
1527 }
Romain Guy06882f82009-06-10 13:36:04 -07001528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 void moveInputMethodDialogsLocked(int pos) {
1530 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001533 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 for (int i=0; i<N; i++) {
1535 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1536 }
1537 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001538 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 logWindowList(" ");
1540 }
Romain Guy06882f82009-06-10 13:36:04 -07001541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 if (pos >= 0) {
1543 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1544 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001545 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 if (wp == mInputMethodWindow) {
1547 pos++;
1548 }
1549 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001550 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 for (int i=0; i<N; i++) {
1552 WindowState win = dialogs.get(i);
1553 win.mTargetAppToken = targetAppToken;
1554 pos = reAddWindowLocked(pos, win);
1555 }
1556 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001557 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 logWindowList(" ");
1559 }
1560 return;
1561 }
1562 for (int i=0; i<N; i++) {
1563 WindowState win = dialogs.get(i);
1564 win.mTargetAppToken = null;
1565 reAddWindowToListInOrderLocked(win);
1566 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 logWindowList(" ");
1569 }
1570 }
1571 }
Romain Guy06882f82009-06-10 13:36:04 -07001572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1574 final WindowState imWin = mInputMethodWindow;
1575 final int DN = mInputMethodDialogs.size();
1576 if (imWin == null && DN == 0) {
1577 return false;
1578 }
Romain Guy06882f82009-06-10 13:36:04 -07001579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1581 if (imPos >= 0) {
1582 // In this case, the input method windows are to be placed
1583 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 // First check to see if the input method windows are already
1586 // located here, and contiguous.
1587 final int N = mWindows.size();
1588 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001589 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 // Figure out the actual input method window that should be
1592 // at the bottom of their stack.
1593 WindowState baseImWin = imWin != null
1594 ? imWin : mInputMethodDialogs.get(0);
1595 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001596 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 if (cw.mSubLayer < 0) baseImWin = cw;
1598 }
Romain Guy06882f82009-06-10 13:36:04 -07001599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 if (firstImWin == baseImWin) {
1601 // The windows haven't moved... but are they still contiguous?
1602 // First find the top IM window.
1603 int pos = imPos+1;
1604 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001605 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 break;
1607 }
1608 pos++;
1609 }
1610 pos++;
1611 // Now there should be no more input method windows above.
1612 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001613 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 break;
1615 }
1616 pos++;
1617 }
1618 if (pos >= N) {
1619 // All is good!
1620 return false;
1621 }
1622 }
Romain Guy06882f82009-06-10 13:36:04 -07001623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 if (imWin != null) {
1625 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 logWindowList(" ");
1628 }
1629 imPos = tmpRemoveWindowLocked(imPos, imWin);
1630 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001631 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 logWindowList(" ");
1633 }
1634 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1635 reAddWindowLocked(imPos, imWin);
1636 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001637 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 logWindowList(" ");
1639 }
1640 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1641 } else {
1642 moveInputMethodDialogsLocked(imPos);
1643 }
Romain Guy06882f82009-06-10 13:36:04 -07001644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 } else {
1646 // In this case, the input method windows go in a fixed layer,
1647 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001650 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 tmpRemoveWindowLocked(0, imWin);
1652 imWin.mTargetAppToken = null;
1653 reAddWindowToListInOrderLocked(imWin);
1654 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 logWindowList(" ");
1657 }
1658 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1659 } else {
1660 moveInputMethodDialogsLocked(-1);;
1661 }
Romain Guy06882f82009-06-10 13:36:04 -07001662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 }
Romain Guy06882f82009-06-10 13:36:04 -07001664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 if (needAssignLayers) {
1666 assignLayersLocked();
1667 }
Romain Guy06882f82009-06-10 13:36:04 -07001668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 return true;
1670 }
Romain Guy06882f82009-06-10 13:36:04 -07001671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 void adjustInputMethodDialogsLocked() {
1673 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1674 }
Romain Guy06882f82009-06-10 13:36:04 -07001675
Dianne Hackborn25994b42009-09-04 14:21:19 -07001676 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001678 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1679 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1680 ? wallpaperTarget.mAppToken.animation : null)
1681 + " upper=" + mUpperWallpaperTarget
1682 + " lower=" + mLowerWallpaperTarget);
1683 return (wallpaperTarget != null
1684 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1685 && wallpaperTarget.mAppToken.animation != null)))
1686 || mUpperWallpaperTarget != null
1687 || mLowerWallpaperTarget != null;
1688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001689
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001690 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1691 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001693 int adjustWallpaperWindowsLocked() {
1694 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001695
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001696 final int dw = mDisplay.getWidth();
1697 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001698
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001699 // First find top-most window that has asked to be on top of the
1700 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001701 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001702 int N = localmWindows.size();
1703 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001704 WindowState foundW = null;
1705 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001706 WindowState topCurW = null;
1707 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001708 int i = N;
1709 while (i > 0) {
1710 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001711 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001712 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1713 if (topCurW == null) {
1714 topCurW = w;
1715 topCurI = i;
1716 }
1717 continue;
1718 }
1719 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001720 if (w.mAppToken != null) {
1721 // If this window's app token is hidden and not animating,
1722 // it is of no interest to us.
1723 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001724 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001725 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001726 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001727 continue;
1728 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001729 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001730 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001731 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1732 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001733 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001734 && (mWallpaperTarget == w
1735 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001736 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001737 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001738 foundW = w;
1739 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001740 if (w == mWallpaperTarget && ((w.mAppToken != null
1741 && w.mAppToken.animation != null)
1742 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001743 // The current wallpaper target is animating, so we'll
1744 // look behind it for another possible target and figure
1745 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001746 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001747 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001748 continue;
1749 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001750 break;
1751 }
1752 }
1753
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001754 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001755 // If we are currently waiting for an app transition, and either
1756 // the current target or the next target are involved with it,
1757 // then hold off on doing anything with the wallpaper.
1758 // Note that we are checking here for just whether the target
1759 // is part of an app token... which is potentially overly aggressive
1760 // (the app token may not be involved in the transition), but good
1761 // enough (we'll just wait until whatever transition is pending
1762 // executes).
1763 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001764 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001765 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001766 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001767 }
1768 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001771 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001772 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001774
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001775 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001776 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001777 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001778 + " oldTarget: " + mWallpaperTarget);
1779 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001780
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001781 mLowerWallpaperTarget = null;
1782 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001783
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001784 WindowState oldW = mWallpaperTarget;
1785 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001786
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001787 // Now what is happening... if the current and new targets are
1788 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001789 if (foundW != null && oldW != null) {
1790 boolean oldAnim = oldW.mAnimation != null
1791 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1792 boolean foundAnim = foundW.mAnimation != null
1793 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001794 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001795 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001796 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001798 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001799 int oldI = localmWindows.indexOf(oldW);
1800 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001801 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001802 }
1803 if (oldI >= 0) {
1804 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001805 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 + "=" + oldW + "; new#" + foundI
1807 + "=" + foundW);
1808 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001809
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001810 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001811 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001812 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 }
1815 mWallpaperTarget = oldW;
1816 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001817
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 // Now set the upper and lower wallpaper targets
1819 // correctly, and make sure that we are positioning
1820 // the wallpaper below the lower.
1821 if (foundI > oldI) {
1822 // The new target is on top of the old one.
1823 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001824 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001825 }
1826 mUpperWallpaperTarget = foundW;
1827 mLowerWallpaperTarget = oldW;
1828 foundW = oldW;
1829 foundI = oldI;
1830 } else {
1831 // The new target is below the old one.
1832 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001834 }
1835 mUpperWallpaperTarget = oldW;
1836 mLowerWallpaperTarget = foundW;
1837 }
1838 }
1839 }
1840 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001842 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001843 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001844 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1845 || (mLowerWallpaperTarget.mAppToken != null
1846 && mLowerWallpaperTarget.mAppToken.animation != null);
1847 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1848 || (mUpperWallpaperTarget.mAppToken != null
1849 && mUpperWallpaperTarget.mAppToken.animation != null);
1850 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001851 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001852 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001853 }
1854 mLowerWallpaperTarget = null;
1855 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001856 }
1857 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001858
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001859 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001860 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001861 // The window is visible to the compositor... but is it visible
1862 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001863 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001864 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001865
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001866 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001867 // its layer adjustment. Only do this if we are not transfering
1868 // between two wallpaper targets.
1869 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001871 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001872
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001873 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1874 * TYPE_LAYER_MULTIPLIER
1875 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001876
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001877 // Now w is the window we are supposed to be behind... but we
1878 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001879 // AND any starting window associated with it, AND below the
1880 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001881 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001882 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001883 if (wb.mBaseLayer < maxLayer &&
1884 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001885 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001886 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001887 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001888 // This window is not related to the previous one in any
1889 // interesting way, so stop here.
1890 break;
1891 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001892 foundW = wb;
1893 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001894 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001895 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001896 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001898
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001899 if (foundW == null && topCurW != null) {
1900 // There is no wallpaper target, so it goes at the bottom.
1901 // We will assume it is the same place as last time, if known.
1902 foundW = topCurW;
1903 foundI = topCurI+1;
1904 } else {
1905 // Okay i is the position immediately above the wallpaper. Look at
1906 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001907 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001909
Dianne Hackborn284ac932009-08-28 10:34:25 -07001910 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001911 if (mWallpaperTarget.mWallpaperX >= 0) {
1912 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001913 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001914 }
1915 if (mWallpaperTarget.mWallpaperY >= 0) {
1916 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001917 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001918 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001920
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001921 // Start stepping backwards from here, ensuring that our wallpaper windows
1922 // are correctly placed.
1923 int curTokenIndex = mWallpaperTokens.size();
1924 while (curTokenIndex > 0) {
1925 curTokenIndex--;
1926 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001927 if (token.hidden == visible) {
1928 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1929 token.hidden = !visible;
1930 // Need to do a layout to ensure the wallpaper now has the
1931 // correct size.
1932 mLayoutNeeded = true;
1933 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001934
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001935 int curWallpaperIndex = token.windows.size();
1936 while (curWallpaperIndex > 0) {
1937 curWallpaperIndex--;
1938 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001939
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001940 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001941 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001942 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001943
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001944 // First, make sure the client has the current visibility
1945 // state.
1946 if (wallpaper.mWallpaperVisible != visible) {
1947 wallpaper.mWallpaperVisible = visible;
1948 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001949 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001950 "Setting visibility of wallpaper " + wallpaper
1951 + ": " + visible);
1952 wallpaper.mClient.dispatchAppVisibility(visible);
1953 } catch (RemoteException e) {
1954 }
1955 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001956
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001957 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001958 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001959 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001960
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001961 // First, if this window is at the current index, then all
1962 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001963 if (wallpaper == foundW) {
1964 foundI--;
1965 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001966 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001967 continue;
1968 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001969
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001970 // The window didn't match... the current wallpaper window,
1971 // wherever it is, is in the wrong place, so make sure it is
1972 // not in the list.
1973 int oldIndex = localmWindows.indexOf(wallpaper);
1974 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001975 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001976 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001977 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001978 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001979 if (oldIndex < foundI) {
1980 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 }
1982 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001983
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001984 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001985 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001986 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001987 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001989 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001990 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001991 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001992 }
1993 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001994
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001995 return changed;
1996 }
1997
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001998 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001999 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002000 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002001 mWallpaperAnimLayerAdjustment = adj;
2002 int curTokenIndex = mWallpaperTokens.size();
2003 while (curTokenIndex > 0) {
2004 curTokenIndex--;
2005 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2006 int curWallpaperIndex = token.windows.size();
2007 while (curWallpaperIndex > 0) {
2008 curWallpaperIndex--;
2009 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2010 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002012 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002013 }
2014 }
2015 }
2016
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002017 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2018 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002019 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002020 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002021 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002022 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002023 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2024 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2025 changed = wallpaperWin.mXOffset != offset;
2026 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002027 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002028 + wallpaperWin + " x: " + offset);
2029 wallpaperWin.mXOffset = offset;
2030 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002031 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002032 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002033 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002034 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002036
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002037 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002038 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002039 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2040 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2041 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002042 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002043 + wallpaperWin + " y: " + offset);
2044 changed = true;
2045 wallpaperWin.mYOffset = offset;
2046 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002047 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002048 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002049 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002050 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002051 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002052
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002053 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002054 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002055 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002056 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2057 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002058 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002059 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002060 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002061 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002062 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2063 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002064 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002065 if (mWaitingOnWallpaper != null) {
2066 long start = SystemClock.uptimeMillis();
2067 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2068 < start) {
2069 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002070 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002071 "Waiting for offset complete...");
2072 mWindowMap.wait(WALLPAPER_TIMEOUT);
2073 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002074 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002075 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002076 if ((start+WALLPAPER_TIMEOUT)
2077 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002078 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002079 + wallpaperWin);
2080 mLastWallpaperTimeoutTime = start;
2081 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002082 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002083 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002084 }
2085 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002086 } catch (RemoteException e) {
2087 }
2088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002089
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002090 return changed;
2091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002092
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002093 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002094 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002095 if (mWaitingOnWallpaper != null &&
2096 mWaitingOnWallpaper.mClient.asBinder() == window) {
2097 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002098 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002099 }
2100 }
2101 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002102
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002103 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002104 final int dw = mDisplay.getWidth();
2105 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002106
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002107 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002108
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002109 WindowState target = mWallpaperTarget;
2110 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002111 if (target.mWallpaperX >= 0) {
2112 mLastWallpaperX = target.mWallpaperX;
2113 } else if (changingTarget.mWallpaperX >= 0) {
2114 mLastWallpaperX = changingTarget.mWallpaperX;
2115 }
2116 if (target.mWallpaperY >= 0) {
2117 mLastWallpaperY = target.mWallpaperY;
2118 } else if (changingTarget.mWallpaperY >= 0) {
2119 mLastWallpaperY = changingTarget.mWallpaperY;
2120 }
2121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002122
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002123 int curTokenIndex = mWallpaperTokens.size();
2124 while (curTokenIndex > 0) {
2125 curTokenIndex--;
2126 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2127 int curWallpaperIndex = token.windows.size();
2128 while (curWallpaperIndex > 0) {
2129 curWallpaperIndex--;
2130 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2131 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2132 wallpaper.computeShownFrameLocked();
2133 changed = true;
2134 // We only want to be synchronous with one wallpaper.
2135 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002136 }
2137 }
2138 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002139
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002140 return changed;
2141 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002142
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002143 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002144 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002145 final int dw = mDisplay.getWidth();
2146 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002147
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002148 int curTokenIndex = mWallpaperTokens.size();
2149 while (curTokenIndex > 0) {
2150 curTokenIndex--;
2151 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002152 if (token.hidden == visible) {
2153 token.hidden = !visible;
2154 // Need to do a layout to ensure the wallpaper now has the
2155 // correct size.
2156 mLayoutNeeded = true;
2157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002158
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002159 int curWallpaperIndex = token.windows.size();
2160 while (curWallpaperIndex > 0) {
2161 curWallpaperIndex--;
2162 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2163 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002164 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002165 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002166
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002167 if (wallpaper.mWallpaperVisible != visible) {
2168 wallpaper.mWallpaperVisible = visible;
2169 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002170 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002171 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002172 + ": " + visible);
2173 wallpaper.mClient.dispatchAppVisibility(visible);
2174 } catch (RemoteException e) {
2175 }
2176 }
2177 }
2178 }
2179 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 public int addWindow(Session session, IWindow client,
2182 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002183 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 int res = mPolicy.checkAddPermission(attrs);
2185 if (res != WindowManagerImpl.ADD_OKAY) {
2186 return res;
2187 }
Romain Guy06882f82009-06-10 13:36:04 -07002188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 boolean reportNewConfig = false;
2190 WindowState attachedWindow = null;
2191 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002192 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002196 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 }
Romain Guy06882f82009-06-10 13:36:04 -07002198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002200 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2202 }
2203
2204 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002205 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002207 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 + attrs.token + ". Aborting.");
2209 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2210 }
2211 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2212 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002213 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 + attrs.token + ". Aborting.");
2215 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2216 }
2217 }
2218
2219 boolean addToken = false;
2220 WindowToken token = mTokenMap.get(attrs.token);
2221 if (token == null) {
2222 if (attrs.type >= FIRST_APPLICATION_WINDOW
2223 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002224 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 + attrs.token + ". Aborting.");
2226 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2227 }
2228 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002229 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 + attrs.token + ". Aborting.");
2231 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2232 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002233 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002234 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002235 + attrs.token + ". Aborting.");
2236 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 token = new WindowToken(attrs.token, -1, false);
2239 addToken = true;
2240 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2241 && attrs.type <= LAST_APPLICATION_WINDOW) {
2242 AppWindowToken atoken = token.appWindowToken;
2243 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002244 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 + token + ". Aborting.");
2246 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2247 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002248 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 + token + ". Aborting.");
2250 return WindowManagerImpl.ADD_APP_EXITING;
2251 }
2252 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2253 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002254 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2256 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2257 }
2258 } else if (attrs.type == TYPE_INPUT_METHOD) {
2259 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002260 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261 + attrs.token + ". Aborting.");
2262 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2263 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002264 } else if (attrs.type == TYPE_WALLPAPER) {
2265 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002266 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002267 + attrs.token + ". Aborting.");
2268 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 }
2271
2272 win = new WindowState(session, client, token,
2273 attachedWindow, attrs, viewVisibility);
2274 if (win.mDeathRecipient == null) {
2275 // Client has apparently died, so there is no reason to
2276 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002277 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 + " that is dead, aborting.");
2279 return WindowManagerImpl.ADD_APP_EXITING;
2280 }
2281
2282 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 res = mPolicy.prepareAddWindowLw(win, attrs);
2285 if (res != WindowManagerImpl.ADD_OKAY) {
2286 return res;
2287 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002288
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002289 if (outInputChannel != null) {
2290 String name = win.makeInputChannelName();
2291 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2292 win.mInputChannel = inputChannels[0];
2293 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2294
2295 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297
2298 // From now on, no exceptions or errors allowed!
2299
2300 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002301
Dianne Hackborn5132b372010-07-29 12:51:35 -07002302 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 if (addToken) {
2305 mTokenMap.put(attrs.token, token);
2306 mTokenList.add(token);
2307 }
2308 win.attach();
2309 mWindowMap.put(client.asBinder(), win);
2310
2311 if (attrs.type == TYPE_APPLICATION_STARTING &&
2312 token.appWindowToken != null) {
2313 token.appWindowToken.startingWindow = win;
2314 }
2315
2316 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 if (attrs.type == TYPE_INPUT_METHOD) {
2319 mInputMethodWindow = win;
2320 addInputMethodWindowToListLocked(win);
2321 imMayMove = false;
2322 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2323 mInputMethodDialogs.add(win);
2324 addWindowToListInOrderLocked(win, true);
2325 adjustInputMethodDialogsLocked();
2326 imMayMove = false;
2327 } else {
2328 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002329 if (attrs.type == TYPE_WALLPAPER) {
2330 mLastWallpaperTimeoutTime = 0;
2331 adjustWallpaperWindowsLocked();
2332 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002333 adjustWallpaperWindowsLocked();
2334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 }
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 if (mInTouchMode) {
2342 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2343 }
2344 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2345 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2346 }
Romain Guy06882f82009-06-10 13:36:04 -07002347
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002348 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002350 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2351 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 imMayMove = false;
2353 }
2354 }
Romain Guy06882f82009-06-10 13:36:04 -07002355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002357 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358 }
Romain Guy06882f82009-06-10 13:36:04 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 assignLayersLocked();
2361 // Don't do layout here, the window must call
2362 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 //dump();
2365
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002366 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002367 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002368 }
Jeff Brown349703e2010-06-22 01:27:15 -07002369
Joe Onorato8a9b2202010-02-26 18:56:32 -08002370 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 TAG, "New client " + client.asBinder()
2372 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002373
2374 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2375 reportNewConfig = true;
2376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 }
2378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002379 if (reportNewConfig) {
2380 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 return res;
2386 }
Romain Guy06882f82009-06-10 13:36:04 -07002387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 public void removeWindow(Session session, IWindow client) {
2389 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002390 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 if (win == null) {
2392 return;
2393 }
2394 removeWindowLocked(session, win);
2395 }
2396 }
Romain Guy06882f82009-06-10 13:36:04 -07002397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 public void removeWindowLocked(Session session, WindowState win) {
2399
Joe Onorato8a9b2202010-02-26 18:56:32 -08002400 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 TAG, "Remove " + win + " client="
2402 + Integer.toHexString(System.identityHashCode(
2403 win.mClient.asBinder()))
2404 + ", surface=" + win.mSurface);
2405
2406 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002407
2408 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002409
Joe Onorato8a9b2202010-02-26 18:56:32 -08002410 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2412 + " mExiting=" + win.mExiting
2413 + " isAnimating=" + win.isAnimating()
2414 + " app-animation="
2415 + (win.mAppToken != null ? win.mAppToken.animation : null)
2416 + " inPendingTransaction="
2417 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2418 + " mDisplayFrozen=" + mDisplayFrozen);
2419 // Visibility of the removed window. Will be used later to update orientation later on.
2420 boolean wasVisible = false;
2421 // First, see if we need to run an animation. If we do, we have
2422 // to hold off on removing the window until the animation is done.
2423 // If the display is frozen, just remove immediately, since the
2424 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002425 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 // If we are not currently running the exit animation, we
2427 // need to see about starting one.
2428 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2431 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2432 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2433 }
2434 // Try starting an animation.
2435 if (applyAnimationLocked(win, transit, false)) {
2436 win.mExiting = true;
2437 }
2438 }
2439 if (win.mExiting || win.isAnimating()) {
2440 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002441 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 win.mExiting = true;
2443 win.mRemoveOnExit = true;
2444 mLayoutNeeded = true;
2445 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2446 performLayoutAndPlaceSurfacesLocked();
2447 if (win.mAppToken != null) {
2448 win.mAppToken.updateReportedVisibilityLocked();
2449 }
2450 //dump();
2451 Binder.restoreCallingIdentity(origId);
2452 return;
2453 }
2454 }
2455
2456 removeWindowInnerLocked(session, win);
2457 // Removing a visible window will effect the computed orientation
2458 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002459 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002460 != mForcedAppOrientation
2461 && updateOrientationFromAppTokensLocked()) {
2462 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 }
2464 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2465 Binder.restoreCallingIdentity(origId);
2466 }
Romain Guy06882f82009-06-10 13:36:04 -07002467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 if (mInputMethodTarget == win) {
2472 moveInputMethodWindowsIfNeededLocked(false);
2473 }
Romain Guy06882f82009-06-10 13:36:04 -07002474
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002475 if (false) {
2476 RuntimeException e = new RuntimeException("here");
2477 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002478 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002479 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 mPolicy.removeWindowLw(win);
2482 win.removeLocked();
2483
2484 mWindowMap.remove(win.mClient.asBinder());
2485 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002486 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002487 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488
2489 if (mInputMethodWindow == win) {
2490 mInputMethodWindow = null;
2491 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2492 mInputMethodDialogs.remove(win);
2493 }
Romain Guy06882f82009-06-10 13:36:04 -07002494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 final WindowToken token = win.mToken;
2496 final AppWindowToken atoken = win.mAppToken;
2497 token.windows.remove(win);
2498 if (atoken != null) {
2499 atoken.allAppWindows.remove(win);
2500 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002501 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 TAG, "**** Removing window " + win + ": count="
2503 + token.windows.size());
2504 if (token.windows.size() == 0) {
2505 if (!token.explicit) {
2506 mTokenMap.remove(token.token);
2507 mTokenList.remove(token);
2508 } else if (atoken != null) {
2509 atoken.firstWindowDrawn = false;
2510 }
2511 }
2512
2513 if (atoken != null) {
2514 if (atoken.startingWindow == win) {
2515 atoken.startingWindow = null;
2516 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2517 // If this is the last window and we had requested a starting
2518 // transition window, well there is no point now.
2519 atoken.startingData = null;
2520 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2521 // If this is the last window except for a starting transition
2522 // window, we need to get rid of the starting transition.
2523 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002524 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 + ": no more real windows");
2526 }
2527 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2528 mH.sendMessage(m);
2529 }
2530 }
Romain Guy06882f82009-06-10 13:36:04 -07002531
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002532 if (win.mAttrs.type == TYPE_WALLPAPER) {
2533 mLastWallpaperTimeoutTime = 0;
2534 adjustWallpaperWindowsLocked();
2535 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002536 adjustWallpaperWindowsLocked();
2537 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 if (!mInLayout) {
2540 assignLayersLocked();
2541 mLayoutNeeded = true;
2542 performLayoutAndPlaceSurfacesLocked();
2543 if (win.mAppToken != null) {
2544 win.mAppToken.updateReportedVisibilityLocked();
2545 }
2546 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002547
2548 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 }
2550
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002551 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2552 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2553 + ": " + msg + " / " + w.mAttrs.getTitle();
2554 if (where != null) {
2555 Slog.i(TAG, str, where);
2556 } else {
2557 Slog.i(TAG, str);
2558 }
2559 }
2560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2562 long origId = Binder.clearCallingIdentity();
2563 try {
2564 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002565 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002567 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 Surface.openTransaction();
2569 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002570 if (SHOW_TRANSACTIONS) logSurface(w,
2571 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 w.mSurface.setTransparentRegionHint(region);
2573 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002574 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 Surface.closeTransaction();
2576 }
2577 }
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(origId);
2581 }
2582 }
2583
2584 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002585 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586 Rect visibleInsets) {
2587 long origId = Binder.clearCallingIdentity();
2588 try {
2589 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002590 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 if (w != null) {
2592 w.mGivenInsetsPending = false;
2593 w.mGivenContentInsets.set(contentInsets);
2594 w.mGivenVisibleInsets.set(visibleInsets);
2595 w.mTouchableInsets = touchableInsets;
2596 mLayoutNeeded = true;
2597 performLayoutAndPlaceSurfacesLocked();
2598 }
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(origId);
2602 }
2603 }
Romain Guy06882f82009-06-10 13:36:04 -07002604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 public void getWindowDisplayFrame(Session session, IWindow client,
2606 Rect outDisplayFrame) {
2607 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002608 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 if (win == null) {
2610 outDisplayFrame.setEmpty();
2611 return;
2612 }
2613 outDisplayFrame.set(win.mDisplayFrame);
2614 }
2615 }
2616
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002617 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2618 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002619 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2620 window.mWallpaperX = x;
2621 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002622 window.mWallpaperXStep = xStep;
2623 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002624 if (updateWallpaperOffsetLocked(window, true)) {
2625 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002626 }
2627 }
2628 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002629
Dianne Hackborn75804932009-10-20 20:15:20 -07002630 void wallpaperCommandComplete(IBinder window, Bundle result) {
2631 synchronized (mWindowMap) {
2632 if (mWaitingOnWallpaper != null &&
2633 mWaitingOnWallpaper.mClient.asBinder() == window) {
2634 mWaitingOnWallpaper = null;
2635 mWindowMap.notifyAll();
2636 }
2637 }
2638 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002639
Dianne Hackborn75804932009-10-20 20:15:20 -07002640 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2641 String action, int x, int y, int z, Bundle extras, boolean sync) {
2642 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2643 || window == mUpperWallpaperTarget) {
2644 boolean doWait = sync;
2645 int curTokenIndex = mWallpaperTokens.size();
2646 while (curTokenIndex > 0) {
2647 curTokenIndex--;
2648 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2649 int curWallpaperIndex = token.windows.size();
2650 while (curWallpaperIndex > 0) {
2651 curWallpaperIndex--;
2652 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2653 try {
2654 wallpaper.mClient.dispatchWallpaperCommand(action,
2655 x, y, z, extras, sync);
2656 // We only want to be synchronous with one wallpaper.
2657 sync = false;
2658 } catch (RemoteException e) {
2659 }
2660 }
2661 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002662
Dianne Hackborn75804932009-10-20 20:15:20 -07002663 if (doWait) {
2664 // XXX Need to wait for result.
2665 }
2666 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002667
Dianne Hackborn75804932009-10-20 20:15:20 -07002668 return null;
2669 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 public int relayoutWindow(Session session, IWindow client,
2672 WindowManager.LayoutParams attrs, int requestedWidth,
2673 int requestedHeight, int viewVisibility, boolean insetsPending,
2674 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002675 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 boolean displayed = false;
2677 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002678 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002681 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002682 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 if (win == null) {
2684 return 0;
2685 }
2686 win.mRequestedWidth = requestedWidth;
2687 win.mRequestedHeight = requestedHeight;
2688
2689 if (attrs != null) {
2690 mPolicy.adjustWindowParamsLw(attrs);
2691 }
Romain Guy06882f82009-06-10 13:36:04 -07002692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 int attrChanges = 0;
2694 int flagChanges = 0;
2695 if (attrs != null) {
2696 flagChanges = win.mAttrs.flags ^= attrs.flags;
2697 attrChanges = win.mAttrs.copyFrom(attrs);
2698 }
2699
Joe Onorato8a9b2202010-02-26 18:56:32 -08002700 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701
2702 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2703 win.mAlpha = attrs.alpha;
2704 }
2705
2706 final boolean scaledWindow =
2707 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2708
2709 if (scaledWindow) {
2710 // requested{Width|Height} Surface's physical size
2711 // attrs.{width|height} Size on screen
2712 win.mHScale = (attrs.width != requestedWidth) ?
2713 (attrs.width / (float)requestedWidth) : 1.0f;
2714 win.mVScale = (attrs.height != requestedHeight) ?
2715 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002716 } else {
2717 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 }
2719
2720 boolean imMayMove = (flagChanges&(
2721 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2722 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002724 boolean focusMayChange = win.mViewVisibility != viewVisibility
2725 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2726 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002727
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002728 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2729 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 win.mRelayoutCalled = true;
2732 final int oldVisibility = win.mViewVisibility;
2733 win.mViewVisibility = viewVisibility;
2734 if (viewVisibility == View.VISIBLE &&
2735 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2736 displayed = !win.isVisibleLw();
2737 if (win.mExiting) {
2738 win.mExiting = false;
2739 win.mAnimation = null;
2740 }
2741 if (win.mDestroying) {
2742 win.mDestroying = false;
2743 mDestroySurface.remove(win);
2744 }
2745 if (oldVisibility == View.GONE) {
2746 win.mEnterAnimationPending = true;
2747 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002748 if (displayed) {
2749 if (win.mSurface != null && !win.mDrawPending
2750 && !win.mCommitDrawPending && !mDisplayFrozen
2751 && mPolicy.isScreenOn()) {
2752 applyEnterAnimationLocked(win);
2753 }
2754 if ((win.mAttrs.flags
2755 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2756 if (DEBUG_VISIBILITY) Slog.v(TAG,
2757 "Relayout window turning screen on: " + win);
2758 win.mTurnOnScreen = true;
2759 }
2760 int diff = 0;
2761 if (win.mConfiguration != mCurConfiguration
2762 && (win.mConfiguration == null
2763 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2764 win.mConfiguration = mCurConfiguration;
2765 if (DEBUG_CONFIGURATION) {
2766 Slog.i(TAG, "Window " + win + " visible with new config: "
2767 + win.mConfiguration + " / 0x"
2768 + Integer.toHexString(diff));
2769 }
2770 outConfig.setTo(mCurConfiguration);
2771 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002772 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2774 // To change the format, we need to re-build the surface.
2775 win.destroySurfaceLocked();
2776 displayed = true;
2777 }
2778 try {
2779 Surface surface = win.createSurfaceLocked();
2780 if (surface != null) {
2781 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002782 win.mReportDestroySurface = false;
2783 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002784 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002785 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002787 // For some reason there isn't a surface. Clear the
2788 // caller's object so they see the same state.
2789 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 }
2791 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002792 mInputMonitor.updateInputWindowsLw();
2793
Joe Onorato8a9b2202010-02-26 18:56:32 -08002794 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002795 + client + " (" + win.mAttrs.getTitle() + ")",
2796 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 Binder.restoreCallingIdentity(origId);
2798 return 0;
2799 }
2800 if (displayed) {
2801 focusMayChange = true;
2802 }
2803 if (win.mAttrs.type == TYPE_INPUT_METHOD
2804 && mInputMethodWindow == null) {
2805 mInputMethodWindow = win;
2806 imMayMove = true;
2807 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002808 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2809 && win.mAppToken != null
2810 && win.mAppToken.startingWindow != null) {
2811 // Special handling of starting window over the base
2812 // window of the app: propagate lock screen flags to it,
2813 // to provide the correct semantics while starting.
2814 final int mask =
2815 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002816 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2817 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002818 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2819 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2820 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 } else {
2822 win.mEnterAnimationPending = false;
2823 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002824 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002825 + ": mExiting=" + win.mExiting
2826 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 // If we are not currently running the exit animation, we
2828 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002829 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 // Try starting an animation; if there isn't one, we
2831 // can destroy the surface right away.
2832 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2833 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2834 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2835 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002836 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002838 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 } else if (win.isAnimating()) {
2841 // Currently in a hide animation... turn this into
2842 // an exit.
2843 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002844 } else if (win == mWallpaperTarget) {
2845 // If the wallpaper is currently behind this
2846 // window, we need to change both of them inside
2847 // of a transaction to avoid artifacts.
2848 win.mExiting = true;
2849 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 } else {
2851 if (mInputMethodWindow == win) {
2852 mInputMethodWindow = null;
2853 }
2854 win.destroySurfaceLocked();
2855 }
2856 }
2857 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002858
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002859 if (win.mSurface == null || (win.getAttrs().flags
2860 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2861 || win.mSurfacePendingDestroy) {
2862 // We are being called from a local process, which
2863 // means outSurface holds its current surface. Ensure the
2864 // surface object is cleared, but we don't want it actually
2865 // destroyed at this point.
2866 win.mSurfacePendingDestroy = false;
2867 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002868 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002869 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002870 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002871 "Keeping surface, will report destroy: " + win);
2872 win.mReportDestroySurface = true;
2873 outSurface.copyFrom(win.mSurface);
2874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 }
2876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 if (focusMayChange) {
2878 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2879 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 imMayMove = false;
2881 }
2882 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2883 }
Romain Guy06882f82009-06-10 13:36:04 -07002884
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002885 // updateFocusedWindowLocked() already assigned layers so we only need to
2886 // reassign them at this point if the IM window state gets shuffled
2887 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002890 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2891 // Little hack here -- we -should- be able to rely on the
2892 // function to return true if the IME has moved and needs
2893 // its layer recomputed. However, if the IME was hidden
2894 // and isn't actually moved in the list, its layer may be
2895 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 assignLayers = true;
2897 }
2898 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002899 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002900 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002901 assignLayers = true;
2902 }
2903 }
Romain Guy06882f82009-06-10 13:36:04 -07002904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 mLayoutNeeded = true;
2906 win.mGivenInsetsPending = insetsPending;
2907 if (assignLayers) {
2908 assignLayersLocked();
2909 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002910 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002912 if (displayed && win.mIsWallpaper) {
2913 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002914 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002915 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 if (win.mAppToken != null) {
2917 win.mAppToken.updateReportedVisibilityLocked();
2918 }
2919 outFrame.set(win.mFrame);
2920 outContentInsets.set(win.mContentInsets);
2921 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002922 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002924 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 + ", requestedHeight=" + requestedHeight
2926 + ", viewVisibility=" + viewVisibility
2927 + "\nRelayout returning frame=" + outFrame
2928 + ", surface=" + outSurface);
2929
Joe Onorato8a9b2202010-02-26 18:56:32 -08002930 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2932
2933 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002934
2935 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002936 }
2937
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002938 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 sendNewConfiguration();
2940 }
Romain Guy06882f82009-06-10 13:36:04 -07002941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002944 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2945 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2946 }
2947
2948 public void finishDrawingWindow(Session session, IWindow client) {
2949 final long origId = Binder.clearCallingIdentity();
2950 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002951 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002953 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2954 adjustWallpaperWindowsLocked();
2955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 mLayoutNeeded = true;
2957 performLayoutAndPlaceSurfacesLocked();
2958 }
2959 }
2960 Binder.restoreCallingIdentity(origId);
2961 }
2962
2963 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002964 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 + (lp != null ? lp.packageName : null)
2966 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2967 if (lp != null && lp.windowAnimations != 0) {
2968 // If this is a system resource, don't try to load it from the
2969 // application resources. It is nice to avoid loading application
2970 // resources if we can.
2971 String packageName = lp.packageName != null ? lp.packageName : "android";
2972 int resId = lp.windowAnimations;
2973 if ((resId&0xFF000000) == 0x01000000) {
2974 packageName = "android";
2975 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002976 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 + packageName);
2978 return AttributeCache.instance().get(packageName, resId,
2979 com.android.internal.R.styleable.WindowAnimation);
2980 }
2981 return null;
2982 }
Romain Guy06882f82009-06-10 13:36:04 -07002983
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002984 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002985 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002986 + packageName + " resId=0x" + Integer.toHexString(resId));
2987 if (packageName != null) {
2988 if ((resId&0xFF000000) == 0x01000000) {
2989 packageName = "android";
2990 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002991 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002992 + packageName);
2993 return AttributeCache.instance().get(packageName, resId,
2994 com.android.internal.R.styleable.WindowAnimation);
2995 }
2996 return null;
2997 }
2998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 private void applyEnterAnimationLocked(WindowState win) {
3000 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3001 if (win.mEnterAnimationPending) {
3002 win.mEnterAnimationPending = false;
3003 transit = WindowManagerPolicy.TRANSIT_ENTER;
3004 }
3005
3006 applyAnimationLocked(win, transit, true);
3007 }
3008
3009 private boolean applyAnimationLocked(WindowState win,
3010 int transit, boolean isEntrance) {
3011 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3012 // If we are trying to apply an animation, but already running
3013 // an animation of the same type, then just leave that one alone.
3014 return true;
3015 }
Romain Guy06882f82009-06-10 13:36:04 -07003016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003017 // Only apply an animation if the display isn't frozen. If it is
3018 // frozen, there is no reason to animate and it can cause strange
3019 // artifacts when we unfreeze the display if some different animation
3020 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003021 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 int anim = mPolicy.selectAnimationLw(win, transit);
3023 int attr = -1;
3024 Animation a = null;
3025 if (anim != 0) {
3026 a = AnimationUtils.loadAnimation(mContext, anim);
3027 } else {
3028 switch (transit) {
3029 case WindowManagerPolicy.TRANSIT_ENTER:
3030 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3031 break;
3032 case WindowManagerPolicy.TRANSIT_EXIT:
3033 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3034 break;
3035 case WindowManagerPolicy.TRANSIT_SHOW:
3036 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3037 break;
3038 case WindowManagerPolicy.TRANSIT_HIDE:
3039 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3040 break;
3041 }
3042 if (attr >= 0) {
3043 a = loadAnimation(win.mAttrs, attr);
3044 }
3045 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003046 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3048 + " mAnimation=" + win.mAnimation
3049 + " isEntrance=" + isEntrance);
3050 if (a != null) {
3051 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003052 RuntimeException e = null;
3053 if (!HIDE_STACK_CRAWLS) {
3054 e = new RuntimeException();
3055 e.fillInStackTrace();
3056 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003057 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
3059 win.setAnimation(a);
3060 win.mAnimationIsEntrance = isEntrance;
3061 }
3062 } else {
3063 win.clearAnimation();
3064 }
3065
3066 return win.mAnimation != null;
3067 }
3068
3069 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3070 int anim = 0;
3071 Context context = mContext;
3072 if (animAttr >= 0) {
3073 AttributeCache.Entry ent = getCachedAnimations(lp);
3074 if (ent != null) {
3075 context = ent.context;
3076 anim = ent.array.getResourceId(animAttr, 0);
3077 }
3078 }
3079 if (anim != 0) {
3080 return AnimationUtils.loadAnimation(context, anim);
3081 }
3082 return null;
3083 }
Romain Guy06882f82009-06-10 13:36:04 -07003084
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003085 private Animation loadAnimation(String packageName, int resId) {
3086 int anim = 0;
3087 Context context = mContext;
3088 if (resId >= 0) {
3089 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3090 if (ent != null) {
3091 context = ent.context;
3092 anim = resId;
3093 }
3094 }
3095 if (anim != 0) {
3096 return AnimationUtils.loadAnimation(context, anim);
3097 }
3098 return null;
3099 }
3100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 private boolean applyAnimationLocked(AppWindowToken wtoken,
3102 WindowManager.LayoutParams lp, int transit, boolean enter) {
3103 // Only apply an animation if the display isn't frozen. If it is
3104 // frozen, there is no reason to animate and it can cause strange
3105 // artifacts when we unfreeze the display if some different animation
3106 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003107 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003108 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003109 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003110 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003111 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003112 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003113 } else if (mNextAppTransitionPackage != null) {
3114 a = loadAnimation(mNextAppTransitionPackage, enter ?
3115 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003116 } else {
3117 int animAttr = 0;
3118 switch (transit) {
3119 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3120 animAttr = enter
3121 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3122 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3123 break;
3124 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3125 animAttr = enter
3126 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3127 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3128 break;
3129 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3130 animAttr = enter
3131 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3132 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3133 break;
3134 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3135 animAttr = enter
3136 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3137 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3138 break;
3139 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3140 animAttr = enter
3141 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3142 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3143 break;
3144 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3145 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003146 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003147 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3148 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003149 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003150 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003151 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3152 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003153 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003154 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003155 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003156 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3157 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3158 break;
3159 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3160 animAttr = enter
3161 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3162 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3163 break;
3164 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3165 animAttr = enter
3166 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3167 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003168 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003169 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003170 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003171 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003172 + " anim=" + a
3173 + " animAttr=0x" + Integer.toHexString(animAttr)
3174 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 if (a != null) {
3177 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003178 RuntimeException e = null;
3179 if (!HIDE_STACK_CRAWLS) {
3180 e = new RuntimeException();
3181 e.fillInStackTrace();
3182 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003183 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 }
3185 wtoken.setAnimation(a);
3186 }
3187 } else {
3188 wtoken.clearAnimation();
3189 }
3190
3191 return wtoken.animation != null;
3192 }
3193
3194 // -------------------------------------------------------------
3195 // Application Window Tokens
3196 // -------------------------------------------------------------
3197
3198 public void validateAppTokens(List tokens) {
3199 int v = tokens.size()-1;
3200 int m = mAppTokens.size()-1;
3201 while (v >= 0 && m >= 0) {
3202 AppWindowToken wtoken = mAppTokens.get(m);
3203 if (wtoken.removed) {
3204 m--;
3205 continue;
3206 }
3207 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003208 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3210 }
3211 v--;
3212 m--;
3213 }
3214 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003215 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003216 v--;
3217 }
3218 while (m >= 0) {
3219 AppWindowToken wtoken = mAppTokens.get(m);
3220 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003221 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 }
3223 m--;
3224 }
3225 }
3226
3227 boolean checkCallingPermission(String permission, String func) {
3228 // Quick check: if the calling permission is me, it's all okay.
3229 if (Binder.getCallingPid() == Process.myPid()) {
3230 return true;
3231 }
Romain Guy06882f82009-06-10 13:36:04 -07003232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 if (mContext.checkCallingPermission(permission)
3234 == PackageManager.PERMISSION_GRANTED) {
3235 return true;
3236 }
3237 String msg = "Permission Denial: " + func + " from pid="
3238 + Binder.getCallingPid()
3239 + ", uid=" + Binder.getCallingUid()
3240 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003241 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 return false;
3243 }
Romain Guy06882f82009-06-10 13:36:04 -07003244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 AppWindowToken findAppWindowToken(IBinder token) {
3246 WindowToken wtoken = mTokenMap.get(token);
3247 if (wtoken == null) {
3248 return null;
3249 }
3250 return wtoken.appWindowToken;
3251 }
Romain Guy06882f82009-06-10 13:36:04 -07003252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003253 public void addWindowToken(IBinder token, int type) {
3254 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3255 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003256 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257 }
Romain Guy06882f82009-06-10 13:36:04 -07003258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 synchronized(mWindowMap) {
3260 WindowToken wtoken = mTokenMap.get(token);
3261 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003262 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 return;
3264 }
3265 wtoken = new WindowToken(token, type, true);
3266 mTokenMap.put(token, wtoken);
3267 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003268 if (type == TYPE_WALLPAPER) {
3269 mWallpaperTokens.add(wtoken);
3270 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003271 }
3272 }
Romain Guy06882f82009-06-10 13:36:04 -07003273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 public void removeWindowToken(IBinder token) {
3275 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3276 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003277 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 }
3279
3280 final long origId = Binder.clearCallingIdentity();
3281 synchronized(mWindowMap) {
3282 WindowToken wtoken = mTokenMap.remove(token);
3283 mTokenList.remove(wtoken);
3284 if (wtoken != null) {
3285 boolean delayed = false;
3286 if (!wtoken.hidden) {
3287 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003289 final int N = wtoken.windows.size();
3290 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 for (int i=0; i<N; i++) {
3293 WindowState win = wtoken.windows.get(i);
3294
3295 if (win.isAnimating()) {
3296 delayed = true;
3297 }
Romain Guy06882f82009-06-10 13:36:04 -07003298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 if (win.isVisibleNow()) {
3300 applyAnimationLocked(win,
3301 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 changed = true;
3303 }
3304 }
3305
3306 if (changed) {
3307 mLayoutNeeded = true;
3308 performLayoutAndPlaceSurfacesLocked();
3309 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3310 }
Romain Guy06882f82009-06-10 13:36:04 -07003311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 if (delayed) {
3313 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003314 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3315 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 }
3317 }
Romain Guy06882f82009-06-10 13:36:04 -07003318
Jeff Brownc5ed5912010-07-14 18:48:53 -07003319 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003321 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 }
3323 }
3324 Binder.restoreCallingIdentity(origId);
3325 }
3326
3327 public void addAppToken(int addPos, IApplicationToken token,
3328 int groupId, int requestedOrientation, boolean fullscreen) {
3329 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3330 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003331 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 }
Jeff Brown349703e2010-06-22 01:27:15 -07003333
3334 // Get the dispatching timeout here while we are not holding any locks so that it
3335 // can be cached by the AppWindowToken. The timeout value is used later by the
3336 // input dispatcher in code that does hold locks. If we did not cache the value
3337 // here we would run the chance of introducing a deadlock between the window manager
3338 // (which holds locks while updating the input dispatcher state) and the activity manager
3339 // (which holds locks while querying the application token).
3340 long inputDispatchingTimeoutNanos;
3341 try {
3342 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3343 } catch (RemoteException ex) {
3344 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3345 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3346 }
Romain Guy06882f82009-06-10 13:36:04 -07003347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 synchronized(mWindowMap) {
3349 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3350 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003351 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 return;
3353 }
3354 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003355 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 wtoken.groupId = groupId;
3357 wtoken.appFullscreen = fullscreen;
3358 wtoken.requestedOrientation = requestedOrientation;
3359 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003360 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003361 mTokenMap.put(token.asBinder(), wtoken);
3362 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 // Application tokens start out hidden.
3365 wtoken.hidden = true;
3366 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 //dump();
3369 }
3370 }
Romain Guy06882f82009-06-10 13:36:04 -07003371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 public void setAppGroupId(IBinder token, int groupId) {
3373 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3374 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003375 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 }
3377
3378 synchronized(mWindowMap) {
3379 AppWindowToken wtoken = findAppWindowToken(token);
3380 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003381 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 return;
3383 }
3384 wtoken.groupId = groupId;
3385 }
3386 }
Romain Guy06882f82009-06-10 13:36:04 -07003387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003388 public int getOrientationFromWindowsLocked() {
3389 int pos = mWindows.size() - 1;
3390 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003391 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 pos--;
3393 if (wtoken.mAppToken != null) {
3394 // We hit an application window. so the orientation will be determined by the
3395 // app window. No point in continuing further.
3396 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3397 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003398 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 continue;
3400 }
3401 int req = wtoken.mAttrs.screenOrientation;
3402 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3403 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3404 continue;
3405 } else {
3406 return req;
3407 }
3408 }
3409 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3410 }
Romain Guy06882f82009-06-10 13:36:04 -07003411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003413 int pos = mAppTokens.size() - 1;
3414 int curGroup = 0;
3415 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3416 boolean findingBehind = false;
3417 boolean haveGroup = false;
3418 boolean lastFullscreen = false;
3419 while (pos >= 0) {
3420 AppWindowToken wtoken = mAppTokens.get(pos);
3421 pos--;
3422 // if we're about to tear down this window and not seek for
3423 // the behind activity, don't use it for orientation
3424 if (!findingBehind
3425 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3426 continue;
3427 }
3428
3429 if (!haveGroup) {
3430 // We ignore any hidden applications on the top.
3431 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003432 continue;
3433 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003434 haveGroup = true;
3435 curGroup = wtoken.groupId;
3436 lastOrientation = wtoken.requestedOrientation;
3437 } else if (curGroup != wtoken.groupId) {
3438 // If we have hit a new application group, and the bottom
3439 // of the previous group didn't explicitly say to use
3440 // the orientation behind it, and the last app was
3441 // full screen, then we'll stick with the
3442 // user's orientation.
3443 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3444 && lastFullscreen) {
3445 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003448 int or = wtoken.requestedOrientation;
3449 // If this application is fullscreen, and didn't explicitly say
3450 // to use the orientation behind it, then just take whatever
3451 // orientation it has and ignores whatever is under it.
3452 lastFullscreen = wtoken.appFullscreen;
3453 if (lastFullscreen
3454 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3455 return or;
3456 }
3457 // If this application has requested an explicit orientation,
3458 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003459 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3460 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003461 return or;
3462 }
3463 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3464 }
3465 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 }
Romain Guy06882f82009-06-10 13:36:04 -07003467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003469 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003470 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3471 "updateOrientationFromAppTokens()")) {
3472 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3473 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003474
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003475 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003477
3478 synchronized(mWindowMap) {
3479 if (updateOrientationFromAppTokensLocked()) {
3480 if (freezeThisOneIfNeeded != null) {
3481 AppWindowToken wtoken = findAppWindowToken(
3482 freezeThisOneIfNeeded);
3483 if (wtoken != null) {
3484 startAppFreezingScreenLocked(wtoken,
3485 ActivityInfo.CONFIG_ORIENTATION);
3486 }
3487 }
3488 config = computeNewConfigurationLocked();
3489
3490 } else if (currentConfig != null) {
3491 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003492 // state mismatches the activity manager's, update it,
3493 // disregarding font scale, which should remain set to
3494 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003495 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003496 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003497 if (computeNewConfigurationLocked(mTempConfiguration)) {
3498 if (currentConfig.diff(mTempConfiguration) != 0) {
3499 mWaitingForConfig = true;
3500 mLayoutNeeded = true;
3501 startFreezingDisplayLocked();
3502 config = new Configuration(mTempConfiguration);
3503 }
3504 }
3505 }
3506 }
3507
Dianne Hackborncfaef692009-06-15 14:24:44 -07003508 Binder.restoreCallingIdentity(ident);
3509 return config;
3510 }
3511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003513 * Determine the new desired orientation of the display, returning
3514 * a non-null new Configuration if it has changed from the current
3515 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3516 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3517 * SCREEN. This will typically be done for you if you call
3518 * sendNewConfiguration().
3519 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 * The orientation is computed from non-application windows first. If none of
3521 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003522 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3524 * android.os.IBinder)
3525 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003526 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003527 if (mDisplayFrozen) {
3528 // If the display is frozen, some activities may be in the middle
3529 // of restarting, and thus have removed their old window. If the
3530 // window has the flag to hide the lock screen, then the lock screen
3531 // can re-appear and inflict its own orientation on us. Keep the
3532 // orientation stable until this all settles down.
3533 return false;
3534 }
3535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003536 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 long ident = Binder.clearCallingIdentity();
3538 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003539 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 mForcedAppOrientation = req;
3543 //send a message to Policy indicating orientation change to take
3544 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003545 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003546 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3547 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3548 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003549 }
3550 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003551
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003552 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 } finally {
3554 Binder.restoreCallingIdentity(ident);
3555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 }
Romain Guy06882f82009-06-10 13:36:04 -07003557
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003558 int computeForcedAppOrientationLocked() {
3559 int req = getOrientationFromWindowsLocked();
3560 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3561 req = getOrientationFromAppTokensLocked();
3562 }
3563 return req;
3564 }
Romain Guy06882f82009-06-10 13:36:04 -07003565
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003566 public void setNewConfiguration(Configuration config) {
3567 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3568 "setNewConfiguration()")) {
3569 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3570 }
3571
3572 synchronized(mWindowMap) {
3573 mCurConfiguration = new Configuration(config);
3574 mWaitingForConfig = false;
3575 performLayoutAndPlaceSurfacesLocked();
3576 }
3577 }
3578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3580 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3581 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003582 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 }
Romain Guy06882f82009-06-10 13:36:04 -07003584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 synchronized(mWindowMap) {
3586 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3587 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003588 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003589 return;
3590 }
Romain Guy06882f82009-06-10 13:36:04 -07003591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 wtoken.requestedOrientation = requestedOrientation;
3593 }
3594 }
Romain Guy06882f82009-06-10 13:36:04 -07003595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 public int getAppOrientation(IApplicationToken token) {
3597 synchronized(mWindowMap) {
3598 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3599 if (wtoken == null) {
3600 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3601 }
Romain Guy06882f82009-06-10 13:36:04 -07003602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 return wtoken.requestedOrientation;
3604 }
3605 }
Romain Guy06882f82009-06-10 13:36:04 -07003606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3608 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3609 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003610 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 }
3612
3613 synchronized(mWindowMap) {
3614 boolean changed = false;
3615 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003616 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 changed = mFocusedApp != null;
3618 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003619 if (changed) {
3620 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 } else {
3623 AppWindowToken newFocus = findAppWindowToken(token);
3624 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003625 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 return;
3627 }
3628 changed = mFocusedApp != newFocus;
3629 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003630 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003631 if (changed) {
3632 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003633 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 }
3635
3636 if (moveFocusNow && changed) {
3637 final long origId = Binder.clearCallingIdentity();
3638 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3639 Binder.restoreCallingIdentity(origId);
3640 }
3641 }
3642 }
3643
3644 public void prepareAppTransition(int transit) {
3645 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3646 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003647 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 }
Romain Guy06882f82009-06-10 13:36:04 -07003649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003650 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003651 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003652 TAG, "Prepare app transition: transit=" + transit
3653 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003654 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003655 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3656 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003658 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3659 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3660 // Opening a new task always supersedes a close for the anim.
3661 mNextAppTransition = transit;
3662 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3663 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3664 // Opening a new activity always supersedes a close for the anim.
3665 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003666 }
3667 mAppTransitionReady = false;
3668 mAppTransitionTimeout = false;
3669 mStartingIconInTransition = false;
3670 mSkipAppTransitionAnimation = false;
3671 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3672 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3673 5000);
3674 }
3675 }
3676 }
3677
3678 public int getPendingAppTransition() {
3679 return mNextAppTransition;
3680 }
Romain Guy06882f82009-06-10 13:36:04 -07003681
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003682 public void overridePendingAppTransition(String packageName,
3683 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003684 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003685 mNextAppTransitionPackage = packageName;
3686 mNextAppTransitionEnter = enterAnim;
3687 mNextAppTransitionExit = exitAnim;
3688 }
3689 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 public void executeAppTransition() {
3692 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3693 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003694 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 }
Romain Guy06882f82009-06-10 13:36:04 -07003696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003697 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003698 if (DEBUG_APP_TRANSITIONS) {
3699 RuntimeException e = new RuntimeException("here");
3700 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003701 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003702 + mNextAppTransition, e);
3703 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003704 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003705 mAppTransitionReady = true;
3706 final long origId = Binder.clearCallingIdentity();
3707 performLayoutAndPlaceSurfacesLocked();
3708 Binder.restoreCallingIdentity(origId);
3709 }
3710 }
3711 }
3712
3713 public void setAppStartingWindow(IBinder token, String pkg,
3714 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3715 IBinder transferFrom, boolean createIfNeeded) {
3716 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3717 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003718 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 }
3720
3721 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003722 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3724 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 AppWindowToken wtoken = findAppWindowToken(token);
3727 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003728 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 return;
3730 }
3731
3732 // If the display is frozen, we won't do anything until the
3733 // actual window is displayed so there is no reason to put in
3734 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003735 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 return;
3737 }
Romain Guy06882f82009-06-10 13:36:04 -07003738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 if (wtoken.startingData != null) {
3740 return;
3741 }
Romain Guy06882f82009-06-10 13:36:04 -07003742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 if (transferFrom != null) {
3744 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3745 if (ttoken != null) {
3746 WindowState startingWindow = ttoken.startingWindow;
3747 if (startingWindow != null) {
3748 if (mStartingIconInTransition) {
3749 // In this case, the starting icon has already
3750 // been displayed, so start letting windows get
3751 // shown immediately without any more transitions.
3752 mSkipAppTransitionAnimation = true;
3753 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003754 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755 "Moving existing starting from " + ttoken
3756 + " to " + wtoken);
3757 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 // Transfer the starting window over to the new
3760 // token.
3761 wtoken.startingData = ttoken.startingData;
3762 wtoken.startingView = ttoken.startingView;
3763 wtoken.startingWindow = startingWindow;
3764 ttoken.startingData = null;
3765 ttoken.startingView = null;
3766 ttoken.startingWindow = null;
3767 ttoken.startingMoved = true;
3768 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003769 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003771 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003772 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003774 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 ttoken.windows.remove(startingWindow);
3776 ttoken.allAppWindows.remove(startingWindow);
3777 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 // Propagate other interesting state between the
3780 // tokens. If the old token is displayed, we should
3781 // immediately force the new one to be displayed. If
3782 // it is animating, we need to move that animation to
3783 // the new one.
3784 if (ttoken.allDrawn) {
3785 wtoken.allDrawn = true;
3786 }
3787 if (ttoken.firstWindowDrawn) {
3788 wtoken.firstWindowDrawn = true;
3789 }
3790 if (!ttoken.hidden) {
3791 wtoken.hidden = false;
3792 wtoken.hiddenRequested = false;
3793 wtoken.willBeHidden = false;
3794 }
3795 if (wtoken.clientHidden != ttoken.clientHidden) {
3796 wtoken.clientHidden = ttoken.clientHidden;
3797 wtoken.sendAppVisibilityToClients();
3798 }
3799 if (ttoken.animation != null) {
3800 wtoken.animation = ttoken.animation;
3801 wtoken.animating = ttoken.animating;
3802 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3803 ttoken.animation = null;
3804 ttoken.animLayerAdjustment = 0;
3805 wtoken.updateLayers();
3806 ttoken.updateLayers();
3807 }
Romain Guy06882f82009-06-10 13:36:04 -07003808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 mLayoutNeeded = true;
3811 performLayoutAndPlaceSurfacesLocked();
3812 Binder.restoreCallingIdentity(origId);
3813 return;
3814 } else if (ttoken.startingData != null) {
3815 // The previous app was getting ready to show a
3816 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003817 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 "Moving pending starting from " + ttoken
3819 + " to " + wtoken);
3820 wtoken.startingData = ttoken.startingData;
3821 ttoken.startingData = null;
3822 ttoken.startingMoved = true;
3823 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3824 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3825 // want to process the message ASAP, before any other queued
3826 // messages.
3827 mH.sendMessageAtFrontOfQueue(m);
3828 return;
3829 }
3830 }
3831 }
3832
3833 // There is no existing starting window, and the caller doesn't
3834 // want us to create one, so that's it!
3835 if (!createIfNeeded) {
3836 return;
3837 }
Romain Guy06882f82009-06-10 13:36:04 -07003838
Dianne Hackborn284ac932009-08-28 10:34:25 -07003839 // If this is a translucent or wallpaper window, then don't
3840 // show a starting window -- the current effect (a full-screen
3841 // opaque starting window that fades away to the real contents
3842 // when it is ready) does not work for this.
3843 if (theme != 0) {
3844 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3845 com.android.internal.R.styleable.Window);
3846 if (ent.array.getBoolean(
3847 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3848 return;
3849 }
3850 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003851 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3852 return;
3853 }
3854 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003855 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3856 return;
3857 }
3858 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 mStartingIconInTransition = true;
3861 wtoken.startingData = new StartingData(
3862 pkg, theme, nonLocalizedLabel,
3863 labelRes, icon);
3864 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3865 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3866 // want to process the message ASAP, before any other queued
3867 // messages.
3868 mH.sendMessageAtFrontOfQueue(m);
3869 }
3870 }
3871
3872 public void setAppWillBeHidden(IBinder token) {
3873 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3874 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003875 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 }
3877
3878 AppWindowToken wtoken;
3879
3880 synchronized(mWindowMap) {
3881 wtoken = findAppWindowToken(token);
3882 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003883 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 -08003884 return;
3885 }
3886 wtoken.willBeHidden = true;
3887 }
3888 }
Romain Guy06882f82009-06-10 13:36:04 -07003889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3891 boolean visible, int transit, boolean performLayout) {
3892 boolean delayed = false;
3893
3894 if (wtoken.clientHidden == visible) {
3895 wtoken.clientHidden = !visible;
3896 wtoken.sendAppVisibilityToClients();
3897 }
Romain Guy06882f82009-06-10 13:36:04 -07003898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 wtoken.willBeHidden = false;
3900 if (wtoken.hidden == visible) {
3901 final int N = wtoken.allAppWindows.size();
3902 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003903 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3905 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003908
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003909 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 if (wtoken.animation == sDummyAnimation) {
3911 wtoken.animation = null;
3912 }
3913 applyAnimationLocked(wtoken, lp, transit, visible);
3914 changed = true;
3915 if (wtoken.animation != null) {
3916 delayed = runningAppAnimation = true;
3917 }
3918 }
Romain Guy06882f82009-06-10 13:36:04 -07003919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003920 for (int i=0; i<N; i++) {
3921 WindowState win = wtoken.allAppWindows.get(i);
3922 if (win == wtoken.startingWindow) {
3923 continue;
3924 }
3925
3926 if (win.isAnimating()) {
3927 delayed = true;
3928 }
Romain Guy06882f82009-06-10 13:36:04 -07003929
Joe Onorato8a9b2202010-02-26 18:56:32 -08003930 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 //win.dump(" ");
3932 if (visible) {
3933 if (!win.isVisibleNow()) {
3934 if (!runningAppAnimation) {
3935 applyAnimationLocked(win,
3936 WindowManagerPolicy.TRANSIT_ENTER, true);
3937 }
3938 changed = true;
3939 }
3940 } else if (win.isVisibleNow()) {
3941 if (!runningAppAnimation) {
3942 applyAnimationLocked(win,
3943 WindowManagerPolicy.TRANSIT_EXIT, false);
3944 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003945 changed = true;
3946 }
3947 }
3948
3949 wtoken.hidden = wtoken.hiddenRequested = !visible;
3950 if (!visible) {
3951 unsetAppFreezingScreenLocked(wtoken, true, true);
3952 } else {
3953 // If we are being set visible, and the starting window is
3954 // not yet displayed, then make sure it doesn't get displayed.
3955 WindowState swin = wtoken.startingWindow;
3956 if (swin != null && (swin.mDrawPending
3957 || swin.mCommitDrawPending)) {
3958 swin.mPolicyVisibility = false;
3959 swin.mPolicyVisibilityAfterAnim = false;
3960 }
3961 }
Romain Guy06882f82009-06-10 13:36:04 -07003962
Joe Onorato8a9b2202010-02-26 18:56:32 -08003963 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3965 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003966
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003967 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003968 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003969 if (performLayout) {
3970 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3971 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003972 } else {
3973 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003974 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 }
3976 }
3977
3978 if (wtoken.animation != null) {
3979 delayed = true;
3980 }
Romain Guy06882f82009-06-10 13:36:04 -07003981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 return delayed;
3983 }
3984
3985 public void setAppVisibility(IBinder token, boolean visible) {
3986 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3987 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003988 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 }
3990
3991 AppWindowToken wtoken;
3992
3993 synchronized(mWindowMap) {
3994 wtoken = findAppWindowToken(token);
3995 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003996 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 return;
3998 }
3999
4000 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004001 RuntimeException e = null;
4002 if (!HIDE_STACK_CRAWLS) {
4003 e = new RuntimeException();
4004 e.fillInStackTrace();
4005 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004006 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 + "): mNextAppTransition=" + mNextAppTransition
4008 + " hidden=" + wtoken.hidden
4009 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4010 }
Romain Guy06882f82009-06-10 13:36:04 -07004011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 // If we are preparing an app transition, then delay changing
4013 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004014 if (!mDisplayFrozen && mPolicy.isScreenOn()
4015 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004016 // Already in requested state, don't do anything more.
4017 if (wtoken.hiddenRequested != visible) {
4018 return;
4019 }
4020 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004021
Joe Onorato8a9b2202010-02-26 18:56:32 -08004022 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 TAG, "Setting dummy animation on: " + wtoken);
4024 wtoken.setDummyAnimation();
4025 mOpeningApps.remove(wtoken);
4026 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004027 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004028 wtoken.inPendingTransaction = true;
4029 if (visible) {
4030 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 wtoken.startingDisplayed = false;
4032 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004033
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004034 // If the token is currently hidden (should be the
4035 // common case), then we need to set up to wait for
4036 // its windows to be ready.
4037 if (wtoken.hidden) {
4038 wtoken.allDrawn = false;
4039 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004040
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004041 if (wtoken.clientHidden) {
4042 // In the case where we are making an app visible
4043 // but holding off for a transition, we still need
4044 // to tell the client to make its windows visible so
4045 // they get drawn. Otherwise, we will wait on
4046 // performing the transition until all windows have
4047 // been drawn, they never will be, and we are sad.
4048 wtoken.clientHidden = false;
4049 wtoken.sendAppVisibilityToClients();
4050 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004051 }
4052 } else {
4053 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004054
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004055 // If the token is currently visible (should be the
4056 // common case), then set up to wait for it to be hidden.
4057 if (!wtoken.hidden) {
4058 wtoken.waitingToHide = true;
4059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004060 }
4061 return;
4062 }
Romain Guy06882f82009-06-10 13:36:04 -07004063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004065 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004066 wtoken.updateReportedVisibilityLocked();
4067 Binder.restoreCallingIdentity(origId);
4068 }
4069 }
4070
4071 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4072 boolean unfreezeSurfaceNow, boolean force) {
4073 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004074 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 + " force=" + force);
4076 final int N = wtoken.allAppWindows.size();
4077 boolean unfrozeWindows = false;
4078 for (int i=0; i<N; i++) {
4079 WindowState w = wtoken.allAppWindows.get(i);
4080 if (w.mAppFreezing) {
4081 w.mAppFreezing = false;
4082 if (w.mSurface != null && !w.mOrientationChanging) {
4083 w.mOrientationChanging = true;
4084 }
4085 unfrozeWindows = true;
4086 }
4087 }
4088 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004089 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 wtoken.freezingScreen = false;
4091 mAppsFreezingScreen--;
4092 }
4093 if (unfreezeSurfaceNow) {
4094 if (unfrozeWindows) {
4095 mLayoutNeeded = true;
4096 performLayoutAndPlaceSurfacesLocked();
4097 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004098 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 }
4100 }
4101 }
Romain Guy06882f82009-06-10 13:36:04 -07004102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004103 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4104 int configChanges) {
4105 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004106 RuntimeException e = null;
4107 if (!HIDE_STACK_CRAWLS) {
4108 e = new RuntimeException();
4109 e.fillInStackTrace();
4110 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004111 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 + ": hidden=" + wtoken.hidden + " freezing="
4113 + wtoken.freezingScreen, e);
4114 }
4115 if (!wtoken.hiddenRequested) {
4116 if (!wtoken.freezingScreen) {
4117 wtoken.freezingScreen = true;
4118 mAppsFreezingScreen++;
4119 if (mAppsFreezingScreen == 1) {
4120 startFreezingDisplayLocked();
4121 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4122 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4123 5000);
4124 }
4125 }
4126 final int N = wtoken.allAppWindows.size();
4127 for (int i=0; i<N; i++) {
4128 WindowState w = wtoken.allAppWindows.get(i);
4129 w.mAppFreezing = true;
4130 }
4131 }
4132 }
Romain Guy06882f82009-06-10 13:36:04 -07004133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004134 public void startAppFreezingScreen(IBinder token, int configChanges) {
4135 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4136 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004137 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004138 }
4139
4140 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004141 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004142 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004143 return;
4144 }
Romain Guy06882f82009-06-10 13:36:04 -07004145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004146 AppWindowToken wtoken = findAppWindowToken(token);
4147 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004148 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 return;
4150 }
4151 final long origId = Binder.clearCallingIdentity();
4152 startAppFreezingScreenLocked(wtoken, configChanges);
4153 Binder.restoreCallingIdentity(origId);
4154 }
4155 }
Romain Guy06882f82009-06-10 13:36:04 -07004156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004157 public void stopAppFreezingScreen(IBinder token, boolean force) {
4158 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4159 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004160 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 }
4162
4163 synchronized(mWindowMap) {
4164 AppWindowToken wtoken = findAppWindowToken(token);
4165 if (wtoken == null || wtoken.appToken == null) {
4166 return;
4167 }
4168 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004169 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004170 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4171 unsetAppFreezingScreenLocked(wtoken, true, force);
4172 Binder.restoreCallingIdentity(origId);
4173 }
4174 }
Romain Guy06882f82009-06-10 13:36:04 -07004175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 public void removeAppToken(IBinder token) {
4177 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4178 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004179 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 }
4181
4182 AppWindowToken wtoken = null;
4183 AppWindowToken startingToken = null;
4184 boolean delayed = false;
4185
4186 final long origId = Binder.clearCallingIdentity();
4187 synchronized(mWindowMap) {
4188 WindowToken basewtoken = mTokenMap.remove(token);
4189 mTokenList.remove(basewtoken);
4190 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004191 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004192 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 wtoken.inPendingTransaction = false;
4194 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004195 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004196 if (mClosingApps.contains(wtoken)) {
4197 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004198 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004200 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 delayed = true;
4202 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004203 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 TAG, "Removing app " + wtoken + " delayed=" + delayed
4205 + " animation=" + wtoken.animation
4206 + " animating=" + wtoken.animating);
4207 if (delayed) {
4208 // set the token aside because it has an active animation to be finished
4209 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004210 } else {
4211 // Make sure there is no animation running on this token,
4212 // so any windows associated with it will be removed as
4213 // soon as their animations are complete
4214 wtoken.animation = null;
4215 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 }
4217 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004218 if (mLastEnterAnimToken == wtoken) {
4219 mLastEnterAnimToken = null;
4220 mLastEnterAnimParams = null;
4221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 wtoken.removed = true;
4223 if (wtoken.startingData != null) {
4224 startingToken = wtoken;
4225 }
4226 unsetAppFreezingScreenLocked(wtoken, true, true);
4227 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004228 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 mFocusedApp = null;
4230 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004231 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004232 }
4233 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004234 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004235 }
Romain Guy06882f82009-06-10 13:36:04 -07004236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004237 if (!delayed && wtoken != null) {
4238 wtoken.updateReportedVisibilityLocked();
4239 }
4240 }
4241 Binder.restoreCallingIdentity(origId);
4242
4243 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004244 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 + startingToken + ": app token removed");
4246 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4247 mH.sendMessage(m);
4248 }
4249 }
4250
4251 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4252 final int NW = token.windows.size();
4253 for (int i=0; i<NW; i++) {
4254 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004255 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004256 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004257 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 int j = win.mChildWindows.size();
4259 while (j > 0) {
4260 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004261 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004262 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004263 "Tmp removing child window " + cwin);
4264 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 }
4266 }
4267 return NW > 0;
4268 }
4269
4270 void dumpAppTokensLocked() {
4271 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004272 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 }
4274 }
Romain Guy06882f82009-06-10 13:36:04 -07004275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 void dumpWindowsLocked() {
4277 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004278 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 }
4280 }
Romain Guy06882f82009-06-10 13:36:04 -07004281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 private int findWindowOffsetLocked(int tokenPos) {
4283 final int NW = mWindows.size();
4284
4285 if (tokenPos >= mAppTokens.size()) {
4286 int i = NW;
4287 while (i > 0) {
4288 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004289 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 if (win.getAppToken() != null) {
4291 return i+1;
4292 }
4293 }
4294 }
4295
4296 while (tokenPos > 0) {
4297 // Find the first app token below the new position that has
4298 // a window displayed.
4299 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004300 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004302 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004303 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004304 "Skipping token -- currently sending to bottom");
4305 tokenPos--;
4306 continue;
4307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 int i = wtoken.windows.size();
4309 while (i > 0) {
4310 i--;
4311 WindowState win = wtoken.windows.get(i);
4312 int j = win.mChildWindows.size();
4313 while (j > 0) {
4314 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004315 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004316 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 for (int pos=NW-1; pos>=0; pos--) {
4318 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004319 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 "Found child win @" + (pos+1));
4321 return pos+1;
4322 }
4323 }
4324 }
4325 }
4326 for (int pos=NW-1; pos>=0; pos--) {
4327 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004328 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 return pos+1;
4330 }
4331 }
4332 }
4333 tokenPos--;
4334 }
4335
4336 return 0;
4337 }
4338
4339 private final int reAddWindowLocked(int index, WindowState win) {
4340 final int NCW = win.mChildWindows.size();
4341 boolean added = false;
4342 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004343 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004345 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004346 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 mWindows.add(index, win);
4348 index++;
4349 added = true;
4350 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004351 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004352 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004353 mWindows.add(index, cwin);
4354 index++;
4355 }
4356 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004357 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004358 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 mWindows.add(index, win);
4360 index++;
4361 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004362 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 return index;
4364 }
Romain Guy06882f82009-06-10 13:36:04 -07004365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4367 final int NW = token.windows.size();
4368 for (int i=0; i<NW; i++) {
4369 index = reAddWindowLocked(index, token.windows.get(i));
4370 }
4371 return index;
4372 }
4373
4374 public void moveAppToken(int index, IBinder token) {
4375 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4376 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004377 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 }
4379
4380 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004381 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 if (DEBUG_REORDER) dumpAppTokensLocked();
4383 final AppWindowToken wtoken = findAppWindowToken(token);
4384 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004385 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 + token + " (" + wtoken + ")");
4387 return;
4388 }
4389 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004390 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004391 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004393 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004394 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 if (DEBUG_REORDER) dumpWindowsLocked();
4396 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004397 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 if (DEBUG_REORDER) dumpWindowsLocked();
4399 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004400 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 if (DEBUG_REORDER) dumpWindowsLocked();
4402 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 mLayoutNeeded = true;
4404 performLayoutAndPlaceSurfacesLocked();
4405 }
4406 Binder.restoreCallingIdentity(origId);
4407 }
4408 }
4409
4410 private void removeAppTokensLocked(List<IBinder> tokens) {
4411 // XXX This should be done more efficiently!
4412 // (take advantage of the fact that both lists should be
4413 // ordered in the same way.)
4414 int N = tokens.size();
4415 for (int i=0; i<N; i++) {
4416 IBinder token = tokens.get(i);
4417 final AppWindowToken wtoken = findAppWindowToken(token);
4418 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004419 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 + token + " (" + wtoken + ")");
4421 i--;
4422 N--;
4423 }
4424 }
4425 }
4426
Dianne Hackborna8f60182009-09-01 19:01:50 -07004427 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4428 boolean updateFocusAndLayout) {
4429 // First remove all of the windows from the list.
4430 tmpRemoveAppWindowsLocked(wtoken);
4431
4432 // Where to start adding?
4433 int pos = findWindowOffsetLocked(tokenPos);
4434
4435 // And now add them back at the correct place.
4436 pos = reAddAppWindowsLocked(pos, wtoken);
4437
4438 if (updateFocusAndLayout) {
4439 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4440 assignLayersLocked();
4441 }
4442 mLayoutNeeded = true;
4443 performLayoutAndPlaceSurfacesLocked();
4444 }
4445 }
4446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4448 // First remove all of the windows from the list.
4449 final int N = tokens.size();
4450 int i;
4451 for (i=0; i<N; i++) {
4452 WindowToken token = mTokenMap.get(tokens.get(i));
4453 if (token != null) {
4454 tmpRemoveAppWindowsLocked(token);
4455 }
4456 }
4457
4458 // Where to start adding?
4459 int pos = findWindowOffsetLocked(tokenPos);
4460
4461 // And now add them back at the correct place.
4462 for (i=0; i<N; i++) {
4463 WindowToken token = mTokenMap.get(tokens.get(i));
4464 if (token != null) {
4465 pos = reAddAppWindowsLocked(pos, token);
4466 }
4467 }
4468
Dianne Hackborna8f60182009-09-01 19:01:50 -07004469 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4470 assignLayersLocked();
4471 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 mLayoutNeeded = true;
4473 performLayoutAndPlaceSurfacesLocked();
4474
4475 //dump();
4476 }
4477
4478 public void moveAppTokensToTop(List<IBinder> tokens) {
4479 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4480 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004481 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 }
4483
4484 final long origId = Binder.clearCallingIdentity();
4485 synchronized(mWindowMap) {
4486 removeAppTokensLocked(tokens);
4487 final int N = tokens.size();
4488 for (int i=0; i<N; i++) {
4489 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4490 if (wt != null) {
4491 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004492 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004493 mToTopApps.remove(wt);
4494 mToBottomApps.remove(wt);
4495 mToTopApps.add(wt);
4496 wt.sendingToBottom = false;
4497 wt.sendingToTop = true;
4498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 }
4500 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004501
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004502 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004503 moveAppWindowsLocked(tokens, mAppTokens.size());
4504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 }
4506 Binder.restoreCallingIdentity(origId);
4507 }
4508
4509 public void moveAppTokensToBottom(List<IBinder> tokens) {
4510 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4511 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004512 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 }
4514
4515 final long origId = Binder.clearCallingIdentity();
4516 synchronized(mWindowMap) {
4517 removeAppTokensLocked(tokens);
4518 final int N = tokens.size();
4519 int pos = 0;
4520 for (int i=0; i<N; i++) {
4521 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4522 if (wt != null) {
4523 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004524 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004525 mToTopApps.remove(wt);
4526 mToBottomApps.remove(wt);
4527 mToBottomApps.add(i, wt);
4528 wt.sendingToTop = false;
4529 wt.sendingToBottom = true;
4530 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 pos++;
4532 }
4533 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004534
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004535 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004536 moveAppWindowsLocked(tokens, 0);
4537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 }
4539 Binder.restoreCallingIdentity(origId);
4540 }
4541
4542 // -------------------------------------------------------------
4543 // Misc IWindowSession methods
4544 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004545
Jim Miller284b62e2010-06-08 14:27:42 -07004546 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004547 {
Jim Miller284b62e2010-06-08 14:27:42 -07004548 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4549 // called before DevicePolicyManagerService has started.
4550 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4551 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4552 Context.DEVICE_POLICY_SERVICE);
4553 if (dpm != null) {
4554 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4555 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4556 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4557 }
Jim Millerd6b57052010-06-07 17:52:42 -07004558 }
Jim Miller284b62e2010-06-08 14:27:42 -07004559 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004560 }
4561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004562 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004563 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004564 != PackageManager.PERMISSION_GRANTED) {
4565 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4566 }
Jim Millerd6b57052010-06-07 17:52:42 -07004567
Jim Miller284b62e2010-06-08 14:27:42 -07004568 synchronized (mKeyguardTokenWatcher) {
4569 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004570 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 }
4572
4573 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004574 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004575 != PackageManager.PERMISSION_GRANTED) {
4576 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578
Jim Miller284b62e2010-06-08 14:27:42 -07004579 synchronized (mKeyguardTokenWatcher) {
4580 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004581
Jim Miller284b62e2010-06-08 14:27:42 -07004582 if (!mKeyguardTokenWatcher.isAcquired()) {
4583 // If we are the last one to reenable the keyguard wait until
4584 // we have actually finished reenabling until returning.
4585 // It is possible that reenableKeyguard() can be called before
4586 // the previous disableKeyguard() is handled, in which case
4587 // neither mKeyguardTokenWatcher.acquired() or released() would
4588 // be called. In that case mKeyguardDisabled will be false here
4589 // and we have nothing to wait for.
4590 while (mKeyguardDisabled) {
4591 try {
4592 mKeyguardTokenWatcher.wait();
4593 } catch (InterruptedException e) {
4594 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004595 }
4596 }
4597 }
4598 }
4599 }
4600
4601 /**
4602 * @see android.app.KeyguardManager#exitKeyguardSecurely
4603 */
4604 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004605 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004606 != PackageManager.PERMISSION_GRANTED) {
4607 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4608 }
4609 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4610 public void onKeyguardExitResult(boolean success) {
4611 try {
4612 callback.onKeyguardExitResult(success);
4613 } catch (RemoteException e) {
4614 // Client has died, we don't care.
4615 }
4616 }
4617 });
4618 }
4619
4620 public boolean inKeyguardRestrictedInputMode() {
4621 return mPolicy.inKeyguardRestrictedKeyInputMode();
4622 }
Romain Guy06882f82009-06-10 13:36:04 -07004623
Dianne Hackbornffa42482009-09-23 22:20:11 -07004624 public void closeSystemDialogs(String reason) {
4625 synchronized(mWindowMap) {
4626 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004627 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004628 if (w.mSurface != null) {
4629 try {
4630 w.mClient.closeSystemDialogs(reason);
4631 } catch (RemoteException e) {
4632 }
4633 }
4634 }
4635 }
4636 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004638 static float fixScale(float scale) {
4639 if (scale < 0) scale = 0;
4640 else if (scale > 20) scale = 20;
4641 return Math.abs(scale);
4642 }
Romain Guy06882f82009-06-10 13:36:04 -07004643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004644 public void setAnimationScale(int which, float scale) {
4645 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4646 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004647 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004648 }
4649
4650 if (scale < 0) scale = 0;
4651 else if (scale > 20) scale = 20;
4652 scale = Math.abs(scale);
4653 switch (which) {
4654 case 0: mWindowAnimationScale = fixScale(scale); break;
4655 case 1: mTransitionAnimationScale = fixScale(scale); break;
4656 }
Romain Guy06882f82009-06-10 13:36:04 -07004657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004658 // Persist setting
4659 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4660 }
Romain Guy06882f82009-06-10 13:36:04 -07004661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662 public void setAnimationScales(float[] scales) {
4663 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4664 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004665 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 }
4667
4668 if (scales != null) {
4669 if (scales.length >= 1) {
4670 mWindowAnimationScale = fixScale(scales[0]);
4671 }
4672 if (scales.length >= 2) {
4673 mTransitionAnimationScale = fixScale(scales[1]);
4674 }
4675 }
Romain Guy06882f82009-06-10 13:36:04 -07004676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004677 // Persist setting
4678 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4679 }
Romain Guy06882f82009-06-10 13:36:04 -07004680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 public float getAnimationScale(int which) {
4682 switch (which) {
4683 case 0: return mWindowAnimationScale;
4684 case 1: return mTransitionAnimationScale;
4685 }
4686 return 0;
4687 }
Romain Guy06882f82009-06-10 13:36:04 -07004688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 public float[] getAnimationScales() {
4690 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4691 }
Romain Guy06882f82009-06-10 13:36:04 -07004692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 public int getSwitchState(int sw) {
4694 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4695 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004696 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004698 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 }
Romain Guy06882f82009-06-10 13:36:04 -07004700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004701 public int getSwitchStateForDevice(int devid, int sw) {
4702 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4703 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004704 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004705 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004706 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 }
Romain Guy06882f82009-06-10 13:36:04 -07004708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 public int getScancodeState(int sw) {
4710 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4711 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004712 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004713 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004714 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004715 }
Romain Guy06882f82009-06-10 13:36:04 -07004716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 public int getScancodeStateForDevice(int devid, int sw) {
4718 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4719 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004720 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004721 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004722 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004723 }
Romain Guy06882f82009-06-10 13:36:04 -07004724
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004725 public int getTrackballScancodeState(int sw) {
4726 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4727 "getTrackballScancodeState()")) {
4728 throw new SecurityException("Requires READ_INPUT_STATE permission");
4729 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004730 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004731 }
4732
4733 public int getDPadScancodeState(int sw) {
4734 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4735 "getDPadScancodeState()")) {
4736 throw new SecurityException("Requires READ_INPUT_STATE permission");
4737 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004738 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004739 }
4740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004741 public int getKeycodeState(int sw) {
4742 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4743 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004744 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004745 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004746 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004747 }
Romain Guy06882f82009-06-10 13:36:04 -07004748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004749 public int getKeycodeStateForDevice(int devid, int sw) {
4750 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4751 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004752 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004753 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004754 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004755 }
Romain Guy06882f82009-06-10 13:36:04 -07004756
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004757 public int getTrackballKeycodeState(int sw) {
4758 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4759 "getTrackballKeycodeState()")) {
4760 throw new SecurityException("Requires READ_INPUT_STATE permission");
4761 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004762 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004763 }
4764
4765 public int getDPadKeycodeState(int sw) {
4766 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4767 "getDPadKeycodeState()")) {
4768 throw new SecurityException("Requires READ_INPUT_STATE permission");
4769 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004770 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004771 }
Jeff Browna41ca772010-08-11 14:46:32 -07004772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004773 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004774 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004775 }
Romain Guy06882f82009-06-10 13:36:04 -07004776
Jeff Browna41ca772010-08-11 14:46:32 -07004777 public InputChannel monitorInput(String inputChannelName) {
4778 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4779 "monitorInput()")) {
4780 throw new SecurityException("Requires READ_INPUT_STATE permission");
4781 }
4782 return mInputManager.monitorInput(inputChannelName);
4783 }
4784
Jeff Brown8d608662010-08-30 03:02:23 -07004785 public InputDevice getInputDevice(int deviceId) {
4786 return mInputManager.getInputDevice(deviceId);
4787 }
4788
4789 public int[] getInputDeviceIds() {
4790 return mInputManager.getInputDeviceIds();
4791 }
4792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004793 public void enableScreenAfterBoot() {
4794 synchronized(mWindowMap) {
4795 if (mSystemBooted) {
4796 return;
4797 }
4798 mSystemBooted = true;
4799 }
Romain Guy06882f82009-06-10 13:36:04 -07004800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 performEnableScreen();
4802 }
Romain Guy06882f82009-06-10 13:36:04 -07004803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 public void enableScreenIfNeededLocked() {
4805 if (mDisplayEnabled) {
4806 return;
4807 }
4808 if (!mSystemBooted) {
4809 return;
4810 }
4811 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4812 }
Romain Guy06882f82009-06-10 13:36:04 -07004813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004814 public void performEnableScreen() {
4815 synchronized(mWindowMap) {
4816 if (mDisplayEnabled) {
4817 return;
4818 }
4819 if (!mSystemBooted) {
4820 return;
4821 }
Romain Guy06882f82009-06-10 13:36:04 -07004822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823 // Don't enable the screen until all existing windows
4824 // have been drawn.
4825 final int N = mWindows.size();
4826 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004827 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004828 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 return;
4830 }
4831 }
Romain Guy06882f82009-06-10 13:36:04 -07004832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004833 mDisplayEnabled = true;
4834 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004835 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004836 StringWriter sw = new StringWriter();
4837 PrintWriter pw = new PrintWriter(sw);
4838 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004839 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004840 }
4841 try {
4842 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4843 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004844 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004845 Parcel data = Parcel.obtain();
4846 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4847 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4848 data, null, 0);
4849 data.recycle();
4850 }
4851 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004852 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 }
4854 }
Romain Guy06882f82009-06-10 13:36:04 -07004855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004858 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004859 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4860 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004861 }
Romain Guy06882f82009-06-10 13:36:04 -07004862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 public void setInTouchMode(boolean mode) {
4864 synchronized(mWindowMap) {
4865 mInTouchMode = mode;
4866 }
4867 }
4868
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004869 public void freezeRotation() {
4870 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4871 "setRotation()")) {
4872 throw new SecurityException("Requires SET_ORIENTATION permission");
4873 }
4874
4875 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4876 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4877 }
4878
4879 public void thawRotation() {
4880 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4881 "setRotation()")) {
4882 throw new SecurityException("Requires SET_ORIENTATION permission");
4883 }
4884
4885 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4886 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4887 }
4888
Romain Guy06882f82009-06-10 13:36:04 -07004889 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004890 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004891 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004892 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004893 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004894 }
4895
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004896 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 }
Romain Guy06882f82009-06-10 13:36:04 -07004898
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004899 public void setRotationUnchecked(int rotation,
4900 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004901 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004904 long origId = Binder.clearCallingIdentity();
4905 boolean changed;
4906 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004907 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004908 }
Romain Guy06882f82009-06-10 13:36:04 -07004909
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004910 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 sendNewConfiguration();
4912 }
Romain Guy06882f82009-06-10 13:36:04 -07004913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004914 Binder.restoreCallingIdentity(origId);
4915 }
Romain Guy06882f82009-06-10 13:36:04 -07004916
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004917 /**
4918 * Apply a new rotation to the screen, respecting the requests of
4919 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4920 * re-evaluate the desired rotation.
4921 *
4922 * Returns null if the rotation has been changed. In this case YOU
4923 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4924 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004925 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 boolean changed;
4927 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4928 rotation = mRequestedRotation;
4929 } else {
4930 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004931 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004932 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004933 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004934 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004936 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004939 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004940 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004941 "Rotation changed to " + rotation
4942 + " from " + mRotation
4943 + " (forceApp=" + mForcedAppOrientation
4944 + ", req=" + mRequestedRotation + ")");
4945 mRotation = rotation;
4946 mWindowsFreezingScreen = true;
4947 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4948 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4949 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004950 mWaitingForConfig = true;
4951 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004953 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004954 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004956 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004957 }
4958 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004959 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004960 if (w.mSurface != null) {
4961 w.mOrientationChanging = true;
4962 }
4963 }
4964 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4965 try {
4966 mRotationWatchers.get(i).onRotationChanged(rotation);
4967 } catch (RemoteException e) {
4968 }
4969 }
4970 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004972 return changed;
4973 }
Romain Guy06882f82009-06-10 13:36:04 -07004974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 public int getRotation() {
4976 return mRotation;
4977 }
4978
4979 public int watchRotation(IRotationWatcher watcher) {
4980 final IBinder watcherBinder = watcher.asBinder();
4981 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4982 public void binderDied() {
4983 synchronized (mWindowMap) {
4984 for (int i=0; i<mRotationWatchers.size(); i++) {
4985 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004986 IRotationWatcher removed = mRotationWatchers.remove(i);
4987 if (removed != null) {
4988 removed.asBinder().unlinkToDeath(this, 0);
4989 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004990 i--;
4991 }
4992 }
4993 }
4994 }
4995 };
Romain Guy06882f82009-06-10 13:36:04 -07004996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004997 synchronized (mWindowMap) {
4998 try {
4999 watcher.asBinder().linkToDeath(dr, 0);
5000 mRotationWatchers.add(watcher);
5001 } catch (RemoteException e) {
5002 // Client died, no cleanup needed.
5003 }
Romain Guy06882f82009-06-10 13:36:04 -07005004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005005 return mRotation;
5006 }
5007 }
5008
5009 /**
5010 * Starts the view server on the specified port.
5011 *
5012 * @param port The port to listener to.
5013 *
5014 * @return True if the server was successfully started, false otherwise.
5015 *
5016 * @see com.android.server.ViewServer
5017 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5018 */
5019 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005020 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005021 return false;
5022 }
5023
5024 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5025 return false;
5026 }
5027
5028 if (port < 1024) {
5029 return false;
5030 }
5031
5032 if (mViewServer != null) {
5033 if (!mViewServer.isRunning()) {
5034 try {
5035 return mViewServer.start();
5036 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005037 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005038 }
5039 }
5040 return false;
5041 }
5042
5043 try {
5044 mViewServer = new ViewServer(this, port);
5045 return mViewServer.start();
5046 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005047 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005048 }
5049 return false;
5050 }
5051
Romain Guy06882f82009-06-10 13:36:04 -07005052 private boolean isSystemSecure() {
5053 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5054 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5055 }
5056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005057 /**
5058 * Stops the view server if it exists.
5059 *
5060 * @return True if the server stopped, false if it wasn't started or
5061 * couldn't be stopped.
5062 *
5063 * @see com.android.server.ViewServer
5064 */
5065 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005066 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005067 return false;
5068 }
5069
5070 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5071 return false;
5072 }
5073
5074 if (mViewServer != null) {
5075 return mViewServer.stop();
5076 }
5077 return false;
5078 }
5079
5080 /**
5081 * Indicates whether the view server is running.
5082 *
5083 * @return True if the server is running, false otherwise.
5084 *
5085 * @see com.android.server.ViewServer
5086 */
5087 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005088 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005089 return false;
5090 }
5091
5092 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5093 return false;
5094 }
5095
5096 return mViewServer != null && mViewServer.isRunning();
5097 }
5098
5099 /**
5100 * Lists all availble windows in the system. The listing is written in the
5101 * specified Socket's output stream with the following syntax:
5102 * windowHashCodeInHexadecimal windowName
5103 * Each line of the ouput represents a different window.
5104 *
5105 * @param client The remote client to send the listing to.
5106 * @return False if an error occured, true otherwise.
5107 */
5108 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005109 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005110 return false;
5111 }
5112
5113 boolean result = true;
5114
Jeff Browne33348b2010-07-15 23:54:05 -07005115 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005116 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005117 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005118 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005119 }
5120
5121 BufferedWriter out = null;
5122
5123 // Any uncaught exception will crash the system process
5124 try {
5125 OutputStream clientStream = client.getOutputStream();
5126 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5127
5128 final int count = windows.length;
5129 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005130 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005131 out.write(Integer.toHexString(System.identityHashCode(w)));
5132 out.write(' ');
5133 out.append(w.mAttrs.getTitle());
5134 out.write('\n');
5135 }
5136
5137 out.write("DONE.\n");
5138 out.flush();
5139 } catch (Exception e) {
5140 result = false;
5141 } finally {
5142 if (out != null) {
5143 try {
5144 out.close();
5145 } catch (IOException e) {
5146 result = false;
5147 }
5148 }
5149 }
5150
5151 return result;
5152 }
5153
5154 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005155 * Returns the focused window in the following format:
5156 * windowHashCodeInHexadecimal windowName
5157 *
5158 * @param client The remote client to send the listing to.
5159 * @return False if an error occurred, true otherwise.
5160 */
5161 boolean viewServerGetFocusedWindow(Socket client) {
5162 if (isSystemSecure()) {
5163 return false;
5164 }
5165
5166 boolean result = true;
5167
5168 WindowState focusedWindow = getFocusedWindow();
5169
5170 BufferedWriter out = null;
5171
5172 // Any uncaught exception will crash the system process
5173 try {
5174 OutputStream clientStream = client.getOutputStream();
5175 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5176
5177 if(focusedWindow != null) {
5178 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5179 out.write(' ');
5180 out.append(focusedWindow.mAttrs.getTitle());
5181 }
5182 out.write('\n');
5183 out.flush();
5184 } catch (Exception e) {
5185 result = false;
5186 } finally {
5187 if (out != null) {
5188 try {
5189 out.close();
5190 } catch (IOException e) {
5191 result = false;
5192 }
5193 }
5194 }
5195
5196 return result;
5197 }
5198
5199 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005200 * Sends a command to a target window. The result of the command, if any, will be
5201 * written in the output stream of the specified socket.
5202 *
5203 * The parameters must follow this syntax:
5204 * windowHashcode extra
5205 *
5206 * Where XX is the length in characeters of the windowTitle.
5207 *
5208 * The first parameter is the target window. The window with the specified hashcode
5209 * will be the target. If no target can be found, nothing happens. The extra parameters
5210 * will be delivered to the target window and as parameters to the command itself.
5211 *
5212 * @param client The remote client to sent the result, if any, to.
5213 * @param command The command to execute.
5214 * @param parameters The command parameters.
5215 *
5216 * @return True if the command was successfully delivered, false otherwise. This does
5217 * not indicate whether the command itself was successful.
5218 */
5219 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005220 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005221 return false;
5222 }
5223
5224 boolean success = true;
5225 Parcel data = null;
5226 Parcel reply = null;
5227
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005228 BufferedWriter out = null;
5229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005230 // Any uncaught exception will crash the system process
5231 try {
5232 // Find the hashcode of the window
5233 int index = parameters.indexOf(' ');
5234 if (index == -1) {
5235 index = parameters.length();
5236 }
5237 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005238 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005239
5240 // Extract the command's parameter after the window description
5241 if (index < parameters.length()) {
5242 parameters = parameters.substring(index + 1);
5243 } else {
5244 parameters = "";
5245 }
5246
5247 final WindowManagerService.WindowState window = findWindow(hashCode);
5248 if (window == null) {
5249 return false;
5250 }
5251
5252 data = Parcel.obtain();
5253 data.writeInterfaceToken("android.view.IWindow");
5254 data.writeString(command);
5255 data.writeString(parameters);
5256 data.writeInt(1);
5257 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5258
5259 reply = Parcel.obtain();
5260
5261 final IBinder binder = window.mClient.asBinder();
5262 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5263 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5264
5265 reply.readException();
5266
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005267 if (!client.isOutputShutdown()) {
5268 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5269 out.write("DONE\n");
5270 out.flush();
5271 }
5272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005273 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005274 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005275 success = false;
5276 } finally {
5277 if (data != null) {
5278 data.recycle();
5279 }
5280 if (reply != null) {
5281 reply.recycle();
5282 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005283 if (out != null) {
5284 try {
5285 out.close();
5286 } catch (IOException e) {
5287
5288 }
5289 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005290 }
5291
5292 return success;
5293 }
5294
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005295 public void addWindowChangeListener(WindowChangeListener listener) {
5296 synchronized(mWindowMap) {
5297 mWindowChangeListeners.add(listener);
5298 }
5299 }
5300
5301 public void removeWindowChangeListener(WindowChangeListener listener) {
5302 synchronized(mWindowMap) {
5303 mWindowChangeListeners.remove(listener);
5304 }
5305 }
5306
5307 private void notifyWindowsChanged() {
5308 WindowChangeListener[] windowChangeListeners;
5309 synchronized(mWindowMap) {
5310 if(mWindowChangeListeners.isEmpty()) {
5311 return;
5312 }
5313 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5314 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5315 }
5316 int N = windowChangeListeners.length;
5317 for(int i = 0; i < N; i++) {
5318 windowChangeListeners[i].windowsChanged();
5319 }
5320 }
5321
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005322 private void notifyFocusChanged() {
5323 WindowChangeListener[] windowChangeListeners;
5324 synchronized(mWindowMap) {
5325 if(mWindowChangeListeners.isEmpty()) {
5326 return;
5327 }
5328 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5329 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5330 }
5331 int N = windowChangeListeners.length;
5332 for(int i = 0; i < N; i++) {
5333 windowChangeListeners[i].focusChanged();
5334 }
5335 }
5336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005337 private WindowState findWindow(int hashCode) {
5338 if (hashCode == -1) {
5339 return getFocusedWindow();
5340 }
5341
5342 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005343 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005344 final int count = windows.size();
5345
5346 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005347 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005348 if (System.identityHashCode(w) == hashCode) {
5349 return w;
5350 }
5351 }
5352 }
5353
5354 return null;
5355 }
5356
5357 /*
5358 * Instruct the Activity Manager to fetch the current configuration and broadcast
5359 * that to config-changed listeners if appropriate.
5360 */
5361 void sendNewConfiguration() {
5362 try {
5363 mActivityManager.updateConfiguration(null);
5364 } catch (RemoteException e) {
5365 }
5366 }
Romain Guy06882f82009-06-10 13:36:04 -07005367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005368 public Configuration computeNewConfiguration() {
5369 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005370 return computeNewConfigurationLocked();
5371 }
5372 }
Romain Guy06882f82009-06-10 13:36:04 -07005373
Dianne Hackbornc485a602009-03-24 22:39:49 -07005374 Configuration computeNewConfigurationLocked() {
5375 Configuration config = new Configuration();
5376 if (!computeNewConfigurationLocked(config)) {
5377 return null;
5378 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005379 return config;
5380 }
Romain Guy06882f82009-06-10 13:36:04 -07005381
Dianne Hackbornc485a602009-03-24 22:39:49 -07005382 boolean computeNewConfigurationLocked(Configuration config) {
5383 if (mDisplay == null) {
5384 return false;
5385 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005386
5387 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005388
5389 // Use the effective "visual" dimensions based on current rotation
5390 final boolean rotated = (mRotation == Surface.ROTATION_90
5391 || mRotation == Surface.ROTATION_270);
5392 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5393 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5394
Dianne Hackbornc485a602009-03-24 22:39:49 -07005395 int orientation = Configuration.ORIENTATION_SQUARE;
5396 if (dw < dh) {
5397 orientation = Configuration.ORIENTATION_PORTRAIT;
5398 } else if (dw > dh) {
5399 orientation = Configuration.ORIENTATION_LANDSCAPE;
5400 }
5401 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005402
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005403 DisplayMetrics dm = new DisplayMetrics();
5404 mDisplay.getMetrics(dm);
5405 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5406
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005407 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005408 // Note we only do this once because at this point we don't
5409 // expect the screen to change in this way at runtime, and want
5410 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005411 int longSize = dw;
5412 int shortSize = dh;
5413 if (longSize < shortSize) {
5414 int tmp = longSize;
5415 longSize = shortSize;
5416 shortSize = tmp;
5417 }
5418 longSize = (int)(longSize/dm.density);
5419 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005420
Dianne Hackborn723738c2009-06-25 19:48:04 -07005421 // These semi-magic numbers define our compatibility modes for
5422 // applications with different screens. Don't change unless you
5423 // make sure to test lots and lots of apps!
5424 if (longSize < 470) {
5425 // This is shorter than an HVGA normal density screen (which
5426 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005427 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5428 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005429 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005430 // What size is this screen screen?
5431 if (longSize >= 800 && shortSize >= 600) {
5432 // SVGA or larger screens at medium density are the point
5433 // at which we consider it to be an extra large screen.
5434 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005435 } else if (longSize >= 530 && shortSize >= 400) {
5436 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005437 // at which we consider it to be a large screen.
5438 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5439 } else {
5440 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005441
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005442 // If this screen is wider than normal HVGA, or taller
5443 // than FWVGA, then for old apps we want to run in size
5444 // compatibility mode.
5445 if (shortSize > 321 || longSize > 570) {
5446 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5447 }
5448 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005449
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005450 // Is this a long screen?
5451 if (((longSize*3)/5) >= (shortSize-1)) {
5452 // Anything wider than WVGA (5:3) is considering to be long.
5453 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5454 } else {
5455 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5456 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005457 }
5458 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005459 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005460
Dianne Hackbornc485a602009-03-24 22:39:49 -07005461 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5462 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5463 mPolicy.adjustConfigurationLw(config);
5464 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005465 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005466
5467 // -------------------------------------------------------------
5468 // Drag and drop
5469 // -------------------------------------------------------------
5470
5471 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5472 boolean localOnly, int width, int height, Surface outSurface) {
5473 if (DEBUG_DRAG) {
5474 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5475 + " local=" + localOnly + " win=" + window
5476 + " asbinder=" + window.asBinder());
5477 }
5478
5479 final int callerPid = Binder.getCallingPid();
5480 final long origId = Binder.clearCallingIdentity();
5481 IBinder token = null;
5482
5483 try {
5484 synchronized (mWindowMap) {
5485 try {
5486 // !!! TODO: fail if the given window does not currently have touch focus?
5487
5488 if (mDragState == null) {
5489 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5490 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5491 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005492 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005493 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005494 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005495 mDragState.mSurface = surface;
5496 mDragState.mLocalOnly = localOnly;
5497 token = mDragState.mToken = new Binder();
5498
5499 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005500 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5501 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005502 mH.sendMessageDelayed(msg, 5000);
5503 } else {
5504 Slog.w(TAG, "Drag already in progress");
5505 }
5506 } catch (Surface.OutOfResourcesException e) {
5507 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5508 if (mDragState != null) {
5509 mDragState.reset();
5510 mDragState = null;
5511 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005512 }
5513 }
5514 } finally {
5515 Binder.restoreCallingIdentity(origId);
5516 }
5517
5518 return token;
5519 }
5520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005521 // -------------------------------------------------------------
5522 // Input Events and Focus Management
5523 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005524
Jeff Brown349703e2010-06-22 01:27:15 -07005525 InputMonitor mInputMonitor = new InputMonitor();
5526
5527 /* Tracks the progress of input dispatch and ensures that input dispatch state
5528 * is kept in sync with changes in window focus, visibility, registration, and
5529 * other relevant Window Manager state transitions. */
5530 final class InputMonitor {
5531 // Current window with input focus for keys and other non-touch events. May be null.
5532 private WindowState mInputFocus;
5533
5534 // When true, prevents input dispatch from proceeding until set to false again.
5535 private boolean mInputDispatchFrozen;
5536
5537 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5538 private boolean mInputDispatchEnabled = true;
5539
5540 // Temporary list of windows information to provide to the input dispatcher.
5541 private InputWindowList mTempInputWindows = new InputWindowList();
5542
5543 // Temporary input application object to provide to the input dispatcher.
5544 private InputApplication mTempInputApplication = new InputApplication();
5545
5546 /* Notifies the window manager about a broken input channel.
5547 *
5548 * Called by the InputManager.
5549 */
5550 public void notifyInputChannelBroken(InputChannel inputChannel) {
5551 synchronized (mWindowMap) {
5552 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5553 if (windowState == null) {
5554 return; // irrelevant
5555 }
5556
5557 Slog.i(TAG, "WINDOW DIED " + windowState);
5558 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005559 }
5560 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005561
Jeff Brown519e0242010-09-15 15:18:56 -07005562 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005563 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005564 *
5565 * Called by the InputManager.
5566 */
Jeff Brown519e0242010-09-15 15:18:56 -07005567 public long notifyANR(Object token, InputChannel inputChannel) {
5568 AppWindowToken appWindowToken = null;
5569 if (inputChannel != null) {
5570 synchronized (mWindowMap) {
5571 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5572 if (windowState != null) {
5573 Slog.i(TAG, "Input event dispatching timed out sending to "
5574 + windowState.mAttrs.getTitle());
5575 appWindowToken = windowState.mAppToken;
5576 }
Jeff Brown349703e2010-06-22 01:27:15 -07005577 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005578 }
5579
Jeff Brown519e0242010-09-15 15:18:56 -07005580 if (appWindowToken == null && token != null) {
5581 appWindowToken = (AppWindowToken) token;
5582 Slog.i(TAG, "Input event dispatching timed out sending to application "
5583 + appWindowToken.stringName);
5584 }
Jeff Brown349703e2010-06-22 01:27:15 -07005585
Jeff Brown519e0242010-09-15 15:18:56 -07005586 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005587 try {
5588 // Notify the activity manager about the timeout and let it decide whether
5589 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005590 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005591 if (! abort) {
5592 // The activity manager declined to abort dispatching.
5593 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005594 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005595 }
Jeff Brown349703e2010-06-22 01:27:15 -07005596 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005597 }
5598 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005599 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005600 }
5601
Jeff Brown349703e2010-06-22 01:27:15 -07005602 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5603 synchronized (mWindowMap) {
5604 return getWindowStateForInputChannelLocked(inputChannel);
5605 }
5606 }
5607
5608 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5609 int windowCount = mWindows.size();
5610 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005611 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005612 if (windowState.mInputChannel == inputChannel) {
5613 return windowState;
5614 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005615 }
5616
Jeff Brown349703e2010-06-22 01:27:15 -07005617 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005618 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005619
Chris Tatea32dcf72010-10-14 12:13:50 -07005620 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005621 final InputWindow inputWindow = windowList.add();
5622 inputWindow.inputChannel = mDragState.mServerChannel;
5623 inputWindow.name = "drag";
5624 inputWindow.layoutParamsFlags = 0;
5625 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5626 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5627 inputWindow.visible = true;
5628 inputWindow.canReceiveKeys = false;
5629 inputWindow.hasFocus = true;
5630 inputWindow.hasWallpaper = false;
5631 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005632 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005633 inputWindow.ownerPid = Process.myPid();
5634 inputWindow.ownerUid = Process.myUid();
5635
5636 // The drag window covers the entire display
5637 inputWindow.frameLeft = 0;
5638 inputWindow.frameTop = 0;
5639 inputWindow.frameRight = mDisplay.getWidth();
5640 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005641
Christopher Tatea53146c2010-09-07 11:57:52 -07005642 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5643 inputWindow.visibleFrameTop = inputWindow.frameTop;
5644 inputWindow.visibleFrameRight = inputWindow.frameRight;
5645 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5646
5647 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5648 inputWindow.touchableAreaTop = inputWindow.frameTop;
5649 inputWindow.touchableAreaRight = inputWindow.frameRight;
5650 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5651 }
5652
Jeff Brown349703e2010-06-22 01:27:15 -07005653 /* Updates the cached window information provided to the input dispatcher. */
5654 public void updateInputWindowsLw() {
5655 // Populate the input window list with information about all of the windows that
5656 // could potentially receive input.
5657 // As an optimization, we could try to prune the list of windows but this turns
5658 // out to be difficult because only the native code knows for sure which window
5659 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005660 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005661
5662 // If there's a drag in flight, provide a pseudowindow to catch drag input
5663 final boolean inDrag = (mDragState != null);
5664 if (inDrag) {
5665 if (DEBUG_DRAG) {
5666 Log.d(TAG, "Inserting drag window");
5667 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005668 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005669 }
5670
Jeff Brown7fbdc842010-06-17 20:52:56 -07005671 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005672 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005673 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005674 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005675 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005676 continue;
5677 }
5678
Jeff Brown349703e2010-06-22 01:27:15 -07005679 final int flags = child.mAttrs.flags;
5680 final int type = child.mAttrs.type;
5681
5682 final boolean hasFocus = (child == mInputFocus);
5683 final boolean isVisible = child.isVisibleLw();
5684 final boolean hasWallpaper = (child == mWallpaperTarget)
5685 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005686
5687 // If there's a drag in progress and 'child' is a potential drop target,
5688 // make sure it's been told about the drag
5689 if (inDrag && isVisible) {
5690 mDragState.sendDragStartedIfNeededLw(child);
5691 }
5692
Jeff Brown349703e2010-06-22 01:27:15 -07005693 // Add a window to our list of input windows.
5694 final InputWindow inputWindow = mTempInputWindows.add();
5695 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005696 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005697 inputWindow.layoutParamsFlags = flags;
5698 inputWindow.layoutParamsType = type;
5699 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5700 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005701 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005702 inputWindow.hasFocus = hasFocus;
5703 inputWindow.hasWallpaper = hasWallpaper;
5704 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005705 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005706 inputWindow.ownerPid = child.mSession.mPid;
5707 inputWindow.ownerUid = child.mSession.mUid;
5708
5709 final Rect frame = child.mFrame;
5710 inputWindow.frameLeft = frame.left;
5711 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005712 inputWindow.frameRight = frame.right;
5713 inputWindow.frameBottom = frame.bottom;
5714
5715 final Rect visibleFrame = child.mVisibleFrame;
5716 inputWindow.visibleFrameLeft = visibleFrame.left;
5717 inputWindow.visibleFrameTop = visibleFrame.top;
5718 inputWindow.visibleFrameRight = visibleFrame.right;
5719 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005720
5721 switch (child.mTouchableInsets) {
5722 default:
5723 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5724 inputWindow.touchableAreaLeft = frame.left;
5725 inputWindow.touchableAreaTop = frame.top;
5726 inputWindow.touchableAreaRight = frame.right;
5727 inputWindow.touchableAreaBottom = frame.bottom;
5728 break;
5729
5730 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5731 Rect inset = child.mGivenContentInsets;
5732 inputWindow.touchableAreaLeft = frame.left + inset.left;
5733 inputWindow.touchableAreaTop = frame.top + inset.top;
5734 inputWindow.touchableAreaRight = frame.right - inset.right;
5735 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5736 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005737 }
Jeff Brown349703e2010-06-22 01:27:15 -07005738
5739 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5740 Rect inset = child.mGivenVisibleInsets;
5741 inputWindow.touchableAreaLeft = frame.left + inset.left;
5742 inputWindow.touchableAreaTop = frame.top + inset.top;
5743 inputWindow.touchableAreaRight = frame.right - inset.right;
5744 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005745 break;
5746 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005747 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005748 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005749
Jeff Brown349703e2010-06-22 01:27:15 -07005750 // Send windows to native code.
5751 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005752
Jeff Brown349703e2010-06-22 01:27:15 -07005753 // Clear the list in preparation for the next round.
5754 // Also avoids keeping InputChannel objects referenced unnecessarily.
5755 mTempInputWindows.clear();
5756 }
5757
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005758 /* Notifies that the lid switch changed state. */
5759 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5760 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5761 }
5762
Jeff Brown349703e2010-06-22 01:27:15 -07005763 /* Provides an opportunity for the window manager policy to intercept early key
5764 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005765 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5766 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5767 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5768 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005769 }
5770
5771 /* Provides an opportunity for the window manager policy to process a key before
5772 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005773 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005774 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005775 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005776 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005777 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005778 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005779 }
5780
5781 /* Called when the current input focus changes.
5782 * Layer assignment is assumed to be complete by the time this is called.
5783 */
5784 public void setInputFocusLw(WindowState newWindow) {
5785 if (DEBUG_INPUT) {
5786 Slog.d(TAG, "Input focus has changed to " + newWindow);
5787 }
5788
5789 if (newWindow != mInputFocus) {
5790 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005791 // Displaying a window implicitly causes dispatching to be unpaused.
5792 // This is to protect against bugs if someone pauses dispatching but
5793 // forgets to resume.
5794 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005795 }
Jeff Brown349703e2010-06-22 01:27:15 -07005796
5797 mInputFocus = newWindow;
5798 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005799 }
5800 }
5801
Jeff Brown349703e2010-06-22 01:27:15 -07005802 public void setFocusedAppLw(AppWindowToken newApp) {
5803 // Focused app has changed.
5804 if (newApp == null) {
5805 mInputManager.setFocusedApplication(null);
5806 } else {
5807 mTempInputApplication.name = newApp.toString();
5808 mTempInputApplication.dispatchingTimeoutNanos =
5809 newApp.inputDispatchingTimeoutNanos;
5810 mTempInputApplication.token = newApp;
5811
5812 mInputManager.setFocusedApplication(mTempInputApplication);
5813 }
5814 }
5815
Jeff Brown349703e2010-06-22 01:27:15 -07005816 public void pauseDispatchingLw(WindowToken window) {
5817 if (! window.paused) {
5818 if (DEBUG_INPUT) {
5819 Slog.v(TAG, "Pausing WindowToken " + window);
5820 }
5821
5822 window.paused = true;
5823 updateInputWindowsLw();
5824 }
5825 }
5826
5827 public void resumeDispatchingLw(WindowToken window) {
5828 if (window.paused) {
5829 if (DEBUG_INPUT) {
5830 Slog.v(TAG, "Resuming WindowToken " + window);
5831 }
5832
5833 window.paused = false;
5834 updateInputWindowsLw();
5835 }
5836 }
5837
5838 public void freezeInputDispatchingLw() {
5839 if (! mInputDispatchFrozen) {
5840 if (DEBUG_INPUT) {
5841 Slog.v(TAG, "Freezing input dispatching");
5842 }
5843
5844 mInputDispatchFrozen = true;
5845 updateInputDispatchModeLw();
5846 }
5847 }
5848
5849 public void thawInputDispatchingLw() {
5850 if (mInputDispatchFrozen) {
5851 if (DEBUG_INPUT) {
5852 Slog.v(TAG, "Thawing input dispatching");
5853 }
5854
5855 mInputDispatchFrozen = false;
5856 updateInputDispatchModeLw();
5857 }
5858 }
5859
5860 public void setEventDispatchingLw(boolean enabled) {
5861 if (mInputDispatchEnabled != enabled) {
5862 if (DEBUG_INPUT) {
5863 Slog.v(TAG, "Setting event dispatching to " + enabled);
5864 }
5865
5866 mInputDispatchEnabled = enabled;
5867 updateInputDispatchModeLw();
5868 }
5869 }
5870
5871 private void updateInputDispatchModeLw() {
5872 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5873 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005876 public void pauseKeyDispatching(IBinder _token) {
5877 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5878 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005879 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 }
5881
5882 synchronized (mWindowMap) {
5883 WindowToken token = mTokenMap.get(_token);
5884 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005885 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 }
5887 }
5888 }
5889
5890 public void resumeKeyDispatching(IBinder _token) {
5891 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5892 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005893 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005894 }
5895
5896 synchronized (mWindowMap) {
5897 WindowToken token = mTokenMap.get(_token);
5898 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005899 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 }
5901 }
5902 }
5903
5904 public void setEventDispatching(boolean enabled) {
5905 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5906 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005907 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005908 }
5909
5910 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005911 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005912 }
5913 }
Romain Guy06882f82009-06-10 13:36:04 -07005914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 /**
5916 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005917 * Even when sync is false, this method may block while waiting for current
5918 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005919 *
5920 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005921 * {@link SystemClock#uptimeMillis()} as the timebase.)
5922 * @param sync If true, wait for the event to be completed before returning to the caller.
5923 * @return Returns true if event was dispatched, false if it was dropped for any reason
5924 */
5925 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5926 long downTime = ev.getDownTime();
5927 long eventTime = ev.getEventTime();
5928
5929 int action = ev.getAction();
5930 int code = ev.getKeyCode();
5931 int repeatCount = ev.getRepeatCount();
5932 int metaState = ev.getMetaState();
5933 int deviceId = ev.getDeviceId();
5934 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005935 int source = ev.getSource();
5936
5937 if (source == InputDevice.SOURCE_UNKNOWN) {
5938 source = InputDevice.SOURCE_KEYBOARD;
5939 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005940
5941 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5942 if (downTime == 0) downTime = eventTime;
5943
5944 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005945 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005946
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005947 final int pid = Binder.getCallingPid();
5948 final int uid = Binder.getCallingUid();
5949 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005950
Jeff Brownbbda99d2010-07-28 15:48:59 -07005951 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5952 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5953 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5954 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005955
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005956 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005957 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005958 }
5959
5960 /**
5961 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005962 * Even when sync is false, this method may block while waiting for current
5963 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005964 *
5965 * @param ev A motion event describing the pointer (touch) action. (As noted in
5966 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005967 * {@link SystemClock#uptimeMillis()} as the timebase.)
5968 * @param sync If true, wait for the event to be completed before returning to the caller.
5969 * @return Returns true if event was dispatched, false if it was dropped for any reason
5970 */
5971 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005972 final int pid = Binder.getCallingPid();
5973 final int uid = Binder.getCallingUid();
5974 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005975
Jeff Brownc5ed5912010-07-14 18:48:53 -07005976 MotionEvent newEvent = MotionEvent.obtain(ev);
5977 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5978 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5979 }
5980
Jeff Brownbbda99d2010-07-28 15:48:59 -07005981 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5982 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5983 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5984 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005985
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005986 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005987 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005988 }
Romain Guy06882f82009-06-10 13:36:04 -07005989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005990 /**
5991 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005992 * Even when sync is false, this method may block while waiting for current
5993 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005994 *
5995 * @param ev A motion event describing the trackball action. (As noted in
5996 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005997 * {@link SystemClock#uptimeMillis()} as the timebase.)
5998 * @param sync If true, wait for the event to be completed before returning to the caller.
5999 * @return Returns true if event was dispatched, false if it was dropped for any reason
6000 */
6001 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006002 final int pid = Binder.getCallingPid();
6003 final int uid = Binder.getCallingUid();
6004 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006005
Jeff Brownc5ed5912010-07-14 18:48:53 -07006006 MotionEvent newEvent = MotionEvent.obtain(ev);
6007 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6008 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6009 }
6010
Jeff Brownbbda99d2010-07-28 15:48:59 -07006011 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6012 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6013 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6014 INJECTION_TIMEOUT_MILLIS);
6015
6016 Binder.restoreCallingIdentity(ident);
6017 return reportInjectionResult(result);
6018 }
6019
6020 /**
6021 * Inject an input event into the UI without waiting for dispatch to commence.
6022 * This variant is useful for fire-and-forget input event injection. It does not
6023 * block any longer than it takes to enqueue the input event.
6024 *
6025 * @param ev An input event. (Be sure to set the input source correctly.)
6026 * @return Returns true if event was dispatched, false if it was dropped for any reason
6027 */
6028 public boolean injectInputEventNoWait(InputEvent ev) {
6029 final int pid = Binder.getCallingPid();
6030 final int uid = Binder.getCallingUid();
6031 final long ident = Binder.clearCallingIdentity();
6032
6033 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6034 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6035 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006036
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006037 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006038 return reportInjectionResult(result);
6039 }
6040
6041 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006042 switch (result) {
6043 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6044 Slog.w(TAG, "Input event injection permission denied.");
6045 throw new SecurityException(
6046 "Injecting to another application requires INJECT_EVENTS permission");
6047 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006048 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006049 return true;
6050 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6051 Slog.w(TAG, "Input event injection timed out.");
6052 return false;
6053 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6054 default:
6055 Slog.w(TAG, "Input event injection failed.");
6056 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006058 }
Romain Guy06882f82009-06-10 13:36:04 -07006059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006060 private WindowState getFocusedWindow() {
6061 synchronized (mWindowMap) {
6062 return getFocusedWindowLocked();
6063 }
6064 }
6065
6066 private WindowState getFocusedWindowLocked() {
6067 return mCurrentFocus;
6068 }
Romain Guy06882f82009-06-10 13:36:04 -07006069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006070 public boolean detectSafeMode() {
6071 mSafeMode = mPolicy.detectSafeMode();
6072 return mSafeMode;
6073 }
Romain Guy06882f82009-06-10 13:36:04 -07006074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006075 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006076 synchronized(mWindowMap) {
6077 if (mDisplay != null) {
6078 throw new IllegalStateException("Display already initialized");
6079 }
6080 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6081 mDisplay = wm.getDefaultDisplay();
6082 mInitialDisplayWidth = mDisplay.getWidth();
6083 mInitialDisplayHeight = mDisplay.getHeight();
6084 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6085 }
6086
6087 try {
6088 mActivityManager.updateConfiguration(null);
6089 } catch (RemoteException e) {
6090 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006091
6092 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006093 }
6094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006095 // -------------------------------------------------------------
6096 // Client Session State
6097 // -------------------------------------------------------------
6098
6099 private final class Session extends IWindowSession.Stub
6100 implements IBinder.DeathRecipient {
6101 final IInputMethodClient mClient;
6102 final IInputContext mInputContext;
6103 final int mUid;
6104 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006105 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006106 SurfaceSession mSurfaceSession;
6107 int mNumWindow = 0;
6108 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006110 public Session(IInputMethodClient client, IInputContext inputContext) {
6111 mClient = client;
6112 mInputContext = inputContext;
6113 mUid = Binder.getCallingUid();
6114 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006115 StringBuilder sb = new StringBuilder();
6116 sb.append("Session{");
6117 sb.append(Integer.toHexString(System.identityHashCode(this)));
6118 sb.append(" uid ");
6119 sb.append(mUid);
6120 sb.append("}");
6121 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123 synchronized (mWindowMap) {
6124 if (mInputMethodManager == null && mHaveInputMethods) {
6125 IBinder b = ServiceManager.getService(
6126 Context.INPUT_METHOD_SERVICE);
6127 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6128 }
6129 }
6130 long ident = Binder.clearCallingIdentity();
6131 try {
6132 // Note: it is safe to call in to the input method manager
6133 // here because we are not holding our lock.
6134 if (mInputMethodManager != null) {
6135 mInputMethodManager.addClient(client, inputContext,
6136 mUid, mPid);
6137 } else {
6138 client.setUsingInputMethod(false);
6139 }
6140 client.asBinder().linkToDeath(this, 0);
6141 } catch (RemoteException e) {
6142 // The caller has died, so we can just forget about this.
6143 try {
6144 if (mInputMethodManager != null) {
6145 mInputMethodManager.removeClient(client);
6146 }
6147 } catch (RemoteException ee) {
6148 }
6149 } finally {
6150 Binder.restoreCallingIdentity(ident);
6151 }
6152 }
Romain Guy06882f82009-06-10 13:36:04 -07006153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 @Override
6155 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6156 throws RemoteException {
6157 try {
6158 return super.onTransact(code, data, reply, flags);
6159 } catch (RuntimeException e) {
6160 // Log all 'real' exceptions thrown to the caller
6161 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006162 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006163 }
6164 throw e;
6165 }
6166 }
6167
6168 public void binderDied() {
6169 // Note: it is safe to call in to the input method manager
6170 // here because we are not holding our lock.
6171 try {
6172 if (mInputMethodManager != null) {
6173 mInputMethodManager.removeClient(mClient);
6174 }
6175 } catch (RemoteException e) {
6176 }
6177 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006178 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006179 mClientDead = true;
6180 killSessionLocked();
6181 }
6182 }
6183
6184 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006185 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6186 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6187 outInputChannel);
6188 }
6189
6190 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006192 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193 }
Romain Guy06882f82009-06-10 13:36:04 -07006194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006195 public void remove(IWindow window) {
6196 removeWindow(this, window);
6197 }
Romain Guy06882f82009-06-10 13:36:04 -07006198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006199 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6200 int requestedWidth, int requestedHeight, int viewFlags,
6201 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006202 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006203 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6204 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006205 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006206 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006207 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6208 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209 }
Romain Guy06882f82009-06-10 13:36:04 -07006210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006211 public void setTransparentRegion(IWindow window, Region region) {
6212 setTransparentRegionWindow(this, window, region);
6213 }
Romain Guy06882f82009-06-10 13:36:04 -07006214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006215 public void setInsets(IWindow window, int touchableInsets,
6216 Rect contentInsets, Rect visibleInsets) {
6217 setInsetsWindow(this, window, touchableInsets, contentInsets,
6218 visibleInsets);
6219 }
Romain Guy06882f82009-06-10 13:36:04 -07006220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006221 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6222 getWindowDisplayFrame(this, window, outDisplayFrame);
6223 }
Romain Guy06882f82009-06-10 13:36:04 -07006224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006225 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006226 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006227 TAG, "IWindow finishDrawing called for " + window);
6228 finishDrawingWindow(this, window);
6229 }
6230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006231 public void setInTouchMode(boolean mode) {
6232 synchronized(mWindowMap) {
6233 mInTouchMode = mode;
6234 }
6235 }
6236
6237 public boolean getInTouchMode() {
6238 synchronized(mWindowMap) {
6239 return mInTouchMode;
6240 }
6241 }
6242
6243 public boolean performHapticFeedback(IWindow window, int effectId,
6244 boolean always) {
6245 synchronized(mWindowMap) {
6246 long ident = Binder.clearCallingIdentity();
6247 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006248 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006249 windowForClientLocked(this, window, true),
6250 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006251 } finally {
6252 Binder.restoreCallingIdentity(ident);
6253 }
6254 }
6255 }
Romain Guy06882f82009-06-10 13:36:04 -07006256
Christopher Tatea53146c2010-09-07 11:57:52 -07006257 /* Drag/drop */
6258 public IBinder prepareDrag(IWindow window, boolean localOnly,
6259 int width, int height, Surface outSurface) {
6260 return prepareDragSurface(window, mSurfaceSession, localOnly,
6261 width, height, outSurface);
6262 }
6263
6264 public boolean performDrag(IWindow window, IBinder dragToken,
6265 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6266 ClipData data) {
6267 if (DEBUG_DRAG) {
6268 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6269 }
6270
6271 synchronized (mWindowMap) {
6272 if (mDragState == null) {
6273 Slog.w(TAG, "No drag prepared");
6274 throw new IllegalStateException("performDrag() without prepareDrag()");
6275 }
6276
6277 if (dragToken != mDragState.mToken) {
6278 Slog.w(TAG, "Performing mismatched drag");
6279 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6280 }
6281
6282 WindowState callingWin = windowForClientLocked(null, window, false);
6283 if (callingWin == null) {
6284 Slog.w(TAG, "Bad requesting window " + window);
6285 return false; // !!! TODO: throw here?
6286 }
6287
6288 // !!! TODO: if input is not still focused on the initiating window, fail
6289 // the drag initiation (e.g. an alarm window popped up just as the application
6290 // called performDrag()
6291
6292 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6293
Christopher Tate2c095f32010-10-04 14:13:40 -07006294 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6295 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006296
Chris Tateb478f462010-10-15 16:02:26 -07006297 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6298 // the actual drag event dispatch stuff in the dragstate
6299
Christopher Tatea53146c2010-09-07 11:57:52 -07006300 mDragState.register();
6301 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006302 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6303 mDragState.mServerChannel)) {
6304 Slog.e(TAG, "Unable to transfer touch focus");
6305 mDragState.unregister();
6306 mDragState = null;
6307 mInputMonitor.updateInputWindowsLw();
6308 return false;
6309 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006310
6311 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006312 mDragState.mCurrentX = touchX;
6313 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006314 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006315
6316 // remember the thumb offsets for later
6317 mDragState.mThumbOffsetX = thumbCenterX;
6318 mDragState.mThumbOffsetY = thumbCenterY;
6319
6320 // Make the surface visible at the proper location
6321 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006322 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006323 try {
6324 surface.setPosition((int)(touchX - thumbCenterX),
6325 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006326 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006327 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006328 surface.show();
6329 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006330 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006331 }
6332 }
6333
6334 return true; // success!
6335 }
6336
Chris Tated4533f142010-10-19 15:15:08 -07006337 public void reportDropResult(IWindow window, boolean consumed) {
6338 IBinder token = window.asBinder();
6339 if (DEBUG_DRAG) {
6340 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6341 }
6342
6343 synchronized (mWindowMap) {
6344 if (mDragState.mToken != token) {
6345 Slog.w(TAG, "Invalid drop-result claim by " + window);
6346 throw new IllegalStateException("reportDropResult() by non-recipient");
6347 }
6348
6349 // The right window has responded, even if it's no longer around,
6350 // so be sure to halt the timeout even if the later WindowState
6351 // lookup fails.
6352 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6353
6354 WindowState callingWin = windowForClientLocked(null, window, false);
6355 if (callingWin == null) {
6356 Slog.w(TAG, "Bad result-reporting window " + window);
6357 return; // !!! TODO: throw here?
6358 }
6359
6360 mDragState.mDragResult = consumed;
6361 mDragState.endDragLw();
6362 }
6363 }
6364
Christopher Tatea53146c2010-09-07 11:57:52 -07006365 public void dragRecipientEntered(IWindow window) {
6366 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006367 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006368 }
6369 }
6370
6371 public void dragRecipientExited(IWindow window) {
6372 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006373 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006374 }
6375 }
6376
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006377 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006378 synchronized(mWindowMap) {
6379 long ident = Binder.clearCallingIdentity();
6380 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006381 setWindowWallpaperPositionLocked(
6382 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006383 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006384 } finally {
6385 Binder.restoreCallingIdentity(ident);
6386 }
6387 }
6388 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006389
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006390 public void wallpaperOffsetsComplete(IBinder window) {
6391 WindowManagerService.this.wallpaperOffsetsComplete(window);
6392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006393
Dianne Hackborn75804932009-10-20 20:15:20 -07006394 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6395 int z, Bundle extras, boolean sync) {
6396 synchronized(mWindowMap) {
6397 long ident = Binder.clearCallingIdentity();
6398 try {
6399 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006400 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006401 action, x, y, z, extras, sync);
6402 } finally {
6403 Binder.restoreCallingIdentity(ident);
6404 }
6405 }
6406 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006407
Dianne Hackborn75804932009-10-20 20:15:20 -07006408 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6409 WindowManagerService.this.wallpaperCommandComplete(window, result);
6410 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006412 void windowAddedLocked() {
6413 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006414 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 TAG, "First window added to " + this + ", creating SurfaceSession");
6416 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006417 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006418 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 mSessions.add(this);
6420 }
6421 mNumWindow++;
6422 }
6423
6424 void windowRemovedLocked() {
6425 mNumWindow--;
6426 killSessionLocked();
6427 }
Romain Guy06882f82009-06-10 13:36:04 -07006428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 void killSessionLocked() {
6430 if (mNumWindow <= 0 && mClientDead) {
6431 mSessions.remove(this);
6432 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006433 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006434 TAG, "Last window removed from " + this
6435 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006436 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006437 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 try {
6439 mSurfaceSession.kill();
6440 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006441 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 + mSurfaceSession + " in session " + this
6443 + ": " + e.toString());
6444 }
6445 mSurfaceSession = null;
6446 }
6447 }
6448 }
Romain Guy06882f82009-06-10 13:36:04 -07006449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006450 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006451 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6452 pw.print(" mClientDead="); pw.print(mClientDead);
6453 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 }
6455
6456 @Override
6457 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006458 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006459 }
6460 }
6461
6462 // -------------------------------------------------------------
6463 // Client Window State
6464 // -------------------------------------------------------------
6465
6466 private final class WindowState implements WindowManagerPolicy.WindowState {
6467 final Session mSession;
6468 final IWindow mClient;
6469 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006470 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006471 AppWindowToken mAppToken;
6472 AppWindowToken mTargetAppToken;
6473 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6474 final DeathRecipient mDeathRecipient;
6475 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006476 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006477 final int mBaseLayer;
6478 final int mSubLayer;
6479 final boolean mLayoutAttached;
6480 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006481 final boolean mIsWallpaper;
6482 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 int mViewVisibility;
6484 boolean mPolicyVisibility = true;
6485 boolean mPolicyVisibilityAfterAnim = true;
6486 boolean mAppFreezing;
6487 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006488 boolean mReportDestroySurface;
6489 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 boolean mAttachedHidden; // is our parent window hidden?
6491 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006492 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 int mRequestedWidth;
6494 int mRequestedHeight;
6495 int mLastRequestedWidth;
6496 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006497 int mLayer;
6498 int mAnimLayer;
6499 int mLastLayer;
6500 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006501 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006502 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006504 int mLayoutSeq = -1;
6505
6506 Configuration mConfiguration = null;
6507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 // Actual frame shown on-screen (may be modified by animation)
6509 final Rect mShownFrame = new Rect();
6510 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006512 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006513 * Set when we have changed the size of the surface, to know that
6514 * we must tell them application to resize (and thus redraw itself).
6515 */
6516 boolean mSurfaceResized;
6517
6518 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 * Insets that determine the actually visible area
6520 */
6521 final Rect mVisibleInsets = new Rect();
6522 final Rect mLastVisibleInsets = new Rect();
6523 boolean mVisibleInsetsChanged;
6524
6525 /**
6526 * Insets that are covered by system windows
6527 */
6528 final Rect mContentInsets = new Rect();
6529 final Rect mLastContentInsets = new Rect();
6530 boolean mContentInsetsChanged;
6531
6532 /**
6533 * Set to true if we are waiting for this window to receive its
6534 * given internal insets before laying out other windows based on it.
6535 */
6536 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006538 /**
6539 * These are the content insets that were given during layout for
6540 * this window, to be applied to windows behind it.
6541 */
6542 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006544 /**
6545 * These are the visible insets that were given during layout for
6546 * this window, to be applied to windows behind it.
6547 */
6548 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006550 /**
6551 * Flag indicating whether the touchable region should be adjusted by
6552 * the visible insets; if false the area outside the visible insets is
6553 * NOT touchable, so we must use those to adjust the frame during hit
6554 * tests.
6555 */
6556 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 // Current transformation being applied.
6559 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6560 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6561 float mHScale=1, mVScale=1;
6562 float mLastHScale=1, mLastVScale=1;
6563 final Matrix mTmpMatrix = new Matrix();
6564
6565 // "Real" frame that the application sees.
6566 final Rect mFrame = new Rect();
6567 final Rect mLastFrame = new Rect();
6568
6569 final Rect mContainingFrame = new Rect();
6570 final Rect mDisplayFrame = new Rect();
6571 final Rect mContentFrame = new Rect();
6572 final Rect mVisibleFrame = new Rect();
6573
6574 float mShownAlpha = 1;
6575 float mAlpha = 1;
6576 float mLastAlpha = 1;
6577
6578 // Set to true if, when the window gets displayed, it should perform
6579 // an enter animation.
6580 boolean mEnterAnimationPending;
6581
6582 // Currently running animation.
6583 boolean mAnimating;
6584 boolean mLocalAnimating;
6585 Animation mAnimation;
6586 boolean mAnimationIsEntrance;
6587 boolean mHasTransformation;
6588 boolean mHasLocalTransformation;
6589 final Transformation mTransformation = new Transformation();
6590
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006591 // If a window showing a wallpaper: the requested offset for the
6592 // wallpaper; if a wallpaper window: the currently applied offset.
6593 float mWallpaperX = -1;
6594 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006595
6596 // If a window showing a wallpaper: what fraction of the offset
6597 // range corresponds to a full virtual screen.
6598 float mWallpaperXStep = -1;
6599 float mWallpaperYStep = -1;
6600
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006601 // Wallpaper windows: pixels offset based on above variables.
6602 int mXOffset;
6603 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006605 // This is set after IWindowSession.relayout() has been called at
6606 // least once for the window. It allows us to detect the situation
6607 // where we don't yet have a surface, but should have one soon, so
6608 // we can give the window focus before waiting for the relayout.
6609 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006611 // This is set after the Surface has been created but before the
6612 // window has been drawn. During this time the surface is hidden.
6613 boolean mDrawPending;
6614
6615 // This is set after the window has finished drawing for the first
6616 // time but before its surface is shown. The surface will be
6617 // displayed when the next layout is run.
6618 boolean mCommitDrawPending;
6619
6620 // This is set during the time after the window's drawing has been
6621 // committed, and before its surface is actually shown. It is used
6622 // to delay showing the surface until all windows in a token are ready
6623 // to be shown.
6624 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626 // Set when the window has been shown in the screen the first time.
6627 boolean mHasDrawn;
6628
6629 // Currently running an exit animation?
6630 boolean mExiting;
6631
6632 // Currently on the mDestroySurface list?
6633 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 // Completely remove from window manager after exit animation?
6636 boolean mRemoveOnExit;
6637
6638 // Set when the orientation is changing and this window has not yet
6639 // been updated for the new orientation.
6640 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642 // Is this window now (or just being) removed?
6643 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006644
Dianne Hackborn16064f92010-03-25 00:47:24 -07006645 // For debugging, this is the last information given to the surface flinger.
6646 boolean mSurfaceShown;
6647 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6648 int mSurfaceLayer;
6649 float mSurfaceAlpha;
6650
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006651 // Input channel
6652 InputChannel mInputChannel;
6653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654 WindowState(Session s, IWindow c, WindowToken token,
6655 WindowState attachedWindow, WindowManager.LayoutParams a,
6656 int viewVisibility) {
6657 mSession = s;
6658 mClient = c;
6659 mToken = token;
6660 mAttrs.copyFrom(a);
6661 mViewVisibility = viewVisibility;
6662 DeathRecipient deathRecipient = new DeathRecipient();
6663 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006664 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006665 TAG, "Window " + this + " client=" + c.asBinder()
6666 + " token=" + token + " (" + mAttrs.token + ")");
6667 try {
6668 c.asBinder().linkToDeath(deathRecipient, 0);
6669 } catch (RemoteException e) {
6670 mDeathRecipient = null;
6671 mAttachedWindow = null;
6672 mLayoutAttached = false;
6673 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006674 mIsWallpaper = false;
6675 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 mBaseLayer = 0;
6677 mSubLayer = 0;
6678 return;
6679 }
6680 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006682 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6683 mAttrs.type <= LAST_SUB_WINDOW)) {
6684 // The multiplier here is to reserve space for multiple
6685 // windows in the same type layer.
6686 mBaseLayer = mPolicy.windowTypeToLayerLw(
6687 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6688 + TYPE_LAYER_OFFSET;
6689 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6690 mAttachedWindow = attachedWindow;
6691 mAttachedWindow.mChildWindows.add(this);
6692 mLayoutAttached = mAttrs.type !=
6693 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6694 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6695 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006696 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6697 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006698 } else {
6699 // The multiplier here is to reserve space for multiple
6700 // windows in the same type layer.
6701 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6702 * TYPE_LAYER_MULTIPLIER
6703 + TYPE_LAYER_OFFSET;
6704 mSubLayer = 0;
6705 mAttachedWindow = null;
6706 mLayoutAttached = false;
6707 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6708 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006709 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6710 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006711 }
6712
6713 WindowState appWin = this;
6714 while (appWin.mAttachedWindow != null) {
6715 appWin = mAttachedWindow;
6716 }
6717 WindowToken appToken = appWin.mToken;
6718 while (appToken.appWindowToken == null) {
6719 WindowToken parent = mTokenMap.get(appToken.token);
6720 if (parent == null || appToken == parent) {
6721 break;
6722 }
6723 appToken = parent;
6724 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006725 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006726 mAppToken = appToken.appWindowToken;
6727
6728 mSurface = null;
6729 mRequestedWidth = 0;
6730 mRequestedHeight = 0;
6731 mLastRequestedWidth = 0;
6732 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006733 mXOffset = 0;
6734 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006735 mLayer = 0;
6736 mAnimLayer = 0;
6737 mLastLayer = 0;
6738 }
6739
6740 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006741 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 TAG, "Attaching " + this + " token=" + mToken
6743 + ", list=" + mToken.windows);
6744 mSession.windowAddedLocked();
6745 }
6746
6747 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6748 mHaveFrame = true;
6749
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006750 final Rect container = mContainingFrame;
6751 container.set(pf);
6752
6753 final Rect display = mDisplayFrame;
6754 display.set(df);
6755
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006756 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006757 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006758 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6759 display.intersect(mCompatibleScreenFrame);
6760 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006761 }
6762
6763 final int pw = container.right - container.left;
6764 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765
6766 int w,h;
6767 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6768 w = mAttrs.width < 0 ? pw : mAttrs.width;
6769 h = mAttrs.height< 0 ? ph : mAttrs.height;
6770 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006771 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6772 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 }
Romain Guy06882f82009-06-10 13:36:04 -07006774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006775 final Rect content = mContentFrame;
6776 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006778 final Rect visible = mVisibleFrame;
6779 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006781 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006782 final int fw = frame.width();
6783 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006785 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6786 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6787
6788 Gravity.apply(mAttrs.gravity, w, h, container,
6789 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6790 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6791
6792 //System.out.println("Out: " + mFrame);
6793
6794 // Now make sure the window fits in the overall display.
6795 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 // Make sure the content and visible frames are inside of the
6798 // final window frame.
6799 if (content.left < frame.left) content.left = frame.left;
6800 if (content.top < frame.top) content.top = frame.top;
6801 if (content.right > frame.right) content.right = frame.right;
6802 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6803 if (visible.left < frame.left) visible.left = frame.left;
6804 if (visible.top < frame.top) visible.top = frame.top;
6805 if (visible.right > frame.right) visible.right = frame.right;
6806 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006808 final Rect contentInsets = mContentInsets;
6809 contentInsets.left = content.left-frame.left;
6810 contentInsets.top = content.top-frame.top;
6811 contentInsets.right = frame.right-content.right;
6812 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 final Rect visibleInsets = mVisibleInsets;
6815 visibleInsets.left = visible.left-frame.left;
6816 visibleInsets.top = visible.top-frame.top;
6817 visibleInsets.right = frame.right-visible.right;
6818 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006819
Dianne Hackborn284ac932009-08-28 10:34:25 -07006820 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6821 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006822 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006823 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 if (localLOGV) {
6826 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6827 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006828 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006829 + mRequestedWidth + ", mRequestedheight="
6830 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6831 + "): frame=" + mFrame.toShortString()
6832 + " ci=" + contentInsets.toShortString()
6833 + " vi=" + visibleInsets.toShortString());
6834 //}
6835 }
6836 }
Romain Guy06882f82009-06-10 13:36:04 -07006837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 public Rect getFrameLw() {
6839 return mFrame;
6840 }
6841
6842 public Rect getShownFrameLw() {
6843 return mShownFrame;
6844 }
6845
6846 public Rect getDisplayFrameLw() {
6847 return mDisplayFrame;
6848 }
6849
6850 public Rect getContentFrameLw() {
6851 return mContentFrame;
6852 }
6853
6854 public Rect getVisibleFrameLw() {
6855 return mVisibleFrame;
6856 }
6857
6858 public boolean getGivenInsetsPendingLw() {
6859 return mGivenInsetsPending;
6860 }
6861
6862 public Rect getGivenContentInsetsLw() {
6863 return mGivenContentInsets;
6864 }
Romain Guy06882f82009-06-10 13:36:04 -07006865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 public Rect getGivenVisibleInsetsLw() {
6867 return mGivenVisibleInsets;
6868 }
Romain Guy06882f82009-06-10 13:36:04 -07006869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 public WindowManager.LayoutParams getAttrs() {
6871 return mAttrs;
6872 }
6873
6874 public int getSurfaceLayer() {
6875 return mLayer;
6876 }
Romain Guy06882f82009-06-10 13:36:04 -07006877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 public IApplicationToken getAppToken() {
6879 return mAppToken != null ? mAppToken.appToken : null;
6880 }
Jeff Brown349703e2010-06-22 01:27:15 -07006881
6882 public long getInputDispatchingTimeoutNanos() {
6883 return mAppToken != null
6884 ? mAppToken.inputDispatchingTimeoutNanos
6885 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6886 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887
6888 public boolean hasAppShownWindows() {
6889 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6890 }
6891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006892 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006893 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006894 TAG, "Setting animation in " + this + ": " + anim);
6895 mAnimating = false;
6896 mLocalAnimating = false;
6897 mAnimation = anim;
6898 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6899 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6900 }
6901
6902 public void clearAnimation() {
6903 if (mAnimation != null) {
6904 mAnimating = true;
6905 mLocalAnimating = false;
6906 mAnimation = null;
6907 }
6908 }
Romain Guy06882f82009-06-10 13:36:04 -07006909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006910 Surface createSurfaceLocked() {
6911 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006912 mReportDestroySurface = false;
6913 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 mDrawPending = true;
6915 mCommitDrawPending = false;
6916 mReadyToShow = false;
6917 if (mAppToken != null) {
6918 mAppToken.allDrawn = false;
6919 }
6920
6921 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006922 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006923 flags |= Surface.PUSH_BUFFERS;
6924 }
6925
6926 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6927 flags |= Surface.SECURE;
6928 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006929 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006930 TAG, "Creating surface in session "
6931 + mSession.mSurfaceSession + " window " + this
6932 + " w=" + mFrame.width()
6933 + " h=" + mFrame.height() + " format="
6934 + mAttrs.format + " flags=" + flags);
6935
6936 int w = mFrame.width();
6937 int h = mFrame.height();
6938 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6939 // for a scaled surface, we always want the requested
6940 // size.
6941 w = mRequestedWidth;
6942 h = mRequestedHeight;
6943 }
6944
Romain Guy9825ec62009-10-01 00:58:09 -07006945 // Something is wrong and SurfaceFlinger will not like this,
6946 // try to revert to sane values
6947 if (w <= 0) w = 1;
6948 if (h <= 0) h = 1;
6949
Dianne Hackborn16064f92010-03-25 00:47:24 -07006950 mSurfaceShown = false;
6951 mSurfaceLayer = 0;
6952 mSurfaceAlpha = 1;
6953 mSurfaceX = 0;
6954 mSurfaceY = 0;
6955 mSurfaceW = w;
6956 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006958 final boolean isHwAccelerated = (mAttrs.flags &
6959 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6960 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6961 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6962 flags |= Surface.OPAQUE;
6963 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006965 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006966 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006967 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006968 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006969 + mSurface + " IN SESSION "
6970 + mSession.mSurfaceSession
6971 + ": pid=" + mSession.mPid + " format="
6972 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006973 + Integer.toHexString(flags)
6974 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006976 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 reclaimSomeSurfaceMemoryLocked(this, "create");
6978 return null;
6979 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006980 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 return null;
6982 }
Romain Guy06882f82009-06-10 13:36:04 -07006983
Joe Onorato8a9b2202010-02-26 18:56:32 -08006984 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006985 TAG, "Got surface: " + mSurface
6986 + ", set left=" + mFrame.left + " top=" + mFrame.top
6987 + ", animLayer=" + mAnimLayer);
6988 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006989 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006990 if (SHOW_TRANSACTIONS) logSurface(this,
6991 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6992 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6993 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006994 }
6995 Surface.openTransaction();
6996 try {
6997 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006998 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006999 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007000 mSurface.setPosition(mSurfaceX, mSurfaceY);
7001 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007002 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007003 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007004 mSurface.hide();
7005 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007006 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007007 mSurface.setFlags(Surface.SURFACE_DITHER,
7008 Surface.SURFACE_DITHER);
7009 }
7010 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007011 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7013 }
7014 mLastHidden = true;
7015 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007016 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007017 Surface.closeTransaction();
7018 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007019 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007020 TAG, "Created surface " + this);
7021 }
7022 return mSurface;
7023 }
Romain Guy06882f82009-06-10 13:36:04 -07007024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007025 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007026 if (mAppToken != null && this == mAppToken.startingWindow) {
7027 mAppToken.startingDisplayed = false;
7028 }
Romain Guy06882f82009-06-10 13:36:04 -07007029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007031 mDrawPending = false;
7032 mCommitDrawPending = false;
7033 mReadyToShow = false;
7034
7035 int i = mChildWindows.size();
7036 while (i > 0) {
7037 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007038 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007039 c.mAttachedHidden = true;
7040 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007041
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007042 if (mReportDestroySurface) {
7043 mReportDestroySurface = false;
7044 mSurfacePendingDestroy = true;
7045 try {
7046 mClient.dispatchGetNewSurface();
7047 // We'll really destroy on the next time around.
7048 return;
7049 } catch (RemoteException e) {
7050 }
7051 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007053 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007054 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007055 RuntimeException e = null;
7056 if (!HIDE_STACK_CRAWLS) {
7057 e = new RuntimeException();
7058 e.fillInStackTrace();
7059 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007060 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007061 + mSurface + ", session " + mSession, e);
7062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007064 RuntimeException e = null;
7065 if (!HIDE_STACK_CRAWLS) {
7066 e = new RuntimeException();
7067 e.fillInStackTrace();
7068 }
7069 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007071 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007073 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074 + " surface " + mSurface + " session " + mSession
7075 + ": " + e.toString());
7076 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007077
Dianne Hackborn16064f92010-03-25 00:47:24 -07007078 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007080 }
7081 }
7082
7083 boolean finishDrawingLocked() {
7084 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007085 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 TAG, "finishDrawingLocked: " + mSurface);
7087 mCommitDrawPending = true;
7088 mDrawPending = false;
7089 return true;
7090 }
7091 return false;
7092 }
7093
7094 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007095 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007096 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007098 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 }
7100 mCommitDrawPending = false;
7101 mReadyToShow = true;
7102 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7103 final AppWindowToken atoken = mAppToken;
7104 if (atoken == null || atoken.allDrawn || starting) {
7105 performShowLocked();
7106 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007107 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 }
7109
7110 // This must be called while inside a transaction.
7111 boolean performShowLocked() {
7112 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007113 RuntimeException e = null;
7114 if (!HIDE_STACK_CRAWLS) {
7115 e = new RuntimeException();
7116 e.fillInStackTrace();
7117 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007118 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007119 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7120 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7121 }
7122 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007123 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7124 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007125 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 + " during animation: policyVis=" + mPolicyVisibility
7127 + " attHidden=" + mAttachedHidden
7128 + " tok.hiddenRequested="
7129 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007130 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007131 + (mAppToken != null ? mAppToken.hidden : false)
7132 + " animating=" + mAnimating
7133 + " tok animating="
7134 + (mAppToken != null ? mAppToken.animating : false));
7135 if (!showSurfaceRobustlyLocked(this)) {
7136 return false;
7137 }
7138 mLastAlpha = -1;
7139 mHasDrawn = true;
7140 mLastHidden = false;
7141 mReadyToShow = false;
7142 enableScreenIfNeededLocked();
7143
7144 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007146 int i = mChildWindows.size();
7147 while (i > 0) {
7148 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007149 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007150 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007151 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007152 if (c.mSurface != null) {
7153 c.performShowLocked();
7154 // It hadn't been shown, which means layout not
7155 // performed on it, so now we want to make sure to
7156 // do a layout. If called from within the transaction
7157 // loop, this will cause it to restart with a new
7158 // layout.
7159 mLayoutNeeded = true;
7160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007161 }
7162 }
Romain Guy06882f82009-06-10 13:36:04 -07007163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007164 if (mAttrs.type != TYPE_APPLICATION_STARTING
7165 && mAppToken != null) {
7166 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007167
Dianne Hackborn248b1882009-09-16 16:46:44 -07007168 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007169 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007170 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007171 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007172 // If this initial window is animating, stop it -- we
7173 // will do an animation to reveal it from behind the
7174 // starting window, so there is no need for it to also
7175 // be doing its own stuff.
7176 if (mAnimation != null) {
7177 mAnimation = null;
7178 // Make sure we clean up the animation.
7179 mAnimating = true;
7180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007181 mFinishedStarting.add(mAppToken);
7182 mH.sendEmptyMessage(H.FINISHED_STARTING);
7183 }
7184 mAppToken.updateReportedVisibilityLocked();
7185 }
7186 }
7187 return true;
7188 }
Romain Guy06882f82009-06-10 13:36:04 -07007189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007190 // This must be called while inside a transaction. Returns true if
7191 // there is more animation to run.
7192 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007193 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7197 mHasTransformation = true;
7198 mHasLocalTransformation = true;
7199 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007200 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007201 TAG, "Starting animation in " + this +
7202 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7203 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7204 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7205 mAnimation.setStartTime(currentTime);
7206 mLocalAnimating = true;
7207 mAnimating = true;
7208 }
7209 mTransformation.clear();
7210 final boolean more = mAnimation.getTransformation(
7211 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007212 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007213 TAG, "Stepped animation in " + this +
7214 ": more=" + more + ", xform=" + mTransformation);
7215 if (more) {
7216 // we're not done!
7217 return true;
7218 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007219 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007220 TAG, "Finished animation in " + this +
7221 " @ " + currentTime);
7222 mAnimation = null;
7223 //WindowManagerService.this.dump();
7224 }
7225 mHasLocalTransformation = false;
7226 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007227 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228 // When our app token is animating, we kind-of pretend like
7229 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7230 // part of this check means that we will only do this if
7231 // our window is not currently exiting, or it is not
7232 // locally animating itself. The idea being that one that
7233 // is exiting and doing a local animation should be removed
7234 // once that animation is done.
7235 mAnimating = true;
7236 mHasTransformation = true;
7237 mTransformation.clear();
7238 return false;
7239 } else if (mHasTransformation) {
7240 // Little trick to get through the path below to act like
7241 // we have finished an animation.
7242 mAnimating = true;
7243 } else if (isAnimating()) {
7244 mAnimating = true;
7245 }
7246 } else if (mAnimation != null) {
7247 // If the display is frozen, and there is a pending animation,
7248 // clear it and make sure we run the cleanup code.
7249 mAnimating = true;
7250 mLocalAnimating = true;
7251 mAnimation = null;
7252 }
Romain Guy06882f82009-06-10 13:36:04 -07007253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007254 if (!mAnimating && !mLocalAnimating) {
7255 return false;
7256 }
7257
Joe Onorato8a9b2202010-02-26 18:56:32 -08007258 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259 TAG, "Animation done in " + this + ": exiting=" + mExiting
7260 + ", reportedVisible="
7261 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007263 mAnimating = false;
7264 mLocalAnimating = false;
7265 mAnimation = null;
7266 mAnimLayer = mLayer;
7267 if (mIsImWindow) {
7268 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007269 } else if (mIsWallpaper) {
7270 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007272 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007273 + " anim layer: " + mAnimLayer);
7274 mHasTransformation = false;
7275 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007276 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7277 if (DEBUG_VISIBILITY) {
7278 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7279 + mPolicyVisibilityAfterAnim);
7280 }
7281 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7282 if (!mPolicyVisibility) {
7283 if (mCurrentFocus == this) {
7284 mFocusMayChange = true;
7285 }
7286 // Window is no longer visible -- make sure if we were waiting
7287 // for it to be displayed before enabling the display, that
7288 // we allow the display to be enabled now.
7289 enableScreenIfNeededLocked();
7290 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007291 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007292 mTransformation.clear();
7293 if (mHasDrawn
7294 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7295 && mAppToken != null
7296 && mAppToken.firstWindowDrawn
7297 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007298 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 + mToken + ": first real window done animating");
7300 mFinishedStarting.add(mAppToken);
7301 mH.sendEmptyMessage(H.FINISHED_STARTING);
7302 }
Romain Guy06882f82009-06-10 13:36:04 -07007303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 finishExit();
7305
7306 if (mAppToken != null) {
7307 mAppToken.updateReportedVisibilityLocked();
7308 }
7309
7310 return false;
7311 }
7312
7313 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007314 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007315 TAG, "finishExit in " + this
7316 + ": exiting=" + mExiting
7317 + " remove=" + mRemoveOnExit
7318 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007320 final int N = mChildWindows.size();
7321 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007322 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007323 }
Romain Guy06882f82009-06-10 13:36:04 -07007324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 if (!mExiting) {
7326 return;
7327 }
Romain Guy06882f82009-06-10 13:36:04 -07007328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 if (isWindowAnimating()) {
7330 return;
7331 }
7332
Joe Onorato8a9b2202010-02-26 18:56:32 -08007333 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 TAG, "Exit animation finished in " + this
7335 + ": remove=" + mRemoveOnExit);
7336 if (mSurface != null) {
7337 mDestroySurface.add(this);
7338 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007339 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007340 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007341 try {
7342 mSurface.hide();
7343 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007344 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007345 }
7346 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 }
7348 mExiting = false;
7349 if (mRemoveOnExit) {
7350 mPendingRemove.add(this);
7351 mRemoveOnExit = false;
7352 }
7353 }
Romain Guy06882f82009-06-10 13:36:04 -07007354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007355 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7356 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7357 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7358 if (dtdx < -.000001f || dtdx > .000001f) return false;
7359 if (dsdy < -.000001f || dsdy > .000001f) return false;
7360 return true;
7361 }
Romain Guy06882f82009-06-10 13:36:04 -07007362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007363 void computeShownFrameLocked() {
7364 final boolean selfTransformation = mHasLocalTransformation;
7365 Transformation attachedTransformation =
7366 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7367 ? mAttachedWindow.mTransformation : null;
7368 Transformation appTransformation =
7369 (mAppToken != null && mAppToken.hasTransformation)
7370 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007371
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007372 // Wallpapers are animated based on the "real" window they
7373 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007374 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007375 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007376 if (mWallpaperTarget.mHasLocalTransformation &&
7377 mWallpaperTarget.mAnimation != null &&
7378 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007379 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007380 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007381 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007382 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007383 }
7384 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007385 mWallpaperTarget.mAppToken.hasTransformation &&
7386 mWallpaperTarget.mAppToken.animation != null &&
7387 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007388 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007389 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007390 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007391 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007392 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007393 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007395 if (selfTransformation || attachedTransformation != null
7396 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007397 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007398 final Rect frame = mFrame;
7399 final float tmpFloats[] = mTmpFloats;
7400 final Matrix tmpMatrix = mTmpMatrix;
7401
7402 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007403 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007405 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007407 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007409 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 }
7411 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007412 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 }
7414
7415 // "convert" it into SurfaceFlinger's format
7416 // (a 2x2 matrix + an offset)
7417 // Here we must not transform the position of the surface
7418 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007419 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 tmpMatrix.getValues(tmpFloats);
7422 mDsDx = tmpFloats[Matrix.MSCALE_X];
7423 mDtDx = tmpFloats[Matrix.MSKEW_X];
7424 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7425 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007426 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7427 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 int w = frame.width();
7429 int h = frame.height();
7430 mShownFrame.set(x, y, x+w, y+h);
7431
7432 // Now set the alpha... but because our current hardware
7433 // can't do alpha transformation on a non-opaque surface,
7434 // turn it off if we are running an animation that is also
7435 // transforming since it is more important to have that
7436 // animation be smooth.
7437 mShownAlpha = mAlpha;
7438 if (!mLimitedAlphaCompositing
7439 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7440 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7441 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007442 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 if (selfTransformation) {
7444 mShownAlpha *= mTransformation.getAlpha();
7445 }
7446 if (attachedTransformation != null) {
7447 mShownAlpha *= attachedTransformation.getAlpha();
7448 }
7449 if (appTransformation != null) {
7450 mShownAlpha *= appTransformation.getAlpha();
7451 }
7452 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007453 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 }
Romain Guy06882f82009-06-10 13:36:04 -07007455
Joe Onorato8a9b2202010-02-26 18:56:32 -08007456 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007457 TAG, "Continuing animation in " + this +
7458 ": " + mShownFrame +
7459 ", alpha=" + mTransformation.getAlpha());
7460 return;
7461 }
Romain Guy06882f82009-06-10 13:36:04 -07007462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007464 if (mXOffset != 0 || mYOffset != 0) {
7465 mShownFrame.offset(mXOffset, mYOffset);
7466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 mShownAlpha = mAlpha;
7468 mDsDx = 1;
7469 mDtDx = 0;
7470 mDsDy = 0;
7471 mDtDy = 1;
7472 }
Romain Guy06882f82009-06-10 13:36:04 -07007473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 /**
7475 * Is this window visible? It is not visible if there is no
7476 * surface, or we are in the process of running an exit animation
7477 * that will remove the surface, or its app token has been hidden.
7478 */
7479 public boolean isVisibleLw() {
7480 final AppWindowToken atoken = mAppToken;
7481 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7482 && (atoken == null || !atoken.hiddenRequested)
7483 && !mExiting && !mDestroying;
7484 }
7485
7486 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007487 * Like {@link #isVisibleLw}, but also counts a window that is currently
7488 * "hidden" behind the keyguard as visible. This allows us to apply
7489 * things like window flags that impact the keyguard.
7490 * XXX I am starting to think we need to have ANOTHER visibility flag
7491 * for this "hidden behind keyguard" state rather than overloading
7492 * mPolicyVisibility. Ungh.
7493 */
7494 public boolean isVisibleOrBehindKeyguardLw() {
7495 final AppWindowToken atoken = mAppToken;
7496 return mSurface != null && !mAttachedHidden
7497 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007498 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007499 && !mExiting && !mDestroying;
7500 }
7501
7502 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 * Is this window visible, ignoring its app token? It is not visible
7504 * if there is no surface, or we are in the process of running an exit animation
7505 * that will remove the surface.
7506 */
7507 public boolean isWinVisibleLw() {
7508 final AppWindowToken atoken = mAppToken;
7509 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7510 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7511 && !mExiting && !mDestroying;
7512 }
7513
7514 /**
7515 * The same as isVisible(), but follows the current hidden state of
7516 * the associated app token, not the pending requested hidden state.
7517 */
7518 boolean isVisibleNow() {
7519 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007520 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007521 }
7522
7523 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007524 * Can this window possibly be a drag/drop target? The test here is
7525 * a combination of the above "visible now" with the check that the
7526 * Input Manager uses when discarding windows from input consideration.
7527 */
7528 boolean isPotentialDragTarget() {
7529 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7530 }
7531
7532 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007533 * Same as isVisible(), but we also count it as visible between the
7534 * call to IWindowSession.add() and the first relayout().
7535 */
7536 boolean isVisibleOrAdding() {
7537 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007538 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007539 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7540 && mPolicyVisibility && !mAttachedHidden
7541 && (atoken == null || !atoken.hiddenRequested)
7542 && !mExiting && !mDestroying;
7543 }
7544
7545 /**
7546 * Is this window currently on-screen? It is on-screen either if it
7547 * is visible or it is currently running an animation before no longer
7548 * being visible.
7549 */
7550 boolean isOnScreen() {
7551 final AppWindowToken atoken = mAppToken;
7552 if (atoken != null) {
7553 return mSurface != null && mPolicyVisibility && !mDestroying
7554 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007555 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007556 } else {
7557 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007558 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007559 }
7560 }
Romain Guy06882f82009-06-10 13:36:04 -07007561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 /**
7563 * Like isOnScreen(), but we don't return true if the window is part
7564 * of a transition that has not yet been started.
7565 */
7566 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007567 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007568 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007569 return false;
7570 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007571 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007572 final boolean animating = atoken != null
7573 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007574 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007575 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7576 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007577 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007578 }
7579
7580 /** Is the window or its container currently animating? */
7581 boolean isAnimating() {
7582 final WindowState attached = mAttachedWindow;
7583 final AppWindowToken atoken = mAppToken;
7584 return mAnimation != null
7585 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007586 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 (atoken.animation != null
7588 || atoken.inPendingTransaction));
7589 }
7590
7591 /** Is this window currently animating? */
7592 boolean isWindowAnimating() {
7593 return mAnimation != null;
7594 }
7595
7596 /**
7597 * Like isOnScreen, but returns false if the surface hasn't yet
7598 * been drawn.
7599 */
7600 public boolean isDisplayedLw() {
7601 final AppWindowToken atoken = mAppToken;
7602 return mSurface != null && mPolicyVisibility && !mDestroying
7603 && !mDrawPending && !mCommitDrawPending
7604 && ((!mAttachedHidden &&
7605 (atoken == null || !atoken.hiddenRequested))
7606 || mAnimating);
7607 }
7608
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007609 /**
7610 * Returns true if the window has a surface that it has drawn a
7611 * complete UI in to.
7612 */
7613 public boolean isDrawnLw() {
7614 final AppWindowToken atoken = mAppToken;
7615 return mSurface != null && !mDestroying
7616 && !mDrawPending && !mCommitDrawPending;
7617 }
7618
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007619 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007620 * Return true if the window is opaque and fully drawn. This indicates
7621 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007622 */
7623 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007624 return (mAttrs.format == PixelFormat.OPAQUE
7625 || mAttrs.type == TYPE_WALLPAPER)
7626 && mSurface != null && mAnimation == null
7627 && (mAppToken == null || mAppToken.animation == null)
7628 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007629 }
7630
7631 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7632 return
7633 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007634 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7635 // only if it's visible
7636 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007637 // and only if the application fills the compatible screen
7638 mFrame.left <= mCompatibleScreenFrame.left &&
7639 mFrame.top <= mCompatibleScreenFrame.top &&
7640 mFrame.right >= mCompatibleScreenFrame.right &&
7641 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007642 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007643 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007644 }
7645
7646 boolean isFullscreen(int screenWidth, int screenHeight) {
7647 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007648 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007649 }
7650
7651 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007652 disposeInputChannel();
7653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007654 if (mAttachedWindow != null) {
7655 mAttachedWindow.mChildWindows.remove(this);
7656 }
7657 destroySurfaceLocked();
7658 mSession.windowRemovedLocked();
7659 try {
7660 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7661 } catch (RuntimeException e) {
7662 // Ignore if it has already been removed (usually because
7663 // we are doing this as part of processing a death note.)
7664 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007665 }
7666
7667 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007668 if (mInputChannel != null) {
7669 mInputManager.unregisterInputChannel(mInputChannel);
7670
7671 mInputChannel.dispose();
7672 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007673 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007674 }
7675
7676 private class DeathRecipient implements IBinder.DeathRecipient {
7677 public void binderDied() {
7678 try {
7679 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007680 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007681 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007682 if (win != null) {
7683 removeWindowLocked(mSession, win);
7684 }
7685 }
7686 } catch (IllegalArgumentException ex) {
7687 // This will happen if the window has already been
7688 // removed.
7689 }
7690 }
7691 }
7692
7693 /** Returns true if this window desires key events. */
7694 public final boolean canReceiveKeys() {
7695 return isVisibleOrAdding()
7696 && (mViewVisibility == View.VISIBLE)
7697 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7698 }
7699
7700 public boolean hasDrawnLw() {
7701 return mHasDrawn;
7702 }
7703
7704 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007705 return showLw(doAnimation, true);
7706 }
7707
7708 boolean showLw(boolean doAnimation, boolean requestAnim) {
7709 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7710 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007711 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007712 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007713 if (doAnimation) {
7714 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7715 + mPolicyVisibility + " mAnimation=" + mAnimation);
7716 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7717 doAnimation = false;
7718 } else if (mPolicyVisibility && mAnimation == null) {
7719 // Check for the case where we are currently visible and
7720 // not animating; we do not want to do animation at such a
7721 // point to become visible when we already are.
7722 doAnimation = false;
7723 }
7724 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007725 mPolicyVisibility = true;
7726 mPolicyVisibilityAfterAnim = true;
7727 if (doAnimation) {
7728 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7729 }
7730 if (requestAnim) {
7731 requestAnimationLocked(0);
7732 }
7733 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007734 }
7735
7736 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007737 return hideLw(doAnimation, true);
7738 }
7739
7740 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007741 if (doAnimation) {
7742 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7743 doAnimation = false;
7744 }
7745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007746 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7747 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007748 if (!current) {
7749 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007751 if (doAnimation) {
7752 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7753 if (mAnimation == null) {
7754 doAnimation = false;
7755 }
7756 }
7757 if (doAnimation) {
7758 mPolicyVisibilityAfterAnim = false;
7759 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007760 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007761 mPolicyVisibilityAfterAnim = false;
7762 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007763 // Window is no longer visible -- make sure if we were waiting
7764 // for it to be displayed before enabling the display, that
7765 // we allow the display to be enabled now.
7766 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007767 if (mCurrentFocus == this) {
7768 mFocusMayChange = true;
7769 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007770 }
7771 if (requestAnim) {
7772 requestAnimationLocked(0);
7773 }
7774 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 }
7776
7777 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007778 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7779 pw.print(" mClient="); pw.println(mClient.asBinder());
7780 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7781 if (mAttachedWindow != null || mLayoutAttached) {
7782 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7783 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7784 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007785 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7786 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7787 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007788 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7789 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007790 }
7791 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7792 pw.print(" mSubLayer="); pw.print(mSubLayer);
7793 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7794 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7795 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7796 pw.print("="); pw.print(mAnimLayer);
7797 pw.print(" mLastLayer="); pw.println(mLastLayer);
7798 if (mSurface != null) {
7799 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007800 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7801 pw.print(" layer="); pw.print(mSurfaceLayer);
7802 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7803 pw.print(" rect=("); pw.print(mSurfaceX);
7804 pw.print(","); pw.print(mSurfaceY);
7805 pw.print(") "); pw.print(mSurfaceW);
7806 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007807 }
7808 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7809 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7810 if (mAppToken != null) {
7811 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7812 }
7813 if (mTargetAppToken != null) {
7814 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7815 }
7816 pw.print(prefix); pw.print("mViewVisibility=0x");
7817 pw.print(Integer.toHexString(mViewVisibility));
7818 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007819 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7820 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007821 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7822 pw.print(prefix); pw.print("mPolicyVisibility=");
7823 pw.print(mPolicyVisibility);
7824 pw.print(" mPolicyVisibilityAfterAnim=");
7825 pw.print(mPolicyVisibilityAfterAnim);
7826 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7827 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007828 if (!mRelayoutCalled) {
7829 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7830 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007831 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007832 pw.print(" h="); pw.print(mRequestedHeight);
7833 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007834 if (mXOffset != 0 || mYOffset != 0) {
7835 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7836 pw.print(" y="); pw.println(mYOffset);
7837 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007838 pw.print(prefix); pw.print("mGivenContentInsets=");
7839 mGivenContentInsets.printShortString(pw);
7840 pw.print(" mGivenVisibleInsets=");
7841 mGivenVisibleInsets.printShortString(pw);
7842 pw.println();
7843 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7844 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7845 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7846 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007847 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007848 pw.print(prefix); pw.print("mShownFrame=");
7849 mShownFrame.printShortString(pw);
7850 pw.print(" last="); mLastShownFrame.printShortString(pw);
7851 pw.println();
7852 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7853 pw.print(" last="); mLastFrame.printShortString(pw);
7854 pw.println();
7855 pw.print(prefix); pw.print("mContainingFrame=");
7856 mContainingFrame.printShortString(pw);
7857 pw.print(" mDisplayFrame=");
7858 mDisplayFrame.printShortString(pw);
7859 pw.println();
7860 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7861 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7862 pw.println();
7863 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7864 pw.print(" last="); mLastContentInsets.printShortString(pw);
7865 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7866 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7867 pw.println();
7868 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7869 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7870 pw.print(" mAlpha="); pw.print(mAlpha);
7871 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7872 }
7873 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7874 || mAnimation != null) {
7875 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7876 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7877 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7878 pw.print(" mAnimation="); pw.println(mAnimation);
7879 }
7880 if (mHasTransformation || mHasLocalTransformation) {
7881 pw.print(prefix); pw.print("XForm: has=");
7882 pw.print(mHasTransformation);
7883 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7884 pw.print(" "); mTransformation.printShortString(pw);
7885 pw.println();
7886 }
7887 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7888 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7889 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7890 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7891 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7892 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7893 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7894 pw.print(" mDestroying="); pw.print(mDestroying);
7895 pw.print(" mRemoved="); pw.println(mRemoved);
7896 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007897 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007898 pw.print(prefix); pw.print("mOrientationChanging=");
7899 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007900 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7901 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007902 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007903 if (mHScale != 1 || mVScale != 1) {
7904 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7905 pw.print(" mVScale="); pw.println(mVScale);
7906 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007907 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007908 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7909 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7910 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007911 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7912 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7913 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7914 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007915 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007916
7917 String makeInputChannelName() {
7918 return Integer.toHexString(System.identityHashCode(this))
7919 + " " + mAttrs.getTitle();
7920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007921
7922 @Override
7923 public String toString() {
7924 return "Window{"
7925 + Integer.toHexString(System.identityHashCode(this))
7926 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7927 }
7928 }
Romain Guy06882f82009-06-10 13:36:04 -07007929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007930 // -------------------------------------------------------------
7931 // Window Token State
7932 // -------------------------------------------------------------
7933
7934 class WindowToken {
7935 // The actual token.
7936 final IBinder token;
7937
7938 // The type of window this token is for, as per WindowManager.LayoutParams.
7939 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007941 // Set if this token was explicitly added by a client, so should
7942 // not be removed when all windows are removed.
7943 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007944
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007945 // For printing.
7946 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007948 // If this is an AppWindowToken, this is non-null.
7949 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007951 // All of the windows associated with this token.
7952 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7953
7954 // Is key dispatching paused for this token?
7955 boolean paused = false;
7956
7957 // Should this token's windows be hidden?
7958 boolean hidden;
7959
7960 // Temporary for finding which tokens no longer have visible windows.
7961 boolean hasVisible;
7962
Dianne Hackborna8f60182009-09-01 19:01:50 -07007963 // Set to true when this token is in a pending transaction where it
7964 // will be shown.
7965 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007966
Dianne Hackborna8f60182009-09-01 19:01:50 -07007967 // Set to true when this token is in a pending transaction where it
7968 // will be hidden.
7969 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007970
Dianne Hackborna8f60182009-09-01 19:01:50 -07007971 // Set to true when this token is in a pending transaction where its
7972 // windows will be put to the bottom of the list.
7973 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007974
Dianne Hackborna8f60182009-09-01 19:01:50 -07007975 // Set to true when this token is in a pending transaction where its
7976 // windows will be put to the top of the list.
7977 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 WindowToken(IBinder _token, int type, boolean _explicit) {
7980 token = _token;
7981 windowType = type;
7982 explicit = _explicit;
7983 }
7984
7985 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007986 pw.print(prefix); pw.print("token="); pw.println(token);
7987 pw.print(prefix); pw.print("windows="); pw.println(windows);
7988 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7989 pw.print(" hidden="); pw.print(hidden);
7990 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007991 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7992 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7993 pw.print(" waitingToHide="); pw.print(waitingToHide);
7994 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7995 pw.print(" sendingToTop="); pw.println(sendingToTop);
7996 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007997 }
7998
7999 @Override
8000 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008001 if (stringName == null) {
8002 StringBuilder sb = new StringBuilder();
8003 sb.append("WindowToken{");
8004 sb.append(Integer.toHexString(System.identityHashCode(this)));
8005 sb.append(" token="); sb.append(token); sb.append('}');
8006 stringName = sb.toString();
8007 }
8008 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008009 }
8010 };
8011
8012 class AppWindowToken extends WindowToken {
8013 // Non-null only for application tokens.
8014 final IApplicationToken appToken;
8015
8016 // All of the windows and child windows that are included in this
8017 // application token. Note this list is NOT sorted!
8018 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8019
8020 int groupId = -1;
8021 boolean appFullscreen;
8022 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008023
8024 // The input dispatching timeout for this application token in nanoseconds.
8025 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008027 // These are used for determining when all windows associated with
8028 // an activity have been drawn, so they can be made visible together
8029 // at the same time.
8030 int lastTransactionSequence = mTransactionSequence-1;
8031 int numInterestingWindows;
8032 int numDrawnWindows;
8033 boolean inPendingTransaction;
8034 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008036 // Is this token going to be hidden in a little while? If so, it
8037 // won't be taken into account for setting the screen orientation.
8038 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008040 // Is this window's surface needed? This is almost like hidden, except
8041 // it will sometimes be true a little earlier: when the token has
8042 // been shown, but is still waiting for its app transition to execute
8043 // before making its windows shown.
8044 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 // Have we told the window clients to hide themselves?
8047 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008049 // Last visibility state we reported to the app token.
8050 boolean reportedVisible;
8051
8052 // Set to true when the token has been removed from the window mgr.
8053 boolean removed;
8054
8055 // Have we been asked to have this token keep the screen frozen?
8056 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008058 boolean animating;
8059 Animation animation;
8060 boolean hasTransformation;
8061 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008063 // Offset to the window of all layers in the token, for use by
8064 // AppWindowToken animations.
8065 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008067 // Information about an application starting window if displayed.
8068 StartingData startingData;
8069 WindowState startingWindow;
8070 View startingView;
8071 boolean startingDisplayed;
8072 boolean startingMoved;
8073 boolean firstWindowDrawn;
8074
8075 AppWindowToken(IApplicationToken _token) {
8076 super(_token.asBinder(),
8077 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8078 appWindowToken = this;
8079 appToken = _token;
8080 }
Romain Guy06882f82009-06-10 13:36:04 -07008081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008082 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008083 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008084 TAG, "Setting animation in " + this + ": " + anim);
8085 animation = anim;
8086 animating = false;
8087 anim.restrictDuration(MAX_ANIMATION_DURATION);
8088 anim.scaleCurrentDuration(mTransitionAnimationScale);
8089 int zorder = anim.getZAdjustment();
8090 int adj = 0;
8091 if (zorder == Animation.ZORDER_TOP) {
8092 adj = TYPE_LAYER_OFFSET;
8093 } else if (zorder == Animation.ZORDER_BOTTOM) {
8094 adj = -TYPE_LAYER_OFFSET;
8095 }
Romain Guy06882f82009-06-10 13:36:04 -07008096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008097 if (animLayerAdjustment != adj) {
8098 animLayerAdjustment = adj;
8099 updateLayers();
8100 }
8101 }
Romain Guy06882f82009-06-10 13:36:04 -07008102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 public void setDummyAnimation() {
8104 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008105 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008106 TAG, "Setting dummy animation in " + this);
8107 animation = sDummyAnimation;
8108 }
8109 }
8110
8111 public void clearAnimation() {
8112 if (animation != null) {
8113 animation = null;
8114 animating = true;
8115 }
8116 }
Romain Guy06882f82009-06-10 13:36:04 -07008117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008118 void updateLayers() {
8119 final int N = allAppWindows.size();
8120 final int adj = animLayerAdjustment;
8121 for (int i=0; i<N; i++) {
8122 WindowState w = allAppWindows.get(i);
8123 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008124 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 + w.mAnimLayer);
8126 if (w == mInputMethodTarget) {
8127 setInputMethodAnimLayerAdjustment(adj);
8128 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008129 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008130 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008132 }
8133 }
Romain Guy06882f82009-06-10 13:36:04 -07008134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008135 void sendAppVisibilityToClients() {
8136 final int N = allAppWindows.size();
8137 for (int i=0; i<N; i++) {
8138 WindowState win = allAppWindows.get(i);
8139 if (win == startingWindow && clientHidden) {
8140 // Don't hide the starting window.
8141 continue;
8142 }
8143 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008144 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 "Setting visibility of " + win + ": " + (!clientHidden));
8146 win.mClient.dispatchAppVisibility(!clientHidden);
8147 } catch (RemoteException e) {
8148 }
8149 }
8150 }
Romain Guy06882f82009-06-10 13:36:04 -07008151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008152 void showAllWindowsLocked() {
8153 final int NW = allAppWindows.size();
8154 for (int i=0; i<NW; i++) {
8155 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008156 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008157 "performing show on: " + w);
8158 w.performShowLocked();
8159 }
8160 }
Romain Guy06882f82009-06-10 13:36:04 -07008161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 // This must be called while inside a transaction.
8163 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008164 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008165 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008167 if (animation == sDummyAnimation) {
8168 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008169 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008170 // when it is really time to animate, this will be set to
8171 // a real animation and the next call will execute normally.
8172 return false;
8173 }
Romain Guy06882f82009-06-10 13:36:04 -07008174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008175 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8176 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008177 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008178 TAG, "Starting animation in " + this +
8179 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8180 + " scale=" + mTransitionAnimationScale
8181 + " allDrawn=" + allDrawn + " animating=" + animating);
8182 animation.initialize(dw, dh, dw, dh);
8183 animation.setStartTime(currentTime);
8184 animating = true;
8185 }
8186 transformation.clear();
8187 final boolean more = animation.getTransformation(
8188 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008189 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008190 TAG, "Stepped animation in " + this +
8191 ": more=" + more + ", xform=" + transformation);
8192 if (more) {
8193 // we're done!
8194 hasTransformation = true;
8195 return true;
8196 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008197 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008198 TAG, "Finished animation in " + this +
8199 " @ " + currentTime);
8200 animation = null;
8201 }
8202 } else if (animation != null) {
8203 // If the display is frozen, and there is a pending animation,
8204 // clear it and make sure we run the cleanup code.
8205 animating = true;
8206 animation = null;
8207 }
8208
8209 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008211 if (!animating) {
8212 return false;
8213 }
8214
8215 clearAnimation();
8216 animating = false;
8217 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8218 moveInputMethodWindowsIfNeededLocked(true);
8219 }
Romain Guy06882f82009-06-10 13:36:04 -07008220
Joe Onorato8a9b2202010-02-26 18:56:32 -08008221 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008222 TAG, "Animation done in " + this
8223 + ": reportedVisible=" + reportedVisible);
8224
8225 transformation.clear();
8226 if (animLayerAdjustment != 0) {
8227 animLayerAdjustment = 0;
8228 updateLayers();
8229 }
Romain Guy06882f82009-06-10 13:36:04 -07008230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008231 final int N = windows.size();
8232 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008233 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008234 }
8235 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008237 return false;
8238 }
8239
8240 void updateReportedVisibilityLocked() {
8241 if (appToken == null) {
8242 return;
8243 }
Romain Guy06882f82009-06-10 13:36:04 -07008244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008245 int numInteresting = 0;
8246 int numVisible = 0;
8247 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008248
Joe Onorato8a9b2202010-02-26 18:56:32 -08008249 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250 final int N = allAppWindows.size();
8251 for (int i=0; i<N; i++) {
8252 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008253 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008254 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008255 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8256 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008257 continue;
8258 }
8259 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008260 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008261 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008262 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008263 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008264 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008265 + " pv=" + win.mPolicyVisibility
8266 + " dp=" + win.mDrawPending
8267 + " cdp=" + win.mCommitDrawPending
8268 + " ah=" + win.mAttachedHidden
8269 + " th="
8270 + (win.mAppToken != null
8271 ? win.mAppToken.hiddenRequested : false)
8272 + " a=" + win.mAnimating);
8273 }
8274 }
8275 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008276 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008277 if (!win.isAnimating()) {
8278 numVisible++;
8279 }
8280 nowGone = false;
8281 } else if (win.isAnimating()) {
8282 nowGone = false;
8283 }
8284 }
Romain Guy06882f82009-06-10 13:36:04 -07008285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008286 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008287 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008288 + numInteresting + " visible=" + numVisible);
8289 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008290 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008291 TAG, "Visibility changed in " + this
8292 + ": vis=" + nowVisible);
8293 reportedVisible = nowVisible;
8294 Message m = mH.obtainMessage(
8295 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8296 nowVisible ? 1 : 0,
8297 nowGone ? 1 : 0,
8298 this);
8299 mH.sendMessage(m);
8300 }
8301 }
Romain Guy06882f82009-06-10 13:36:04 -07008302
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008303 WindowState findMainWindow() {
8304 int j = windows.size();
8305 while (j > 0) {
8306 j--;
8307 WindowState win = windows.get(j);
8308 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8309 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8310 return win;
8311 }
8312 }
8313 return null;
8314 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316 void dump(PrintWriter pw, String prefix) {
8317 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008318 if (appToken != null) {
8319 pw.print(prefix); pw.println("app=true");
8320 }
8321 if (allAppWindows.size() > 0) {
8322 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8323 }
8324 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008325 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008326 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8327 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8328 pw.print(" clientHidden="); pw.print(clientHidden);
8329 pw.print(" willBeHidden="); pw.print(willBeHidden);
8330 pw.print(" reportedVisible="); pw.println(reportedVisible);
8331 if (paused || freezingScreen) {
8332 pw.print(prefix); pw.print("paused="); pw.print(paused);
8333 pw.print(" freezingScreen="); pw.println(freezingScreen);
8334 }
8335 if (numInterestingWindows != 0 || numDrawnWindows != 0
8336 || inPendingTransaction || allDrawn) {
8337 pw.print(prefix); pw.print("numInterestingWindows=");
8338 pw.print(numInterestingWindows);
8339 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8340 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8341 pw.print(" allDrawn="); pw.println(allDrawn);
8342 }
8343 if (animating || animation != null) {
8344 pw.print(prefix); pw.print("animating="); pw.print(animating);
8345 pw.print(" animation="); pw.println(animation);
8346 }
8347 if (animLayerAdjustment != 0) {
8348 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8349 }
8350 if (hasTransformation) {
8351 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8352 pw.print(" transformation="); transformation.printShortString(pw);
8353 pw.println();
8354 }
8355 if (startingData != null || removed || firstWindowDrawn) {
8356 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8357 pw.print(" removed="); pw.print(removed);
8358 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8359 }
8360 if (startingWindow != null || startingView != null
8361 || startingDisplayed || startingMoved) {
8362 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8363 pw.print(" startingView="); pw.print(startingView);
8364 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8365 pw.print(" startingMoved"); pw.println(startingMoved);
8366 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008367 }
8368
8369 @Override
8370 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008371 if (stringName == null) {
8372 StringBuilder sb = new StringBuilder();
8373 sb.append("AppWindowToken{");
8374 sb.append(Integer.toHexString(System.identityHashCode(this)));
8375 sb.append(" token="); sb.append(token); sb.append('}');
8376 stringName = sb.toString();
8377 }
8378 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 }
8380 }
Romain Guy06882f82009-06-10 13:36:04 -07008381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008382 // -------------------------------------------------------------
8383 // DummyAnimation
8384 // -------------------------------------------------------------
8385
8386 // This is an animation that does nothing: it just immediately finishes
8387 // itself every time it is called. It is used as a stub animation in cases
8388 // where we want to synchronize multiple things that may be animating.
8389 static final class DummyAnimation extends Animation {
8390 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8391 return false;
8392 }
8393 }
8394 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008396 // -------------------------------------------------------------
8397 // Async Handler
8398 // -------------------------------------------------------------
8399
8400 static final class StartingData {
8401 final String pkg;
8402 final int theme;
8403 final CharSequence nonLocalizedLabel;
8404 final int labelRes;
8405 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008407 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8408 int _labelRes, int _icon) {
8409 pkg = _pkg;
8410 theme = _theme;
8411 nonLocalizedLabel = _nonLocalizedLabel;
8412 labelRes = _labelRes;
8413 icon = _icon;
8414 }
8415 }
8416
8417 private final class H extends Handler {
8418 public static final int REPORT_FOCUS_CHANGE = 2;
8419 public static final int REPORT_LOSING_FOCUS = 3;
8420 public static final int ANIMATE = 4;
8421 public static final int ADD_STARTING = 5;
8422 public static final int REMOVE_STARTING = 6;
8423 public static final int FINISHED_STARTING = 7;
8424 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008425 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8426 public static final int HOLD_SCREEN_CHANGED = 12;
8427 public static final int APP_TRANSITION_TIMEOUT = 13;
8428 public static final int PERSIST_ANIMATION_SCALE = 14;
8429 public static final int FORCE_GC = 15;
8430 public static final int ENABLE_SCREEN = 16;
8431 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008432 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008433 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008434 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008435 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008439 public H() {
8440 }
Romain Guy06882f82009-06-10 13:36:04 -07008441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008442 @Override
8443 public void handleMessage(Message msg) {
8444 switch (msg.what) {
8445 case REPORT_FOCUS_CHANGE: {
8446 WindowState lastFocus;
8447 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008449 synchronized(mWindowMap) {
8450 lastFocus = mLastFocus;
8451 newFocus = mCurrentFocus;
8452 if (lastFocus == newFocus) {
8453 // Focus is not changing, so nothing to do.
8454 return;
8455 }
8456 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008457 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 // + " to " + newFocus);
8459 if (newFocus != null && lastFocus != null
8460 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008461 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 mLosingFocus.add(lastFocus);
8463 lastFocus = null;
8464 }
8465 }
8466
8467 if (lastFocus != newFocus) {
8468 //System.out.println("Changing focus from " + lastFocus
8469 // + " to " + newFocus);
8470 if (newFocus != null) {
8471 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008472 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008473 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8474 } catch (RemoteException e) {
8475 // Ignore if process has died.
8476 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008477 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008478 }
8479
8480 if (lastFocus != null) {
8481 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008482 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008483 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8484 } catch (RemoteException e) {
8485 // Ignore if process has died.
8486 }
8487 }
8488 }
8489 } break;
8490
8491 case REPORT_LOSING_FOCUS: {
8492 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 synchronized(mWindowMap) {
8495 losers = mLosingFocus;
8496 mLosingFocus = new ArrayList<WindowState>();
8497 }
8498
8499 final int N = losers.size();
8500 for (int i=0; i<N; i++) {
8501 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008502 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8504 } catch (RemoteException e) {
8505 // Ignore if process has died.
8506 }
8507 }
8508 } break;
8509
8510 case ANIMATE: {
8511 synchronized(mWindowMap) {
8512 mAnimationPending = false;
8513 performLayoutAndPlaceSurfacesLocked();
8514 }
8515 } break;
8516
8517 case ADD_STARTING: {
8518 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8519 final StartingData sd = wtoken.startingData;
8520
8521 if (sd == null) {
8522 // Animation has been canceled... do nothing.
8523 return;
8524 }
Romain Guy06882f82009-06-10 13:36:04 -07008525
Joe Onorato8a9b2202010-02-26 18:56:32 -08008526 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 View view = null;
8530 try {
8531 view = mPolicy.addStartingWindow(
8532 wtoken.token, sd.pkg,
8533 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8534 sd.icon);
8535 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008536 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 }
8538
8539 if (view != null) {
8540 boolean abort = false;
8541
8542 synchronized(mWindowMap) {
8543 if (wtoken.removed || wtoken.startingData == null) {
8544 // If the window was successfully added, then
8545 // we need to remove it.
8546 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008547 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 "Aborted starting " + wtoken
8549 + ": removed=" + wtoken.removed
8550 + " startingData=" + wtoken.startingData);
8551 wtoken.startingWindow = null;
8552 wtoken.startingData = null;
8553 abort = true;
8554 }
8555 } else {
8556 wtoken.startingView = view;
8557 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008558 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 "Added starting " + wtoken
8560 + ": startingWindow="
8561 + wtoken.startingWindow + " startingView="
8562 + wtoken.startingView);
8563 }
8564
8565 if (abort) {
8566 try {
8567 mPolicy.removeStartingWindow(wtoken.token, view);
8568 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008569 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 }
8571 }
8572 }
8573 } break;
8574
8575 case REMOVE_STARTING: {
8576 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8577 IBinder token = null;
8578 View view = null;
8579 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008580 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008581 + wtoken + ": startingWindow="
8582 + wtoken.startingWindow + " startingView="
8583 + wtoken.startingView);
8584 if (wtoken.startingWindow != null) {
8585 view = wtoken.startingView;
8586 token = wtoken.token;
8587 wtoken.startingData = null;
8588 wtoken.startingView = null;
8589 wtoken.startingWindow = null;
8590 }
8591 }
8592 if (view != null) {
8593 try {
8594 mPolicy.removeStartingWindow(token, view);
8595 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008596 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008597 }
8598 }
8599 } break;
8600
8601 case FINISHED_STARTING: {
8602 IBinder token = null;
8603 View view = null;
8604 while (true) {
8605 synchronized (mWindowMap) {
8606 final int N = mFinishedStarting.size();
8607 if (N <= 0) {
8608 break;
8609 }
8610 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8611
Joe Onorato8a9b2202010-02-26 18:56:32 -08008612 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008613 "Finished starting " + wtoken
8614 + ": startingWindow=" + wtoken.startingWindow
8615 + " startingView=" + wtoken.startingView);
8616
8617 if (wtoken.startingWindow == null) {
8618 continue;
8619 }
8620
8621 view = wtoken.startingView;
8622 token = wtoken.token;
8623 wtoken.startingData = null;
8624 wtoken.startingView = null;
8625 wtoken.startingWindow = null;
8626 }
8627
8628 try {
8629 mPolicy.removeStartingWindow(token, view);
8630 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008631 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008632 }
8633 }
8634 } break;
8635
8636 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8637 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8638
8639 boolean nowVisible = msg.arg1 != 0;
8640 boolean nowGone = msg.arg2 != 0;
8641
8642 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008643 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 TAG, "Reporting visible in " + wtoken
8645 + " visible=" + nowVisible
8646 + " gone=" + nowGone);
8647 if (nowVisible) {
8648 wtoken.appToken.windowsVisible();
8649 } else {
8650 wtoken.appToken.windowsGone();
8651 }
8652 } catch (RemoteException ex) {
8653 }
8654 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008656 case WINDOW_FREEZE_TIMEOUT: {
8657 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008658 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 int i = mWindows.size();
8660 while (i > 0) {
8661 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008662 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008663 if (w.mOrientationChanging) {
8664 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008665 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008666 }
8667 }
8668 performLayoutAndPlaceSurfacesLocked();
8669 }
8670 break;
8671 }
Romain Guy06882f82009-06-10 13:36:04 -07008672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 case HOLD_SCREEN_CHANGED: {
8674 Session oldHold;
8675 Session newHold;
8676 synchronized (mWindowMap) {
8677 oldHold = mLastReportedHold;
8678 newHold = (Session)msg.obj;
8679 mLastReportedHold = newHold;
8680 }
Romain Guy06882f82009-06-10 13:36:04 -07008681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008682 if (oldHold != newHold) {
8683 try {
8684 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008685 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 "window",
8687 BatteryStats.WAKE_TYPE_WINDOW);
8688 }
8689 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008690 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008691 "window",
8692 BatteryStats.WAKE_TYPE_WINDOW);
8693 }
8694 } catch (RemoteException e) {
8695 }
8696 }
8697 break;
8698 }
Romain Guy06882f82009-06-10 13:36:04 -07008699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008700 case APP_TRANSITION_TIMEOUT: {
8701 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008702 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008703 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 "*** APP TRANSITION TIMEOUT");
8705 mAppTransitionReady = true;
8706 mAppTransitionTimeout = true;
8707 performLayoutAndPlaceSurfacesLocked();
8708 }
8709 }
8710 break;
8711 }
Romain Guy06882f82009-06-10 13:36:04 -07008712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008713 case PERSIST_ANIMATION_SCALE: {
8714 Settings.System.putFloat(mContext.getContentResolver(),
8715 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8716 Settings.System.putFloat(mContext.getContentResolver(),
8717 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8718 break;
8719 }
Romain Guy06882f82009-06-10 13:36:04 -07008720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008721 case FORCE_GC: {
8722 synchronized(mWindowMap) {
8723 if (mAnimationPending) {
8724 // If we are animating, don't do the gc now but
8725 // delay a bit so we don't interrupt the animation.
8726 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8727 2000);
8728 return;
8729 }
8730 // If we are currently rotating the display, it will
8731 // schedule a new message when done.
8732 if (mDisplayFrozen) {
8733 return;
8734 }
8735 mFreezeGcPending = 0;
8736 }
8737 Runtime.getRuntime().gc();
8738 break;
8739 }
Romain Guy06882f82009-06-10 13:36:04 -07008740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008741 case ENABLE_SCREEN: {
8742 performEnableScreen();
8743 break;
8744 }
Romain Guy06882f82009-06-10 13:36:04 -07008745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008746 case APP_FREEZE_TIMEOUT: {
8747 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008748 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008749 int i = mAppTokens.size();
8750 while (i > 0) {
8751 i--;
8752 AppWindowToken tok = mAppTokens.get(i);
8753 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008754 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008755 unsetAppFreezingScreenLocked(tok, true, true);
8756 }
8757 }
8758 }
8759 break;
8760 }
Romain Guy06882f82009-06-10 13:36:04 -07008761
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008762 case SEND_NEW_CONFIGURATION: {
8763 removeMessages(SEND_NEW_CONFIGURATION);
8764 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008765 break;
8766 }
Romain Guy06882f82009-06-10 13:36:04 -07008767
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008768 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008769 if (mWindowsChanged) {
8770 synchronized (mWindowMap) {
8771 mWindowsChanged = false;
8772 }
8773 notifyWindowsChanged();
8774 }
8775 break;
8776 }
8777
Christopher Tatea53146c2010-09-07 11:57:52 -07008778 case DRAG_START_TIMEOUT: {
8779 IBinder win = (IBinder)msg.obj;
8780 if (DEBUG_DRAG) {
8781 Slog.w(TAG, "Timeout starting drag by win " + win);
8782 }
8783 synchronized (mWindowMap) {
8784 // !!! TODO: ANR the app that has failed to start the drag in time
8785 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008786 mDragState.unregister();
8787 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008788 mDragState.reset();
8789 mDragState = null;
8790 }
8791 }
Chris Tated4533f142010-10-19 15:15:08 -07008792 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008793 }
8794
Chris Tated4533f142010-10-19 15:15:08 -07008795 case DRAG_END_TIMEOUT: {
8796 IBinder win = (IBinder)msg.obj;
8797 if (DEBUG_DRAG) {
8798 Slog.w(TAG, "Timeout ending drag to win " + win);
8799 }
8800 synchronized (mWindowMap) {
8801 // !!! TODO: ANR the drag-receiving app
8802 mDragState.mDragResult = false;
8803 mDragState.endDragLw();
8804 }
8805 break;
8806 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008807 }
8808 }
8809 }
8810
8811 // -------------------------------------------------------------
8812 // IWindowManager API
8813 // -------------------------------------------------------------
8814
8815 public IWindowSession openSession(IInputMethodClient client,
8816 IInputContext inputContext) {
8817 if (client == null) throw new IllegalArgumentException("null client");
8818 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008819 Session session = new Session(client, inputContext);
8820 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008821 }
8822
8823 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8824 synchronized (mWindowMap) {
8825 // The focus for the client is the window immediately below
8826 // where we would place the input method window.
8827 int idx = findDesiredInputMethodWindowIndexLocked(false);
8828 WindowState imFocus;
8829 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008830 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008831 if (imFocus != null) {
8832 if (imFocus.mSession.mClient != null &&
8833 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8834 return true;
8835 }
8836 }
8837 }
8838 }
8839 return false;
8840 }
Romain Guy06882f82009-06-10 13:36:04 -07008841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008842 // -------------------------------------------------------------
8843 // Internals
8844 // -------------------------------------------------------------
8845
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008846 final WindowState windowForClientLocked(Session session, IWindow client,
8847 boolean throwOnError) {
8848 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008849 }
Romain Guy06882f82009-06-10 13:36:04 -07008850
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008851 final WindowState windowForClientLocked(Session session, IBinder client,
8852 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008853 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008854 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008855 TAG, "Looking up client " + client + ": " + win);
8856 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008857 RuntimeException ex = new IllegalArgumentException(
8858 "Requested window " + client + " does not exist");
8859 if (throwOnError) {
8860 throw ex;
8861 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008862 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008863 return null;
8864 }
8865 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008866 RuntimeException ex = new IllegalArgumentException(
8867 "Requested window " + client + " is in session " +
8868 win.mSession + ", not " + session);
8869 if (throwOnError) {
8870 throw ex;
8871 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008872 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008873 return null;
8874 }
8875
8876 return win;
8877 }
8878
Dianne Hackborna8f60182009-09-01 19:01:50 -07008879 final void rebuildAppWindowListLocked() {
8880 int NW = mWindows.size();
8881 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008882 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008883 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008884
Dianne Hackborna8f60182009-09-01 19:01:50 -07008885 // First remove all existing app windows.
8886 i=0;
8887 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008888 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008889 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008890 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008891 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008892 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008893 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008894 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008895 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008896 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008897 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8898 && lastWallpaper == i-1) {
8899 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008900 }
8901 i++;
8902 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008903
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008904 // The wallpaper window(s) typically live at the bottom of the stack,
8905 // so skip them before adding app tokens.
8906 lastWallpaper++;
8907 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008908
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008909 // First add all of the exiting app tokens... these are no longer
8910 // in the main app list, but still have windows shown. We put them
8911 // in the back because now that the animation is over we no longer
8912 // will care about them.
8913 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008914 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008915 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8916 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008917
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008918 // And add in the still active app tokens in Z order.
8919 NT = mAppTokens.size();
8920 for (int j=0; j<NT; j++) {
8921 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008922 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008923
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008924 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008925 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008926 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008927 + " windows but added " + i);
8928 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008929 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008931 private final void assignLayersLocked() {
8932 int N = mWindows.size();
8933 int curBaseLayer = 0;
8934 int curLayer = 0;
8935 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008937 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008938 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008939 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8940 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008941 curLayer += WINDOW_LAYER_MULTIPLIER;
8942 w.mLayer = curLayer;
8943 } else {
8944 curBaseLayer = curLayer = w.mBaseLayer;
8945 w.mLayer = curLayer;
8946 }
8947 if (w.mTargetAppToken != null) {
8948 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8949 } else if (w.mAppToken != null) {
8950 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8951 } else {
8952 w.mAnimLayer = w.mLayer;
8953 }
8954 if (w.mIsImWindow) {
8955 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008956 } else if (w.mIsWallpaper) {
8957 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008958 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008959 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008960 + w.mAnimLayer);
8961 //System.out.println(
8962 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8963 }
8964 }
8965
8966 private boolean mInLayout = false;
8967 private final void performLayoutAndPlaceSurfacesLocked() {
8968 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008969 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008970 throw new RuntimeException("Recursive call!");
8971 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008972 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 return;
8974 }
8975
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008976 if (mWaitingForConfig) {
8977 // Our configuration has changed (most likely rotation), but we
8978 // don't yet have the complete configuration to report to
8979 // applications. Don't do any window layout until we have it.
8980 return;
8981 }
8982
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008983 if (mDisplay == null) {
8984 // Not yet initialized, nothing to do.
8985 return;
8986 }
8987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008988 boolean recoveringMemory = false;
8989 if (mForceRemoves != null) {
8990 recoveringMemory = true;
8991 // Wait a little it for things to settle down, and off we go.
8992 for (int i=0; i<mForceRemoves.size(); i++) {
8993 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008994 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008995 removeWindowInnerLocked(ws.mSession, ws);
8996 }
8997 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008998 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008999 Object tmp = new Object();
9000 synchronized (tmp) {
9001 try {
9002 tmp.wait(250);
9003 } catch (InterruptedException e) {
9004 }
9005 }
9006 }
Romain Guy06882f82009-06-10 13:36:04 -07009007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 mInLayout = true;
9009 try {
9010 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009012 int i = mPendingRemove.size()-1;
9013 if (i >= 0) {
9014 while (i >= 0) {
9015 WindowState w = mPendingRemove.get(i);
9016 removeWindowInnerLocked(w.mSession, w);
9017 i--;
9018 }
9019 mPendingRemove.clear();
9020
9021 mInLayout = false;
9022 assignLayersLocked();
9023 mLayoutNeeded = true;
9024 performLayoutAndPlaceSurfacesLocked();
9025
9026 } else {
9027 mInLayout = false;
9028 if (mLayoutNeeded) {
9029 requestAnimationLocked(0);
9030 }
9031 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009032 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009033 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9034 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009036 } catch (RuntimeException e) {
9037 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009038 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009039 }
9040 }
9041
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009042 private final int performLayoutLockedInner() {
9043 if (!mLayoutNeeded) {
9044 return 0;
9045 }
9046
9047 mLayoutNeeded = false;
9048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009049 final int dw = mDisplay.getWidth();
9050 final int dh = mDisplay.getHeight();
9051
9052 final int N = mWindows.size();
9053 int i;
9054
Joe Onorato8a9b2202010-02-26 18:56:32 -08009055 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009056 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9057
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009058 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009059
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009060 int seq = mLayoutSeq+1;
9061 if (seq < 0) seq = 0;
9062 mLayoutSeq = seq;
9063
9064 // First perform layout of any root windows (not attached
9065 // to another window).
9066 int topAttached = -1;
9067 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009068 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009069
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009070 // Don't do layout of a window if it is not visible, or
9071 // soon won't be visible, to avoid wasting time and funky
9072 // changes while a window is animating away.
9073 final AppWindowToken atoken = win.mAppToken;
9074 final boolean gone = win.mViewVisibility == View.GONE
9075 || !win.mRelayoutCalled
9076 || win.mRootToken.hidden
9077 || (atoken != null && atoken.hiddenRequested)
9078 || win.mAttachedHidden
9079 || win.mExiting || win.mDestroying;
9080
9081 if (!win.mLayoutAttached) {
9082 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9083 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9084 + " mLayoutAttached=" + win.mLayoutAttached);
9085 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9086 + win.mViewVisibility + " mRelayoutCalled="
9087 + win.mRelayoutCalled + " hidden="
9088 + win.mRootToken.hidden + " hiddenRequested="
9089 + (atoken != null && atoken.hiddenRequested)
9090 + " mAttachedHidden=" + win.mAttachedHidden);
9091 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009092
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009093 // If this view is GONE, then skip it -- keep the current
9094 // frame, and let the caller know so they can ignore it
9095 // if they want. (We do the normal layout for INVISIBLE
9096 // windows, since that means "perform layout as normal,
9097 // just don't display").
9098 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009099 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009100 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9101 win.mLayoutSeq = seq;
9102 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9103 + win.mFrame + " mContainingFrame="
9104 + win.mContainingFrame + " mDisplayFrame="
9105 + win.mDisplayFrame);
9106 } else {
9107 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009108 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009109 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009110 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009111
9112 // Now perform layout of attached windows, which usually
9113 // depend on the position of the window they are attached to.
9114 // XXX does not deal with windows that are attached to windows
9115 // that are themselves attached.
9116 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009117 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009118
9119 // If this view is GONE, then skip it -- keep the current
9120 // frame, and let the caller know so they can ignore it
9121 // if they want. (We do the normal layout for INVISIBLE
9122 // windows, since that means "perform layout as normal,
9123 // just don't display").
9124 if (win.mLayoutAttached) {
9125 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9126 + " mHaveFrame=" + win.mHaveFrame
9127 + " mViewVisibility=" + win.mViewVisibility
9128 + " mRelayoutCalled=" + win.mRelayoutCalled);
9129 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9130 || !win.mHaveFrame) {
9131 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9132 win.mLayoutSeq = seq;
9133 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9134 + win.mFrame + " mContainingFrame="
9135 + win.mContainingFrame + " mDisplayFrame="
9136 + win.mDisplayFrame);
9137 }
9138 }
9139 }
Jeff Brown349703e2010-06-22 01:27:15 -07009140
9141 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009142 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009143
9144 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 }
Romain Guy06882f82009-06-10 13:36:04 -07009146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009147 private final void performLayoutAndPlaceSurfacesLockedInner(
9148 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009149 if (mDisplay == null) {
9150 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9151 return;
9152 }
9153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009154 final long currentTime = SystemClock.uptimeMillis();
9155 final int dw = mDisplay.getWidth();
9156 final int dh = mDisplay.getHeight();
9157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009158 int i;
9159
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009160 if (mFocusMayChange) {
9161 mFocusMayChange = false;
9162 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9163 }
9164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009165 // Initialize state of exiting tokens.
9166 for (i=mExitingTokens.size()-1; i>=0; i--) {
9167 mExitingTokens.get(i).hasVisible = false;
9168 }
9169
9170 // Initialize state of exiting applications.
9171 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9172 mExitingAppTokens.get(i).hasVisible = false;
9173 }
9174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009175 boolean orientationChangeComplete = true;
9176 Session holdScreen = null;
9177 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009178 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009179 boolean focusDisplayed = false;
9180 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009181 boolean createWatermark = false;
9182
9183 if (mFxSession == null) {
9184 mFxSession = new SurfaceSession();
9185 createWatermark = true;
9186 }
9187
9188 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009189
9190 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009191
9192 if (createWatermark) {
9193 createWatermark();
9194 }
9195 if (mWatermark != null) {
9196 mWatermark.positionSurface(dw, dh);
9197 }
9198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009200 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009201 int repeats = 0;
9202 int changes = 0;
9203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009204 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009205 repeats++;
9206 if (repeats > 6) {
9207 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9208 mLayoutNeeded = false;
9209 break;
9210 }
9211
9212 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9213 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9214 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9215 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9216 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9217 assignLayersLocked();
9218 mLayoutNeeded = true;
9219 }
9220 }
9221 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9222 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9223 if (updateOrientationFromAppTokensLocked()) {
9224 mLayoutNeeded = true;
9225 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9226 }
9227 }
9228 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9229 mLayoutNeeded = true;
9230 }
9231 }
9232
9233 // FIRST LOOP: Perform a layout, if needed.
9234 if (repeats < 4) {
9235 changes = performLayoutLockedInner();
9236 if (changes != 0) {
9237 continue;
9238 }
9239 } else {
9240 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9241 changes = 0;
9242 }
9243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244 final int transactionSequence = ++mTransactionSequence;
9245
9246 // Update animations of all applications, including those
9247 // associated with exiting/removed apps
9248 boolean tokensAnimating = false;
9249 final int NAT = mAppTokens.size();
9250 for (i=0; i<NAT; i++) {
9251 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9252 tokensAnimating = true;
9253 }
9254 }
9255 final int NEAT = mExitingAppTokens.size();
9256 for (i=0; i<NEAT; i++) {
9257 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9258 tokensAnimating = true;
9259 }
9260 }
9261
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009262 // SECOND LOOP: Execute animations and update visibility of windows.
9263
Joe Onorato8a9b2202010-02-26 18:56:32 -08009264 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009265 + transactionSequence + " tokensAnimating="
9266 + tokensAnimating);
9267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009268 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009269
9270 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009271 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009272 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009273
9274 mPolicy.beginAnimationLw(dw, dh);
9275
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009276 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009278 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009279 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280
9281 final WindowManager.LayoutParams attrs = w.mAttrs;
9282
9283 if (w.mSurface != null) {
9284 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009285 if (w.commitFinishDrawingLocked(currentTime)) {
9286 if ((w.mAttrs.flags
9287 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009288 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009289 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009290 wallpaperMayChange = true;
9291 }
9292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009293
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009294 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9296 animating = true;
9297 //w.dump(" ");
9298 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009299 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9300 wallpaperMayChange = true;
9301 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009302
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009303 if (mPolicy.doesForceHide(w, attrs)) {
9304 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009305 if (DEBUG_VISIBILITY) Slog.v(TAG,
9306 "Animation done that could impact force hide: "
9307 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009308 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009309 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009310 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9311 forceHiding = true;
9312 }
9313 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9314 boolean changed;
9315 if (forceHiding) {
9316 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009317 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9318 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009319 } else {
9320 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009321 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9322 "Now policy shown: " + w);
9323 if (changed) {
9324 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009325 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009326 // Assume we will need to animate. If
9327 // we don't (because the wallpaper will
9328 // stay with the lock screen), then we will
9329 // clean up later.
9330 Animation a = mPolicy.createForceHideEnterAnimation();
9331 if (a != null) {
9332 w.setAnimation(a);
9333 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009334 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009335 if (mCurrentFocus == null ||
9336 mCurrentFocus.mLayer < w.mLayer) {
9337 // We are showing on to of the current
9338 // focus, so re-evaluate focus to make
9339 // sure it is correct.
9340 mFocusMayChange = true;
9341 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009342 }
9343 }
9344 if (changed && (attrs.flags
9345 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9346 wallpaperMayChange = true;
9347 }
9348 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009350 mPolicy.animatingWindowLw(w, attrs);
9351 }
9352
9353 final AppWindowToken atoken = w.mAppToken;
9354 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9355 if (atoken.lastTransactionSequence != transactionSequence) {
9356 atoken.lastTransactionSequence = transactionSequence;
9357 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9358 atoken.startingDisplayed = false;
9359 }
9360 if ((w.isOnScreen() || w.mAttrs.type
9361 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9362 && !w.mExiting && !w.mDestroying) {
9363 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009364 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009365 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009366 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009367 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009368 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009369 + " pv=" + w.mPolicyVisibility
9370 + " dp=" + w.mDrawPending
9371 + " cdp=" + w.mCommitDrawPending
9372 + " ah=" + w.mAttachedHidden
9373 + " th=" + atoken.hiddenRequested
9374 + " a=" + w.mAnimating);
9375 }
9376 }
9377 if (w != atoken.startingWindow) {
9378 if (!atoken.freezingScreen || !w.mAppFreezing) {
9379 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009380 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009381 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009382 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 "tokenMayBeDrawn: " + atoken
9384 + " freezingScreen=" + atoken.freezingScreen
9385 + " mAppFreezing=" + w.mAppFreezing);
9386 tokenMayBeDrawn = true;
9387 }
9388 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009389 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009390 atoken.startingDisplayed = true;
9391 }
9392 }
9393 } else if (w.mReadyToShow) {
9394 w.performShowLocked();
9395 }
9396 }
9397
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009398 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009399
9400 if (tokenMayBeDrawn) {
9401 // See if any windows have been drawn, so they (and others
9402 // associated with them) can now be shown.
9403 final int NT = mTokenList.size();
9404 for (i=0; i<NT; i++) {
9405 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9406 if (wtoken == null) {
9407 continue;
9408 }
9409 if (wtoken.freezingScreen) {
9410 int numInteresting = wtoken.numInterestingWindows;
9411 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009412 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009413 "allDrawn: " + wtoken
9414 + " interesting=" + numInteresting
9415 + " drawn=" + wtoken.numDrawnWindows);
9416 wtoken.showAllWindowsLocked();
9417 unsetAppFreezingScreenLocked(wtoken, false, true);
9418 orientationChangeComplete = true;
9419 }
9420 } else if (!wtoken.allDrawn) {
9421 int numInteresting = wtoken.numInterestingWindows;
9422 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009423 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009424 "allDrawn: " + wtoken
9425 + " interesting=" + numInteresting
9426 + " drawn=" + wtoken.numDrawnWindows);
9427 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009428 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429
9430 // We can now show all of the drawn windows!
9431 if (!mOpeningApps.contains(wtoken)) {
9432 wtoken.showAllWindowsLocked();
9433 }
9434 }
9435 }
9436 }
9437 }
9438
9439 // If we are ready to perform an app transition, check through
9440 // all of the app tokens to be shown and see if they are ready
9441 // to go.
9442 if (mAppTransitionReady) {
9443 int NN = mOpeningApps.size();
9444 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009445 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009446 "Checking " + NN + " opening apps (frozen="
9447 + mDisplayFrozen + " timeout="
9448 + mAppTransitionTimeout + ")...");
9449 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9450 // If the display isn't frozen, wait to do anything until
9451 // all of the apps are ready. Otherwise just go because
9452 // we'll unfreeze the display when everyone is ready.
9453 for (i=0; i<NN && goodToGo; i++) {
9454 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009455 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009456 "Check opening app" + wtoken + ": allDrawn="
9457 + wtoken.allDrawn + " startingDisplayed="
9458 + wtoken.startingDisplayed);
9459 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9460 && !wtoken.startingMoved) {
9461 goodToGo = false;
9462 }
9463 }
9464 }
9465 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009466 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009467 int transit = mNextAppTransition;
9468 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009469 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009470 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009471 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009472 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009473 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 mAppTransitionTimeout = false;
9475 mStartingIconInTransition = false;
9476 mSkipAppTransitionAnimation = false;
9477
9478 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9479
Dianne Hackborna8f60182009-09-01 19:01:50 -07009480 // If there are applications waiting to come to the
9481 // top of the stack, now is the time to move their windows.
9482 // (Note that we don't do apps going to the bottom
9483 // here -- we want to keep their windows in the old
9484 // Z-order until the animation completes.)
9485 if (mToTopApps.size() > 0) {
9486 NN = mAppTokens.size();
9487 for (i=0; i<NN; i++) {
9488 AppWindowToken wtoken = mAppTokens.get(i);
9489 if (wtoken.sendingToTop) {
9490 wtoken.sendingToTop = false;
9491 moveAppWindowsLocked(wtoken, NN, false);
9492 }
9493 }
9494 mToTopApps.clear();
9495 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009496
Dianne Hackborn25994b42009-09-04 14:21:19 -07009497 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009498
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009499 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009500 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009501
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009502 // The top-most window will supply the layout params,
9503 // and we will determine it below.
9504 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009505 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009506 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009507
Joe Onorato8a9b2202010-02-26 18:56:32 -08009508 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009509 "New wallpaper target=" + mWallpaperTarget
9510 + ", lower target=" + mLowerWallpaperTarget
9511 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009512 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009513 // Do a first pass through the tokens for two
9514 // things:
9515 // (1) Determine if both the closing and opening
9516 // app token sets are wallpaper targets, in which
9517 // case special animations are needed
9518 // (since the wallpaper needs to stay static
9519 // behind them).
9520 // (2) Find the layout params of the top-most
9521 // application window in the tokens, which is
9522 // what will control the animation theme.
9523 final int NC = mClosingApps.size();
9524 NN = NC + mOpeningApps.size();
9525 for (i=0; i<NN; i++) {
9526 AppWindowToken wtoken;
9527 int mode;
9528 if (i < NC) {
9529 wtoken = mClosingApps.get(i);
9530 mode = 1;
9531 } else {
9532 wtoken = mOpeningApps.get(i-NC);
9533 mode = 2;
9534 }
9535 if (mLowerWallpaperTarget != null) {
9536 if (mLowerWallpaperTarget.mAppToken == wtoken
9537 || mUpperWallpaperTarget.mAppToken == wtoken) {
9538 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009539 }
9540 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009541 if (wtoken.appFullscreen) {
9542 WindowState ws = wtoken.findMainWindow();
9543 if (ws != null) {
9544 // If this is a compatibility mode
9545 // window, we will always use its anim.
9546 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9547 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009548 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009549 bestAnimLayer = Integer.MAX_VALUE;
9550 } else if (ws.mLayer > bestAnimLayer) {
9551 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009552 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009553 bestAnimLayer = ws.mLayer;
9554 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009555 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009556 }
9557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009558
Dianne Hackborn25994b42009-09-04 14:21:19 -07009559 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009560 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009561 "Wallpaper animation!");
9562 switch (transit) {
9563 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9564 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9565 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9566 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9567 break;
9568 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9569 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9570 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9571 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9572 break;
9573 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009574 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009575 "New transit: " + transit);
9576 } else if (oldWallpaper != null) {
9577 // We are transitioning from an activity with
9578 // a wallpaper to one without.
9579 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009580 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009581 "New transit away from wallpaper: " + transit);
9582 } else if (mWallpaperTarget != null) {
9583 // We are transitioning from an activity without
9584 // a wallpaper to now showing the wallpaper
9585 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009586 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009587 "New transit into wallpaper: " + transit);
9588 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009589
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009590 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9591 mLastEnterAnimToken = animToken;
9592 mLastEnterAnimParams = animLp;
9593 } else if (mLastEnterAnimParams != null) {
9594 animLp = mLastEnterAnimParams;
9595 mLastEnterAnimToken = null;
9596 mLastEnterAnimParams = null;
9597 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009598
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009599 // If all closing windows are obscured, then there is
9600 // no need to do an animation. This is the case, for
9601 // example, when this transition is being done behind
9602 // the lock screen.
9603 if (!mPolicy.allowAppAnimationsLw()) {
9604 animLp = null;
9605 }
9606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009607 NN = mOpeningApps.size();
9608 for (i=0; i<NN; i++) {
9609 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009610 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009611 "Now opening app" + wtoken);
9612 wtoken.reportedVisible = false;
9613 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009614 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009615 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009616 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009617 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009618 wtoken.showAllWindowsLocked();
9619 }
9620 NN = mClosingApps.size();
9621 for (i=0; i<NN; i++) {
9622 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009623 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009624 "Now closing app" + wtoken);
9625 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009626 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009627 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009628 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009629 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009630 // Force the allDrawn flag, because we want to start
9631 // this guy's animations regardless of whether it's
9632 // gotten drawn.
9633 wtoken.allDrawn = true;
9634 }
9635
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009636 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009638 mOpeningApps.clear();
9639 mClosingApps.clear();
9640
9641 // This has changed the visibility of windows, so perform
9642 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009643 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009644 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009645 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9646 assignLayersLocked();
9647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009648 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009649 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009650 }
9651 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009652
Dianne Hackborn16064f92010-03-25 00:47:24 -07009653 int adjResult = 0;
9654
Dianne Hackborna8f60182009-09-01 19:01:50 -07009655 if (!animating && mAppTransitionRunning) {
9656 // We have finished the animation of an app transition. To do
9657 // this, we have delayed a lot of operations like showing and
9658 // hiding apps, moving apps in Z-order, etc. The app token list
9659 // reflects the correct Z-order, but the window list may now
9660 // be out of sync with it. So here we will just rebuild the
9661 // entire app window list. Fun!
9662 mAppTransitionRunning = false;
9663 // Clear information about apps that were moving.
9664 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009665
Dianne Hackborna8f60182009-09-01 19:01:50 -07009666 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009667 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009668 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009669 moveInputMethodWindowsIfNeededLocked(false);
9670 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009671 // Since the window list has been rebuilt, focus might
9672 // have to be recomputed since the actual order of windows
9673 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009674 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009676
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009677 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009678 // At this point, there was a window with a wallpaper that
9679 // was force hiding other windows behind it, but now it
9680 // is going away. This may be simple -- just animate
9681 // away the wallpaper and its window -- or it may be
9682 // hard -- the wallpaper now needs to be shown behind
9683 // something that was hidden.
9684 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009685 if (mLowerWallpaperTarget != null
9686 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009687 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009688 "wallpaperForceHiding changed with lower="
9689 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009690 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009691 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9692 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9693 if (mLowerWallpaperTarget.mAppToken.hidden) {
9694 // The lower target has become hidden before we
9695 // actually started the animation... let's completely
9696 // re-evaluate everything.
9697 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009698 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009699 }
9700 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009701 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009702 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009703 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009704 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009705 + " NEW: " + mWallpaperTarget
9706 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009707 if (mLowerWallpaperTarget == null) {
9708 // Whoops, we don't need a special wallpaper animation.
9709 // Clear them out.
9710 forceHiding = false;
9711 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009712 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009713 if (w.mSurface != null) {
9714 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009715 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009716 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009717 forceHiding = true;
9718 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9719 if (!w.mAnimating) {
9720 // We set the animation above so it
9721 // is not yet running.
9722 w.clearAnimation();
9723 }
9724 }
9725 }
9726 }
9727 }
9728 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009729
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009730 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009731 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009732 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009733 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009734 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009735
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009736 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009737 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009738 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009739 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009740 assignLayersLocked();
9741 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009742 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009743 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009744 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009746
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009747 if (mFocusMayChange) {
9748 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009749 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009750 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009751 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009752 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009753 }
9754
9755 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009756 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009758
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009759 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9760 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009761
Jeff Browne33348b2010-07-15 23:54:05 -07009762 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009763 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764
9765 // THIRD LOOP: Update the surfaces of all windows.
9766
9767 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9768
9769 boolean obscured = false;
9770 boolean blurring = false;
9771 boolean dimming = false;
9772 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009773 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009774 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009776 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009778 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009779 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009780
9781 boolean displayed = false;
9782 final WindowManager.LayoutParams attrs = w.mAttrs;
9783 final int attrFlags = attrs.flags;
9784
9785 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009786 // XXX NOTE: The logic here could be improved. We have
9787 // the decision about whether to resize a window separated
9788 // from whether to hide the surface. This can cause us to
9789 // resize a surface even if we are going to hide it. You
9790 // can see this by (1) holding device in landscape mode on
9791 // home screen; (2) tapping browser icon (device will rotate
9792 // to landscape; (3) tap home. The wallpaper will be resized
9793 // in step 2 but then immediately hidden, causing us to
9794 // have to resize and then redraw it again in step 3. It
9795 // would be nice to figure out how to avoid this, but it is
9796 // difficult because we do need to resize surfaces in some
9797 // cases while they are hidden such as when first showing a
9798 // window.
9799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009801 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009802 TAG, "Placing surface #" + i + " " + w.mSurface
9803 + ": new=" + w.mShownFrame + ", old="
9804 + w.mLastShownFrame);
9805
9806 boolean resize;
9807 int width, height;
9808 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9809 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9810 w.mLastRequestedHeight != w.mRequestedHeight;
9811 // for a scaled surface, we just want to use
9812 // the requested size.
9813 width = w.mRequestedWidth;
9814 height = w.mRequestedHeight;
9815 w.mLastRequestedWidth = width;
9816 w.mLastRequestedHeight = height;
9817 w.mLastShownFrame.set(w.mShownFrame);
9818 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009819 if (SHOW_TRANSACTIONS) logSurface(w,
9820 "POS " + w.mShownFrame.left
9821 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009822 w.mSurfaceX = w.mShownFrame.left;
9823 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009824 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9825 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009826 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 if (!recoveringMemory) {
9828 reclaimSomeSurfaceMemoryLocked(w, "position");
9829 }
9830 }
9831 } else {
9832 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9833 width = w.mShownFrame.width();
9834 height = w.mShownFrame.height();
9835 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009836 }
9837
9838 if (resize) {
9839 if (width < 1) width = 1;
9840 if (height < 1) height = 1;
9841 if (w.mSurface != null) {
9842 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009843 if (SHOW_TRANSACTIONS) logSurface(w,
9844 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009845 + w.mShownFrame.top + " SIZE "
9846 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009847 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009848 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009849 w.mSurfaceW = width;
9850 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009852 w.mSurfaceX = w.mShownFrame.left;
9853 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009854 w.mSurface.setPosition(w.mShownFrame.left,
9855 w.mShownFrame.top);
9856 } catch (RuntimeException e) {
9857 // If something goes wrong with the surface (such
9858 // as running out of memory), don't take down the
9859 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009860 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009861 + "size=(" + width + "x" + height
9862 + "), pos=(" + w.mShownFrame.left
9863 + "," + w.mShownFrame.top + ")", e);
9864 if (!recoveringMemory) {
9865 reclaimSomeSurfaceMemoryLocked(w, "size");
9866 }
9867 }
9868 }
9869 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009870 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009871 w.mContentInsetsChanged =
9872 !w.mLastContentInsets.equals(w.mContentInsets);
9873 w.mVisibleInsetsChanged =
9874 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009875 boolean configChanged =
9876 w.mConfiguration != mCurConfiguration
9877 && (w.mConfiguration == null
9878 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009879 if (DEBUG_CONFIGURATION && configChanged) {
9880 Slog.v(TAG, "Win " + w + " config changed: "
9881 + mCurConfiguration);
9882 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009883 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009884 + ": configChanged=" + configChanged
9885 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009886 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009888 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009889 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009890 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009891 w.mLastFrame.set(w.mFrame);
9892 w.mLastContentInsets.set(w.mContentInsets);
9893 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009894 // If the screen is currently frozen, then keep
9895 // it frozen until this window draws at its new
9896 // orientation.
9897 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009898 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009899 "Resizing while display frozen: " + w);
9900 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009901 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009902 mWindowsFreezingScreen = true;
9903 // XXX should probably keep timeout from
9904 // when we first froze the display.
9905 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9906 mH.sendMessageDelayed(mH.obtainMessage(
9907 H.WINDOW_FREEZE_TIMEOUT), 2000);
9908 }
9909 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009910 // If the orientation is changing, then we need to
9911 // hold off on unfreezing the display until this
9912 // window has been redrawn; to do that, we need
9913 // to go through the process of getting informed
9914 // by the application when it has finished drawing.
9915 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009916 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917 "Orientation start waiting for draw in "
9918 + w + ", surface " + w.mSurface);
9919 w.mDrawPending = true;
9920 w.mCommitDrawPending = false;
9921 w.mReadyToShow = false;
9922 if (w.mAppToken != null) {
9923 w.mAppToken.allDrawn = false;
9924 }
9925 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009926 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009927 "Resizing window " + w + " to " + w.mFrame);
9928 mResizingWindows.add(w);
9929 } else if (w.mOrientationChanging) {
9930 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009931 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009932 "Orientation not waiting for draw in "
9933 + w + ", surface " + w.mSurface);
9934 w.mOrientationChanging = false;
9935 }
9936 }
9937 }
9938
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009939 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009940 if (!w.mLastHidden) {
9941 //dump();
9942 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009943 if (SHOW_TRANSACTIONS) logSurface(w,
9944 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009945 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009946 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009947 try {
9948 w.mSurface.hide();
9949 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009950 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009951 }
9952 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009953 }
9954 // If we are waiting for this window to handle an
9955 // orientation change, well, it is hidden, so
9956 // doesn't really matter. Note that this does
9957 // introduce a potential glitch if the window
9958 // becomes unhidden before it has drawn for the
9959 // new orientation.
9960 if (w.mOrientationChanging) {
9961 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009962 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 "Orientation change skips hidden " + w);
9964 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009965 } else if (w.mLastLayer != w.mAnimLayer
9966 || w.mLastAlpha != w.mShownAlpha
9967 || w.mLastDsDx != w.mDsDx
9968 || w.mLastDtDx != w.mDtDx
9969 || w.mLastDsDy != w.mDsDy
9970 || w.mLastDtDy != w.mDtDy
9971 || w.mLastHScale != w.mHScale
9972 || w.mLastVScale != w.mVScale
9973 || w.mLastHidden) {
9974 displayed = true;
9975 w.mLastAlpha = w.mShownAlpha;
9976 w.mLastLayer = w.mAnimLayer;
9977 w.mLastDsDx = w.mDsDx;
9978 w.mLastDtDx = w.mDtDx;
9979 w.mLastDsDy = w.mDsDy;
9980 w.mLastDtDy = w.mDtDy;
9981 w.mLastHScale = w.mHScale;
9982 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009983 if (SHOW_TRANSACTIONS) logSurface(w,
9984 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009985 + " matrix=[" + (w.mDsDx*w.mHScale)
9986 + "," + (w.mDtDx*w.mVScale)
9987 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009988 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009989 if (w.mSurface != null) {
9990 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009991 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009993 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009994 w.mSurface.setLayer(w.mAnimLayer);
9995 w.mSurface.setMatrix(
9996 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9997 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9998 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009999 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 if (!recoveringMemory) {
10001 reclaimSomeSurfaceMemoryLocked(w, "update");
10002 }
10003 }
10004 }
10005
10006 if (w.mLastHidden && !w.mDrawPending
10007 && !w.mCommitDrawPending
10008 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010009 if (SHOW_TRANSACTIONS) logSurface(w,
10010 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010011 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010012 + " during relayout");
10013 if (showSurfaceRobustlyLocked(w)) {
10014 w.mHasDrawn = true;
10015 w.mLastHidden = false;
10016 } else {
10017 w.mOrientationChanging = false;
10018 }
10019 }
10020 if (w.mSurface != null) {
10021 w.mToken.hasVisible = true;
10022 }
10023 } else {
10024 displayed = true;
10025 }
10026
10027 if (displayed) {
10028 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010029 if (attrs.width == LayoutParams.MATCH_PARENT
10030 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010031 covered = true;
10032 }
10033 }
10034 if (w.mOrientationChanging) {
10035 if (w.mDrawPending || w.mCommitDrawPending) {
10036 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010037 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010038 "Orientation continue waiting for draw in " + w);
10039 } else {
10040 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010041 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010042 "Orientation change complete in " + w);
10043 }
10044 }
10045 w.mToken.hasVisible = true;
10046 }
10047 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010048 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010049 "Orientation change skips hidden " + w);
10050 w.mOrientationChanging = false;
10051 }
10052
10053 final boolean canBeSeen = w.isDisplayedLw();
10054
10055 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10056 focusDisplayed = true;
10057 }
10058
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010059 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010061 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010062 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 if (w.mSurface != null) {
10064 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10065 holdScreen = w.mSession;
10066 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010067 if (!syswin && w.mAttrs.screenBrightness >= 0
10068 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 screenBrightness = w.mAttrs.screenBrightness;
10070 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010071 if (!syswin && w.mAttrs.buttonBrightness >= 0
10072 && buttonBrightness < 0) {
10073 buttonBrightness = w.mAttrs.buttonBrightness;
10074 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010075 if (canBeSeen
10076 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10077 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10078 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010079 syswin = true;
10080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010082
Dianne Hackborn25994b42009-09-04 14:21:19 -070010083 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10084 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010085 // This window completely covers everything behind it,
10086 // so we want to leave all of them as unblurred (for
10087 // performance reasons).
10088 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010089 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010090 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010091 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010092 obscured = true;
10093 if (mBackgroundFillerSurface == null) {
10094 try {
10095 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010096 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010097 0, dw, dh,
10098 PixelFormat.OPAQUE,
10099 Surface.FX_SURFACE_NORMAL);
10100 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010101 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010102 }
10103 }
10104 try {
10105 mBackgroundFillerSurface.setPosition(0, 0);
10106 mBackgroundFillerSurface.setSize(dw, dh);
10107 // Using the same layer as Dim because they will never be shown at the
10108 // same time.
10109 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10110 mBackgroundFillerSurface.show();
10111 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010112 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010113 }
10114 backgroundFillerShown = true;
10115 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010116 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010118 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010119 + ": blurring=" + blurring
10120 + " obscured=" + obscured
10121 + " displayed=" + displayed);
10122 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10123 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010124 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010125 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010126 if (mDimAnimator == null) {
10127 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010128 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010129 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010130 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010132 }
10133 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10134 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010135 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010136 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010137 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010138 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010139 + mBlurSurface + ": CREATE");
10140 try {
Romain Guy06882f82009-06-10 13:36:04 -070010141 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010142 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010143 -1, 16, 16,
10144 PixelFormat.OPAQUE,
10145 Surface.FX_SURFACE_BLUR);
10146 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010147 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010148 }
10149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010150 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010151 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10152 + mBlurSurface + ": pos=(0,0) (" +
10153 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010154 mBlurSurface.setPosition(0, 0);
10155 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010156 mBlurSurface.setLayer(w.mAnimLayer-2);
10157 if (!mBlurShown) {
10158 try {
10159 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10160 + mBlurSurface + ": SHOW");
10161 mBlurSurface.show();
10162 } catch (RuntimeException e) {
10163 Slog.w(TAG, "Failure showing blur surface", e);
10164 }
10165 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 }
10167 }
10168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010169 }
10170 }
10171 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010172
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010173 if (obscuredChanged && mWallpaperTarget == w) {
10174 // This is the wallpaper target and its obscured state
10175 // changed... make sure the current wallaper's visibility
10176 // has been updated accordingly.
10177 updateWallpaperVisibilityLocked();
10178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010179 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010180
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010181 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10182 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010183 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010184 try {
10185 mBackgroundFillerSurface.hide();
10186 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010187 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010188 }
10189 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010190
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010191 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010192 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10193 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010194 }
Romain Guy06882f82009-06-10 13:36:04 -070010195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010196 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010197 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010198 + ": HIDE");
10199 try {
10200 mBlurSurface.hide();
10201 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010202 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010203 }
10204 mBlurShown = false;
10205 }
10206
Joe Onorato8a9b2202010-02-26 18:56:32 -080010207 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010208 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010209 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010210 }
10211
Jeff Browne33348b2010-07-15 23:54:05 -070010212 mInputMonitor.updateInputWindowsLw();
10213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010214 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010215
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010216 if (mWatermark != null) {
10217 mWatermark.drawIfNeeded();
10218 }
10219
Joe Onorato8a9b2202010-02-26 18:56:32 -080010220 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010221 "With display frozen, orientationChangeComplete="
10222 + orientationChangeComplete);
10223 if (orientationChangeComplete) {
10224 if (mWindowsFreezingScreen) {
10225 mWindowsFreezingScreen = false;
10226 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10227 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010228 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010229 }
Romain Guy06882f82009-06-10 13:36:04 -070010230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010231 i = mResizingWindows.size();
10232 if (i > 0) {
10233 do {
10234 i--;
10235 WindowState win = mResizingWindows.get(i);
10236 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010237 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10238 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010239 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010240 boolean configChanged =
10241 win.mConfiguration != mCurConfiguration
10242 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010243 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10244 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10245 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010246 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010247 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010248 + " / " + mCurConfiguration + " / 0x"
10249 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010250 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010251 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010252 win.mClient.resized(win.mFrame.width(),
10253 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010254 win.mLastVisibleInsets, win.mDrawPending,
10255 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010256 win.mContentInsetsChanged = false;
10257 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010258 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010259 } catch (RemoteException e) {
10260 win.mOrientationChanging = false;
10261 }
10262 } while (i > 0);
10263 mResizingWindows.clear();
10264 }
Romain Guy06882f82009-06-10 13:36:04 -070010265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010267 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 i = mDestroySurface.size();
10269 if (i > 0) {
10270 do {
10271 i--;
10272 WindowState win = mDestroySurface.get(i);
10273 win.mDestroying = false;
10274 if (mInputMethodWindow == win) {
10275 mInputMethodWindow = null;
10276 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010277 if (win == mWallpaperTarget) {
10278 wallpaperDestroyed = true;
10279 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 win.destroySurfaceLocked();
10281 } while (i > 0);
10282 mDestroySurface.clear();
10283 }
10284
10285 // Time to remove any exiting tokens?
10286 for (i=mExitingTokens.size()-1; i>=0; i--) {
10287 WindowToken token = mExitingTokens.get(i);
10288 if (!token.hasVisible) {
10289 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010290 if (token.windowType == TYPE_WALLPAPER) {
10291 mWallpaperTokens.remove(token);
10292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 }
10294 }
10295
10296 // Time to remove any exiting applications?
10297 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10298 AppWindowToken token = mExitingAppTokens.get(i);
10299 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010300 // Make sure there is no animation running on this token,
10301 // so any windows associated with it will be removed as
10302 // soon as their animations are complete
10303 token.animation = null;
10304 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010305 mAppTokens.remove(token);
10306 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010307 if (mLastEnterAnimToken == token) {
10308 mLastEnterAnimToken = null;
10309 mLastEnterAnimParams = null;
10310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 }
10312 }
10313
Dianne Hackborna8f60182009-09-01 19:01:50 -070010314 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010315
Dianne Hackborna8f60182009-09-01 19:01:50 -070010316 if (!animating && mAppTransitionRunning) {
10317 // We have finished the animation of an app transition. To do
10318 // this, we have delayed a lot of operations like showing and
10319 // hiding apps, moving apps in Z-order, etc. The app token list
10320 // reflects the correct Z-order, but the window list may now
10321 // be out of sync with it. So here we will just rebuild the
10322 // entire app window list. Fun!
10323 mAppTransitionRunning = false;
10324 needRelayout = true;
10325 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010326 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010327 // Clear information about apps that were moving.
10328 mToBottomApps.clear();
10329 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010331 if (focusDisplayed) {
10332 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10333 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010334 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010335 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010336 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010337 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010338 requestAnimationLocked(0);
10339 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010340 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10341 }
Jeff Browneb857f12010-07-16 10:06:33 -070010342
Jeff Browne33348b2010-07-15 23:54:05 -070010343 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010344
Jeff Brown8e03b752010-06-13 19:16:55 -070010345 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10347 mPowerManager.setScreenBrightnessOverride(-1);
10348 } else {
10349 mPowerManager.setScreenBrightnessOverride((int)
10350 (screenBrightness * Power.BRIGHTNESS_ON));
10351 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010352 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10353 mPowerManager.setButtonBrightnessOverride(-1);
10354 } else {
10355 mPowerManager.setButtonBrightnessOverride((int)
10356 (buttonBrightness * Power.BRIGHTNESS_ON));
10357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010358 if (holdScreen != mHoldingScreenOn) {
10359 mHoldingScreenOn = holdScreen;
10360 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10361 mH.sendMessage(m);
10362 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010363
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010364 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010365 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010366 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10367 LocalPowerManager.BUTTON_EVENT, true);
10368 mTurnOnScreen = false;
10369 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010370
10371 // Check to see if we are now in a state where the screen should
10372 // be enabled, because the window obscured flags have changed.
10373 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010374 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010375
10376 /**
10377 * Must be called with the main window manager lock held.
10378 */
10379 void setHoldScreenLocked(boolean holding) {
10380 boolean state = mHoldingScreenWakeLock.isHeld();
10381 if (holding != state) {
10382 if (holding) {
10383 mHoldingScreenWakeLock.acquire();
10384 } else {
10385 mPolicy.screenOnStoppedLw();
10386 mHoldingScreenWakeLock.release();
10387 }
10388 }
10389 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010390
10391 void requestAnimationLocked(long delay) {
10392 if (!mAnimationPending) {
10393 mAnimationPending = true;
10394 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10395 }
10396 }
Romain Guy06882f82009-06-10 13:36:04 -070010397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 /**
10399 * Have the surface flinger show a surface, robustly dealing with
10400 * error conditions. In particular, if there is not enough memory
10401 * to show the surface, then we will try to get rid of other surfaces
10402 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010403 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010404 * @return Returns true if the surface was successfully shown.
10405 */
10406 boolean showSurfaceRobustlyLocked(WindowState win) {
10407 try {
10408 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010409 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010410 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010411 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010412 if (DEBUG_VISIBILITY) Slog.v(TAG,
10413 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010414 win.mTurnOnScreen = false;
10415 mTurnOnScreen = true;
10416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417 }
10418 return true;
10419 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010420 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 }
Romain Guy06882f82009-06-10 13:36:04 -070010422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010425 return false;
10426 }
Romain Guy06882f82009-06-10 13:36:04 -070010427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010428 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10429 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010430
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010431 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010434 if (mForceRemoves == null) {
10435 mForceRemoves = new ArrayList<WindowState>();
10436 }
Romain Guy06882f82009-06-10 13:36:04 -070010437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010438 long callingIdentity = Binder.clearCallingIdentity();
10439 try {
10440 // There was some problem... first, do a sanity check of the
10441 // window list to make sure we haven't left any dangling surfaces
10442 // around.
10443 int N = mWindows.size();
10444 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010445 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010447 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010448 if (ws.mSurface != null) {
10449 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010450 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010451 + ws + " surface=" + ws.mSurface
10452 + " token=" + win.mToken
10453 + " pid=" + ws.mSession.mPid
10454 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010455 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010456 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010457 ws.mSurface = null;
10458 mForceRemoves.add(ws);
10459 i--;
10460 N--;
10461 leakedSurface = true;
10462 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010463 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010464 + ws + " surface=" + ws.mSurface
10465 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010466 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010467 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010468 ws.mSurface = null;
10469 leakedSurface = true;
10470 }
10471 }
10472 }
Romain Guy06882f82009-06-10 13:36:04 -070010473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010474 boolean killedApps = false;
10475 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010476 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 SparseIntArray pidCandidates = new SparseIntArray();
10478 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010479 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010480 if (ws.mSurface != null) {
10481 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10482 }
10483 }
10484 if (pidCandidates.size() > 0) {
10485 int[] pids = new int[pidCandidates.size()];
10486 for (int i=0; i<pids.length; i++) {
10487 pids[i] = pidCandidates.keyAt(i);
10488 }
10489 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010490 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 killedApps = true;
10492 }
10493 } catch (RemoteException e) {
10494 }
10495 }
10496 }
Romain Guy06882f82009-06-10 13:36:04 -070010497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010498 if (leakedSurface || killedApps) {
10499 // We managed to reclaim some memory, so get rid of the trouble
10500 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010501 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010503 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010504 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010505 win.mSurface = null;
10506 }
Romain Guy06882f82009-06-10 13:36:04 -070010507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010508 try {
10509 win.mClient.dispatchGetNewSurface();
10510 } catch (RemoteException e) {
10511 }
10512 }
10513 } finally {
10514 Binder.restoreCallingIdentity(callingIdentity);
10515 }
10516 }
Romain Guy06882f82009-06-10 13:36:04 -070010517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 private boolean updateFocusedWindowLocked(int mode) {
10519 WindowState newFocus = computeFocusedWindowLocked();
10520 if (mCurrentFocus != newFocus) {
10521 // This check makes sure that we don't already have the focus
10522 // change message pending.
10523 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10524 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010525 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010526 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10527 final WindowState oldFocus = mCurrentFocus;
10528 mCurrentFocus = newFocus;
10529 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 final WindowState imWindow = mInputMethodWindow;
10532 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010533 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010535 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10536 mLayoutNeeded = true;
10537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010538 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10539 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010540 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10541 // Client will do the layout, but we need to assign layers
10542 // for handleNewWindowLocked() below.
10543 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010544 }
10545 }
Jeff Brown349703e2010-06-22 01:27:15 -070010546
10547 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10548 // If we defer assigning layers, then the caller is responsible for
10549 // doing this part.
10550 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010552 return true;
10553 }
10554 return false;
10555 }
Jeff Brown349703e2010-06-22 01:27:15 -070010556
10557 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010558 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010560
10561 private WindowState computeFocusedWindowLocked() {
10562 WindowState result = null;
10563 WindowState win;
10564
10565 int i = mWindows.size() - 1;
10566 int nextAppIndex = mAppTokens.size()-1;
10567 WindowToken nextApp = nextAppIndex >= 0
10568 ? mAppTokens.get(nextAppIndex) : null;
10569
10570 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010571 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010572
Joe Onorato8a9b2202010-02-26 18:56:32 -080010573 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010574 TAG, "Looking for focus: " + i
10575 + " = " + win
10576 + ", flags=" + win.mAttrs.flags
10577 + ", canReceive=" + win.canReceiveKeys());
10578
10579 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 // If this window's application has been removed, just skip it.
10582 if (thisApp != null && thisApp.removed) {
10583 i--;
10584 continue;
10585 }
Romain Guy06882f82009-06-10 13:36:04 -070010586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010587 // If there is a focused app, don't allow focus to go to any
10588 // windows below it. If this is an application window, step
10589 // through the app tokens until we find its app.
10590 if (thisApp != null && nextApp != null && thisApp != nextApp
10591 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10592 int origAppIndex = nextAppIndex;
10593 while (nextAppIndex > 0) {
10594 if (nextApp == mFocusedApp) {
10595 // Whoops, we are below the focused app... no focus
10596 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010597 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010598 TAG, "Reached focused app: " + mFocusedApp);
10599 return null;
10600 }
10601 nextAppIndex--;
10602 nextApp = mAppTokens.get(nextAppIndex);
10603 if (nextApp == thisApp) {
10604 break;
10605 }
10606 }
10607 if (thisApp != nextApp) {
10608 // Uh oh, the app token doesn't exist! This shouldn't
10609 // happen, but if it does we can get totally hosed...
10610 // so restart at the original app.
10611 nextAppIndex = origAppIndex;
10612 nextApp = mAppTokens.get(nextAppIndex);
10613 }
10614 }
10615
10616 // Dispatch to this window if it is wants key events.
10617 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010618 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010619 TAG, "Found focus @ " + i + " = " + win);
10620 result = win;
10621 break;
10622 }
10623
10624 i--;
10625 }
10626
10627 return result;
10628 }
10629
10630 private void startFreezingDisplayLocked() {
10631 if (mDisplayFrozen) {
10632 return;
10633 }
Romain Guy06882f82009-06-10 13:36:04 -070010634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010635 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010637 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010638 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010639 if (mFreezeGcPending != 0) {
10640 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010641 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010642 mH.removeMessages(H.FORCE_GC);
10643 Runtime.getRuntime().gc();
10644 mFreezeGcPending = now;
10645 }
10646 } else {
10647 mFreezeGcPending = now;
10648 }
Romain Guy06882f82009-06-10 13:36:04 -070010649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010650 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010651
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010652 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010653
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010654 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10655 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010656 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010657 mAppTransitionReady = true;
10658 }
Romain Guy06882f82009-06-10 13:36:04 -070010659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010660 if (PROFILE_ORIENTATION) {
10661 File file = new File("/data/system/frozen");
10662 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10663 }
10664 Surface.freezeDisplay(0);
10665 }
Romain Guy06882f82009-06-10 13:36:04 -070010666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010667 private void stopFreezingDisplayLocked() {
10668 if (!mDisplayFrozen) {
10669 return;
10670 }
Romain Guy06882f82009-06-10 13:36:04 -070010671
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010672 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10673 return;
10674 }
10675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010676 mDisplayFrozen = false;
10677 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10678 if (PROFILE_ORIENTATION) {
10679 Debug.stopMethodTracing();
10680 }
10681 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010682
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010683 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010684
Christopher Tateb696aee2010-04-02 19:08:30 -070010685 // While the display is frozen we don't re-compute the orientation
10686 // to avoid inconsistent states. However, something interesting
10687 // could have actually changed during that time so re-evaluate it
10688 // now to catch that.
10689 if (updateOrientationFromAppTokensLocked()) {
10690 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10691 }
10692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010693 // A little kludge: a lot could have happened while the
10694 // display was frozen, so now that we are coming back we
10695 // do a gc so that any remote references the system
10696 // processes holds on others can be released if they are
10697 // no longer needed.
10698 mH.removeMessages(H.FORCE_GC);
10699 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10700 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010702 mScreenFrozenLock.release();
10703 }
Romain Guy06882f82009-06-10 13:36:04 -070010704
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010705 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10706 DisplayMetrics dm) {
10707 if (index < tokens.length) {
10708 String str = tokens[index];
10709 if (str != null && str.length() > 0) {
10710 try {
10711 int val = Integer.parseInt(str);
10712 return val;
10713 } catch (Exception e) {
10714 }
10715 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010716 }
10717 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10718 return defDps;
10719 }
10720 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10721 return val;
10722 }
10723
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010724 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010725 final String[] mTokens;
10726 final String mText;
10727 final Paint mTextPaint;
10728 final int mTextWidth;
10729 final int mTextHeight;
10730 final int mTextAscent;
10731 final int mTextDescent;
10732 final int mDeltaX;
10733 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010734
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010735 Surface mSurface;
10736 int mLastDW;
10737 int mLastDH;
10738 boolean mDrawNeeded;
10739
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010740 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010741 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010742 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010743
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010744 if (false) {
10745 Log.i(TAG, "*********************** WATERMARK");
10746 for (int i=0; i<tokens.length; i++) {
10747 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10748 }
10749 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010750
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010751 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010752
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010753 StringBuilder builder = new StringBuilder(32);
10754 int len = mTokens[0].length();
10755 len = len & ~1;
10756 for (int i=0; i<len; i+=2) {
10757 int c1 = mTokens[0].charAt(i);
10758 int c2 = mTokens[0].charAt(i+1);
10759 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10760 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10761 else c1 -= '0';
10762 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10763 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10764 else c2 -= '0';
10765 builder.append((char)(255-((c1*16)+c2)));
10766 }
10767 mText = builder.toString();
10768 if (false) {
10769 Log.i(TAG, "Final text: " + mText);
10770 }
10771
10772 int fontSize = getPropertyInt(tokens, 1,
10773 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10774
10775 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10776 mTextPaint.setTextSize(fontSize);
10777 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10778
10779 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10780 mTextWidth = (int)mTextPaint.measureText(mText);
10781 mTextAscent = fm.ascent;
10782 mTextDescent = fm.descent;
10783 mTextHeight = fm.descent - fm.ascent;
10784
10785 mDeltaX = getPropertyInt(tokens, 2,
10786 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10787 mDeltaY = getPropertyInt(tokens, 3,
10788 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10789 int shadowColor = getPropertyInt(tokens, 4,
10790 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10791 int color = getPropertyInt(tokens, 5,
10792 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10793 int shadowRadius = getPropertyInt(tokens, 6,
10794 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10795 int shadowDx = getPropertyInt(tokens, 8,
10796 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10797 int shadowDy = getPropertyInt(tokens, 9,
10798 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10799
10800 mTextPaint.setColor(color);
10801 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010802
10803 try {
10804 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010805 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010806 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010807 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010808 mSurface.show();
10809 } catch (OutOfResourcesException e) {
10810 }
10811 }
10812
10813 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010814 if (mLastDW != dw || mLastDH != dh) {
10815 mLastDW = dw;
10816 mLastDH = dh;
10817 mSurface.setSize(dw, dh);
10818 mDrawNeeded = true;
10819 }
10820 }
10821
10822 void drawIfNeeded() {
10823 if (mDrawNeeded) {
10824 final int dw = mLastDW;
10825 final int dh = mLastDH;
10826
10827 mDrawNeeded = false;
10828 Rect dirty = new Rect(0, 0, dw, dh);
10829 Canvas c = null;
10830 try {
10831 c = mSurface.lockCanvas(dirty);
10832 } catch (IllegalArgumentException e) {
10833 } catch (OutOfResourcesException e) {
10834 }
10835 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010836 c.drawColor(0, PorterDuff.Mode.CLEAR);
10837
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010838 int deltaX = mDeltaX;
10839 int deltaY = mDeltaY;
10840
10841 // deltaX shouldn't be close to a round fraction of our
10842 // x step, or else things will line up too much.
10843 int div = (dw+mTextWidth)/deltaX;
10844 int rem = (dw+mTextWidth) - (div*deltaX);
10845 int qdelta = deltaX/4;
10846 if (rem < qdelta || rem > (deltaX-qdelta)) {
10847 deltaX += deltaX/3;
10848 }
10849
10850 int y = -mTextHeight;
10851 int x = -mTextWidth;
10852 while (y < (dh+mTextHeight)) {
10853 c.drawText(mText, x, y, mTextPaint);
10854 x += deltaX;
10855 if (x >= dw) {
10856 x -= (dw+mTextWidth);
10857 y += deltaY;
10858 }
10859 }
10860 mSurface.unlockCanvasAndPost(c);
10861 }
10862 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010863 }
10864 }
10865
10866 void createWatermark() {
10867 if (mWatermark != null) {
10868 return;
10869 }
10870
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010871 File file = new File("/system/etc/setup.conf");
10872 FileInputStream in = null;
10873 try {
10874 in = new FileInputStream(file);
10875 DataInputStream ind = new DataInputStream(in);
10876 String line = ind.readLine();
10877 if (line != null) {
10878 String[] toks = line.split("%");
10879 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010880 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010881 }
10882 }
10883 } catch (FileNotFoundException e) {
10884 } catch (IOException e) {
10885 } finally {
10886 if (in != null) {
10887 try {
10888 in.close();
10889 } catch (IOException e) {
10890 }
10891 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010892 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010893 }
10894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010895 @Override
10896 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10897 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10898 != PackageManager.PERMISSION_GRANTED) {
10899 pw.println("Permission Denial: can't dump WindowManager from from pid="
10900 + Binder.getCallingPid()
10901 + ", uid=" + Binder.getCallingUid());
10902 return;
10903 }
Romain Guy06882f82009-06-10 13:36:04 -070010904
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010905 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010906 pw.println(" ");
10907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010908 synchronized(mWindowMap) {
10909 pw.println("Current Window Manager state:");
10910 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010911 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010912 pw.print(" Window #"); pw.print(i); pw.print(' ');
10913 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010914 w.dump(pw, " ");
10915 }
10916 if (mInputMethodDialogs.size() > 0) {
10917 pw.println(" ");
10918 pw.println(" Input method dialogs:");
10919 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10920 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010921 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010922 }
10923 }
10924 if (mPendingRemove.size() > 0) {
10925 pw.println(" ");
10926 pw.println(" Remove pending for:");
10927 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10928 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010929 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10930 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010931 w.dump(pw, " ");
10932 }
10933 }
10934 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10935 pw.println(" ");
10936 pw.println(" Windows force removing:");
10937 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10938 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010939 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10940 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010941 w.dump(pw, " ");
10942 }
10943 }
10944 if (mDestroySurface.size() > 0) {
10945 pw.println(" ");
10946 pw.println(" Windows waiting to destroy their surface:");
10947 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10948 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010949 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10950 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010951 w.dump(pw, " ");
10952 }
10953 }
10954 if (mLosingFocus.size() > 0) {
10955 pw.println(" ");
10956 pw.println(" Windows losing focus:");
10957 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10958 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010959 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10960 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010961 w.dump(pw, " ");
10962 }
10963 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010964 if (mResizingWindows.size() > 0) {
10965 pw.println(" ");
10966 pw.println(" Windows waiting to resize:");
10967 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10968 WindowState w = mResizingWindows.get(i);
10969 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10970 pw.print(w); pw.println(":");
10971 w.dump(pw, " ");
10972 }
10973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010974 if (mSessions.size() > 0) {
10975 pw.println(" ");
10976 pw.println(" All active sessions:");
10977 Iterator<Session> it = mSessions.iterator();
10978 while (it.hasNext()) {
10979 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010980 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010981 s.dump(pw, " ");
10982 }
10983 }
10984 if (mTokenMap.size() > 0) {
10985 pw.println(" ");
10986 pw.println(" All tokens:");
10987 Iterator<WindowToken> it = mTokenMap.values().iterator();
10988 while (it.hasNext()) {
10989 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010990 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010991 token.dump(pw, " ");
10992 }
10993 }
10994 if (mTokenList.size() > 0) {
10995 pw.println(" ");
10996 pw.println(" Window token list:");
10997 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010998 pw.print(" #"); pw.print(i); pw.print(": ");
10999 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011000 }
11001 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011002 if (mWallpaperTokens.size() > 0) {
11003 pw.println(" ");
11004 pw.println(" Wallpaper tokens:");
11005 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11006 WindowToken token = mWallpaperTokens.get(i);
11007 pw.print(" Wallpaper #"); pw.print(i);
11008 pw.print(' '); pw.print(token); pw.println(':');
11009 token.dump(pw, " ");
11010 }
11011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011012 if (mAppTokens.size() > 0) {
11013 pw.println(" ");
11014 pw.println(" Application tokens in Z order:");
11015 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011016 pw.print(" App #"); pw.print(i); pw.print(": ");
11017 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011018 }
11019 }
11020 if (mFinishedStarting.size() > 0) {
11021 pw.println(" ");
11022 pw.println(" Finishing start of application tokens:");
11023 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11024 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011025 pw.print(" Finished Starting #"); pw.print(i);
11026 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011027 token.dump(pw, " ");
11028 }
11029 }
11030 if (mExitingTokens.size() > 0) {
11031 pw.println(" ");
11032 pw.println(" Exiting tokens:");
11033 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11034 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011035 pw.print(" Exiting #"); pw.print(i);
11036 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011037 token.dump(pw, " ");
11038 }
11039 }
11040 if (mExitingAppTokens.size() > 0) {
11041 pw.println(" ");
11042 pw.println(" Exiting application tokens:");
11043 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11044 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011045 pw.print(" Exiting App #"); pw.print(i);
11046 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011047 token.dump(pw, " ");
11048 }
11049 }
11050 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011051 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11052 pw.print(" mLastFocus="); pw.println(mLastFocus);
11053 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11054 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11055 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011056 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011057 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11058 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11059 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11060 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011061 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11062 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11063 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011064 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11065 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11066 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11067 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011068 if (mDimAnimator != null) {
11069 mDimAnimator.printTo(pw);
11070 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011071 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011072 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011073 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011074 pw.print(mInputMethodAnimLayerAdjustment);
11075 pw.print(" mWallpaperAnimLayerAdjustment=");
11076 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011077 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11078 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011079 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11080 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011081 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11082 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011083 pw.print(" mRotation="); pw.print(mRotation);
11084 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11085 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11086 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11087 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11088 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11089 pw.print(" mNextAppTransition=0x");
11090 pw.print(Integer.toHexString(mNextAppTransition));
11091 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011092 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011093 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011094 if (mNextAppTransitionPackage != null) {
11095 pw.print(" mNextAppTransitionPackage=");
11096 pw.print(mNextAppTransitionPackage);
11097 pw.print(", mNextAppTransitionEnter=0x");
11098 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11099 pw.print(", mNextAppTransitionExit=0x");
11100 pw.print(Integer.toHexString(mNextAppTransitionExit));
11101 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011102 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11103 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011104 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11105 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11106 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11107 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011108 if (mOpeningApps.size() > 0) {
11109 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11110 }
11111 if (mClosingApps.size() > 0) {
11112 pw.print(" mClosingApps="); pw.println(mClosingApps);
11113 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011114 if (mToTopApps.size() > 0) {
11115 pw.print(" mToTopApps="); pw.println(mToTopApps);
11116 }
11117 if (mToBottomApps.size() > 0) {
11118 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11119 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011120 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11121 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011122 }
11123 }
11124
Jeff Brown349703e2010-06-22 01:27:15 -070011125 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011126 public void monitor() {
11127 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011128 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011130
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011131 /**
11132 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011133 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011134 */
11135 private static class DimAnimator {
11136 Surface mDimSurface;
11137 boolean mDimShown = false;
11138 float mDimCurrentAlpha;
11139 float mDimTargetAlpha;
11140 float mDimDeltaPerMs;
11141 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011142
11143 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011144
11145 DimAnimator (SurfaceSession session) {
11146 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011147 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011148 + mDimSurface + ": CREATE");
11149 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011150 mDimSurface = new Surface(session, 0,
11151 "DimSurface",
11152 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011153 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011154 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011155 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011156 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011157 }
11158 }
11159 }
11160
11161 /**
11162 * Show the dim surface.
11163 */
11164 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011165 if (!mDimShown) {
11166 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11167 dw + "x" + dh + ")");
11168 mDimShown = true;
11169 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011170 mLastDimWidth = dw;
11171 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011172 mDimSurface.setPosition(0, 0);
11173 mDimSurface.setSize(dw, dh);
11174 mDimSurface.show();
11175 } catch (RuntimeException e) {
11176 Slog.w(TAG, "Failure showing dim surface", e);
11177 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011178 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11179 mLastDimWidth = dw;
11180 mLastDimHeight = dh;
11181 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011182 }
11183 }
11184
11185 /**
11186 * Set's the dim surface's layer and update dim parameters that will be used in
11187 * {@link updateSurface} after all windows are examined.
11188 */
11189 void updateParameters(WindowState w, long currentTime) {
11190 mDimSurface.setLayer(w.mAnimLayer-1);
11191
11192 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011193 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011194 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011195 if (mDimTargetAlpha != target) {
11196 // If the desired dim level has changed, then
11197 // start an animation to it.
11198 mLastDimAnimTime = currentTime;
11199 long duration = (w.mAnimating && w.mAnimation != null)
11200 ? w.mAnimation.computeDurationHint()
11201 : DEFAULT_DIM_DURATION;
11202 if (target > mDimTargetAlpha) {
11203 // This is happening behind the activity UI,
11204 // so we can make it run a little longer to
11205 // give a stronger impression without disrupting
11206 // the user.
11207 duration *= DIM_DURATION_MULTIPLIER;
11208 }
11209 if (duration < 1) {
11210 // Don't divide by zero
11211 duration = 1;
11212 }
11213 mDimTargetAlpha = target;
11214 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11215 }
11216 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011217
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011218 /**
11219 * Updating the surface's alpha. Returns true if the animation continues, or returns
11220 * false when the animation is finished and the dim surface is hidden.
11221 */
11222 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11223 if (!dimming) {
11224 if (mDimTargetAlpha != 0) {
11225 mLastDimAnimTime = currentTime;
11226 mDimTargetAlpha = 0;
11227 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11228 }
11229 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011230
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011231 boolean animating = false;
11232 if (mLastDimAnimTime != 0) {
11233 mDimCurrentAlpha += mDimDeltaPerMs
11234 * (currentTime-mLastDimAnimTime);
11235 boolean more = true;
11236 if (displayFrozen) {
11237 // If the display is frozen, there is no reason to animate.
11238 more = false;
11239 } else if (mDimDeltaPerMs > 0) {
11240 if (mDimCurrentAlpha > mDimTargetAlpha) {
11241 more = false;
11242 }
11243 } else if (mDimDeltaPerMs < 0) {
11244 if (mDimCurrentAlpha < mDimTargetAlpha) {
11245 more = false;
11246 }
11247 } else {
11248 more = false;
11249 }
11250
11251 // Do we need to continue animating?
11252 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011253 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011254 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11255 mLastDimAnimTime = currentTime;
11256 mDimSurface.setAlpha(mDimCurrentAlpha);
11257 animating = true;
11258 } else {
11259 mDimCurrentAlpha = mDimTargetAlpha;
11260 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011261 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011262 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11263 mDimSurface.setAlpha(mDimCurrentAlpha);
11264 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011265 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011266 + ": HIDE");
11267 try {
11268 mDimSurface.hide();
11269 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011270 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011271 }
11272 mDimShown = false;
11273 }
11274 }
11275 }
11276 return animating;
11277 }
11278
11279 public void printTo(PrintWriter pw) {
11280 pw.print(" mDimShown="); pw.print(mDimShown);
11281 pw.print(" current="); pw.print(mDimCurrentAlpha);
11282 pw.print(" target="); pw.print(mDimTargetAlpha);
11283 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11284 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11285 }
11286 }
11287
11288 /**
11289 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11290 * This is used for opening/closing transition for apps in compatible mode.
11291 */
11292 private static class FadeInOutAnimation extends Animation {
11293 int mWidth;
11294 boolean mFadeIn;
11295
11296 public FadeInOutAnimation(boolean fadeIn) {
11297 setInterpolator(new AccelerateInterpolator());
11298 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11299 mFadeIn = fadeIn;
11300 }
11301
11302 @Override
11303 protected void applyTransformation(float interpolatedTime, Transformation t) {
11304 float x = interpolatedTime;
11305 if (!mFadeIn) {
11306 x = 1.0f - x; // reverse the interpolation for fade out
11307 }
11308 if (x < 0.5) {
11309 // move the window out of the screen.
11310 t.getMatrix().setTranslate(mWidth, 0);
11311 } else {
11312 t.getMatrix().setTranslate(0, 0);// show
11313 t.setAlpha((x - 0.5f) * 2);
11314 }
11315 }
11316
11317 @Override
11318 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11319 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11320 mWidth = width;
11321 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011322
11323 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011324 public int getZAdjustment() {
11325 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011326 }
11327 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011328}