blob: 7a2c0c66a9a80f351f55200361d9195c46f742c1 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
32import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
33import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
35import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070036import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38import com.android.internal.app.IBatteryStats;
39import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080040import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070041import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import com.android.internal.view.IInputContext;
43import com.android.internal.view.IInputMethodClient;
44import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080045import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import com.android.server.am.BatteryStatsService;
47
48import android.Manifest;
49import android.app.ActivityManagerNative;
50import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070053import android.content.ClipData;
54import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070056import android.content.Intent;
57import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080062import android.content.res.Resources;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080063import android.graphics.Bitmap;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070068import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.graphics.Rect;
70import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070071import android.graphics.Typeface;
72import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.BatteryStats;
74import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070075import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.Debug;
77import android.os.Handler;
78import android.os.IBinder;
79import android.os.LocalPowerManager;
80import android.os.Looper;
81import android.os.Message;
82import android.os.Parcel;
83import android.os.ParcelFileDescriptor;
84import android.os.Power;
85import android.os.PowerManager;
86import android.os.Process;
87import android.os.RemoteException;
88import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070089import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.os.SystemClock;
91import android.os.SystemProperties;
92import android.os.TokenWatcher;
93import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070094import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070096import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080097import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070099import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700101import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.Gravity;
103import android.view.IApplicationToken;
104import android.view.IOnKeyguardExitResult;
105import android.view.IRotationWatcher;
106import android.view.IWindow;
107import android.view.IWindowManager;
108import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700109import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700111import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700112import android.view.InputHandler;
113import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.KeyEvent;
115import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116import android.view.Surface;
117import android.view.SurfaceSession;
118import android.view.View;
119import android.view.ViewTreeObserver;
120import android.view.WindowManager;
121import android.view.WindowManagerImpl;
122import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700123import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700125import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import android.view.animation.Animation;
127import android.view.animation.AnimationUtils;
128import android.view.animation.Transformation;
129
130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700163 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_APP_TRANSITIONS = false;
165 static final boolean DEBUG_STARTING_WINDOW = false;
166 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700167 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700168 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700170 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 static final boolean PROFILE_ORIENTATION = false;
173 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700174 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** How much to multiply the policy's type layer, to reserve room
177 * for multiple windows of the same type and Z-ordering adjustment
178 * with TYPE_LAYER_OFFSET. */
179 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
182 * or below others in the same layer. */
183 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /** How much to increment the layer for each window, to reserve room
186 * for effect surfaces between them.
187 */
188 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /** The maximum length we will accept for a loaded animation duration:
191 * this is 10 seconds.
192 */
193 static final int MAX_ANIMATION_DURATION = 10*1000;
194
195 /** Amount of time (in milliseconds) to animate the dim surface from one
196 * value to another, when no window animation is driving it.
197 */
198 static final int DEFAULT_DIM_DURATION = 200;
199
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700200 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
201 * compatible windows.
202 */
203 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
204
Dianne Hackborna1111872010-11-23 20:55:11 -0800205 /**
206 * If true, the window manager will do its own custom freezing and general
207 * management of the screen during rotation.
208 */
209 static final boolean CUSTOM_SCREEN_ROTATION = true;
210
Jeff Brown7fbdc842010-06-17 20:52:56 -0700211 // 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;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800383 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800384 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 final float[] mTmpFloats = new float[9];
389
390 boolean mSafeMode;
391 boolean mDisplayEnabled = false;
392 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700393 int mInitialDisplayWidth = 0;
394 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 int mRotation = 0;
396 int mRequestedRotation = 0;
397 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700398 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 ArrayList<IRotationWatcher> mRotationWatchers
400 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mLayoutNeeded = true;
403 boolean mAnimationPending = false;
404 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800405 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 boolean mWindowsFreezingScreen = false;
407 long mFreezeGcPending = 0;
408 int mAppsFreezingScreen = 0;
409
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800410 int mLayoutSeq = 0;
411
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800412 // State while inside of layoutAndPlaceSurfacesLocked().
413 boolean mFocusMayChange;
414
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800415 Configuration mCurConfiguration = new Configuration();
416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 // This is held as long as we have the screen frozen, to give us time to
418 // perform a rotation animation when turning off shows the lock screen which
419 // changes the orientation.
420 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // State management of app transitions. When we are preparing for a
423 // transition, mNextAppTransition will be the kind of transition to
424 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
425 // mOpeningApps and mClosingApps are the lists of tokens that will be
426 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700427 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700428 String mNextAppTransitionPackage;
429 int mNextAppTransitionEnter;
430 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 boolean mAppTransitionTimeout = false;
434 boolean mStartingIconInTransition = false;
435 boolean mSkipAppTransitionAnimation = false;
436 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700438 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
439 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 H mH = new H();
444
445 WindowState mCurrentFocus = null;
446 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 // This just indicates the window the input method is on top of, not
449 // necessarily the window its input is going to.
450 WindowState mInputMethodTarget = null;
451 WindowState mUpcomingInputMethodTarget = null;
452 boolean mInputMethodTargetWaitingAnim;
453 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 WindowState mInputMethodWindow = null;
456 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
457
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700458 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800459
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700460 // If non-null, this is the currently visible window that is associated
461 // with the wallpaper.
462 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700463 // If non-null, we are in the middle of animating from one wallpaper target
464 // to another, and this is the lower one in Z-order.
465 WindowState mLowerWallpaperTarget = null;
466 // If non-null, we are in the middle of animating from one wallpaper target
467 // to another, and this is the higher one in Z-order.
468 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800469 // Window currently running an animation that has requested it be detached
470 // from the wallpaper. This means we need to ensure the wallpaper is
471 // visible behind it in case it animates in a way that would allow it to be
472 // seen.
473 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700474 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700475 float mLastWallpaperX = -1;
476 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800477 float mLastWallpaperXStep = -1;
478 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700479 // This is set when we are waiting for a wallpaper to tell us it is done
480 // changing its scroll position.
481 WindowState mWaitingOnWallpaper;
482 // The last time we had a timeout when waiting for a wallpaper.
483 long mLastWallpaperTimeoutTime;
484 // We give a wallpaper up to 150ms to finish scrolling.
485 static final long WALLPAPER_TIMEOUT = 150;
486 // Time we wait after a timeout before trying to wait again.
487 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 AppWindowToken mFocusedApp = null;
490
491 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 float mWindowAnimationScale = 1.0f;
494 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700495
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700496 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497
498 // Who is holding the screen on.
499 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700500 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700501
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700502 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700505 * Drag/drop state
506 */
507 class DragState {
508 IBinder mToken;
509 Surface mSurface;
510 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700511 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700512 ClipData mData;
513 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700514 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700515 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700516 float mThumbOffsetX, mThumbOffsetY;
517 InputChannel mServerChannel, mClientChannel;
518 WindowState mTargetWindow;
519 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700520 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700521
522 private final Rect tmpRect = new Rect();
523
Chris Tate7b362e42010-11-04 16:02:52 -0700524 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700525 mToken = token;
526 mSurface = surface;
527 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700528 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700529 mNotifiedWindows = new ArrayList<WindowState>();
530 }
531
532 void reset() {
533 if (mSurface != null) {
534 mSurface.destroy();
535 }
536 mSurface = null;
537 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700538 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700539 mToken = null;
540 mData = null;
541 mThumbOffsetX = mThumbOffsetY = 0;
542 mNotifiedWindows = null;
543 }
544
545 void register() {
546 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
547 if (mClientChannel != null) {
548 Slog.e(TAG, "Duplicate register of drag input channel");
549 } else {
550 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
551 mServerChannel = channels[0];
552 mClientChannel = channels[1];
553 mInputManager.registerInputChannel(mServerChannel);
554 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
555 mH.getLooper().getQueue());
556 }
557 }
558
559 void unregister() {
560 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
561 if (mClientChannel == null) {
562 Slog.e(TAG, "Unregister of nonexistent drag input channel");
563 } else {
564 mInputManager.unregisterInputChannel(mServerChannel);
565 InputQueue.unregisterInputChannel(mClientChannel);
566 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700567 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700568 mClientChannel = null;
569 mServerChannel = null;
570 }
571 }
572
Chris Tatea32dcf72010-10-14 12:13:50 -0700573 int getDragLayerLw() {
574 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
575 * TYPE_LAYER_MULTIPLIER
576 + TYPE_LAYER_OFFSET;
577 }
578
Christopher Tatea53146c2010-09-07 11:57:52 -0700579 /* call out to each visible window/session informing it about the drag
580 */
Chris Tateb8203e92010-10-12 14:23:21 -0700581 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700582 // Cache a base-class instance of the clip metadata so that parceling
583 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700584 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700585 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700586 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700587
588 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700589 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700590 }
591
Christopher Tate2c095f32010-10-04 14:13:40 -0700592 final int N = mWindows.size();
593 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700594 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700595 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700596 }
597
598 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
599 * designated window is potentially a drop recipient. There are race situations
600 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
601 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700602 *
603 * This method clones the 'event' parameter if it's being delivered to the same
604 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700605 */
Chris Tateb478f462010-10-15 16:02:26 -0700606 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
607 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700608 // Don't actually send the event if the drag is supposed to be pinned
609 // to the originating window but 'newWin' is not that window.
610 if (mLocalOnly) {
611 final IBinder winBinder = newWin.mClient.asBinder();
612 if (winBinder != mLocalWin) {
613 if (DEBUG_DRAG) {
614 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
615 }
616 return;
617 }
618 }
619
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700620 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700621 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
622 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800623 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700624 try {
625 newWin.mClient.dispatchDragEvent(event);
626 // track each window that we've notified that the drag is starting
627 mNotifiedWindows.add(newWin);
628 } catch (RemoteException e) {
629 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700630 } finally {
631 // if the callee was local, the dispatch has already recycled the event
632 if (Process.myPid() != newWin.mSession.mPid) {
633 event.recycle();
634 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700635 }
636 }
637 }
638
639 /* helper - construct and send a DRAG_STARTED event only if the window has not
640 * previously been notified, i.e. it became visible after the drag operation
641 * was begun. This is a rare case.
642 */
643 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700644 if (mDragInProgress) {
645 // If we have sent the drag-started, we needn't do so again
646 for (WindowState ws : mNotifiedWindows) {
647 if (ws == newWin) {
648 return;
649 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700650 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700651 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700652 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700653 }
Chris Tateb478f462010-10-15 16:02:26 -0700654 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700655 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700656 }
657
Chris Tated4533f142010-10-19 15:15:08 -0700658 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700659 if (DEBUG_DRAG) {
660 Slog.d(TAG, "broadcasting DRAG_ENDED");
661 }
Chris Tated4533f142010-10-19 15:15:08 -0700662 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800663 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700664 for (WindowState ws: mNotifiedWindows) {
665 try {
666 ws.mClient.dispatchDragEvent(evt);
667 } catch (RemoteException e) {
668 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700669 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700670 }
Chris Tated4533f142010-10-19 15:15:08 -0700671 mNotifiedWindows.clear();
672 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700673 evt.recycle();
674 }
675
Chris Tated4533f142010-10-19 15:15:08 -0700676 void endDragLw() {
677 mDragState.broadcastDragEndedLw();
678
679 // stop intercepting input
680 mDragState.unregister();
681 mInputMonitor.updateInputWindowsLw();
682
683 // free our resources and drop all the object references
684 mDragState.reset();
685 mDragState = null;
686 }
687
Christopher Tatea53146c2010-09-07 11:57:52 -0700688 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700689 final int myPid = Process.myPid();
690
691 // Move the surface to the given touch
692 mSurface.openTransaction();
693 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
694 mSurface.closeTransaction();
695
696 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700697 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700698 if (mLocalOnly) {
699 final IBinder touchedBinder = touchedWin.mClient.asBinder();
700 if (touchedBinder != mLocalWin) {
701 // This drag is pinned only to the originating window, but the drag
702 // point is outside that window. Pretend it's over empty space.
703 touchedWin = null;
704 }
705 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700706 try {
707 // have we dragged over a new window?
708 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
709 if (DEBUG_DRAG) {
710 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
711 }
712 // force DRAG_EXITED_EVENT if appropriate
713 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700714 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800715 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700716 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700717 if (myPid != mTargetWindow.mSession.mPid) {
718 evt.recycle();
719 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700720 }
721 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700722 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700723 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
724 }
725 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700726 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800727 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700728 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700729 if (myPid != touchedWin.mSession.mPid) {
730 evt.recycle();
731 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700732 }
733 } catch (RemoteException e) {
734 Slog.w(TAG, "can't send drag notification to windows");
735 }
736 mTargetWindow = touchedWin;
737 }
738
Chris Tated4533f142010-10-19 15:15:08 -0700739 // Tell the drop target about the data. Returns 'true' if we can immediately
740 // dispatch the global drag-ended message, 'false' if we need to wait for a
741 // result from the recipient.
742 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700744 if (touchedWin == null) {
745 // "drop" outside a valid window -- no recipient to apply a
746 // timeout to, and we can send the drag-ended message immediately.
747 mDragResult = false;
748 return true;
749 }
750
751 if (DEBUG_DRAG) {
752 Slog.d(TAG, "sending DROP to " + touchedWin);
753 }
754 final int myPid = Process.myPid();
755 final IBinder token = touchedWin.mClient.asBinder();
756 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
757 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800758 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700759 try {
760 touchedWin.mClient.dispatchDragEvent(evt);
761
762 // 5 second timeout for this window to respond to the drop
763 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
764 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
765 mH.sendMessageDelayed(msg, 5000);
766 } catch (RemoteException e) {
767 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
768 return true;
769 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700770 if (myPid != touchedWin.mSession.mPid) {
771 evt.recycle();
772 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700773 }
Chris Tated4533f142010-10-19 15:15:08 -0700774 mToken = token;
775 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700776 }
777
778 // Find the visible, touch-deliverable window under the given point
779 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
780 WindowState touchedWin = null;
781 final int x = (int) xf;
782 final int y = (int) yf;
783 final ArrayList<WindowState> windows = mWindows;
784 final int N = windows.size();
785 for (int i = N - 1; i >= 0; i--) {
786 WindowState child = windows.get(i);
787 final int flags = child.mAttrs.flags;
788 if (!child.isVisibleLw()) {
789 // not visible == don't tell about drags
790 continue;
791 }
792 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
793 // not touchable == don't tell about drags
794 continue;
795 }
796 // account for the window's decor etc
797 tmpRect.set(child.mFrame);
798 if (child.mTouchableInsets == ViewTreeObserver
799 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
800 // The point is inside of the window if it is
801 // inside the frame, AND the content part of that
802 // frame that was given by the application.
803 tmpRect.left += child.mGivenContentInsets.left;
804 tmpRect.top += child.mGivenContentInsets.top;
805 tmpRect.right -= child.mGivenContentInsets.right;
806 tmpRect.bottom -= child.mGivenContentInsets.bottom;
807 } else if (child.mTouchableInsets == ViewTreeObserver
808 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
809 // The point is inside of the window if it is
810 // inside the frame, AND the visible part of that
811 // frame that was given by the application.
812 tmpRect.left += child.mGivenVisibleInsets.left;
813 tmpRect.top += child.mGivenVisibleInsets.top;
814 tmpRect.right -= child.mGivenVisibleInsets.right;
815 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
816 }
817 final int touchFlags = flags &
818 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
819 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
820 if (tmpRect.contains(x, y) || touchFlags == 0) {
821 // Found it
822 touchedWin = child;
823 break;
824 }
825 }
826
827 return touchedWin;
828 }
829 }
830
831 DragState mDragState = null;
832 private final InputHandler mDragInputHandler = new BaseInputHandler() {
833 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700834 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
835 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700836 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700837 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
838 && mDragState != null) {
839 boolean endDrag = false;
840 final float newX = event.getRawX();
841 final float newY = event.getRawY();
842
Christopher Tatea53146c2010-09-07 11:57:52 -0700843 switch (event.getAction()) {
844 case MotionEvent.ACTION_DOWN: {
845 if (DEBUG_DRAG) {
846 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
847 }
848 } break;
849
850 case MotionEvent.ACTION_MOVE: {
851 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700852 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700853 mDragState.notifyMoveLw(newX, newY);
854 }
855 } break;
856
857 case MotionEvent.ACTION_UP: {
858 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
859 + newX + "," + newY);
860 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700861 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700862 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700863 } break;
864
865 case MotionEvent.ACTION_CANCEL: {
866 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
867 endDrag = true;
868 } break;
869 }
870
871 if (endDrag) {
872 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
873 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700874 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700875 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700876 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700877 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700878
879 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700880 }
881 } catch (Exception e) {
882 Slog.e(TAG, "Exception caught by drag handleMotion", e);
883 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700884 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700885 }
886 }
887 };
888
889 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 * Whether the UI is currently running in touch mode (not showing
891 * navigational focus because the user is directly pressing the screen).
892 */
893 boolean mInTouchMode = false;
894
895 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700896 private ArrayList<WindowChangeListener> mWindowChangeListeners =
897 new ArrayList<WindowChangeListener>();
898 private boolean mWindowsChanged = false;
899
900 public interface WindowChangeListener {
901 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700902 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904
Dianne Hackbornc485a602009-03-24 22:39:49 -0700905 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700906 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700907
908 // The frame use to limit the size of the app running in compatibility mode.
909 Rect mCompatibleScreenFrame = new Rect();
910 // The surface used to fill the outer rim of the app running in compatibility mode.
911 Surface mBackgroundFillerSurface = null;
912 boolean mBackgroundFillerShown = false;
913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 public static WindowManagerService main(Context context,
915 PowerManagerService pm, boolean haveInputMethods) {
916 WMThread thr = new WMThread(context, pm, haveInputMethods);
917 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 synchronized (thr) {
920 while (thr.mService == null) {
921 try {
922 thr.wait();
923 } catch (InterruptedException e) {
924 }
925 }
926 }
Romain Guy06882f82009-06-10 13:36:04 -0700927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 return thr.mService;
929 }
Romain Guy06882f82009-06-10 13:36:04 -0700930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 static class WMThread extends Thread {
932 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 private final Context mContext;
935 private final PowerManagerService mPM;
936 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 public WMThread(Context context, PowerManagerService pm,
939 boolean haveInputMethods) {
940 super("WindowManager");
941 mContext = context;
942 mPM = pm;
943 mHaveInputMethods = haveInputMethods;
944 }
Romain Guy06882f82009-06-10 13:36:04 -0700945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 public void run() {
947 Looper.prepare();
948 WindowManagerService s = new WindowManagerService(mContext, mPM,
949 mHaveInputMethods);
950 android.os.Process.setThreadPriority(
951 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700952 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 synchronized (this) {
955 mService = s;
956 notifyAll();
957 }
Romain Guy06882f82009-06-10 13:36:04 -0700958
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700959 // For debug builds, log event loop stalls to dropbox for analysis.
960 if (StrictMode.conditionallyEnableDebugLogging()) {
961 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
962 }
963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 Looper.loop();
965 }
966 }
967
968 static class PolicyThread extends Thread {
969 private final WindowManagerPolicy mPolicy;
970 private final WindowManagerService mService;
971 private final Context mContext;
972 private final PowerManagerService mPM;
973 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 public PolicyThread(WindowManagerPolicy policy,
976 WindowManagerService service, Context context,
977 PowerManagerService pm) {
978 super("WindowManagerPolicy");
979 mPolicy = policy;
980 mService = service;
981 mContext = context;
982 mPM = pm;
983 }
Romain Guy06882f82009-06-10 13:36:04 -0700984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 public void run() {
986 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800987 WindowManagerPolicyThread.set(this, Looper.myLooper());
988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800990 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 android.os.Process.setThreadPriority(
992 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700993 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 synchronized (this) {
997 mRunning = true;
998 notifyAll();
999 }
Romain Guy06882f82009-06-10 13:36:04 -07001000
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001001 // For debug builds, log event loop stalls to dropbox for analysis.
1002 if (StrictMode.conditionallyEnableDebugLogging()) {
1003 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1004 }
1005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 Looper.loop();
1007 }
1008 }
1009
1010 private WindowManagerService(Context context, PowerManagerService pm,
1011 boolean haveInputMethods) {
1012 mContext = context;
1013 mHaveInputMethods = haveInputMethods;
1014 mLimitedAlphaCompositing = context.getResources().getBoolean(
1015 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 mPowerManager = pm;
1018 mPowerManager.setPolicy(mPolicy);
1019 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1020 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1021 "SCREEN_FROZEN");
1022 mScreenFrozenLock.setReferenceCounted(false);
1023
1024 mActivityManager = ActivityManagerNative.getDefault();
1025 mBatteryStats = BatteryStatsService.getService();
1026
1027 // Get persisted window scale setting
1028 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1029 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1030 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1031 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001032
Jim Miller284b62e2010-06-08 14:27:42 -07001033 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1034 IntentFilter filter = new IntentFilter();
1035 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1036 mContext.registerReceiver(mBroadcastReceiver, filter);
1037
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001038 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1039 "KEEP_SCREEN_ON_FLAG");
1040 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041
Jeff Browne33348b2010-07-15 23:54:05 -07001042 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1045 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 synchronized (thr) {
1048 while (!thr.mRunning) {
1049 try {
1050 thr.wait();
1051 } catch (InterruptedException e) {
1052 }
1053 }
1054 }
Romain Guy06882f82009-06-10 13:36:04 -07001055
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001056 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 // Add ourself to the Watchdog monitors.
1059 Watchdog.getInstance().addMonitor(this);
1060 }
1061
1062 @Override
1063 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1064 throws RemoteException {
1065 try {
1066 return super.onTransact(code, data, reply, flags);
1067 } catch (RuntimeException e) {
1068 // The window manager only throws security exceptions, so let's
1069 // log all others.
1070 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 }
1073 throw e;
1074 }
1075 }
1076
Jeff Browne33348b2010-07-15 23:54:05 -07001077 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001079 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 TAG, "Adding window " + window + " at "
1081 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1082 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001083 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 }
1085
Jeff Browne33348b2010-07-15 23:54:05 -07001086 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001088 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 TAG, "Adding window " + window + " at "
1090 + i + " of " + mWindows.size() + " (before " + pos + ")");
1091 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001092 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 }
1094
1095 //This method finds out the index of a window that has the same app token as
1096 //win. used for z ordering the windows in mWindows
1097 private int findIdxBasedOnAppTokens(WindowState win) {
1098 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001099 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 int jmax = localmWindows.size();
1101 if(jmax == 0) {
1102 return -1;
1103 }
1104 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001105 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 if(wentry.mAppToken == win.mAppToken) {
1107 return j;
1108 }
1109 }
1110 return -1;
1111 }
Romain Guy06882f82009-06-10 13:36:04 -07001112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1114 final IWindow client = win.mClient;
1115 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001116 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 final int N = localmWindows.size();
1119 final WindowState attached = win.mAttachedWindow;
1120 int i;
1121 if (attached == null) {
1122 int tokenWindowsPos = token.windows.size();
1123 if (token.appWindowToken != null) {
1124 int index = tokenWindowsPos-1;
1125 if (index >= 0) {
1126 // If this application has existing windows, we
1127 // simply place the new window on top of them... but
1128 // keep the starting window on top.
1129 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1130 // Base windows go behind everything else.
1131 placeWindowBefore(token.windows.get(0), win);
1132 tokenWindowsPos = 0;
1133 } else {
1134 AppWindowToken atoken = win.mAppToken;
1135 if (atoken != null &&
1136 token.windows.get(index) == atoken.startingWindow) {
1137 placeWindowBefore(token.windows.get(index), win);
1138 tokenWindowsPos--;
1139 } else {
1140 int newIdx = findIdxBasedOnAppTokens(win);
1141 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001142 //there is a window above this one associated with the same
1143 //apptoken note that the window could be a floating window
1144 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001146 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001147 TAG, "Adding window " + win + " at "
1148 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001150 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 }
1153 }
1154 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001155 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 TAG, "Figuring out where to add app window "
1157 + client.asBinder() + " (token=" + token + ")");
1158 // Figure out where the window should go, based on the
1159 // order of applications.
1160 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001161 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 for (i=NA-1; i>=0; i--) {
1163 AppWindowToken t = mAppTokens.get(i);
1164 if (t == token) {
1165 i--;
1166 break;
1167 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001168
Dianne Hackborna8f60182009-09-01 19:01:50 -07001169 // We haven't reached the token yet; if this token
1170 // is not going to the bottom and has windows, we can
1171 // use it as an anchor for when we do reach the token.
1172 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 pos = t.windows.get(0);
1174 }
1175 }
1176 // We now know the index into the apps. If we found
1177 // an app window above, that gives us the position; else
1178 // we need to look some more.
1179 if (pos != null) {
1180 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001181 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 if (atoken != null) {
1183 final int NC = atoken.windows.size();
1184 if (NC > 0) {
1185 WindowState bottom = atoken.windows.get(0);
1186 if (bottom.mSubLayer < 0) {
1187 pos = bottom;
1188 }
1189 }
1190 }
1191 placeWindowBefore(pos, win);
1192 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001193 // Continue looking down until we find the first
1194 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 while (i >= 0) {
1196 AppWindowToken t = mAppTokens.get(i);
1197 final int NW = t.windows.size();
1198 if (NW > 0) {
1199 pos = t.windows.get(NW-1);
1200 break;
1201 }
1202 i--;
1203 }
1204 if (pos != null) {
1205 // Move in front of any windows attached to this
1206 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001207 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 if (atoken != null) {
1209 final int NC = atoken.windows.size();
1210 if (NC > 0) {
1211 WindowState top = atoken.windows.get(NC-1);
1212 if (top.mSubLayer >= 0) {
1213 pos = top;
1214 }
1215 }
1216 }
1217 placeWindowAfter(pos, win);
1218 } else {
1219 // Just search for the start of this layer.
1220 final int myLayer = win.mBaseLayer;
1221 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001222 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 if (w.mBaseLayer > myLayer) {
1224 break;
1225 }
1226 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001227 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001228 TAG, "Adding window " + win + " at "
1229 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001231 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 }
1233 }
1234 }
1235 } else {
1236 // Figure out where window should go, based on layer.
1237 final int myLayer = win.mBaseLayer;
1238 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001239 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 i++;
1241 break;
1242 }
1243 }
1244 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001245 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001246 TAG, "Adding window " + win + " at "
1247 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001249 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
1251 if (addToToken) {
1252 token.windows.add(tokenWindowsPos, win);
1253 }
1254
1255 } else {
1256 // Figure out this window's ordering relative to the window
1257 // it is attached to.
1258 final int NA = token.windows.size();
1259 final int sublayer = win.mSubLayer;
1260 int largestSublayer = Integer.MIN_VALUE;
1261 WindowState windowWithLargestSublayer = null;
1262 for (i=0; i<NA; i++) {
1263 WindowState w = token.windows.get(i);
1264 final int wSublayer = w.mSubLayer;
1265 if (wSublayer >= largestSublayer) {
1266 largestSublayer = wSublayer;
1267 windowWithLargestSublayer = w;
1268 }
1269 if (sublayer < 0) {
1270 // For negative sublayers, we go below all windows
1271 // in the same sublayer.
1272 if (wSublayer >= sublayer) {
1273 if (addToToken) {
1274 token.windows.add(i, win);
1275 }
1276 placeWindowBefore(
1277 wSublayer >= 0 ? attached : w, win);
1278 break;
1279 }
1280 } else {
1281 // For positive sublayers, we go above all windows
1282 // in the same sublayer.
1283 if (wSublayer > sublayer) {
1284 if (addToToken) {
1285 token.windows.add(i, win);
1286 }
1287 placeWindowBefore(w, win);
1288 break;
1289 }
1290 }
1291 }
1292 if (i >= NA) {
1293 if (addToToken) {
1294 token.windows.add(win);
1295 }
1296 if (sublayer < 0) {
1297 placeWindowBefore(attached, win);
1298 } else {
1299 placeWindowAfter(largestSublayer >= 0
1300 ? windowWithLargestSublayer
1301 : attached,
1302 win);
1303 }
1304 }
1305 }
Romain Guy06882f82009-06-10 13:36:04 -07001306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 if (win.mAppToken != null && addToToken) {
1308 win.mAppToken.allAppWindows.add(win);
1309 }
1310 }
Romain Guy06882f82009-06-10 13:36:04 -07001311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 static boolean canBeImeTarget(WindowState w) {
1313 final int fl = w.mAttrs.flags
1314 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1315 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1316 return w.isVisibleOrAdding();
1317 }
1318 return false;
1319 }
Romain Guy06882f82009-06-10 13:36:04 -07001320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001322 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 final int N = localmWindows.size();
1324 WindowState w = null;
1325 int i = N;
1326 while (i > 0) {
1327 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001328 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001329
Joe Onorato8a9b2202010-02-26 18:56:32 -08001330 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 // + Integer.toHexString(w.mAttrs.flags));
1332 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 // Yet more tricksyness! If this window is a "starting"
1336 // window, we do actually want to be on top of it, but
1337 // it is not -really- where input will go. So if the caller
1338 // is not actually looking to move the IME, look down below
1339 // for a real window to target...
1340 if (!willMove
1341 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1342 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001343 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1345 i--;
1346 w = wb;
1347 }
1348 }
1349 break;
1350 }
1351 }
Romain Guy06882f82009-06-10 13:36:04 -07001352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001354
Joe Onorato8a9b2202010-02-26 18:56:32 -08001355 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 if (willMove && w != null) {
1359 final WindowState curTarget = mInputMethodTarget;
1360 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 // Now some fun for dealing with window animations that
1363 // modify the Z order. We need to look at all windows below
1364 // the current target that are in this app, finding the highest
1365 // visible one in layering.
1366 AppWindowToken token = curTarget.mAppToken;
1367 WindowState highestTarget = null;
1368 int highestPos = 0;
1369 if (token.animating || token.animation != null) {
1370 int pos = 0;
1371 pos = localmWindows.indexOf(curTarget);
1372 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001373 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 if (win.mAppToken != token) {
1375 break;
1376 }
1377 if (!win.mRemoved) {
1378 if (highestTarget == null || win.mAnimLayer >
1379 highestTarget.mAnimLayer) {
1380 highestTarget = win;
1381 highestPos = pos;
1382 }
1383 }
1384 pos--;
1385 }
1386 }
Romain Guy06882f82009-06-10 13:36:04 -07001387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001389 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 + mNextAppTransition + " " + highestTarget
1391 + " animating=" + highestTarget.isAnimating()
1392 + " layer=" + highestTarget.mAnimLayer
1393 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001394
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001395 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 // If we are currently setting up for an animation,
1397 // hold everything until we can find out what will happen.
1398 mInputMethodTargetWaitingAnim = true;
1399 mInputMethodTarget = highestTarget;
1400 return highestPos + 1;
1401 } else if (highestTarget.isAnimating() &&
1402 highestTarget.mAnimLayer > w.mAnimLayer) {
1403 // If the window we are currently targeting is involved
1404 // with an animation, and it is on top of the next target
1405 // we will be over, then hold off on moving until
1406 // that is done.
1407 mInputMethodTarget = highestTarget;
1408 return highestPos + 1;
1409 }
1410 }
1411 }
1412 }
Romain Guy06882f82009-06-10 13:36:04 -07001413
Joe Onorato8a9b2202010-02-26 18:56:32 -08001414 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 if (w != null) {
1416 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001417 if (DEBUG_INPUT_METHOD) {
1418 RuntimeException e = null;
1419 if (!HIDE_STACK_CRAWLS) {
1420 e = new RuntimeException();
1421 e.fillInStackTrace();
1422 }
1423 Slog.w(TAG, "Moving IM target from "
1424 + mInputMethodTarget + " to " + w, e);
1425 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 mInputMethodTarget = w;
1427 if (w.mAppToken != null) {
1428 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1429 } else {
1430 setInputMethodAnimLayerAdjustment(0);
1431 }
1432 }
1433 return i+1;
1434 }
1435 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001436 if (DEBUG_INPUT_METHOD) {
1437 RuntimeException e = null;
1438 if (!HIDE_STACK_CRAWLS) {
1439 e = new RuntimeException();
1440 e.fillInStackTrace();
1441 }
1442 Slog.w(TAG, "Moving IM target from "
1443 + mInputMethodTarget + " to null", e);
1444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 mInputMethodTarget = null;
1446 setInputMethodAnimLayerAdjustment(0);
1447 }
1448 return -1;
1449 }
Romain Guy06882f82009-06-10 13:36:04 -07001450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 void addInputMethodWindowToListLocked(WindowState win) {
1452 int pos = findDesiredInputMethodWindowIndexLocked(true);
1453 if (pos >= 0) {
1454 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001455 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001456 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001458 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 moveInputMethodDialogsLocked(pos+1);
1460 return;
1461 }
1462 win.mTargetAppToken = null;
1463 addWindowToListInOrderLocked(win, true);
1464 moveInputMethodDialogsLocked(pos);
1465 }
Romain Guy06882f82009-06-10 13:36:04 -07001466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001468 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 mInputMethodAnimLayerAdjustment = adj;
1470 WindowState imw = mInputMethodWindow;
1471 if (imw != null) {
1472 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001473 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 + " anim layer: " + imw.mAnimLayer);
1475 int wi = imw.mChildWindows.size();
1476 while (wi > 0) {
1477 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001478 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001480 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 + " anim layer: " + cw.mAnimLayer);
1482 }
1483 }
1484 int di = mInputMethodDialogs.size();
1485 while (di > 0) {
1486 di --;
1487 imw = mInputMethodDialogs.get(di);
1488 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001489 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 + " anim layer: " + imw.mAnimLayer);
1491 }
1492 }
Romain Guy06882f82009-06-10 13:36:04 -07001493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1495 int wpos = mWindows.indexOf(win);
1496 if (wpos >= 0) {
1497 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001498 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001500 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 int NC = win.mChildWindows.size();
1502 while (NC > 0) {
1503 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001504 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 int cpos = mWindows.indexOf(cw);
1506 if (cpos >= 0) {
1507 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001508 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001509 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 mWindows.remove(cpos);
1511 }
1512 }
1513 }
1514 return interestingPos;
1515 }
Romain Guy06882f82009-06-10 13:36:04 -07001516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 private void reAddWindowToListInOrderLocked(WindowState win) {
1518 addWindowToListInOrderLocked(win, false);
1519 // This is a hack to get all of the child windows added as well
1520 // at the right position. Child windows should be rare and
1521 // this case should be rare, so it shouldn't be that big a deal.
1522 int wpos = mWindows.indexOf(win);
1523 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001524 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001525 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001527 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 reAddWindowLocked(wpos, win);
1529 }
1530 }
Romain Guy06882f82009-06-10 13:36:04 -07001531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 void logWindowList(String prefix) {
1533 int N = mWindows.size();
1534 while (N > 0) {
1535 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001536 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 }
1538 }
Romain Guy06882f82009-06-10 13:36:04 -07001539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 void moveInputMethodDialogsLocked(int pos) {
1541 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001544 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 for (int i=0; i<N; i++) {
1546 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1547 }
1548 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001549 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 logWindowList(" ");
1551 }
Romain Guy06882f82009-06-10 13:36:04 -07001552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 if (pos >= 0) {
1554 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1555 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001556 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 if (wp == mInputMethodWindow) {
1558 pos++;
1559 }
1560 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001561 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 for (int i=0; i<N; i++) {
1563 WindowState win = dialogs.get(i);
1564 win.mTargetAppToken = targetAppToken;
1565 pos = reAddWindowLocked(pos, win);
1566 }
1567 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001568 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 logWindowList(" ");
1570 }
1571 return;
1572 }
1573 for (int i=0; i<N; i++) {
1574 WindowState win = dialogs.get(i);
1575 win.mTargetAppToken = null;
1576 reAddWindowToListInOrderLocked(win);
1577 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001578 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 logWindowList(" ");
1580 }
1581 }
1582 }
Romain Guy06882f82009-06-10 13:36:04 -07001583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1585 final WindowState imWin = mInputMethodWindow;
1586 final int DN = mInputMethodDialogs.size();
1587 if (imWin == null && DN == 0) {
1588 return false;
1589 }
Romain Guy06882f82009-06-10 13:36:04 -07001590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1592 if (imPos >= 0) {
1593 // In this case, the input method windows are to be placed
1594 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 // First check to see if the input method windows are already
1597 // located here, and contiguous.
1598 final int N = mWindows.size();
1599 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001600 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 // Figure out the actual input method window that should be
1603 // at the bottom of their stack.
1604 WindowState baseImWin = imWin != null
1605 ? imWin : mInputMethodDialogs.get(0);
1606 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001607 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 if (cw.mSubLayer < 0) baseImWin = cw;
1609 }
Romain Guy06882f82009-06-10 13:36:04 -07001610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 if (firstImWin == baseImWin) {
1612 // The windows haven't moved... but are they still contiguous?
1613 // First find the top IM window.
1614 int pos = imPos+1;
1615 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001616 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 break;
1618 }
1619 pos++;
1620 }
1621 pos++;
1622 // Now there should be no more input method windows above.
1623 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001624 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 break;
1626 }
1627 pos++;
1628 }
1629 if (pos >= N) {
1630 // All is good!
1631 return false;
1632 }
1633 }
Romain Guy06882f82009-06-10 13:36:04 -07001634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 if (imWin != null) {
1636 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001637 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 logWindowList(" ");
1639 }
1640 imPos = tmpRemoveWindowLocked(imPos, imWin);
1641 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001642 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 logWindowList(" ");
1644 }
1645 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1646 reAddWindowLocked(imPos, imWin);
1647 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001648 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 logWindowList(" ");
1650 }
1651 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1652 } else {
1653 moveInputMethodDialogsLocked(imPos);
1654 }
Romain Guy06882f82009-06-10 13:36:04 -07001655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 } else {
1657 // In this case, the input method windows go in a fixed layer,
1658 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001661 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 tmpRemoveWindowLocked(0, imWin);
1663 imWin.mTargetAppToken = null;
1664 reAddWindowToListInOrderLocked(imWin);
1665 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001666 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 logWindowList(" ");
1668 }
1669 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1670 } else {
1671 moveInputMethodDialogsLocked(-1);;
1672 }
Romain Guy06882f82009-06-10 13:36:04 -07001673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 }
Romain Guy06882f82009-06-10 13:36:04 -07001675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676 if (needAssignLayers) {
1677 assignLayersLocked();
1678 }
Romain Guy06882f82009-06-10 13:36:04 -07001679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 return true;
1681 }
Romain Guy06882f82009-06-10 13:36:04 -07001682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 void adjustInputMethodDialogsLocked() {
1684 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1685 }
Romain Guy06882f82009-06-10 13:36:04 -07001686
Dianne Hackborn25994b42009-09-04 14:21:19 -07001687 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001688 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001689 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1690 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1691 ? wallpaperTarget.mAppToken.animation : null)
1692 + " upper=" + mUpperWallpaperTarget
1693 + " lower=" + mLowerWallpaperTarget);
1694 return (wallpaperTarget != null
1695 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1696 && wallpaperTarget.mAppToken.animation != null)))
1697 || mUpperWallpaperTarget != null
1698 || mLowerWallpaperTarget != null;
1699 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001700
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001701 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1702 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001703
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001704 int adjustWallpaperWindowsLocked() {
1705 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001706
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001707 final int dw = mDisplay.getWidth();
1708 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001709
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001710 // First find top-most window that has asked to be on top of the
1711 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001712 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001713 int N = localmWindows.size();
1714 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001715 WindowState foundW = null;
1716 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001717 WindowState topCurW = null;
1718 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001719 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001720 int i = N;
1721 while (i > 0) {
1722 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001723 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001724 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1725 if (topCurW == null) {
1726 topCurW = w;
1727 topCurI = i;
1728 }
1729 continue;
1730 }
1731 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001732 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001733 // If this window's app token is hidden and not animating,
1734 // it is of no interest to us.
1735 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001736 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001737 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001738 continue;
1739 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001740 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001741 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001742 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1743 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001744 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001745 && (mWallpaperTarget == w
1746 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001747 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001748 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001749 foundW = w;
1750 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001751 if (w == mWallpaperTarget && ((w.mAppToken != null
1752 && w.mAppToken.animation != null)
1753 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001754 // The current wallpaper target is animating, so we'll
1755 // look behind it for another possible target and figure
1756 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001757 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001758 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001759 continue;
1760 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001761 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001762 } else if (w == mWindowDetachedWallpaper) {
1763 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001764 }
1765 }
1766
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001767 if (foundW == null && windowDetachedI >= 0) {
1768 if (DEBUG_WALLPAPER) Slog.v(TAG,
1769 "Found animating detached wallpaper activity: #" + i + "=" + w);
1770 foundW = w;
1771 foundI = windowDetachedI;
1772 }
1773
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001774 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001775 // If we are currently waiting for an app transition, and either
1776 // the current target or the next target are involved with it,
1777 // then hold off on doing anything with the wallpaper.
1778 // Note that we are checking here for just whether the target
1779 // is part of an app token... which is potentially overly aggressive
1780 // (the app token may not be involved in the transition), but good
1781 // enough (we'll just wait until whatever transition is pending
1782 // executes).
1783 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001784 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001785 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001786 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001787 }
1788 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001789 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001790 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001791 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001792 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001794
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001795 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001796 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001797 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001798 + " oldTarget: " + mWallpaperTarget);
1799 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001800
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 mLowerWallpaperTarget = null;
1802 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001803
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001804 WindowState oldW = mWallpaperTarget;
1805 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001806
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001807 // Now what is happening... if the current and new targets are
1808 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001809 if (foundW != null && oldW != null) {
1810 boolean oldAnim = oldW.mAnimation != null
1811 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1812 boolean foundAnim = foundW.mAnimation != null
1813 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001816 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001817 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001818 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001819 int oldI = localmWindows.indexOf(oldW);
1820 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001821 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001822 }
1823 if (oldI >= 0) {
1824 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001825 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001826 + "=" + oldW + "; new#" + foundI
1827 + "=" + foundW);
1828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001829
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001830 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001831 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001832 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001834 }
1835 mWallpaperTarget = oldW;
1836 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001837
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001838 // Now set the upper and lower wallpaper targets
1839 // correctly, and make sure that we are positioning
1840 // the wallpaper below the lower.
1841 if (foundI > oldI) {
1842 // The new target is on top of the old one.
1843 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001844 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001845 }
1846 mUpperWallpaperTarget = foundW;
1847 mLowerWallpaperTarget = oldW;
1848 foundW = oldW;
1849 foundI = oldI;
1850 } else {
1851 // The new target is below the old one.
1852 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001853 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001854 }
1855 mUpperWallpaperTarget = oldW;
1856 mLowerWallpaperTarget = foundW;
1857 }
1858 }
1859 }
1860 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001861
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001862 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001863 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001864 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1865 || (mLowerWallpaperTarget.mAppToken != null
1866 && mLowerWallpaperTarget.mAppToken.animation != null);
1867 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1868 || (mUpperWallpaperTarget.mAppToken != null
1869 && mUpperWallpaperTarget.mAppToken.animation != null);
1870 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001871 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001872 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001873 }
1874 mLowerWallpaperTarget = null;
1875 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001876 }
1877 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001878
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001879 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001880 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001881 // The window is visible to the compositor... but is it visible
1882 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001883 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001884 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001885
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001886 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001887 // its layer adjustment. Only do this if we are not transfering
1888 // between two wallpaper targets.
1889 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001890 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001891 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001892
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001893 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1894 * TYPE_LAYER_MULTIPLIER
1895 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001896
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001897 // Now w is the window we are supposed to be behind... but we
1898 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001899 // AND any starting window associated with it, AND below the
1900 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001901 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001902 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001903 if (wb.mBaseLayer < maxLayer &&
1904 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001905 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001906 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001907 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001908 // This window is not related to the previous one in any
1909 // interesting way, so stop here.
1910 break;
1911 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001912 foundW = wb;
1913 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001914 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001915 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001916 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001917 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001918
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001919 if (foundW == null && topCurW != null) {
1920 // There is no wallpaper target, so it goes at the bottom.
1921 // We will assume it is the same place as last time, if known.
1922 foundW = topCurW;
1923 foundI = topCurI+1;
1924 } else {
1925 // Okay i is the position immediately above the wallpaper. Look at
1926 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001927 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001928 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001929
Dianne Hackborn284ac932009-08-28 10:34:25 -07001930 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001931 if (mWallpaperTarget.mWallpaperX >= 0) {
1932 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001933 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001934 }
1935 if (mWallpaperTarget.mWallpaperY >= 0) {
1936 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001937 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001938 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001939 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001940
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001941 // Start stepping backwards from here, ensuring that our wallpaper windows
1942 // are correctly placed.
1943 int curTokenIndex = mWallpaperTokens.size();
1944 while (curTokenIndex > 0) {
1945 curTokenIndex--;
1946 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001947 if (token.hidden == visible) {
1948 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1949 token.hidden = !visible;
1950 // Need to do a layout to ensure the wallpaper now has the
1951 // correct size.
1952 mLayoutNeeded = true;
1953 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001954
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001955 int curWallpaperIndex = token.windows.size();
1956 while (curWallpaperIndex > 0) {
1957 curWallpaperIndex--;
1958 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001959
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001960 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001961 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001962 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001963
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001964 // First, make sure the client has the current visibility
1965 // state.
1966 if (wallpaper.mWallpaperVisible != visible) {
1967 wallpaper.mWallpaperVisible = visible;
1968 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001969 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001970 "Setting visibility of wallpaper " + wallpaper
1971 + ": " + visible);
1972 wallpaper.mClient.dispatchAppVisibility(visible);
1973 } catch (RemoteException e) {
1974 }
1975 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001976
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001977 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001978 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001979 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001980
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 // First, if this window is at the current index, then all
1982 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001983 if (wallpaper == foundW) {
1984 foundI--;
1985 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001986 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001987 continue;
1988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001989
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001990 // The window didn't match... the current wallpaper window,
1991 // wherever it is, is in the wrong place, so make sure it is
1992 // not in the list.
1993 int oldIndex = localmWindows.indexOf(wallpaper);
1994 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001995 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001996 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001997 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001998 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001999 if (oldIndex < foundI) {
2000 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002001 }
2002 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002003
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002004 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002005 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002006 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002007 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002008
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002009 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002010 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002011 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002012 }
2013 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002014
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002015 return changed;
2016 }
2017
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002018 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002019 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002020 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002021 mWallpaperAnimLayerAdjustment = adj;
2022 int curTokenIndex = mWallpaperTokens.size();
2023 while (curTokenIndex > 0) {
2024 curTokenIndex--;
2025 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2026 int curWallpaperIndex = token.windows.size();
2027 while (curWallpaperIndex > 0) {
2028 curWallpaperIndex--;
2029 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2030 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002031 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002032 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002033 }
2034 }
2035 }
2036
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002037 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2038 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002039 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002040 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002041 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002042 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002043 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2044 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2045 changed = wallpaperWin.mXOffset != offset;
2046 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002047 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002048 + wallpaperWin + " x: " + offset);
2049 wallpaperWin.mXOffset = offset;
2050 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002051 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002052 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002053 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002054 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002055 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002056
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002057 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002058 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002059 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2060 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2061 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002062 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002063 + wallpaperWin + " y: " + offset);
2064 changed = true;
2065 wallpaperWin.mYOffset = offset;
2066 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002067 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002068 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002069 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002070 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002071 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002072
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002073 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002074 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002075 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002076 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2077 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002078 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002079 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002080 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002081 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002082 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2083 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002084 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002085 if (mWaitingOnWallpaper != null) {
2086 long start = SystemClock.uptimeMillis();
2087 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2088 < start) {
2089 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002090 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002091 "Waiting for offset complete...");
2092 mWindowMap.wait(WALLPAPER_TIMEOUT);
2093 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002094 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002095 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002096 if ((start+WALLPAPER_TIMEOUT)
2097 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002098 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002099 + wallpaperWin);
2100 mLastWallpaperTimeoutTime = start;
2101 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002102 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002103 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002104 }
2105 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002106 } catch (RemoteException e) {
2107 }
2108 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002109
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002110 return changed;
2111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002112
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002113 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002114 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002115 if (mWaitingOnWallpaper != null &&
2116 mWaitingOnWallpaper.mClient.asBinder() == window) {
2117 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002118 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002119 }
2120 }
2121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002122
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002123 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002124 final int dw = mDisplay.getWidth();
2125 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002126
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002127 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002128
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002129 WindowState target = mWallpaperTarget;
2130 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002131 if (target.mWallpaperX >= 0) {
2132 mLastWallpaperX = target.mWallpaperX;
2133 } else if (changingTarget.mWallpaperX >= 0) {
2134 mLastWallpaperX = changingTarget.mWallpaperX;
2135 }
2136 if (target.mWallpaperY >= 0) {
2137 mLastWallpaperY = target.mWallpaperY;
2138 } else if (changingTarget.mWallpaperY >= 0) {
2139 mLastWallpaperY = changingTarget.mWallpaperY;
2140 }
2141 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002142
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002143 int curTokenIndex = mWallpaperTokens.size();
2144 while (curTokenIndex > 0) {
2145 curTokenIndex--;
2146 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2147 int curWallpaperIndex = token.windows.size();
2148 while (curWallpaperIndex > 0) {
2149 curWallpaperIndex--;
2150 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2151 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2152 wallpaper.computeShownFrameLocked();
2153 changed = true;
2154 // We only want to be synchronous with one wallpaper.
2155 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002156 }
2157 }
2158 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002159
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002160 return changed;
2161 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002162
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002163 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002164 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002165 final int dw = mDisplay.getWidth();
2166 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002167
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002168 int curTokenIndex = mWallpaperTokens.size();
2169 while (curTokenIndex > 0) {
2170 curTokenIndex--;
2171 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002172 if (token.hidden == visible) {
2173 token.hidden = !visible;
2174 // Need to do a layout to ensure the wallpaper now has the
2175 // correct size.
2176 mLayoutNeeded = true;
2177 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002178
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002179 int curWallpaperIndex = token.windows.size();
2180 while (curWallpaperIndex > 0) {
2181 curWallpaperIndex--;
2182 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2183 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002184 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002185 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002186
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002187 if (wallpaper.mWallpaperVisible != visible) {
2188 wallpaper.mWallpaperVisible = visible;
2189 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002190 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002191 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002192 + ": " + visible);
2193 wallpaper.mClient.dispatchAppVisibility(visible);
2194 } catch (RemoteException e) {
2195 }
2196 }
2197 }
2198 }
2199 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 public int addWindow(Session session, IWindow client,
2202 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002203 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 int res = mPolicy.checkAddPermission(attrs);
2205 if (res != WindowManagerImpl.ADD_OKAY) {
2206 return res;
2207 }
Romain Guy06882f82009-06-10 13:36:04 -07002208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 boolean reportNewConfig = false;
2210 WindowState attachedWindow = null;
2211 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002212 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002216 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 }
Romain Guy06882f82009-06-10 13:36:04 -07002218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002220 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2222 }
2223
2224 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002225 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002227 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 + attrs.token + ". Aborting.");
2229 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2230 }
2231 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2232 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002233 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002234 + attrs.token + ". Aborting.");
2235 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2236 }
2237 }
2238
2239 boolean addToken = false;
2240 WindowToken token = mTokenMap.get(attrs.token);
2241 if (token == null) {
2242 if (attrs.type >= FIRST_APPLICATION_WINDOW
2243 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002244 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 + attrs.token + ". Aborting.");
2246 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2247 }
2248 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002249 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 + attrs.token + ". Aborting.");
2251 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2252 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002253 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002254 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002255 + attrs.token + ". Aborting.");
2256 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 token = new WindowToken(attrs.token, -1, false);
2259 addToken = true;
2260 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2261 && attrs.type <= LAST_APPLICATION_WINDOW) {
2262 AppWindowToken atoken = token.appWindowToken;
2263 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002264 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 + token + ". Aborting.");
2266 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2267 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002268 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 + token + ". Aborting.");
2270 return WindowManagerImpl.ADD_APP_EXITING;
2271 }
2272 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2273 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002274 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2276 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2277 }
2278 } else if (attrs.type == TYPE_INPUT_METHOD) {
2279 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002280 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 + attrs.token + ". Aborting.");
2282 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2283 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002284 } else if (attrs.type == TYPE_WALLPAPER) {
2285 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002286 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002287 + attrs.token + ". Aborting.");
2288 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2289 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 }
2291
2292 win = new WindowState(session, client, token,
2293 attachedWindow, attrs, viewVisibility);
2294 if (win.mDeathRecipient == null) {
2295 // Client has apparently died, so there is no reason to
2296 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002297 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 + " that is dead, aborting.");
2299 return WindowManagerImpl.ADD_APP_EXITING;
2300 }
2301
2302 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 res = mPolicy.prepareAddWindowLw(win, attrs);
2305 if (res != WindowManagerImpl.ADD_OKAY) {
2306 return res;
2307 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002308
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002309 if (outInputChannel != null) {
2310 String name = win.makeInputChannelName();
2311 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2312 win.mInputChannel = inputChannels[0];
2313 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2314
2315 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317
2318 // From now on, no exceptions or errors allowed!
2319
2320 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002321
Dianne Hackborn5132b372010-07-29 12:51:35 -07002322 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 if (addToken) {
2325 mTokenMap.put(attrs.token, token);
2326 mTokenList.add(token);
2327 }
2328 win.attach();
2329 mWindowMap.put(client.asBinder(), win);
2330
2331 if (attrs.type == TYPE_APPLICATION_STARTING &&
2332 token.appWindowToken != null) {
2333 token.appWindowToken.startingWindow = win;
2334 }
2335
2336 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 if (attrs.type == TYPE_INPUT_METHOD) {
2339 mInputMethodWindow = win;
2340 addInputMethodWindowToListLocked(win);
2341 imMayMove = false;
2342 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2343 mInputMethodDialogs.add(win);
2344 addWindowToListInOrderLocked(win, true);
2345 adjustInputMethodDialogsLocked();
2346 imMayMove = false;
2347 } else {
2348 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002349 if (attrs.type == TYPE_WALLPAPER) {
2350 mLastWallpaperTimeoutTime = 0;
2351 adjustWallpaperWindowsLocked();
2352 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002353 adjustWallpaperWindowsLocked();
2354 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 }
Romain Guy06882f82009-06-10 13:36:04 -07002356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 if (mInTouchMode) {
2362 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2363 }
2364 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2365 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2366 }
Romain Guy06882f82009-06-10 13:36:04 -07002367
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002368 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002370 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2371 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 imMayMove = false;
2373 }
2374 }
Romain Guy06882f82009-06-10 13:36:04 -07002375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002377 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 }
Romain Guy06882f82009-06-10 13:36:04 -07002379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 assignLayersLocked();
2381 // Don't do layout here, the window must call
2382 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 //dump();
2385
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002386 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002387 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002388 }
Jeff Brown349703e2010-06-22 01:27:15 -07002389
Joe Onorato8a9b2202010-02-26 18:56:32 -08002390 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 TAG, "New client " + client.asBinder()
2392 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002393
2394 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2395 reportNewConfig = true;
2396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 }
2398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 if (reportNewConfig) {
2400 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 return res;
2406 }
Romain Guy06882f82009-06-10 13:36:04 -07002407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 public void removeWindow(Session session, IWindow client) {
2409 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002410 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 if (win == null) {
2412 return;
2413 }
2414 removeWindowLocked(session, win);
2415 }
2416 }
Romain Guy06882f82009-06-10 13:36:04 -07002417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 public void removeWindowLocked(Session session, WindowState win) {
2419
Joe Onorato8a9b2202010-02-26 18:56:32 -08002420 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 TAG, "Remove " + win + " client="
2422 + Integer.toHexString(System.identityHashCode(
2423 win.mClient.asBinder()))
2424 + ", surface=" + win.mSurface);
2425
2426 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002427
2428 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002429
Joe Onorato8a9b2202010-02-26 18:56:32 -08002430 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2432 + " mExiting=" + win.mExiting
2433 + " isAnimating=" + win.isAnimating()
2434 + " app-animation="
2435 + (win.mAppToken != null ? win.mAppToken.animation : null)
2436 + " inPendingTransaction="
2437 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2438 + " mDisplayFrozen=" + mDisplayFrozen);
2439 // Visibility of the removed window. Will be used later to update orientation later on.
2440 boolean wasVisible = false;
2441 // First, see if we need to run an animation. If we do, we have
2442 // to hold off on removing the window until the animation is done.
2443 // If the display is frozen, just remove immediately, since the
2444 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002445 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 // If we are not currently running the exit animation, we
2447 // need to see about starting one.
2448 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2451 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2452 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2453 }
2454 // Try starting an animation.
2455 if (applyAnimationLocked(win, transit, false)) {
2456 win.mExiting = true;
2457 }
2458 }
2459 if (win.mExiting || win.isAnimating()) {
2460 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002461 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 win.mExiting = true;
2463 win.mRemoveOnExit = true;
2464 mLayoutNeeded = true;
2465 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2466 performLayoutAndPlaceSurfacesLocked();
2467 if (win.mAppToken != null) {
2468 win.mAppToken.updateReportedVisibilityLocked();
2469 }
2470 //dump();
2471 Binder.restoreCallingIdentity(origId);
2472 return;
2473 }
2474 }
2475
2476 removeWindowInnerLocked(session, win);
2477 // Removing a visible window will effect the computed orientation
2478 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002479 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002480 != mForcedAppOrientation
2481 && updateOrientationFromAppTokensLocked()) {
2482 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 }
2484 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2485 Binder.restoreCallingIdentity(origId);
2486 }
Romain Guy06882f82009-06-10 13:36:04 -07002487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 if (mInputMethodTarget == win) {
2492 moveInputMethodWindowsIfNeededLocked(false);
2493 }
Romain Guy06882f82009-06-10 13:36:04 -07002494
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002495 if (false) {
2496 RuntimeException e = new RuntimeException("here");
2497 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002498 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002499 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 mPolicy.removeWindowLw(win);
2502 win.removeLocked();
2503
2504 mWindowMap.remove(win.mClient.asBinder());
2505 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002506 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002507 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508
2509 if (mInputMethodWindow == win) {
2510 mInputMethodWindow = null;
2511 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2512 mInputMethodDialogs.remove(win);
2513 }
Romain Guy06882f82009-06-10 13:36:04 -07002514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 final WindowToken token = win.mToken;
2516 final AppWindowToken atoken = win.mAppToken;
2517 token.windows.remove(win);
2518 if (atoken != null) {
2519 atoken.allAppWindows.remove(win);
2520 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002521 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 TAG, "**** Removing window " + win + ": count="
2523 + token.windows.size());
2524 if (token.windows.size() == 0) {
2525 if (!token.explicit) {
2526 mTokenMap.remove(token.token);
2527 mTokenList.remove(token);
2528 } else if (atoken != null) {
2529 atoken.firstWindowDrawn = false;
2530 }
2531 }
2532
2533 if (atoken != null) {
2534 if (atoken.startingWindow == win) {
2535 atoken.startingWindow = null;
2536 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2537 // If this is the last window and we had requested a starting
2538 // transition window, well there is no point now.
2539 atoken.startingData = null;
2540 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2541 // If this is the last window except for a starting transition
2542 // window, we need to get rid of the starting transition.
2543 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002544 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 + ": no more real windows");
2546 }
2547 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2548 mH.sendMessage(m);
2549 }
2550 }
Romain Guy06882f82009-06-10 13:36:04 -07002551
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002552 if (win.mAttrs.type == TYPE_WALLPAPER) {
2553 mLastWallpaperTimeoutTime = 0;
2554 adjustWallpaperWindowsLocked();
2555 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002556 adjustWallpaperWindowsLocked();
2557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 if (!mInLayout) {
2560 assignLayersLocked();
2561 mLayoutNeeded = true;
2562 performLayoutAndPlaceSurfacesLocked();
2563 if (win.mAppToken != null) {
2564 win.mAppToken.updateReportedVisibilityLocked();
2565 }
2566 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002567
2568 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 }
2570
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002571 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2572 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2573 + ": " + msg + " / " + w.mAttrs.getTitle();
2574 if (where != null) {
2575 Slog.i(TAG, str, where);
2576 } else {
2577 Slog.i(TAG, str);
2578 }
2579 }
2580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2582 long origId = Binder.clearCallingIdentity();
2583 try {
2584 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002585 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002587 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 Surface.openTransaction();
2589 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002590 if (SHOW_TRANSACTIONS) logSurface(w,
2591 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592 w.mSurface.setTransparentRegionHint(region);
2593 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002594 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 Surface.closeTransaction();
2596 }
2597 }
2598 }
2599 } finally {
2600 Binder.restoreCallingIdentity(origId);
2601 }
2602 }
2603
2604 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002605 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 Rect visibleInsets) {
2607 long origId = Binder.clearCallingIdentity();
2608 try {
2609 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002610 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 if (w != null) {
2612 w.mGivenInsetsPending = false;
2613 w.mGivenContentInsets.set(contentInsets);
2614 w.mGivenVisibleInsets.set(visibleInsets);
2615 w.mTouchableInsets = touchableInsets;
2616 mLayoutNeeded = true;
2617 performLayoutAndPlaceSurfacesLocked();
2618 }
2619 }
2620 } finally {
2621 Binder.restoreCallingIdentity(origId);
2622 }
2623 }
Romain Guy06882f82009-06-10 13:36:04 -07002624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 public void getWindowDisplayFrame(Session session, IWindow client,
2626 Rect outDisplayFrame) {
2627 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002628 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 if (win == null) {
2630 outDisplayFrame.setEmpty();
2631 return;
2632 }
2633 outDisplayFrame.set(win.mDisplayFrame);
2634 }
2635 }
2636
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002637 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2638 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002639 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2640 window.mWallpaperX = x;
2641 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002642 window.mWallpaperXStep = xStep;
2643 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002644 if (updateWallpaperOffsetLocked(window, true)) {
2645 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002646 }
2647 }
2648 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002649
Dianne Hackborn75804932009-10-20 20:15:20 -07002650 void wallpaperCommandComplete(IBinder window, Bundle result) {
2651 synchronized (mWindowMap) {
2652 if (mWaitingOnWallpaper != null &&
2653 mWaitingOnWallpaper.mClient.asBinder() == window) {
2654 mWaitingOnWallpaper = null;
2655 mWindowMap.notifyAll();
2656 }
2657 }
2658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002659
Dianne Hackborn75804932009-10-20 20:15:20 -07002660 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2661 String action, int x, int y, int z, Bundle extras, boolean sync) {
2662 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2663 || window == mUpperWallpaperTarget) {
2664 boolean doWait = sync;
2665 int curTokenIndex = mWallpaperTokens.size();
2666 while (curTokenIndex > 0) {
2667 curTokenIndex--;
2668 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2669 int curWallpaperIndex = token.windows.size();
2670 while (curWallpaperIndex > 0) {
2671 curWallpaperIndex--;
2672 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2673 try {
2674 wallpaper.mClient.dispatchWallpaperCommand(action,
2675 x, y, z, extras, sync);
2676 // We only want to be synchronous with one wallpaper.
2677 sync = false;
2678 } catch (RemoteException e) {
2679 }
2680 }
2681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002682
Dianne Hackborn75804932009-10-20 20:15:20 -07002683 if (doWait) {
2684 // XXX Need to wait for result.
2685 }
2686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002687
Dianne Hackborn75804932009-10-20 20:15:20 -07002688 return null;
2689 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 public int relayoutWindow(Session session, IWindow client,
2692 WindowManager.LayoutParams attrs, int requestedWidth,
2693 int requestedHeight, int viewVisibility, boolean insetsPending,
2694 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002695 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 boolean displayed = false;
2697 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002698 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002699 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002702 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002703 if (win == null) {
2704 return 0;
2705 }
2706 win.mRequestedWidth = requestedWidth;
2707 win.mRequestedHeight = requestedHeight;
2708
2709 if (attrs != null) {
2710 mPolicy.adjustWindowParamsLw(attrs);
2711 }
Romain Guy06882f82009-06-10 13:36:04 -07002712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 int attrChanges = 0;
2714 int flagChanges = 0;
2715 if (attrs != null) {
2716 flagChanges = win.mAttrs.flags ^= attrs.flags;
2717 attrChanges = win.mAttrs.copyFrom(attrs);
2718 }
2719
Joe Onorato8a9b2202010-02-26 18:56:32 -08002720 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002721
2722 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2723 win.mAlpha = attrs.alpha;
2724 }
2725
2726 final boolean scaledWindow =
2727 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2728
2729 if (scaledWindow) {
2730 // requested{Width|Height} Surface's physical size
2731 // attrs.{width|height} Size on screen
2732 win.mHScale = (attrs.width != requestedWidth) ?
2733 (attrs.width / (float)requestedWidth) : 1.0f;
2734 win.mVScale = (attrs.height != requestedHeight) ?
2735 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002736 } else {
2737 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 }
2739
2740 boolean imMayMove = (flagChanges&(
2741 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2742 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002744 boolean focusMayChange = win.mViewVisibility != viewVisibility
2745 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2746 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002747
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002748 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2749 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 win.mRelayoutCalled = true;
2752 final int oldVisibility = win.mViewVisibility;
2753 win.mViewVisibility = viewVisibility;
2754 if (viewVisibility == View.VISIBLE &&
2755 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2756 displayed = !win.isVisibleLw();
2757 if (win.mExiting) {
2758 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002759 if (win.mAnimation != null) {
2760 win.mAnimation.cancel();
2761 win.mAnimation = null;
2762 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 }
2764 if (win.mDestroying) {
2765 win.mDestroying = false;
2766 mDestroySurface.remove(win);
2767 }
2768 if (oldVisibility == View.GONE) {
2769 win.mEnterAnimationPending = true;
2770 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002771 if (displayed) {
2772 if (win.mSurface != null && !win.mDrawPending
2773 && !win.mCommitDrawPending && !mDisplayFrozen
2774 && mPolicy.isScreenOn()) {
2775 applyEnterAnimationLocked(win);
2776 }
2777 if ((win.mAttrs.flags
2778 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2779 if (DEBUG_VISIBILITY) Slog.v(TAG,
2780 "Relayout window turning screen on: " + win);
2781 win.mTurnOnScreen = true;
2782 }
2783 int diff = 0;
2784 if (win.mConfiguration != mCurConfiguration
2785 && (win.mConfiguration == null
2786 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2787 win.mConfiguration = mCurConfiguration;
2788 if (DEBUG_CONFIGURATION) {
2789 Slog.i(TAG, "Window " + win + " visible with new config: "
2790 + win.mConfiguration + " / 0x"
2791 + Integer.toHexString(diff));
2792 }
2793 outConfig.setTo(mCurConfiguration);
2794 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002795 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2797 // To change the format, we need to re-build the surface.
2798 win.destroySurfaceLocked();
2799 displayed = true;
2800 }
2801 try {
2802 Surface surface = win.createSurfaceLocked();
2803 if (surface != null) {
2804 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002805 win.mReportDestroySurface = false;
2806 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002807 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002808 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002810 // For some reason there isn't a surface. Clear the
2811 // caller's object so they see the same state.
2812 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 }
2814 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002815 mInputMonitor.updateInputWindowsLw();
2816
Joe Onorato8a9b2202010-02-26 18:56:32 -08002817 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002818 + client + " (" + win.mAttrs.getTitle() + ")",
2819 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 Binder.restoreCallingIdentity(origId);
2821 return 0;
2822 }
2823 if (displayed) {
2824 focusMayChange = true;
2825 }
2826 if (win.mAttrs.type == TYPE_INPUT_METHOD
2827 && mInputMethodWindow == null) {
2828 mInputMethodWindow = win;
2829 imMayMove = true;
2830 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002831 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2832 && win.mAppToken != null
2833 && win.mAppToken.startingWindow != null) {
2834 // Special handling of starting window over the base
2835 // window of the app: propagate lock screen flags to it,
2836 // to provide the correct semantics while starting.
2837 final int mask =
2838 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002839 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2840 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002841 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2842 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2843 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 } else {
2845 win.mEnterAnimationPending = false;
2846 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002847 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002848 + ": mExiting=" + win.mExiting
2849 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 // If we are not currently running the exit animation, we
2851 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002852 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 // Try starting an animation; if there isn't one, we
2854 // can destroy the surface right away.
2855 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2856 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2857 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2858 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002859 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002861 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 } else if (win.isAnimating()) {
2864 // Currently in a hide animation... turn this into
2865 // an exit.
2866 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002867 } else if (win == mWallpaperTarget) {
2868 // If the wallpaper is currently behind this
2869 // window, we need to change both of them inside
2870 // of a transaction to avoid artifacts.
2871 win.mExiting = true;
2872 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 } else {
2874 if (mInputMethodWindow == win) {
2875 mInputMethodWindow = null;
2876 }
2877 win.destroySurfaceLocked();
2878 }
2879 }
2880 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002881
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002882 if (win.mSurface == null || (win.getAttrs().flags
2883 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2884 || win.mSurfacePendingDestroy) {
2885 // We are being called from a local process, which
2886 // means outSurface holds its current surface. Ensure the
2887 // surface object is cleared, but we don't want it actually
2888 // destroyed at this point.
2889 win.mSurfacePendingDestroy = false;
2890 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002891 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002892 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002893 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002894 "Keeping surface, will report destroy: " + win);
2895 win.mReportDestroySurface = true;
2896 outSurface.copyFrom(win.mSurface);
2897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 }
2899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 if (focusMayChange) {
2901 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2902 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 imMayMove = false;
2904 }
2905 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2906 }
Romain Guy06882f82009-06-10 13:36:04 -07002907
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002908 // updateFocusedWindowLocked() already assigned layers so we only need to
2909 // reassign them at this point if the IM window state gets shuffled
2910 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002913 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2914 // Little hack here -- we -should- be able to rely on the
2915 // function to return true if the IME has moved and needs
2916 // its layer recomputed. However, if the IME was hidden
2917 // and isn't actually moved in the list, its layer may be
2918 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 assignLayers = true;
2920 }
2921 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002922 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002923 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002924 assignLayers = true;
2925 }
2926 }
Romain Guy06882f82009-06-10 13:36:04 -07002927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 mLayoutNeeded = true;
2929 win.mGivenInsetsPending = insetsPending;
2930 if (assignLayers) {
2931 assignLayersLocked();
2932 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002933 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002935 if (displayed && win.mIsWallpaper) {
2936 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002937 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 if (win.mAppToken != null) {
2940 win.mAppToken.updateReportedVisibilityLocked();
2941 }
2942 outFrame.set(win.mFrame);
2943 outContentInsets.set(win.mContentInsets);
2944 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002945 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002947 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 + ", requestedHeight=" + requestedHeight
2949 + ", viewVisibility=" + viewVisibility
2950 + "\nRelayout returning frame=" + outFrame
2951 + ", surface=" + outSurface);
2952
Joe Onorato8a9b2202010-02-26 18:56:32 -08002953 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2955
2956 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002957
2958 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 }
2960
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002961 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 sendNewConfiguration();
2963 }
Romain Guy06882f82009-06-10 13:36:04 -07002964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2968 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2969 }
2970
2971 public void finishDrawingWindow(Session session, IWindow client) {
2972 final long origId = Binder.clearCallingIdentity();
2973 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002974 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002976 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2977 adjustWallpaperWindowsLocked();
2978 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 mLayoutNeeded = true;
2980 performLayoutAndPlaceSurfacesLocked();
2981 }
2982 }
2983 Binder.restoreCallingIdentity(origId);
2984 }
2985
2986 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002987 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 + (lp != null ? lp.packageName : null)
2989 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2990 if (lp != null && lp.windowAnimations != 0) {
2991 // If this is a system resource, don't try to load it from the
2992 // application resources. It is nice to avoid loading application
2993 // resources if we can.
2994 String packageName = lp.packageName != null ? lp.packageName : "android";
2995 int resId = lp.windowAnimations;
2996 if ((resId&0xFF000000) == 0x01000000) {
2997 packageName = "android";
2998 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002999 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003000 + packageName);
3001 return AttributeCache.instance().get(packageName, resId,
3002 com.android.internal.R.styleable.WindowAnimation);
3003 }
3004 return null;
3005 }
Romain Guy06882f82009-06-10 13:36:04 -07003006
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003007 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003008 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003009 + packageName + " resId=0x" + Integer.toHexString(resId));
3010 if (packageName != null) {
3011 if ((resId&0xFF000000) == 0x01000000) {
3012 packageName = "android";
3013 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003014 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003015 + packageName);
3016 return AttributeCache.instance().get(packageName, resId,
3017 com.android.internal.R.styleable.WindowAnimation);
3018 }
3019 return null;
3020 }
3021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 private void applyEnterAnimationLocked(WindowState win) {
3023 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3024 if (win.mEnterAnimationPending) {
3025 win.mEnterAnimationPending = false;
3026 transit = WindowManagerPolicy.TRANSIT_ENTER;
3027 }
3028
3029 applyAnimationLocked(win, transit, true);
3030 }
3031
3032 private boolean applyAnimationLocked(WindowState win,
3033 int transit, boolean isEntrance) {
3034 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3035 // If we are trying to apply an animation, but already running
3036 // an animation of the same type, then just leave that one alone.
3037 return true;
3038 }
Romain Guy06882f82009-06-10 13:36:04 -07003039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 // Only apply an animation if the display isn't frozen. If it is
3041 // frozen, there is no reason to animate and it can cause strange
3042 // artifacts when we unfreeze the display if some different animation
3043 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003044 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003045 int anim = mPolicy.selectAnimationLw(win, transit);
3046 int attr = -1;
3047 Animation a = null;
3048 if (anim != 0) {
3049 a = AnimationUtils.loadAnimation(mContext, anim);
3050 } else {
3051 switch (transit) {
3052 case WindowManagerPolicy.TRANSIT_ENTER:
3053 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3054 break;
3055 case WindowManagerPolicy.TRANSIT_EXIT:
3056 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3057 break;
3058 case WindowManagerPolicy.TRANSIT_SHOW:
3059 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3060 break;
3061 case WindowManagerPolicy.TRANSIT_HIDE:
3062 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3063 break;
3064 }
3065 if (attr >= 0) {
3066 a = loadAnimation(win.mAttrs, attr);
3067 }
3068 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003069 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3071 + " mAnimation=" + win.mAnimation
3072 + " isEntrance=" + isEntrance);
3073 if (a != null) {
3074 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003075 RuntimeException e = null;
3076 if (!HIDE_STACK_CRAWLS) {
3077 e = new RuntimeException();
3078 e.fillInStackTrace();
3079 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003080 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 }
3082 win.setAnimation(a);
3083 win.mAnimationIsEntrance = isEntrance;
3084 }
3085 } else {
3086 win.clearAnimation();
3087 }
3088
3089 return win.mAnimation != null;
3090 }
3091
3092 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3093 int anim = 0;
3094 Context context = mContext;
3095 if (animAttr >= 0) {
3096 AttributeCache.Entry ent = getCachedAnimations(lp);
3097 if (ent != null) {
3098 context = ent.context;
3099 anim = ent.array.getResourceId(animAttr, 0);
3100 }
3101 }
3102 if (anim != 0) {
3103 return AnimationUtils.loadAnimation(context, anim);
3104 }
3105 return null;
3106 }
Romain Guy06882f82009-06-10 13:36:04 -07003107
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003108 private Animation loadAnimation(String packageName, int resId) {
3109 int anim = 0;
3110 Context context = mContext;
3111 if (resId >= 0) {
3112 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3113 if (ent != null) {
3114 context = ent.context;
3115 anim = resId;
3116 }
3117 }
3118 if (anim != 0) {
3119 return AnimationUtils.loadAnimation(context, anim);
3120 }
3121 return null;
3122 }
3123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003124 private boolean applyAnimationLocked(AppWindowToken wtoken,
3125 WindowManager.LayoutParams lp, int transit, boolean enter) {
3126 // Only apply an animation if the display isn't frozen. If it is
3127 // frozen, there is no reason to animate and it can cause strange
3128 // artifacts when we unfreeze the display if some different animation
3129 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003130 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003131 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003132 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003133 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003134 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003135 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003136 } else if (mNextAppTransitionPackage != null) {
3137 a = loadAnimation(mNextAppTransitionPackage, enter ?
3138 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003139 } else {
3140 int animAttr = 0;
3141 switch (transit) {
3142 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3143 animAttr = enter
3144 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3145 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3146 break;
3147 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3148 animAttr = enter
3149 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3150 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3151 break;
3152 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3153 animAttr = enter
3154 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3155 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3156 break;
3157 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3158 animAttr = enter
3159 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3160 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3161 break;
3162 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3163 animAttr = enter
3164 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3165 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3166 break;
3167 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3168 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003169 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003170 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3171 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003172 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003173 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003174 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3175 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003176 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003177 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003178 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003179 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3180 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3181 break;
3182 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3183 animAttr = enter
3184 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3185 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3186 break;
3187 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3188 animAttr = enter
3189 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3190 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003191 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003192 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003193 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003194 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003195 + " anim=" + a
3196 + " animAttr=0x" + Integer.toHexString(animAttr)
3197 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 if (a != null) {
3200 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003201 RuntimeException e = null;
3202 if (!HIDE_STACK_CRAWLS) {
3203 e = new RuntimeException();
3204 e.fillInStackTrace();
3205 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003206 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 }
3208 wtoken.setAnimation(a);
3209 }
3210 } else {
3211 wtoken.clearAnimation();
3212 }
3213
3214 return wtoken.animation != null;
3215 }
3216
3217 // -------------------------------------------------------------
3218 // Application Window Tokens
3219 // -------------------------------------------------------------
3220
3221 public void validateAppTokens(List tokens) {
3222 int v = tokens.size()-1;
3223 int m = mAppTokens.size()-1;
3224 while (v >= 0 && m >= 0) {
3225 AppWindowToken wtoken = mAppTokens.get(m);
3226 if (wtoken.removed) {
3227 m--;
3228 continue;
3229 }
3230 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003231 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3233 }
3234 v--;
3235 m--;
3236 }
3237 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003238 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 v--;
3240 }
3241 while (m >= 0) {
3242 AppWindowToken wtoken = mAppTokens.get(m);
3243 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003244 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 }
3246 m--;
3247 }
3248 }
3249
3250 boolean checkCallingPermission(String permission, String func) {
3251 // Quick check: if the calling permission is me, it's all okay.
3252 if (Binder.getCallingPid() == Process.myPid()) {
3253 return true;
3254 }
Romain Guy06882f82009-06-10 13:36:04 -07003255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 if (mContext.checkCallingPermission(permission)
3257 == PackageManager.PERMISSION_GRANTED) {
3258 return true;
3259 }
3260 String msg = "Permission Denial: " + func + " from pid="
3261 + Binder.getCallingPid()
3262 + ", uid=" + Binder.getCallingUid()
3263 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003264 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 return false;
3266 }
Romain Guy06882f82009-06-10 13:36:04 -07003267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 AppWindowToken findAppWindowToken(IBinder token) {
3269 WindowToken wtoken = mTokenMap.get(token);
3270 if (wtoken == null) {
3271 return null;
3272 }
3273 return wtoken.appWindowToken;
3274 }
Romain Guy06882f82009-06-10 13:36:04 -07003275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 public void addWindowToken(IBinder token, int type) {
3277 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3278 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003279 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 }
Romain Guy06882f82009-06-10 13:36:04 -07003281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003282 synchronized(mWindowMap) {
3283 WindowToken wtoken = mTokenMap.get(token);
3284 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003285 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 return;
3287 }
3288 wtoken = new WindowToken(token, type, true);
3289 mTokenMap.put(token, wtoken);
3290 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003291 if (type == TYPE_WALLPAPER) {
3292 mWallpaperTokens.add(wtoken);
3293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 }
3295 }
Romain Guy06882f82009-06-10 13:36:04 -07003296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 public void removeWindowToken(IBinder token) {
3298 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3299 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003300 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 }
3302
3303 final long origId = Binder.clearCallingIdentity();
3304 synchronized(mWindowMap) {
3305 WindowToken wtoken = mTokenMap.remove(token);
3306 mTokenList.remove(wtoken);
3307 if (wtoken != null) {
3308 boolean delayed = false;
3309 if (!wtoken.hidden) {
3310 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 final int N = wtoken.windows.size();
3313 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 for (int i=0; i<N; i++) {
3316 WindowState win = wtoken.windows.get(i);
3317
3318 if (win.isAnimating()) {
3319 delayed = true;
3320 }
Romain Guy06882f82009-06-10 13:36:04 -07003321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 if (win.isVisibleNow()) {
3323 applyAnimationLocked(win,
3324 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 changed = true;
3326 }
3327 }
3328
3329 if (changed) {
3330 mLayoutNeeded = true;
3331 performLayoutAndPlaceSurfacesLocked();
3332 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3333 }
Romain Guy06882f82009-06-10 13:36:04 -07003334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 if (delayed) {
3336 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003337 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3338 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 }
3340 }
Romain Guy06882f82009-06-10 13:36:04 -07003341
Jeff Brownc5ed5912010-07-14 18:48:53 -07003342 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003344 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 }
3346 }
3347 Binder.restoreCallingIdentity(origId);
3348 }
3349
3350 public void addAppToken(int addPos, IApplicationToken token,
3351 int groupId, int requestedOrientation, boolean fullscreen) {
3352 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3353 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003354 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 }
Jeff Brown349703e2010-06-22 01:27:15 -07003356
3357 // Get the dispatching timeout here while we are not holding any locks so that it
3358 // can be cached by the AppWindowToken. The timeout value is used later by the
3359 // input dispatcher in code that does hold locks. If we did not cache the value
3360 // here we would run the chance of introducing a deadlock between the window manager
3361 // (which holds locks while updating the input dispatcher state) and the activity manager
3362 // (which holds locks while querying the application token).
3363 long inputDispatchingTimeoutNanos;
3364 try {
3365 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3366 } catch (RemoteException ex) {
3367 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3368 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3369 }
Romain Guy06882f82009-06-10 13:36:04 -07003370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 synchronized(mWindowMap) {
3372 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3373 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003374 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 return;
3376 }
3377 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003378 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 wtoken.groupId = groupId;
3380 wtoken.appFullscreen = fullscreen;
3381 wtoken.requestedOrientation = requestedOrientation;
3382 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003383 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 mTokenMap.put(token.asBinder(), wtoken);
3385 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 // Application tokens start out hidden.
3388 wtoken.hidden = true;
3389 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003391 //dump();
3392 }
3393 }
Romain Guy06882f82009-06-10 13:36:04 -07003394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 public void setAppGroupId(IBinder token, int groupId) {
3396 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3397 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003398 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 }
3400
3401 synchronized(mWindowMap) {
3402 AppWindowToken wtoken = findAppWindowToken(token);
3403 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003404 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 return;
3406 }
3407 wtoken.groupId = groupId;
3408 }
3409 }
Romain Guy06882f82009-06-10 13:36:04 -07003410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 public int getOrientationFromWindowsLocked() {
3412 int pos = mWindows.size() - 1;
3413 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003414 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 pos--;
3416 if (wtoken.mAppToken != null) {
3417 // We hit an application window. so the orientation will be determined by the
3418 // app window. No point in continuing further.
3419 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3420 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003421 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 continue;
3423 }
3424 int req = wtoken.mAttrs.screenOrientation;
3425 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3426 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3427 continue;
3428 } else {
3429 return req;
3430 }
3431 }
3432 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3433 }
Romain Guy06882f82009-06-10 13:36:04 -07003434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003436 int pos = mAppTokens.size() - 1;
3437 int curGroup = 0;
3438 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3439 boolean findingBehind = false;
3440 boolean haveGroup = false;
3441 boolean lastFullscreen = false;
3442 while (pos >= 0) {
3443 AppWindowToken wtoken = mAppTokens.get(pos);
3444 pos--;
3445 // if we're about to tear down this window and not seek for
3446 // the behind activity, don't use it for orientation
3447 if (!findingBehind
3448 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3449 continue;
3450 }
3451
3452 if (!haveGroup) {
3453 // We ignore any hidden applications on the top.
3454 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003455 continue;
3456 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003457 haveGroup = true;
3458 curGroup = wtoken.groupId;
3459 lastOrientation = wtoken.requestedOrientation;
3460 } else if (curGroup != wtoken.groupId) {
3461 // If we have hit a new application group, and the bottom
3462 // of the previous group didn't explicitly say to use
3463 // the orientation behind it, and the last app was
3464 // full screen, then we'll stick with the
3465 // user's orientation.
3466 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3467 && lastFullscreen) {
3468 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003471 int or = wtoken.requestedOrientation;
3472 // If this application is fullscreen, and didn't explicitly say
3473 // to use the orientation behind it, then just take whatever
3474 // orientation it has and ignores whatever is under it.
3475 lastFullscreen = wtoken.appFullscreen;
3476 if (lastFullscreen
3477 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3478 return or;
3479 }
3480 // If this application has requested an explicit orientation,
3481 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003482 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3483 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003484 return or;
3485 }
3486 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3487 }
3488 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489 }
Romain Guy06882f82009-06-10 13:36:04 -07003490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003491 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003492 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003493 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3494 "updateOrientationFromAppTokens()")) {
3495 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3496 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003497
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003498 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003499 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003500
3501 synchronized(mWindowMap) {
3502 if (updateOrientationFromAppTokensLocked()) {
3503 if (freezeThisOneIfNeeded != null) {
3504 AppWindowToken wtoken = findAppWindowToken(
3505 freezeThisOneIfNeeded);
3506 if (wtoken != null) {
3507 startAppFreezingScreenLocked(wtoken,
3508 ActivityInfo.CONFIG_ORIENTATION);
3509 }
3510 }
3511 config = computeNewConfigurationLocked();
3512
3513 } else if (currentConfig != null) {
3514 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003515 // state mismatches the activity manager's, update it,
3516 // disregarding font scale, which should remain set to
3517 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003518 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003519 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003520 if (computeNewConfigurationLocked(mTempConfiguration)) {
3521 if (currentConfig.diff(mTempConfiguration) != 0) {
3522 mWaitingForConfig = true;
3523 mLayoutNeeded = true;
3524 startFreezingDisplayLocked();
3525 config = new Configuration(mTempConfiguration);
3526 }
3527 }
3528 }
3529 }
3530
Dianne Hackborncfaef692009-06-15 14:24:44 -07003531 Binder.restoreCallingIdentity(ident);
3532 return config;
3533 }
3534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003536 * Determine the new desired orientation of the display, returning
3537 * a non-null new Configuration if it has changed from the current
3538 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3539 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3540 * SCREEN. This will typically be done for you if you call
3541 * sendNewConfiguration().
3542 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 * The orientation is computed from non-application windows first. If none of
3544 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003545 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3547 * android.os.IBinder)
3548 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003549 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003550 if (mDisplayFrozen) {
3551 // If the display is frozen, some activities may be in the middle
3552 // of restarting, and thus have removed their old window. If the
3553 // window has the flag to hide the lock screen, then the lock screen
3554 // can re-appear and inflict its own orientation on us. Keep the
3555 // orientation stable until this all settles down.
3556 return false;
3557 }
3558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 long ident = Binder.clearCallingIdentity();
3561 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003562 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003565 mForcedAppOrientation = req;
3566 //send a message to Policy indicating orientation change to take
3567 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003568 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003569 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3570 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3571 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 }
3573 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003574
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003575 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 } finally {
3577 Binder.restoreCallingIdentity(ident);
3578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 }
Romain Guy06882f82009-06-10 13:36:04 -07003580
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003581 int computeForcedAppOrientationLocked() {
3582 int req = getOrientationFromWindowsLocked();
3583 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3584 req = getOrientationFromAppTokensLocked();
3585 }
3586 return req;
3587 }
Romain Guy06882f82009-06-10 13:36:04 -07003588
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003589 public void setNewConfiguration(Configuration config) {
3590 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3591 "setNewConfiguration()")) {
3592 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3593 }
3594
3595 synchronized(mWindowMap) {
3596 mCurConfiguration = new Configuration(config);
3597 mWaitingForConfig = false;
3598 performLayoutAndPlaceSurfacesLocked();
3599 }
3600 }
3601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3603 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3604 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003605 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 }
Romain Guy06882f82009-06-10 13:36:04 -07003607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 synchronized(mWindowMap) {
3609 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3610 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003611 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 return;
3613 }
Romain Guy06882f82009-06-10 13:36:04 -07003614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 wtoken.requestedOrientation = requestedOrientation;
3616 }
3617 }
Romain Guy06882f82009-06-10 13:36:04 -07003618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 public int getAppOrientation(IApplicationToken token) {
3620 synchronized(mWindowMap) {
3621 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3622 if (wtoken == null) {
3623 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3624 }
Romain Guy06882f82009-06-10 13:36:04 -07003625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 return wtoken.requestedOrientation;
3627 }
3628 }
Romain Guy06882f82009-06-10 13:36:04 -07003629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3631 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3632 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003633 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 }
3635
3636 synchronized(mWindowMap) {
3637 boolean changed = false;
3638 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003639 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 changed = mFocusedApp != null;
3641 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003642 if (changed) {
3643 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003644 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003645 } else {
3646 AppWindowToken newFocus = findAppWindowToken(token);
3647 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003648 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 return;
3650 }
3651 changed = mFocusedApp != newFocus;
3652 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003653 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003654 if (changed) {
3655 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 }
3658
3659 if (moveFocusNow && changed) {
3660 final long origId = Binder.clearCallingIdentity();
3661 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3662 Binder.restoreCallingIdentity(origId);
3663 }
3664 }
3665 }
3666
3667 public void prepareAppTransition(int transit) {
3668 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3669 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003670 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 }
Romain Guy06882f82009-06-10 13:36:04 -07003672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003674 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 TAG, "Prepare app transition: transit=" + transit
3676 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003677 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003678 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3679 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003681 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3682 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3683 // Opening a new task always supersedes a close for the anim.
3684 mNextAppTransition = transit;
3685 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3686 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3687 // Opening a new activity always supersedes a close for the anim.
3688 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003689 }
3690 mAppTransitionReady = false;
3691 mAppTransitionTimeout = false;
3692 mStartingIconInTransition = false;
3693 mSkipAppTransitionAnimation = false;
3694 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3695 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3696 5000);
3697 }
3698 }
3699 }
3700
3701 public int getPendingAppTransition() {
3702 return mNextAppTransition;
3703 }
Romain Guy06882f82009-06-10 13:36:04 -07003704
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003705 public void overridePendingAppTransition(String packageName,
3706 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003707 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003708 mNextAppTransitionPackage = packageName;
3709 mNextAppTransitionEnter = enterAnim;
3710 mNextAppTransitionExit = exitAnim;
3711 }
3712 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 public void executeAppTransition() {
3715 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3716 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003717 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 }
Romain Guy06882f82009-06-10 13:36:04 -07003719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003721 if (DEBUG_APP_TRANSITIONS) {
3722 RuntimeException e = new RuntimeException("here");
3723 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003724 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003725 + mNextAppTransition, e);
3726 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003727 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 mAppTransitionReady = true;
3729 final long origId = Binder.clearCallingIdentity();
3730 performLayoutAndPlaceSurfacesLocked();
3731 Binder.restoreCallingIdentity(origId);
3732 }
3733 }
3734 }
3735
3736 public void setAppStartingWindow(IBinder token, String pkg,
3737 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003738 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3740 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003741 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 }
3743
3744 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003745 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3747 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 AppWindowToken wtoken = findAppWindowToken(token);
3750 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003751 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 return;
3753 }
3754
3755 // If the display is frozen, we won't do anything until the
3756 // actual window is displayed so there is no reason to put in
3757 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003758 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 return;
3760 }
Romain Guy06882f82009-06-10 13:36:04 -07003761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 if (wtoken.startingData != null) {
3763 return;
3764 }
Romain Guy06882f82009-06-10 13:36:04 -07003765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 if (transferFrom != null) {
3767 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3768 if (ttoken != null) {
3769 WindowState startingWindow = ttoken.startingWindow;
3770 if (startingWindow != null) {
3771 if (mStartingIconInTransition) {
3772 // In this case, the starting icon has already
3773 // been displayed, so start letting windows get
3774 // shown immediately without any more transitions.
3775 mSkipAppTransitionAnimation = true;
3776 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003777 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 "Moving existing starting from " + ttoken
3779 + " to " + wtoken);
3780 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 // Transfer the starting window over to the new
3783 // token.
3784 wtoken.startingData = ttoken.startingData;
3785 wtoken.startingView = ttoken.startingView;
3786 wtoken.startingWindow = startingWindow;
3787 ttoken.startingData = null;
3788 ttoken.startingView = null;
3789 ttoken.startingWindow = null;
3790 ttoken.startingMoved = true;
3791 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003792 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003794 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003795 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003797 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 ttoken.windows.remove(startingWindow);
3799 ttoken.allAppWindows.remove(startingWindow);
3800 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 // Propagate other interesting state between the
3803 // tokens. If the old token is displayed, we should
3804 // immediately force the new one to be displayed. If
3805 // it is animating, we need to move that animation to
3806 // the new one.
3807 if (ttoken.allDrawn) {
3808 wtoken.allDrawn = true;
3809 }
3810 if (ttoken.firstWindowDrawn) {
3811 wtoken.firstWindowDrawn = true;
3812 }
3813 if (!ttoken.hidden) {
3814 wtoken.hidden = false;
3815 wtoken.hiddenRequested = false;
3816 wtoken.willBeHidden = false;
3817 }
3818 if (wtoken.clientHidden != ttoken.clientHidden) {
3819 wtoken.clientHidden = ttoken.clientHidden;
3820 wtoken.sendAppVisibilityToClients();
3821 }
3822 if (ttoken.animation != null) {
3823 wtoken.animation = ttoken.animation;
3824 wtoken.animating = ttoken.animating;
3825 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3826 ttoken.animation = null;
3827 ttoken.animLayerAdjustment = 0;
3828 wtoken.updateLayers();
3829 ttoken.updateLayers();
3830 }
Romain Guy06882f82009-06-10 13:36:04 -07003831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 mLayoutNeeded = true;
3834 performLayoutAndPlaceSurfacesLocked();
3835 Binder.restoreCallingIdentity(origId);
3836 return;
3837 } else if (ttoken.startingData != null) {
3838 // The previous app was getting ready to show a
3839 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003840 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 "Moving pending starting from " + ttoken
3842 + " to " + wtoken);
3843 wtoken.startingData = ttoken.startingData;
3844 ttoken.startingData = null;
3845 ttoken.startingMoved = true;
3846 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3847 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3848 // want to process the message ASAP, before any other queued
3849 // messages.
3850 mH.sendMessageAtFrontOfQueue(m);
3851 return;
3852 }
3853 }
3854 }
3855
3856 // There is no existing starting window, and the caller doesn't
3857 // want us to create one, so that's it!
3858 if (!createIfNeeded) {
3859 return;
3860 }
Romain Guy06882f82009-06-10 13:36:04 -07003861
Dianne Hackborn284ac932009-08-28 10:34:25 -07003862 // If this is a translucent or wallpaper window, then don't
3863 // show a starting window -- the current effect (a full-screen
3864 // opaque starting window that fades away to the real contents
3865 // when it is ready) does not work for this.
3866 if (theme != 0) {
3867 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3868 com.android.internal.R.styleable.Window);
3869 if (ent.array.getBoolean(
3870 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3871 return;
3872 }
3873 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003874 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3875 return;
3876 }
3877 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003878 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3879 return;
3880 }
3881 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 mStartingIconInTransition = true;
3884 wtoken.startingData = new StartingData(
3885 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003886 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003887 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3888 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3889 // want to process the message ASAP, before any other queued
3890 // messages.
3891 mH.sendMessageAtFrontOfQueue(m);
3892 }
3893 }
3894
3895 public void setAppWillBeHidden(IBinder token) {
3896 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3897 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003898 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 }
3900
3901 AppWindowToken wtoken;
3902
3903 synchronized(mWindowMap) {
3904 wtoken = findAppWindowToken(token);
3905 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 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 -08003907 return;
3908 }
3909 wtoken.willBeHidden = true;
3910 }
3911 }
Romain Guy06882f82009-06-10 13:36:04 -07003912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003913 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3914 boolean visible, int transit, boolean performLayout) {
3915 boolean delayed = false;
3916
3917 if (wtoken.clientHidden == visible) {
3918 wtoken.clientHidden = !visible;
3919 wtoken.sendAppVisibilityToClients();
3920 }
Romain Guy06882f82009-06-10 13:36:04 -07003921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922 wtoken.willBeHidden = false;
3923 if (wtoken.hidden == visible) {
3924 final int N = wtoken.allAppWindows.size();
3925 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003926 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3928 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003931
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003932 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 if (wtoken.animation == sDummyAnimation) {
3934 wtoken.animation = null;
3935 }
3936 applyAnimationLocked(wtoken, lp, transit, visible);
3937 changed = true;
3938 if (wtoken.animation != null) {
3939 delayed = runningAppAnimation = true;
3940 }
3941 }
Romain Guy06882f82009-06-10 13:36:04 -07003942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 for (int i=0; i<N; i++) {
3944 WindowState win = wtoken.allAppWindows.get(i);
3945 if (win == wtoken.startingWindow) {
3946 continue;
3947 }
3948
3949 if (win.isAnimating()) {
3950 delayed = true;
3951 }
Romain Guy06882f82009-06-10 13:36:04 -07003952
Joe Onorato8a9b2202010-02-26 18:56:32 -08003953 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 //win.dump(" ");
3955 if (visible) {
3956 if (!win.isVisibleNow()) {
3957 if (!runningAppAnimation) {
3958 applyAnimationLocked(win,
3959 WindowManagerPolicy.TRANSIT_ENTER, true);
3960 }
3961 changed = true;
3962 }
3963 } else if (win.isVisibleNow()) {
3964 if (!runningAppAnimation) {
3965 applyAnimationLocked(win,
3966 WindowManagerPolicy.TRANSIT_EXIT, false);
3967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003968 changed = true;
3969 }
3970 }
3971
3972 wtoken.hidden = wtoken.hiddenRequested = !visible;
3973 if (!visible) {
3974 unsetAppFreezingScreenLocked(wtoken, true, true);
3975 } else {
3976 // If we are being set visible, and the starting window is
3977 // not yet displayed, then make sure it doesn't get displayed.
3978 WindowState swin = wtoken.startingWindow;
3979 if (swin != null && (swin.mDrawPending
3980 || swin.mCommitDrawPending)) {
3981 swin.mPolicyVisibility = false;
3982 swin.mPolicyVisibilityAfterAnim = false;
3983 }
3984 }
Romain Guy06882f82009-06-10 13:36:04 -07003985
Joe Onorato8a9b2202010-02-26 18:56:32 -08003986 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3988 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003989
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003990 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003991 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003992 if (performLayout) {
3993 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3994 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003995 } else {
3996 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003997 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 }
3999 }
4000
4001 if (wtoken.animation != null) {
4002 delayed = true;
4003 }
Romain Guy06882f82009-06-10 13:36:04 -07004004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 return delayed;
4006 }
4007
4008 public void setAppVisibility(IBinder token, boolean visible) {
4009 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4010 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004011 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 }
4013
4014 AppWindowToken wtoken;
4015
4016 synchronized(mWindowMap) {
4017 wtoken = findAppWindowToken(token);
4018 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004019 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 return;
4021 }
4022
4023 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004024 RuntimeException e = null;
4025 if (!HIDE_STACK_CRAWLS) {
4026 e = new RuntimeException();
4027 e.fillInStackTrace();
4028 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004029 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 + "): mNextAppTransition=" + mNextAppTransition
4031 + " hidden=" + wtoken.hidden
4032 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4033 }
Romain Guy06882f82009-06-10 13:36:04 -07004034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 // If we are preparing an app transition, then delay changing
4036 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004037 if (!mDisplayFrozen && mPolicy.isScreenOn()
4038 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004039 // Already in requested state, don't do anything more.
4040 if (wtoken.hiddenRequested != visible) {
4041 return;
4042 }
4043 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004044
Joe Onorato8a9b2202010-02-26 18:56:32 -08004045 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004046 TAG, "Setting dummy animation on: " + wtoken);
4047 wtoken.setDummyAnimation();
4048 mOpeningApps.remove(wtoken);
4049 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004050 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004051 wtoken.inPendingTransaction = true;
4052 if (visible) {
4053 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 wtoken.startingDisplayed = false;
4055 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004056
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004057 // If the token is currently hidden (should be the
4058 // common case), then we need to set up to wait for
4059 // its windows to be ready.
4060 if (wtoken.hidden) {
4061 wtoken.allDrawn = false;
4062 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004063
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004064 if (wtoken.clientHidden) {
4065 // In the case where we are making an app visible
4066 // but holding off for a transition, we still need
4067 // to tell the client to make its windows visible so
4068 // they get drawn. Otherwise, we will wait on
4069 // performing the transition until all windows have
4070 // been drawn, they never will be, and we are sad.
4071 wtoken.clientHidden = false;
4072 wtoken.sendAppVisibilityToClients();
4073 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004074 }
4075 } else {
4076 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004077
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004078 // If the token is currently visible (should be the
4079 // common case), then set up to wait for it to be hidden.
4080 if (!wtoken.hidden) {
4081 wtoken.waitingToHide = true;
4082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 }
4084 return;
4085 }
Romain Guy06882f82009-06-10 13:36:04 -07004086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004087 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004088 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004089 wtoken.updateReportedVisibilityLocked();
4090 Binder.restoreCallingIdentity(origId);
4091 }
4092 }
4093
4094 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4095 boolean unfreezeSurfaceNow, boolean force) {
4096 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004097 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 + " force=" + force);
4099 final int N = wtoken.allAppWindows.size();
4100 boolean unfrozeWindows = false;
4101 for (int i=0; i<N; i++) {
4102 WindowState w = wtoken.allAppWindows.get(i);
4103 if (w.mAppFreezing) {
4104 w.mAppFreezing = false;
4105 if (w.mSurface != null && !w.mOrientationChanging) {
4106 w.mOrientationChanging = true;
4107 }
4108 unfrozeWindows = true;
4109 }
4110 }
4111 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004112 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 wtoken.freezingScreen = false;
4114 mAppsFreezingScreen--;
4115 }
4116 if (unfreezeSurfaceNow) {
4117 if (unfrozeWindows) {
4118 mLayoutNeeded = true;
4119 performLayoutAndPlaceSurfacesLocked();
4120 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004121 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004122 }
4123 }
4124 }
Romain Guy06882f82009-06-10 13:36:04 -07004125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4127 int configChanges) {
4128 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004129 RuntimeException e = null;
4130 if (!HIDE_STACK_CRAWLS) {
4131 e = new RuntimeException();
4132 e.fillInStackTrace();
4133 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004134 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 + ": hidden=" + wtoken.hidden + " freezing="
4136 + wtoken.freezingScreen, e);
4137 }
4138 if (!wtoken.hiddenRequested) {
4139 if (!wtoken.freezingScreen) {
4140 wtoken.freezingScreen = true;
4141 mAppsFreezingScreen++;
4142 if (mAppsFreezingScreen == 1) {
4143 startFreezingDisplayLocked();
4144 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4145 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4146 5000);
4147 }
4148 }
4149 final int N = wtoken.allAppWindows.size();
4150 for (int i=0; i<N; i++) {
4151 WindowState w = wtoken.allAppWindows.get(i);
4152 w.mAppFreezing = true;
4153 }
4154 }
4155 }
Romain Guy06882f82009-06-10 13:36:04 -07004156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004157 public void startAppFreezingScreen(IBinder token, int configChanges) {
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) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004164 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004165 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 return;
4167 }
Romain Guy06882f82009-06-10 13:36:04 -07004168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 AppWindowToken wtoken = findAppWindowToken(token);
4170 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004171 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 return;
4173 }
4174 final long origId = Binder.clearCallingIdentity();
4175 startAppFreezingScreenLocked(wtoken, configChanges);
4176 Binder.restoreCallingIdentity(origId);
4177 }
4178 }
Romain Guy06882f82009-06-10 13:36:04 -07004179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 public void stopAppFreezingScreen(IBinder token, boolean force) {
4181 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4182 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004183 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 }
4185
4186 synchronized(mWindowMap) {
4187 AppWindowToken wtoken = findAppWindowToken(token);
4188 if (wtoken == null || wtoken.appToken == null) {
4189 return;
4190 }
4191 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004192 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4194 unsetAppFreezingScreenLocked(wtoken, true, force);
4195 Binder.restoreCallingIdentity(origId);
4196 }
4197 }
Romain Guy06882f82009-06-10 13:36:04 -07004198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 public void removeAppToken(IBinder token) {
4200 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4201 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004202 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004203 }
4204
4205 AppWindowToken wtoken = null;
4206 AppWindowToken startingToken = null;
4207 boolean delayed = false;
4208
4209 final long origId = Binder.clearCallingIdentity();
4210 synchronized(mWindowMap) {
4211 WindowToken basewtoken = mTokenMap.remove(token);
4212 mTokenList.remove(basewtoken);
4213 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004214 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004215 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 wtoken.inPendingTransaction = false;
4217 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004218 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 if (mClosingApps.contains(wtoken)) {
4220 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004221 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004223 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004224 delayed = true;
4225 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004226 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004227 TAG, "Removing app " + wtoken + " delayed=" + delayed
4228 + " animation=" + wtoken.animation
4229 + " animating=" + wtoken.animating);
4230 if (delayed) {
4231 // set the token aside because it has an active animation to be finished
4232 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004233 } else {
4234 // Make sure there is no animation running on this token,
4235 // so any windows associated with it will be removed as
4236 // soon as their animations are complete
4237 wtoken.animation = null;
4238 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 }
4240 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004241 if (mLastEnterAnimToken == wtoken) {
4242 mLastEnterAnimToken = null;
4243 mLastEnterAnimParams = null;
4244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 wtoken.removed = true;
4246 if (wtoken.startingData != null) {
4247 startingToken = wtoken;
4248 }
4249 unsetAppFreezingScreenLocked(wtoken, true, true);
4250 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004251 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 mFocusedApp = null;
4253 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004254 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 }
4256 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004257 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 }
Romain Guy06882f82009-06-10 13:36:04 -07004259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 if (!delayed && wtoken != null) {
4261 wtoken.updateReportedVisibilityLocked();
4262 }
4263 }
4264 Binder.restoreCallingIdentity(origId);
4265
4266 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004267 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 + startingToken + ": app token removed");
4269 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4270 mH.sendMessage(m);
4271 }
4272 }
4273
4274 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4275 final int NW = token.windows.size();
4276 for (int i=0; i<NW; i++) {
4277 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004278 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004280 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 int j = win.mChildWindows.size();
4282 while (j > 0) {
4283 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004284 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004285 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004286 "Tmp removing child window " + cwin);
4287 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 }
4289 }
4290 return NW > 0;
4291 }
4292
4293 void dumpAppTokensLocked() {
4294 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004295 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 }
4297 }
Romain Guy06882f82009-06-10 13:36:04 -07004298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 void dumpWindowsLocked() {
4300 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004301 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 }
4303 }
Romain Guy06882f82009-06-10 13:36:04 -07004304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 private int findWindowOffsetLocked(int tokenPos) {
4306 final int NW = mWindows.size();
4307
4308 if (tokenPos >= mAppTokens.size()) {
4309 int i = NW;
4310 while (i > 0) {
4311 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004312 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 if (win.getAppToken() != null) {
4314 return i+1;
4315 }
4316 }
4317 }
4318
4319 while (tokenPos > 0) {
4320 // Find the first app token below the new position that has
4321 // a window displayed.
4322 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004323 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004325 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004326 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004327 "Skipping token -- currently sending to bottom");
4328 tokenPos--;
4329 continue;
4330 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 int i = wtoken.windows.size();
4332 while (i > 0) {
4333 i--;
4334 WindowState win = wtoken.windows.get(i);
4335 int j = win.mChildWindows.size();
4336 while (j > 0) {
4337 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004338 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004339 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004340 for (int pos=NW-1; pos>=0; pos--) {
4341 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004342 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 "Found child win @" + (pos+1));
4344 return pos+1;
4345 }
4346 }
4347 }
4348 }
4349 for (int pos=NW-1; pos>=0; pos--) {
4350 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004351 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 return pos+1;
4353 }
4354 }
4355 }
4356 tokenPos--;
4357 }
4358
4359 return 0;
4360 }
4361
4362 private final int reAddWindowLocked(int index, WindowState win) {
4363 final int NCW = win.mChildWindows.size();
4364 boolean added = false;
4365 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004366 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004368 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004369 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 mWindows.add(index, win);
4371 index++;
4372 added = true;
4373 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004374 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004375 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 mWindows.add(index, cwin);
4377 index++;
4378 }
4379 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004380 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004381 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 mWindows.add(index, win);
4383 index++;
4384 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004385 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 return index;
4387 }
Romain Guy06882f82009-06-10 13:36:04 -07004388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4390 final int NW = token.windows.size();
4391 for (int i=0; i<NW; i++) {
4392 index = reAddWindowLocked(index, token.windows.get(i));
4393 }
4394 return index;
4395 }
4396
4397 public void moveAppToken(int index, IBinder token) {
4398 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4399 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004400 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 }
4402
4403 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004404 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004405 if (DEBUG_REORDER) dumpAppTokensLocked();
4406 final AppWindowToken wtoken = findAppWindowToken(token);
4407 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004408 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 + token + " (" + wtoken + ")");
4410 return;
4411 }
4412 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004413 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004414 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004417 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 if (DEBUG_REORDER) dumpWindowsLocked();
4419 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004420 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004421 if (DEBUG_REORDER) dumpWindowsLocked();
4422 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004423 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 if (DEBUG_REORDER) dumpWindowsLocked();
4425 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 mLayoutNeeded = true;
4427 performLayoutAndPlaceSurfacesLocked();
4428 }
4429 Binder.restoreCallingIdentity(origId);
4430 }
4431 }
4432
4433 private void removeAppTokensLocked(List<IBinder> tokens) {
4434 // XXX This should be done more efficiently!
4435 // (take advantage of the fact that both lists should be
4436 // ordered in the same way.)
4437 int N = tokens.size();
4438 for (int i=0; i<N; i++) {
4439 IBinder token = tokens.get(i);
4440 final AppWindowToken wtoken = findAppWindowToken(token);
4441 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 + token + " (" + wtoken + ")");
4444 i--;
4445 N--;
4446 }
4447 }
4448 }
4449
Dianne Hackborna8f60182009-09-01 19:01:50 -07004450 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4451 boolean updateFocusAndLayout) {
4452 // First remove all of the windows from the list.
4453 tmpRemoveAppWindowsLocked(wtoken);
4454
4455 // Where to start adding?
4456 int pos = findWindowOffsetLocked(tokenPos);
4457
4458 // And now add them back at the correct place.
4459 pos = reAddAppWindowsLocked(pos, wtoken);
4460
4461 if (updateFocusAndLayout) {
4462 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4463 assignLayersLocked();
4464 }
4465 mLayoutNeeded = true;
4466 performLayoutAndPlaceSurfacesLocked();
4467 }
4468 }
4469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4471 // First remove all of the windows from the list.
4472 final int N = tokens.size();
4473 int i;
4474 for (i=0; i<N; i++) {
4475 WindowToken token = mTokenMap.get(tokens.get(i));
4476 if (token != null) {
4477 tmpRemoveAppWindowsLocked(token);
4478 }
4479 }
4480
4481 // Where to start adding?
4482 int pos = findWindowOffsetLocked(tokenPos);
4483
4484 // And now add them back at the correct place.
4485 for (i=0; i<N; i++) {
4486 WindowToken token = mTokenMap.get(tokens.get(i));
4487 if (token != null) {
4488 pos = reAddAppWindowsLocked(pos, token);
4489 }
4490 }
4491
Dianne Hackborna8f60182009-09-01 19:01:50 -07004492 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4493 assignLayersLocked();
4494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 mLayoutNeeded = true;
4496 performLayoutAndPlaceSurfacesLocked();
4497
4498 //dump();
4499 }
4500
4501 public void moveAppTokensToTop(List<IBinder> tokens) {
4502 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4503 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004504 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 }
4506
4507 final long origId = Binder.clearCallingIdentity();
4508 synchronized(mWindowMap) {
4509 removeAppTokensLocked(tokens);
4510 final int N = tokens.size();
4511 for (int i=0; i<N; i++) {
4512 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4513 if (wt != null) {
4514 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004515 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004516 mToTopApps.remove(wt);
4517 mToBottomApps.remove(wt);
4518 mToTopApps.add(wt);
4519 wt.sendingToBottom = false;
4520 wt.sendingToTop = true;
4521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 }
4523 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004524
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004525 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004526 moveAppWindowsLocked(tokens, mAppTokens.size());
4527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 }
4529 Binder.restoreCallingIdentity(origId);
4530 }
4531
4532 public void moveAppTokensToBottom(List<IBinder> tokens) {
4533 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4534 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004535 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004536 }
4537
4538 final long origId = Binder.clearCallingIdentity();
4539 synchronized(mWindowMap) {
4540 removeAppTokensLocked(tokens);
4541 final int N = tokens.size();
4542 int pos = 0;
4543 for (int i=0; i<N; i++) {
4544 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4545 if (wt != null) {
4546 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004547 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004548 mToTopApps.remove(wt);
4549 mToBottomApps.remove(wt);
4550 mToBottomApps.add(i, wt);
4551 wt.sendingToTop = false;
4552 wt.sendingToBottom = true;
4553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004554 pos++;
4555 }
4556 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004557
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004558 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004559 moveAppWindowsLocked(tokens, 0);
4560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004561 }
4562 Binder.restoreCallingIdentity(origId);
4563 }
4564
4565 // -------------------------------------------------------------
4566 // Misc IWindowSession methods
4567 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004568
Jim Miller284b62e2010-06-08 14:27:42 -07004569 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004570 {
Jim Miller284b62e2010-06-08 14:27:42 -07004571 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4572 // called before DevicePolicyManagerService has started.
4573 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4574 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4575 Context.DEVICE_POLICY_SERVICE);
4576 if (dpm != null) {
4577 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4578 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4579 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4580 }
Jim Millerd6b57052010-06-07 17:52:42 -07004581 }
Jim Miller284b62e2010-06-08 14:27:42 -07004582 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004583 }
4584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004585 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004586 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004587 != PackageManager.PERMISSION_GRANTED) {
4588 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4589 }
Jim Millerd6b57052010-06-07 17:52:42 -07004590
Jim Miller284b62e2010-06-08 14:27:42 -07004591 synchronized (mKeyguardTokenWatcher) {
4592 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004594 }
4595
4596 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004597 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 != PackageManager.PERMISSION_GRANTED) {
4599 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004601
Jim Miller284b62e2010-06-08 14:27:42 -07004602 synchronized (mKeyguardTokenWatcher) {
4603 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004604
Jim Miller284b62e2010-06-08 14:27:42 -07004605 if (!mKeyguardTokenWatcher.isAcquired()) {
4606 // If we are the last one to reenable the keyguard wait until
4607 // we have actually finished reenabling until returning.
4608 // It is possible that reenableKeyguard() can be called before
4609 // the previous disableKeyguard() is handled, in which case
4610 // neither mKeyguardTokenWatcher.acquired() or released() would
4611 // be called. In that case mKeyguardDisabled will be false here
4612 // and we have nothing to wait for.
4613 while (mKeyguardDisabled) {
4614 try {
4615 mKeyguardTokenWatcher.wait();
4616 } catch (InterruptedException e) {
4617 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004618 }
4619 }
4620 }
4621 }
4622 }
4623
4624 /**
4625 * @see android.app.KeyguardManager#exitKeyguardSecurely
4626 */
4627 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004628 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004629 != PackageManager.PERMISSION_GRANTED) {
4630 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4631 }
4632 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4633 public void onKeyguardExitResult(boolean success) {
4634 try {
4635 callback.onKeyguardExitResult(success);
4636 } catch (RemoteException e) {
4637 // Client has died, we don't care.
4638 }
4639 }
4640 });
4641 }
4642
4643 public boolean inKeyguardRestrictedInputMode() {
4644 return mPolicy.inKeyguardRestrictedKeyInputMode();
4645 }
Romain Guy06882f82009-06-10 13:36:04 -07004646
Dianne Hackbornffa42482009-09-23 22:20:11 -07004647 public void closeSystemDialogs(String reason) {
4648 synchronized(mWindowMap) {
4649 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004650 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004651 if (w.mSurface != null) {
4652 try {
4653 w.mClient.closeSystemDialogs(reason);
4654 } catch (RemoteException e) {
4655 }
4656 }
4657 }
4658 }
4659 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 static float fixScale(float scale) {
4662 if (scale < 0) scale = 0;
4663 else if (scale > 20) scale = 20;
4664 return Math.abs(scale);
4665 }
Romain Guy06882f82009-06-10 13:36:04 -07004666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004667 public void setAnimationScale(int which, float scale) {
4668 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4669 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004670 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004671 }
4672
4673 if (scale < 0) scale = 0;
4674 else if (scale > 20) scale = 20;
4675 scale = Math.abs(scale);
4676 switch (which) {
4677 case 0: mWindowAnimationScale = fixScale(scale); break;
4678 case 1: mTransitionAnimationScale = fixScale(scale); break;
4679 }
Romain Guy06882f82009-06-10 13:36:04 -07004680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 // Persist setting
4682 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4683 }
Romain Guy06882f82009-06-10 13:36:04 -07004684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 public void setAnimationScales(float[] scales) {
4686 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4687 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004688 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 }
4690
4691 if (scales != null) {
4692 if (scales.length >= 1) {
4693 mWindowAnimationScale = fixScale(scales[0]);
4694 }
4695 if (scales.length >= 2) {
4696 mTransitionAnimationScale = fixScale(scales[1]);
4697 }
4698 }
Romain Guy06882f82009-06-10 13:36:04 -07004699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700 // Persist setting
4701 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4702 }
Romain Guy06882f82009-06-10 13:36:04 -07004703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004704 public float getAnimationScale(int which) {
4705 switch (which) {
4706 case 0: return mWindowAnimationScale;
4707 case 1: return mTransitionAnimationScale;
4708 }
4709 return 0;
4710 }
Romain Guy06882f82009-06-10 13:36:04 -07004711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 public float[] getAnimationScales() {
4713 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4714 }
Romain Guy06882f82009-06-10 13:36:04 -07004715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004716 public int getSwitchState(int sw) {
4717 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4718 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004719 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004720 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004721 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 }
Romain Guy06882f82009-06-10 13:36:04 -07004723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 public int getSwitchStateForDevice(int devid, int sw) {
4725 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4726 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004727 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004728 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004729 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004730 }
Romain Guy06882f82009-06-10 13:36:04 -07004731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 public int getScancodeState(int sw) {
4733 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4734 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004735 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004736 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004737 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 }
Romain Guy06882f82009-06-10 13:36:04 -07004739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004740 public int getScancodeStateForDevice(int devid, int sw) {
4741 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4742 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004743 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004744 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004745 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004746 }
Romain Guy06882f82009-06-10 13:36:04 -07004747
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004748 public int getTrackballScancodeState(int sw) {
4749 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4750 "getTrackballScancodeState()")) {
4751 throw new SecurityException("Requires READ_INPUT_STATE permission");
4752 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004753 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004754 }
4755
4756 public int getDPadScancodeState(int sw) {
4757 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4758 "getDPadScancodeState()")) {
4759 throw new SecurityException("Requires READ_INPUT_STATE permission");
4760 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004761 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004762 }
4763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764 public int getKeycodeState(int sw) {
4765 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4766 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004767 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004768 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004769 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 }
Romain Guy06882f82009-06-10 13:36:04 -07004771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004772 public int getKeycodeStateForDevice(int devid, int sw) {
4773 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4774 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004775 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004776 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004777 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 }
Romain Guy06882f82009-06-10 13:36:04 -07004779
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004780 public int getTrackballKeycodeState(int sw) {
4781 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4782 "getTrackballKeycodeState()")) {
4783 throw new SecurityException("Requires READ_INPUT_STATE permission");
4784 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004785 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004786 }
4787
4788 public int getDPadKeycodeState(int sw) {
4789 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4790 "getDPadKeycodeState()")) {
4791 throw new SecurityException("Requires READ_INPUT_STATE permission");
4792 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004793 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004794 }
Jeff Browna41ca772010-08-11 14:46:32 -07004795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004797 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 }
Romain Guy06882f82009-06-10 13:36:04 -07004799
Jeff Browna41ca772010-08-11 14:46:32 -07004800 public InputChannel monitorInput(String inputChannelName) {
4801 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4802 "monitorInput()")) {
4803 throw new SecurityException("Requires READ_INPUT_STATE permission");
4804 }
4805 return mInputManager.monitorInput(inputChannelName);
4806 }
4807
Jeff Brown8d608662010-08-30 03:02:23 -07004808 public InputDevice getInputDevice(int deviceId) {
4809 return mInputManager.getInputDevice(deviceId);
4810 }
4811
4812 public int[] getInputDeviceIds() {
4813 return mInputManager.getInputDeviceIds();
4814 }
4815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004816 public void enableScreenAfterBoot() {
4817 synchronized(mWindowMap) {
4818 if (mSystemBooted) {
4819 return;
4820 }
4821 mSystemBooted = true;
4822 }
Romain Guy06882f82009-06-10 13:36:04 -07004823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004824 performEnableScreen();
4825 }
Romain Guy06882f82009-06-10 13:36:04 -07004826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 public void enableScreenIfNeededLocked() {
4828 if (mDisplayEnabled) {
4829 return;
4830 }
4831 if (!mSystemBooted) {
4832 return;
4833 }
4834 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4835 }
Romain Guy06882f82009-06-10 13:36:04 -07004836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 public void performEnableScreen() {
4838 synchronized(mWindowMap) {
4839 if (mDisplayEnabled) {
4840 return;
4841 }
4842 if (!mSystemBooted) {
4843 return;
4844 }
Romain Guy06882f82009-06-10 13:36:04 -07004845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004846 // Don't enable the screen until all existing windows
4847 // have been drawn.
4848 final int N = mWindows.size();
4849 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004850 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004851 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 return;
4853 }
4854 }
Romain Guy06882f82009-06-10 13:36:04 -07004855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 mDisplayEnabled = true;
4857 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004858 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859 StringWriter sw = new StringWriter();
4860 PrintWriter pw = new PrintWriter(sw);
4861 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004862 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 }
4864 try {
4865 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4866 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004867 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004868 Parcel data = Parcel.obtain();
4869 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4870 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4871 data, null, 0);
4872 data.recycle();
4873 }
4874 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004875 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 }
4877 }
Romain Guy06882f82009-06-10 13:36:04 -07004878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004879 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004882 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4883 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004884 }
Romain Guy06882f82009-06-10 13:36:04 -07004885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004886 public void setInTouchMode(boolean mode) {
4887 synchronized(mWindowMap) {
4888 mInTouchMode = mode;
4889 }
4890 }
4891
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004892 // TODO: more accounting of which pid(s) turned it on, keep count,
4893 // only allow disables from pids which have count on, etc.
4894 public void showStrictModeViolation(boolean on) {
4895 int pid = Binder.getCallingPid();
4896 synchronized(mWindowMap) {
4897 // Ignoring requests to enable the red border from clients
4898 // which aren't on screen. (e.g. Broadcast Receivers in
4899 // the background..)
4900 if (on) {
4901 boolean isVisible = false;
4902 for (WindowState ws : mWindows) {
4903 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4904 isVisible = true;
4905 break;
4906 }
4907 }
4908 if (!isVisible) {
4909 return;
4910 }
4911 }
4912
4913 Surface.openTransaction();
4914 if (mStrictModeFlash == null) {
4915 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4916 }
4917 mStrictModeFlash.setVisibility(on);
4918 Surface.closeTransaction();
4919 }
4920 }
4921
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004922 public void setStrictModeVisualIndicatorPreference(String value) {
4923 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4924 }
4925
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004926 public Bitmap screenshotApplications(int maxWidth, int maxHeight) {
4927 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4928 "screenshotApplications()")) {
4929 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
4930 }
4931
4932 Bitmap rawss;
4933
4934 final Rect frame = new Rect();
4935
4936 float scale;
4937 int sw, sh, dw, dh;
4938 int rot;
4939
4940 synchronized(mWindowMap) {
4941 long ident = Binder.clearCallingIdentity();
4942
4943 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
4944 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
4945 + TYPE_LAYER_OFFSET;
4946 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
4947
4948 // Figure out the part of the screen that is actually the app.
4949 for (int i=0; i<mWindows.size(); i++) {
4950 WindowState ws = mWindows.get(i);
4951 if (ws.mSurface == null) {
4952 continue;
4953 }
4954 if (ws.mLayer >= aboveAppLayer) {
4955 break;
4956 }
4957 final Rect wf = ws.mFrame;
4958 final Rect cr = ws.mContentInsets;
4959 int left = wf.left + cr.left;
4960 int top = wf.top + cr.top;
4961 int right = wf.right - cr.right;
4962 int bottom = wf.bottom - cr.bottom;
4963 frame.union(left, top, right, bottom);
4964 }
4965 Binder.restoreCallingIdentity(ident);
4966
4967 if (frame.isEmpty()) {
4968 return null;
4969 }
4970
4971 // The screenshot API does not apply the current screen rotation.
4972 rot = mDisplay.getRotation();
4973 int fw = frame.width();
4974 int fh = frame.height();
4975
4976 // First try reducing to fit in x dimension.
4977 scale = maxWidth/(float)fw;
4978 sw = maxWidth;
4979 sh = (int)(fh*scale);
4980 if (sh > maxHeight) {
4981 // y dimension became too long; constrain by that.
4982 scale = maxHeight/(float)fh;
4983 sw = (int)(fw*scale);
4984 sh = maxHeight;
4985 }
4986
4987 // The screen shot will contain the entire screen.
4988 dw = (int)(mDisplay.getWidth()*scale);
4989 dh = (int)(mDisplay.getHeight()*scale);
4990 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
4991 int tmp = dw;
4992 dw = dh;
4993 dh = tmp;
4994 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
4995 }
4996 rawss = Surface.screenshot(dw, dh);
4997 }
4998
4999 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5000 Matrix matrix = new Matrix();
5001 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5002 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5003 Canvas canvas = new Canvas(bm);
5004 canvas.drawBitmap(rawss, matrix, null);
5005
5006 rawss.recycle();
5007 return bm;
5008 }
5009
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005010 public void freezeRotation() {
5011 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5012 "setRotation()")) {
5013 throw new SecurityException("Requires SET_ORIENTATION permission");
5014 }
5015
5016 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5017 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5018 }
5019
5020 public void thawRotation() {
5021 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5022 "setRotation()")) {
5023 throw new SecurityException("Requires SET_ORIENTATION permission");
5024 }
5025
5026 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5027 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5028 }
5029
Romain Guy06882f82009-06-10 13:36:04 -07005030 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005031 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005032 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005033 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005034 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 }
5036
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005037 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005038 }
Romain Guy06882f82009-06-10 13:36:04 -07005039
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005040 public void setRotationUnchecked(int rotation,
5041 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005042 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005043 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 long origId = Binder.clearCallingIdentity();
5046 boolean changed;
5047 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005048 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005049 }
Romain Guy06882f82009-06-10 13:36:04 -07005050
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005051 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005052 sendNewConfiguration();
5053 }
Romain Guy06882f82009-06-10 13:36:04 -07005054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 Binder.restoreCallingIdentity(origId);
5056 }
Romain Guy06882f82009-06-10 13:36:04 -07005057
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005058 /**
5059 * Apply a new rotation to the screen, respecting the requests of
5060 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5061 * re-evaluate the desired rotation.
5062 *
5063 * Returns null if the rotation has been changed. In this case YOU
5064 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5065 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005066 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005067 boolean changed;
5068 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5069 rotation = mRequestedRotation;
5070 } else {
5071 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005072 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005074 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005075 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005076 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005077 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005078 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005080 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005081 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005082 "Rotation changed to " + rotation
5083 + " from " + mRotation
5084 + " (forceApp=" + mForcedAppOrientation
5085 + ", req=" + mRequestedRotation + ")");
5086 mRotation = rotation;
5087 mWindowsFreezingScreen = true;
5088 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5089 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5090 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005091 mWaitingForConfig = true;
5092 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005093 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005094 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005095 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005096 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005097 if (CUSTOM_SCREEN_ROTATION) {
5098 Surface.freezeDisplay(0);
5099 Surface.openTransaction();
5100 if (mScreenRotationAnimation != null) {
5101 mScreenRotationAnimation.setRotation(rotation);
5102 }
5103 Surface.closeTransaction();
5104 Surface.setOrientation(0, rotation, animFlags);
5105 Surface.unfreezeDisplay(0);
5106 } else {
5107 Surface.setOrientation(0, rotation, animFlags);
5108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005109 }
5110 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005111 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005112 if (w.mSurface != null) {
5113 w.mOrientationChanging = true;
5114 }
5115 }
5116 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5117 try {
5118 mRotationWatchers.get(i).onRotationChanged(rotation);
5119 } catch (RemoteException e) {
5120 }
5121 }
5122 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 return changed;
5125 }
Romain Guy06882f82009-06-10 13:36:04 -07005126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005127 public int getRotation() {
5128 return mRotation;
5129 }
5130
5131 public int watchRotation(IRotationWatcher watcher) {
5132 final IBinder watcherBinder = watcher.asBinder();
5133 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5134 public void binderDied() {
5135 synchronized (mWindowMap) {
5136 for (int i=0; i<mRotationWatchers.size(); i++) {
5137 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005138 IRotationWatcher removed = mRotationWatchers.remove(i);
5139 if (removed != null) {
5140 removed.asBinder().unlinkToDeath(this, 0);
5141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005142 i--;
5143 }
5144 }
5145 }
5146 }
5147 };
Romain Guy06882f82009-06-10 13:36:04 -07005148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005149 synchronized (mWindowMap) {
5150 try {
5151 watcher.asBinder().linkToDeath(dr, 0);
5152 mRotationWatchers.add(watcher);
5153 } catch (RemoteException e) {
5154 // Client died, no cleanup needed.
5155 }
Romain Guy06882f82009-06-10 13:36:04 -07005156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005157 return mRotation;
5158 }
5159 }
5160
5161 /**
5162 * Starts the view server on the specified port.
5163 *
5164 * @param port The port to listener to.
5165 *
5166 * @return True if the server was successfully started, false otherwise.
5167 *
5168 * @see com.android.server.ViewServer
5169 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5170 */
5171 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005172 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005173 return false;
5174 }
5175
5176 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5177 return false;
5178 }
5179
5180 if (port < 1024) {
5181 return false;
5182 }
5183
5184 if (mViewServer != null) {
5185 if (!mViewServer.isRunning()) {
5186 try {
5187 return mViewServer.start();
5188 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005189 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005190 }
5191 }
5192 return false;
5193 }
5194
5195 try {
5196 mViewServer = new ViewServer(this, port);
5197 return mViewServer.start();
5198 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005199 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005200 }
5201 return false;
5202 }
5203
Romain Guy06882f82009-06-10 13:36:04 -07005204 private boolean isSystemSecure() {
5205 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5206 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5207 }
5208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005209 /**
5210 * Stops the view server if it exists.
5211 *
5212 * @return True if the server stopped, false if it wasn't started or
5213 * couldn't be stopped.
5214 *
5215 * @see com.android.server.ViewServer
5216 */
5217 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005218 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005219 return false;
5220 }
5221
5222 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5223 return false;
5224 }
5225
5226 if (mViewServer != null) {
5227 return mViewServer.stop();
5228 }
5229 return false;
5230 }
5231
5232 /**
5233 * Indicates whether the view server is running.
5234 *
5235 * @return True if the server is running, false otherwise.
5236 *
5237 * @see com.android.server.ViewServer
5238 */
5239 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005240 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 return false;
5242 }
5243
5244 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5245 return false;
5246 }
5247
5248 return mViewServer != null && mViewServer.isRunning();
5249 }
5250
5251 /**
5252 * Lists all availble windows in the system. The listing is written in the
5253 * specified Socket's output stream with the following syntax:
5254 * windowHashCodeInHexadecimal windowName
5255 * Each line of the ouput represents a different window.
5256 *
5257 * @param client The remote client to send the listing to.
5258 * @return False if an error occured, true otherwise.
5259 */
5260 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005261 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 return false;
5263 }
5264
5265 boolean result = true;
5266
Jeff Browne33348b2010-07-15 23:54:05 -07005267 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005268 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005269 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005270 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005271 }
5272
5273 BufferedWriter out = null;
5274
5275 // Any uncaught exception will crash the system process
5276 try {
5277 OutputStream clientStream = client.getOutputStream();
5278 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5279
5280 final int count = windows.length;
5281 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005282 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005283 out.write(Integer.toHexString(System.identityHashCode(w)));
5284 out.write(' ');
5285 out.append(w.mAttrs.getTitle());
5286 out.write('\n');
5287 }
5288
5289 out.write("DONE.\n");
5290 out.flush();
5291 } catch (Exception e) {
5292 result = false;
5293 } finally {
5294 if (out != null) {
5295 try {
5296 out.close();
5297 } catch (IOException e) {
5298 result = false;
5299 }
5300 }
5301 }
5302
5303 return result;
5304 }
5305
5306 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005307 * Returns the focused window in the following format:
5308 * windowHashCodeInHexadecimal windowName
5309 *
5310 * @param client The remote client to send the listing to.
5311 * @return False if an error occurred, true otherwise.
5312 */
5313 boolean viewServerGetFocusedWindow(Socket client) {
5314 if (isSystemSecure()) {
5315 return false;
5316 }
5317
5318 boolean result = true;
5319
5320 WindowState focusedWindow = getFocusedWindow();
5321
5322 BufferedWriter out = null;
5323
5324 // Any uncaught exception will crash the system process
5325 try {
5326 OutputStream clientStream = client.getOutputStream();
5327 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5328
5329 if(focusedWindow != null) {
5330 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5331 out.write(' ');
5332 out.append(focusedWindow.mAttrs.getTitle());
5333 }
5334 out.write('\n');
5335 out.flush();
5336 } catch (Exception e) {
5337 result = false;
5338 } finally {
5339 if (out != null) {
5340 try {
5341 out.close();
5342 } catch (IOException e) {
5343 result = false;
5344 }
5345 }
5346 }
5347
5348 return result;
5349 }
5350
5351 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005352 * Sends a command to a target window. The result of the command, if any, will be
5353 * written in the output stream of the specified socket.
5354 *
5355 * The parameters must follow this syntax:
5356 * windowHashcode extra
5357 *
5358 * Where XX is the length in characeters of the windowTitle.
5359 *
5360 * The first parameter is the target window. The window with the specified hashcode
5361 * will be the target. If no target can be found, nothing happens. The extra parameters
5362 * will be delivered to the target window and as parameters to the command itself.
5363 *
5364 * @param client The remote client to sent the result, if any, to.
5365 * @param command The command to execute.
5366 * @param parameters The command parameters.
5367 *
5368 * @return True if the command was successfully delivered, false otherwise. This does
5369 * not indicate whether the command itself was successful.
5370 */
5371 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005372 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005373 return false;
5374 }
5375
5376 boolean success = true;
5377 Parcel data = null;
5378 Parcel reply = null;
5379
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005380 BufferedWriter out = null;
5381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 // Any uncaught exception will crash the system process
5383 try {
5384 // Find the hashcode of the window
5385 int index = parameters.indexOf(' ');
5386 if (index == -1) {
5387 index = parameters.length();
5388 }
5389 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005390 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005391
5392 // Extract the command's parameter after the window description
5393 if (index < parameters.length()) {
5394 parameters = parameters.substring(index + 1);
5395 } else {
5396 parameters = "";
5397 }
5398
5399 final WindowManagerService.WindowState window = findWindow(hashCode);
5400 if (window == null) {
5401 return false;
5402 }
5403
5404 data = Parcel.obtain();
5405 data.writeInterfaceToken("android.view.IWindow");
5406 data.writeString(command);
5407 data.writeString(parameters);
5408 data.writeInt(1);
5409 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5410
5411 reply = Parcel.obtain();
5412
5413 final IBinder binder = window.mClient.asBinder();
5414 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5415 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5416
5417 reply.readException();
5418
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005419 if (!client.isOutputShutdown()) {
5420 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5421 out.write("DONE\n");
5422 out.flush();
5423 }
5424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005425 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005426 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427 success = false;
5428 } finally {
5429 if (data != null) {
5430 data.recycle();
5431 }
5432 if (reply != null) {
5433 reply.recycle();
5434 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005435 if (out != null) {
5436 try {
5437 out.close();
5438 } catch (IOException e) {
5439
5440 }
5441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005442 }
5443
5444 return success;
5445 }
5446
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005447 public void addWindowChangeListener(WindowChangeListener listener) {
5448 synchronized(mWindowMap) {
5449 mWindowChangeListeners.add(listener);
5450 }
5451 }
5452
5453 public void removeWindowChangeListener(WindowChangeListener listener) {
5454 synchronized(mWindowMap) {
5455 mWindowChangeListeners.remove(listener);
5456 }
5457 }
5458
5459 private void notifyWindowsChanged() {
5460 WindowChangeListener[] windowChangeListeners;
5461 synchronized(mWindowMap) {
5462 if(mWindowChangeListeners.isEmpty()) {
5463 return;
5464 }
5465 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5466 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5467 }
5468 int N = windowChangeListeners.length;
5469 for(int i = 0; i < N; i++) {
5470 windowChangeListeners[i].windowsChanged();
5471 }
5472 }
5473
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005474 private void notifyFocusChanged() {
5475 WindowChangeListener[] windowChangeListeners;
5476 synchronized(mWindowMap) {
5477 if(mWindowChangeListeners.isEmpty()) {
5478 return;
5479 }
5480 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5481 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5482 }
5483 int N = windowChangeListeners.length;
5484 for(int i = 0; i < N; i++) {
5485 windowChangeListeners[i].focusChanged();
5486 }
5487 }
5488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005489 private WindowState findWindow(int hashCode) {
5490 if (hashCode == -1) {
5491 return getFocusedWindow();
5492 }
5493
5494 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005495 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 final int count = windows.size();
5497
5498 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005499 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005500 if (System.identityHashCode(w) == hashCode) {
5501 return w;
5502 }
5503 }
5504 }
5505
5506 return null;
5507 }
5508
5509 /*
5510 * Instruct the Activity Manager to fetch the current configuration and broadcast
5511 * that to config-changed listeners if appropriate.
5512 */
5513 void sendNewConfiguration() {
5514 try {
5515 mActivityManager.updateConfiguration(null);
5516 } catch (RemoteException e) {
5517 }
5518 }
Romain Guy06882f82009-06-10 13:36:04 -07005519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005520 public Configuration computeNewConfiguration() {
5521 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005522 return computeNewConfigurationLocked();
5523 }
5524 }
Romain Guy06882f82009-06-10 13:36:04 -07005525
Dianne Hackbornc485a602009-03-24 22:39:49 -07005526 Configuration computeNewConfigurationLocked() {
5527 Configuration config = new Configuration();
5528 if (!computeNewConfigurationLocked(config)) {
5529 return null;
5530 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005531 return config;
5532 }
Romain Guy06882f82009-06-10 13:36:04 -07005533
Dianne Hackbornc485a602009-03-24 22:39:49 -07005534 boolean computeNewConfigurationLocked(Configuration config) {
5535 if (mDisplay == null) {
5536 return false;
5537 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005538
5539 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005540
5541 // Use the effective "visual" dimensions based on current rotation
5542 final boolean rotated = (mRotation == Surface.ROTATION_90
5543 || mRotation == Surface.ROTATION_270);
5544 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5545 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5546
Dianne Hackbornc485a602009-03-24 22:39:49 -07005547 int orientation = Configuration.ORIENTATION_SQUARE;
5548 if (dw < dh) {
5549 orientation = Configuration.ORIENTATION_PORTRAIT;
5550 } else if (dw > dh) {
5551 orientation = Configuration.ORIENTATION_LANDSCAPE;
5552 }
5553 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005554
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005555 DisplayMetrics dm = new DisplayMetrics();
5556 mDisplay.getMetrics(dm);
5557 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5558
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005559 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005560 // Note we only do this once because at this point we don't
5561 // expect the screen to change in this way at runtime, and want
5562 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005563 int longSize = dw;
5564 int shortSize = dh;
5565 if (longSize < shortSize) {
5566 int tmp = longSize;
5567 longSize = shortSize;
5568 shortSize = tmp;
5569 }
5570 longSize = (int)(longSize/dm.density);
5571 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005572
Dianne Hackborn723738c2009-06-25 19:48:04 -07005573 // These semi-magic numbers define our compatibility modes for
5574 // applications with different screens. Don't change unless you
5575 // make sure to test lots and lots of apps!
5576 if (longSize < 470) {
5577 // This is shorter than an HVGA normal density screen (which
5578 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005579 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5580 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005581 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005582 // What size is this screen screen?
5583 if (longSize >= 800 && shortSize >= 600) {
5584 // SVGA or larger screens at medium density are the point
5585 // at which we consider it to be an extra large screen.
5586 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005587 } else if (longSize >= 530 && shortSize >= 400) {
5588 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005589 // at which we consider it to be a large screen.
5590 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5591 } else {
5592 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005593
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005594 // If this screen is wider than normal HVGA, or taller
5595 // than FWVGA, then for old apps we want to run in size
5596 // compatibility mode.
5597 if (shortSize > 321 || longSize > 570) {
5598 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5599 }
5600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005601
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005602 // Is this a long screen?
5603 if (((longSize*3)/5) >= (shortSize-1)) {
5604 // Anything wider than WVGA (5:3) is considering to be long.
5605 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5606 } else {
5607 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5608 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005609 }
5610 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005611 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005612
Dianne Hackbornc485a602009-03-24 22:39:49 -07005613 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5614 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5615 mPolicy.adjustConfigurationLw(config);
5616 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005617 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005618
5619 // -------------------------------------------------------------
5620 // Drag and drop
5621 // -------------------------------------------------------------
5622
5623 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5624 boolean localOnly, int width, int height, Surface outSurface) {
5625 if (DEBUG_DRAG) {
5626 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5627 + " local=" + localOnly + " win=" + window
5628 + " asbinder=" + window.asBinder());
5629 }
5630
5631 final int callerPid = Binder.getCallingPid();
5632 final long origId = Binder.clearCallingIdentity();
5633 IBinder token = null;
5634
5635 try {
5636 synchronized (mWindowMap) {
5637 try {
5638 // !!! TODO: fail if the given window does not currently have touch focus?
5639
5640 if (mDragState == null) {
5641 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5642 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5643 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005644 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005645 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005646 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005647 mDragState.mSurface = surface;
5648 mDragState.mLocalOnly = localOnly;
5649 token = mDragState.mToken = new Binder();
5650
5651 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005652 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5653 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005654 mH.sendMessageDelayed(msg, 5000);
5655 } else {
5656 Slog.w(TAG, "Drag already in progress");
5657 }
5658 } catch (Surface.OutOfResourcesException e) {
5659 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5660 if (mDragState != null) {
5661 mDragState.reset();
5662 mDragState = null;
5663 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005664 }
5665 }
5666 } finally {
5667 Binder.restoreCallingIdentity(origId);
5668 }
5669
5670 return token;
5671 }
5672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005673 // -------------------------------------------------------------
5674 // Input Events and Focus Management
5675 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005676
Jeff Brown349703e2010-06-22 01:27:15 -07005677 InputMonitor mInputMonitor = new InputMonitor();
5678
5679 /* Tracks the progress of input dispatch and ensures that input dispatch state
5680 * is kept in sync with changes in window focus, visibility, registration, and
5681 * other relevant Window Manager state transitions. */
5682 final class InputMonitor {
5683 // Current window with input focus for keys and other non-touch events. May be null.
5684 private WindowState mInputFocus;
5685
5686 // When true, prevents input dispatch from proceeding until set to false again.
5687 private boolean mInputDispatchFrozen;
5688
5689 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5690 private boolean mInputDispatchEnabled = true;
5691
5692 // Temporary list of windows information to provide to the input dispatcher.
5693 private InputWindowList mTempInputWindows = new InputWindowList();
5694
5695 // Temporary input application object to provide to the input dispatcher.
5696 private InputApplication mTempInputApplication = new InputApplication();
5697
5698 /* Notifies the window manager about a broken input channel.
5699 *
5700 * Called by the InputManager.
5701 */
5702 public void notifyInputChannelBroken(InputChannel inputChannel) {
5703 synchronized (mWindowMap) {
5704 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5705 if (windowState == null) {
5706 return; // irrelevant
5707 }
5708
5709 Slog.i(TAG, "WINDOW DIED " + windowState);
5710 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005711 }
5712 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005713
Jeff Brown519e0242010-09-15 15:18:56 -07005714 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005715 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005716 *
5717 * Called by the InputManager.
5718 */
Jeff Brown519e0242010-09-15 15:18:56 -07005719 public long notifyANR(Object token, InputChannel inputChannel) {
5720 AppWindowToken appWindowToken = null;
5721 if (inputChannel != null) {
5722 synchronized (mWindowMap) {
5723 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5724 if (windowState != null) {
5725 Slog.i(TAG, "Input event dispatching timed out sending to "
5726 + windowState.mAttrs.getTitle());
5727 appWindowToken = windowState.mAppToken;
5728 }
Jeff Brown349703e2010-06-22 01:27:15 -07005729 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005730 }
5731
Jeff Brown519e0242010-09-15 15:18:56 -07005732 if (appWindowToken == null && token != null) {
5733 appWindowToken = (AppWindowToken) token;
5734 Slog.i(TAG, "Input event dispatching timed out sending to application "
5735 + appWindowToken.stringName);
5736 }
Jeff Brown349703e2010-06-22 01:27:15 -07005737
Jeff Brown519e0242010-09-15 15:18:56 -07005738 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005739 try {
5740 // Notify the activity manager about the timeout and let it decide whether
5741 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005742 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005743 if (! abort) {
5744 // The activity manager declined to abort dispatching.
5745 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005746 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005747 }
Jeff Brown349703e2010-06-22 01:27:15 -07005748 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005749 }
5750 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005751 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005752 }
5753
Jeff Brown349703e2010-06-22 01:27:15 -07005754 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5755 synchronized (mWindowMap) {
5756 return getWindowStateForInputChannelLocked(inputChannel);
5757 }
5758 }
5759
5760 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5761 int windowCount = mWindows.size();
5762 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005763 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005764 if (windowState.mInputChannel == inputChannel) {
5765 return windowState;
5766 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005767 }
5768
Jeff Brown349703e2010-06-22 01:27:15 -07005769 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005770 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005771
Chris Tatea32dcf72010-10-14 12:13:50 -07005772 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005773 final InputWindow inputWindow = windowList.add();
5774 inputWindow.inputChannel = mDragState.mServerChannel;
5775 inputWindow.name = "drag";
5776 inputWindow.layoutParamsFlags = 0;
5777 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5778 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5779 inputWindow.visible = true;
5780 inputWindow.canReceiveKeys = false;
5781 inputWindow.hasFocus = true;
5782 inputWindow.hasWallpaper = false;
5783 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005784 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005785 inputWindow.ownerPid = Process.myPid();
5786 inputWindow.ownerUid = Process.myUid();
5787
5788 // The drag window covers the entire display
5789 inputWindow.frameLeft = 0;
5790 inputWindow.frameTop = 0;
5791 inputWindow.frameRight = mDisplay.getWidth();
5792 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005793
Christopher Tatea53146c2010-09-07 11:57:52 -07005794 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5795 inputWindow.visibleFrameTop = inputWindow.frameTop;
5796 inputWindow.visibleFrameRight = inputWindow.frameRight;
5797 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5798
5799 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5800 inputWindow.touchableAreaTop = inputWindow.frameTop;
5801 inputWindow.touchableAreaRight = inputWindow.frameRight;
5802 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5803 }
5804
Jeff Brown349703e2010-06-22 01:27:15 -07005805 /* Updates the cached window information provided to the input dispatcher. */
5806 public void updateInputWindowsLw() {
5807 // Populate the input window list with information about all of the windows that
5808 // could potentially receive input.
5809 // As an optimization, we could try to prune the list of windows but this turns
5810 // out to be difficult because only the native code knows for sure which window
5811 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005812 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005813
5814 // If there's a drag in flight, provide a pseudowindow to catch drag input
5815 final boolean inDrag = (mDragState != null);
5816 if (inDrag) {
5817 if (DEBUG_DRAG) {
5818 Log.d(TAG, "Inserting drag window");
5819 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005820 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005821 }
5822
Jeff Brown7fbdc842010-06-17 20:52:56 -07005823 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005824 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005825 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005826 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005827 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005828 continue;
5829 }
5830
Jeff Brown349703e2010-06-22 01:27:15 -07005831 final int flags = child.mAttrs.flags;
5832 final int type = child.mAttrs.type;
5833
5834 final boolean hasFocus = (child == mInputFocus);
5835 final boolean isVisible = child.isVisibleLw();
5836 final boolean hasWallpaper = (child == mWallpaperTarget)
5837 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005838
5839 // If there's a drag in progress and 'child' is a potential drop target,
5840 // make sure it's been told about the drag
5841 if (inDrag && isVisible) {
5842 mDragState.sendDragStartedIfNeededLw(child);
5843 }
5844
Jeff Brown349703e2010-06-22 01:27:15 -07005845 // Add a window to our list of input windows.
5846 final InputWindow inputWindow = mTempInputWindows.add();
5847 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005848 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005849 inputWindow.layoutParamsFlags = flags;
5850 inputWindow.layoutParamsType = type;
5851 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5852 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005853 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005854 inputWindow.hasFocus = hasFocus;
5855 inputWindow.hasWallpaper = hasWallpaper;
5856 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005857 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005858 inputWindow.ownerPid = child.mSession.mPid;
5859 inputWindow.ownerUid = child.mSession.mUid;
5860
5861 final Rect frame = child.mFrame;
5862 inputWindow.frameLeft = frame.left;
5863 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005864 inputWindow.frameRight = frame.right;
5865 inputWindow.frameBottom = frame.bottom;
5866
5867 final Rect visibleFrame = child.mVisibleFrame;
5868 inputWindow.visibleFrameLeft = visibleFrame.left;
5869 inputWindow.visibleFrameTop = visibleFrame.top;
5870 inputWindow.visibleFrameRight = visibleFrame.right;
5871 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005872
5873 switch (child.mTouchableInsets) {
5874 default:
5875 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5876 inputWindow.touchableAreaLeft = frame.left;
5877 inputWindow.touchableAreaTop = frame.top;
5878 inputWindow.touchableAreaRight = frame.right;
5879 inputWindow.touchableAreaBottom = frame.bottom;
5880 break;
5881
5882 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5883 Rect inset = child.mGivenContentInsets;
5884 inputWindow.touchableAreaLeft = frame.left + inset.left;
5885 inputWindow.touchableAreaTop = frame.top + inset.top;
5886 inputWindow.touchableAreaRight = frame.right - inset.right;
5887 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5888 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005889 }
Jeff Brown349703e2010-06-22 01:27:15 -07005890
5891 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5892 Rect inset = child.mGivenVisibleInsets;
5893 inputWindow.touchableAreaLeft = frame.left + inset.left;
5894 inputWindow.touchableAreaTop = frame.top + inset.top;
5895 inputWindow.touchableAreaRight = frame.right - inset.right;
5896 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005897 break;
5898 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005899 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005900 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005901
Jeff Brown349703e2010-06-22 01:27:15 -07005902 // Send windows to native code.
5903 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005904
Jeff Brown349703e2010-06-22 01:27:15 -07005905 // Clear the list in preparation for the next round.
5906 // Also avoids keeping InputChannel objects referenced unnecessarily.
5907 mTempInputWindows.clear();
5908 }
5909
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005910 /* Notifies that the lid switch changed state. */
5911 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5912 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5913 }
5914
Jeff Brown349703e2010-06-22 01:27:15 -07005915 /* Provides an opportunity for the window manager policy to intercept early key
5916 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08005917 public int interceptKeyBeforeQueueing(
5918 KeyEvent event, int policyFlags, boolean isScreenOn) {
5919 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005920 }
5921
5922 /* Provides an opportunity for the window manager policy to process a key before
5923 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08005924 public boolean interceptKeyBeforeDispatching(
5925 InputChannel focus, KeyEvent event, int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005926 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown1f245102010-11-18 20:53:46 -08005927 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005928 }
5929
Jeff Brown3915bb82010-11-05 15:02:16 -07005930 /* Provides an opportunity for the window manager policy to process a key that
5931 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08005932 public KeyEvent dispatchUnhandledKey(
Jeff Brown1f245102010-11-18 20:53:46 -08005933 InputChannel focus, KeyEvent event, int policyFlags) {
Jeff Brown3915bb82010-11-05 15:02:16 -07005934 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown1f245102010-11-18 20:53:46 -08005935 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07005936 }
5937
Jeff Brown349703e2010-06-22 01:27:15 -07005938 /* Called when the current input focus changes.
5939 * Layer assignment is assumed to be complete by the time this is called.
5940 */
5941 public void setInputFocusLw(WindowState newWindow) {
5942 if (DEBUG_INPUT) {
5943 Slog.d(TAG, "Input focus has changed to " + newWindow);
5944 }
5945
5946 if (newWindow != mInputFocus) {
5947 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005948 // Displaying a window implicitly causes dispatching to be unpaused.
5949 // This is to protect against bugs if someone pauses dispatching but
5950 // forgets to resume.
5951 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005952 }
Jeff Brown349703e2010-06-22 01:27:15 -07005953
5954 mInputFocus = newWindow;
5955 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005956 }
5957 }
5958
Jeff Brown349703e2010-06-22 01:27:15 -07005959 public void setFocusedAppLw(AppWindowToken newApp) {
5960 // Focused app has changed.
5961 if (newApp == null) {
5962 mInputManager.setFocusedApplication(null);
5963 } else {
5964 mTempInputApplication.name = newApp.toString();
5965 mTempInputApplication.dispatchingTimeoutNanos =
5966 newApp.inputDispatchingTimeoutNanos;
5967 mTempInputApplication.token = newApp;
5968
5969 mInputManager.setFocusedApplication(mTempInputApplication);
5970 }
5971 }
5972
Jeff Brown349703e2010-06-22 01:27:15 -07005973 public void pauseDispatchingLw(WindowToken window) {
5974 if (! window.paused) {
5975 if (DEBUG_INPUT) {
5976 Slog.v(TAG, "Pausing WindowToken " + window);
5977 }
5978
5979 window.paused = true;
5980 updateInputWindowsLw();
5981 }
5982 }
5983
5984 public void resumeDispatchingLw(WindowToken window) {
5985 if (window.paused) {
5986 if (DEBUG_INPUT) {
5987 Slog.v(TAG, "Resuming WindowToken " + window);
5988 }
5989
5990 window.paused = false;
5991 updateInputWindowsLw();
5992 }
5993 }
5994
5995 public void freezeInputDispatchingLw() {
5996 if (! mInputDispatchFrozen) {
5997 if (DEBUG_INPUT) {
5998 Slog.v(TAG, "Freezing input dispatching");
5999 }
6000
6001 mInputDispatchFrozen = true;
6002 updateInputDispatchModeLw();
6003 }
6004 }
6005
6006 public void thawInputDispatchingLw() {
6007 if (mInputDispatchFrozen) {
6008 if (DEBUG_INPUT) {
6009 Slog.v(TAG, "Thawing input dispatching");
6010 }
6011
6012 mInputDispatchFrozen = false;
6013 updateInputDispatchModeLw();
6014 }
6015 }
6016
6017 public void setEventDispatchingLw(boolean enabled) {
6018 if (mInputDispatchEnabled != enabled) {
6019 if (DEBUG_INPUT) {
6020 Slog.v(TAG, "Setting event dispatching to " + enabled);
6021 }
6022
6023 mInputDispatchEnabled = enabled;
6024 updateInputDispatchModeLw();
6025 }
6026 }
6027
6028 private void updateInputDispatchModeLw() {
6029 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6030 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006033 public void pauseKeyDispatching(IBinder _token) {
6034 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6035 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006036 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006037 }
6038
6039 synchronized (mWindowMap) {
6040 WindowToken token = mTokenMap.get(_token);
6041 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006042 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006043 }
6044 }
6045 }
6046
6047 public void resumeKeyDispatching(IBinder _token) {
6048 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6049 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006050 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006051 }
6052
6053 synchronized (mWindowMap) {
6054 WindowToken token = mTokenMap.get(_token);
6055 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006056 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006057 }
6058 }
6059 }
6060
6061 public void setEventDispatching(boolean enabled) {
6062 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6063 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006064 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006065 }
6066
6067 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006068 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006069 }
6070 }
Romain Guy06882f82009-06-10 13:36:04 -07006071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 /**
6073 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006074 * Even when sync is false, this method may block while waiting for current
6075 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006076 *
6077 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 * {@link SystemClock#uptimeMillis()} as the timebase.)
6079 * @param sync If true, wait for the event to be completed before returning to the caller.
6080 * @return Returns true if event was dispatched, false if it was dropped for any reason
6081 */
6082 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6083 long downTime = ev.getDownTime();
6084 long eventTime = ev.getEventTime();
6085
6086 int action = ev.getAction();
6087 int code = ev.getKeyCode();
6088 int repeatCount = ev.getRepeatCount();
6089 int metaState = ev.getMetaState();
6090 int deviceId = ev.getDeviceId();
6091 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006092 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006093 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006094
6095 if (source == InputDevice.SOURCE_UNKNOWN) {
6096 source = InputDevice.SOURCE_KEYBOARD;
6097 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098
6099 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6100 if (downTime == 0) downTime = eventTime;
6101
6102 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006103 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006104
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006105 final int pid = Binder.getCallingPid();
6106 final int uid = Binder.getCallingUid();
6107 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006108
Jeff Brownbbda99d2010-07-28 15:48:59 -07006109 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6110 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6111 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6112 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006113
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006114 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006115 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116 }
6117
6118 /**
6119 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006120 * Even when sync is false, this method may block while waiting for current
6121 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006122 *
6123 * @param ev A motion event describing the pointer (touch) action. (As noted in
6124 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006125 * {@link SystemClock#uptimeMillis()} as the timebase.)
6126 * @param sync If true, wait for the event to be completed before returning to the caller.
6127 * @return Returns true if event was dispatched, false if it was dropped for any reason
6128 */
6129 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006130 final int pid = Binder.getCallingPid();
6131 final int uid = Binder.getCallingUid();
6132 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006133
Jeff Brownc5ed5912010-07-14 18:48:53 -07006134 MotionEvent newEvent = MotionEvent.obtain(ev);
6135 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6136 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6137 }
6138
Jeff Brownbbda99d2010-07-28 15:48:59 -07006139 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6140 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6141 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6142 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006143
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006144 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006145 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 }
Romain Guy06882f82009-06-10 13:36:04 -07006147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 /**
6149 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006150 * Even when sync is false, this method may block while waiting for current
6151 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006152 *
6153 * @param ev A motion event describing the trackball action. (As noted in
6154 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155 * {@link SystemClock#uptimeMillis()} as the timebase.)
6156 * @param sync If true, wait for the event to be completed before returning to the caller.
6157 * @return Returns true if event was dispatched, false if it was dropped for any reason
6158 */
6159 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006160 final int pid = Binder.getCallingPid();
6161 final int uid = Binder.getCallingUid();
6162 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006163
Jeff Brownc5ed5912010-07-14 18:48:53 -07006164 MotionEvent newEvent = MotionEvent.obtain(ev);
6165 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6166 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6167 }
6168
Jeff Brownbbda99d2010-07-28 15:48:59 -07006169 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6170 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6171 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6172 INJECTION_TIMEOUT_MILLIS);
6173
6174 Binder.restoreCallingIdentity(ident);
6175 return reportInjectionResult(result);
6176 }
6177
6178 /**
6179 * Inject an input event into the UI without waiting for dispatch to commence.
6180 * This variant is useful for fire-and-forget input event injection. It does not
6181 * block any longer than it takes to enqueue the input event.
6182 *
6183 * @param ev An input event. (Be sure to set the input source correctly.)
6184 * @return Returns true if event was dispatched, false if it was dropped for any reason
6185 */
6186 public boolean injectInputEventNoWait(InputEvent ev) {
6187 final int pid = Binder.getCallingPid();
6188 final int uid = Binder.getCallingUid();
6189 final long ident = Binder.clearCallingIdentity();
6190
6191 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6192 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6193 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006194
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006195 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006196 return reportInjectionResult(result);
6197 }
6198
6199 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006200 switch (result) {
6201 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6202 Slog.w(TAG, "Input event injection permission denied.");
6203 throw new SecurityException(
6204 "Injecting to another application requires INJECT_EVENTS permission");
6205 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006206 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006207 return true;
6208 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6209 Slog.w(TAG, "Input event injection timed out.");
6210 return false;
6211 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6212 default:
6213 Slog.w(TAG, "Input event injection failed.");
6214 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006215 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 }
Romain Guy06882f82009-06-10 13:36:04 -07006217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 private WindowState getFocusedWindow() {
6219 synchronized (mWindowMap) {
6220 return getFocusedWindowLocked();
6221 }
6222 }
6223
6224 private WindowState getFocusedWindowLocked() {
6225 return mCurrentFocus;
6226 }
Romain Guy06882f82009-06-10 13:36:04 -07006227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 public boolean detectSafeMode() {
6229 mSafeMode = mPolicy.detectSafeMode();
6230 return mSafeMode;
6231 }
Romain Guy06882f82009-06-10 13:36:04 -07006232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006233 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006234 synchronized(mWindowMap) {
6235 if (mDisplay != null) {
6236 throw new IllegalStateException("Display already initialized");
6237 }
6238 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6239 mDisplay = wm.getDefaultDisplay();
6240 mInitialDisplayWidth = mDisplay.getWidth();
6241 mInitialDisplayHeight = mDisplay.getHeight();
6242 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6243 }
6244
6245 try {
6246 mActivityManager.updateConfiguration(null);
6247 } catch (RemoteException e) {
6248 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006249
6250 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006251 }
6252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006253 // -------------------------------------------------------------
6254 // Client Session State
6255 // -------------------------------------------------------------
6256
6257 private final class Session extends IWindowSession.Stub
6258 implements IBinder.DeathRecipient {
6259 final IInputMethodClient mClient;
6260 final IInputContext mInputContext;
6261 final int mUid;
6262 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006263 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006264 SurfaceSession mSurfaceSession;
6265 int mNumWindow = 0;
6266 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 public Session(IInputMethodClient client, IInputContext inputContext) {
6269 mClient = client;
6270 mInputContext = inputContext;
6271 mUid = Binder.getCallingUid();
6272 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006273 StringBuilder sb = new StringBuilder();
6274 sb.append("Session{");
6275 sb.append(Integer.toHexString(System.identityHashCode(this)));
6276 sb.append(" uid ");
6277 sb.append(mUid);
6278 sb.append("}");
6279 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 synchronized (mWindowMap) {
6282 if (mInputMethodManager == null && mHaveInputMethods) {
6283 IBinder b = ServiceManager.getService(
6284 Context.INPUT_METHOD_SERVICE);
6285 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6286 }
6287 }
6288 long ident = Binder.clearCallingIdentity();
6289 try {
6290 // Note: it is safe to call in to the input method manager
6291 // here because we are not holding our lock.
6292 if (mInputMethodManager != null) {
6293 mInputMethodManager.addClient(client, inputContext,
6294 mUid, mPid);
6295 } else {
6296 client.setUsingInputMethod(false);
6297 }
6298 client.asBinder().linkToDeath(this, 0);
6299 } catch (RemoteException e) {
6300 // The caller has died, so we can just forget about this.
6301 try {
6302 if (mInputMethodManager != null) {
6303 mInputMethodManager.removeClient(client);
6304 }
6305 } catch (RemoteException ee) {
6306 }
6307 } finally {
6308 Binder.restoreCallingIdentity(ident);
6309 }
6310 }
Romain Guy06882f82009-06-10 13:36:04 -07006311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006312 @Override
6313 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6314 throws RemoteException {
6315 try {
6316 return super.onTransact(code, data, reply, flags);
6317 } catch (RuntimeException e) {
6318 // Log all 'real' exceptions thrown to the caller
6319 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006320 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006321 }
6322 throw e;
6323 }
6324 }
6325
6326 public void binderDied() {
6327 // Note: it is safe to call in to the input method manager
6328 // here because we are not holding our lock.
6329 try {
6330 if (mInputMethodManager != null) {
6331 mInputMethodManager.removeClient(mClient);
6332 }
6333 } catch (RemoteException e) {
6334 }
6335 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006336 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006337 mClientDead = true;
6338 killSessionLocked();
6339 }
6340 }
6341
6342 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006343 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6344 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6345 outInputChannel);
6346 }
6347
6348 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006349 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006350 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006351 }
Romain Guy06882f82009-06-10 13:36:04 -07006352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006353 public void remove(IWindow window) {
6354 removeWindow(this, window);
6355 }
Romain Guy06882f82009-06-10 13:36:04 -07006356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006357 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6358 int requestedWidth, int requestedHeight, int viewFlags,
6359 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006360 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006361 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6362 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006363 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006364 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006365 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6366 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006367 }
Romain Guy06882f82009-06-10 13:36:04 -07006368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 public void setTransparentRegion(IWindow window, Region region) {
6370 setTransparentRegionWindow(this, window, region);
6371 }
Romain Guy06882f82009-06-10 13:36:04 -07006372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006373 public void setInsets(IWindow window, int touchableInsets,
6374 Rect contentInsets, Rect visibleInsets) {
6375 setInsetsWindow(this, window, touchableInsets, contentInsets,
6376 visibleInsets);
6377 }
Romain Guy06882f82009-06-10 13:36:04 -07006378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6380 getWindowDisplayFrame(this, window, outDisplayFrame);
6381 }
Romain Guy06882f82009-06-10 13:36:04 -07006382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006384 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385 TAG, "IWindow finishDrawing called for " + window);
6386 finishDrawingWindow(this, window);
6387 }
6388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 public void setInTouchMode(boolean mode) {
6390 synchronized(mWindowMap) {
6391 mInTouchMode = mode;
6392 }
6393 }
6394
6395 public boolean getInTouchMode() {
6396 synchronized(mWindowMap) {
6397 return mInTouchMode;
6398 }
6399 }
6400
6401 public boolean performHapticFeedback(IWindow window, int effectId,
6402 boolean always) {
6403 synchronized(mWindowMap) {
6404 long ident = Binder.clearCallingIdentity();
6405 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006406 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006407 windowForClientLocked(this, window, true),
6408 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 } finally {
6410 Binder.restoreCallingIdentity(ident);
6411 }
6412 }
6413 }
Romain Guy06882f82009-06-10 13:36:04 -07006414
Christopher Tatea53146c2010-09-07 11:57:52 -07006415 /* Drag/drop */
6416 public IBinder prepareDrag(IWindow window, boolean localOnly,
6417 int width, int height, Surface outSurface) {
6418 return prepareDragSurface(window, mSurfaceSession, localOnly,
6419 width, height, outSurface);
6420 }
6421
6422 public boolean performDrag(IWindow window, IBinder dragToken,
6423 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6424 ClipData data) {
6425 if (DEBUG_DRAG) {
6426 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6427 }
6428
6429 synchronized (mWindowMap) {
6430 if (mDragState == null) {
6431 Slog.w(TAG, "No drag prepared");
6432 throw new IllegalStateException("performDrag() without prepareDrag()");
6433 }
6434
6435 if (dragToken != mDragState.mToken) {
6436 Slog.w(TAG, "Performing mismatched drag");
6437 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6438 }
6439
6440 WindowState callingWin = windowForClientLocked(null, window, false);
6441 if (callingWin == null) {
6442 Slog.w(TAG, "Bad requesting window " + window);
6443 return false; // !!! TODO: throw here?
6444 }
6445
6446 // !!! TODO: if input is not still focused on the initiating window, fail
6447 // the drag initiation (e.g. an alarm window popped up just as the application
6448 // called performDrag()
6449
6450 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6451
Christopher Tate2c095f32010-10-04 14:13:40 -07006452 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6453 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006454
Chris Tateb478f462010-10-15 16:02:26 -07006455 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6456 // the actual drag event dispatch stuff in the dragstate
6457
Christopher Tatea53146c2010-09-07 11:57:52 -07006458 mDragState.register();
6459 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006460 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6461 mDragState.mServerChannel)) {
6462 Slog.e(TAG, "Unable to transfer touch focus");
6463 mDragState.unregister();
6464 mDragState = null;
6465 mInputMonitor.updateInputWindowsLw();
6466 return false;
6467 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006468
6469 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006470 mDragState.mCurrentX = touchX;
6471 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006472 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006473
6474 // remember the thumb offsets for later
6475 mDragState.mThumbOffsetX = thumbCenterX;
6476 mDragState.mThumbOffsetY = thumbCenterY;
6477
6478 // Make the surface visible at the proper location
6479 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006480 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006481 try {
6482 surface.setPosition((int)(touchX - thumbCenterX),
6483 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006484 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006485 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006486 surface.show();
6487 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006488 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006489 }
6490 }
6491
6492 return true; // success!
6493 }
6494
Chris Tated4533f142010-10-19 15:15:08 -07006495 public void reportDropResult(IWindow window, boolean consumed) {
6496 IBinder token = window.asBinder();
6497 if (DEBUG_DRAG) {
6498 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6499 }
6500
6501 synchronized (mWindowMap) {
6502 if (mDragState.mToken != token) {
6503 Slog.w(TAG, "Invalid drop-result claim by " + window);
6504 throw new IllegalStateException("reportDropResult() by non-recipient");
6505 }
6506
6507 // The right window has responded, even if it's no longer around,
6508 // so be sure to halt the timeout even if the later WindowState
6509 // lookup fails.
6510 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6511
6512 WindowState callingWin = windowForClientLocked(null, window, false);
6513 if (callingWin == null) {
6514 Slog.w(TAG, "Bad result-reporting window " + window);
6515 return; // !!! TODO: throw here?
6516 }
6517
6518 mDragState.mDragResult = consumed;
6519 mDragState.endDragLw();
6520 }
6521 }
6522
Christopher Tatea53146c2010-09-07 11:57:52 -07006523 public void dragRecipientEntered(IWindow window) {
6524 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006525 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006526 }
6527 }
6528
6529 public void dragRecipientExited(IWindow window) {
6530 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006531 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006532 }
6533 }
6534
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006535 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006536 synchronized(mWindowMap) {
6537 long ident = Binder.clearCallingIdentity();
6538 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006539 setWindowWallpaperPositionLocked(
6540 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006541 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006542 } finally {
6543 Binder.restoreCallingIdentity(ident);
6544 }
6545 }
6546 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006547
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006548 public void wallpaperOffsetsComplete(IBinder window) {
6549 WindowManagerService.this.wallpaperOffsetsComplete(window);
6550 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006551
Dianne Hackborn75804932009-10-20 20:15:20 -07006552 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6553 int z, Bundle extras, boolean sync) {
6554 synchronized(mWindowMap) {
6555 long ident = Binder.clearCallingIdentity();
6556 try {
6557 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006558 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006559 action, x, y, z, extras, sync);
6560 } finally {
6561 Binder.restoreCallingIdentity(ident);
6562 }
6563 }
6564 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006565
Dianne Hackborn75804932009-10-20 20:15:20 -07006566 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6567 WindowManagerService.this.wallpaperCommandComplete(window, result);
6568 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 void windowAddedLocked() {
6571 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006572 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 TAG, "First window added to " + this + ", creating SurfaceSession");
6574 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006575 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006576 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006577 mSessions.add(this);
6578 }
6579 mNumWindow++;
6580 }
6581
6582 void windowRemovedLocked() {
6583 mNumWindow--;
6584 killSessionLocked();
6585 }
Romain Guy06882f82009-06-10 13:36:04 -07006586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 void killSessionLocked() {
6588 if (mNumWindow <= 0 && mClientDead) {
6589 mSessions.remove(this);
6590 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006591 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006592 TAG, "Last window removed from " + this
6593 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006594 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006595 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006596 try {
6597 mSurfaceSession.kill();
6598 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006599 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 + mSurfaceSession + " in session " + this
6601 + ": " + e.toString());
6602 }
6603 mSurfaceSession = null;
6604 }
6605 }
6606 }
Romain Guy06882f82009-06-10 13:36:04 -07006607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006608 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006609 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6610 pw.print(" mClientDead="); pw.print(mClientDead);
6611 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006612 }
6613
6614 @Override
6615 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006616 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006617 }
6618 }
6619
6620 // -------------------------------------------------------------
6621 // Client Window State
6622 // -------------------------------------------------------------
6623
6624 private final class WindowState implements WindowManagerPolicy.WindowState {
6625 final Session mSession;
6626 final IWindow mClient;
6627 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006628 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 AppWindowToken mAppToken;
6630 AppWindowToken mTargetAppToken;
6631 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6632 final DeathRecipient mDeathRecipient;
6633 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006634 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 final int mBaseLayer;
6636 final int mSubLayer;
6637 final boolean mLayoutAttached;
6638 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006639 final boolean mIsWallpaper;
6640 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006641 int mViewVisibility;
6642 boolean mPolicyVisibility = true;
6643 boolean mPolicyVisibilityAfterAnim = true;
6644 boolean mAppFreezing;
6645 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006646 boolean mReportDestroySurface;
6647 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006648 boolean mAttachedHidden; // is our parent window hidden?
6649 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006650 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 int mRequestedWidth;
6652 int mRequestedHeight;
6653 int mLastRequestedWidth;
6654 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 int mLayer;
6656 int mAnimLayer;
6657 int mLastLayer;
6658 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006659 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006660 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006661
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006662 int mLayoutSeq = -1;
6663
6664 Configuration mConfiguration = null;
6665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006666 // Actual frame shown on-screen (may be modified by animation)
6667 final Rect mShownFrame = new Rect();
6668 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006670 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006671 * Set when we have changed the size of the surface, to know that
6672 * we must tell them application to resize (and thus redraw itself).
6673 */
6674 boolean mSurfaceResized;
6675
6676 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006677 * Insets that determine the actually visible area
6678 */
6679 final Rect mVisibleInsets = new Rect();
6680 final Rect mLastVisibleInsets = new Rect();
6681 boolean mVisibleInsetsChanged;
6682
6683 /**
6684 * Insets that are covered by system windows
6685 */
6686 final Rect mContentInsets = new Rect();
6687 final Rect mLastContentInsets = new Rect();
6688 boolean mContentInsetsChanged;
6689
6690 /**
6691 * Set to true if we are waiting for this window to receive its
6692 * given internal insets before laying out other windows based on it.
6693 */
6694 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006696 /**
6697 * These are the content insets that were given during layout for
6698 * this window, to be applied to windows behind it.
6699 */
6700 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 /**
6703 * These are the visible insets that were given during layout for
6704 * this window, to be applied to windows behind it.
6705 */
6706 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006708 /**
6709 * Flag indicating whether the touchable region should be adjusted by
6710 * the visible insets; if false the area outside the visible insets is
6711 * NOT touchable, so we must use those to adjust the frame during hit
6712 * tests.
6713 */
6714 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 // Current transformation being applied.
6717 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6718 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6719 float mHScale=1, mVScale=1;
6720 float mLastHScale=1, mLastVScale=1;
6721 final Matrix mTmpMatrix = new Matrix();
6722
6723 // "Real" frame that the application sees.
6724 final Rect mFrame = new Rect();
6725 final Rect mLastFrame = new Rect();
6726
6727 final Rect mContainingFrame = new Rect();
6728 final Rect mDisplayFrame = new Rect();
6729 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006730 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006731 final Rect mVisibleFrame = new Rect();
6732
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006733 boolean mContentChanged;
6734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006735 float mShownAlpha = 1;
6736 float mAlpha = 1;
6737 float mLastAlpha = 1;
6738
6739 // Set to true if, when the window gets displayed, it should perform
6740 // an enter animation.
6741 boolean mEnterAnimationPending;
6742
6743 // Currently running animation.
6744 boolean mAnimating;
6745 boolean mLocalAnimating;
6746 Animation mAnimation;
6747 boolean mAnimationIsEntrance;
6748 boolean mHasTransformation;
6749 boolean mHasLocalTransformation;
6750 final Transformation mTransformation = new Transformation();
6751
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006752 // If a window showing a wallpaper: the requested offset for the
6753 // wallpaper; if a wallpaper window: the currently applied offset.
6754 float mWallpaperX = -1;
6755 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006756
6757 // If a window showing a wallpaper: what fraction of the offset
6758 // range corresponds to a full virtual screen.
6759 float mWallpaperXStep = -1;
6760 float mWallpaperYStep = -1;
6761
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006762 // Wallpaper windows: pixels offset based on above variables.
6763 int mXOffset;
6764 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006766 // This is set after IWindowSession.relayout() has been called at
6767 // least once for the window. It allows us to detect the situation
6768 // where we don't yet have a surface, but should have one soon, so
6769 // we can give the window focus before waiting for the relayout.
6770 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 // This is set after the Surface has been created but before the
6773 // window has been drawn. During this time the surface is hidden.
6774 boolean mDrawPending;
6775
6776 // This is set after the window has finished drawing for the first
6777 // time but before its surface is shown. The surface will be
6778 // displayed when the next layout is run.
6779 boolean mCommitDrawPending;
6780
6781 // This is set during the time after the window's drawing has been
6782 // committed, and before its surface is actually shown. It is used
6783 // to delay showing the surface until all windows in a token are ready
6784 // to be shown.
6785 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006787 // Set when the window has been shown in the screen the first time.
6788 boolean mHasDrawn;
6789
6790 // Currently running an exit animation?
6791 boolean mExiting;
6792
6793 // Currently on the mDestroySurface list?
6794 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006796 // Completely remove from window manager after exit animation?
6797 boolean mRemoveOnExit;
6798
6799 // Set when the orientation is changing and this window has not yet
6800 // been updated for the new orientation.
6801 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 // Is this window now (or just being) removed?
6804 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006805
Dianne Hackborn16064f92010-03-25 00:47:24 -07006806 // For debugging, this is the last information given to the surface flinger.
6807 boolean mSurfaceShown;
6808 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6809 int mSurfaceLayer;
6810 float mSurfaceAlpha;
6811
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006812 // Input channel
6813 InputChannel mInputChannel;
6814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 WindowState(Session s, IWindow c, WindowToken token,
6816 WindowState attachedWindow, WindowManager.LayoutParams a,
6817 int viewVisibility) {
6818 mSession = s;
6819 mClient = c;
6820 mToken = token;
6821 mAttrs.copyFrom(a);
6822 mViewVisibility = viewVisibility;
6823 DeathRecipient deathRecipient = new DeathRecipient();
6824 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006825 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006826 TAG, "Window " + this + " client=" + c.asBinder()
6827 + " token=" + token + " (" + mAttrs.token + ")");
6828 try {
6829 c.asBinder().linkToDeath(deathRecipient, 0);
6830 } catch (RemoteException e) {
6831 mDeathRecipient = null;
6832 mAttachedWindow = null;
6833 mLayoutAttached = false;
6834 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006835 mIsWallpaper = false;
6836 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006837 mBaseLayer = 0;
6838 mSubLayer = 0;
6839 return;
6840 }
6841 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6844 mAttrs.type <= LAST_SUB_WINDOW)) {
6845 // The multiplier here is to reserve space for multiple
6846 // windows in the same type layer.
6847 mBaseLayer = mPolicy.windowTypeToLayerLw(
6848 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6849 + TYPE_LAYER_OFFSET;
6850 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6851 mAttachedWindow = attachedWindow;
6852 mAttachedWindow.mChildWindows.add(this);
6853 mLayoutAttached = mAttrs.type !=
6854 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6855 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6856 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006857 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6858 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006859 } else {
6860 // The multiplier here is to reserve space for multiple
6861 // windows in the same type layer.
6862 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6863 * TYPE_LAYER_MULTIPLIER
6864 + TYPE_LAYER_OFFSET;
6865 mSubLayer = 0;
6866 mAttachedWindow = null;
6867 mLayoutAttached = false;
6868 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6869 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006870 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6871 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006872 }
6873
6874 WindowState appWin = this;
6875 while (appWin.mAttachedWindow != null) {
6876 appWin = mAttachedWindow;
6877 }
6878 WindowToken appToken = appWin.mToken;
6879 while (appToken.appWindowToken == null) {
6880 WindowToken parent = mTokenMap.get(appToken.token);
6881 if (parent == null || appToken == parent) {
6882 break;
6883 }
6884 appToken = parent;
6885 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006886 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 mAppToken = appToken.appWindowToken;
6888
6889 mSurface = null;
6890 mRequestedWidth = 0;
6891 mRequestedHeight = 0;
6892 mLastRequestedWidth = 0;
6893 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006894 mXOffset = 0;
6895 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006896 mLayer = 0;
6897 mAnimLayer = 0;
6898 mLastLayer = 0;
6899 }
6900
6901 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006902 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 TAG, "Attaching " + this + " token=" + mToken
6904 + ", list=" + mToken.windows);
6905 mSession.windowAddedLocked();
6906 }
6907
6908 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6909 mHaveFrame = true;
6910
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006911 final Rect container = mContainingFrame;
6912 container.set(pf);
6913
6914 final Rect display = mDisplayFrame;
6915 display.set(df);
6916
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006917 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006918 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006919 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6920 display.intersect(mCompatibleScreenFrame);
6921 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006922 }
6923
6924 final int pw = container.right - container.left;
6925 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006926
6927 int w,h;
6928 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6929 w = mAttrs.width < 0 ? pw : mAttrs.width;
6930 h = mAttrs.height< 0 ? ph : mAttrs.height;
6931 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006932 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6933 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006934 }
Romain Guy06882f82009-06-10 13:36:04 -07006935
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006936 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006937 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
6938 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006939 mParentFrame.set(pf);
6940 mContentChanged = true;
6941 }
6942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006943 final Rect content = mContentFrame;
6944 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 final Rect visible = mVisibleFrame;
6947 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006950 final int fw = frame.width();
6951 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006953 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6954 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6955
6956 Gravity.apply(mAttrs.gravity, w, h, container,
6957 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6958 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6959
6960 //System.out.println("Out: " + mFrame);
6961
6962 // Now make sure the window fits in the overall display.
6963 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006965 // Make sure the content and visible frames are inside of the
6966 // final window frame.
6967 if (content.left < frame.left) content.left = frame.left;
6968 if (content.top < frame.top) content.top = frame.top;
6969 if (content.right > frame.right) content.right = frame.right;
6970 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6971 if (visible.left < frame.left) visible.left = frame.left;
6972 if (visible.top < frame.top) visible.top = frame.top;
6973 if (visible.right > frame.right) visible.right = frame.right;
6974 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006976 final Rect contentInsets = mContentInsets;
6977 contentInsets.left = content.left-frame.left;
6978 contentInsets.top = content.top-frame.top;
6979 contentInsets.right = frame.right-content.right;
6980 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006982 final Rect visibleInsets = mVisibleInsets;
6983 visibleInsets.left = visible.left-frame.left;
6984 visibleInsets.top = visible.top-frame.top;
6985 visibleInsets.right = frame.right-visible.right;
6986 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006987
Dianne Hackborn284ac932009-08-28 10:34:25 -07006988 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6989 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006990 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006991 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006993 if (localLOGV) {
6994 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6995 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006996 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006997 + mRequestedWidth + ", mRequestedheight="
6998 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6999 + "): frame=" + mFrame.toShortString()
7000 + " ci=" + contentInsets.toShortString()
7001 + " vi=" + visibleInsets.toShortString());
7002 //}
7003 }
7004 }
Romain Guy06882f82009-06-10 13:36:04 -07007005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007006 public Rect getFrameLw() {
7007 return mFrame;
7008 }
7009
7010 public Rect getShownFrameLw() {
7011 return mShownFrame;
7012 }
7013
7014 public Rect getDisplayFrameLw() {
7015 return mDisplayFrame;
7016 }
7017
7018 public Rect getContentFrameLw() {
7019 return mContentFrame;
7020 }
7021
7022 public Rect getVisibleFrameLw() {
7023 return mVisibleFrame;
7024 }
7025
7026 public boolean getGivenInsetsPendingLw() {
7027 return mGivenInsetsPending;
7028 }
7029
7030 public Rect getGivenContentInsetsLw() {
7031 return mGivenContentInsets;
7032 }
Romain Guy06882f82009-06-10 13:36:04 -07007033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 public Rect getGivenVisibleInsetsLw() {
7035 return mGivenVisibleInsets;
7036 }
Romain Guy06882f82009-06-10 13:36:04 -07007037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 public WindowManager.LayoutParams getAttrs() {
7039 return mAttrs;
7040 }
7041
7042 public int getSurfaceLayer() {
7043 return mLayer;
7044 }
Romain Guy06882f82009-06-10 13:36:04 -07007045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007046 public IApplicationToken getAppToken() {
7047 return mAppToken != null ? mAppToken.appToken : null;
7048 }
Jeff Brown349703e2010-06-22 01:27:15 -07007049
7050 public long getInputDispatchingTimeoutNanos() {
7051 return mAppToken != null
7052 ? mAppToken.inputDispatchingTimeoutNanos
7053 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7054 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007055
7056 public boolean hasAppShownWindows() {
7057 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7058 }
7059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007060 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007061 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007062 TAG, "Setting animation in " + this + ": " + anim);
7063 mAnimating = false;
7064 mLocalAnimating = false;
7065 mAnimation = anim;
7066 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7067 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7068 }
7069
7070 public void clearAnimation() {
7071 if (mAnimation != null) {
7072 mAnimating = true;
7073 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007074 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007075 mAnimation = null;
7076 }
7077 }
Romain Guy06882f82009-06-10 13:36:04 -07007078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 Surface createSurfaceLocked() {
7080 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007081 mReportDestroySurface = false;
7082 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 mDrawPending = true;
7084 mCommitDrawPending = false;
7085 mReadyToShow = false;
7086 if (mAppToken != null) {
7087 mAppToken.allDrawn = false;
7088 }
7089
7090 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007091 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007092 flags |= Surface.PUSH_BUFFERS;
7093 }
7094
7095 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7096 flags |= Surface.SECURE;
7097 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007098 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 TAG, "Creating surface in session "
7100 + mSession.mSurfaceSession + " window " + this
7101 + " w=" + mFrame.width()
7102 + " h=" + mFrame.height() + " format="
7103 + mAttrs.format + " flags=" + flags);
7104
7105 int w = mFrame.width();
7106 int h = mFrame.height();
7107 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7108 // for a scaled surface, we always want the requested
7109 // size.
7110 w = mRequestedWidth;
7111 h = mRequestedHeight;
7112 }
7113
Romain Guy9825ec62009-10-01 00:58:09 -07007114 // Something is wrong and SurfaceFlinger will not like this,
7115 // try to revert to sane values
7116 if (w <= 0) w = 1;
7117 if (h <= 0) h = 1;
7118
Dianne Hackborn16064f92010-03-25 00:47:24 -07007119 mSurfaceShown = false;
7120 mSurfaceLayer = 0;
7121 mSurfaceAlpha = 1;
7122 mSurfaceX = 0;
7123 mSurfaceY = 0;
7124 mSurfaceW = w;
7125 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007127 final boolean isHwAccelerated = (mAttrs.flags &
7128 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7129 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7130 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7131 flags |= Surface.OPAQUE;
7132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007133 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007134 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007135 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007136 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007137 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007138 + mSurface + " IN SESSION "
7139 + mSession.mSurfaceSession
7140 + ": pid=" + mSession.mPid + " format="
7141 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007142 + Integer.toHexString(flags)
7143 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007144 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007145 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007146 reclaimSomeSurfaceMemoryLocked(this, "create");
7147 return null;
7148 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007149 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 return null;
7151 }
Romain Guy06882f82009-06-10 13:36:04 -07007152
Joe Onorato8a9b2202010-02-26 18:56:32 -08007153 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007154 TAG, "Got surface: " + mSurface
7155 + ", set left=" + mFrame.left + " top=" + mFrame.top
7156 + ", animLayer=" + mAnimLayer);
7157 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007158 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007159 if (SHOW_TRANSACTIONS) logSurface(this,
7160 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7161 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7162 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007163 }
7164 Surface.openTransaction();
7165 try {
7166 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007167 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007168 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007169 mSurface.setPosition(mSurfaceX, mSurfaceY);
7170 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007171 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007172 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007173 mSurface.hide();
7174 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007175 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007176 mSurface.setFlags(Surface.SURFACE_DITHER,
7177 Surface.SURFACE_DITHER);
7178 }
7179 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007180 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007181 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7182 }
7183 mLastHidden = true;
7184 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007185 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007186 Surface.closeTransaction();
7187 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007188 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007189 TAG, "Created surface " + this);
7190 }
7191 return mSurface;
7192 }
Romain Guy06882f82009-06-10 13:36:04 -07007193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 if (mAppToken != null && this == mAppToken.startingWindow) {
7196 mAppToken.startingDisplayed = false;
7197 }
Romain Guy06882f82009-06-10 13:36:04 -07007198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007200 mDrawPending = false;
7201 mCommitDrawPending = false;
7202 mReadyToShow = false;
7203
7204 int i = mChildWindows.size();
7205 while (i > 0) {
7206 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007207 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007208 c.mAttachedHidden = true;
7209 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007210
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007211 if (mReportDestroySurface) {
7212 mReportDestroySurface = false;
7213 mSurfacePendingDestroy = true;
7214 try {
7215 mClient.dispatchGetNewSurface();
7216 // We'll really destroy on the next time around.
7217 return;
7218 } catch (RemoteException e) {
7219 }
7220 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007222 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007223 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007224 RuntimeException e = null;
7225 if (!HIDE_STACK_CRAWLS) {
7226 e = new RuntimeException();
7227 e.fillInStackTrace();
7228 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007229 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007230 + mSurface + ", session " + mSession, e);
7231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007233 RuntimeException e = null;
7234 if (!HIDE_STACK_CRAWLS) {
7235 e = new RuntimeException();
7236 e.fillInStackTrace();
7237 }
7238 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007240 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007241 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007242 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007243 + " surface " + mSurface + " session " + mSession
7244 + ": " + e.toString());
7245 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007246
Dianne Hackborn16064f92010-03-25 00:47:24 -07007247 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007249 }
7250 }
7251
7252 boolean finishDrawingLocked() {
7253 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007254 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 TAG, "finishDrawingLocked: " + mSurface);
7256 mCommitDrawPending = true;
7257 mDrawPending = false;
7258 return true;
7259 }
7260 return false;
7261 }
7262
7263 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007264 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007265 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007266 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007267 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 }
7269 mCommitDrawPending = false;
7270 mReadyToShow = true;
7271 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7272 final AppWindowToken atoken = mAppToken;
7273 if (atoken == null || atoken.allDrawn || starting) {
7274 performShowLocked();
7275 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007276 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007277 }
7278
7279 // This must be called while inside a transaction.
7280 boolean performShowLocked() {
7281 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007282 RuntimeException e = null;
7283 if (!HIDE_STACK_CRAWLS) {
7284 e = new RuntimeException();
7285 e.fillInStackTrace();
7286 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007287 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007288 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7289 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7290 }
7291 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007292 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7293 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007294 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 + " during animation: policyVis=" + mPolicyVisibility
7296 + " attHidden=" + mAttachedHidden
7297 + " tok.hiddenRequested="
7298 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007299 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 + (mAppToken != null ? mAppToken.hidden : false)
7301 + " animating=" + mAnimating
7302 + " tok animating="
7303 + (mAppToken != null ? mAppToken.animating : false));
7304 if (!showSurfaceRobustlyLocked(this)) {
7305 return false;
7306 }
7307 mLastAlpha = -1;
7308 mHasDrawn = true;
7309 mLastHidden = false;
7310 mReadyToShow = false;
7311 enableScreenIfNeededLocked();
7312
7313 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007315 int i = mChildWindows.size();
7316 while (i > 0) {
7317 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007318 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007319 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007320 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007321 if (c.mSurface != null) {
7322 c.performShowLocked();
7323 // It hadn't been shown, which means layout not
7324 // performed on it, so now we want to make sure to
7325 // do a layout. If called from within the transaction
7326 // loop, this will cause it to restart with a new
7327 // layout.
7328 mLayoutNeeded = true;
7329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 }
7331 }
Romain Guy06882f82009-06-10 13:36:04 -07007332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007333 if (mAttrs.type != TYPE_APPLICATION_STARTING
7334 && mAppToken != null) {
7335 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007336
Dianne Hackborn248b1882009-09-16 16:46:44 -07007337 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007338 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007339 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007341 // If this initial window is animating, stop it -- we
7342 // will do an animation to reveal it from behind the
7343 // starting window, so there is no need for it to also
7344 // be doing its own stuff.
7345 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007346 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007347 mAnimation = null;
7348 // Make sure we clean up the animation.
7349 mAnimating = true;
7350 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007351 mFinishedStarting.add(mAppToken);
7352 mH.sendEmptyMessage(H.FINISHED_STARTING);
7353 }
7354 mAppToken.updateReportedVisibilityLocked();
7355 }
7356 }
7357 return true;
7358 }
Romain Guy06882f82009-06-10 13:36:04 -07007359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007360 // This must be called while inside a transaction. Returns true if
7361 // there is more animation to run.
7362 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007363 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007364 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007366 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7367 mHasTransformation = true;
7368 mHasLocalTransformation = true;
7369 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007370 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007371 TAG, "Starting animation in " + this +
7372 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7373 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7374 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7375 mAnimation.setStartTime(currentTime);
7376 mLocalAnimating = true;
7377 mAnimating = true;
7378 }
7379 mTransformation.clear();
7380 final boolean more = mAnimation.getTransformation(
7381 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007382 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 TAG, "Stepped animation in " + this +
7384 ": more=" + more + ", xform=" + mTransformation);
7385 if (more) {
7386 // we're not done!
7387 return true;
7388 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007389 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007390 TAG, "Finished animation in " + this +
7391 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007392
7393 if (mAnimation != null) {
7394 mAnimation.cancel();
7395 mAnimation = null;
7396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007397 //WindowManagerService.this.dump();
7398 }
7399 mHasLocalTransformation = false;
7400 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007401 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 // When our app token is animating, we kind-of pretend like
7403 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7404 // part of this check means that we will only do this if
7405 // our window is not currently exiting, or it is not
7406 // locally animating itself. The idea being that one that
7407 // is exiting and doing a local animation should be removed
7408 // once that animation is done.
7409 mAnimating = true;
7410 mHasTransformation = true;
7411 mTransformation.clear();
7412 return false;
7413 } else if (mHasTransformation) {
7414 // Little trick to get through the path below to act like
7415 // we have finished an animation.
7416 mAnimating = true;
7417 } else if (isAnimating()) {
7418 mAnimating = true;
7419 }
7420 } else if (mAnimation != null) {
7421 // If the display is frozen, and there is a pending animation,
7422 // clear it and make sure we run the cleanup code.
7423 mAnimating = true;
7424 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007425 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007426 mAnimation = null;
7427 }
Romain Guy06882f82009-06-10 13:36:04 -07007428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 if (!mAnimating && !mLocalAnimating) {
7430 return false;
7431 }
7432
Joe Onorato8a9b2202010-02-26 18:56:32 -08007433 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007434 TAG, "Animation done in " + this + ": exiting=" + mExiting
7435 + ", reportedVisible="
7436 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 mAnimating = false;
7439 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007440 if (mAnimation != null) {
7441 mAnimation.cancel();
7442 mAnimation = null;
7443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 mAnimLayer = mLayer;
7445 if (mIsImWindow) {
7446 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007447 } else if (mIsWallpaper) {
7448 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007450 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 + " anim layer: " + mAnimLayer);
7452 mHasTransformation = false;
7453 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007454 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7455 if (DEBUG_VISIBILITY) {
7456 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7457 + mPolicyVisibilityAfterAnim);
7458 }
7459 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7460 if (!mPolicyVisibility) {
7461 if (mCurrentFocus == this) {
7462 mFocusMayChange = true;
7463 }
7464 // Window is no longer visible -- make sure if we were waiting
7465 // for it to be displayed before enabling the display, that
7466 // we allow the display to be enabled now.
7467 enableScreenIfNeededLocked();
7468 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 mTransformation.clear();
7471 if (mHasDrawn
7472 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7473 && mAppToken != null
7474 && mAppToken.firstWindowDrawn
7475 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007476 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 + mToken + ": first real window done animating");
7478 mFinishedStarting.add(mAppToken);
7479 mH.sendEmptyMessage(H.FINISHED_STARTING);
7480 }
Romain Guy06882f82009-06-10 13:36:04 -07007481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007482 finishExit();
7483
7484 if (mAppToken != null) {
7485 mAppToken.updateReportedVisibilityLocked();
7486 }
7487
7488 return false;
7489 }
7490
7491 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007492 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 TAG, "finishExit in " + this
7494 + ": exiting=" + mExiting
7495 + " remove=" + mRemoveOnExit
7496 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 final int N = mChildWindows.size();
7499 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007500 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 }
Romain Guy06882f82009-06-10 13:36:04 -07007502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 if (!mExiting) {
7504 return;
7505 }
Romain Guy06882f82009-06-10 13:36:04 -07007506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 if (isWindowAnimating()) {
7508 return;
7509 }
7510
Joe Onorato8a9b2202010-02-26 18:56:32 -08007511 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 TAG, "Exit animation finished in " + this
7513 + ": remove=" + mRemoveOnExit);
7514 if (mSurface != null) {
7515 mDestroySurface.add(this);
7516 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007517 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007518 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007519 try {
7520 mSurface.hide();
7521 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007522 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007523 }
7524 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 }
7526 mExiting = false;
7527 if (mRemoveOnExit) {
7528 mPendingRemove.add(this);
7529 mRemoveOnExit = false;
7530 }
7531 }
Romain Guy06882f82009-06-10 13:36:04 -07007532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007533 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7534 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7535 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7536 if (dtdx < -.000001f || dtdx > .000001f) return false;
7537 if (dsdy < -.000001f || dsdy > .000001f) return false;
7538 return true;
7539 }
Romain Guy06882f82009-06-10 13:36:04 -07007540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007541 void computeShownFrameLocked() {
7542 final boolean selfTransformation = mHasLocalTransformation;
7543 Transformation attachedTransformation =
7544 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7545 ? mAttachedWindow.mTransformation : null;
7546 Transformation appTransformation =
7547 (mAppToken != null && mAppToken.hasTransformation)
7548 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007549
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007550 // Wallpapers are animated based on the "real" window they
7551 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007552 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007553 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007554 if (mWallpaperTarget.mHasLocalTransformation &&
7555 mWallpaperTarget.mAnimation != null &&
7556 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007557 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007558 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007559 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007560 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007561 }
7562 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007563 mWallpaperTarget.mAppToken.hasTransformation &&
7564 mWallpaperTarget.mAppToken.animation != null &&
7565 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007566 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007567 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007568 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007569 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007570 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007571 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007572
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007573 final boolean screenAnimation = mScreenRotationAnimation != null
7574 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007576 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007577 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007578 final Rect frame = mFrame;
7579 final float tmpFloats[] = mTmpFloats;
7580 final Matrix tmpMatrix = mTmpMatrix;
7581
7582 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007583 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007585 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007586 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007587 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007589 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007590 }
7591 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007592 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007594 if (screenAnimation) {
7595 tmpMatrix.postConcat(
7596 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007598
7599 // "convert" it into SurfaceFlinger's format
7600 // (a 2x2 matrix + an offset)
7601 // Here we must not transform the position of the surface
7602 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007603 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 tmpMatrix.getValues(tmpFloats);
7606 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007607 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7608 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007610 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7611 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 int w = frame.width();
7613 int h = frame.height();
7614 mShownFrame.set(x, y, x+w, y+h);
7615
7616 // Now set the alpha... but because our current hardware
7617 // can't do alpha transformation on a non-opaque surface,
7618 // turn it off if we are running an animation that is also
7619 // transforming since it is more important to have that
7620 // animation be smooth.
7621 mShownAlpha = mAlpha;
7622 if (!mLimitedAlphaCompositing
7623 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7624 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7625 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007626 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 if (selfTransformation) {
7628 mShownAlpha *= mTransformation.getAlpha();
7629 }
7630 if (attachedTransformation != null) {
7631 mShownAlpha *= attachedTransformation.getAlpha();
7632 }
7633 if (appTransformation != null) {
7634 mShownAlpha *= appTransformation.getAlpha();
7635 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007636 if (screenAnimation) {
7637 mShownAlpha *=
7638 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007641 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007642 }
Romain Guy06882f82009-06-10 13:36:04 -07007643
Joe Onorato8a9b2202010-02-26 18:56:32 -08007644 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007645 TAG, "Continuing animation in " + this +
7646 ": " + mShownFrame +
7647 ", alpha=" + mTransformation.getAlpha());
7648 return;
7649 }
Romain Guy06882f82009-06-10 13:36:04 -07007650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007652 if (mXOffset != 0 || mYOffset != 0) {
7653 mShownFrame.offset(mXOffset, mYOffset);
7654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007655 mShownAlpha = mAlpha;
7656 mDsDx = 1;
7657 mDtDx = 0;
7658 mDsDy = 0;
7659 mDtDy = 1;
7660 }
Romain Guy06882f82009-06-10 13:36:04 -07007661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007662 /**
7663 * Is this window visible? It is not visible if there is no
7664 * surface, or we are in the process of running an exit animation
7665 * that will remove the surface, or its app token has been hidden.
7666 */
7667 public boolean isVisibleLw() {
7668 final AppWindowToken atoken = mAppToken;
7669 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7670 && (atoken == null || !atoken.hiddenRequested)
7671 && !mExiting && !mDestroying;
7672 }
7673
7674 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007675 * Like {@link #isVisibleLw}, but also counts a window that is currently
7676 * "hidden" behind the keyguard as visible. This allows us to apply
7677 * things like window flags that impact the keyguard.
7678 * XXX I am starting to think we need to have ANOTHER visibility flag
7679 * for this "hidden behind keyguard" state rather than overloading
7680 * mPolicyVisibility. Ungh.
7681 */
7682 public boolean isVisibleOrBehindKeyguardLw() {
7683 final AppWindowToken atoken = mAppToken;
7684 return mSurface != null && !mAttachedHidden
7685 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007686 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007687 && !mExiting && !mDestroying;
7688 }
7689
7690 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007691 * Is this window visible, ignoring its app token? It is not visible
7692 * if there is no surface, or we are in the process of running an exit animation
7693 * that will remove the surface.
7694 */
7695 public boolean isWinVisibleLw() {
7696 final AppWindowToken atoken = mAppToken;
7697 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7698 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7699 && !mExiting && !mDestroying;
7700 }
7701
7702 /**
7703 * The same as isVisible(), but follows the current hidden state of
7704 * the associated app token, not the pending requested hidden state.
7705 */
7706 boolean isVisibleNow() {
7707 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007708 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007709 }
7710
7711 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007712 * Can this window possibly be a drag/drop target? The test here is
7713 * a combination of the above "visible now" with the check that the
7714 * Input Manager uses when discarding windows from input consideration.
7715 */
7716 boolean isPotentialDragTarget() {
7717 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7718 }
7719
7720 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007721 * Same as isVisible(), but we also count it as visible between the
7722 * call to IWindowSession.add() and the first relayout().
7723 */
7724 boolean isVisibleOrAdding() {
7725 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007726 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007727 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7728 && mPolicyVisibility && !mAttachedHidden
7729 && (atoken == null || !atoken.hiddenRequested)
7730 && !mExiting && !mDestroying;
7731 }
7732
7733 /**
7734 * Is this window currently on-screen? It is on-screen either if it
7735 * is visible or it is currently running an animation before no longer
7736 * being visible.
7737 */
7738 boolean isOnScreen() {
7739 final AppWindowToken atoken = mAppToken;
7740 if (atoken != null) {
7741 return mSurface != null && mPolicyVisibility && !mDestroying
7742 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007743 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007744 } else {
7745 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007746 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007747 }
7748 }
Romain Guy06882f82009-06-10 13:36:04 -07007749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 /**
7751 * Like isOnScreen(), but we don't return true if the window is part
7752 * of a transition that has not yet been started.
7753 */
7754 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007755 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007756 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007757 return false;
7758 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007760 final boolean animating = atoken != null
7761 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007762 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007763 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7764 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007765 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007766 }
7767
7768 /** Is the window or its container currently animating? */
7769 boolean isAnimating() {
7770 final WindowState attached = mAttachedWindow;
7771 final AppWindowToken atoken = mAppToken;
7772 return mAnimation != null
7773 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007774 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 (atoken.animation != null
7776 || atoken.inPendingTransaction));
7777 }
7778
7779 /** Is this window currently animating? */
7780 boolean isWindowAnimating() {
7781 return mAnimation != null;
7782 }
7783
7784 /**
7785 * Like isOnScreen, but returns false if the surface hasn't yet
7786 * been drawn.
7787 */
7788 public boolean isDisplayedLw() {
7789 final AppWindowToken atoken = mAppToken;
7790 return mSurface != null && mPolicyVisibility && !mDestroying
7791 && !mDrawPending && !mCommitDrawPending
7792 && ((!mAttachedHidden &&
7793 (atoken == null || !atoken.hiddenRequested))
7794 || mAnimating);
7795 }
7796
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007797 /**
7798 * Returns true if the window has a surface that it has drawn a
7799 * complete UI in to.
7800 */
7801 public boolean isDrawnLw() {
7802 final AppWindowToken atoken = mAppToken;
7803 return mSurface != null && !mDestroying
7804 && !mDrawPending && !mCommitDrawPending;
7805 }
7806
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007807 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007808 * Return true if the window is opaque and fully drawn. This indicates
7809 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007810 */
7811 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007812 return (mAttrs.format == PixelFormat.OPAQUE
7813 || mAttrs.type == TYPE_WALLPAPER)
7814 && mSurface != null && mAnimation == null
7815 && (mAppToken == null || mAppToken.animation == null)
7816 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007817 }
7818
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007819 /**
7820 * Return whether this window is wanting to have a translation
7821 * animation applied to it for an in-progress move. (Only makes
7822 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7823 */
7824 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007825 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007826 && (mFrame.top != mLastFrame.top
7827 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007828 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007829 && mPolicy.isScreenOn();
7830 }
7831
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007832 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7833 return
7834 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007835 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7836 // only if it's visible
7837 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007838 // and only if the application fills the compatible screen
7839 mFrame.left <= mCompatibleScreenFrame.left &&
7840 mFrame.top <= mCompatibleScreenFrame.top &&
7841 mFrame.right >= mCompatibleScreenFrame.right &&
7842 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007843 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007844 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007845 }
7846
7847 boolean isFullscreen(int screenWidth, int screenHeight) {
7848 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007849 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007850 }
7851
7852 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007853 disposeInputChannel();
7854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 if (mAttachedWindow != null) {
7856 mAttachedWindow.mChildWindows.remove(this);
7857 }
7858 destroySurfaceLocked();
7859 mSession.windowRemovedLocked();
7860 try {
7861 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7862 } catch (RuntimeException e) {
7863 // Ignore if it has already been removed (usually because
7864 // we are doing this as part of processing a death note.)
7865 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007866 }
7867
7868 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007869 if (mInputChannel != null) {
7870 mInputManager.unregisterInputChannel(mInputChannel);
7871
7872 mInputChannel.dispose();
7873 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007875 }
7876
7877 private class DeathRecipient implements IBinder.DeathRecipient {
7878 public void binderDied() {
7879 try {
7880 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007881 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007882 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007883 if (win != null) {
7884 removeWindowLocked(mSession, win);
7885 }
7886 }
7887 } catch (IllegalArgumentException ex) {
7888 // This will happen if the window has already been
7889 // removed.
7890 }
7891 }
7892 }
7893
7894 /** Returns true if this window desires key events. */
7895 public final boolean canReceiveKeys() {
7896 return isVisibleOrAdding()
7897 && (mViewVisibility == View.VISIBLE)
7898 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7899 }
7900
7901 public boolean hasDrawnLw() {
7902 return mHasDrawn;
7903 }
7904
7905 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007906 return showLw(doAnimation, true);
7907 }
7908
7909 boolean showLw(boolean doAnimation, boolean requestAnim) {
7910 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7911 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007912 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007913 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007914 if (doAnimation) {
7915 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7916 + mPolicyVisibility + " mAnimation=" + mAnimation);
7917 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7918 doAnimation = false;
7919 } else if (mPolicyVisibility && mAnimation == null) {
7920 // Check for the case where we are currently visible and
7921 // not animating; we do not want to do animation at such a
7922 // point to become visible when we already are.
7923 doAnimation = false;
7924 }
7925 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007926 mPolicyVisibility = true;
7927 mPolicyVisibilityAfterAnim = true;
7928 if (doAnimation) {
7929 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7930 }
7931 if (requestAnim) {
7932 requestAnimationLocked(0);
7933 }
7934 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007935 }
7936
7937 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007938 return hideLw(doAnimation, true);
7939 }
7940
7941 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007942 if (doAnimation) {
7943 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7944 doAnimation = false;
7945 }
7946 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007947 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7948 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007949 if (!current) {
7950 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007951 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007952 if (doAnimation) {
7953 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7954 if (mAnimation == null) {
7955 doAnimation = false;
7956 }
7957 }
7958 if (doAnimation) {
7959 mPolicyVisibilityAfterAnim = false;
7960 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007961 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007962 mPolicyVisibilityAfterAnim = false;
7963 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007964 // Window is no longer visible -- make sure if we were waiting
7965 // for it to be displayed before enabling the display, that
7966 // we allow the display to be enabled now.
7967 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007968 if (mCurrentFocus == this) {
7969 mFocusMayChange = true;
7970 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007971 }
7972 if (requestAnim) {
7973 requestAnimationLocked(0);
7974 }
7975 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007976 }
7977
7978 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007979 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7980 pw.print(" mClient="); pw.println(mClient.asBinder());
7981 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7982 if (mAttachedWindow != null || mLayoutAttached) {
7983 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7984 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7985 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007986 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7987 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7988 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007989 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7990 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007991 }
7992 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7993 pw.print(" mSubLayer="); pw.print(mSubLayer);
7994 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7995 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7996 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7997 pw.print("="); pw.print(mAnimLayer);
7998 pw.print(" mLastLayer="); pw.println(mLastLayer);
7999 if (mSurface != null) {
8000 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008001 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8002 pw.print(" layer="); pw.print(mSurfaceLayer);
8003 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8004 pw.print(" rect=("); pw.print(mSurfaceX);
8005 pw.print(","); pw.print(mSurfaceY);
8006 pw.print(") "); pw.print(mSurfaceW);
8007 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008008 }
8009 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8010 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8011 if (mAppToken != null) {
8012 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8013 }
8014 if (mTargetAppToken != null) {
8015 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8016 }
8017 pw.print(prefix); pw.print("mViewVisibility=0x");
8018 pw.print(Integer.toHexString(mViewVisibility));
8019 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008020 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8021 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008022 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8023 pw.print(prefix); pw.print("mPolicyVisibility=");
8024 pw.print(mPolicyVisibility);
8025 pw.print(" mPolicyVisibilityAfterAnim=");
8026 pw.print(mPolicyVisibilityAfterAnim);
8027 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8028 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008029 if (!mRelayoutCalled) {
8030 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8031 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008032 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008033 pw.print(" h="); pw.print(mRequestedHeight);
8034 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008035 if (mXOffset != 0 || mYOffset != 0) {
8036 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8037 pw.print(" y="); pw.println(mYOffset);
8038 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008039 pw.print(prefix); pw.print("mGivenContentInsets=");
8040 mGivenContentInsets.printShortString(pw);
8041 pw.print(" mGivenVisibleInsets=");
8042 mGivenVisibleInsets.printShortString(pw);
8043 pw.println();
8044 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8045 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8046 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8047 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008048 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008049 pw.print(prefix); pw.print("mShownFrame=");
8050 mShownFrame.printShortString(pw);
8051 pw.print(" last="); mLastShownFrame.printShortString(pw);
8052 pw.println();
8053 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8054 pw.print(" last="); mLastFrame.printShortString(pw);
8055 pw.println();
8056 pw.print(prefix); pw.print("mContainingFrame=");
8057 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008058 pw.print(" mParentFrame=");
8059 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008060 pw.print(" mDisplayFrame=");
8061 mDisplayFrame.printShortString(pw);
8062 pw.println();
8063 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8064 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8065 pw.println();
8066 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8067 pw.print(" last="); mLastContentInsets.printShortString(pw);
8068 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8069 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8070 pw.println();
8071 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8072 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8073 pw.print(" mAlpha="); pw.print(mAlpha);
8074 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8075 }
8076 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8077 || mAnimation != null) {
8078 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8079 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8080 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8081 pw.print(" mAnimation="); pw.println(mAnimation);
8082 }
8083 if (mHasTransformation || mHasLocalTransformation) {
8084 pw.print(prefix); pw.print("XForm: has=");
8085 pw.print(mHasTransformation);
8086 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8087 pw.print(" "); mTransformation.printShortString(pw);
8088 pw.println();
8089 }
8090 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8091 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8092 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8093 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8094 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8095 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8096 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8097 pw.print(" mDestroying="); pw.print(mDestroying);
8098 pw.print(" mRemoved="); pw.println(mRemoved);
8099 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008100 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008101 pw.print(prefix); pw.print("mOrientationChanging=");
8102 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008103 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8104 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008105 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008106 if (mHScale != 1 || mVScale != 1) {
8107 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8108 pw.print(" mVScale="); pw.println(mVScale);
8109 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008110 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008111 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8112 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8113 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008114 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8115 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8116 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008118 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008119
8120 String makeInputChannelName() {
8121 return Integer.toHexString(System.identityHashCode(this))
8122 + " " + mAttrs.getTitle();
8123 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008124
8125 @Override
8126 public String toString() {
8127 return "Window{"
8128 + Integer.toHexString(System.identityHashCode(this))
8129 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8130 }
8131 }
Romain Guy06882f82009-06-10 13:36:04 -07008132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 // -------------------------------------------------------------
8134 // Window Token State
8135 // -------------------------------------------------------------
8136
8137 class WindowToken {
8138 // The actual token.
8139 final IBinder token;
8140
8141 // The type of window this token is for, as per WindowManager.LayoutParams.
8142 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008144 // Set if this token was explicitly added by a client, so should
8145 // not be removed when all windows are removed.
8146 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008147
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008148 // For printing.
8149 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 // If this is an AppWindowToken, this is non-null.
8152 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008154 // All of the windows associated with this token.
8155 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8156
8157 // Is key dispatching paused for this token?
8158 boolean paused = false;
8159
8160 // Should this token's windows be hidden?
8161 boolean hidden;
8162
8163 // Temporary for finding which tokens no longer have visible windows.
8164 boolean hasVisible;
8165
Dianne Hackborna8f60182009-09-01 19:01:50 -07008166 // Set to true when this token is in a pending transaction where it
8167 // will be shown.
8168 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008169
Dianne Hackborna8f60182009-09-01 19:01:50 -07008170 // Set to true when this token is in a pending transaction where it
8171 // will be hidden.
8172 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008173
Dianne Hackborna8f60182009-09-01 19:01:50 -07008174 // Set to true when this token is in a pending transaction where its
8175 // windows will be put to the bottom of the list.
8176 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008177
Dianne Hackborna8f60182009-09-01 19:01:50 -07008178 // Set to true when this token is in a pending transaction where its
8179 // windows will be put to the top of the list.
8180 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008182 WindowToken(IBinder _token, int type, boolean _explicit) {
8183 token = _token;
8184 windowType = type;
8185 explicit = _explicit;
8186 }
8187
8188 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008189 pw.print(prefix); pw.print("token="); pw.println(token);
8190 pw.print(prefix); pw.print("windows="); pw.println(windows);
8191 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8192 pw.print(" hidden="); pw.print(hidden);
8193 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008194 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8195 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8196 pw.print(" waitingToHide="); pw.print(waitingToHide);
8197 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8198 pw.print(" sendingToTop="); pw.println(sendingToTop);
8199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008200 }
8201
8202 @Override
8203 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008204 if (stringName == null) {
8205 StringBuilder sb = new StringBuilder();
8206 sb.append("WindowToken{");
8207 sb.append(Integer.toHexString(System.identityHashCode(this)));
8208 sb.append(" token="); sb.append(token); sb.append('}');
8209 stringName = sb.toString();
8210 }
8211 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 }
8213 };
8214
8215 class AppWindowToken extends WindowToken {
8216 // Non-null only for application tokens.
8217 final IApplicationToken appToken;
8218
8219 // All of the windows and child windows that are included in this
8220 // application token. Note this list is NOT sorted!
8221 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8222
8223 int groupId = -1;
8224 boolean appFullscreen;
8225 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008226
8227 // The input dispatching timeout for this application token in nanoseconds.
8228 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008230 // These are used for determining when all windows associated with
8231 // an activity have been drawn, so they can be made visible together
8232 // at the same time.
8233 int lastTransactionSequence = mTransactionSequence-1;
8234 int numInterestingWindows;
8235 int numDrawnWindows;
8236 boolean inPendingTransaction;
8237 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008239 // Is this token going to be hidden in a little while? If so, it
8240 // won't be taken into account for setting the screen orientation.
8241 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008243 // Is this window's surface needed? This is almost like hidden, except
8244 // it will sometimes be true a little earlier: when the token has
8245 // been shown, but is still waiting for its app transition to execute
8246 // before making its windows shown.
8247 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008249 // Have we told the window clients to hide themselves?
8250 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008252 // Last visibility state we reported to the app token.
8253 boolean reportedVisible;
8254
8255 // Set to true when the token has been removed from the window mgr.
8256 boolean removed;
8257
8258 // Have we been asked to have this token keep the screen frozen?
8259 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008261 boolean animating;
8262 Animation animation;
8263 boolean hasTransformation;
8264 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008266 // Offset to the window of all layers in the token, for use by
8267 // AppWindowToken animations.
8268 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008270 // Information about an application starting window if displayed.
8271 StartingData startingData;
8272 WindowState startingWindow;
8273 View startingView;
8274 boolean startingDisplayed;
8275 boolean startingMoved;
8276 boolean firstWindowDrawn;
8277
8278 AppWindowToken(IApplicationToken _token) {
8279 super(_token.asBinder(),
8280 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8281 appWindowToken = this;
8282 appToken = _token;
8283 }
Romain Guy06882f82009-06-10 13:36:04 -07008284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008285 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008286 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008287 TAG, "Setting animation in " + this + ": " + anim);
8288 animation = anim;
8289 animating = false;
8290 anim.restrictDuration(MAX_ANIMATION_DURATION);
8291 anim.scaleCurrentDuration(mTransitionAnimationScale);
8292 int zorder = anim.getZAdjustment();
8293 int adj = 0;
8294 if (zorder == Animation.ZORDER_TOP) {
8295 adj = TYPE_LAYER_OFFSET;
8296 } else if (zorder == Animation.ZORDER_BOTTOM) {
8297 adj = -TYPE_LAYER_OFFSET;
8298 }
Romain Guy06882f82009-06-10 13:36:04 -07008299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008300 if (animLayerAdjustment != adj) {
8301 animLayerAdjustment = adj;
8302 updateLayers();
8303 }
8304 }
Romain Guy06882f82009-06-10 13:36:04 -07008305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008306 public void setDummyAnimation() {
8307 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008308 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008309 TAG, "Setting dummy animation in " + this);
8310 animation = sDummyAnimation;
8311 }
8312 }
8313
8314 public void clearAnimation() {
8315 if (animation != null) {
8316 animation = null;
8317 animating = true;
8318 }
8319 }
Romain Guy06882f82009-06-10 13:36:04 -07008320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 void updateLayers() {
8322 final int N = allAppWindows.size();
8323 final int adj = animLayerAdjustment;
8324 for (int i=0; i<N; i++) {
8325 WindowState w = allAppWindows.get(i);
8326 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008327 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 + w.mAnimLayer);
8329 if (w == mInputMethodTarget) {
8330 setInputMethodAnimLayerAdjustment(adj);
8331 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008332 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008333 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008335 }
8336 }
Romain Guy06882f82009-06-10 13:36:04 -07008337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008338 void sendAppVisibilityToClients() {
8339 final int N = allAppWindows.size();
8340 for (int i=0; i<N; i++) {
8341 WindowState win = allAppWindows.get(i);
8342 if (win == startingWindow && clientHidden) {
8343 // Don't hide the starting window.
8344 continue;
8345 }
8346 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008347 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008348 "Setting visibility of " + win + ": " + (!clientHidden));
8349 win.mClient.dispatchAppVisibility(!clientHidden);
8350 } catch (RemoteException e) {
8351 }
8352 }
8353 }
Romain Guy06882f82009-06-10 13:36:04 -07008354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008355 void showAllWindowsLocked() {
8356 final int NW = allAppWindows.size();
8357 for (int i=0; i<NW; i++) {
8358 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008359 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 "performing show on: " + w);
8361 w.performShowLocked();
8362 }
8363 }
Romain Guy06882f82009-06-10 13:36:04 -07008364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008365 // This must be called while inside a transaction.
8366 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008367 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008368 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008370 if (animation == sDummyAnimation) {
8371 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008372 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008373 // when it is really time to animate, this will be set to
8374 // a real animation and the next call will execute normally.
8375 return false;
8376 }
Romain Guy06882f82009-06-10 13:36:04 -07008377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008378 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8379 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008380 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008381 TAG, "Starting animation in " + this +
8382 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8383 + " scale=" + mTransitionAnimationScale
8384 + " allDrawn=" + allDrawn + " animating=" + animating);
8385 animation.initialize(dw, dh, dw, dh);
8386 animation.setStartTime(currentTime);
8387 animating = true;
8388 }
8389 transformation.clear();
8390 final boolean more = animation.getTransformation(
8391 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008392 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008393 TAG, "Stepped animation in " + this +
8394 ": more=" + more + ", xform=" + transformation);
8395 if (more) {
8396 // we're done!
8397 hasTransformation = true;
8398 return true;
8399 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008400 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008401 TAG, "Finished animation in " + this +
8402 " @ " + currentTime);
8403 animation = null;
8404 }
8405 } else if (animation != null) {
8406 // If the display is frozen, and there is a pending animation,
8407 // clear it and make sure we run the cleanup code.
8408 animating = true;
8409 animation = null;
8410 }
8411
8412 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 if (!animating) {
8415 return false;
8416 }
8417
8418 clearAnimation();
8419 animating = false;
8420 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8421 moveInputMethodWindowsIfNeededLocked(true);
8422 }
Romain Guy06882f82009-06-10 13:36:04 -07008423
Joe Onorato8a9b2202010-02-26 18:56:32 -08008424 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008425 TAG, "Animation done in " + this
8426 + ": reportedVisible=" + reportedVisible);
8427
8428 transformation.clear();
8429 if (animLayerAdjustment != 0) {
8430 animLayerAdjustment = 0;
8431 updateLayers();
8432 }
Romain Guy06882f82009-06-10 13:36:04 -07008433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008434 final int N = windows.size();
8435 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008436 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 }
8438 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 return false;
8441 }
8442
8443 void updateReportedVisibilityLocked() {
8444 if (appToken == null) {
8445 return;
8446 }
Romain Guy06882f82009-06-10 13:36:04 -07008447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008448 int numInteresting = 0;
8449 int numVisible = 0;
8450 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008451
Joe Onorato8a9b2202010-02-26 18:56:32 -08008452 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453 final int N = allAppWindows.size();
8454 for (int i=0; i<N; i++) {
8455 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008456 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008457 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008458 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8459 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008460 continue;
8461 }
8462 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008463 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008464 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008465 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008466 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008467 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008468 + " pv=" + win.mPolicyVisibility
8469 + " dp=" + win.mDrawPending
8470 + " cdp=" + win.mCommitDrawPending
8471 + " ah=" + win.mAttachedHidden
8472 + " th="
8473 + (win.mAppToken != null
8474 ? win.mAppToken.hiddenRequested : false)
8475 + " a=" + win.mAnimating);
8476 }
8477 }
8478 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008479 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008480 if (!win.isAnimating()) {
8481 numVisible++;
8482 }
8483 nowGone = false;
8484 } else if (win.isAnimating()) {
8485 nowGone = false;
8486 }
8487 }
Romain Guy06882f82009-06-10 13:36:04 -07008488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008489 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008490 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 + numInteresting + " visible=" + numVisible);
8492 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008493 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 TAG, "Visibility changed in " + this
8495 + ": vis=" + nowVisible);
8496 reportedVisible = nowVisible;
8497 Message m = mH.obtainMessage(
8498 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8499 nowVisible ? 1 : 0,
8500 nowGone ? 1 : 0,
8501 this);
8502 mH.sendMessage(m);
8503 }
8504 }
Romain Guy06882f82009-06-10 13:36:04 -07008505
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008506 WindowState findMainWindow() {
8507 int j = windows.size();
8508 while (j > 0) {
8509 j--;
8510 WindowState win = windows.get(j);
8511 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8512 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8513 return win;
8514 }
8515 }
8516 return null;
8517 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008519 void dump(PrintWriter pw, String prefix) {
8520 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008521 if (appToken != null) {
8522 pw.print(prefix); pw.println("app=true");
8523 }
8524 if (allAppWindows.size() > 0) {
8525 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8526 }
8527 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008528 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008529 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8530 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8531 pw.print(" clientHidden="); pw.print(clientHidden);
8532 pw.print(" willBeHidden="); pw.print(willBeHidden);
8533 pw.print(" reportedVisible="); pw.println(reportedVisible);
8534 if (paused || freezingScreen) {
8535 pw.print(prefix); pw.print("paused="); pw.print(paused);
8536 pw.print(" freezingScreen="); pw.println(freezingScreen);
8537 }
8538 if (numInterestingWindows != 0 || numDrawnWindows != 0
8539 || inPendingTransaction || allDrawn) {
8540 pw.print(prefix); pw.print("numInterestingWindows=");
8541 pw.print(numInterestingWindows);
8542 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8543 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8544 pw.print(" allDrawn="); pw.println(allDrawn);
8545 }
8546 if (animating || animation != null) {
8547 pw.print(prefix); pw.print("animating="); pw.print(animating);
8548 pw.print(" animation="); pw.println(animation);
8549 }
8550 if (animLayerAdjustment != 0) {
8551 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8552 }
8553 if (hasTransformation) {
8554 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8555 pw.print(" transformation="); transformation.printShortString(pw);
8556 pw.println();
8557 }
8558 if (startingData != null || removed || firstWindowDrawn) {
8559 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8560 pw.print(" removed="); pw.print(removed);
8561 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8562 }
8563 if (startingWindow != null || startingView != null
8564 || startingDisplayed || startingMoved) {
8565 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8566 pw.print(" startingView="); pw.print(startingView);
8567 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8568 pw.print(" startingMoved"); pw.println(startingMoved);
8569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 }
8571
8572 @Override
8573 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008574 if (stringName == null) {
8575 StringBuilder sb = new StringBuilder();
8576 sb.append("AppWindowToken{");
8577 sb.append(Integer.toHexString(System.identityHashCode(this)));
8578 sb.append(" token="); sb.append(token); sb.append('}');
8579 stringName = sb.toString();
8580 }
8581 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 }
8583 }
Romain Guy06882f82009-06-10 13:36:04 -07008584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008585 // -------------------------------------------------------------
8586 // DummyAnimation
8587 // -------------------------------------------------------------
8588
8589 // This is an animation that does nothing: it just immediately finishes
8590 // itself every time it is called. It is used as a stub animation in cases
8591 // where we want to synchronize multiple things that may be animating.
8592 static final class DummyAnimation extends Animation {
8593 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8594 return false;
8595 }
8596 }
8597 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 // -------------------------------------------------------------
8600 // Async Handler
8601 // -------------------------------------------------------------
8602
8603 static final class StartingData {
8604 final String pkg;
8605 final int theme;
8606 final CharSequence nonLocalizedLabel;
8607 final int labelRes;
8608 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008609 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008612 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008613 pkg = _pkg;
8614 theme = _theme;
8615 nonLocalizedLabel = _nonLocalizedLabel;
8616 labelRes = _labelRes;
8617 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008618 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 }
8620 }
8621
8622 private final class H extends Handler {
8623 public static final int REPORT_FOCUS_CHANGE = 2;
8624 public static final int REPORT_LOSING_FOCUS = 3;
8625 public static final int ANIMATE = 4;
8626 public static final int ADD_STARTING = 5;
8627 public static final int REMOVE_STARTING = 6;
8628 public static final int FINISHED_STARTING = 7;
8629 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8631 public static final int HOLD_SCREEN_CHANGED = 12;
8632 public static final int APP_TRANSITION_TIMEOUT = 13;
8633 public static final int PERSIST_ANIMATION_SCALE = 14;
8634 public static final int FORCE_GC = 15;
8635 public static final int ENABLE_SCREEN = 16;
8636 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008637 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008638 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008639 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008640 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008642 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 public H() {
8645 }
Romain Guy06882f82009-06-10 13:36:04 -07008646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008647 @Override
8648 public void handleMessage(Message msg) {
8649 switch (msg.what) {
8650 case REPORT_FOCUS_CHANGE: {
8651 WindowState lastFocus;
8652 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654 synchronized(mWindowMap) {
8655 lastFocus = mLastFocus;
8656 newFocus = mCurrentFocus;
8657 if (lastFocus == newFocus) {
8658 // Focus is not changing, so nothing to do.
8659 return;
8660 }
8661 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008662 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008663 // + " to " + newFocus);
8664 if (newFocus != null && lastFocus != null
8665 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008666 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008667 mLosingFocus.add(lastFocus);
8668 lastFocus = null;
8669 }
8670 }
8671
8672 if (lastFocus != newFocus) {
8673 //System.out.println("Changing focus from " + lastFocus
8674 // + " to " + newFocus);
8675 if (newFocus != null) {
8676 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008677 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008678 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8679 } catch (RemoteException e) {
8680 // Ignore if process has died.
8681 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008682 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 }
8684
8685 if (lastFocus != null) {
8686 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008687 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008688 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8689 } catch (RemoteException e) {
8690 // Ignore if process has died.
8691 }
8692 }
8693 }
8694 } break;
8695
8696 case REPORT_LOSING_FOCUS: {
8697 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008699 synchronized(mWindowMap) {
8700 losers = mLosingFocus;
8701 mLosingFocus = new ArrayList<WindowState>();
8702 }
8703
8704 final int N = losers.size();
8705 for (int i=0; i<N; i++) {
8706 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008707 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008708 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8709 } catch (RemoteException e) {
8710 // Ignore if process has died.
8711 }
8712 }
8713 } break;
8714
8715 case ANIMATE: {
8716 synchronized(mWindowMap) {
8717 mAnimationPending = false;
8718 performLayoutAndPlaceSurfacesLocked();
8719 }
8720 } break;
8721
8722 case ADD_STARTING: {
8723 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8724 final StartingData sd = wtoken.startingData;
8725
8726 if (sd == null) {
8727 // Animation has been canceled... do nothing.
8728 return;
8729 }
Romain Guy06882f82009-06-10 13:36:04 -07008730
Joe Onorato8a9b2202010-02-26 18:56:32 -08008731 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008732 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734 View view = null;
8735 try {
8736 view = mPolicy.addStartingWindow(
8737 wtoken.token, sd.pkg,
8738 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008739 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008741 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008742 }
8743
8744 if (view != null) {
8745 boolean abort = false;
8746
8747 synchronized(mWindowMap) {
8748 if (wtoken.removed || wtoken.startingData == null) {
8749 // If the window was successfully added, then
8750 // we need to remove it.
8751 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008752 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008753 "Aborted starting " + wtoken
8754 + ": removed=" + wtoken.removed
8755 + " startingData=" + wtoken.startingData);
8756 wtoken.startingWindow = null;
8757 wtoken.startingData = null;
8758 abort = true;
8759 }
8760 } else {
8761 wtoken.startingView = view;
8762 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008763 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008764 "Added starting " + wtoken
8765 + ": startingWindow="
8766 + wtoken.startingWindow + " startingView="
8767 + wtoken.startingView);
8768 }
8769
8770 if (abort) {
8771 try {
8772 mPolicy.removeStartingWindow(wtoken.token, view);
8773 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008774 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008775 }
8776 }
8777 }
8778 } break;
8779
8780 case REMOVE_STARTING: {
8781 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8782 IBinder token = null;
8783 View view = null;
8784 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008785 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 + wtoken + ": startingWindow="
8787 + wtoken.startingWindow + " startingView="
8788 + wtoken.startingView);
8789 if (wtoken.startingWindow != null) {
8790 view = wtoken.startingView;
8791 token = wtoken.token;
8792 wtoken.startingData = null;
8793 wtoken.startingView = null;
8794 wtoken.startingWindow = null;
8795 }
8796 }
8797 if (view != null) {
8798 try {
8799 mPolicy.removeStartingWindow(token, view);
8800 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008801 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008802 }
8803 }
8804 } break;
8805
8806 case FINISHED_STARTING: {
8807 IBinder token = null;
8808 View view = null;
8809 while (true) {
8810 synchronized (mWindowMap) {
8811 final int N = mFinishedStarting.size();
8812 if (N <= 0) {
8813 break;
8814 }
8815 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8816
Joe Onorato8a9b2202010-02-26 18:56:32 -08008817 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008818 "Finished starting " + wtoken
8819 + ": startingWindow=" + wtoken.startingWindow
8820 + " startingView=" + wtoken.startingView);
8821
8822 if (wtoken.startingWindow == null) {
8823 continue;
8824 }
8825
8826 view = wtoken.startingView;
8827 token = wtoken.token;
8828 wtoken.startingData = null;
8829 wtoken.startingView = null;
8830 wtoken.startingWindow = null;
8831 }
8832
8833 try {
8834 mPolicy.removeStartingWindow(token, view);
8835 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008836 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008837 }
8838 }
8839 } break;
8840
8841 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8842 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8843
8844 boolean nowVisible = msg.arg1 != 0;
8845 boolean nowGone = msg.arg2 != 0;
8846
8847 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008848 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008849 TAG, "Reporting visible in " + wtoken
8850 + " visible=" + nowVisible
8851 + " gone=" + nowGone);
8852 if (nowVisible) {
8853 wtoken.appToken.windowsVisible();
8854 } else {
8855 wtoken.appToken.windowsGone();
8856 }
8857 } catch (RemoteException ex) {
8858 }
8859 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008861 case WINDOW_FREEZE_TIMEOUT: {
8862 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008863 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008864 int i = mWindows.size();
8865 while (i > 0) {
8866 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008867 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 if (w.mOrientationChanging) {
8869 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008870 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008871 }
8872 }
8873 performLayoutAndPlaceSurfacesLocked();
8874 }
8875 break;
8876 }
Romain Guy06882f82009-06-10 13:36:04 -07008877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008878 case HOLD_SCREEN_CHANGED: {
8879 Session oldHold;
8880 Session newHold;
8881 synchronized (mWindowMap) {
8882 oldHold = mLastReportedHold;
8883 newHold = (Session)msg.obj;
8884 mLastReportedHold = newHold;
8885 }
Romain Guy06882f82009-06-10 13:36:04 -07008886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008887 if (oldHold != newHold) {
8888 try {
8889 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008890 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 "window",
8892 BatteryStats.WAKE_TYPE_WINDOW);
8893 }
8894 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008895 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008896 "window",
8897 BatteryStats.WAKE_TYPE_WINDOW);
8898 }
8899 } catch (RemoteException e) {
8900 }
8901 }
8902 break;
8903 }
Romain Guy06882f82009-06-10 13:36:04 -07008904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008905 case APP_TRANSITION_TIMEOUT: {
8906 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008907 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008908 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008909 "*** APP TRANSITION TIMEOUT");
8910 mAppTransitionReady = true;
8911 mAppTransitionTimeout = true;
8912 performLayoutAndPlaceSurfacesLocked();
8913 }
8914 }
8915 break;
8916 }
Romain Guy06882f82009-06-10 13:36:04 -07008917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008918 case PERSIST_ANIMATION_SCALE: {
8919 Settings.System.putFloat(mContext.getContentResolver(),
8920 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8921 Settings.System.putFloat(mContext.getContentResolver(),
8922 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8923 break;
8924 }
Romain Guy06882f82009-06-10 13:36:04 -07008925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008926 case FORCE_GC: {
8927 synchronized(mWindowMap) {
8928 if (mAnimationPending) {
8929 // If we are animating, don't do the gc now but
8930 // delay a bit so we don't interrupt the animation.
8931 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8932 2000);
8933 return;
8934 }
8935 // If we are currently rotating the display, it will
8936 // schedule a new message when done.
8937 if (mDisplayFrozen) {
8938 return;
8939 }
8940 mFreezeGcPending = 0;
8941 }
8942 Runtime.getRuntime().gc();
8943 break;
8944 }
Romain Guy06882f82009-06-10 13:36:04 -07008945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008946 case ENABLE_SCREEN: {
8947 performEnableScreen();
8948 break;
8949 }
Romain Guy06882f82009-06-10 13:36:04 -07008950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008951 case APP_FREEZE_TIMEOUT: {
8952 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 int i = mAppTokens.size();
8955 while (i > 0) {
8956 i--;
8957 AppWindowToken tok = mAppTokens.get(i);
8958 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008959 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008960 unsetAppFreezingScreenLocked(tok, true, true);
8961 }
8962 }
8963 }
8964 break;
8965 }
Romain Guy06882f82009-06-10 13:36:04 -07008966
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008967 case SEND_NEW_CONFIGURATION: {
8968 removeMessages(SEND_NEW_CONFIGURATION);
8969 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008970 break;
8971 }
Romain Guy06882f82009-06-10 13:36:04 -07008972
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008973 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008974 if (mWindowsChanged) {
8975 synchronized (mWindowMap) {
8976 mWindowsChanged = false;
8977 }
8978 notifyWindowsChanged();
8979 }
8980 break;
8981 }
8982
Christopher Tatea53146c2010-09-07 11:57:52 -07008983 case DRAG_START_TIMEOUT: {
8984 IBinder win = (IBinder)msg.obj;
8985 if (DEBUG_DRAG) {
8986 Slog.w(TAG, "Timeout starting drag by win " + win);
8987 }
8988 synchronized (mWindowMap) {
8989 // !!! TODO: ANR the app that has failed to start the drag in time
8990 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008991 mDragState.unregister();
8992 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008993 mDragState.reset();
8994 mDragState = null;
8995 }
8996 }
Chris Tated4533f142010-10-19 15:15:08 -07008997 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008998 }
8999
Chris Tated4533f142010-10-19 15:15:08 -07009000 case DRAG_END_TIMEOUT: {
9001 IBinder win = (IBinder)msg.obj;
9002 if (DEBUG_DRAG) {
9003 Slog.w(TAG, "Timeout ending drag to win " + win);
9004 }
9005 synchronized (mWindowMap) {
9006 // !!! TODO: ANR the drag-receiving app
9007 mDragState.mDragResult = false;
9008 mDragState.endDragLw();
9009 }
9010 break;
9011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009012 }
9013 }
9014 }
9015
9016 // -------------------------------------------------------------
9017 // IWindowManager API
9018 // -------------------------------------------------------------
9019
9020 public IWindowSession openSession(IInputMethodClient client,
9021 IInputContext inputContext) {
9022 if (client == null) throw new IllegalArgumentException("null client");
9023 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009024 Session session = new Session(client, inputContext);
9025 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009026 }
9027
9028 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9029 synchronized (mWindowMap) {
9030 // The focus for the client is the window immediately below
9031 // where we would place the input method window.
9032 int idx = findDesiredInputMethodWindowIndexLocked(false);
9033 WindowState imFocus;
9034 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009035 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009036 if (imFocus != null) {
9037 if (imFocus.mSession.mClient != null &&
9038 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9039 return true;
9040 }
9041 }
9042 }
9043 }
9044 return false;
9045 }
Romain Guy06882f82009-06-10 13:36:04 -07009046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009047 // -------------------------------------------------------------
9048 // Internals
9049 // -------------------------------------------------------------
9050
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009051 final WindowState windowForClientLocked(Session session, IWindow client,
9052 boolean throwOnError) {
9053 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009054 }
Romain Guy06882f82009-06-10 13:36:04 -07009055
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009056 final WindowState windowForClientLocked(Session session, IBinder client,
9057 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009058 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009059 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009060 TAG, "Looking up client " + client + ": " + win);
9061 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009062 RuntimeException ex = new IllegalArgumentException(
9063 "Requested window " + client + " does not exist");
9064 if (throwOnError) {
9065 throw ex;
9066 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009067 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009068 return null;
9069 }
9070 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009071 RuntimeException ex = new IllegalArgumentException(
9072 "Requested window " + client + " is in session " +
9073 win.mSession + ", not " + session);
9074 if (throwOnError) {
9075 throw ex;
9076 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009077 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009078 return null;
9079 }
9080
9081 return win;
9082 }
9083
Dianne Hackborna8f60182009-09-01 19:01:50 -07009084 final void rebuildAppWindowListLocked() {
9085 int NW = mWindows.size();
9086 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009087 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009088 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009089
Dianne Hackborna8f60182009-09-01 19:01:50 -07009090 // First remove all existing app windows.
9091 i=0;
9092 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009093 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009094 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009095 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009096 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009097 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009098 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009099 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009100 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009101 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009102 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9103 && lastWallpaper == i-1) {
9104 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009105 }
9106 i++;
9107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009108
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009109 // The wallpaper window(s) typically live at the bottom of the stack,
9110 // so skip them before adding app tokens.
9111 lastWallpaper++;
9112 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009113
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009114 // First add all of the exiting app tokens... these are no longer
9115 // in the main app list, but still have windows shown. We put them
9116 // in the back because now that the animation is over we no longer
9117 // will care about them.
9118 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009119 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009120 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009122
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009123 // And add in the still active app tokens in Z order.
9124 NT = mAppTokens.size();
9125 for (int j=0; j<NT; j++) {
9126 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009127 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009128
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009129 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009130 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009131 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009132 + " windows but added " + i);
9133 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009134 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009136 private final void assignLayersLocked() {
9137 int N = mWindows.size();
9138 int curBaseLayer = 0;
9139 int curLayer = 0;
9140 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009141
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009142 if (DEBUG_LAYERS) {
9143 RuntimeException here = new RuntimeException("here");
9144 here.fillInStackTrace();
9145 Log.v(TAG, "Assigning layers", here);
9146 }
9147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009148 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009149 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009150 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9151 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009152 curLayer += WINDOW_LAYER_MULTIPLIER;
9153 w.mLayer = curLayer;
9154 } else {
9155 curBaseLayer = curLayer = w.mBaseLayer;
9156 w.mLayer = curLayer;
9157 }
9158 if (w.mTargetAppToken != null) {
9159 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9160 } else if (w.mAppToken != null) {
9161 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9162 } else {
9163 w.mAnimLayer = w.mLayer;
9164 }
9165 if (w.mIsImWindow) {
9166 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009167 } else if (w.mIsWallpaper) {
9168 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009169 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009170 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 + w.mAnimLayer);
9172 //System.out.println(
9173 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9174 }
9175 }
9176
9177 private boolean mInLayout = false;
9178 private final void performLayoutAndPlaceSurfacesLocked() {
9179 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009180 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009181 throw new RuntimeException("Recursive call!");
9182 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009183 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 return;
9185 }
9186
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009187 if (mWaitingForConfig) {
9188 // Our configuration has changed (most likely rotation), but we
9189 // don't yet have the complete configuration to report to
9190 // applications. Don't do any window layout until we have it.
9191 return;
9192 }
9193
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009194 if (mDisplay == null) {
9195 // Not yet initialized, nothing to do.
9196 return;
9197 }
9198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 boolean recoveringMemory = false;
9200 if (mForceRemoves != null) {
9201 recoveringMemory = true;
9202 // Wait a little it for things to settle down, and off we go.
9203 for (int i=0; i<mForceRemoves.size(); i++) {
9204 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009205 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009206 removeWindowInnerLocked(ws.mSession, ws);
9207 }
9208 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009209 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009210 Object tmp = new Object();
9211 synchronized (tmp) {
9212 try {
9213 tmp.wait(250);
9214 } catch (InterruptedException e) {
9215 }
9216 }
9217 }
Romain Guy06882f82009-06-10 13:36:04 -07009218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 mInLayout = true;
9220 try {
9221 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009223 int i = mPendingRemove.size()-1;
9224 if (i >= 0) {
9225 while (i >= 0) {
9226 WindowState w = mPendingRemove.get(i);
9227 removeWindowInnerLocked(w.mSession, w);
9228 i--;
9229 }
9230 mPendingRemove.clear();
9231
9232 mInLayout = false;
9233 assignLayersLocked();
9234 mLayoutNeeded = true;
9235 performLayoutAndPlaceSurfacesLocked();
9236
9237 } else {
9238 mInLayout = false;
9239 if (mLayoutNeeded) {
9240 requestAnimationLocked(0);
9241 }
9242 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009243 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009244 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9245 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 } catch (RuntimeException e) {
9248 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009249 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009250 }
9251 }
9252
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009253 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009254 if (!mLayoutNeeded) {
9255 return 0;
9256 }
9257
9258 mLayoutNeeded = false;
9259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 final int dw = mDisplay.getWidth();
9261 final int dh = mDisplay.getHeight();
9262
9263 final int N = mWindows.size();
9264 int i;
9265
Joe Onorato8a9b2202010-02-26 18:56:32 -08009266 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009267 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9268
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009269 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009270
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009271 int seq = mLayoutSeq+1;
9272 if (seq < 0) seq = 0;
9273 mLayoutSeq = seq;
9274
9275 // First perform layout of any root windows (not attached
9276 // to another window).
9277 int topAttached = -1;
9278 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009279 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009281 // Don't do layout of a window if it is not visible, or
9282 // soon won't be visible, to avoid wasting time and funky
9283 // changes while a window is animating away.
9284 final AppWindowToken atoken = win.mAppToken;
9285 final boolean gone = win.mViewVisibility == View.GONE
9286 || !win.mRelayoutCalled
9287 || win.mRootToken.hidden
9288 || (atoken != null && atoken.hiddenRequested)
9289 || win.mAttachedHidden
9290 || win.mExiting || win.mDestroying;
9291
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009292 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9293 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009294 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9295 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009296 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009297 + win.mViewVisibility + " mRelayoutCalled="
9298 + win.mRelayoutCalled + " hidden="
9299 + win.mRootToken.hidden + " hiddenRequested="
9300 + (atoken != null && atoken.hiddenRequested)
9301 + " mAttachedHidden=" + win.mAttachedHidden);
9302 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009303
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009304 // If this view is GONE, then skip it -- keep the current
9305 // frame, and let the caller know so they can ignore it
9306 // if they want. (We do the normal layout for INVISIBLE
9307 // windows, since that means "perform layout as normal,
9308 // just don't display").
9309 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009310 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009311 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009312 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009313 win.mContentChanged = false;
9314 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009315 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9316 win.mLayoutSeq = seq;
9317 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9318 + win.mFrame + " mContainingFrame="
9319 + win.mContainingFrame + " mDisplayFrame="
9320 + win.mDisplayFrame);
9321 } else {
9322 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009323 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009324 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009325 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009326
9327 // Now perform layout of attached windows, which usually
9328 // depend on the position of the window they are attached to.
9329 // XXX does not deal with windows that are attached to windows
9330 // that are themselves attached.
9331 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009332 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009333
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009334 if (win.mLayoutAttached) {
9335 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9336 + " mHaveFrame=" + win.mHaveFrame
9337 + " mViewVisibility=" + win.mViewVisibility
9338 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009339 // If this view is GONE, then skip it -- keep the current
9340 // frame, and let the caller know so they can ignore it
9341 // if they want. (We do the normal layout for INVISIBLE
9342 // windows, since that means "perform layout as normal,
9343 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009344 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9345 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009346 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009347 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009348 win.mContentChanged = false;
9349 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009350 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9351 win.mLayoutSeq = seq;
9352 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9353 + win.mFrame + " mContainingFrame="
9354 + win.mContainingFrame + " mDisplayFrame="
9355 + win.mDisplayFrame);
9356 }
9357 }
9358 }
Jeff Brown349703e2010-06-22 01:27:15 -07009359
9360 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009361 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009362
9363 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009364 }
Romain Guy06882f82009-06-10 13:36:04 -07009365
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009366 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009367 private final void performLayoutAndPlaceSurfacesLockedInner(
9368 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009369 if (mDisplay == null) {
9370 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9371 return;
9372 }
9373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009374 final long currentTime = SystemClock.uptimeMillis();
9375 final int dw = mDisplay.getWidth();
9376 final int dh = mDisplay.getHeight();
9377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009378 int i;
9379
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009380 if (mFocusMayChange) {
9381 mFocusMayChange = false;
9382 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9383 }
9384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009385 // Initialize state of exiting tokens.
9386 for (i=mExitingTokens.size()-1; i>=0; i--) {
9387 mExitingTokens.get(i).hasVisible = false;
9388 }
9389
9390 // Initialize state of exiting applications.
9391 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9392 mExitingAppTokens.get(i).hasVisible = false;
9393 }
9394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009395 boolean orientationChangeComplete = true;
9396 Session holdScreen = null;
9397 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009398 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009399 boolean focusDisplayed = false;
9400 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009401 boolean createWatermark = false;
9402
9403 if (mFxSession == null) {
9404 mFxSession = new SurfaceSession();
9405 createWatermark = true;
9406 }
9407
9408 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009409
9410 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009411
9412 if (createWatermark) {
9413 createWatermark();
9414 }
9415 if (mWatermark != null) {
9416 mWatermark.positionSurface(dw, dh);
9417 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009418 if (mStrictModeFlash != null) {
9419 mStrictModeFlash.positionSurface(dw, dh);
9420 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009423 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009424 int repeats = 0;
9425 int changes = 0;
9426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009428 repeats++;
9429 if (repeats > 6) {
9430 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9431 mLayoutNeeded = false;
9432 break;
9433 }
9434
9435 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9436 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9437 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9438 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9439 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9440 assignLayersLocked();
9441 mLayoutNeeded = true;
9442 }
9443 }
9444 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9445 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9446 if (updateOrientationFromAppTokensLocked()) {
9447 mLayoutNeeded = true;
9448 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9449 }
9450 }
9451 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9452 mLayoutNeeded = true;
9453 }
9454 }
9455
9456 // FIRST LOOP: Perform a layout, if needed.
9457 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009458 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009459 if (changes != 0) {
9460 continue;
9461 }
9462 } else {
9463 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9464 changes = 0;
9465 }
9466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009467 final int transactionSequence = ++mTransactionSequence;
9468
9469 // Update animations of all applications, including those
9470 // associated with exiting/removed apps
9471 boolean tokensAnimating = false;
9472 final int NAT = mAppTokens.size();
9473 for (i=0; i<NAT; i++) {
9474 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9475 tokensAnimating = true;
9476 }
9477 }
9478 final int NEAT = mExitingAppTokens.size();
9479 for (i=0; i<NEAT; i++) {
9480 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9481 tokensAnimating = true;
9482 }
9483 }
9484
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009485 // SECOND LOOP: Execute animations and update visibility of windows.
9486
Joe Onorato8a9b2202010-02-26 18:56:32 -08009487 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009488 + transactionSequence + " tokensAnimating="
9489 + tokensAnimating);
9490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009492
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009493 if (mScreenRotationAnimation != null) {
9494 if (mScreenRotationAnimation.isAnimating()) {
9495 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9496 animating = true;
9497 } else {
9498 mScreenRotationAnimation = null;
9499 }
9500 }
9501 }
9502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009504 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009505 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009506 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009507
9508 mPolicy.beginAnimationLw(dw, dh);
9509
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009510 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009512 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009513 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514
9515 final WindowManager.LayoutParams attrs = w.mAttrs;
9516
9517 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009518 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009519 if (w.commitFinishDrawingLocked(currentTime)) {
9520 if ((w.mAttrs.flags
9521 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009522 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009523 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009524 wallpaperMayChange = true;
9525 }
9526 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009527
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009528 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009529
9530 int animDw = dw;
9531 int animDh = dh;
9532
9533 // If the window has moved due to its containing
9534 // content frame changing, then we'd like to animate
9535 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009536 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009537 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009538 // Frame has moved, containing content frame
9539 // has also moved, and we're not currently animating...
9540 // let's do something.
9541 Animation a = AnimationUtils.loadAnimation(mContext,
9542 com.android.internal.R.anim.window_move_from_decor);
9543 w.setAnimation(a);
9544 animDw = w.mLastFrame.left - w.mFrame.left;
9545 animDh = w.mLastFrame.top - w.mFrame.top;
9546 }
9547
9548 // Execute animation.
9549 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9550 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009551
9552 // If this window is animating, make a note that we have
9553 // an animating window and take care of a request to run
9554 // a detached wallpaper animation.
9555 if (nowAnimating) {
9556 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9557 windowDetachedWallpaper = w;
9558 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009559 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009560 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009561
9562 // If this window's app token is running a detached wallpaper
9563 // animation, make a note so we can ensure the wallpaper is
9564 // displayed behind it.
9565 if (w.mAppToken != null && w.mAppToken.animation != null
9566 && w.mAppToken.animation.getDetachWallpaper()) {
9567 windowDetachedWallpaper = w;
9568 }
9569
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009570 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9571 wallpaperMayChange = true;
9572 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009573
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009574 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009575 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009576 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009577 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009578 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009579 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009580 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009581 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9582 forceHiding = true;
9583 }
9584 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9585 boolean changed;
9586 if (forceHiding) {
9587 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009588 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9589 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009590 } else {
9591 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009592 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9593 "Now policy shown: " + w);
9594 if (changed) {
9595 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009596 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009597 // Assume we will need to animate. If
9598 // we don't (because the wallpaper will
9599 // stay with the lock screen), then we will
9600 // clean up later.
9601 Animation a = mPolicy.createForceHideEnterAnimation();
9602 if (a != null) {
9603 w.setAnimation(a);
9604 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009605 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009606 if (mCurrentFocus == null ||
9607 mCurrentFocus.mLayer < w.mLayer) {
9608 // We are showing on to of the current
9609 // focus, so re-evaluate focus to make
9610 // sure it is correct.
9611 mFocusMayChange = true;
9612 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009613 }
9614 }
9615 if (changed && (attrs.flags
9616 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9617 wallpaperMayChange = true;
9618 }
9619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009621 mPolicy.animatingWindowLw(w, attrs);
9622 }
9623
9624 final AppWindowToken atoken = w.mAppToken;
9625 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9626 if (atoken.lastTransactionSequence != transactionSequence) {
9627 atoken.lastTransactionSequence = transactionSequence;
9628 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9629 atoken.startingDisplayed = false;
9630 }
9631 if ((w.isOnScreen() || w.mAttrs.type
9632 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9633 && !w.mExiting && !w.mDestroying) {
9634 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009635 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009636 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009637 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009638 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009639 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009640 + " pv=" + w.mPolicyVisibility
9641 + " dp=" + w.mDrawPending
9642 + " cdp=" + w.mCommitDrawPending
9643 + " ah=" + w.mAttachedHidden
9644 + " th=" + atoken.hiddenRequested
9645 + " a=" + w.mAnimating);
9646 }
9647 }
9648 if (w != atoken.startingWindow) {
9649 if (!atoken.freezingScreen || !w.mAppFreezing) {
9650 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009651 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009652 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009653 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009654 "tokenMayBeDrawn: " + atoken
9655 + " freezingScreen=" + atoken.freezingScreen
9656 + " mAppFreezing=" + w.mAppFreezing);
9657 tokenMayBeDrawn = true;
9658 }
9659 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009660 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 atoken.startingDisplayed = true;
9662 }
9663 }
9664 } else if (w.mReadyToShow) {
9665 w.performShowLocked();
9666 }
9667 }
9668
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009669 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009670
9671 if (tokenMayBeDrawn) {
9672 // See if any windows have been drawn, so they (and others
9673 // associated with them) can now be shown.
9674 final int NT = mTokenList.size();
9675 for (i=0; i<NT; i++) {
9676 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9677 if (wtoken == null) {
9678 continue;
9679 }
9680 if (wtoken.freezingScreen) {
9681 int numInteresting = wtoken.numInterestingWindows;
9682 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009683 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009684 "allDrawn: " + wtoken
9685 + " interesting=" + numInteresting
9686 + " drawn=" + wtoken.numDrawnWindows);
9687 wtoken.showAllWindowsLocked();
9688 unsetAppFreezingScreenLocked(wtoken, false, true);
9689 orientationChangeComplete = true;
9690 }
9691 } else if (!wtoken.allDrawn) {
9692 int numInteresting = wtoken.numInterestingWindows;
9693 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009694 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009695 "allDrawn: " + wtoken
9696 + " interesting=" + numInteresting
9697 + " drawn=" + wtoken.numDrawnWindows);
9698 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009699 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009700
9701 // We can now show all of the drawn windows!
9702 if (!mOpeningApps.contains(wtoken)) {
9703 wtoken.showAllWindowsLocked();
9704 }
9705 }
9706 }
9707 }
9708 }
9709
9710 // If we are ready to perform an app transition, check through
9711 // all of the app tokens to be shown and see if they are ready
9712 // to go.
9713 if (mAppTransitionReady) {
9714 int NN = mOpeningApps.size();
9715 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009716 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009717 "Checking " + NN + " opening apps (frozen="
9718 + mDisplayFrozen + " timeout="
9719 + mAppTransitionTimeout + ")...");
9720 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9721 // If the display isn't frozen, wait to do anything until
9722 // all of the apps are ready. Otherwise just go because
9723 // we'll unfreeze the display when everyone is ready.
9724 for (i=0; i<NN && goodToGo; i++) {
9725 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009726 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009727 "Check opening app" + wtoken + ": allDrawn="
9728 + wtoken.allDrawn + " startingDisplayed="
9729 + wtoken.startingDisplayed);
9730 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9731 && !wtoken.startingMoved) {
9732 goodToGo = false;
9733 }
9734 }
9735 }
9736 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009737 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009738 int transit = mNextAppTransition;
9739 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009740 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009742 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009743 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009744 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009745 mAppTransitionTimeout = false;
9746 mStartingIconInTransition = false;
9747 mSkipAppTransitionAnimation = false;
9748
9749 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9750
Dianne Hackborna8f60182009-09-01 19:01:50 -07009751 // If there are applications waiting to come to the
9752 // top of the stack, now is the time to move their windows.
9753 // (Note that we don't do apps going to the bottom
9754 // here -- we want to keep their windows in the old
9755 // Z-order until the animation completes.)
9756 if (mToTopApps.size() > 0) {
9757 NN = mAppTokens.size();
9758 for (i=0; i<NN; i++) {
9759 AppWindowToken wtoken = mAppTokens.get(i);
9760 if (wtoken.sendingToTop) {
9761 wtoken.sendingToTop = false;
9762 moveAppWindowsLocked(wtoken, NN, false);
9763 }
9764 }
9765 mToTopApps.clear();
9766 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009767
Dianne Hackborn25994b42009-09-04 14:21:19 -07009768 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009769
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009770 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009771 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009772
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009773 // The top-most window will supply the layout params,
9774 // and we will determine it below.
9775 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009776 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009777 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009778
Joe Onorato8a9b2202010-02-26 18:56:32 -08009779 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009780 "New wallpaper target=" + mWallpaperTarget
9781 + ", lower target=" + mLowerWallpaperTarget
9782 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009783 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009784 // Do a first pass through the tokens for two
9785 // things:
9786 // (1) Determine if both the closing and opening
9787 // app token sets are wallpaper targets, in which
9788 // case special animations are needed
9789 // (since the wallpaper needs to stay static
9790 // behind them).
9791 // (2) Find the layout params of the top-most
9792 // application window in the tokens, which is
9793 // what will control the animation theme.
9794 final int NC = mClosingApps.size();
9795 NN = NC + mOpeningApps.size();
9796 for (i=0; i<NN; i++) {
9797 AppWindowToken wtoken;
9798 int mode;
9799 if (i < NC) {
9800 wtoken = mClosingApps.get(i);
9801 mode = 1;
9802 } else {
9803 wtoken = mOpeningApps.get(i-NC);
9804 mode = 2;
9805 }
9806 if (mLowerWallpaperTarget != null) {
9807 if (mLowerWallpaperTarget.mAppToken == wtoken
9808 || mUpperWallpaperTarget.mAppToken == wtoken) {
9809 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009810 }
9811 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009812 if (wtoken.appFullscreen) {
9813 WindowState ws = wtoken.findMainWindow();
9814 if (ws != null) {
9815 // If this is a compatibility mode
9816 // window, we will always use its anim.
9817 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9818 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009819 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009820 bestAnimLayer = Integer.MAX_VALUE;
9821 } else if (ws.mLayer > bestAnimLayer) {
9822 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009823 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009824 bestAnimLayer = ws.mLayer;
9825 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009826 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009827 }
9828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009829
Dianne Hackborn25994b42009-09-04 14:21:19 -07009830 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009831 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009832 "Wallpaper animation!");
9833 switch (transit) {
9834 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9835 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9836 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9837 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9838 break;
9839 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9840 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9841 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9842 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9843 break;
9844 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009845 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009846 "New transit: " + transit);
9847 } else if (oldWallpaper != null) {
9848 // We are transitioning from an activity with
9849 // a wallpaper to one without.
9850 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009851 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009852 "New transit away from wallpaper: " + transit);
9853 } else if (mWallpaperTarget != null) {
9854 // We are transitioning from an activity without
9855 // a wallpaper to now showing the wallpaper
9856 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009857 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009858 "New transit into wallpaper: " + transit);
9859 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009860
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009861 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9862 mLastEnterAnimToken = animToken;
9863 mLastEnterAnimParams = animLp;
9864 } else if (mLastEnterAnimParams != null) {
9865 animLp = mLastEnterAnimParams;
9866 mLastEnterAnimToken = null;
9867 mLastEnterAnimParams = null;
9868 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009869
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009870 // If all closing windows are obscured, then there is
9871 // no need to do an animation. This is the case, for
9872 // example, when this transition is being done behind
9873 // the lock screen.
9874 if (!mPolicy.allowAppAnimationsLw()) {
9875 animLp = null;
9876 }
9877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009878 NN = mOpeningApps.size();
9879 for (i=0; i<NN; i++) {
9880 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009881 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 "Now opening app" + wtoken);
9883 wtoken.reportedVisible = false;
9884 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009885 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009886 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009888 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009889 wtoken.showAllWindowsLocked();
9890 }
9891 NN = mClosingApps.size();
9892 for (i=0; i<NN; i++) {
9893 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009894 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009895 "Now closing app" + wtoken);
9896 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009897 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009898 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009900 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009901 // Force the allDrawn flag, because we want to start
9902 // this guy's animations regardless of whether it's
9903 // gotten drawn.
9904 wtoken.allDrawn = true;
9905 }
9906
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009907 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 mOpeningApps.clear();
9910 mClosingApps.clear();
9911
9912 // This has changed the visibility of windows, so perform
9913 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009914 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009916 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9917 assignLayersLocked();
9918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009919 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009920 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009921 }
9922 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009923
Dianne Hackborn16064f92010-03-25 00:47:24 -07009924 int adjResult = 0;
9925
Dianne Hackborna8f60182009-09-01 19:01:50 -07009926 if (!animating && mAppTransitionRunning) {
9927 // We have finished the animation of an app transition. To do
9928 // this, we have delayed a lot of operations like showing and
9929 // hiding apps, moving apps in Z-order, etc. The app token list
9930 // reflects the correct Z-order, but the window list may now
9931 // be out of sync with it. So here we will just rebuild the
9932 // entire app window list. Fun!
9933 mAppTransitionRunning = false;
9934 // Clear information about apps that were moving.
9935 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009936
Dianne Hackborna8f60182009-09-01 19:01:50 -07009937 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009938 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009939 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009940 moveInputMethodWindowsIfNeededLocked(false);
9941 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009942 // Since the window list has been rebuilt, focus might
9943 // have to be recomputed since the actual order of windows
9944 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009945 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009946 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009947
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009948 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009949 // At this point, there was a window with a wallpaper that
9950 // was force hiding other windows behind it, but now it
9951 // is going away. This may be simple -- just animate
9952 // away the wallpaper and its window -- or it may be
9953 // hard -- the wallpaper now needs to be shown behind
9954 // something that was hidden.
9955 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009956 if (mLowerWallpaperTarget != null
9957 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009958 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009959 "wallpaperForceHiding changed with lower="
9960 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009961 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009962 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9963 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9964 if (mLowerWallpaperTarget.mAppToken.hidden) {
9965 // The lower target has become hidden before we
9966 // actually started the animation... let's completely
9967 // re-evaluate everything.
9968 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009969 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009970 }
9971 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009972 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009973 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009974 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009975 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009976 + " NEW: " + mWallpaperTarget
9977 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009978 if (mLowerWallpaperTarget == null) {
9979 // Whoops, we don't need a special wallpaper animation.
9980 // Clear them out.
9981 forceHiding = false;
9982 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009983 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009984 if (w.mSurface != null) {
9985 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009986 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009987 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009988 forceHiding = true;
9989 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9990 if (!w.mAnimating) {
9991 // We set the animation above so it
9992 // is not yet running.
9993 w.clearAnimation();
9994 }
9995 }
9996 }
9997 }
9998 }
9999 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010000
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010001 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10002 if (DEBUG_WALLPAPER) Slog.v(TAG,
10003 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10004 + windowDetachedWallpaper);
10005 mWindowDetachedWallpaper = windowDetachedWallpaper;
10006 wallpaperMayChange = true;
10007 }
10008
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010009 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010010 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010011 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010012 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010013 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010014
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010015 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010016 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010017 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010018 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010019 assignLayersLocked();
10020 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010021 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010022 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010023 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010024 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010025
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010026 if (mFocusMayChange) {
10027 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010028 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010029 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010030 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010031 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010032 }
10033
10034 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010035 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010036 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010037
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010038 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10039 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010040
Jeff Browne33348b2010-07-15 23:54:05 -070010041 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010042 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010043
10044 // THIRD LOOP: Update the surfaces of all windows.
10045
10046 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10047
10048 boolean obscured = false;
10049 boolean blurring = false;
10050 boolean dimming = false;
10051 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010052 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010053 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010055 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010057 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010058 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010059
10060 boolean displayed = false;
10061 final WindowManager.LayoutParams attrs = w.mAttrs;
10062 final int attrFlags = attrs.flags;
10063
10064 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010065 // XXX NOTE: The logic here could be improved. We have
10066 // the decision about whether to resize a window separated
10067 // from whether to hide the surface. This can cause us to
10068 // resize a surface even if we are going to hide it. You
10069 // can see this by (1) holding device in landscape mode on
10070 // home screen; (2) tapping browser icon (device will rotate
10071 // to landscape; (3) tap home. The wallpaper will be resized
10072 // in step 2 but then immediately hidden, causing us to
10073 // have to resize and then redraw it again in step 3. It
10074 // would be nice to figure out how to avoid this, but it is
10075 // difficult because we do need to resize surfaces in some
10076 // cases while they are hidden such as when first showing a
10077 // window.
10078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010079 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010080 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 TAG, "Placing surface #" + i + " " + w.mSurface
10082 + ": new=" + w.mShownFrame + ", old="
10083 + w.mLastShownFrame);
10084
10085 boolean resize;
10086 int width, height;
10087 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10088 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10089 w.mLastRequestedHeight != w.mRequestedHeight;
10090 // for a scaled surface, we just want to use
10091 // the requested size.
10092 width = w.mRequestedWidth;
10093 height = w.mRequestedHeight;
10094 w.mLastRequestedWidth = width;
10095 w.mLastRequestedHeight = height;
10096 w.mLastShownFrame.set(w.mShownFrame);
10097 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010098 if (SHOW_TRANSACTIONS) logSurface(w,
10099 "POS " + w.mShownFrame.left
10100 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010101 w.mSurfaceX = w.mShownFrame.left;
10102 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010103 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10104 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010105 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 if (!recoveringMemory) {
10107 reclaimSomeSurfaceMemoryLocked(w, "position");
10108 }
10109 }
10110 } else {
10111 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10112 width = w.mShownFrame.width();
10113 height = w.mShownFrame.height();
10114 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010115 }
10116
10117 if (resize) {
10118 if (width < 1) width = 1;
10119 if (height < 1) height = 1;
10120 if (w.mSurface != null) {
10121 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010122 if (SHOW_TRANSACTIONS) logSurface(w,
10123 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010124 + w.mShownFrame.top + " SIZE "
10125 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010126 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010127 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010128 w.mSurfaceW = width;
10129 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010130 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010131 w.mSurfaceX = w.mShownFrame.left;
10132 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010133 w.mSurface.setPosition(w.mShownFrame.left,
10134 w.mShownFrame.top);
10135 } catch (RuntimeException e) {
10136 // If something goes wrong with the surface (such
10137 // as running out of memory), don't take down the
10138 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010139 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010140 + "size=(" + width + "x" + height
10141 + "), pos=(" + w.mShownFrame.left
10142 + "," + w.mShownFrame.top + ")", e);
10143 if (!recoveringMemory) {
10144 reclaimSomeSurfaceMemoryLocked(w, "size");
10145 }
10146 }
10147 }
10148 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010149 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010150 w.mContentInsetsChanged =
10151 !w.mLastContentInsets.equals(w.mContentInsets);
10152 w.mVisibleInsetsChanged =
10153 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010154 boolean configChanged =
10155 w.mConfiguration != mCurConfiguration
10156 && (w.mConfiguration == null
10157 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010158 if (DEBUG_CONFIGURATION && configChanged) {
10159 Slog.v(TAG, "Win " + w + " config changed: "
10160 + mCurConfiguration);
10161 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010162 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010163 + ": configChanged=" + configChanged
10164 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010165 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010167 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010168 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010169 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010170 w.mLastFrame.set(w.mFrame);
10171 w.mLastContentInsets.set(w.mContentInsets);
10172 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010173 // If the screen is currently frozen, then keep
10174 // it frozen until this window draws at its new
10175 // orientation.
10176 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010177 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010178 "Resizing while display frozen: " + w);
10179 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010180 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010181 mWindowsFreezingScreen = true;
10182 // XXX should probably keep timeout from
10183 // when we first froze the display.
10184 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10185 mH.sendMessageDelayed(mH.obtainMessage(
10186 H.WINDOW_FREEZE_TIMEOUT), 2000);
10187 }
10188 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010189 // If the orientation is changing, then we need to
10190 // hold off on unfreezing the display until this
10191 // window has been redrawn; to do that, we need
10192 // to go through the process of getting informed
10193 // by the application when it has finished drawing.
10194 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010195 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010196 "Orientation start waiting for draw in "
10197 + w + ", surface " + w.mSurface);
10198 w.mDrawPending = true;
10199 w.mCommitDrawPending = false;
10200 w.mReadyToShow = false;
10201 if (w.mAppToken != null) {
10202 w.mAppToken.allDrawn = false;
10203 }
10204 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010205 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010206 "Resizing window " + w + " to " + w.mFrame);
10207 mResizingWindows.add(w);
10208 } else if (w.mOrientationChanging) {
10209 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010210 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010211 "Orientation not waiting for draw in "
10212 + w + ", surface " + w.mSurface);
10213 w.mOrientationChanging = false;
10214 }
10215 }
10216 }
10217
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010218 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010219 if (!w.mLastHidden) {
10220 //dump();
10221 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010222 if (SHOW_TRANSACTIONS) logSurface(w,
10223 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010224 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010225 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010226 try {
10227 w.mSurface.hide();
10228 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010229 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010230 }
10231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010232 }
10233 // If we are waiting for this window to handle an
10234 // orientation change, well, it is hidden, so
10235 // doesn't really matter. Note that this does
10236 // introduce a potential glitch if the window
10237 // becomes unhidden before it has drawn for the
10238 // new orientation.
10239 if (w.mOrientationChanging) {
10240 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010241 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010242 "Orientation change skips hidden " + w);
10243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010244 } else if (w.mLastLayer != w.mAnimLayer
10245 || w.mLastAlpha != w.mShownAlpha
10246 || w.mLastDsDx != w.mDsDx
10247 || w.mLastDtDx != w.mDtDx
10248 || w.mLastDsDy != w.mDsDy
10249 || w.mLastDtDy != w.mDtDy
10250 || w.mLastHScale != w.mHScale
10251 || w.mLastVScale != w.mVScale
10252 || w.mLastHidden) {
10253 displayed = true;
10254 w.mLastAlpha = w.mShownAlpha;
10255 w.mLastLayer = w.mAnimLayer;
10256 w.mLastDsDx = w.mDsDx;
10257 w.mLastDtDx = w.mDtDx;
10258 w.mLastDsDy = w.mDsDy;
10259 w.mLastDtDy = w.mDtDy;
10260 w.mLastHScale = w.mHScale;
10261 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010262 if (SHOW_TRANSACTIONS) logSurface(w,
10263 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010264 + " matrix=[" + (w.mDsDx*w.mHScale)
10265 + "," + (w.mDtDx*w.mVScale)
10266 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010267 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 if (w.mSurface != null) {
10269 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010270 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010271 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010272 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010273 w.mSurface.setLayer(w.mAnimLayer);
10274 w.mSurface.setMatrix(
10275 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10276 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10277 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010278 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010279 if (!recoveringMemory) {
10280 reclaimSomeSurfaceMemoryLocked(w, "update");
10281 }
10282 }
10283 }
10284
10285 if (w.mLastHidden && !w.mDrawPending
10286 && !w.mCommitDrawPending
10287 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010288 if (SHOW_TRANSACTIONS) logSurface(w,
10289 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010290 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010291 + " during relayout");
10292 if (showSurfaceRobustlyLocked(w)) {
10293 w.mHasDrawn = true;
10294 w.mLastHidden = false;
10295 } else {
10296 w.mOrientationChanging = false;
10297 }
10298 }
10299 if (w.mSurface != null) {
10300 w.mToken.hasVisible = true;
10301 }
10302 } else {
10303 displayed = true;
10304 }
10305
10306 if (displayed) {
10307 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010308 if (attrs.width == LayoutParams.MATCH_PARENT
10309 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010310 covered = true;
10311 }
10312 }
10313 if (w.mOrientationChanging) {
10314 if (w.mDrawPending || w.mCommitDrawPending) {
10315 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010316 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010317 "Orientation continue waiting for draw in " + w);
10318 } else {
10319 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010320 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010321 "Orientation change complete in " + w);
10322 }
10323 }
10324 w.mToken.hasVisible = true;
10325 }
10326 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010327 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010328 "Orientation change skips hidden " + w);
10329 w.mOrientationChanging = false;
10330 }
10331
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010332 if (w.mContentChanged) {
10333 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10334 w.mContentChanged = false;
10335 }
10336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010337 final boolean canBeSeen = w.isDisplayedLw();
10338
10339 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10340 focusDisplayed = true;
10341 }
10342
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010343 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010345 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010346 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 if (w.mSurface != null) {
10348 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10349 holdScreen = w.mSession;
10350 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010351 if (!syswin && w.mAttrs.screenBrightness >= 0
10352 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 screenBrightness = w.mAttrs.screenBrightness;
10354 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010355 if (!syswin && w.mAttrs.buttonBrightness >= 0
10356 && buttonBrightness < 0) {
10357 buttonBrightness = w.mAttrs.buttonBrightness;
10358 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010359 if (canBeSeen
10360 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10361 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10362 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010363 syswin = true;
10364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010365 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010366
Dianne Hackborn25994b42009-09-04 14:21:19 -070010367 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10368 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010369 // This window completely covers everything behind it,
10370 // so we want to leave all of them as unblurred (for
10371 // performance reasons).
10372 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010373 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010374 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010375 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010376 obscured = true;
10377 if (mBackgroundFillerSurface == null) {
10378 try {
10379 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010380 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010381 0, dw, dh,
10382 PixelFormat.OPAQUE,
10383 Surface.FX_SURFACE_NORMAL);
10384 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010385 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010386 }
10387 }
10388 try {
10389 mBackgroundFillerSurface.setPosition(0, 0);
10390 mBackgroundFillerSurface.setSize(dw, dh);
10391 // Using the same layer as Dim because they will never be shown at the
10392 // same time.
10393 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10394 mBackgroundFillerSurface.show();
10395 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010396 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010397 }
10398 backgroundFillerShown = true;
10399 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010400 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010402 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403 + ": blurring=" + blurring
10404 + " obscured=" + obscured
10405 + " displayed=" + displayed);
10406 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10407 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010408 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010409 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010410 if (mDimAnimator == null) {
10411 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010413 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010414 mDimAnimator.updateParameters(mContext.getResources(),
10415 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417 }
10418 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10419 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010420 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010422 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010423 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010424 + mBlurSurface + ": CREATE");
10425 try {
Romain Guy06882f82009-06-10 13:36:04 -070010426 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010427 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010428 -1, 16, 16,
10429 PixelFormat.OPAQUE,
10430 Surface.FX_SURFACE_BLUR);
10431 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010432 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433 }
10434 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010436 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10437 + mBlurSurface + ": pos=(0,0) (" +
10438 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010439 mBlurSurface.setPosition(0, 0);
10440 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010441 mBlurSurface.setLayer(w.mAnimLayer-2);
10442 if (!mBlurShown) {
10443 try {
10444 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10445 + mBlurSurface + ": SHOW");
10446 mBlurSurface.show();
10447 } catch (RuntimeException e) {
10448 Slog.w(TAG, "Failure showing blur surface", e);
10449 }
10450 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010451 }
10452 }
10453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 }
10455 }
10456 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010457
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010458 if (obscuredChanged && mWallpaperTarget == w) {
10459 // This is the wallpaper target and its obscured state
10460 // changed... make sure the current wallaper's visibility
10461 // has been updated accordingly.
10462 updateWallpaperVisibilityLocked();
10463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010464 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010465
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010466 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10467 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010468 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010469 try {
10470 mBackgroundFillerSurface.hide();
10471 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010472 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010473 }
10474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010476 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010477 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10478 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010479 }
Romain Guy06882f82009-06-10 13:36:04 -070010480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010481 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010482 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010483 + ": HIDE");
10484 try {
10485 mBlurSurface.hide();
10486 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010487 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010488 }
10489 mBlurShown = false;
10490 }
10491
Joe Onorato8a9b2202010-02-26 18:56:32 -080010492 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010494 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010495 }
10496
Jeff Browne33348b2010-07-15 23:54:05 -070010497 mInputMonitor.updateInputWindowsLw();
10498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010499 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010500
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010501 if (mWatermark != null) {
10502 mWatermark.drawIfNeeded();
10503 }
10504
Joe Onorato8a9b2202010-02-26 18:56:32 -080010505 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010506 "With display frozen, orientationChangeComplete="
10507 + orientationChangeComplete);
10508 if (orientationChangeComplete) {
10509 if (mWindowsFreezingScreen) {
10510 mWindowsFreezingScreen = false;
10511 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10512 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010513 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 }
Romain Guy06882f82009-06-10 13:36:04 -070010515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 i = mResizingWindows.size();
10517 if (i > 0) {
10518 do {
10519 i--;
10520 WindowState win = mResizingWindows.get(i);
10521 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010522 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10523 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010524 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010525 boolean configChanged =
10526 win.mConfiguration != mCurConfiguration
10527 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010528 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10529 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10530 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010531 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010532 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010533 + " / " + mCurConfiguration + " / 0x"
10534 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010535 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010536 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010537 win.mClient.resized(win.mFrame.width(),
10538 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010539 win.mLastVisibleInsets, win.mDrawPending,
10540 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010541 win.mContentInsetsChanged = false;
10542 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010543 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010544 } catch (RemoteException e) {
10545 win.mOrientationChanging = false;
10546 }
10547 } while (i > 0);
10548 mResizingWindows.clear();
10549 }
Romain Guy06882f82009-06-10 13:36:04 -070010550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010551 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010552 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010553 i = mDestroySurface.size();
10554 if (i > 0) {
10555 do {
10556 i--;
10557 WindowState win = mDestroySurface.get(i);
10558 win.mDestroying = false;
10559 if (mInputMethodWindow == win) {
10560 mInputMethodWindow = null;
10561 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010562 if (win == mWallpaperTarget) {
10563 wallpaperDestroyed = true;
10564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010565 win.destroySurfaceLocked();
10566 } while (i > 0);
10567 mDestroySurface.clear();
10568 }
10569
10570 // Time to remove any exiting tokens?
10571 for (i=mExitingTokens.size()-1; i>=0; i--) {
10572 WindowToken token = mExitingTokens.get(i);
10573 if (!token.hasVisible) {
10574 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010575 if (token.windowType == TYPE_WALLPAPER) {
10576 mWallpaperTokens.remove(token);
10577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010578 }
10579 }
10580
10581 // Time to remove any exiting applications?
10582 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10583 AppWindowToken token = mExitingAppTokens.get(i);
10584 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010585 // Make sure there is no animation running on this token,
10586 // so any windows associated with it will be removed as
10587 // soon as their animations are complete
10588 token.animation = null;
10589 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010590 mAppTokens.remove(token);
10591 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010592 if (mLastEnterAnimToken == token) {
10593 mLastEnterAnimToken = null;
10594 mLastEnterAnimParams = null;
10595 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010596 }
10597 }
10598
Dianne Hackborna8f60182009-09-01 19:01:50 -070010599 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010600
Dianne Hackborna8f60182009-09-01 19:01:50 -070010601 if (!animating && mAppTransitionRunning) {
10602 // We have finished the animation of an app transition. To do
10603 // this, we have delayed a lot of operations like showing and
10604 // hiding apps, moving apps in Z-order, etc. The app token list
10605 // reflects the correct Z-order, but the window list may now
10606 // be out of sync with it. So here we will just rebuild the
10607 // entire app window list. Fun!
10608 mAppTransitionRunning = false;
10609 needRelayout = true;
10610 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010611 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010612 // Clear information about apps that were moving.
10613 mToBottomApps.clear();
10614 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010616 if (focusDisplayed) {
10617 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10618 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010619 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010620 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010621 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010622 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010623 requestAnimationLocked(0);
10624 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010625 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10626 }
Jeff Browneb857f12010-07-16 10:06:33 -070010627
Jeff Browne33348b2010-07-15 23:54:05 -070010628 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010629
Jeff Brown8e03b752010-06-13 19:16:55 -070010630 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010631 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10632 mPowerManager.setScreenBrightnessOverride(-1);
10633 } else {
10634 mPowerManager.setScreenBrightnessOverride((int)
10635 (screenBrightness * Power.BRIGHTNESS_ON));
10636 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010637 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10638 mPowerManager.setButtonBrightnessOverride(-1);
10639 } else {
10640 mPowerManager.setButtonBrightnessOverride((int)
10641 (buttonBrightness * Power.BRIGHTNESS_ON));
10642 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010643 if (holdScreen != mHoldingScreenOn) {
10644 mHoldingScreenOn = holdScreen;
10645 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10646 mH.sendMessage(m);
10647 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010648
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010649 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010650 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010651 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10652 LocalPowerManager.BUTTON_EVENT, true);
10653 mTurnOnScreen = false;
10654 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010655
10656 // Check to see if we are now in a state where the screen should
10657 // be enabled, because the window obscured flags have changed.
10658 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010660
10661 /**
10662 * Must be called with the main window manager lock held.
10663 */
10664 void setHoldScreenLocked(boolean holding) {
10665 boolean state = mHoldingScreenWakeLock.isHeld();
10666 if (holding != state) {
10667 if (holding) {
10668 mHoldingScreenWakeLock.acquire();
10669 } else {
10670 mPolicy.screenOnStoppedLw();
10671 mHoldingScreenWakeLock.release();
10672 }
10673 }
10674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010675
10676 void requestAnimationLocked(long delay) {
10677 if (!mAnimationPending) {
10678 mAnimationPending = true;
10679 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10680 }
10681 }
Romain Guy06882f82009-06-10 13:36:04 -070010682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010683 /**
10684 * Have the surface flinger show a surface, robustly dealing with
10685 * error conditions. In particular, if there is not enough memory
10686 * to show the surface, then we will try to get rid of other surfaces
10687 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010688 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010689 * @return Returns true if the surface was successfully shown.
10690 */
10691 boolean showSurfaceRobustlyLocked(WindowState win) {
10692 try {
10693 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010694 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010695 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010696 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010697 if (DEBUG_VISIBILITY) Slog.v(TAG,
10698 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010699 win.mTurnOnScreen = false;
10700 mTurnOnScreen = true;
10701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010702 }
10703 return true;
10704 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010705 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010706 }
Romain Guy06882f82009-06-10 13:36:04 -070010707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010708 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010710 return false;
10711 }
Romain Guy06882f82009-06-10 13:36:04 -070010712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010713 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10714 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010715
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010716 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010717 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010719 if (mForceRemoves == null) {
10720 mForceRemoves = new ArrayList<WindowState>();
10721 }
Romain Guy06882f82009-06-10 13:36:04 -070010722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010723 long callingIdentity = Binder.clearCallingIdentity();
10724 try {
10725 // There was some problem... first, do a sanity check of the
10726 // window list to make sure we haven't left any dangling surfaces
10727 // around.
10728 int N = mWindows.size();
10729 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010730 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010731 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010732 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010733 if (ws.mSurface != null) {
10734 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010735 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010736 + ws + " surface=" + ws.mSurface
10737 + " token=" + win.mToken
10738 + " pid=" + ws.mSession.mPid
10739 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010740 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010741 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010742 ws.mSurface = null;
10743 mForceRemoves.add(ws);
10744 i--;
10745 N--;
10746 leakedSurface = true;
10747 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010748 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 + ws + " surface=" + ws.mSurface
10750 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010751 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010752 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010753 ws.mSurface = null;
10754 leakedSurface = true;
10755 }
10756 }
10757 }
Romain Guy06882f82009-06-10 13:36:04 -070010758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010759 boolean killedApps = false;
10760 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010761 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010762 SparseIntArray pidCandidates = new SparseIntArray();
10763 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010764 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010765 if (ws.mSurface != null) {
10766 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10767 }
10768 }
10769 if (pidCandidates.size() > 0) {
10770 int[] pids = new int[pidCandidates.size()];
10771 for (int i=0; i<pids.length; i++) {
10772 pids[i] = pidCandidates.keyAt(i);
10773 }
10774 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010775 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010776 killedApps = true;
10777 }
10778 } catch (RemoteException e) {
10779 }
10780 }
10781 }
Romain Guy06882f82009-06-10 13:36:04 -070010782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010783 if (leakedSurface || killedApps) {
10784 // We managed to reclaim some memory, so get rid of the trouble
10785 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010786 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010787 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010788 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010789 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010790 win.mSurface = null;
10791 }
Romain Guy06882f82009-06-10 13:36:04 -070010792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010793 try {
10794 win.mClient.dispatchGetNewSurface();
10795 } catch (RemoteException e) {
10796 }
10797 }
10798 } finally {
10799 Binder.restoreCallingIdentity(callingIdentity);
10800 }
10801 }
Romain Guy06882f82009-06-10 13:36:04 -070010802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010803 private boolean updateFocusedWindowLocked(int mode) {
10804 WindowState newFocus = computeFocusedWindowLocked();
10805 if (mCurrentFocus != newFocus) {
10806 // This check makes sure that we don't already have the focus
10807 // change message pending.
10808 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10809 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010810 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010811 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10812 final WindowState oldFocus = mCurrentFocus;
10813 mCurrentFocus = newFocus;
10814 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010816 final WindowState imWindow = mInputMethodWindow;
10817 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010818 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010819 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010820 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10821 mLayoutNeeded = true;
10822 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010823 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080010824 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010825 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10826 // Client will do the layout, but we need to assign layers
10827 // for handleNewWindowLocked() below.
10828 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010829 }
10830 }
Jeff Brown349703e2010-06-22 01:27:15 -070010831
10832 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10833 // If we defer assigning layers, then the caller is responsible for
10834 // doing this part.
10835 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010836 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010837 return true;
10838 }
10839 return false;
10840 }
Jeff Brown349703e2010-06-22 01:27:15 -070010841
10842 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010843 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010844 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010845
10846 private WindowState computeFocusedWindowLocked() {
10847 WindowState result = null;
10848 WindowState win;
10849
10850 int i = mWindows.size() - 1;
10851 int nextAppIndex = mAppTokens.size()-1;
10852 WindowToken nextApp = nextAppIndex >= 0
10853 ? mAppTokens.get(nextAppIndex) : null;
10854
10855 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010856 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010857
Joe Onorato8a9b2202010-02-26 18:56:32 -080010858 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010859 TAG, "Looking for focus: " + i
10860 + " = " + win
10861 + ", flags=" + win.mAttrs.flags
10862 + ", canReceive=" + win.canReceiveKeys());
10863
10864 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 // If this window's application has been removed, just skip it.
10867 if (thisApp != null && thisApp.removed) {
10868 i--;
10869 continue;
10870 }
Romain Guy06882f82009-06-10 13:36:04 -070010871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010872 // If there is a focused app, don't allow focus to go to any
10873 // windows below it. If this is an application window, step
10874 // through the app tokens until we find its app.
10875 if (thisApp != null && nextApp != null && thisApp != nextApp
10876 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10877 int origAppIndex = nextAppIndex;
10878 while (nextAppIndex > 0) {
10879 if (nextApp == mFocusedApp) {
10880 // Whoops, we are below the focused app... no focus
10881 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010882 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010883 TAG, "Reached focused app: " + mFocusedApp);
10884 return null;
10885 }
10886 nextAppIndex--;
10887 nextApp = mAppTokens.get(nextAppIndex);
10888 if (nextApp == thisApp) {
10889 break;
10890 }
10891 }
10892 if (thisApp != nextApp) {
10893 // Uh oh, the app token doesn't exist! This shouldn't
10894 // happen, but if it does we can get totally hosed...
10895 // so restart at the original app.
10896 nextAppIndex = origAppIndex;
10897 nextApp = mAppTokens.get(nextAppIndex);
10898 }
10899 }
10900
10901 // Dispatch to this window if it is wants key events.
10902 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010903 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904 TAG, "Found focus @ " + i + " = " + win);
10905 result = win;
10906 break;
10907 }
10908
10909 i--;
10910 }
10911
10912 return result;
10913 }
10914
10915 private void startFreezingDisplayLocked() {
10916 if (mDisplayFrozen) {
10917 return;
10918 }
Romain Guy06882f82009-06-10 13:36:04 -070010919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010920 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010922 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010923 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 if (mFreezeGcPending != 0) {
10925 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010926 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010927 mH.removeMessages(H.FORCE_GC);
10928 Runtime.getRuntime().gc();
10929 mFreezeGcPending = now;
10930 }
10931 } else {
10932 mFreezeGcPending = now;
10933 }
Romain Guy06882f82009-06-10 13:36:04 -070010934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010935 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010936
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010937 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010938
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010939 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10940 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010941 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010942 mAppTransitionReady = true;
10943 }
Romain Guy06882f82009-06-10 13:36:04 -070010944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010945 if (PROFILE_ORIENTATION) {
10946 File file = new File("/data/system/frozen");
10947 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10948 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010949
10950 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010951 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
10952 mScreenRotationAnimation.kill();
10953 mScreenRotationAnimation = null;
10954 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010955 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010956 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
10957 mDisplay, mFxSession);
Dianne Hackborna1111872010-11-23 20:55:11 -080010958 }
10959 } else {
10960 Surface.freezeDisplay(0);
10961 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010962 }
Romain Guy06882f82009-06-10 13:36:04 -070010963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010964 private void stopFreezingDisplayLocked() {
10965 if (!mDisplayFrozen) {
10966 return;
10967 }
Romain Guy06882f82009-06-10 13:36:04 -070010968
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010969 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10970 return;
10971 }
10972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010973 mDisplayFrozen = false;
10974 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10975 if (PROFILE_ORIENTATION) {
10976 Debug.stopMethodTracing();
10977 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010978
10979 if (CUSTOM_SCREEN_ROTATION) {
10980 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010981 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
10982 mTransitionAnimationScale)) {
10983 requestAnimationLocked(0);
10984 } else {
10985 mScreenRotationAnimation = null;
10986 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010987 }
10988 } else {
10989 Surface.unfreezeDisplay(0);
10990 }
Romain Guy06882f82009-06-10 13:36:04 -070010991
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010992 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010993
Christopher Tateb696aee2010-04-02 19:08:30 -070010994 // While the display is frozen we don't re-compute the orientation
10995 // to avoid inconsistent states. However, something interesting
10996 // could have actually changed during that time so re-evaluate it
10997 // now to catch that.
10998 if (updateOrientationFromAppTokensLocked()) {
10999 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11000 }
11001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011002 // A little kludge: a lot could have happened while the
11003 // display was frozen, so now that we are coming back we
11004 // do a gc so that any remote references the system
11005 // processes holds on others can be released if they are
11006 // no longer needed.
11007 mH.removeMessages(H.FORCE_GC);
11008 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11009 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011011 mScreenFrozenLock.release();
11012 }
Romain Guy06882f82009-06-10 13:36:04 -070011013
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011014 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11015 DisplayMetrics dm) {
11016 if (index < tokens.length) {
11017 String str = tokens[index];
11018 if (str != null && str.length() > 0) {
11019 try {
11020 int val = Integer.parseInt(str);
11021 return val;
11022 } catch (Exception e) {
11023 }
11024 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011025 }
11026 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11027 return defDps;
11028 }
11029 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11030 return val;
11031 }
11032
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011033 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011034 final String[] mTokens;
11035 final String mText;
11036 final Paint mTextPaint;
11037 final int mTextWidth;
11038 final int mTextHeight;
11039 final int mTextAscent;
11040 final int mTextDescent;
11041 final int mDeltaX;
11042 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011043
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011044 Surface mSurface;
11045 int mLastDW;
11046 int mLastDH;
11047 boolean mDrawNeeded;
11048
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011049 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011050 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011051 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011052
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011053 if (false) {
11054 Log.i(TAG, "*********************** WATERMARK");
11055 for (int i=0; i<tokens.length; i++) {
11056 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11057 }
11058 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011059
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011060 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011061
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011062 StringBuilder builder = new StringBuilder(32);
11063 int len = mTokens[0].length();
11064 len = len & ~1;
11065 for (int i=0; i<len; i+=2) {
11066 int c1 = mTokens[0].charAt(i);
11067 int c2 = mTokens[0].charAt(i+1);
11068 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11069 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11070 else c1 -= '0';
11071 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11072 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11073 else c2 -= '0';
11074 builder.append((char)(255-((c1*16)+c2)));
11075 }
11076 mText = builder.toString();
11077 if (false) {
11078 Log.i(TAG, "Final text: " + mText);
11079 }
11080
11081 int fontSize = getPropertyInt(tokens, 1,
11082 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11083
11084 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11085 mTextPaint.setTextSize(fontSize);
11086 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11087
11088 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11089 mTextWidth = (int)mTextPaint.measureText(mText);
11090 mTextAscent = fm.ascent;
11091 mTextDescent = fm.descent;
11092 mTextHeight = fm.descent - fm.ascent;
11093
11094 mDeltaX = getPropertyInt(tokens, 2,
11095 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11096 mDeltaY = getPropertyInt(tokens, 3,
11097 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11098 int shadowColor = getPropertyInt(tokens, 4,
11099 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11100 int color = getPropertyInt(tokens, 5,
11101 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11102 int shadowRadius = getPropertyInt(tokens, 6,
11103 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11104 int shadowDx = getPropertyInt(tokens, 8,
11105 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11106 int shadowDy = getPropertyInt(tokens, 9,
11107 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11108
11109 mTextPaint.setColor(color);
11110 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011111
11112 try {
11113 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011114 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011115 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011116 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011117 mSurface.show();
11118 } catch (OutOfResourcesException e) {
11119 }
11120 }
11121
11122 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011123 if (mLastDW != dw || mLastDH != dh) {
11124 mLastDW = dw;
11125 mLastDH = dh;
11126 mSurface.setSize(dw, dh);
11127 mDrawNeeded = true;
11128 }
11129 }
11130
11131 void drawIfNeeded() {
11132 if (mDrawNeeded) {
11133 final int dw = mLastDW;
11134 final int dh = mLastDH;
11135
11136 mDrawNeeded = false;
11137 Rect dirty = new Rect(0, 0, dw, dh);
11138 Canvas c = null;
11139 try {
11140 c = mSurface.lockCanvas(dirty);
11141 } catch (IllegalArgumentException e) {
11142 } catch (OutOfResourcesException e) {
11143 }
11144 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011145 c.drawColor(0, PorterDuff.Mode.CLEAR);
11146
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011147 int deltaX = mDeltaX;
11148 int deltaY = mDeltaY;
11149
11150 // deltaX shouldn't be close to a round fraction of our
11151 // x step, or else things will line up too much.
11152 int div = (dw+mTextWidth)/deltaX;
11153 int rem = (dw+mTextWidth) - (div*deltaX);
11154 int qdelta = deltaX/4;
11155 if (rem < qdelta || rem > (deltaX-qdelta)) {
11156 deltaX += deltaX/3;
11157 }
11158
11159 int y = -mTextHeight;
11160 int x = -mTextWidth;
11161 while (y < (dh+mTextHeight)) {
11162 c.drawText(mText, x, y, mTextPaint);
11163 x += deltaX;
11164 if (x >= dw) {
11165 x -= (dw+mTextWidth);
11166 y += deltaY;
11167 }
11168 }
11169 mSurface.unlockCanvasAndPost(c);
11170 }
11171 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011172 }
11173 }
11174
11175 void createWatermark() {
11176 if (mWatermark != null) {
11177 return;
11178 }
11179
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011180 File file = new File("/system/etc/setup.conf");
11181 FileInputStream in = null;
11182 try {
11183 in = new FileInputStream(file);
11184 DataInputStream ind = new DataInputStream(in);
11185 String line = ind.readLine();
11186 if (line != null) {
11187 String[] toks = line.split("%");
11188 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011189 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011190 }
11191 }
11192 } catch (FileNotFoundException e) {
11193 } catch (IOException e) {
11194 } finally {
11195 if (in != null) {
11196 try {
11197 in.close();
11198 } catch (IOException e) {
11199 }
11200 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011201 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011202 }
11203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011204 @Override
11205 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11206 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11207 != PackageManager.PERMISSION_GRANTED) {
11208 pw.println("Permission Denial: can't dump WindowManager from from pid="
11209 + Binder.getCallingPid()
11210 + ", uid=" + Binder.getCallingUid());
11211 return;
11212 }
Romain Guy06882f82009-06-10 13:36:04 -070011213
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011214 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011215 pw.println(" ");
11216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011217 synchronized(mWindowMap) {
11218 pw.println("Current Window Manager state:");
11219 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011220 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011221 pw.print(" Window #"); pw.print(i); pw.print(' ');
11222 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011223 w.dump(pw, " ");
11224 }
11225 if (mInputMethodDialogs.size() > 0) {
11226 pw.println(" ");
11227 pw.println(" Input method dialogs:");
11228 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11229 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011230 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011231 }
11232 }
11233 if (mPendingRemove.size() > 0) {
11234 pw.println(" ");
11235 pw.println(" Remove pending for:");
11236 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11237 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011238 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11239 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011240 w.dump(pw, " ");
11241 }
11242 }
11243 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11244 pw.println(" ");
11245 pw.println(" Windows force removing:");
11246 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11247 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011248 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11249 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011250 w.dump(pw, " ");
11251 }
11252 }
11253 if (mDestroySurface.size() > 0) {
11254 pw.println(" ");
11255 pw.println(" Windows waiting to destroy their surface:");
11256 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11257 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011258 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11259 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011260 w.dump(pw, " ");
11261 }
11262 }
11263 if (mLosingFocus.size() > 0) {
11264 pw.println(" ");
11265 pw.println(" Windows losing focus:");
11266 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11267 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011268 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11269 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011270 w.dump(pw, " ");
11271 }
11272 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011273 if (mResizingWindows.size() > 0) {
11274 pw.println(" ");
11275 pw.println(" Windows waiting to resize:");
11276 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11277 WindowState w = mResizingWindows.get(i);
11278 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11279 pw.print(w); pw.println(":");
11280 w.dump(pw, " ");
11281 }
11282 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011283 if (mSessions.size() > 0) {
11284 pw.println(" ");
11285 pw.println(" All active sessions:");
11286 Iterator<Session> it = mSessions.iterator();
11287 while (it.hasNext()) {
11288 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011289 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011290 s.dump(pw, " ");
11291 }
11292 }
11293 if (mTokenMap.size() > 0) {
11294 pw.println(" ");
11295 pw.println(" All tokens:");
11296 Iterator<WindowToken> it = mTokenMap.values().iterator();
11297 while (it.hasNext()) {
11298 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011299 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011300 token.dump(pw, " ");
11301 }
11302 }
11303 if (mTokenList.size() > 0) {
11304 pw.println(" ");
11305 pw.println(" Window token list:");
11306 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011307 pw.print(" #"); pw.print(i); pw.print(": ");
11308 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011309 }
11310 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011311 if (mWallpaperTokens.size() > 0) {
11312 pw.println(" ");
11313 pw.println(" Wallpaper tokens:");
11314 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11315 WindowToken token = mWallpaperTokens.get(i);
11316 pw.print(" Wallpaper #"); pw.print(i);
11317 pw.print(' '); pw.print(token); pw.println(':');
11318 token.dump(pw, " ");
11319 }
11320 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011321 if (mAppTokens.size() > 0) {
11322 pw.println(" ");
11323 pw.println(" Application tokens in Z order:");
11324 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011325 pw.print(" App #"); pw.print(i); pw.print(": ");
11326 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011327 }
11328 }
11329 if (mFinishedStarting.size() > 0) {
11330 pw.println(" ");
11331 pw.println(" Finishing start of application tokens:");
11332 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11333 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011334 pw.print(" Finished Starting #"); pw.print(i);
11335 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011336 token.dump(pw, " ");
11337 }
11338 }
11339 if (mExitingTokens.size() > 0) {
11340 pw.println(" ");
11341 pw.println(" Exiting tokens:");
11342 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11343 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011344 pw.print(" Exiting #"); pw.print(i);
11345 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011346 token.dump(pw, " ");
11347 }
11348 }
11349 if (mExitingAppTokens.size() > 0) {
11350 pw.println(" ");
11351 pw.println(" Exiting application tokens:");
11352 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11353 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011354 pw.print(" Exiting App #"); pw.print(i);
11355 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011356 token.dump(pw, " ");
11357 }
11358 }
11359 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011360 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11361 pw.print(" mLastFocus="); pw.println(mLastFocus);
11362 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11363 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11364 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011365 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011366 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11367 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11368 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11369 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011370 if (mWindowDetachedWallpaper != null) {
11371 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11372 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011373 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11374 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11375 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011376 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11377 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11378 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11379 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011380 if (mDimAnimator != null) {
11381 mDimAnimator.printTo(pw);
11382 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011383 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011384 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011385 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011386 pw.print(mInputMethodAnimLayerAdjustment);
11387 pw.print(" mWallpaperAnimLayerAdjustment=");
11388 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011389 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11390 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011391 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11392 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011393 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11394 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011395 pw.print(" mRotation="); pw.print(mRotation);
11396 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11397 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11398 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11399 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11400 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11401 pw.print(" mNextAppTransition=0x");
11402 pw.print(Integer.toHexString(mNextAppTransition));
11403 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011404 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011405 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011406 if (mNextAppTransitionPackage != null) {
11407 pw.print(" mNextAppTransitionPackage=");
11408 pw.print(mNextAppTransitionPackage);
11409 pw.print(", mNextAppTransitionEnter=0x");
11410 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11411 pw.print(", mNextAppTransitionExit=0x");
11412 pw.print(Integer.toHexString(mNextAppTransitionExit));
11413 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011414 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11415 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011416 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11417 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11418 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11419 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011420 if (mOpeningApps.size() > 0) {
11421 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11422 }
11423 if (mClosingApps.size() > 0) {
11424 pw.print(" mClosingApps="); pw.println(mClosingApps);
11425 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011426 if (mToTopApps.size() > 0) {
11427 pw.print(" mToTopApps="); pw.println(mToTopApps);
11428 }
11429 if (mToBottomApps.size() > 0) {
11430 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11431 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011432 if (mDisplay != null) {
11433 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11434 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11435 } else {
11436 pw.println(" NO DISPLAY");
11437 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011438 }
11439 }
11440
Jeff Brown349703e2010-06-22 01:27:15 -070011441 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011442 public void monitor() {
11443 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011444 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011445 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011446
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011447 /**
11448 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011449 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011450 */
11451 private static class DimAnimator {
11452 Surface mDimSurface;
11453 boolean mDimShown = false;
11454 float mDimCurrentAlpha;
11455 float mDimTargetAlpha;
11456 float mDimDeltaPerMs;
11457 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011458
11459 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011460
11461 DimAnimator (SurfaceSession session) {
11462 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011463 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011464 + mDimSurface + ": CREATE");
11465 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011466 mDimSurface = new Surface(session, 0,
11467 "DimSurface",
11468 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011469 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011470 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011471 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011472 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011473 }
11474 }
11475 }
11476
11477 /**
11478 * Show the dim surface.
11479 */
11480 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011481 if (!mDimShown) {
11482 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11483 dw + "x" + dh + ")");
11484 mDimShown = true;
11485 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011486 mLastDimWidth = dw;
11487 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011488 mDimSurface.setPosition(0, 0);
11489 mDimSurface.setSize(dw, dh);
11490 mDimSurface.show();
11491 } catch (RuntimeException e) {
11492 Slog.w(TAG, "Failure showing dim surface", e);
11493 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011494 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11495 mLastDimWidth = dw;
11496 mLastDimHeight = dh;
11497 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011498 }
11499 }
11500
11501 /**
11502 * Set's the dim surface's layer and update dim parameters that will be used in
11503 * {@link updateSurface} after all windows are examined.
11504 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011505 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011506 mDimSurface.setLayer(w.mAnimLayer-1);
11507
11508 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011509 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011510 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011511 if (mDimTargetAlpha != target) {
11512 // If the desired dim level has changed, then
11513 // start an animation to it.
11514 mLastDimAnimTime = currentTime;
11515 long duration = (w.mAnimating && w.mAnimation != null)
11516 ? w.mAnimation.computeDurationHint()
11517 : DEFAULT_DIM_DURATION;
11518 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011519 TypedValue tv = new TypedValue();
11520 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11521 tv, true);
11522 if (tv.type == TypedValue.TYPE_FRACTION) {
11523 duration = (long)tv.getFraction((float)duration, (float)duration);
11524 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11525 && tv.type <= TypedValue.TYPE_LAST_INT) {
11526 duration = tv.data;
11527 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011528 }
11529 if (duration < 1) {
11530 // Don't divide by zero
11531 duration = 1;
11532 }
11533 mDimTargetAlpha = target;
11534 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11535 }
11536 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011537
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011538 /**
11539 * Updating the surface's alpha. Returns true if the animation continues, or returns
11540 * false when the animation is finished and the dim surface is hidden.
11541 */
11542 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11543 if (!dimming) {
11544 if (mDimTargetAlpha != 0) {
11545 mLastDimAnimTime = currentTime;
11546 mDimTargetAlpha = 0;
11547 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11548 }
11549 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011550
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011551 boolean animating = false;
11552 if (mLastDimAnimTime != 0) {
11553 mDimCurrentAlpha += mDimDeltaPerMs
11554 * (currentTime-mLastDimAnimTime);
11555 boolean more = true;
11556 if (displayFrozen) {
11557 // If the display is frozen, there is no reason to animate.
11558 more = false;
11559 } else if (mDimDeltaPerMs > 0) {
11560 if (mDimCurrentAlpha > mDimTargetAlpha) {
11561 more = false;
11562 }
11563 } else if (mDimDeltaPerMs < 0) {
11564 if (mDimCurrentAlpha < mDimTargetAlpha) {
11565 more = false;
11566 }
11567 } else {
11568 more = false;
11569 }
11570
11571 // Do we need to continue animating?
11572 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011573 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011574 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11575 mLastDimAnimTime = currentTime;
11576 mDimSurface.setAlpha(mDimCurrentAlpha);
11577 animating = true;
11578 } else {
11579 mDimCurrentAlpha = mDimTargetAlpha;
11580 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011581 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011582 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11583 mDimSurface.setAlpha(mDimCurrentAlpha);
11584 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011585 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011586 + ": HIDE");
11587 try {
11588 mDimSurface.hide();
11589 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011590 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011591 }
11592 mDimShown = false;
11593 }
11594 }
11595 }
11596 return animating;
11597 }
11598
11599 public void printTo(PrintWriter pw) {
11600 pw.print(" mDimShown="); pw.print(mDimShown);
11601 pw.print(" current="); pw.print(mDimCurrentAlpha);
11602 pw.print(" target="); pw.print(mDimTargetAlpha);
11603 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11604 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11605 }
11606 }
11607
11608 /**
11609 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11610 * This is used for opening/closing transition for apps in compatible mode.
11611 */
11612 private static class FadeInOutAnimation extends Animation {
11613 int mWidth;
11614 boolean mFadeIn;
11615
11616 public FadeInOutAnimation(boolean fadeIn) {
11617 setInterpolator(new AccelerateInterpolator());
11618 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11619 mFadeIn = fadeIn;
11620 }
11621
11622 @Override
11623 protected void applyTransformation(float interpolatedTime, Transformation t) {
11624 float x = interpolatedTime;
11625 if (!mFadeIn) {
11626 x = 1.0f - x; // reverse the interpolation for fade out
11627 }
11628 if (x < 0.5) {
11629 // move the window out of the screen.
11630 t.getMatrix().setTranslate(mWidth, 0);
11631 } else {
11632 t.getMatrix().setTranslate(0, 0);// show
11633 t.setAlpha((x - 0.5f) * 2);
11634 }
11635 }
11636
11637 @Override
11638 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11639 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11640 mWidth = width;
11641 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011642
11643 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011644 public int getZAdjustment() {
11645 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011646 }
11647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011648}