blob: c33d19d706a7d465ae6cfad4161604ccd2e69987 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
32import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070035import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37import com.android.internal.app.IBatteryStats;
38import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080039import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070040import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import com.android.internal.view.IInputContext;
42import com.android.internal.view.IInputMethodClient;
43import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080044import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import com.android.server.am.BatteryStatsService;
46
47import android.Manifest;
48import android.app.ActivityManagerNative;
49import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070050import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070051import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070052import android.content.ClipData;
53import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.Intent;
56import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080061import android.content.res.Resources;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080062import android.graphics.Bitmap;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070065import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070067import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070088import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.os.SystemClock;
90import android.os.SystemProperties;
91import android.os.TokenWatcher;
92import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070093import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070095import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080096import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070098import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700100import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101import android.view.Gravity;
102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
129import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.File;
132import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.FileInputStream;
134import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135import java.io.IOException;
136import java.io.OutputStream;
137import java.io.OutputStreamWriter;
138import java.io.PrintWriter;
139import java.io.StringWriter;
140import java.net.Socket;
141import java.util.ArrayList;
142import java.util.HashMap;
143import java.util.HashSet;
144import java.util.Iterator;
145import java.util.List;
146
147/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700148public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700149 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
152 static final boolean DEBUG_FOCUS = false;
153 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800154 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800155 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 static final boolean DEBUG_LAYERS = false;
157 static final boolean DEBUG_INPUT = false;
158 static final boolean DEBUG_INPUT_METHOD = false;
159 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700160 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700162 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_APP_TRANSITIONS = false;
164 static final boolean DEBUG_STARTING_WINDOW = false;
165 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700166 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700167 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700169 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 static final boolean PROFILE_ORIENTATION = false;
172 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700173 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 /** How much to multiply the policy's type layer, to reserve room
176 * for multiple windows of the same type and Z-ordering adjustment
177 * with TYPE_LAYER_OFFSET. */
178 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
181 * or below others in the same layer. */
182 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 /** How much to increment the layer for each window, to reserve room
185 * for effect surfaces between them.
186 */
187 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 /** The maximum length we will accept for a loaded animation duration:
190 * this is 10 seconds.
191 */
192 static final int MAX_ANIMATION_DURATION = 10*1000;
193
194 /** Amount of time (in milliseconds) to animate the dim surface from one
195 * value to another, when no window animation is driving it.
196 */
197 static final int DEFAULT_DIM_DURATION = 200;
198
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700199 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
200 * compatible windows.
201 */
202 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
203
Dianne Hackborna1111872010-11-23 20:55:11 -0800204 /**
205 * If true, the window manager will do its own custom freezing and general
206 * management of the screen during rotation.
207 */
208 static final boolean CUSTOM_SCREEN_ROTATION = true;
209
Jeff Brown7fbdc842010-06-17 20:52:56 -0700210 // Maximum number of milliseconds to wait for input event injection.
211 // FIXME is this value reasonable?
212 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700213
214 // Default input dispatching timeout in nanoseconds.
215 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 static final int UPDATE_FOCUS_NORMAL = 0;
218 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
219 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
220 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700223 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224
225 /**
226 * Condition waited on by {@link #reenableKeyguard} to know the call to
227 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500228 * This is set to true only if mKeyguardTokenWatcher.acquired() has
229 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500231 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232
Jim Miller284b62e2010-06-08 14:27:42 -0700233 private static final int ALLOW_DISABLE_YES = 1;
234 private static final int ALLOW_DISABLE_NO = 0;
235 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
236 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
237
Mike Lockwood983ee092009-11-22 01:42:24 -0500238 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
239 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700241 if (shouldAllowDisableKeyguard()) {
242 mPolicy.enableKeyguard(false);
243 mKeyguardDisabled = true;
244 } else {
245 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 }
248 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700249 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500250 synchronized (mKeyguardTokenWatcher) {
251 mKeyguardDisabled = false;
252 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 }
255 };
256
Jim Miller284b62e2010-06-08 14:27:42 -0700257 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
258 @Override
259 public void onReceive(Context context, Intent intent) {
260 mPolicy.enableKeyguard(true);
261 synchronized(mKeyguardTokenWatcher) {
262 // lazily evaluate this next time we're asked to disable keyguard
263 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
264 mKeyguardDisabled = false;
265 }
266 }
267 };
268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 final Context mContext;
270
271 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
276
277 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 /**
282 * All currently active sessions with clients.
283 */
284 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 /**
287 * Mapping from an IWindow IBinder to the server's Window object.
288 * This is also used as the lock for all of our state.
289 */
290 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
291
292 /**
293 * Mapping from a token IBinder to a WindowToken object.
294 */
295 final HashMap<IBinder, WindowToken> mTokenMap =
296 new HashMap<IBinder, WindowToken>();
297
298 /**
299 * The same tokens as mTokenMap, stored in a list for efficient iteration
300 * over them.
301 */
302 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 /**
305 * Window tokens that are in the process of exiting, but still
306 * on screen for animations.
307 */
308 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
309
310 /**
311 * Z-ordered (bottom-most first) list of all application tokens, for
312 * controlling the ordering of windows in different applications. This
313 * contains WindowToken objects.
314 */
315 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
316
317 /**
318 * Application tokens that are in the process of exiting, but still
319 * on screen for animations.
320 */
321 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
322
323 /**
324 * List of window tokens that have finished starting their application,
325 * and now need to have the policy remove their windows.
326 */
327 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
328
329 /**
330 * Z-ordered (bottom-most first) list of all Window objects.
331 */
Jeff Browne33348b2010-07-15 23:54:05 -0700332 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
334 /**
335 * Windows that are being resized. Used so we can tell the client about
336 * the resize after closing the transaction in which we resized the
337 * underlying surface.
338 */
339 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
340
341 /**
342 * Windows whose animations have ended and now must be removed.
343 */
344 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
345
346 /**
347 * Windows whose surface should be destroyed.
348 */
349 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
350
351 /**
352 * Windows that have lost input focus and are waiting for the new
353 * focus window to be displayed before they are told about this.
354 */
355 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
356
357 /**
358 * This is set when we have run out of memory, and will either be an empty
359 * list or contain windows that need to be force removed.
360 */
361 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700366 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 Surface mBlurSurface;
368 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700369 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800370 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800371 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 final float[] mTmpFloats = new float[9];
376
377 boolean mSafeMode;
378 boolean mDisplayEnabled = false;
379 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700380 int mInitialDisplayWidth = 0;
381 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mRotation = 0;
383 int mRequestedRotation = 0;
384 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700385 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 ArrayList<IRotationWatcher> mRotationWatchers
387 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 boolean mLayoutNeeded = true;
390 boolean mAnimationPending = false;
391 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800392 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 boolean mWindowsFreezingScreen = false;
394 long mFreezeGcPending = 0;
395 int mAppsFreezingScreen = 0;
396
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800397 int mLayoutSeq = 0;
398
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800399 // State while inside of layoutAndPlaceSurfacesLocked().
400 boolean mFocusMayChange;
401
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800402 Configuration mCurConfiguration = new Configuration();
403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 // This is held as long as we have the screen frozen, to give us time to
405 // perform a rotation animation when turning off shows the lock screen which
406 // changes the orientation.
407 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 // State management of app transitions. When we are preparing for a
410 // transition, mNextAppTransition will be the kind of transition to
411 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
412 // mOpeningApps and mClosingApps are the lists of tokens that will be
413 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700414 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700415 String mNextAppTransitionPackage;
416 int mNextAppTransitionEnter;
417 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700419 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 boolean mAppTransitionTimeout = false;
421 boolean mStartingIconInTransition = false;
422 boolean mSkipAppTransitionAnimation = false;
423 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
424 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700425 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
426 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 H mH = new H();
431
432 WindowState mCurrentFocus = null;
433 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 // This just indicates the window the input method is on top of, not
436 // necessarily the window its input is going to.
437 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 boolean mInputMethodTargetWaitingAnim;
439 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 WindowState mInputMethodWindow = null;
442 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
443
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700444 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800445
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700446 // If non-null, this is the currently visible window that is associated
447 // with the wallpaper.
448 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700449 // If non-null, we are in the middle of animating from one wallpaper target
450 // to another, and this is the lower one in Z-order.
451 WindowState mLowerWallpaperTarget = null;
452 // If non-null, we are in the middle of animating from one wallpaper target
453 // to another, and this is the higher one in Z-order.
454 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800455 // Window currently running an animation that has requested it be detached
456 // from the wallpaper. This means we need to ensure the wallpaper is
457 // visible behind it in case it animates in a way that would allow it to be
458 // seen.
459 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700460 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700461 float mLastWallpaperX = -1;
462 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800463 float mLastWallpaperXStep = -1;
464 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700465 // This is set when we are waiting for a wallpaper to tell us it is done
466 // changing its scroll position.
467 WindowState mWaitingOnWallpaper;
468 // The last time we had a timeout when waiting for a wallpaper.
469 long mLastWallpaperTimeoutTime;
470 // We give a wallpaper up to 150ms to finish scrolling.
471 static final long WALLPAPER_TIMEOUT = 150;
472 // Time we wait after a timeout before trying to wait again.
473 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 AppWindowToken mFocusedApp = null;
476
477 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 float mWindowAnimationScale = 1.0f;
480 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700481
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700482 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483
484 // Who is holding the screen on.
485 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700486 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700487
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700488 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700491 * Drag/drop state
492 */
493 class DragState {
494 IBinder mToken;
495 Surface mSurface;
496 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700497 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700498 ClipData mData;
499 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700500 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700501 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700502 float mThumbOffsetX, mThumbOffsetY;
503 InputChannel mServerChannel, mClientChannel;
504 WindowState mTargetWindow;
505 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700506 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700507
508 private final Rect tmpRect = new Rect();
509
Chris Tate7b362e42010-11-04 16:02:52 -0700510 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700511 mToken = token;
512 mSurface = surface;
513 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700514 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 mNotifiedWindows = new ArrayList<WindowState>();
516 }
517
518 void reset() {
519 if (mSurface != null) {
520 mSurface.destroy();
521 }
522 mSurface = null;
523 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700524 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700525 mToken = null;
526 mData = null;
527 mThumbOffsetX = mThumbOffsetY = 0;
528 mNotifiedWindows = null;
529 }
530
531 void register() {
532 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
533 if (mClientChannel != null) {
534 Slog.e(TAG, "Duplicate register of drag input channel");
535 } else {
536 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
537 mServerChannel = channels[0];
538 mClientChannel = channels[1];
539 mInputManager.registerInputChannel(mServerChannel);
540 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
541 mH.getLooper().getQueue());
542 }
543 }
544
545 void unregister() {
546 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
547 if (mClientChannel == null) {
548 Slog.e(TAG, "Unregister of nonexistent drag input channel");
549 } else {
550 mInputManager.unregisterInputChannel(mServerChannel);
551 InputQueue.unregisterInputChannel(mClientChannel);
552 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700553 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700554 mClientChannel = null;
555 mServerChannel = null;
556 }
557 }
558
Chris Tatea32dcf72010-10-14 12:13:50 -0700559 int getDragLayerLw() {
560 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
561 * TYPE_LAYER_MULTIPLIER
562 + TYPE_LAYER_OFFSET;
563 }
564
Christopher Tatea53146c2010-09-07 11:57:52 -0700565 /* call out to each visible window/session informing it about the drag
566 */
Chris Tateb8203e92010-10-12 14:23:21 -0700567 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700568 // Cache a base-class instance of the clip metadata so that parceling
569 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700570 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700571 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700572 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700573
574 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700575 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700576 }
577
Christopher Tate2c095f32010-10-04 14:13:40 -0700578 final int N = mWindows.size();
579 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700580 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700582 }
583
584 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
585 * designated window is potentially a drop recipient. There are race situations
586 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
587 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700588 *
589 * This method clones the 'event' parameter if it's being delivered to the same
590 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700591 */
Chris Tateb478f462010-10-15 16:02:26 -0700592 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
593 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700594 // Don't actually send the event if the drag is supposed to be pinned
595 // to the originating window but 'newWin' is not that window.
596 if (mLocalOnly) {
597 final IBinder winBinder = newWin.mClient.asBinder();
598 if (winBinder != mLocalWin) {
599 if (DEBUG_DRAG) {
600 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
601 }
602 return;
603 }
604 }
605
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700606 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700607 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
608 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800609 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700610 try {
611 newWin.mClient.dispatchDragEvent(event);
612 // track each window that we've notified that the drag is starting
613 mNotifiedWindows.add(newWin);
614 } catch (RemoteException e) {
615 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700616 } finally {
617 // if the callee was local, the dispatch has already recycled the event
618 if (Process.myPid() != newWin.mSession.mPid) {
619 event.recycle();
620 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700621 }
622 }
623 }
624
625 /* helper - construct and send a DRAG_STARTED event only if the window has not
626 * previously been notified, i.e. it became visible after the drag operation
627 * was begun. This is a rare case.
628 */
629 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700630 if (mDragInProgress) {
631 // If we have sent the drag-started, we needn't do so again
632 for (WindowState ws : mNotifiedWindows) {
633 if (ws == newWin) {
634 return;
635 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700636 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700637 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700638 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700639 }
Chris Tateb478f462010-10-15 16:02:26 -0700640 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700641 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700642 }
643
Chris Tated4533f142010-10-19 15:15:08 -0700644 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700645 if (DEBUG_DRAG) {
646 Slog.d(TAG, "broadcasting DRAG_ENDED");
647 }
Chris Tated4533f142010-10-19 15:15:08 -0700648 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800649 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700650 for (WindowState ws: mNotifiedWindows) {
651 try {
652 ws.mClient.dispatchDragEvent(evt);
653 } catch (RemoteException e) {
654 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700655 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700656 }
Chris Tated4533f142010-10-19 15:15:08 -0700657 mNotifiedWindows.clear();
658 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700659 evt.recycle();
660 }
661
Chris Tated4533f142010-10-19 15:15:08 -0700662 void endDragLw() {
663 mDragState.broadcastDragEndedLw();
664
665 // stop intercepting input
666 mDragState.unregister();
667 mInputMonitor.updateInputWindowsLw();
668
669 // free our resources and drop all the object references
670 mDragState.reset();
671 mDragState = null;
672 }
673
Christopher Tatea53146c2010-09-07 11:57:52 -0700674 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700675 final int myPid = Process.myPid();
676
677 // Move the surface to the given touch
678 mSurface.openTransaction();
679 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
680 mSurface.closeTransaction();
681
682 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700683 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700684 if (mLocalOnly) {
685 final IBinder touchedBinder = touchedWin.mClient.asBinder();
686 if (touchedBinder != mLocalWin) {
687 // This drag is pinned only to the originating window, but the drag
688 // point is outside that window. Pretend it's over empty space.
689 touchedWin = null;
690 }
691 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700692 try {
693 // have we dragged over a new window?
694 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
695 if (DEBUG_DRAG) {
696 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
697 }
698 // force DRAG_EXITED_EVENT if appropriate
699 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700700 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800701 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700702 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700703 if (myPid != mTargetWindow.mSession.mPid) {
704 evt.recycle();
705 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700706 }
707 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700708 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700709 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
710 }
711 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700712 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800713 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700714 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700715 if (myPid != touchedWin.mSession.mPid) {
716 evt.recycle();
717 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700718 }
719 } catch (RemoteException e) {
720 Slog.w(TAG, "can't send drag notification to windows");
721 }
722 mTargetWindow = touchedWin;
723 }
724
Chris Tated4533f142010-10-19 15:15:08 -0700725 // Tell the drop target about the data. Returns 'true' if we can immediately
726 // dispatch the global drag-ended message, 'false' if we need to wait for a
727 // result from the recipient.
728 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700729 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700730 if (touchedWin == null) {
731 // "drop" outside a valid window -- no recipient to apply a
732 // timeout to, and we can send the drag-ended message immediately.
733 mDragResult = false;
734 return true;
735 }
736
737 if (DEBUG_DRAG) {
738 Slog.d(TAG, "sending DROP to " + touchedWin);
739 }
740 final int myPid = Process.myPid();
741 final IBinder token = touchedWin.mClient.asBinder();
742 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
743 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800744 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700745 try {
746 touchedWin.mClient.dispatchDragEvent(evt);
747
748 // 5 second timeout for this window to respond to the drop
749 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
750 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
751 mH.sendMessageDelayed(msg, 5000);
752 } catch (RemoteException e) {
753 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
754 return true;
755 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700756 if (myPid != touchedWin.mSession.mPid) {
757 evt.recycle();
758 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700759 }
Chris Tated4533f142010-10-19 15:15:08 -0700760 mToken = token;
761 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700762 }
763
764 // Find the visible, touch-deliverable window under the given point
765 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
766 WindowState touchedWin = null;
767 final int x = (int) xf;
768 final int y = (int) yf;
769 final ArrayList<WindowState> windows = mWindows;
770 final int N = windows.size();
771 for (int i = N - 1; i >= 0; i--) {
772 WindowState child = windows.get(i);
773 final int flags = child.mAttrs.flags;
774 if (!child.isVisibleLw()) {
775 // not visible == don't tell about drags
776 continue;
777 }
778 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
779 // not touchable == don't tell about drags
780 continue;
781 }
782 // account for the window's decor etc
783 tmpRect.set(child.mFrame);
784 if (child.mTouchableInsets == ViewTreeObserver
785 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
786 // The point is inside of the window if it is
787 // inside the frame, AND the content part of that
788 // frame that was given by the application.
789 tmpRect.left += child.mGivenContentInsets.left;
790 tmpRect.top += child.mGivenContentInsets.top;
791 tmpRect.right -= child.mGivenContentInsets.right;
792 tmpRect.bottom -= child.mGivenContentInsets.bottom;
793 } else if (child.mTouchableInsets == ViewTreeObserver
794 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
795 // The point is inside of the window if it is
796 // inside the frame, AND the visible part of that
797 // frame that was given by the application.
798 tmpRect.left += child.mGivenVisibleInsets.left;
799 tmpRect.top += child.mGivenVisibleInsets.top;
800 tmpRect.right -= child.mGivenVisibleInsets.right;
801 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
802 }
803 final int touchFlags = flags &
804 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
805 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
806 if (tmpRect.contains(x, y) || touchFlags == 0) {
807 // Found it
808 touchedWin = child;
809 break;
810 }
811 }
812
813 return touchedWin;
814 }
815 }
816
817 DragState mDragState = null;
818 private final InputHandler mDragInputHandler = new BaseInputHandler() {
819 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700820 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
821 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700822 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700823 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
824 && mDragState != null) {
825 boolean endDrag = false;
826 final float newX = event.getRawX();
827 final float newY = event.getRawY();
828
Christopher Tatea53146c2010-09-07 11:57:52 -0700829 switch (event.getAction()) {
830 case MotionEvent.ACTION_DOWN: {
831 if (DEBUG_DRAG) {
832 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
833 }
834 } break;
835
836 case MotionEvent.ACTION_MOVE: {
837 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700838 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700839 mDragState.notifyMoveLw(newX, newY);
840 }
841 } break;
842
843 case MotionEvent.ACTION_UP: {
844 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
845 + newX + "," + newY);
846 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700847 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700848 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700849 } break;
850
851 case MotionEvent.ACTION_CANCEL: {
852 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
853 endDrag = true;
854 } break;
855 }
856
857 if (endDrag) {
858 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
859 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700860 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700861 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700862 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700863 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700864
865 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700866 }
867 } catch (Exception e) {
868 Slog.e(TAG, "Exception caught by drag handleMotion", e);
869 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700870 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700871 }
872 }
873 };
874
875 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 * Whether the UI is currently running in touch mode (not showing
877 * navigational focus because the user is directly pressing the screen).
878 */
879 boolean mInTouchMode = false;
880
881 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700882 private ArrayList<WindowChangeListener> mWindowChangeListeners =
883 new ArrayList<WindowChangeListener>();
884 private boolean mWindowsChanged = false;
885
886 public interface WindowChangeListener {
887 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700888 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700889 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890
Dianne Hackbornc485a602009-03-24 22:39:49 -0700891 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700892 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700893
894 // The frame use to limit the size of the app running in compatibility mode.
895 Rect mCompatibleScreenFrame = new Rect();
896 // The surface used to fill the outer rim of the app running in compatibility mode.
897 Surface mBackgroundFillerSurface = null;
898 boolean mBackgroundFillerShown = false;
899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 public static WindowManagerService main(Context context,
901 PowerManagerService pm, boolean haveInputMethods) {
902 WMThread thr = new WMThread(context, pm, haveInputMethods);
903 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 synchronized (thr) {
906 while (thr.mService == null) {
907 try {
908 thr.wait();
909 } catch (InterruptedException e) {
910 }
911 }
912 }
Romain Guy06882f82009-06-10 13:36:04 -0700913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 return thr.mService;
915 }
Romain Guy06882f82009-06-10 13:36:04 -0700916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 static class WMThread extends Thread {
918 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 private final Context mContext;
921 private final PowerManagerService mPM;
922 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 public WMThread(Context context, PowerManagerService pm,
925 boolean haveInputMethods) {
926 super("WindowManager");
927 mContext = context;
928 mPM = pm;
929 mHaveInputMethods = haveInputMethods;
930 }
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 public void run() {
933 Looper.prepare();
934 WindowManagerService s = new WindowManagerService(mContext, mPM,
935 mHaveInputMethods);
936 android.os.Process.setThreadPriority(
937 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700938 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 synchronized (this) {
941 mService = s;
942 notifyAll();
943 }
Romain Guy06882f82009-06-10 13:36:04 -0700944
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700945 // For debug builds, log event loop stalls to dropbox for analysis.
946 if (StrictMode.conditionallyEnableDebugLogging()) {
947 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
948 }
949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 Looper.loop();
951 }
952 }
953
954 static class PolicyThread extends Thread {
955 private final WindowManagerPolicy mPolicy;
956 private final WindowManagerService mService;
957 private final Context mContext;
958 private final PowerManagerService mPM;
959 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 public PolicyThread(WindowManagerPolicy policy,
962 WindowManagerService service, Context context,
963 PowerManagerService pm) {
964 super("WindowManagerPolicy");
965 mPolicy = policy;
966 mService = service;
967 mContext = context;
968 mPM = pm;
969 }
Romain Guy06882f82009-06-10 13:36:04 -0700970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 public void run() {
972 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800973 WindowManagerPolicyThread.set(this, Looper.myLooper());
974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800976 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 android.os.Process.setThreadPriority(
978 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700979 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 synchronized (this) {
983 mRunning = true;
984 notifyAll();
985 }
Romain Guy06882f82009-06-10 13:36:04 -0700986
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700987 // For debug builds, log event loop stalls to dropbox for analysis.
988 if (StrictMode.conditionallyEnableDebugLogging()) {
989 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
990 }
991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 Looper.loop();
993 }
994 }
995
996 private WindowManagerService(Context context, PowerManagerService pm,
997 boolean haveInputMethods) {
998 mContext = context;
999 mHaveInputMethods = haveInputMethods;
1000 mLimitedAlphaCompositing = context.getResources().getBoolean(
1001 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 mPowerManager = pm;
1004 mPowerManager.setPolicy(mPolicy);
1005 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1006 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1007 "SCREEN_FROZEN");
1008 mScreenFrozenLock.setReferenceCounted(false);
1009
1010 mActivityManager = ActivityManagerNative.getDefault();
1011 mBatteryStats = BatteryStatsService.getService();
1012
1013 // Get persisted window scale setting
1014 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1015 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1016 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1017 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001018
Jim Miller284b62e2010-06-08 14:27:42 -07001019 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1020 IntentFilter filter = new IntentFilter();
1021 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1022 mContext.registerReceiver(mBroadcastReceiver, filter);
1023
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001024 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1025 "KEEP_SCREEN_ON_FLAG");
1026 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027
Jeff Browne33348b2010-07-15 23:54:05 -07001028 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1031 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 synchronized (thr) {
1034 while (!thr.mRunning) {
1035 try {
1036 thr.wait();
1037 } catch (InterruptedException e) {
1038 }
1039 }
1040 }
Romain Guy06882f82009-06-10 13:36:04 -07001041
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001042 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 // Add ourself to the Watchdog monitors.
1045 Watchdog.getInstance().addMonitor(this);
1046 }
1047
1048 @Override
1049 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1050 throws RemoteException {
1051 try {
1052 return super.onTransact(code, data, reply, flags);
1053 } catch (RuntimeException e) {
1054 // The window manager only throws security exceptions, so let's
1055 // log all others.
1056 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001057 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 }
1059 throw e;
1060 }
1061 }
1062
Jeff Browne33348b2010-07-15 23:54:05 -07001063 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001065 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 TAG, "Adding window " + window + " at "
1067 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1068 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001069 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 }
1071
Jeff Browne33348b2010-07-15 23:54:05 -07001072 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001074 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 TAG, "Adding window " + window + " at "
1076 + i + " of " + mWindows.size() + " (before " + pos + ")");
1077 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001078 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 }
1080
1081 //This method finds out the index of a window that has the same app token as
1082 //win. used for z ordering the windows in mWindows
1083 private int findIdxBasedOnAppTokens(WindowState win) {
1084 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001085 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 int jmax = localmWindows.size();
1087 if(jmax == 0) {
1088 return -1;
1089 }
1090 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001091 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 if(wentry.mAppToken == win.mAppToken) {
1093 return j;
1094 }
1095 }
1096 return -1;
1097 }
Romain Guy06882f82009-06-10 13:36:04 -07001098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1100 final IWindow client = win.mClient;
1101 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001102 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 final int N = localmWindows.size();
1105 final WindowState attached = win.mAttachedWindow;
1106 int i;
1107 if (attached == null) {
1108 int tokenWindowsPos = token.windows.size();
1109 if (token.appWindowToken != null) {
1110 int index = tokenWindowsPos-1;
1111 if (index >= 0) {
1112 // If this application has existing windows, we
1113 // simply place the new window on top of them... but
1114 // keep the starting window on top.
1115 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1116 // Base windows go behind everything else.
1117 placeWindowBefore(token.windows.get(0), win);
1118 tokenWindowsPos = 0;
1119 } else {
1120 AppWindowToken atoken = win.mAppToken;
1121 if (atoken != null &&
1122 token.windows.get(index) == atoken.startingWindow) {
1123 placeWindowBefore(token.windows.get(index), win);
1124 tokenWindowsPos--;
1125 } else {
1126 int newIdx = findIdxBasedOnAppTokens(win);
1127 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001128 //there is a window above this one associated with the same
1129 //apptoken note that the window could be a floating window
1130 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001132 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001133 TAG, "Adding window " + win + " at "
1134 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001136 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 }
1139 }
1140 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001141 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 TAG, "Figuring out where to add app window "
1143 + client.asBinder() + " (token=" + token + ")");
1144 // Figure out where the window should go, based on the
1145 // order of applications.
1146 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001147 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 for (i=NA-1; i>=0; i--) {
1149 AppWindowToken t = mAppTokens.get(i);
1150 if (t == token) {
1151 i--;
1152 break;
1153 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001154
Dianne Hackborna8f60182009-09-01 19:01:50 -07001155 // We haven't reached the token yet; if this token
1156 // is not going to the bottom and has windows, we can
1157 // use it as an anchor for when we do reach the token.
1158 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 pos = t.windows.get(0);
1160 }
1161 }
1162 // We now know the index into the apps. If we found
1163 // an app window above, that gives us the position; else
1164 // we need to look some more.
1165 if (pos != null) {
1166 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001167 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 if (atoken != null) {
1169 final int NC = atoken.windows.size();
1170 if (NC > 0) {
1171 WindowState bottom = atoken.windows.get(0);
1172 if (bottom.mSubLayer < 0) {
1173 pos = bottom;
1174 }
1175 }
1176 }
1177 placeWindowBefore(pos, win);
1178 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001179 // Continue looking down until we find the first
1180 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 while (i >= 0) {
1182 AppWindowToken t = mAppTokens.get(i);
1183 final int NW = t.windows.size();
1184 if (NW > 0) {
1185 pos = t.windows.get(NW-1);
1186 break;
1187 }
1188 i--;
1189 }
1190 if (pos != null) {
1191 // Move in front of any windows attached to this
1192 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001193 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 if (atoken != null) {
1195 final int NC = atoken.windows.size();
1196 if (NC > 0) {
1197 WindowState top = atoken.windows.get(NC-1);
1198 if (top.mSubLayer >= 0) {
1199 pos = top;
1200 }
1201 }
1202 }
1203 placeWindowAfter(pos, win);
1204 } else {
1205 // Just search for the start of this layer.
1206 final int myLayer = win.mBaseLayer;
1207 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001208 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 if (w.mBaseLayer > myLayer) {
1210 break;
1211 }
1212 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001213 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001214 TAG, "Adding window " + win + " at "
1215 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001217 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 }
1219 }
1220 }
1221 } else {
1222 // Figure out where window should go, based on layer.
1223 final int myLayer = win.mBaseLayer;
1224 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001225 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 i++;
1227 break;
1228 }
1229 }
1230 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001231 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001232 TAG, "Adding window " + win + " at "
1233 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001235 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 }
1237 if (addToToken) {
1238 token.windows.add(tokenWindowsPos, win);
1239 }
1240
1241 } else {
1242 // Figure out this window's ordering relative to the window
1243 // it is attached to.
1244 final int NA = token.windows.size();
1245 final int sublayer = win.mSubLayer;
1246 int largestSublayer = Integer.MIN_VALUE;
1247 WindowState windowWithLargestSublayer = null;
1248 for (i=0; i<NA; i++) {
1249 WindowState w = token.windows.get(i);
1250 final int wSublayer = w.mSubLayer;
1251 if (wSublayer >= largestSublayer) {
1252 largestSublayer = wSublayer;
1253 windowWithLargestSublayer = w;
1254 }
1255 if (sublayer < 0) {
1256 // For negative sublayers, we go below all windows
1257 // in the same sublayer.
1258 if (wSublayer >= sublayer) {
1259 if (addToToken) {
1260 token.windows.add(i, win);
1261 }
1262 placeWindowBefore(
1263 wSublayer >= 0 ? attached : w, win);
1264 break;
1265 }
1266 } else {
1267 // For positive sublayers, we go above all windows
1268 // in the same sublayer.
1269 if (wSublayer > sublayer) {
1270 if (addToToken) {
1271 token.windows.add(i, win);
1272 }
1273 placeWindowBefore(w, win);
1274 break;
1275 }
1276 }
1277 }
1278 if (i >= NA) {
1279 if (addToToken) {
1280 token.windows.add(win);
1281 }
1282 if (sublayer < 0) {
1283 placeWindowBefore(attached, win);
1284 } else {
1285 placeWindowAfter(largestSublayer >= 0
1286 ? windowWithLargestSublayer
1287 : attached,
1288 win);
1289 }
1290 }
1291 }
Romain Guy06882f82009-06-10 13:36:04 -07001292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 if (win.mAppToken != null && addToToken) {
1294 win.mAppToken.allAppWindows.add(win);
1295 }
1296 }
Romain Guy06882f82009-06-10 13:36:04 -07001297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 static boolean canBeImeTarget(WindowState w) {
1299 final int fl = w.mAttrs.flags
1300 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1301 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1302 return w.isVisibleOrAdding();
1303 }
1304 return false;
1305 }
Romain Guy06882f82009-06-10 13:36:04 -07001306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001308 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 final int N = localmWindows.size();
1310 WindowState w = null;
1311 int i = N;
1312 while (i > 0) {
1313 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001314 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001315
Joe Onorato8a9b2202010-02-26 18:56:32 -08001316 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 // + Integer.toHexString(w.mAttrs.flags));
1318 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001319 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 // Yet more tricksyness! If this window is a "starting"
1322 // window, we do actually want to be on top of it, but
1323 // it is not -really- where input will go. So if the caller
1324 // is not actually looking to move the IME, look down below
1325 // for a real window to target...
1326 if (!willMove
1327 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1328 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001329 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1331 i--;
1332 w = wb;
1333 }
1334 }
1335 break;
1336 }
1337 }
Romain Guy06882f82009-06-10 13:36:04 -07001338
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001339 // Now, a special case -- if the last target's window is in the
1340 // process of exiting, and is above the new target, keep on the
1341 // last target to avoid flicker. Consider for example a Dialog with
1342 // the IME shown: when the Dialog is dismissed, we want to keep
1343 // the IME above it until it is completely gone so it doesn't drop
1344 // behind the dialog or its full-screen scrim.
1345 if (mInputMethodTarget != null && w != null
1346 && mInputMethodTarget.isDisplayedLw()
1347 && mInputMethodTarget.mExiting) {
1348 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1349 w = mInputMethodTarget;
1350 i = localmWindows.indexOf(w);
1351 }
1352 }
Romain Guy06882f82009-06-10 13:36:04 -07001353
Joe Onorato8a9b2202010-02-26 18:56:32 -08001354 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001355 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001357 if (willMove && w != null) {
1358 final WindowState curTarget = mInputMethodTarget;
1359 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 // Now some fun for dealing with window animations that
1362 // modify the Z order. We need to look at all windows below
1363 // the current target that are in this app, finding the highest
1364 // visible one in layering.
1365 AppWindowToken token = curTarget.mAppToken;
1366 WindowState highestTarget = null;
1367 int highestPos = 0;
1368 if (token.animating || token.animation != null) {
1369 int pos = 0;
1370 pos = localmWindows.indexOf(curTarget);
1371 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001372 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 if (win.mAppToken != token) {
1374 break;
1375 }
1376 if (!win.mRemoved) {
1377 if (highestTarget == null || win.mAnimLayer >
1378 highestTarget.mAnimLayer) {
1379 highestTarget = win;
1380 highestPos = pos;
1381 }
1382 }
1383 pos--;
1384 }
1385 }
Romain Guy06882f82009-06-10 13:36:04 -07001386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001387 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001388 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 + mNextAppTransition + " " + highestTarget
1390 + " animating=" + highestTarget.isAnimating()
1391 + " layer=" + highestTarget.mAnimLayer
1392 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001393
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001394 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 // If we are currently setting up for an animation,
1396 // hold everything until we can find out what will happen.
1397 mInputMethodTargetWaitingAnim = true;
1398 mInputMethodTarget = highestTarget;
1399 return highestPos + 1;
1400 } else if (highestTarget.isAnimating() &&
1401 highestTarget.mAnimLayer > w.mAnimLayer) {
1402 // If the window we are currently targeting is involved
1403 // with an animation, and it is on top of the next target
1404 // we will be over, then hold off on moving until
1405 // that is done.
1406 mInputMethodTarget = highestTarget;
1407 return highestPos + 1;
1408 }
1409 }
1410 }
1411 }
Romain Guy06882f82009-06-10 13:36:04 -07001412
Joe Onorato8a9b2202010-02-26 18:56:32 -08001413 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 if (w != null) {
1415 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001416 if (DEBUG_INPUT_METHOD) {
1417 RuntimeException e = null;
1418 if (!HIDE_STACK_CRAWLS) {
1419 e = new RuntimeException();
1420 e.fillInStackTrace();
1421 }
1422 Slog.w(TAG, "Moving IM target from "
1423 + mInputMethodTarget + " to " + w, e);
1424 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 mInputMethodTarget = w;
1426 if (w.mAppToken != null) {
1427 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1428 } else {
1429 setInputMethodAnimLayerAdjustment(0);
1430 }
1431 }
1432 return i+1;
1433 }
1434 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001435 if (DEBUG_INPUT_METHOD) {
1436 RuntimeException e = null;
1437 if (!HIDE_STACK_CRAWLS) {
1438 e = new RuntimeException();
1439 e.fillInStackTrace();
1440 }
1441 Slog.w(TAG, "Moving IM target from "
1442 + mInputMethodTarget + " to null", e);
1443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 mInputMethodTarget = null;
1445 setInputMethodAnimLayerAdjustment(0);
1446 }
1447 return -1;
1448 }
Romain Guy06882f82009-06-10 13:36:04 -07001449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 void addInputMethodWindowToListLocked(WindowState win) {
1451 int pos = findDesiredInputMethodWindowIndexLocked(true);
1452 if (pos >= 0) {
1453 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001454 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001455 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001457 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 moveInputMethodDialogsLocked(pos+1);
1459 return;
1460 }
1461 win.mTargetAppToken = null;
1462 addWindowToListInOrderLocked(win, true);
1463 moveInputMethodDialogsLocked(pos);
1464 }
Romain Guy06882f82009-06-10 13:36:04 -07001465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 mInputMethodAnimLayerAdjustment = adj;
1469 WindowState imw = mInputMethodWindow;
1470 if (imw != null) {
1471 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001472 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 + " anim layer: " + imw.mAnimLayer);
1474 int wi = imw.mChildWindows.size();
1475 while (wi > 0) {
1476 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001477 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001479 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 + " anim layer: " + cw.mAnimLayer);
1481 }
1482 }
1483 int di = mInputMethodDialogs.size();
1484 while (di > 0) {
1485 di --;
1486 imw = mInputMethodDialogs.get(di);
1487 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001488 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 + " anim layer: " + imw.mAnimLayer);
1490 }
1491 }
Romain Guy06882f82009-06-10 13:36:04 -07001492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1494 int wpos = mWindows.indexOf(win);
1495 if (wpos >= 0) {
1496 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001497 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001499 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 int NC = win.mChildWindows.size();
1501 while (NC > 0) {
1502 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001503 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 int cpos = mWindows.indexOf(cw);
1505 if (cpos >= 0) {
1506 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001508 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 mWindows.remove(cpos);
1510 }
1511 }
1512 }
1513 return interestingPos;
1514 }
Romain Guy06882f82009-06-10 13:36:04 -07001515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 private void reAddWindowToListInOrderLocked(WindowState win) {
1517 addWindowToListInOrderLocked(win, false);
1518 // This is a hack to get all of the child windows added as well
1519 // at the right position. Child windows should be rare and
1520 // this case should be rare, so it shouldn't be that big a deal.
1521 int wpos = mWindows.indexOf(win);
1522 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001523 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001524 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001526 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 reAddWindowLocked(wpos, win);
1528 }
1529 }
Romain Guy06882f82009-06-10 13:36:04 -07001530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 void logWindowList(String prefix) {
1532 int N = mWindows.size();
1533 while (N > 0) {
1534 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001535 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 }
1537 }
Romain Guy06882f82009-06-10 13:36:04 -07001538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 void moveInputMethodDialogsLocked(int pos) {
1540 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 for (int i=0; i<N; i++) {
1545 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1546 }
1547 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001548 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 logWindowList(" ");
1550 }
Romain Guy06882f82009-06-10 13:36:04 -07001551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 if (pos >= 0) {
1553 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1554 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001555 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 if (wp == mInputMethodWindow) {
1557 pos++;
1558 }
1559 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 for (int i=0; i<N; i++) {
1562 WindowState win = dialogs.get(i);
1563 win.mTargetAppToken = targetAppToken;
1564 pos = reAddWindowLocked(pos, win);
1565 }
1566 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 logWindowList(" ");
1569 }
1570 return;
1571 }
1572 for (int i=0; i<N; i++) {
1573 WindowState win = dialogs.get(i);
1574 win.mTargetAppToken = null;
1575 reAddWindowToListInOrderLocked(win);
1576 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001577 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 logWindowList(" ");
1579 }
1580 }
1581 }
Romain Guy06882f82009-06-10 13:36:04 -07001582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1584 final WindowState imWin = mInputMethodWindow;
1585 final int DN = mInputMethodDialogs.size();
1586 if (imWin == null && DN == 0) {
1587 return false;
1588 }
Romain Guy06882f82009-06-10 13:36:04 -07001589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1591 if (imPos >= 0) {
1592 // In this case, the input method windows are to be placed
1593 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 // First check to see if the input method windows are already
1596 // located here, and contiguous.
1597 final int N = mWindows.size();
1598 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001599 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 // Figure out the actual input method window that should be
1602 // at the bottom of their stack.
1603 WindowState baseImWin = imWin != null
1604 ? imWin : mInputMethodDialogs.get(0);
1605 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001606 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 if (cw.mSubLayer < 0) baseImWin = cw;
1608 }
Romain Guy06882f82009-06-10 13:36:04 -07001609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 if (firstImWin == baseImWin) {
1611 // The windows haven't moved... but are they still contiguous?
1612 // First find the top IM window.
1613 int pos = imPos+1;
1614 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001615 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 break;
1617 }
1618 pos++;
1619 }
1620 pos++;
1621 // Now there should be no more input method windows above.
1622 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001623 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 break;
1625 }
1626 pos++;
1627 }
1628 if (pos >= N) {
1629 // All is good!
1630 return false;
1631 }
1632 }
Romain Guy06882f82009-06-10 13:36:04 -07001633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 if (imWin != null) {
1635 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001636 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 logWindowList(" ");
1638 }
1639 imPos = tmpRemoveWindowLocked(imPos, imWin);
1640 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001641 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 logWindowList(" ");
1643 }
1644 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1645 reAddWindowLocked(imPos, imWin);
1646 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001647 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 logWindowList(" ");
1649 }
1650 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1651 } else {
1652 moveInputMethodDialogsLocked(imPos);
1653 }
Romain Guy06882f82009-06-10 13:36:04 -07001654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 } else {
1656 // In this case, the input method windows go in a fixed layer,
1657 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001660 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 tmpRemoveWindowLocked(0, imWin);
1662 imWin.mTargetAppToken = null;
1663 reAddWindowToListInOrderLocked(imWin);
1664 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001665 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 logWindowList(" ");
1667 }
1668 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1669 } else {
1670 moveInputMethodDialogsLocked(-1);;
1671 }
Romain Guy06882f82009-06-10 13:36:04 -07001672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 }
Romain Guy06882f82009-06-10 13:36:04 -07001674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 if (needAssignLayers) {
1676 assignLayersLocked();
1677 }
Romain Guy06882f82009-06-10 13:36:04 -07001678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 return true;
1680 }
Romain Guy06882f82009-06-10 13:36:04 -07001681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 void adjustInputMethodDialogsLocked() {
1683 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1684 }
Romain Guy06882f82009-06-10 13:36:04 -07001685
Dianne Hackborn25994b42009-09-04 14:21:19 -07001686 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001687 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001688 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1689 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1690 ? wallpaperTarget.mAppToken.animation : null)
1691 + " upper=" + mUpperWallpaperTarget
1692 + " lower=" + mLowerWallpaperTarget);
1693 return (wallpaperTarget != null
1694 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1695 && wallpaperTarget.mAppToken.animation != null)))
1696 || mUpperWallpaperTarget != null
1697 || mLowerWallpaperTarget != null;
1698 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001699
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001700 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1701 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001702
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001703 int adjustWallpaperWindowsLocked() {
1704 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001706 final int dw = mDisplay.getWidth();
1707 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001709 // First find top-most window that has asked to be on top of the
1710 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001711 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001712 int N = localmWindows.size();
1713 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001714 WindowState foundW = null;
1715 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001716 WindowState topCurW = null;
1717 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001718 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001719 int i = N;
1720 while (i > 0) {
1721 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001722 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001723 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1724 if (topCurW == null) {
1725 topCurW = w;
1726 topCurI = i;
1727 }
1728 continue;
1729 }
1730 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001731 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001732 // If this window's app token is hidden and not animating,
1733 // it is of no interest to us.
1734 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001735 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001736 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001737 continue;
1738 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001739 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001740 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1742 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001743 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001744 && (mWallpaperTarget == w
1745 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001746 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001747 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001748 foundW = w;
1749 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001750 if (w == mWallpaperTarget && ((w.mAppToken != null
1751 && w.mAppToken.animation != null)
1752 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001753 // The current wallpaper target is animating, so we'll
1754 // look behind it for another possible target and figure
1755 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001756 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001757 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001758 continue;
1759 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001760 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001761 } else if (w == mWindowDetachedWallpaper) {
1762 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001763 }
1764 }
1765
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001766 if (foundW == null && windowDetachedI >= 0) {
1767 if (DEBUG_WALLPAPER) Slog.v(TAG,
1768 "Found animating detached wallpaper activity: #" + i + "=" + w);
1769 foundW = w;
1770 foundI = windowDetachedI;
1771 }
1772
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001773 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001774 // If we are currently waiting for an app transition, and either
1775 // the current target or the next target are involved with it,
1776 // then hold off on doing anything with the wallpaper.
1777 // Note that we are checking here for just whether the target
1778 // is part of an app token... which is potentially overly aggressive
1779 // (the app token may not be involved in the transition), but good
1780 // enough (we'll just wait until whatever transition is pending
1781 // executes).
1782 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001783 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001784 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001785 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001786 }
1787 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001788 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001789 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001790 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001791 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001792 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001793
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001794 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001795 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001796 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 + " oldTarget: " + mWallpaperTarget);
1798 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001799
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001800 mLowerWallpaperTarget = null;
1801 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001802
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001803 WindowState oldW = mWallpaperTarget;
1804 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001805
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 // Now what is happening... if the current and new targets are
1807 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001808 if (foundW != null && oldW != null) {
1809 boolean oldAnim = oldW.mAnimation != null
1810 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1811 boolean foundAnim = foundW.mAnimation != null
1812 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001813 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001814 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001815 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001816 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001817 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 int oldI = localmWindows.indexOf(oldW);
1819 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001820 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001821 }
1822 if (oldI >= 0) {
1823 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001824 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001825 + "=" + oldW + "; new#" + foundI
1826 + "=" + foundW);
1827 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001828
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001829 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001830 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001831 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001833 }
1834 mWallpaperTarget = oldW;
1835 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001836
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001837 // Now set the upper and lower wallpaper targets
1838 // correctly, and make sure that we are positioning
1839 // the wallpaper below the lower.
1840 if (foundI > oldI) {
1841 // The new target is on top of the old one.
1842 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001843 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001844 }
1845 mUpperWallpaperTarget = foundW;
1846 mLowerWallpaperTarget = oldW;
1847 foundW = oldW;
1848 foundI = oldI;
1849 } else {
1850 // The new target is below the old one.
1851 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001852 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001853 }
1854 mUpperWallpaperTarget = oldW;
1855 mLowerWallpaperTarget = foundW;
1856 }
1857 }
1858 }
1859 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001860
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001861 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001862 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001863 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1864 || (mLowerWallpaperTarget.mAppToken != null
1865 && mLowerWallpaperTarget.mAppToken.animation != null);
1866 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1867 || (mUpperWallpaperTarget.mAppToken != null
1868 && mUpperWallpaperTarget.mAppToken.animation != null);
1869 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001871 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001872 }
1873 mLowerWallpaperTarget = null;
1874 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001875 }
1876 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001877
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001878 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001879 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001880 // The window is visible to the compositor... but is it visible
1881 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001882 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001884
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001885 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001886 // its layer adjustment. Only do this if we are not transfering
1887 // between two wallpaper targets.
1888 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001889 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001890 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001891
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001892 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1893 * TYPE_LAYER_MULTIPLIER
1894 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001895
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001896 // Now w is the window we are supposed to be behind... but we
1897 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001898 // AND any starting window associated with it, AND below the
1899 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001900 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001901 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001902 if (wb.mBaseLayer < maxLayer &&
1903 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001904 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001905 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001906 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001907 // This window is not related to the previous one in any
1908 // interesting way, so stop here.
1909 break;
1910 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001911 foundW = wb;
1912 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001913 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001914 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001915 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001916 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001917
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001918 if (foundW == null && topCurW != null) {
1919 // There is no wallpaper target, so it goes at the bottom.
1920 // We will assume it is the same place as last time, if known.
1921 foundW = topCurW;
1922 foundI = topCurI+1;
1923 } else {
1924 // Okay i is the position immediately above the wallpaper. Look at
1925 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001926 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001927 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001928
Dianne Hackborn284ac932009-08-28 10:34:25 -07001929 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001930 if (mWallpaperTarget.mWallpaperX >= 0) {
1931 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001932 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001933 }
1934 if (mWallpaperTarget.mWallpaperY >= 0) {
1935 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001936 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001937 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001938 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001939
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001940 // Start stepping backwards from here, ensuring that our wallpaper windows
1941 // are correctly placed.
1942 int curTokenIndex = mWallpaperTokens.size();
1943 while (curTokenIndex > 0) {
1944 curTokenIndex--;
1945 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001946 if (token.hidden == visible) {
1947 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1948 token.hidden = !visible;
1949 // Need to do a layout to ensure the wallpaper now has the
1950 // correct size.
1951 mLayoutNeeded = true;
1952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001953
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001954 int curWallpaperIndex = token.windows.size();
1955 while (curWallpaperIndex > 0) {
1956 curWallpaperIndex--;
1957 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001958
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001959 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001960 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001961 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001962
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001963 // First, make sure the client has the current visibility
1964 // state.
1965 if (wallpaper.mWallpaperVisible != visible) {
1966 wallpaper.mWallpaperVisible = visible;
1967 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001968 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001969 "Setting visibility of wallpaper " + wallpaper
1970 + ": " + visible);
1971 wallpaper.mClient.dispatchAppVisibility(visible);
1972 } catch (RemoteException e) {
1973 }
1974 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001975
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001976 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001977 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001978 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001979
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001980 // First, if this window is at the current index, then all
1981 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001982 if (wallpaper == foundW) {
1983 foundI--;
1984 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001985 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001986 continue;
1987 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001989 // The window didn't match... the current wallpaper window,
1990 // wherever it is, is in the wrong place, so make sure it is
1991 // not in the list.
1992 int oldIndex = localmWindows.indexOf(wallpaper);
1993 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001994 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001995 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001996 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001997 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001998 if (oldIndex < foundI) {
1999 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002000 }
2001 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002002
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002003 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002004 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002005 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002006 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002007
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002008 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002009 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002010 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002011 }
2012 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002013
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002014 return changed;
2015 }
2016
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002017 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002018 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002019 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002020 mWallpaperAnimLayerAdjustment = adj;
2021 int curTokenIndex = mWallpaperTokens.size();
2022 while (curTokenIndex > 0) {
2023 curTokenIndex--;
2024 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2025 int curWallpaperIndex = token.windows.size();
2026 while (curWallpaperIndex > 0) {
2027 curWallpaperIndex--;
2028 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2029 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002030 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002031 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002032 }
2033 }
2034 }
2035
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002036 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2037 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002038 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002039 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002040 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002041 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002042 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2043 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2044 changed = wallpaperWin.mXOffset != offset;
2045 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002046 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002047 + wallpaperWin + " x: " + offset);
2048 wallpaperWin.mXOffset = offset;
2049 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002050 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002051 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002052 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002053 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002054 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002055
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002056 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002057 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002058 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2059 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2060 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002061 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002062 + wallpaperWin + " y: " + offset);
2063 changed = true;
2064 wallpaperWin.mYOffset = offset;
2065 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002066 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002067 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002068 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002069 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002070 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002071
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002072 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002073 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002074 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002075 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2076 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002077 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002078 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002079 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002080 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002081 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2082 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002083 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002084 if (mWaitingOnWallpaper != null) {
2085 long start = SystemClock.uptimeMillis();
2086 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2087 < start) {
2088 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002089 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002090 "Waiting for offset complete...");
2091 mWindowMap.wait(WALLPAPER_TIMEOUT);
2092 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002093 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002094 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002095 if ((start+WALLPAPER_TIMEOUT)
2096 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002097 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002098 + wallpaperWin);
2099 mLastWallpaperTimeoutTime = start;
2100 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002101 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002102 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002103 }
2104 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002105 } catch (RemoteException e) {
2106 }
2107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002108
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002109 return changed;
2110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002111
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002112 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002113 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002114 if (mWaitingOnWallpaper != null &&
2115 mWaitingOnWallpaper.mClient.asBinder() == window) {
2116 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002117 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002118 }
2119 }
2120 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002121
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002122 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002123 final int dw = mDisplay.getWidth();
2124 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002125
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002126 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002127
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002128 WindowState target = mWallpaperTarget;
2129 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002130 if (target.mWallpaperX >= 0) {
2131 mLastWallpaperX = target.mWallpaperX;
2132 } else if (changingTarget.mWallpaperX >= 0) {
2133 mLastWallpaperX = changingTarget.mWallpaperX;
2134 }
2135 if (target.mWallpaperY >= 0) {
2136 mLastWallpaperY = target.mWallpaperY;
2137 } else if (changingTarget.mWallpaperY >= 0) {
2138 mLastWallpaperY = changingTarget.mWallpaperY;
2139 }
2140 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002141
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002142 int curTokenIndex = mWallpaperTokens.size();
2143 while (curTokenIndex > 0) {
2144 curTokenIndex--;
2145 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2146 int curWallpaperIndex = token.windows.size();
2147 while (curWallpaperIndex > 0) {
2148 curWallpaperIndex--;
2149 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2150 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2151 wallpaper.computeShownFrameLocked();
2152 changed = true;
2153 // We only want to be synchronous with one wallpaper.
2154 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002155 }
2156 }
2157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002158
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002159 return changed;
2160 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002161
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002162 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002163 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002164 final int dw = mDisplay.getWidth();
2165 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002166
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002167 int curTokenIndex = mWallpaperTokens.size();
2168 while (curTokenIndex > 0) {
2169 curTokenIndex--;
2170 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002171 if (token.hidden == visible) {
2172 token.hidden = !visible;
2173 // Need to do a layout to ensure the wallpaper now has the
2174 // correct size.
2175 mLayoutNeeded = true;
2176 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002177
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002178 int curWallpaperIndex = token.windows.size();
2179 while (curWallpaperIndex > 0) {
2180 curWallpaperIndex--;
2181 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2182 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002183 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002184 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002185
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002186 if (wallpaper.mWallpaperVisible != visible) {
2187 wallpaper.mWallpaperVisible = visible;
2188 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002189 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002190 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002191 + ": " + visible);
2192 wallpaper.mClient.dispatchAppVisibility(visible);
2193 } catch (RemoteException e) {
2194 }
2195 }
2196 }
2197 }
2198 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002200 public int addWindow(Session session, IWindow client,
2201 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002202 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 int res = mPolicy.checkAddPermission(attrs);
2204 if (res != WindowManagerImpl.ADD_OKAY) {
2205 return res;
2206 }
Romain Guy06882f82009-06-10 13:36:04 -07002207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 boolean reportNewConfig = false;
2209 WindowState attachedWindow = null;
2210 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002211 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002215 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 }
Romain Guy06882f82009-06-10 13:36:04 -07002217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002219 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2221 }
2222
2223 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002224 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002226 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 + attrs.token + ". Aborting.");
2228 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2229 }
2230 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2231 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002232 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233 + attrs.token + ". Aborting.");
2234 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2235 }
2236 }
2237
2238 boolean addToken = false;
2239 WindowToken token = mTokenMap.get(attrs.token);
2240 if (token == null) {
2241 if (attrs.type >= FIRST_APPLICATION_WINDOW
2242 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002243 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 + attrs.token + ". Aborting.");
2245 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2246 }
2247 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002248 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 + attrs.token + ". Aborting.");
2250 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2251 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002252 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002253 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002254 + attrs.token + ". Aborting.");
2255 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 token = new WindowToken(attrs.token, -1, false);
2258 addToken = true;
2259 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2260 && attrs.type <= LAST_APPLICATION_WINDOW) {
2261 AppWindowToken atoken = token.appWindowToken;
2262 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002263 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 + token + ". Aborting.");
2265 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2266 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002267 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 + token + ". Aborting.");
2269 return WindowManagerImpl.ADD_APP_EXITING;
2270 }
2271 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2272 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002273 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002274 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2275 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2276 }
2277 } else if (attrs.type == TYPE_INPUT_METHOD) {
2278 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002279 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 + attrs.token + ". Aborting.");
2281 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2282 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002283 } else if (attrs.type == TYPE_WALLPAPER) {
2284 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002285 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002286 + attrs.token + ". Aborting.");
2287 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2288 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 }
2290
2291 win = new WindowState(session, client, token,
2292 attachedWindow, attrs, viewVisibility);
2293 if (win.mDeathRecipient == null) {
2294 // Client has apparently died, so there is no reason to
2295 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002296 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 + " that is dead, aborting.");
2298 return WindowManagerImpl.ADD_APP_EXITING;
2299 }
2300
2301 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 res = mPolicy.prepareAddWindowLw(win, attrs);
2304 if (res != WindowManagerImpl.ADD_OKAY) {
2305 return res;
2306 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002307
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002308 if (outInputChannel != null) {
2309 String name = win.makeInputChannelName();
2310 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2311 win.mInputChannel = inputChannels[0];
2312 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2313
2314 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316
2317 // From now on, no exceptions or errors allowed!
2318
2319 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002320
Dianne Hackborn5132b372010-07-29 12:51:35 -07002321 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 if (addToken) {
2324 mTokenMap.put(attrs.token, token);
2325 mTokenList.add(token);
2326 }
2327 win.attach();
2328 mWindowMap.put(client.asBinder(), win);
2329
2330 if (attrs.type == TYPE_APPLICATION_STARTING &&
2331 token.appWindowToken != null) {
2332 token.appWindowToken.startingWindow = win;
2333 }
2334
2335 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 if (attrs.type == TYPE_INPUT_METHOD) {
2338 mInputMethodWindow = win;
2339 addInputMethodWindowToListLocked(win);
2340 imMayMove = false;
2341 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2342 mInputMethodDialogs.add(win);
2343 addWindowToListInOrderLocked(win, true);
2344 adjustInputMethodDialogsLocked();
2345 imMayMove = false;
2346 } else {
2347 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002348 if (attrs.type == TYPE_WALLPAPER) {
2349 mLastWallpaperTimeoutTime = 0;
2350 adjustWallpaperWindowsLocked();
2351 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002352 adjustWallpaperWindowsLocked();
2353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 }
Romain Guy06882f82009-06-10 13:36:04 -07002355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 if (mInTouchMode) {
2361 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2362 }
2363 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2364 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2365 }
Romain Guy06882f82009-06-10 13:36:04 -07002366
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002367 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002369 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2370 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 imMayMove = false;
2372 }
2373 }
Romain Guy06882f82009-06-10 13:36:04 -07002374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002376 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 }
Romain Guy06882f82009-06-10 13:36:04 -07002378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002379 assignLayersLocked();
2380 // Don't do layout here, the window must call
2381 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 //dump();
2384
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002385 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002386 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002387 }
Jeff Brown349703e2010-06-22 01:27:15 -07002388
Joe Onorato8a9b2202010-02-26 18:56:32 -08002389 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 TAG, "New client " + client.asBinder()
2391 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002392
2393 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2394 reportNewConfig = true;
2395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 }
2397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 if (reportNewConfig) {
2399 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 return res;
2405 }
Romain Guy06882f82009-06-10 13:36:04 -07002406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 public void removeWindow(Session session, IWindow client) {
2408 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002409 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 if (win == null) {
2411 return;
2412 }
2413 removeWindowLocked(session, win);
2414 }
2415 }
Romain Guy06882f82009-06-10 13:36:04 -07002416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 public void removeWindowLocked(Session session, WindowState win) {
2418
Joe Onorato8a9b2202010-02-26 18:56:32 -08002419 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 TAG, "Remove " + win + " client="
2421 + Integer.toHexString(System.identityHashCode(
2422 win.mClient.asBinder()))
2423 + ", surface=" + win.mSurface);
2424
2425 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002426
2427 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002428
Joe Onorato8a9b2202010-02-26 18:56:32 -08002429 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2431 + " mExiting=" + win.mExiting
2432 + " isAnimating=" + win.isAnimating()
2433 + " app-animation="
2434 + (win.mAppToken != null ? win.mAppToken.animation : null)
2435 + " inPendingTransaction="
2436 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2437 + " mDisplayFrozen=" + mDisplayFrozen);
2438 // Visibility of the removed window. Will be used later to update orientation later on.
2439 boolean wasVisible = false;
2440 // First, see if we need to run an animation. If we do, we have
2441 // to hold off on removing the window until the animation is done.
2442 // If the display is frozen, just remove immediately, since the
2443 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002444 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 // If we are not currently running the exit animation, we
2446 // need to see about starting one.
2447 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2450 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2451 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2452 }
2453 // Try starting an animation.
2454 if (applyAnimationLocked(win, transit, false)) {
2455 win.mExiting = true;
2456 }
2457 }
2458 if (win.mExiting || win.isAnimating()) {
2459 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002460 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 win.mExiting = true;
2462 win.mRemoveOnExit = true;
2463 mLayoutNeeded = true;
2464 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2465 performLayoutAndPlaceSurfacesLocked();
2466 if (win.mAppToken != null) {
2467 win.mAppToken.updateReportedVisibilityLocked();
2468 }
2469 //dump();
2470 Binder.restoreCallingIdentity(origId);
2471 return;
2472 }
2473 }
2474
2475 removeWindowInnerLocked(session, win);
2476 // Removing a visible window will effect the computed orientation
2477 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002478 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002479 != mForcedAppOrientation
2480 && updateOrientationFromAppTokensLocked()) {
2481 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 }
2483 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2484 Binder.restoreCallingIdentity(origId);
2485 }
Romain Guy06882f82009-06-10 13:36:04 -07002486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 if (mInputMethodTarget == win) {
2491 moveInputMethodWindowsIfNeededLocked(false);
2492 }
Romain Guy06882f82009-06-10 13:36:04 -07002493
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002494 if (false) {
2495 RuntimeException e = new RuntimeException("here");
2496 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002497 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002498 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 mPolicy.removeWindowLw(win);
2501 win.removeLocked();
2502
2503 mWindowMap.remove(win.mClient.asBinder());
2504 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002505 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002506 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507
2508 if (mInputMethodWindow == win) {
2509 mInputMethodWindow = null;
2510 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2511 mInputMethodDialogs.remove(win);
2512 }
Romain Guy06882f82009-06-10 13:36:04 -07002513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 final WindowToken token = win.mToken;
2515 final AppWindowToken atoken = win.mAppToken;
2516 token.windows.remove(win);
2517 if (atoken != null) {
2518 atoken.allAppWindows.remove(win);
2519 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002520 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 TAG, "**** Removing window " + win + ": count="
2522 + token.windows.size());
2523 if (token.windows.size() == 0) {
2524 if (!token.explicit) {
2525 mTokenMap.remove(token.token);
2526 mTokenList.remove(token);
2527 } else if (atoken != null) {
2528 atoken.firstWindowDrawn = false;
2529 }
2530 }
2531
2532 if (atoken != null) {
2533 if (atoken.startingWindow == win) {
2534 atoken.startingWindow = null;
2535 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2536 // If this is the last window and we had requested a starting
2537 // transition window, well there is no point now.
2538 atoken.startingData = null;
2539 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2540 // If this is the last window except for a starting transition
2541 // window, we need to get rid of the starting transition.
2542 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002543 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 + ": no more real windows");
2545 }
2546 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2547 mH.sendMessage(m);
2548 }
2549 }
Romain Guy06882f82009-06-10 13:36:04 -07002550
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002551 if (win.mAttrs.type == TYPE_WALLPAPER) {
2552 mLastWallpaperTimeoutTime = 0;
2553 adjustWallpaperWindowsLocked();
2554 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002555 adjustWallpaperWindowsLocked();
2556 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 if (!mInLayout) {
2559 assignLayersLocked();
2560 mLayoutNeeded = true;
2561 performLayoutAndPlaceSurfacesLocked();
2562 if (win.mAppToken != null) {
2563 win.mAppToken.updateReportedVisibilityLocked();
2564 }
2565 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002566
2567 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 }
2569
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002570 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2571 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2572 + ": " + msg + " / " + w.mAttrs.getTitle();
2573 if (where != null) {
2574 Slog.i(TAG, str, where);
2575 } else {
2576 Slog.i(TAG, str);
2577 }
2578 }
2579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2581 long origId = Binder.clearCallingIdentity();
2582 try {
2583 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002584 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002586 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 Surface.openTransaction();
2588 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002589 if (SHOW_TRANSACTIONS) logSurface(w,
2590 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 w.mSurface.setTransparentRegionHint(region);
2592 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002593 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 Surface.closeTransaction();
2595 }
2596 }
2597 }
2598 } finally {
2599 Binder.restoreCallingIdentity(origId);
2600 }
2601 }
2602
2603 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002604 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 Rect visibleInsets) {
2606 long origId = Binder.clearCallingIdentity();
2607 try {
2608 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002609 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 if (w != null) {
2611 w.mGivenInsetsPending = false;
2612 w.mGivenContentInsets.set(contentInsets);
2613 w.mGivenVisibleInsets.set(visibleInsets);
2614 w.mTouchableInsets = touchableInsets;
2615 mLayoutNeeded = true;
2616 performLayoutAndPlaceSurfacesLocked();
2617 }
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(origId);
2621 }
2622 }
Romain Guy06882f82009-06-10 13:36:04 -07002623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 public void getWindowDisplayFrame(Session session, IWindow client,
2625 Rect outDisplayFrame) {
2626 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002627 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 if (win == null) {
2629 outDisplayFrame.setEmpty();
2630 return;
2631 }
2632 outDisplayFrame.set(win.mDisplayFrame);
2633 }
2634 }
2635
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002636 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2637 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002638 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2639 window.mWallpaperX = x;
2640 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002641 window.mWallpaperXStep = xStep;
2642 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002643 if (updateWallpaperOffsetLocked(window, true)) {
2644 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002645 }
2646 }
2647 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002648
Dianne Hackborn75804932009-10-20 20:15:20 -07002649 void wallpaperCommandComplete(IBinder window, Bundle result) {
2650 synchronized (mWindowMap) {
2651 if (mWaitingOnWallpaper != null &&
2652 mWaitingOnWallpaper.mClient.asBinder() == window) {
2653 mWaitingOnWallpaper = null;
2654 mWindowMap.notifyAll();
2655 }
2656 }
2657 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002658
Dianne Hackborn75804932009-10-20 20:15:20 -07002659 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2660 String action, int x, int y, int z, Bundle extras, boolean sync) {
2661 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2662 || window == mUpperWallpaperTarget) {
2663 boolean doWait = sync;
2664 int curTokenIndex = mWallpaperTokens.size();
2665 while (curTokenIndex > 0) {
2666 curTokenIndex--;
2667 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2668 int curWallpaperIndex = token.windows.size();
2669 while (curWallpaperIndex > 0) {
2670 curWallpaperIndex--;
2671 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2672 try {
2673 wallpaper.mClient.dispatchWallpaperCommand(action,
2674 x, y, z, extras, sync);
2675 // We only want to be synchronous with one wallpaper.
2676 sync = false;
2677 } catch (RemoteException e) {
2678 }
2679 }
2680 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002681
Dianne Hackborn75804932009-10-20 20:15:20 -07002682 if (doWait) {
2683 // XXX Need to wait for result.
2684 }
2685 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002686
Dianne Hackborn75804932009-10-20 20:15:20 -07002687 return null;
2688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 public int relayoutWindow(Session session, IWindow client,
2691 WindowManager.LayoutParams attrs, int requestedWidth,
2692 int requestedHeight, int viewVisibility, boolean insetsPending,
2693 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002694 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 boolean displayed = false;
2696 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002697 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002701 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 if (win == null) {
2703 return 0;
2704 }
2705 win.mRequestedWidth = requestedWidth;
2706 win.mRequestedHeight = requestedHeight;
2707
2708 if (attrs != null) {
2709 mPolicy.adjustWindowParamsLw(attrs);
2710 }
Romain Guy06882f82009-06-10 13:36:04 -07002711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 int attrChanges = 0;
2713 int flagChanges = 0;
2714 if (attrs != null) {
2715 flagChanges = win.mAttrs.flags ^= attrs.flags;
2716 attrChanges = win.mAttrs.copyFrom(attrs);
2717 }
2718
Joe Onorato8a9b2202010-02-26 18:56:32 -08002719 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002720
2721 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2722 win.mAlpha = attrs.alpha;
2723 }
2724
2725 final boolean scaledWindow =
2726 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2727
2728 if (scaledWindow) {
2729 // requested{Width|Height} Surface's physical size
2730 // attrs.{width|height} Size on screen
2731 win.mHScale = (attrs.width != requestedWidth) ?
2732 (attrs.width / (float)requestedWidth) : 1.0f;
2733 win.mVScale = (attrs.height != requestedHeight) ?
2734 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002735 } else {
2736 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 }
2738
2739 boolean imMayMove = (flagChanges&(
2740 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2741 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 boolean focusMayChange = win.mViewVisibility != viewVisibility
2744 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2745 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002746
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002747 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2748 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 win.mRelayoutCalled = true;
2751 final int oldVisibility = win.mViewVisibility;
2752 win.mViewVisibility = viewVisibility;
2753 if (viewVisibility == View.VISIBLE &&
2754 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2755 displayed = !win.isVisibleLw();
2756 if (win.mExiting) {
2757 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002758 if (win.mAnimation != null) {
2759 win.mAnimation.cancel();
2760 win.mAnimation = null;
2761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 }
2763 if (win.mDestroying) {
2764 win.mDestroying = false;
2765 mDestroySurface.remove(win);
2766 }
2767 if (oldVisibility == View.GONE) {
2768 win.mEnterAnimationPending = true;
2769 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002770 if (displayed) {
2771 if (win.mSurface != null && !win.mDrawPending
2772 && !win.mCommitDrawPending && !mDisplayFrozen
2773 && mPolicy.isScreenOn()) {
2774 applyEnterAnimationLocked(win);
2775 }
2776 if ((win.mAttrs.flags
2777 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2778 if (DEBUG_VISIBILITY) Slog.v(TAG,
2779 "Relayout window turning screen on: " + win);
2780 win.mTurnOnScreen = true;
2781 }
2782 int diff = 0;
2783 if (win.mConfiguration != mCurConfiguration
2784 && (win.mConfiguration == null
2785 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2786 win.mConfiguration = mCurConfiguration;
2787 if (DEBUG_CONFIGURATION) {
2788 Slog.i(TAG, "Window " + win + " visible with new config: "
2789 + win.mConfiguration + " / 0x"
2790 + Integer.toHexString(diff));
2791 }
2792 outConfig.setTo(mCurConfiguration);
2793 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2796 // To change the format, we need to re-build the surface.
2797 win.destroySurfaceLocked();
2798 displayed = true;
2799 }
2800 try {
2801 Surface surface = win.createSurfaceLocked();
2802 if (surface != null) {
2803 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002804 win.mReportDestroySurface = false;
2805 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002806 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002807 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002809 // For some reason there isn't a surface. Clear the
2810 // caller's object so they see the same state.
2811 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 }
2813 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002814 mInputMonitor.updateInputWindowsLw();
2815
Joe Onorato8a9b2202010-02-26 18:56:32 -08002816 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002817 + client + " (" + win.mAttrs.getTitle() + ")",
2818 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 Binder.restoreCallingIdentity(origId);
2820 return 0;
2821 }
2822 if (displayed) {
2823 focusMayChange = true;
2824 }
2825 if (win.mAttrs.type == TYPE_INPUT_METHOD
2826 && mInputMethodWindow == null) {
2827 mInputMethodWindow = win;
2828 imMayMove = true;
2829 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002830 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2831 && win.mAppToken != null
2832 && win.mAppToken.startingWindow != null) {
2833 // Special handling of starting window over the base
2834 // window of the app: propagate lock screen flags to it,
2835 // to provide the correct semantics while starting.
2836 final int mask =
2837 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002838 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2839 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002840 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2841 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2842 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 } else {
2844 win.mEnterAnimationPending = false;
2845 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002846 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002847 + ": mExiting=" + win.mExiting
2848 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 // If we are not currently running the exit animation, we
2850 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002851 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 // Try starting an animation; if there isn't one, we
2853 // can destroy the surface right away.
2854 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2855 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2856 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2857 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002858 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002860 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 } else if (win.isAnimating()) {
2863 // Currently in a hide animation... turn this into
2864 // an exit.
2865 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002866 } else if (win == mWallpaperTarget) {
2867 // If the wallpaper is currently behind this
2868 // window, we need to change both of them inside
2869 // of a transaction to avoid artifacts.
2870 win.mExiting = true;
2871 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 } else {
2873 if (mInputMethodWindow == win) {
2874 mInputMethodWindow = null;
2875 }
2876 win.destroySurfaceLocked();
2877 }
2878 }
2879 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002880
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002881 if (win.mSurface == null || (win.getAttrs().flags
2882 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2883 || win.mSurfacePendingDestroy) {
2884 // We are being called from a local process, which
2885 // means outSurface holds its current surface. Ensure the
2886 // surface object is cleared, but we don't want it actually
2887 // destroyed at this point.
2888 win.mSurfacePendingDestroy = false;
2889 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002890 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002891 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002892 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002893 "Keeping surface, will report destroy: " + win);
2894 win.mReportDestroySurface = true;
2895 outSurface.copyFrom(win.mSurface);
2896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 }
2898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 if (focusMayChange) {
2900 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2901 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 imMayMove = false;
2903 }
2904 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2905 }
Romain Guy06882f82009-06-10 13:36:04 -07002906
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002907 // updateFocusedWindowLocked() already assigned layers so we only need to
2908 // reassign them at this point if the IM window state gets shuffled
2909 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002912 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2913 // Little hack here -- we -should- be able to rely on the
2914 // function to return true if the IME has moved and needs
2915 // its layer recomputed. However, if the IME was hidden
2916 // and isn't actually moved in the list, its layer may be
2917 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 assignLayers = true;
2919 }
2920 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002921 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002922 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002923 assignLayers = true;
2924 }
2925 }
Romain Guy06882f82009-06-10 13:36:04 -07002926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 mLayoutNeeded = true;
2928 win.mGivenInsetsPending = insetsPending;
2929 if (assignLayers) {
2930 assignLayersLocked();
2931 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002932 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002934 if (displayed && win.mIsWallpaper) {
2935 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002936 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 if (win.mAppToken != null) {
2939 win.mAppToken.updateReportedVisibilityLocked();
2940 }
2941 outFrame.set(win.mFrame);
2942 outContentInsets.set(win.mContentInsets);
2943 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002944 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002946 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 + ", requestedHeight=" + requestedHeight
2948 + ", viewVisibility=" + viewVisibility
2949 + "\nRelayout returning frame=" + outFrame
2950 + ", surface=" + outSurface);
2951
Joe Onorato8a9b2202010-02-26 18:56:32 -08002952 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2954
2955 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002956
2957 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 }
2959
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002960 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 sendNewConfiguration();
2962 }
Romain Guy06882f82009-06-10 13:36:04 -07002963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2967 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2968 }
2969
2970 public void finishDrawingWindow(Session session, IWindow client) {
2971 final long origId = Binder.clearCallingIdentity();
2972 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002973 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002975 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2976 adjustWallpaperWindowsLocked();
2977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 mLayoutNeeded = true;
2979 performLayoutAndPlaceSurfacesLocked();
2980 }
2981 }
2982 Binder.restoreCallingIdentity(origId);
2983 }
2984
2985 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002986 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 + (lp != null ? lp.packageName : null)
2988 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2989 if (lp != null && lp.windowAnimations != 0) {
2990 // If this is a system resource, don't try to load it from the
2991 // application resources. It is nice to avoid loading application
2992 // resources if we can.
2993 String packageName = lp.packageName != null ? lp.packageName : "android";
2994 int resId = lp.windowAnimations;
2995 if ((resId&0xFF000000) == 0x01000000) {
2996 packageName = "android";
2997 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002998 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 + packageName);
3000 return AttributeCache.instance().get(packageName, resId,
3001 com.android.internal.R.styleable.WindowAnimation);
3002 }
3003 return null;
3004 }
Romain Guy06882f82009-06-10 13:36:04 -07003005
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003006 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003007 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003008 + packageName + " resId=0x" + Integer.toHexString(resId));
3009 if (packageName != null) {
3010 if ((resId&0xFF000000) == 0x01000000) {
3011 packageName = "android";
3012 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003013 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003014 + packageName);
3015 return AttributeCache.instance().get(packageName, resId,
3016 com.android.internal.R.styleable.WindowAnimation);
3017 }
3018 return null;
3019 }
3020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 private void applyEnterAnimationLocked(WindowState win) {
3022 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3023 if (win.mEnterAnimationPending) {
3024 win.mEnterAnimationPending = false;
3025 transit = WindowManagerPolicy.TRANSIT_ENTER;
3026 }
3027
3028 applyAnimationLocked(win, transit, true);
3029 }
3030
3031 private boolean applyAnimationLocked(WindowState win,
3032 int transit, boolean isEntrance) {
3033 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3034 // If we are trying to apply an animation, but already running
3035 // an animation of the same type, then just leave that one alone.
3036 return true;
3037 }
Romain Guy06882f82009-06-10 13:36:04 -07003038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 // Only apply an animation if the display isn't frozen. If it is
3040 // frozen, there is no reason to animate and it can cause strange
3041 // artifacts when we unfreeze the display if some different animation
3042 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003043 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003044 int anim = mPolicy.selectAnimationLw(win, transit);
3045 int attr = -1;
3046 Animation a = null;
3047 if (anim != 0) {
3048 a = AnimationUtils.loadAnimation(mContext, anim);
3049 } else {
3050 switch (transit) {
3051 case WindowManagerPolicy.TRANSIT_ENTER:
3052 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3053 break;
3054 case WindowManagerPolicy.TRANSIT_EXIT:
3055 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3056 break;
3057 case WindowManagerPolicy.TRANSIT_SHOW:
3058 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3059 break;
3060 case WindowManagerPolicy.TRANSIT_HIDE:
3061 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3062 break;
3063 }
3064 if (attr >= 0) {
3065 a = loadAnimation(win.mAttrs, attr);
3066 }
3067 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003068 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003069 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3070 + " mAnimation=" + win.mAnimation
3071 + " isEntrance=" + isEntrance);
3072 if (a != null) {
3073 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003074 RuntimeException e = null;
3075 if (!HIDE_STACK_CRAWLS) {
3076 e = new RuntimeException();
3077 e.fillInStackTrace();
3078 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003079 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 }
3081 win.setAnimation(a);
3082 win.mAnimationIsEntrance = isEntrance;
3083 }
3084 } else {
3085 win.clearAnimation();
3086 }
3087
3088 return win.mAnimation != null;
3089 }
3090
3091 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3092 int anim = 0;
3093 Context context = mContext;
3094 if (animAttr >= 0) {
3095 AttributeCache.Entry ent = getCachedAnimations(lp);
3096 if (ent != null) {
3097 context = ent.context;
3098 anim = ent.array.getResourceId(animAttr, 0);
3099 }
3100 }
3101 if (anim != 0) {
3102 return AnimationUtils.loadAnimation(context, anim);
3103 }
3104 return null;
3105 }
Romain Guy06882f82009-06-10 13:36:04 -07003106
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003107 private Animation loadAnimation(String packageName, int resId) {
3108 int anim = 0;
3109 Context context = mContext;
3110 if (resId >= 0) {
3111 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3112 if (ent != null) {
3113 context = ent.context;
3114 anim = resId;
3115 }
3116 }
3117 if (anim != 0) {
3118 return AnimationUtils.loadAnimation(context, anim);
3119 }
3120 return null;
3121 }
3122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 private boolean applyAnimationLocked(AppWindowToken wtoken,
3124 WindowManager.LayoutParams lp, int transit, boolean enter) {
3125 // Only apply an animation if the display isn't frozen. If it is
3126 // frozen, there is no reason to animate and it can cause strange
3127 // artifacts when we unfreeze the display if some different animation
3128 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003129 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003130 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003131 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003132 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003133 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003134 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003135 } else if (mNextAppTransitionPackage != null) {
3136 a = loadAnimation(mNextAppTransitionPackage, enter ?
3137 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003138 } else {
3139 int animAttr = 0;
3140 switch (transit) {
3141 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3142 animAttr = enter
3143 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3144 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3145 break;
3146 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3147 animAttr = enter
3148 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3149 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3150 break;
3151 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3152 animAttr = enter
3153 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3154 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3155 break;
3156 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3157 animAttr = enter
3158 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3159 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3160 break;
3161 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3162 animAttr = enter
3163 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3164 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3165 break;
3166 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3167 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003168 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003169 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3170 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003171 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003172 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003173 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3174 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003175 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003176 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003177 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003178 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3179 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3180 break;
3181 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3182 animAttr = enter
3183 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3184 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3185 break;
3186 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3187 animAttr = enter
3188 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3189 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003190 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003191 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003192 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003193 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003194 + " anim=" + a
3195 + " animAttr=0x" + Integer.toHexString(animAttr)
3196 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 if (a != null) {
3199 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003200 RuntimeException e = null;
3201 if (!HIDE_STACK_CRAWLS) {
3202 e = new RuntimeException();
3203 e.fillInStackTrace();
3204 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003205 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 }
3207 wtoken.setAnimation(a);
3208 }
3209 } else {
3210 wtoken.clearAnimation();
3211 }
3212
3213 return wtoken.animation != null;
3214 }
3215
3216 // -------------------------------------------------------------
3217 // Application Window Tokens
3218 // -------------------------------------------------------------
3219
3220 public void validateAppTokens(List tokens) {
3221 int v = tokens.size()-1;
3222 int m = mAppTokens.size()-1;
3223 while (v >= 0 && m >= 0) {
3224 AppWindowToken wtoken = mAppTokens.get(m);
3225 if (wtoken.removed) {
3226 m--;
3227 continue;
3228 }
3229 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003230 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3232 }
3233 v--;
3234 m--;
3235 }
3236 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003237 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 v--;
3239 }
3240 while (m >= 0) {
3241 AppWindowToken wtoken = mAppTokens.get(m);
3242 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003243 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003244 }
3245 m--;
3246 }
3247 }
3248
3249 boolean checkCallingPermission(String permission, String func) {
3250 // Quick check: if the calling permission is me, it's all okay.
3251 if (Binder.getCallingPid() == Process.myPid()) {
3252 return true;
3253 }
Romain Guy06882f82009-06-10 13:36:04 -07003254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 if (mContext.checkCallingPermission(permission)
3256 == PackageManager.PERMISSION_GRANTED) {
3257 return true;
3258 }
3259 String msg = "Permission Denial: " + func + " from pid="
3260 + Binder.getCallingPid()
3261 + ", uid=" + Binder.getCallingUid()
3262 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003263 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 return false;
3265 }
Romain Guy06882f82009-06-10 13:36:04 -07003266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 AppWindowToken findAppWindowToken(IBinder token) {
3268 WindowToken wtoken = mTokenMap.get(token);
3269 if (wtoken == null) {
3270 return null;
3271 }
3272 return wtoken.appWindowToken;
3273 }
Romain Guy06882f82009-06-10 13:36:04 -07003274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 public void addWindowToken(IBinder token, int type) {
3276 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3277 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003278 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 }
Romain Guy06882f82009-06-10 13:36:04 -07003280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 synchronized(mWindowMap) {
3282 WindowToken wtoken = mTokenMap.get(token);
3283 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003284 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 return;
3286 }
3287 wtoken = new WindowToken(token, type, true);
3288 mTokenMap.put(token, wtoken);
3289 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003290 if (type == TYPE_WALLPAPER) {
3291 mWallpaperTokens.add(wtoken);
3292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 }
3294 }
Romain Guy06882f82009-06-10 13:36:04 -07003295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 public void removeWindowToken(IBinder token) {
3297 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3298 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003299 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 }
3301
3302 final long origId = Binder.clearCallingIdentity();
3303 synchronized(mWindowMap) {
3304 WindowToken wtoken = mTokenMap.remove(token);
3305 mTokenList.remove(wtoken);
3306 if (wtoken != null) {
3307 boolean delayed = false;
3308 if (!wtoken.hidden) {
3309 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 final int N = wtoken.windows.size();
3312 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003314 for (int i=0; i<N; i++) {
3315 WindowState win = wtoken.windows.get(i);
3316
3317 if (win.isAnimating()) {
3318 delayed = true;
3319 }
Romain Guy06882f82009-06-10 13:36:04 -07003320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 if (win.isVisibleNow()) {
3322 applyAnimationLocked(win,
3323 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 changed = true;
3325 }
3326 }
3327
3328 if (changed) {
3329 mLayoutNeeded = true;
3330 performLayoutAndPlaceSurfacesLocked();
3331 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3332 }
Romain Guy06882f82009-06-10 13:36:04 -07003333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 if (delayed) {
3335 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003336 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3337 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 }
3339 }
Romain Guy06882f82009-06-10 13:36:04 -07003340
Jeff Brownc5ed5912010-07-14 18:48:53 -07003341 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003343 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 }
3345 }
3346 Binder.restoreCallingIdentity(origId);
3347 }
3348
3349 public void addAppToken(int addPos, IApplicationToken token,
3350 int groupId, int requestedOrientation, boolean fullscreen) {
3351 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3352 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003353 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 }
Jeff Brown349703e2010-06-22 01:27:15 -07003355
3356 // Get the dispatching timeout here while we are not holding any locks so that it
3357 // can be cached by the AppWindowToken. The timeout value is used later by the
3358 // input dispatcher in code that does hold locks. If we did not cache the value
3359 // here we would run the chance of introducing a deadlock between the window manager
3360 // (which holds locks while updating the input dispatcher state) and the activity manager
3361 // (which holds locks while querying the application token).
3362 long inputDispatchingTimeoutNanos;
3363 try {
3364 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3365 } catch (RemoteException ex) {
3366 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3367 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3368 }
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 synchronized(mWindowMap) {
3371 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3372 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003373 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 return;
3375 }
3376 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003377 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 wtoken.groupId = groupId;
3379 wtoken.appFullscreen = fullscreen;
3380 wtoken.requestedOrientation = requestedOrientation;
3381 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003382 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 mTokenMap.put(token.asBinder(), wtoken);
3384 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 // Application tokens start out hidden.
3387 wtoken.hidden = true;
3388 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 //dump();
3391 }
3392 }
Romain Guy06882f82009-06-10 13:36:04 -07003393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003394 public void setAppGroupId(IBinder token, int groupId) {
3395 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3396 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003397 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 }
3399
3400 synchronized(mWindowMap) {
3401 AppWindowToken wtoken = findAppWindowToken(token);
3402 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003403 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 return;
3405 }
3406 wtoken.groupId = groupId;
3407 }
3408 }
Romain Guy06882f82009-06-10 13:36:04 -07003409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 public int getOrientationFromWindowsLocked() {
3411 int pos = mWindows.size() - 1;
3412 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003413 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 pos--;
3415 if (wtoken.mAppToken != null) {
3416 // We hit an application window. so the orientation will be determined by the
3417 // app window. No point in continuing further.
3418 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3419 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003420 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 continue;
3422 }
3423 int req = wtoken.mAttrs.screenOrientation;
3424 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3425 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3426 continue;
3427 } else {
3428 return req;
3429 }
3430 }
3431 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3432 }
Romain Guy06882f82009-06-10 13:36:04 -07003433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003435 int pos = mAppTokens.size() - 1;
3436 int curGroup = 0;
3437 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3438 boolean findingBehind = false;
3439 boolean haveGroup = false;
3440 boolean lastFullscreen = false;
3441 while (pos >= 0) {
3442 AppWindowToken wtoken = mAppTokens.get(pos);
3443 pos--;
3444 // if we're about to tear down this window and not seek for
3445 // the behind activity, don't use it for orientation
3446 if (!findingBehind
3447 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3448 continue;
3449 }
3450
3451 if (!haveGroup) {
3452 // We ignore any hidden applications on the top.
3453 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003454 continue;
3455 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003456 haveGroup = true;
3457 curGroup = wtoken.groupId;
3458 lastOrientation = wtoken.requestedOrientation;
3459 } else if (curGroup != wtoken.groupId) {
3460 // If we have hit a new application group, and the bottom
3461 // of the previous group didn't explicitly say to use
3462 // the orientation behind it, and the last app was
3463 // full screen, then we'll stick with the
3464 // user's orientation.
3465 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3466 && lastFullscreen) {
3467 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003469 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003470 int or = wtoken.requestedOrientation;
3471 // If this application is fullscreen, and didn't explicitly say
3472 // to use the orientation behind it, then just take whatever
3473 // orientation it has and ignores whatever is under it.
3474 lastFullscreen = wtoken.appFullscreen;
3475 if (lastFullscreen
3476 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3477 return or;
3478 }
3479 // If this application has requested an explicit orientation,
3480 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003481 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3482 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003483 return or;
3484 }
3485 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3486 }
3487 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 }
Romain Guy06882f82009-06-10 13:36:04 -07003489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003491 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003492 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3493 "updateOrientationFromAppTokens()")) {
3494 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3495 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003496
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003497 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003499
3500 synchronized(mWindowMap) {
3501 if (updateOrientationFromAppTokensLocked()) {
3502 if (freezeThisOneIfNeeded != null) {
3503 AppWindowToken wtoken = findAppWindowToken(
3504 freezeThisOneIfNeeded);
3505 if (wtoken != null) {
3506 startAppFreezingScreenLocked(wtoken,
3507 ActivityInfo.CONFIG_ORIENTATION);
3508 }
3509 }
3510 config = computeNewConfigurationLocked();
3511
3512 } else if (currentConfig != null) {
3513 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003514 // state mismatches the activity manager's, update it,
3515 // disregarding font scale, which should remain set to
3516 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003517 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003518 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003519 if (computeNewConfigurationLocked(mTempConfiguration)) {
3520 if (currentConfig.diff(mTempConfiguration) != 0) {
3521 mWaitingForConfig = true;
3522 mLayoutNeeded = true;
3523 startFreezingDisplayLocked();
3524 config = new Configuration(mTempConfiguration);
3525 }
3526 }
3527 }
3528 }
3529
Dianne Hackborncfaef692009-06-15 14:24:44 -07003530 Binder.restoreCallingIdentity(ident);
3531 return config;
3532 }
3533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003535 * Determine the new desired orientation of the display, returning
3536 * a non-null new Configuration if it has changed from the current
3537 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3538 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3539 * SCREEN. This will typically be done for you if you call
3540 * sendNewConfiguration().
3541 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 * The orientation is computed from non-application windows first. If none of
3543 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003544 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3546 * android.os.IBinder)
3547 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003548 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003549 if (mDisplayFrozen) {
3550 // If the display is frozen, some activities may be in the middle
3551 // of restarting, and thus have removed their old window. If the
3552 // window has the flag to hide the lock screen, then the lock screen
3553 // can re-appear and inflict its own orientation on us. Keep the
3554 // orientation stable until this all settles down.
3555 return false;
3556 }
3557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 long ident = Binder.clearCallingIdentity();
3560 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003561 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 mForcedAppOrientation = req;
3565 //send a message to Policy indicating orientation change to take
3566 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003567 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003568 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3569 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3570 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 }
3572 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003573
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003574 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 } finally {
3576 Binder.restoreCallingIdentity(ident);
3577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 }
Romain Guy06882f82009-06-10 13:36:04 -07003579
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003580 int computeForcedAppOrientationLocked() {
3581 int req = getOrientationFromWindowsLocked();
3582 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3583 req = getOrientationFromAppTokensLocked();
3584 }
3585 return req;
3586 }
Romain Guy06882f82009-06-10 13:36:04 -07003587
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003588 public void setNewConfiguration(Configuration config) {
3589 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3590 "setNewConfiguration()")) {
3591 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3592 }
3593
3594 synchronized(mWindowMap) {
3595 mCurConfiguration = new Configuration(config);
3596 mWaitingForConfig = false;
3597 performLayoutAndPlaceSurfacesLocked();
3598 }
3599 }
3600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3602 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3603 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003604 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 }
Romain Guy06882f82009-06-10 13:36:04 -07003606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 synchronized(mWindowMap) {
3608 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3609 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003610 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 return;
3612 }
Romain Guy06882f82009-06-10 13:36:04 -07003613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 wtoken.requestedOrientation = requestedOrientation;
3615 }
3616 }
Romain Guy06882f82009-06-10 13:36:04 -07003617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 public int getAppOrientation(IApplicationToken token) {
3619 synchronized(mWindowMap) {
3620 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3621 if (wtoken == null) {
3622 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3623 }
Romain Guy06882f82009-06-10 13:36:04 -07003624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 return wtoken.requestedOrientation;
3626 }
3627 }
Romain Guy06882f82009-06-10 13:36:04 -07003628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3630 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3631 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003632 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 }
3634
3635 synchronized(mWindowMap) {
3636 boolean changed = false;
3637 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003638 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 changed = mFocusedApp != null;
3640 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003641 if (changed) {
3642 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003643 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 } else {
3645 AppWindowToken newFocus = findAppWindowToken(token);
3646 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003647 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 return;
3649 }
3650 changed = mFocusedApp != newFocus;
3651 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003652 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003653 if (changed) {
3654 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656 }
3657
3658 if (moveFocusNow && changed) {
3659 final long origId = Binder.clearCallingIdentity();
3660 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3661 Binder.restoreCallingIdentity(origId);
3662 }
3663 }
3664 }
3665
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003666 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3668 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003669 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 }
Romain Guy06882f82009-06-10 13:36:04 -07003671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003673 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 TAG, "Prepare app transition: transit=" + transit
3675 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003676 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003677 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3678 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003680 } else if (!alwaysKeepCurrent) {
3681 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;
3689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 }
3691 mAppTransitionReady = false;
3692 mAppTransitionTimeout = false;
3693 mStartingIconInTransition = false;
3694 mSkipAppTransitionAnimation = false;
3695 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3696 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3697 5000);
3698 }
3699 }
3700 }
3701
3702 public int getPendingAppTransition() {
3703 return mNextAppTransition;
3704 }
Romain Guy06882f82009-06-10 13:36:04 -07003705
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003706 public void overridePendingAppTransition(String packageName,
3707 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003708 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003709 mNextAppTransitionPackage = packageName;
3710 mNextAppTransitionEnter = enterAnim;
3711 mNextAppTransitionExit = exitAnim;
3712 }
3713 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 public void executeAppTransition() {
3716 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3717 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003718 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 }
Romain Guy06882f82009-06-10 13:36:04 -07003720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003722 if (DEBUG_APP_TRANSITIONS) {
3723 RuntimeException e = new RuntimeException("here");
3724 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003725 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003726 + mNextAppTransition, e);
3727 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003728 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 mAppTransitionReady = true;
3730 final long origId = Binder.clearCallingIdentity();
3731 performLayoutAndPlaceSurfacesLocked();
3732 Binder.restoreCallingIdentity(origId);
3733 }
3734 }
3735 }
3736
3737 public void setAppStartingWindow(IBinder token, String pkg,
3738 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003739 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3741 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003742 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 }
3744
3745 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003746 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3748 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 AppWindowToken wtoken = findAppWindowToken(token);
3751 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003752 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 return;
3754 }
3755
3756 // If the display is frozen, we won't do anything until the
3757 // actual window is displayed so there is no reason to put in
3758 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003759 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 return;
3761 }
Romain Guy06882f82009-06-10 13:36:04 -07003762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 if (wtoken.startingData != null) {
3764 return;
3765 }
Romain Guy06882f82009-06-10 13:36:04 -07003766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 if (transferFrom != null) {
3768 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3769 if (ttoken != null) {
3770 WindowState startingWindow = ttoken.startingWindow;
3771 if (startingWindow != null) {
3772 if (mStartingIconInTransition) {
3773 // In this case, the starting icon has already
3774 // been displayed, so start letting windows get
3775 // shown immediately without any more transitions.
3776 mSkipAppTransitionAnimation = true;
3777 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003778 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 "Moving existing starting from " + ttoken
3780 + " to " + wtoken);
3781 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 // Transfer the starting window over to the new
3784 // token.
3785 wtoken.startingData = ttoken.startingData;
3786 wtoken.startingView = ttoken.startingView;
3787 wtoken.startingWindow = startingWindow;
3788 ttoken.startingData = null;
3789 ttoken.startingView = null;
3790 ttoken.startingWindow = null;
3791 ttoken.startingMoved = true;
3792 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003793 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003795 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003796 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003798 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 ttoken.windows.remove(startingWindow);
3800 ttoken.allAppWindows.remove(startingWindow);
3801 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 // Propagate other interesting state between the
3804 // tokens. If the old token is displayed, we should
3805 // immediately force the new one to be displayed. If
3806 // it is animating, we need to move that animation to
3807 // the new one.
3808 if (ttoken.allDrawn) {
3809 wtoken.allDrawn = true;
3810 }
3811 if (ttoken.firstWindowDrawn) {
3812 wtoken.firstWindowDrawn = true;
3813 }
3814 if (!ttoken.hidden) {
3815 wtoken.hidden = false;
3816 wtoken.hiddenRequested = false;
3817 wtoken.willBeHidden = false;
3818 }
3819 if (wtoken.clientHidden != ttoken.clientHidden) {
3820 wtoken.clientHidden = ttoken.clientHidden;
3821 wtoken.sendAppVisibilityToClients();
3822 }
3823 if (ttoken.animation != null) {
3824 wtoken.animation = ttoken.animation;
3825 wtoken.animating = ttoken.animating;
3826 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3827 ttoken.animation = null;
3828 ttoken.animLayerAdjustment = 0;
3829 wtoken.updateLayers();
3830 ttoken.updateLayers();
3831 }
Romain Guy06882f82009-06-10 13:36:04 -07003832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 mLayoutNeeded = true;
3835 performLayoutAndPlaceSurfacesLocked();
3836 Binder.restoreCallingIdentity(origId);
3837 return;
3838 } else if (ttoken.startingData != null) {
3839 // The previous app was getting ready to show a
3840 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003841 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 "Moving pending starting from " + ttoken
3843 + " to " + wtoken);
3844 wtoken.startingData = ttoken.startingData;
3845 ttoken.startingData = null;
3846 ttoken.startingMoved = true;
3847 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3848 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3849 // want to process the message ASAP, before any other queued
3850 // messages.
3851 mH.sendMessageAtFrontOfQueue(m);
3852 return;
3853 }
3854 }
3855 }
3856
3857 // There is no existing starting window, and the caller doesn't
3858 // want us to create one, so that's it!
3859 if (!createIfNeeded) {
3860 return;
3861 }
Romain Guy06882f82009-06-10 13:36:04 -07003862
Dianne Hackborn284ac932009-08-28 10:34:25 -07003863 // If this is a translucent or wallpaper window, then don't
3864 // show a starting window -- the current effect (a full-screen
3865 // opaque starting window that fades away to the real contents
3866 // when it is ready) does not work for this.
3867 if (theme != 0) {
3868 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3869 com.android.internal.R.styleable.Window);
3870 if (ent.array.getBoolean(
3871 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3872 return;
3873 }
3874 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003875 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3876 return;
3877 }
3878 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003879 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3880 return;
3881 }
3882 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884 mStartingIconInTransition = true;
3885 wtoken.startingData = new StartingData(
3886 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003887 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3889 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3890 // want to process the message ASAP, before any other queued
3891 // messages.
3892 mH.sendMessageAtFrontOfQueue(m);
3893 }
3894 }
3895
3896 public void setAppWillBeHidden(IBinder token) {
3897 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3898 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003899 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003900 }
3901
3902 AppWindowToken wtoken;
3903
3904 synchronized(mWindowMap) {
3905 wtoken = findAppWindowToken(token);
3906 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003907 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 -08003908 return;
3909 }
3910 wtoken.willBeHidden = true;
3911 }
3912 }
Romain Guy06882f82009-06-10 13:36:04 -07003913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3915 boolean visible, int transit, boolean performLayout) {
3916 boolean delayed = false;
3917
3918 if (wtoken.clientHidden == visible) {
3919 wtoken.clientHidden = !visible;
3920 wtoken.sendAppVisibilityToClients();
3921 }
Romain Guy06882f82009-06-10 13:36:04 -07003922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003923 wtoken.willBeHidden = false;
3924 if (wtoken.hidden == visible) {
3925 final int N = wtoken.allAppWindows.size();
3926 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003927 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003928 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3929 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003932
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003933 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934 if (wtoken.animation == sDummyAnimation) {
3935 wtoken.animation = null;
3936 }
3937 applyAnimationLocked(wtoken, lp, transit, visible);
3938 changed = true;
3939 if (wtoken.animation != null) {
3940 delayed = runningAppAnimation = true;
3941 }
3942 }
Romain Guy06882f82009-06-10 13:36:04 -07003943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944 for (int i=0; i<N; i++) {
3945 WindowState win = wtoken.allAppWindows.get(i);
3946 if (win == wtoken.startingWindow) {
3947 continue;
3948 }
3949
3950 if (win.isAnimating()) {
3951 delayed = true;
3952 }
Romain Guy06882f82009-06-10 13:36:04 -07003953
Joe Onorato8a9b2202010-02-26 18:56:32 -08003954 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003955 //win.dump(" ");
3956 if (visible) {
3957 if (!win.isVisibleNow()) {
3958 if (!runningAppAnimation) {
3959 applyAnimationLocked(win,
3960 WindowManagerPolicy.TRANSIT_ENTER, true);
3961 }
3962 changed = true;
3963 }
3964 } else if (win.isVisibleNow()) {
3965 if (!runningAppAnimation) {
3966 applyAnimationLocked(win,
3967 WindowManagerPolicy.TRANSIT_EXIT, false);
3968 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003969 changed = true;
3970 }
3971 }
3972
3973 wtoken.hidden = wtoken.hiddenRequested = !visible;
3974 if (!visible) {
3975 unsetAppFreezingScreenLocked(wtoken, true, true);
3976 } else {
3977 // If we are being set visible, and the starting window is
3978 // not yet displayed, then make sure it doesn't get displayed.
3979 WindowState swin = wtoken.startingWindow;
3980 if (swin != null && (swin.mDrawPending
3981 || swin.mCommitDrawPending)) {
3982 swin.mPolicyVisibility = false;
3983 swin.mPolicyVisibilityAfterAnim = false;
3984 }
3985 }
Romain Guy06882f82009-06-10 13:36:04 -07003986
Joe Onorato8a9b2202010-02-26 18:56:32 -08003987 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3989 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003990
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003991 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003993 if (performLayout) {
3994 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3995 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003996 } else {
3997 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003998 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 }
4000 }
4001
4002 if (wtoken.animation != null) {
4003 delayed = true;
4004 }
Romain Guy06882f82009-06-10 13:36:04 -07004005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 return delayed;
4007 }
4008
4009 public void setAppVisibility(IBinder token, boolean visible) {
4010 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4011 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004012 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 }
4014
4015 AppWindowToken wtoken;
4016
4017 synchronized(mWindowMap) {
4018 wtoken = findAppWindowToken(token);
4019 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004020 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004021 return;
4022 }
4023
4024 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004025 RuntimeException e = null;
4026 if (!HIDE_STACK_CRAWLS) {
4027 e = new RuntimeException();
4028 e.fillInStackTrace();
4029 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004030 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 + "): mNextAppTransition=" + mNextAppTransition
4032 + " hidden=" + wtoken.hidden
4033 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4034 }
Romain Guy06882f82009-06-10 13:36:04 -07004035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004036 // If we are preparing an app transition, then delay changing
4037 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004038 if (!mDisplayFrozen && mPolicy.isScreenOn()
4039 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 // Already in requested state, don't do anything more.
4041 if (wtoken.hiddenRequested != visible) {
4042 return;
4043 }
4044 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004045
Joe Onorato8a9b2202010-02-26 18:56:32 -08004046 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004047 TAG, "Setting dummy animation on: " + wtoken);
4048 wtoken.setDummyAnimation();
4049 mOpeningApps.remove(wtoken);
4050 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004051 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004052 wtoken.inPendingTransaction = true;
4053 if (visible) {
4054 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004055 wtoken.startingDisplayed = false;
4056 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004057
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004058 // If the token is currently hidden (should be the
4059 // common case), then we need to set up to wait for
4060 // its windows to be ready.
4061 if (wtoken.hidden) {
4062 wtoken.allDrawn = false;
4063 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004064
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004065 if (wtoken.clientHidden) {
4066 // In the case where we are making an app visible
4067 // but holding off for a transition, we still need
4068 // to tell the client to make its windows visible so
4069 // they get drawn. Otherwise, we will wait on
4070 // performing the transition until all windows have
4071 // been drawn, they never will be, and we are sad.
4072 wtoken.clientHidden = false;
4073 wtoken.sendAppVisibilityToClients();
4074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 }
4076 } else {
4077 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004078
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004079 // If the token is currently visible (should be the
4080 // common case), then set up to wait for it to be hidden.
4081 if (!wtoken.hidden) {
4082 wtoken.waitingToHide = true;
4083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 }
4085 return;
4086 }
Romain Guy06882f82009-06-10 13:36:04 -07004087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004089 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 wtoken.updateReportedVisibilityLocked();
4091 Binder.restoreCallingIdentity(origId);
4092 }
4093 }
4094
4095 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4096 boolean unfreezeSurfaceNow, boolean force) {
4097 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004098 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 + " force=" + force);
4100 final int N = wtoken.allAppWindows.size();
4101 boolean unfrozeWindows = false;
4102 for (int i=0; i<N; i++) {
4103 WindowState w = wtoken.allAppWindows.get(i);
4104 if (w.mAppFreezing) {
4105 w.mAppFreezing = false;
4106 if (w.mSurface != null && !w.mOrientationChanging) {
4107 w.mOrientationChanging = true;
4108 }
4109 unfrozeWindows = true;
4110 }
4111 }
4112 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004113 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 wtoken.freezingScreen = false;
4115 mAppsFreezingScreen--;
4116 }
4117 if (unfreezeSurfaceNow) {
4118 if (unfrozeWindows) {
4119 mLayoutNeeded = true;
4120 performLayoutAndPlaceSurfacesLocked();
4121 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004122 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 }
4124 }
4125 }
Romain Guy06882f82009-06-10 13:36:04 -07004126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4128 int configChanges) {
4129 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004130 RuntimeException e = null;
4131 if (!HIDE_STACK_CRAWLS) {
4132 e = new RuntimeException();
4133 e.fillInStackTrace();
4134 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004135 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 + ": hidden=" + wtoken.hidden + " freezing="
4137 + wtoken.freezingScreen, e);
4138 }
4139 if (!wtoken.hiddenRequested) {
4140 if (!wtoken.freezingScreen) {
4141 wtoken.freezingScreen = true;
4142 mAppsFreezingScreen++;
4143 if (mAppsFreezingScreen == 1) {
4144 startFreezingDisplayLocked();
4145 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4146 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4147 5000);
4148 }
4149 }
4150 final int N = wtoken.allAppWindows.size();
4151 for (int i=0; i<N; i++) {
4152 WindowState w = wtoken.allAppWindows.get(i);
4153 w.mAppFreezing = true;
4154 }
4155 }
4156 }
Romain Guy06882f82009-06-10 13:36:04 -07004157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 public void startAppFreezingScreen(IBinder token, int configChanges) {
4159 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4160 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004161 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162 }
4163
4164 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004165 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004166 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004167 return;
4168 }
Romain Guy06882f82009-06-10 13:36:04 -07004169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004170 AppWindowToken wtoken = findAppWindowToken(token);
4171 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004172 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 return;
4174 }
4175 final long origId = Binder.clearCallingIdentity();
4176 startAppFreezingScreenLocked(wtoken, configChanges);
4177 Binder.restoreCallingIdentity(origId);
4178 }
4179 }
Romain Guy06882f82009-06-10 13:36:04 -07004180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 public void stopAppFreezingScreen(IBinder token, boolean force) {
4182 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4183 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004184 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 }
4186
4187 synchronized(mWindowMap) {
4188 AppWindowToken wtoken = findAppWindowToken(token);
4189 if (wtoken == null || wtoken.appToken == null) {
4190 return;
4191 }
4192 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004193 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4195 unsetAppFreezingScreenLocked(wtoken, true, force);
4196 Binder.restoreCallingIdentity(origId);
4197 }
4198 }
Romain Guy06882f82009-06-10 13:36:04 -07004199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 public void removeAppToken(IBinder token) {
4201 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4202 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004203 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 }
4205
4206 AppWindowToken wtoken = null;
4207 AppWindowToken startingToken = null;
4208 boolean delayed = false;
4209
4210 final long origId = Binder.clearCallingIdentity();
4211 synchronized(mWindowMap) {
4212 WindowToken basewtoken = mTokenMap.remove(token);
4213 mTokenList.remove(basewtoken);
4214 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004215 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004216 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004217 wtoken.inPendingTransaction = false;
4218 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004219 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004220 if (mClosingApps.contains(wtoken)) {
4221 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004222 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004224 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 delayed = true;
4226 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004227 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004228 TAG, "Removing app " + wtoken + " delayed=" + delayed
4229 + " animation=" + wtoken.animation
4230 + " animating=" + wtoken.animating);
4231 if (delayed) {
4232 // set the token aside because it has an active animation to be finished
4233 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004234 } else {
4235 // Make sure there is no animation running on this token,
4236 // so any windows associated with it will be removed as
4237 // soon as their animations are complete
4238 wtoken.animation = null;
4239 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004240 }
4241 mAppTokens.remove(wtoken);
4242 wtoken.removed = true;
4243 if (wtoken.startingData != null) {
4244 startingToken = wtoken;
4245 }
4246 unsetAppFreezingScreenLocked(wtoken, true, true);
4247 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004248 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 mFocusedApp = null;
4250 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004251 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 }
4253 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004254 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 }
Romain Guy06882f82009-06-10 13:36:04 -07004256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 if (!delayed && wtoken != null) {
4258 wtoken.updateReportedVisibilityLocked();
4259 }
4260 }
4261 Binder.restoreCallingIdentity(origId);
4262
4263 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004264 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 + startingToken + ": app token removed");
4266 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4267 mH.sendMessage(m);
4268 }
4269 }
4270
4271 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4272 final int NW = token.windows.size();
4273 for (int i=0; i<NW; i++) {
4274 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004275 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004277 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 int j = win.mChildWindows.size();
4279 while (j > 0) {
4280 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004281 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004282 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004283 "Tmp removing child window " + cwin);
4284 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 }
4286 }
4287 return NW > 0;
4288 }
4289
4290 void dumpAppTokensLocked() {
4291 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004292 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 }
4294 }
Romain Guy06882f82009-06-10 13:36:04 -07004295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 void dumpWindowsLocked() {
4297 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004298 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 }
4300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 private int findWindowOffsetLocked(int tokenPos) {
4303 final int NW = mWindows.size();
4304
4305 if (tokenPos >= mAppTokens.size()) {
4306 int i = NW;
4307 while (i > 0) {
4308 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004309 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 if (win.getAppToken() != null) {
4311 return i+1;
4312 }
4313 }
4314 }
4315
4316 while (tokenPos > 0) {
4317 // Find the first app token below the new position that has
4318 // a window displayed.
4319 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004320 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004322 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004323 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004324 "Skipping token -- currently sending to bottom");
4325 tokenPos--;
4326 continue;
4327 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 int i = wtoken.windows.size();
4329 while (i > 0) {
4330 i--;
4331 WindowState win = wtoken.windows.get(i);
4332 int j = win.mChildWindows.size();
4333 while (j > 0) {
4334 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004335 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004336 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 for (int pos=NW-1; pos>=0; pos--) {
4338 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004339 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004340 "Found child win @" + (pos+1));
4341 return pos+1;
4342 }
4343 }
4344 }
4345 }
4346 for (int pos=NW-1; pos>=0; pos--) {
4347 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004348 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 return pos+1;
4350 }
4351 }
4352 }
4353 tokenPos--;
4354 }
4355
4356 return 0;
4357 }
4358
4359 private final int reAddWindowLocked(int index, WindowState win) {
4360 final int NCW = win.mChildWindows.size();
4361 boolean added = false;
4362 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004363 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004365 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004366 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 mWindows.add(index, win);
4368 index++;
4369 added = true;
4370 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004371 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004372 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004373 mWindows.add(index, cwin);
4374 index++;
4375 }
4376 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004377 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004378 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379 mWindows.add(index, win);
4380 index++;
4381 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004382 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 return index;
4384 }
Romain Guy06882f82009-06-10 13:36:04 -07004385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4387 final int NW = token.windows.size();
4388 for (int i=0; i<NW; i++) {
4389 index = reAddWindowLocked(index, token.windows.get(i));
4390 }
4391 return index;
4392 }
4393
4394 public void moveAppToken(int index, IBinder token) {
4395 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4396 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004397 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 }
4399
4400 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004401 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004402 if (DEBUG_REORDER) dumpAppTokensLocked();
4403 final AppWindowToken wtoken = findAppWindowToken(token);
4404 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004405 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 + token + " (" + wtoken + ")");
4407 return;
4408 }
4409 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004410 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004414 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 if (DEBUG_REORDER) dumpWindowsLocked();
4416 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004417 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 if (DEBUG_REORDER) dumpWindowsLocked();
4419 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004420 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004421 if (DEBUG_REORDER) dumpWindowsLocked();
4422 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 mLayoutNeeded = true;
4424 performLayoutAndPlaceSurfacesLocked();
4425 }
4426 Binder.restoreCallingIdentity(origId);
4427 }
4428 }
4429
4430 private void removeAppTokensLocked(List<IBinder> tokens) {
4431 // XXX This should be done more efficiently!
4432 // (take advantage of the fact that both lists should be
4433 // ordered in the same way.)
4434 int N = tokens.size();
4435 for (int i=0; i<N; i++) {
4436 IBinder token = tokens.get(i);
4437 final AppWindowToken wtoken = findAppWindowToken(token);
4438 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004439 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 + token + " (" + wtoken + ")");
4441 i--;
4442 N--;
4443 }
4444 }
4445 }
4446
Dianne Hackborna8f60182009-09-01 19:01:50 -07004447 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4448 boolean updateFocusAndLayout) {
4449 // First remove all of the windows from the list.
4450 tmpRemoveAppWindowsLocked(wtoken);
4451
4452 // Where to start adding?
4453 int pos = findWindowOffsetLocked(tokenPos);
4454
4455 // And now add them back at the correct place.
4456 pos = reAddAppWindowsLocked(pos, wtoken);
4457
4458 if (updateFocusAndLayout) {
4459 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4460 assignLayersLocked();
4461 }
4462 mLayoutNeeded = true;
4463 performLayoutAndPlaceSurfacesLocked();
4464 }
4465 }
4466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4468 // First remove all of the windows from the list.
4469 final int N = tokens.size();
4470 int i;
4471 for (i=0; i<N; i++) {
4472 WindowToken token = mTokenMap.get(tokens.get(i));
4473 if (token != null) {
4474 tmpRemoveAppWindowsLocked(token);
4475 }
4476 }
4477
4478 // Where to start adding?
4479 int pos = findWindowOffsetLocked(tokenPos);
4480
4481 // And now add them back at the correct place.
4482 for (i=0; i<N; i++) {
4483 WindowToken token = mTokenMap.get(tokens.get(i));
4484 if (token != null) {
4485 pos = reAddAppWindowsLocked(pos, token);
4486 }
4487 }
4488
Dianne Hackborna8f60182009-09-01 19:01:50 -07004489 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4490 assignLayersLocked();
4491 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 mLayoutNeeded = true;
4493 performLayoutAndPlaceSurfacesLocked();
4494
4495 //dump();
4496 }
4497
4498 public void moveAppTokensToTop(List<IBinder> tokens) {
4499 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4500 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004501 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 }
4503
4504 final long origId = Binder.clearCallingIdentity();
4505 synchronized(mWindowMap) {
4506 removeAppTokensLocked(tokens);
4507 final int N = tokens.size();
4508 for (int i=0; i<N; i++) {
4509 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4510 if (wt != null) {
4511 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004512 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004513 mToTopApps.remove(wt);
4514 mToBottomApps.remove(wt);
4515 mToTopApps.add(wt);
4516 wt.sendingToBottom = false;
4517 wt.sendingToTop = true;
4518 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 }
4520 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004521
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004522 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004523 moveAppWindowsLocked(tokens, mAppTokens.size());
4524 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 }
4526 Binder.restoreCallingIdentity(origId);
4527 }
4528
4529 public void moveAppTokensToBottom(List<IBinder> tokens) {
4530 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4531 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004532 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004533 }
4534
4535 final long origId = Binder.clearCallingIdentity();
4536 synchronized(mWindowMap) {
4537 removeAppTokensLocked(tokens);
4538 final int N = tokens.size();
4539 int pos = 0;
4540 for (int i=0; i<N; i++) {
4541 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4542 if (wt != null) {
4543 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004544 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004545 mToTopApps.remove(wt);
4546 mToBottomApps.remove(wt);
4547 mToBottomApps.add(i, wt);
4548 wt.sendingToTop = false;
4549 wt.sendingToBottom = true;
4550 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004551 pos++;
4552 }
4553 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004554
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004555 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004556 moveAppWindowsLocked(tokens, 0);
4557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004558 }
4559 Binder.restoreCallingIdentity(origId);
4560 }
4561
4562 // -------------------------------------------------------------
4563 // Misc IWindowSession methods
4564 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004565
Jim Miller284b62e2010-06-08 14:27:42 -07004566 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004567 {
Jim Miller284b62e2010-06-08 14:27:42 -07004568 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4569 // called before DevicePolicyManagerService has started.
4570 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4571 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4572 Context.DEVICE_POLICY_SERVICE);
4573 if (dpm != null) {
4574 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4575 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4576 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4577 }
Jim Millerd6b57052010-06-07 17:52:42 -07004578 }
Jim Miller284b62e2010-06-08 14:27:42 -07004579 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004580 }
4581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004582 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004583 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004584 != PackageManager.PERMISSION_GRANTED) {
4585 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4586 }
Jim Millerd6b57052010-06-07 17:52:42 -07004587
Jim Miller284b62e2010-06-08 14:27:42 -07004588 synchronized (mKeyguardTokenWatcher) {
4589 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004590 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004591 }
4592
4593 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004594 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004595 != PackageManager.PERMISSION_GRANTED) {
4596 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598
Jim Miller284b62e2010-06-08 14:27:42 -07004599 synchronized (mKeyguardTokenWatcher) {
4600 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004601
Jim Miller284b62e2010-06-08 14:27:42 -07004602 if (!mKeyguardTokenWatcher.isAcquired()) {
4603 // If we are the last one to reenable the keyguard wait until
4604 // we have actually finished reenabling until returning.
4605 // It is possible that reenableKeyguard() can be called before
4606 // the previous disableKeyguard() is handled, in which case
4607 // neither mKeyguardTokenWatcher.acquired() or released() would
4608 // be called. In that case mKeyguardDisabled will be false here
4609 // and we have nothing to wait for.
4610 while (mKeyguardDisabled) {
4611 try {
4612 mKeyguardTokenWatcher.wait();
4613 } catch (InterruptedException e) {
4614 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004615 }
4616 }
4617 }
4618 }
4619 }
4620
4621 /**
4622 * @see android.app.KeyguardManager#exitKeyguardSecurely
4623 */
4624 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004625 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004626 != PackageManager.PERMISSION_GRANTED) {
4627 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4628 }
4629 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4630 public void onKeyguardExitResult(boolean success) {
4631 try {
4632 callback.onKeyguardExitResult(success);
4633 } catch (RemoteException e) {
4634 // Client has died, we don't care.
4635 }
4636 }
4637 });
4638 }
4639
4640 public boolean inKeyguardRestrictedInputMode() {
4641 return mPolicy.inKeyguardRestrictedKeyInputMode();
4642 }
Romain Guy06882f82009-06-10 13:36:04 -07004643
Dianne Hackbornffa42482009-09-23 22:20:11 -07004644 public void closeSystemDialogs(String reason) {
4645 synchronized(mWindowMap) {
4646 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004647 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004648 if (w.mSurface != null) {
4649 try {
4650 w.mClient.closeSystemDialogs(reason);
4651 } catch (RemoteException e) {
4652 }
4653 }
4654 }
4655 }
4656 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004658 static float fixScale(float scale) {
4659 if (scale < 0) scale = 0;
4660 else if (scale > 20) scale = 20;
4661 return Math.abs(scale);
4662 }
Romain Guy06882f82009-06-10 13:36:04 -07004663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 public void setAnimationScale(int which, float scale) {
4665 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4666 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004667 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004668 }
4669
4670 if (scale < 0) scale = 0;
4671 else if (scale > 20) scale = 20;
4672 scale = Math.abs(scale);
4673 switch (which) {
4674 case 0: mWindowAnimationScale = fixScale(scale); break;
4675 case 1: mTransitionAnimationScale = fixScale(scale); break;
4676 }
Romain Guy06882f82009-06-10 13:36:04 -07004677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004678 // Persist setting
4679 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4680 }
Romain Guy06882f82009-06-10 13:36:04 -07004681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 public void setAnimationScales(float[] scales) {
4683 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4684 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004685 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 }
4687
4688 if (scales != null) {
4689 if (scales.length >= 1) {
4690 mWindowAnimationScale = fixScale(scales[0]);
4691 }
4692 if (scales.length >= 2) {
4693 mTransitionAnimationScale = fixScale(scales[1]);
4694 }
4695 }
Romain Guy06882f82009-06-10 13:36:04 -07004696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 // Persist setting
4698 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4699 }
Romain Guy06882f82009-06-10 13:36:04 -07004700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004701 public float getAnimationScale(int which) {
4702 switch (which) {
4703 case 0: return mWindowAnimationScale;
4704 case 1: return mTransitionAnimationScale;
4705 }
4706 return 0;
4707 }
Romain Guy06882f82009-06-10 13:36:04 -07004708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 public float[] getAnimationScales() {
4710 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4711 }
Romain Guy06882f82009-06-10 13:36:04 -07004712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004713 public int getSwitchState(int sw) {
4714 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4715 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004716 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004718 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004719 }
Romain Guy06882f82009-06-10 13:36:04 -07004720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004721 public int getSwitchStateForDevice(int devid, int sw) {
4722 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4723 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004724 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004725 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004726 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004727 }
Romain Guy06882f82009-06-10 13:36:04 -07004728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004729 public int getScancodeState(int sw) {
4730 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4731 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004732 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004733 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004734 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004735 }
Romain Guy06882f82009-06-10 13:36:04 -07004736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 public int getScancodeStateForDevice(int devid, int sw) {
4738 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4739 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004740 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004741 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004742 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004743 }
Romain Guy06882f82009-06-10 13:36:04 -07004744
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004745 public int getTrackballScancodeState(int sw) {
4746 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4747 "getTrackballScancodeState()")) {
4748 throw new SecurityException("Requires READ_INPUT_STATE permission");
4749 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004750 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004751 }
4752
4753 public int getDPadScancodeState(int sw) {
4754 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4755 "getDPadScancodeState()")) {
4756 throw new SecurityException("Requires READ_INPUT_STATE permission");
4757 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004758 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004759 }
4760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004761 public int getKeycodeState(int sw) {
4762 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4763 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004764 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004765 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004766 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 }
Romain Guy06882f82009-06-10 13:36:04 -07004768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 public int getKeycodeStateForDevice(int devid, int sw) {
4770 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4771 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004772 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004773 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004774 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004775 }
Romain Guy06882f82009-06-10 13:36:04 -07004776
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004777 public int getTrackballKeycodeState(int sw) {
4778 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4779 "getTrackballKeycodeState()")) {
4780 throw new SecurityException("Requires READ_INPUT_STATE permission");
4781 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004782 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004783 }
4784
4785 public int getDPadKeycodeState(int sw) {
4786 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4787 "getDPadKeycodeState()")) {
4788 throw new SecurityException("Requires READ_INPUT_STATE permission");
4789 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004790 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004791 }
Jeff Browna41ca772010-08-11 14:46:32 -07004792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004793 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004794 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 }
Romain Guy06882f82009-06-10 13:36:04 -07004796
Jeff Browna41ca772010-08-11 14:46:32 -07004797 public InputChannel monitorInput(String inputChannelName) {
4798 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4799 "monitorInput()")) {
4800 throw new SecurityException("Requires READ_INPUT_STATE permission");
4801 }
4802 return mInputManager.monitorInput(inputChannelName);
4803 }
4804
Jeff Brown8d608662010-08-30 03:02:23 -07004805 public InputDevice getInputDevice(int deviceId) {
4806 return mInputManager.getInputDevice(deviceId);
4807 }
4808
4809 public int[] getInputDeviceIds() {
4810 return mInputManager.getInputDeviceIds();
4811 }
4812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 public void enableScreenAfterBoot() {
4814 synchronized(mWindowMap) {
4815 if (mSystemBooted) {
4816 return;
4817 }
4818 mSystemBooted = true;
4819 }
Romain Guy06882f82009-06-10 13:36:04 -07004820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 performEnableScreen();
4822 }
Romain Guy06882f82009-06-10 13:36:04 -07004823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004824 public void enableScreenIfNeededLocked() {
4825 if (mDisplayEnabled) {
4826 return;
4827 }
4828 if (!mSystemBooted) {
4829 return;
4830 }
4831 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4832 }
Romain Guy06882f82009-06-10 13:36:04 -07004833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004834 public void performEnableScreen() {
4835 synchronized(mWindowMap) {
4836 if (mDisplayEnabled) {
4837 return;
4838 }
4839 if (!mSystemBooted) {
4840 return;
4841 }
Romain Guy06882f82009-06-10 13:36:04 -07004842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 // Don't enable the screen until all existing windows
4844 // have been drawn.
4845 final int N = mWindows.size();
4846 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004847 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004848 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004849 return;
4850 }
4851 }
Romain Guy06882f82009-06-10 13:36:04 -07004852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 mDisplayEnabled = true;
4854 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004855 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 StringWriter sw = new StringWriter();
4857 PrintWriter pw = new PrintWriter(sw);
4858 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004859 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004860 }
4861 try {
4862 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4863 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004864 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004865 Parcel data = Parcel.obtain();
4866 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4867 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4868 data, null, 0);
4869 data.recycle();
4870 }
4871 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004872 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 }
4874 }
Romain Guy06882f82009-06-10 13:36:04 -07004875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004878 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004879 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4880 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 }
Romain Guy06882f82009-06-10 13:36:04 -07004882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 public void setInTouchMode(boolean mode) {
4884 synchronized(mWindowMap) {
4885 mInTouchMode = mode;
4886 }
4887 }
4888
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004889 // TODO: more accounting of which pid(s) turned it on, keep count,
4890 // only allow disables from pids which have count on, etc.
4891 public void showStrictModeViolation(boolean on) {
4892 int pid = Binder.getCallingPid();
4893 synchronized(mWindowMap) {
4894 // Ignoring requests to enable the red border from clients
4895 // which aren't on screen. (e.g. Broadcast Receivers in
4896 // the background..)
4897 if (on) {
4898 boolean isVisible = false;
4899 for (WindowState ws : mWindows) {
4900 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4901 isVisible = true;
4902 break;
4903 }
4904 }
4905 if (!isVisible) {
4906 return;
4907 }
4908 }
4909
4910 Surface.openTransaction();
4911 if (mStrictModeFlash == null) {
4912 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4913 }
4914 mStrictModeFlash.setVisibility(on);
4915 Surface.closeTransaction();
4916 }
4917 }
4918
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004919 public void setStrictModeVisualIndicatorPreference(String value) {
4920 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4921 }
4922
Dianne Hackbornd2835932010-12-13 16:28:46 -08004923 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004924 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4925 "screenshotApplications()")) {
4926 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
4927 }
4928
4929 Bitmap rawss;
4930
Dianne Hackbornd2835932010-12-13 16:28:46 -08004931 int maxLayer = 0;
4932 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004933 final Rect frame = new Rect();
4934
4935 float scale;
4936 int sw, sh, dw, dh;
4937 int rot;
4938
4939 synchronized(mWindowMap) {
4940 long ident = Binder.clearCallingIdentity();
4941
4942 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
4943 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
4944 + TYPE_LAYER_OFFSET;
4945 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
4946
4947 // Figure out the part of the screen that is actually the app.
4948 for (int i=0; i<mWindows.size(); i++) {
4949 WindowState ws = mWindows.get(i);
4950 if (ws.mSurface == null) {
4951 continue;
4952 }
4953 if (ws.mLayer >= aboveAppLayer) {
4954 break;
4955 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08004956 if (appToken != null && (ws.mAppToken == null
4957 || ws.mAppToken.token != appToken)) {
4958 continue;
4959 }
4960 if (maxLayer < ws.mAnimLayer) {
4961 maxLayer = ws.mAnimLayer;
4962 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004963 final Rect wf = ws.mFrame;
4964 final Rect cr = ws.mContentInsets;
4965 int left = wf.left + cr.left;
4966 int top = wf.top + cr.top;
4967 int right = wf.right - cr.right;
4968 int bottom = wf.bottom - cr.bottom;
4969 frame.union(left, top, right, bottom);
4970 }
4971 Binder.restoreCallingIdentity(ident);
4972
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004973 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004974 return null;
4975 }
4976
4977 // The screenshot API does not apply the current screen rotation.
4978 rot = mDisplay.getRotation();
4979 int fw = frame.width();
4980 int fh = frame.height();
4981
4982 // First try reducing to fit in x dimension.
4983 scale = maxWidth/(float)fw;
4984 sw = maxWidth;
4985 sh = (int)(fh*scale);
4986 if (sh > maxHeight) {
4987 // y dimension became too long; constrain by that.
4988 scale = maxHeight/(float)fh;
4989 sw = (int)(fw*scale);
4990 sh = maxHeight;
4991 }
4992
4993 // The screen shot will contain the entire screen.
4994 dw = (int)(mDisplay.getWidth()*scale);
4995 dh = (int)(mDisplay.getHeight()*scale);
4996 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
4997 int tmp = dw;
4998 dw = dh;
4999 dh = tmp;
5000 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5001 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005002 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005003 }
5004
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005005 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005006 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5007 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005008 return null;
5009 }
5010
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005011 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5012 Matrix matrix = new Matrix();
5013 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5014 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5015 Canvas canvas = new Canvas(bm);
5016 canvas.drawBitmap(rawss, matrix, null);
5017
5018 rawss.recycle();
5019 return bm;
5020 }
5021
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005022 public void freezeRotation() {
5023 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5024 "setRotation()")) {
5025 throw new SecurityException("Requires SET_ORIENTATION permission");
5026 }
5027
5028 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5029 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5030 }
5031
5032 public void thawRotation() {
5033 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5034 "setRotation()")) {
5035 throw new SecurityException("Requires SET_ORIENTATION permission");
5036 }
5037
5038 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5039 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5040 }
5041
Romain Guy06882f82009-06-10 13:36:04 -07005042 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005043 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005044 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005045 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005046 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005047 }
5048
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005049 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005050 }
Romain Guy06882f82009-06-10 13:36:04 -07005051
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005052 public void setRotationUnchecked(int rotation,
5053 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005054 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005057 long origId = Binder.clearCallingIdentity();
5058 boolean changed;
5059 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005060 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005061 }
Romain Guy06882f82009-06-10 13:36:04 -07005062
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005063 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005064 sendNewConfiguration();
5065 }
Romain Guy06882f82009-06-10 13:36:04 -07005066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005067 Binder.restoreCallingIdentity(origId);
5068 }
Romain Guy06882f82009-06-10 13:36:04 -07005069
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005070 /**
5071 * Apply a new rotation to the screen, respecting the requests of
5072 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5073 * re-evaluate the desired rotation.
5074 *
5075 * Returns null if the rotation has been changed. In this case YOU
5076 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5077 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005078 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005079 boolean changed;
5080 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5081 rotation = mRequestedRotation;
5082 } else {
5083 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005084 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005085 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005086 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005087 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005088 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005089 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005090 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005092 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005093 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005094 "Rotation changed to " + rotation
5095 + " from " + mRotation
5096 + " (forceApp=" + mForcedAppOrientation
5097 + ", req=" + mRequestedRotation + ")");
5098 mRotation = rotation;
5099 mWindowsFreezingScreen = true;
5100 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5101 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5102 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005103 mWaitingForConfig = true;
5104 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005105 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005106 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005107 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005108 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005109 if (CUSTOM_SCREEN_ROTATION) {
5110 Surface.freezeDisplay(0);
5111 Surface.openTransaction();
5112 if (mScreenRotationAnimation != null) {
5113 mScreenRotationAnimation.setRotation(rotation);
5114 }
5115 Surface.closeTransaction();
5116 Surface.setOrientation(0, rotation, animFlags);
5117 Surface.unfreezeDisplay(0);
5118 } else {
5119 Surface.setOrientation(0, rotation, animFlags);
5120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005121 }
5122 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005123 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 if (w.mSurface != null) {
5125 w.mOrientationChanging = true;
5126 }
5127 }
5128 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5129 try {
5130 mRotationWatchers.get(i).onRotationChanged(rotation);
5131 } catch (RemoteException e) {
5132 }
5133 }
5134 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 return changed;
5137 }
Romain Guy06882f82009-06-10 13:36:04 -07005138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005139 public int getRotation() {
5140 return mRotation;
5141 }
5142
5143 public int watchRotation(IRotationWatcher watcher) {
5144 final IBinder watcherBinder = watcher.asBinder();
5145 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5146 public void binderDied() {
5147 synchronized (mWindowMap) {
5148 for (int i=0; i<mRotationWatchers.size(); i++) {
5149 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005150 IRotationWatcher removed = mRotationWatchers.remove(i);
5151 if (removed != null) {
5152 removed.asBinder().unlinkToDeath(this, 0);
5153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005154 i--;
5155 }
5156 }
5157 }
5158 }
5159 };
Romain Guy06882f82009-06-10 13:36:04 -07005160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005161 synchronized (mWindowMap) {
5162 try {
5163 watcher.asBinder().linkToDeath(dr, 0);
5164 mRotationWatchers.add(watcher);
5165 } catch (RemoteException e) {
5166 // Client died, no cleanup needed.
5167 }
Romain Guy06882f82009-06-10 13:36:04 -07005168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005169 return mRotation;
5170 }
5171 }
5172
5173 /**
5174 * Starts the view server on the specified port.
5175 *
5176 * @param port The port to listener to.
5177 *
5178 * @return True if the server was successfully started, false otherwise.
5179 *
5180 * @see com.android.server.ViewServer
5181 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5182 */
5183 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005184 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005185 return false;
5186 }
5187
5188 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5189 return false;
5190 }
5191
5192 if (port < 1024) {
5193 return false;
5194 }
5195
5196 if (mViewServer != null) {
5197 if (!mViewServer.isRunning()) {
5198 try {
5199 return mViewServer.start();
5200 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005201 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005202 }
5203 }
5204 return false;
5205 }
5206
5207 try {
5208 mViewServer = new ViewServer(this, port);
5209 return mViewServer.start();
5210 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005211 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005212 }
5213 return false;
5214 }
5215
Romain Guy06882f82009-06-10 13:36:04 -07005216 private boolean isSystemSecure() {
5217 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5218 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5219 }
5220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005221 /**
5222 * Stops the view server if it exists.
5223 *
5224 * @return True if the server stopped, false if it wasn't started or
5225 * couldn't be stopped.
5226 *
5227 * @see com.android.server.ViewServer
5228 */
5229 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005230 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231 return false;
5232 }
5233
5234 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5235 return false;
5236 }
5237
5238 if (mViewServer != null) {
5239 return mViewServer.stop();
5240 }
5241 return false;
5242 }
5243
5244 /**
5245 * Indicates whether the view server is running.
5246 *
5247 * @return True if the server is running, false otherwise.
5248 *
5249 * @see com.android.server.ViewServer
5250 */
5251 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005252 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005253 return false;
5254 }
5255
5256 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5257 return false;
5258 }
5259
5260 return mViewServer != null && mViewServer.isRunning();
5261 }
5262
5263 /**
5264 * Lists all availble windows in the system. The listing is written in the
5265 * specified Socket's output stream with the following syntax:
5266 * windowHashCodeInHexadecimal windowName
5267 * Each line of the ouput represents a different window.
5268 *
5269 * @param client The remote client to send the listing to.
5270 * @return False if an error occured, true otherwise.
5271 */
5272 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005273 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005274 return false;
5275 }
5276
5277 boolean result = true;
5278
Jeff Browne33348b2010-07-15 23:54:05 -07005279 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005280 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005281 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005282 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005283 }
5284
5285 BufferedWriter out = null;
5286
5287 // Any uncaught exception will crash the system process
5288 try {
5289 OutputStream clientStream = client.getOutputStream();
5290 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5291
5292 final int count = windows.length;
5293 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005294 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005295 out.write(Integer.toHexString(System.identityHashCode(w)));
5296 out.write(' ');
5297 out.append(w.mAttrs.getTitle());
5298 out.write('\n');
5299 }
5300
5301 out.write("DONE.\n");
5302 out.flush();
5303 } catch (Exception e) {
5304 result = false;
5305 } finally {
5306 if (out != null) {
5307 try {
5308 out.close();
5309 } catch (IOException e) {
5310 result = false;
5311 }
5312 }
5313 }
5314
5315 return result;
5316 }
5317
5318 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005319 * Returns the focused window in the following format:
5320 * windowHashCodeInHexadecimal windowName
5321 *
5322 * @param client The remote client to send the listing to.
5323 * @return False if an error occurred, true otherwise.
5324 */
5325 boolean viewServerGetFocusedWindow(Socket client) {
5326 if (isSystemSecure()) {
5327 return false;
5328 }
5329
5330 boolean result = true;
5331
5332 WindowState focusedWindow = getFocusedWindow();
5333
5334 BufferedWriter out = null;
5335
5336 // Any uncaught exception will crash the system process
5337 try {
5338 OutputStream clientStream = client.getOutputStream();
5339 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5340
5341 if(focusedWindow != null) {
5342 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5343 out.write(' ');
5344 out.append(focusedWindow.mAttrs.getTitle());
5345 }
5346 out.write('\n');
5347 out.flush();
5348 } catch (Exception e) {
5349 result = false;
5350 } finally {
5351 if (out != null) {
5352 try {
5353 out.close();
5354 } catch (IOException e) {
5355 result = false;
5356 }
5357 }
5358 }
5359
5360 return result;
5361 }
5362
5363 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005364 * Sends a command to a target window. The result of the command, if any, will be
5365 * written in the output stream of the specified socket.
5366 *
5367 * The parameters must follow this syntax:
5368 * windowHashcode extra
5369 *
5370 * Where XX is the length in characeters of the windowTitle.
5371 *
5372 * The first parameter is the target window. The window with the specified hashcode
5373 * will be the target. If no target can be found, nothing happens. The extra parameters
5374 * will be delivered to the target window and as parameters to the command itself.
5375 *
5376 * @param client The remote client to sent the result, if any, to.
5377 * @param command The command to execute.
5378 * @param parameters The command parameters.
5379 *
5380 * @return True if the command was successfully delivered, false otherwise. This does
5381 * not indicate whether the command itself was successful.
5382 */
5383 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005384 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 return false;
5386 }
5387
5388 boolean success = true;
5389 Parcel data = null;
5390 Parcel reply = null;
5391
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005392 BufferedWriter out = null;
5393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005394 // Any uncaught exception will crash the system process
5395 try {
5396 // Find the hashcode of the window
5397 int index = parameters.indexOf(' ');
5398 if (index == -1) {
5399 index = parameters.length();
5400 }
5401 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005402 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005403
5404 // Extract the command's parameter after the window description
5405 if (index < parameters.length()) {
5406 parameters = parameters.substring(index + 1);
5407 } else {
5408 parameters = "";
5409 }
5410
5411 final WindowManagerService.WindowState window = findWindow(hashCode);
5412 if (window == null) {
5413 return false;
5414 }
5415
5416 data = Parcel.obtain();
5417 data.writeInterfaceToken("android.view.IWindow");
5418 data.writeString(command);
5419 data.writeString(parameters);
5420 data.writeInt(1);
5421 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5422
5423 reply = Parcel.obtain();
5424
5425 final IBinder binder = window.mClient.asBinder();
5426 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5427 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5428
5429 reply.readException();
5430
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005431 if (!client.isOutputShutdown()) {
5432 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5433 out.write("DONE\n");
5434 out.flush();
5435 }
5436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005437 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005438 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005439 success = false;
5440 } finally {
5441 if (data != null) {
5442 data.recycle();
5443 }
5444 if (reply != null) {
5445 reply.recycle();
5446 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005447 if (out != null) {
5448 try {
5449 out.close();
5450 } catch (IOException e) {
5451
5452 }
5453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005454 }
5455
5456 return success;
5457 }
5458
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005459 public void addWindowChangeListener(WindowChangeListener listener) {
5460 synchronized(mWindowMap) {
5461 mWindowChangeListeners.add(listener);
5462 }
5463 }
5464
5465 public void removeWindowChangeListener(WindowChangeListener listener) {
5466 synchronized(mWindowMap) {
5467 mWindowChangeListeners.remove(listener);
5468 }
5469 }
5470
5471 private void notifyWindowsChanged() {
5472 WindowChangeListener[] windowChangeListeners;
5473 synchronized(mWindowMap) {
5474 if(mWindowChangeListeners.isEmpty()) {
5475 return;
5476 }
5477 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5478 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5479 }
5480 int N = windowChangeListeners.length;
5481 for(int i = 0; i < N; i++) {
5482 windowChangeListeners[i].windowsChanged();
5483 }
5484 }
5485
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005486 private void notifyFocusChanged() {
5487 WindowChangeListener[] windowChangeListeners;
5488 synchronized(mWindowMap) {
5489 if(mWindowChangeListeners.isEmpty()) {
5490 return;
5491 }
5492 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5493 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5494 }
5495 int N = windowChangeListeners.length;
5496 for(int i = 0; i < N; i++) {
5497 windowChangeListeners[i].focusChanged();
5498 }
5499 }
5500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005501 private WindowState findWindow(int hashCode) {
5502 if (hashCode == -1) {
5503 return getFocusedWindow();
5504 }
5505
5506 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005507 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005508 final int count = windows.size();
5509
5510 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005511 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005512 if (System.identityHashCode(w) == hashCode) {
5513 return w;
5514 }
5515 }
5516 }
5517
5518 return null;
5519 }
5520
5521 /*
5522 * Instruct the Activity Manager to fetch the current configuration and broadcast
5523 * that to config-changed listeners if appropriate.
5524 */
5525 void sendNewConfiguration() {
5526 try {
5527 mActivityManager.updateConfiguration(null);
5528 } catch (RemoteException e) {
5529 }
5530 }
Romain Guy06882f82009-06-10 13:36:04 -07005531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005532 public Configuration computeNewConfiguration() {
5533 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005534 return computeNewConfigurationLocked();
5535 }
5536 }
Romain Guy06882f82009-06-10 13:36:04 -07005537
Dianne Hackbornc485a602009-03-24 22:39:49 -07005538 Configuration computeNewConfigurationLocked() {
5539 Configuration config = new Configuration();
5540 if (!computeNewConfigurationLocked(config)) {
5541 return null;
5542 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005543 return config;
5544 }
Romain Guy06882f82009-06-10 13:36:04 -07005545
Dianne Hackbornc485a602009-03-24 22:39:49 -07005546 boolean computeNewConfigurationLocked(Configuration config) {
5547 if (mDisplay == null) {
5548 return false;
5549 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005550
5551 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005552
5553 // Use the effective "visual" dimensions based on current rotation
5554 final boolean rotated = (mRotation == Surface.ROTATION_90
5555 || mRotation == Surface.ROTATION_270);
5556 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5557 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5558
Dianne Hackbornc485a602009-03-24 22:39:49 -07005559 int orientation = Configuration.ORIENTATION_SQUARE;
5560 if (dw < dh) {
5561 orientation = Configuration.ORIENTATION_PORTRAIT;
5562 } else if (dw > dh) {
5563 orientation = Configuration.ORIENTATION_LANDSCAPE;
5564 }
5565 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005566
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005567 DisplayMetrics dm = new DisplayMetrics();
5568 mDisplay.getMetrics(dm);
5569 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5570
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005571 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005572 // Note we only do this once because at this point we don't
5573 // expect the screen to change in this way at runtime, and want
5574 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005575 int longSize = dw;
5576 int shortSize = dh;
5577 if (longSize < shortSize) {
5578 int tmp = longSize;
5579 longSize = shortSize;
5580 shortSize = tmp;
5581 }
5582 longSize = (int)(longSize/dm.density);
5583 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005584
Dianne Hackborn723738c2009-06-25 19:48:04 -07005585 // These semi-magic numbers define our compatibility modes for
5586 // applications with different screens. Don't change unless you
5587 // make sure to test lots and lots of apps!
5588 if (longSize < 470) {
5589 // This is shorter than an HVGA normal density screen (which
5590 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005591 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5592 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005593 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005594 // What size is this screen screen?
5595 if (longSize >= 800 && shortSize >= 600) {
5596 // SVGA or larger screens at medium density are the point
5597 // at which we consider it to be an extra large screen.
5598 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005599 } else if (longSize >= 530 && shortSize >= 400) {
5600 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005601 // at which we consider it to be a large screen.
5602 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5603 } else {
5604 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005605
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005606 // If this screen is wider than normal HVGA, or taller
5607 // than FWVGA, then for old apps we want to run in size
5608 // compatibility mode.
5609 if (shortSize > 321 || longSize > 570) {
5610 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5611 }
5612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005613
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005614 // Is this a long screen?
5615 if (((longSize*3)/5) >= (shortSize-1)) {
5616 // Anything wider than WVGA (5:3) is considering to be long.
5617 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5618 } else {
5619 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5620 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005621 }
5622 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005623 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005624
Dianne Hackbornc485a602009-03-24 22:39:49 -07005625 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5626 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5627 mPolicy.adjustConfigurationLw(config);
5628 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005629 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005630
5631 // -------------------------------------------------------------
5632 // Drag and drop
5633 // -------------------------------------------------------------
5634
5635 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5636 boolean localOnly, int width, int height, Surface outSurface) {
5637 if (DEBUG_DRAG) {
5638 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5639 + " local=" + localOnly + " win=" + window
5640 + " asbinder=" + window.asBinder());
5641 }
5642
5643 final int callerPid = Binder.getCallingPid();
5644 final long origId = Binder.clearCallingIdentity();
5645 IBinder token = null;
5646
5647 try {
5648 synchronized (mWindowMap) {
5649 try {
5650 // !!! TODO: fail if the given window does not currently have touch focus?
5651
5652 if (mDragState == null) {
5653 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5654 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5655 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005656 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005657 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005658 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005659 mDragState.mSurface = surface;
5660 mDragState.mLocalOnly = localOnly;
5661 token = mDragState.mToken = new Binder();
5662
5663 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005664 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5665 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005666 mH.sendMessageDelayed(msg, 5000);
5667 } else {
5668 Slog.w(TAG, "Drag already in progress");
5669 }
5670 } catch (Surface.OutOfResourcesException e) {
5671 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5672 if (mDragState != null) {
5673 mDragState.reset();
5674 mDragState = null;
5675 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005676 }
5677 }
5678 } finally {
5679 Binder.restoreCallingIdentity(origId);
5680 }
5681
5682 return token;
5683 }
5684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005685 // -------------------------------------------------------------
5686 // Input Events and Focus Management
5687 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005688
Jeff Brown349703e2010-06-22 01:27:15 -07005689 InputMonitor mInputMonitor = new InputMonitor();
5690
5691 /* Tracks the progress of input dispatch and ensures that input dispatch state
5692 * is kept in sync with changes in window focus, visibility, registration, and
5693 * other relevant Window Manager state transitions. */
5694 final class InputMonitor {
5695 // Current window with input focus for keys and other non-touch events. May be null.
5696 private WindowState mInputFocus;
5697
5698 // When true, prevents input dispatch from proceeding until set to false again.
5699 private boolean mInputDispatchFrozen;
5700
5701 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5702 private boolean mInputDispatchEnabled = true;
5703
5704 // Temporary list of windows information to provide to the input dispatcher.
5705 private InputWindowList mTempInputWindows = new InputWindowList();
5706
5707 // Temporary input application object to provide to the input dispatcher.
5708 private InputApplication mTempInputApplication = new InputApplication();
5709
5710 /* Notifies the window manager about a broken input channel.
5711 *
5712 * Called by the InputManager.
5713 */
5714 public void notifyInputChannelBroken(InputChannel inputChannel) {
5715 synchronized (mWindowMap) {
5716 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5717 if (windowState == null) {
5718 return; // irrelevant
5719 }
5720
5721 Slog.i(TAG, "WINDOW DIED " + windowState);
5722 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005723 }
5724 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005725
Jeff Brown519e0242010-09-15 15:18:56 -07005726 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005727 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005728 *
5729 * Called by the InputManager.
5730 */
Jeff Brown519e0242010-09-15 15:18:56 -07005731 public long notifyANR(Object token, InputChannel inputChannel) {
5732 AppWindowToken appWindowToken = null;
5733 if (inputChannel != null) {
5734 synchronized (mWindowMap) {
5735 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5736 if (windowState != null) {
5737 Slog.i(TAG, "Input event dispatching timed out sending to "
5738 + windowState.mAttrs.getTitle());
5739 appWindowToken = windowState.mAppToken;
5740 }
Jeff Brown349703e2010-06-22 01:27:15 -07005741 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005742 }
5743
Jeff Brown519e0242010-09-15 15:18:56 -07005744 if (appWindowToken == null && token != null) {
5745 appWindowToken = (AppWindowToken) token;
5746 Slog.i(TAG, "Input event dispatching timed out sending to application "
5747 + appWindowToken.stringName);
5748 }
Jeff Brown349703e2010-06-22 01:27:15 -07005749
Jeff Brown519e0242010-09-15 15:18:56 -07005750 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005751 try {
5752 // Notify the activity manager about the timeout and let it decide whether
5753 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005754 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005755 if (! abort) {
5756 // The activity manager declined to abort dispatching.
5757 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005758 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005759 }
Jeff Brown349703e2010-06-22 01:27:15 -07005760 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005761 }
5762 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005763 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005764 }
5765
Jeff Brown349703e2010-06-22 01:27:15 -07005766 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5767 synchronized (mWindowMap) {
5768 return getWindowStateForInputChannelLocked(inputChannel);
5769 }
5770 }
5771
5772 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5773 int windowCount = mWindows.size();
5774 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005775 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005776 if (windowState.mInputChannel == inputChannel) {
5777 return windowState;
5778 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005779 }
5780
Jeff Brown349703e2010-06-22 01:27:15 -07005781 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005782 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005783
Chris Tatea32dcf72010-10-14 12:13:50 -07005784 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005785 final InputWindow inputWindow = windowList.add();
5786 inputWindow.inputChannel = mDragState.mServerChannel;
5787 inputWindow.name = "drag";
5788 inputWindow.layoutParamsFlags = 0;
5789 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5790 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5791 inputWindow.visible = true;
5792 inputWindow.canReceiveKeys = false;
5793 inputWindow.hasFocus = true;
5794 inputWindow.hasWallpaper = false;
5795 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005796 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005797 inputWindow.ownerPid = Process.myPid();
5798 inputWindow.ownerUid = Process.myUid();
5799
5800 // The drag window covers the entire display
5801 inputWindow.frameLeft = 0;
5802 inputWindow.frameTop = 0;
5803 inputWindow.frameRight = mDisplay.getWidth();
5804 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005805
Christopher Tatea53146c2010-09-07 11:57:52 -07005806 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5807 inputWindow.visibleFrameTop = inputWindow.frameTop;
5808 inputWindow.visibleFrameRight = inputWindow.frameRight;
5809 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5810
5811 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5812 inputWindow.touchableAreaTop = inputWindow.frameTop;
5813 inputWindow.touchableAreaRight = inputWindow.frameRight;
5814 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5815 }
5816
Jeff Brown349703e2010-06-22 01:27:15 -07005817 /* Updates the cached window information provided to the input dispatcher. */
5818 public void updateInputWindowsLw() {
5819 // Populate the input window list with information about all of the windows that
5820 // could potentially receive input.
5821 // As an optimization, we could try to prune the list of windows but this turns
5822 // out to be difficult because only the native code knows for sure which window
5823 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005824 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005825
5826 // If there's a drag in flight, provide a pseudowindow to catch drag input
5827 final boolean inDrag = (mDragState != null);
5828 if (inDrag) {
5829 if (DEBUG_DRAG) {
5830 Log.d(TAG, "Inserting drag window");
5831 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005832 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005833 }
5834
Jeff Brown7fbdc842010-06-17 20:52:56 -07005835 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005836 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005837 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005838 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005839 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005840 continue;
5841 }
5842
Jeff Brown349703e2010-06-22 01:27:15 -07005843 final int flags = child.mAttrs.flags;
5844 final int type = child.mAttrs.type;
5845
5846 final boolean hasFocus = (child == mInputFocus);
5847 final boolean isVisible = child.isVisibleLw();
5848 final boolean hasWallpaper = (child == mWallpaperTarget)
5849 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005850
5851 // If there's a drag in progress and 'child' is a potential drop target,
5852 // make sure it's been told about the drag
5853 if (inDrag && isVisible) {
5854 mDragState.sendDragStartedIfNeededLw(child);
5855 }
5856
Jeff Brown349703e2010-06-22 01:27:15 -07005857 // Add a window to our list of input windows.
5858 final InputWindow inputWindow = mTempInputWindows.add();
5859 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005860 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005861 inputWindow.layoutParamsFlags = flags;
5862 inputWindow.layoutParamsType = type;
5863 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5864 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005865 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005866 inputWindow.hasFocus = hasFocus;
5867 inputWindow.hasWallpaper = hasWallpaper;
5868 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005869 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005870 inputWindow.ownerPid = child.mSession.mPid;
5871 inputWindow.ownerUid = child.mSession.mUid;
5872
5873 final Rect frame = child.mFrame;
5874 inputWindow.frameLeft = frame.left;
5875 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005876 inputWindow.frameRight = frame.right;
5877 inputWindow.frameBottom = frame.bottom;
5878
5879 final Rect visibleFrame = child.mVisibleFrame;
5880 inputWindow.visibleFrameLeft = visibleFrame.left;
5881 inputWindow.visibleFrameTop = visibleFrame.top;
5882 inputWindow.visibleFrameRight = visibleFrame.right;
5883 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005884
5885 switch (child.mTouchableInsets) {
5886 default:
5887 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5888 inputWindow.touchableAreaLeft = frame.left;
5889 inputWindow.touchableAreaTop = frame.top;
5890 inputWindow.touchableAreaRight = frame.right;
5891 inputWindow.touchableAreaBottom = frame.bottom;
5892 break;
5893
5894 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5895 Rect inset = child.mGivenContentInsets;
5896 inputWindow.touchableAreaLeft = frame.left + inset.left;
5897 inputWindow.touchableAreaTop = frame.top + inset.top;
5898 inputWindow.touchableAreaRight = frame.right - inset.right;
5899 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5900 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005901 }
Jeff Brown349703e2010-06-22 01:27:15 -07005902
5903 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5904 Rect inset = child.mGivenVisibleInsets;
5905 inputWindow.touchableAreaLeft = frame.left + inset.left;
5906 inputWindow.touchableAreaTop = frame.top + inset.top;
5907 inputWindow.touchableAreaRight = frame.right - inset.right;
5908 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005909 break;
5910 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005911 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005912 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005913
Jeff Brown349703e2010-06-22 01:27:15 -07005914 // Send windows to native code.
5915 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005916
Jeff Brown349703e2010-06-22 01:27:15 -07005917 // Clear the list in preparation for the next round.
5918 // Also avoids keeping InputChannel objects referenced unnecessarily.
5919 mTempInputWindows.clear();
5920 }
5921
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005922 /* Notifies that the lid switch changed state. */
5923 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5924 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5925 }
5926
Jeff Brown349703e2010-06-22 01:27:15 -07005927 /* Provides an opportunity for the window manager policy to intercept early key
5928 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08005929 public int interceptKeyBeforeQueueing(
5930 KeyEvent event, int policyFlags, boolean isScreenOn) {
5931 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005932 }
5933
5934 /* Provides an opportunity for the window manager policy to process a key before
5935 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08005936 public boolean interceptKeyBeforeDispatching(
5937 InputChannel focus, KeyEvent event, int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005938 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown1f245102010-11-18 20:53:46 -08005939 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005940 }
5941
Jeff Brown3915bb82010-11-05 15:02:16 -07005942 /* Provides an opportunity for the window manager policy to process a key that
5943 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08005944 public KeyEvent dispatchUnhandledKey(
Jeff Brown1f245102010-11-18 20:53:46 -08005945 InputChannel focus, KeyEvent event, int policyFlags) {
Jeff Brown3915bb82010-11-05 15:02:16 -07005946 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown1f245102010-11-18 20:53:46 -08005947 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07005948 }
5949
Jeff Brown349703e2010-06-22 01:27:15 -07005950 /* Called when the current input focus changes.
5951 * Layer assignment is assumed to be complete by the time this is called.
5952 */
5953 public void setInputFocusLw(WindowState newWindow) {
5954 if (DEBUG_INPUT) {
5955 Slog.d(TAG, "Input focus has changed to " + newWindow);
5956 }
5957
5958 if (newWindow != mInputFocus) {
5959 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005960 // Displaying a window implicitly causes dispatching to be unpaused.
5961 // This is to protect against bugs if someone pauses dispatching but
5962 // forgets to resume.
5963 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005964 }
Jeff Brown349703e2010-06-22 01:27:15 -07005965
5966 mInputFocus = newWindow;
5967 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005968 }
5969 }
5970
Jeff Brown349703e2010-06-22 01:27:15 -07005971 public void setFocusedAppLw(AppWindowToken newApp) {
5972 // Focused app has changed.
5973 if (newApp == null) {
5974 mInputManager.setFocusedApplication(null);
5975 } else {
5976 mTempInputApplication.name = newApp.toString();
5977 mTempInputApplication.dispatchingTimeoutNanos =
5978 newApp.inputDispatchingTimeoutNanos;
5979 mTempInputApplication.token = newApp;
5980
5981 mInputManager.setFocusedApplication(mTempInputApplication);
5982 }
5983 }
5984
Jeff Brown349703e2010-06-22 01:27:15 -07005985 public void pauseDispatchingLw(WindowToken window) {
5986 if (! window.paused) {
5987 if (DEBUG_INPUT) {
5988 Slog.v(TAG, "Pausing WindowToken " + window);
5989 }
5990
5991 window.paused = true;
5992 updateInputWindowsLw();
5993 }
5994 }
5995
5996 public void resumeDispatchingLw(WindowToken window) {
5997 if (window.paused) {
5998 if (DEBUG_INPUT) {
5999 Slog.v(TAG, "Resuming WindowToken " + window);
6000 }
6001
6002 window.paused = false;
6003 updateInputWindowsLw();
6004 }
6005 }
6006
6007 public void freezeInputDispatchingLw() {
6008 if (! mInputDispatchFrozen) {
6009 if (DEBUG_INPUT) {
6010 Slog.v(TAG, "Freezing input dispatching");
6011 }
6012
6013 mInputDispatchFrozen = true;
6014 updateInputDispatchModeLw();
6015 }
6016 }
6017
6018 public void thawInputDispatchingLw() {
6019 if (mInputDispatchFrozen) {
6020 if (DEBUG_INPUT) {
6021 Slog.v(TAG, "Thawing input dispatching");
6022 }
6023
6024 mInputDispatchFrozen = false;
6025 updateInputDispatchModeLw();
6026 }
6027 }
6028
6029 public void setEventDispatchingLw(boolean enabled) {
6030 if (mInputDispatchEnabled != enabled) {
6031 if (DEBUG_INPUT) {
6032 Slog.v(TAG, "Setting event dispatching to " + enabled);
6033 }
6034
6035 mInputDispatchEnabled = enabled;
6036 updateInputDispatchModeLw();
6037 }
6038 }
6039
6040 private void updateInputDispatchModeLw() {
6041 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6042 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006043 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 public void pauseKeyDispatching(IBinder _token) {
6046 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6047 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006048 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006049 }
6050
6051 synchronized (mWindowMap) {
6052 WindowToken token = mTokenMap.get(_token);
6053 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006054 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006055 }
6056 }
6057 }
6058
6059 public void resumeKeyDispatching(IBinder _token) {
6060 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6061 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006062 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006063 }
6064
6065 synchronized (mWindowMap) {
6066 WindowToken token = mTokenMap.get(_token);
6067 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006068 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006069 }
6070 }
6071 }
6072
6073 public void setEventDispatching(boolean enabled) {
6074 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6075 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006076 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006077 }
6078
6079 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006080 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006081 }
6082 }
Romain Guy06882f82009-06-10 13:36:04 -07006083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 /**
6085 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006086 * Even when sync is false, this method may block while waiting for current
6087 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006088 *
6089 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006090 * {@link SystemClock#uptimeMillis()} as the timebase.)
6091 * @param sync If true, wait for the event to be completed before returning to the caller.
6092 * @return Returns true if event was dispatched, false if it was dropped for any reason
6093 */
6094 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6095 long downTime = ev.getDownTime();
6096 long eventTime = ev.getEventTime();
6097
6098 int action = ev.getAction();
6099 int code = ev.getKeyCode();
6100 int repeatCount = ev.getRepeatCount();
6101 int metaState = ev.getMetaState();
6102 int deviceId = ev.getDeviceId();
6103 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006104 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006105 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006106
6107 if (source == InputDevice.SOURCE_UNKNOWN) {
6108 source = InputDevice.SOURCE_KEYBOARD;
6109 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006110
6111 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6112 if (downTime == 0) downTime = eventTime;
6113
6114 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006115 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006117 final int pid = Binder.getCallingPid();
6118 final int uid = Binder.getCallingUid();
6119 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006120
Jeff Brownbbda99d2010-07-28 15:48:59 -07006121 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6122 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6123 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6124 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006125
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006126 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006127 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 }
6129
6130 /**
6131 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006132 * Even when sync is false, this method may block while waiting for current
6133 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006134 *
6135 * @param ev A motion event describing the pointer (touch) action. (As noted in
6136 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006137 * {@link SystemClock#uptimeMillis()} as the timebase.)
6138 * @param sync If true, wait for the event to be completed before returning to the caller.
6139 * @return Returns true if event was dispatched, false if it was dropped for any reason
6140 */
6141 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006142 final int pid = Binder.getCallingPid();
6143 final int uid = Binder.getCallingUid();
6144 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006145
Jeff Brownc5ed5912010-07-14 18:48:53 -07006146 MotionEvent newEvent = MotionEvent.obtain(ev);
6147 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6148 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6149 }
6150
Jeff Brownbbda99d2010-07-28 15:48:59 -07006151 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6152 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6153 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6154 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006155
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006156 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006157 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006158 }
Romain Guy06882f82009-06-10 13:36:04 -07006159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006160 /**
6161 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006162 * Even when sync is false, this method may block while waiting for current
6163 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006164 *
6165 * @param ev A motion event describing the trackball action. (As noted in
6166 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006167 * {@link SystemClock#uptimeMillis()} as the timebase.)
6168 * @param sync If true, wait for the event to be completed before returning to the caller.
6169 * @return Returns true if event was dispatched, false if it was dropped for any reason
6170 */
6171 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006172 final int pid = Binder.getCallingPid();
6173 final int uid = Binder.getCallingUid();
6174 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006175
Jeff Brownc5ed5912010-07-14 18:48:53 -07006176 MotionEvent newEvent = MotionEvent.obtain(ev);
6177 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6178 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6179 }
6180
Jeff Brownbbda99d2010-07-28 15:48:59 -07006181 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6182 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6183 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6184 INJECTION_TIMEOUT_MILLIS);
6185
6186 Binder.restoreCallingIdentity(ident);
6187 return reportInjectionResult(result);
6188 }
6189
6190 /**
6191 * Inject an input event into the UI without waiting for dispatch to commence.
6192 * This variant is useful for fire-and-forget input event injection. It does not
6193 * block any longer than it takes to enqueue the input event.
6194 *
6195 * @param ev An input event. (Be sure to set the input source correctly.)
6196 * @return Returns true if event was dispatched, false if it was dropped for any reason
6197 */
6198 public boolean injectInputEventNoWait(InputEvent ev) {
6199 final int pid = Binder.getCallingPid();
6200 final int uid = Binder.getCallingUid();
6201 final long ident = Binder.clearCallingIdentity();
6202
6203 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6204 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6205 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006206
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006207 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006208 return reportInjectionResult(result);
6209 }
6210
6211 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006212 switch (result) {
6213 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6214 Slog.w(TAG, "Input event injection permission denied.");
6215 throw new SecurityException(
6216 "Injecting to another application requires INJECT_EVENTS permission");
6217 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006218 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006219 return true;
6220 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6221 Slog.w(TAG, "Input event injection timed out.");
6222 return false;
6223 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6224 default:
6225 Slog.w(TAG, "Input event injection failed.");
6226 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 }
Romain Guy06882f82009-06-10 13:36:04 -07006229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006230 private WindowState getFocusedWindow() {
6231 synchronized (mWindowMap) {
6232 return getFocusedWindowLocked();
6233 }
6234 }
6235
6236 private WindowState getFocusedWindowLocked() {
6237 return mCurrentFocus;
6238 }
Romain Guy06882f82009-06-10 13:36:04 -07006239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006240 public boolean detectSafeMode() {
6241 mSafeMode = mPolicy.detectSafeMode();
6242 return mSafeMode;
6243 }
Romain Guy06882f82009-06-10 13:36:04 -07006244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006245 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006246 synchronized(mWindowMap) {
6247 if (mDisplay != null) {
6248 throw new IllegalStateException("Display already initialized");
6249 }
6250 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6251 mDisplay = wm.getDefaultDisplay();
6252 mInitialDisplayWidth = mDisplay.getWidth();
6253 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006254 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6255 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006256 }
6257
6258 try {
6259 mActivityManager.updateConfiguration(null);
6260 } catch (RemoteException e) {
6261 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006262
6263 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006264 }
6265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006266 // -------------------------------------------------------------
6267 // Client Session State
6268 // -------------------------------------------------------------
6269
6270 private final class Session extends IWindowSession.Stub
6271 implements IBinder.DeathRecipient {
6272 final IInputMethodClient mClient;
6273 final IInputContext mInputContext;
6274 final int mUid;
6275 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006276 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277 SurfaceSession mSurfaceSession;
6278 int mNumWindow = 0;
6279 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 public Session(IInputMethodClient client, IInputContext inputContext) {
6282 mClient = client;
6283 mInputContext = inputContext;
6284 mUid = Binder.getCallingUid();
6285 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006286 StringBuilder sb = new StringBuilder();
6287 sb.append("Session{");
6288 sb.append(Integer.toHexString(System.identityHashCode(this)));
6289 sb.append(" uid ");
6290 sb.append(mUid);
6291 sb.append("}");
6292 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 synchronized (mWindowMap) {
6295 if (mInputMethodManager == null && mHaveInputMethods) {
6296 IBinder b = ServiceManager.getService(
6297 Context.INPUT_METHOD_SERVICE);
6298 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6299 }
6300 }
6301 long ident = Binder.clearCallingIdentity();
6302 try {
6303 // Note: it is safe to call in to the input method manager
6304 // here because we are not holding our lock.
6305 if (mInputMethodManager != null) {
6306 mInputMethodManager.addClient(client, inputContext,
6307 mUid, mPid);
6308 } else {
6309 client.setUsingInputMethod(false);
6310 }
6311 client.asBinder().linkToDeath(this, 0);
6312 } catch (RemoteException e) {
6313 // The caller has died, so we can just forget about this.
6314 try {
6315 if (mInputMethodManager != null) {
6316 mInputMethodManager.removeClient(client);
6317 }
6318 } catch (RemoteException ee) {
6319 }
6320 } finally {
6321 Binder.restoreCallingIdentity(ident);
6322 }
6323 }
Romain Guy06882f82009-06-10 13:36:04 -07006324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006325 @Override
6326 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6327 throws RemoteException {
6328 try {
6329 return super.onTransact(code, data, reply, flags);
6330 } catch (RuntimeException e) {
6331 // Log all 'real' exceptions thrown to the caller
6332 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006333 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006334 }
6335 throw e;
6336 }
6337 }
6338
6339 public void binderDied() {
6340 // Note: it is safe to call in to the input method manager
6341 // here because we are not holding our lock.
6342 try {
6343 if (mInputMethodManager != null) {
6344 mInputMethodManager.removeClient(mClient);
6345 }
6346 } catch (RemoteException e) {
6347 }
6348 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006349 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006350 mClientDead = true;
6351 killSessionLocked();
6352 }
6353 }
6354
6355 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006356 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6357 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6358 outInputChannel);
6359 }
6360
6361 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006362 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006363 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006364 }
Romain Guy06882f82009-06-10 13:36:04 -07006365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006366 public void remove(IWindow window) {
6367 removeWindow(this, window);
6368 }
Romain Guy06882f82009-06-10 13:36:04 -07006369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6371 int requestedWidth, int requestedHeight, int viewFlags,
6372 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006373 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006374 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6375 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006377 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006378 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6379 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006380 }
Romain Guy06882f82009-06-10 13:36:04 -07006381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 public void setTransparentRegion(IWindow window, Region region) {
6383 setTransparentRegionWindow(this, window, region);
6384 }
Romain Guy06882f82009-06-10 13:36:04 -07006385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 public void setInsets(IWindow window, int touchableInsets,
6387 Rect contentInsets, Rect visibleInsets) {
6388 setInsetsWindow(this, window, touchableInsets, contentInsets,
6389 visibleInsets);
6390 }
Romain Guy06882f82009-06-10 13:36:04 -07006391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006392 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6393 getWindowDisplayFrame(this, window, outDisplayFrame);
6394 }
Romain Guy06882f82009-06-10 13:36:04 -07006395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006397 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 TAG, "IWindow finishDrawing called for " + window);
6399 finishDrawingWindow(this, window);
6400 }
6401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 public void setInTouchMode(boolean mode) {
6403 synchronized(mWindowMap) {
6404 mInTouchMode = mode;
6405 }
6406 }
6407
6408 public boolean getInTouchMode() {
6409 synchronized(mWindowMap) {
6410 return mInTouchMode;
6411 }
6412 }
6413
6414 public boolean performHapticFeedback(IWindow window, int effectId,
6415 boolean always) {
6416 synchronized(mWindowMap) {
6417 long ident = Binder.clearCallingIdentity();
6418 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006419 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006420 windowForClientLocked(this, window, true),
6421 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006422 } finally {
6423 Binder.restoreCallingIdentity(ident);
6424 }
6425 }
6426 }
Romain Guy06882f82009-06-10 13:36:04 -07006427
Christopher Tatea53146c2010-09-07 11:57:52 -07006428 /* Drag/drop */
6429 public IBinder prepareDrag(IWindow window, boolean localOnly,
6430 int width, int height, Surface outSurface) {
6431 return prepareDragSurface(window, mSurfaceSession, localOnly,
6432 width, height, outSurface);
6433 }
6434
6435 public boolean performDrag(IWindow window, IBinder dragToken,
6436 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6437 ClipData data) {
6438 if (DEBUG_DRAG) {
6439 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6440 }
6441
6442 synchronized (mWindowMap) {
6443 if (mDragState == null) {
6444 Slog.w(TAG, "No drag prepared");
6445 throw new IllegalStateException("performDrag() without prepareDrag()");
6446 }
6447
6448 if (dragToken != mDragState.mToken) {
6449 Slog.w(TAG, "Performing mismatched drag");
6450 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6451 }
6452
6453 WindowState callingWin = windowForClientLocked(null, window, false);
6454 if (callingWin == null) {
6455 Slog.w(TAG, "Bad requesting window " + window);
6456 return false; // !!! TODO: throw here?
6457 }
6458
6459 // !!! TODO: if input is not still focused on the initiating window, fail
6460 // the drag initiation (e.g. an alarm window popped up just as the application
6461 // called performDrag()
6462
6463 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6464
Christopher Tate2c095f32010-10-04 14:13:40 -07006465 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6466 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006467
Chris Tateb478f462010-10-15 16:02:26 -07006468 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6469 // the actual drag event dispatch stuff in the dragstate
6470
Christopher Tatea53146c2010-09-07 11:57:52 -07006471 mDragState.register();
6472 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006473 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6474 mDragState.mServerChannel)) {
6475 Slog.e(TAG, "Unable to transfer touch focus");
6476 mDragState.unregister();
6477 mDragState = null;
6478 mInputMonitor.updateInputWindowsLw();
6479 return false;
6480 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006481
6482 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006483 mDragState.mCurrentX = touchX;
6484 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006485 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006486
6487 // remember the thumb offsets for later
6488 mDragState.mThumbOffsetX = thumbCenterX;
6489 mDragState.mThumbOffsetY = thumbCenterY;
6490
6491 // Make the surface visible at the proper location
6492 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006493 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006494 try {
6495 surface.setPosition((int)(touchX - thumbCenterX),
6496 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006497 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006498 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006499 surface.show();
6500 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006501 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006502 }
6503 }
6504
6505 return true; // success!
6506 }
6507
Chris Tated4533f142010-10-19 15:15:08 -07006508 public void reportDropResult(IWindow window, boolean consumed) {
6509 IBinder token = window.asBinder();
6510 if (DEBUG_DRAG) {
6511 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6512 }
6513
6514 synchronized (mWindowMap) {
6515 if (mDragState.mToken != token) {
6516 Slog.w(TAG, "Invalid drop-result claim by " + window);
6517 throw new IllegalStateException("reportDropResult() by non-recipient");
6518 }
6519
6520 // The right window has responded, even if it's no longer around,
6521 // so be sure to halt the timeout even if the later WindowState
6522 // lookup fails.
6523 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6524
6525 WindowState callingWin = windowForClientLocked(null, window, false);
6526 if (callingWin == null) {
6527 Slog.w(TAG, "Bad result-reporting window " + window);
6528 return; // !!! TODO: throw here?
6529 }
6530
6531 mDragState.mDragResult = consumed;
6532 mDragState.endDragLw();
6533 }
6534 }
6535
Christopher Tatea53146c2010-09-07 11:57:52 -07006536 public void dragRecipientEntered(IWindow window) {
6537 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006538 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006539 }
6540 }
6541
6542 public void dragRecipientExited(IWindow window) {
6543 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006544 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006545 }
6546 }
6547
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006548 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006549 synchronized(mWindowMap) {
6550 long ident = Binder.clearCallingIdentity();
6551 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006552 setWindowWallpaperPositionLocked(
6553 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006554 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006555 } finally {
6556 Binder.restoreCallingIdentity(ident);
6557 }
6558 }
6559 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006560
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006561 public void wallpaperOffsetsComplete(IBinder window) {
6562 WindowManagerService.this.wallpaperOffsetsComplete(window);
6563 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006564
Dianne Hackborn75804932009-10-20 20:15:20 -07006565 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6566 int z, Bundle extras, boolean sync) {
6567 synchronized(mWindowMap) {
6568 long ident = Binder.clearCallingIdentity();
6569 try {
6570 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006571 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006572 action, x, y, z, extras, sync);
6573 } finally {
6574 Binder.restoreCallingIdentity(ident);
6575 }
6576 }
6577 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006578
Dianne Hackborn75804932009-10-20 20:15:20 -07006579 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6580 WindowManagerService.this.wallpaperCommandComplete(window, result);
6581 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006583 void windowAddedLocked() {
6584 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006585 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006586 TAG, "First window added to " + this + ", creating SurfaceSession");
6587 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006588 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006589 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 mSessions.add(this);
6591 }
6592 mNumWindow++;
6593 }
6594
6595 void windowRemovedLocked() {
6596 mNumWindow--;
6597 killSessionLocked();
6598 }
Romain Guy06882f82009-06-10 13:36:04 -07006599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 void killSessionLocked() {
6601 if (mNumWindow <= 0 && mClientDead) {
6602 mSessions.remove(this);
6603 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006604 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006605 TAG, "Last window removed from " + this
6606 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006607 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006608 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 try {
6610 mSurfaceSession.kill();
6611 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006612 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 + mSurfaceSession + " in session " + this
6614 + ": " + e.toString());
6615 }
6616 mSurfaceSession = null;
6617 }
6618 }
6619 }
Romain Guy06882f82009-06-10 13:36:04 -07006620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006621 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006622 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6623 pw.print(" mClientDead="); pw.print(mClientDead);
6624 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006625 }
6626
6627 @Override
6628 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006629 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006630 }
6631 }
6632
6633 // -------------------------------------------------------------
6634 // Client Window State
6635 // -------------------------------------------------------------
6636
6637 private final class WindowState implements WindowManagerPolicy.WindowState {
6638 final Session mSession;
6639 final IWindow mClient;
6640 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006641 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642 AppWindowToken mAppToken;
6643 AppWindowToken mTargetAppToken;
6644 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6645 final DeathRecipient mDeathRecipient;
6646 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006647 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006648 final int mBaseLayer;
6649 final int mSubLayer;
6650 final boolean mLayoutAttached;
6651 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006652 final boolean mIsWallpaper;
6653 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654 int mViewVisibility;
6655 boolean mPolicyVisibility = true;
6656 boolean mPolicyVisibilityAfterAnim = true;
6657 boolean mAppFreezing;
6658 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006659 boolean mReportDestroySurface;
6660 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006661 boolean mAttachedHidden; // is our parent window hidden?
6662 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006663 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006664 int mRequestedWidth;
6665 int mRequestedHeight;
6666 int mLastRequestedWidth;
6667 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006668 int mLayer;
6669 int mAnimLayer;
6670 int mLastLayer;
6671 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006672 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006673 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006674
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006675 int mLayoutSeq = -1;
6676
6677 Configuration mConfiguration = null;
6678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006679 // Actual frame shown on-screen (may be modified by animation)
6680 final Rect mShownFrame = new Rect();
6681 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006684 * Set when we have changed the size of the surface, to know that
6685 * we must tell them application to resize (and thus redraw itself).
6686 */
6687 boolean mSurfaceResized;
6688
6689 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 * Insets that determine the actually visible area
6691 */
6692 final Rect mVisibleInsets = new Rect();
6693 final Rect mLastVisibleInsets = new Rect();
6694 boolean mVisibleInsetsChanged;
6695
6696 /**
6697 * Insets that are covered by system windows
6698 */
6699 final Rect mContentInsets = new Rect();
6700 final Rect mLastContentInsets = new Rect();
6701 boolean mContentInsetsChanged;
6702
6703 /**
6704 * Set to true if we are waiting for this window to receive its
6705 * given internal insets before laying out other windows based on it.
6706 */
6707 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709 /**
6710 * These are the content insets that were given during layout for
6711 * this window, to be applied to windows behind it.
6712 */
6713 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 /**
6716 * These are the visible insets that were given during layout for
6717 * this window, to be applied to windows behind it.
6718 */
6719 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006721 /**
6722 * Flag indicating whether the touchable region should be adjusted by
6723 * the visible insets; if false the area outside the visible insets is
6724 * NOT touchable, so we must use those to adjust the frame during hit
6725 * tests.
6726 */
6727 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006729 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006730 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006731 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6732 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6733 float mHScale=1, mVScale=1;
6734 float mLastHScale=1, mLastVScale=1;
6735 final Matrix mTmpMatrix = new Matrix();
6736
6737 // "Real" frame that the application sees.
6738 final Rect mFrame = new Rect();
6739 final Rect mLastFrame = new Rect();
6740
6741 final Rect mContainingFrame = new Rect();
6742 final Rect mDisplayFrame = new Rect();
6743 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006744 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 final Rect mVisibleFrame = new Rect();
6746
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006747 boolean mContentChanged;
6748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 float mShownAlpha = 1;
6750 float mAlpha = 1;
6751 float mLastAlpha = 1;
6752
6753 // Set to true if, when the window gets displayed, it should perform
6754 // an enter animation.
6755 boolean mEnterAnimationPending;
6756
6757 // Currently running animation.
6758 boolean mAnimating;
6759 boolean mLocalAnimating;
6760 Animation mAnimation;
6761 boolean mAnimationIsEntrance;
6762 boolean mHasTransformation;
6763 boolean mHasLocalTransformation;
6764 final Transformation mTransformation = new Transformation();
6765
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006766 // If a window showing a wallpaper: the requested offset for the
6767 // wallpaper; if a wallpaper window: the currently applied offset.
6768 float mWallpaperX = -1;
6769 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006770
6771 // If a window showing a wallpaper: what fraction of the offset
6772 // range corresponds to a full virtual screen.
6773 float mWallpaperXStep = -1;
6774 float mWallpaperYStep = -1;
6775
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006776 // Wallpaper windows: pixels offset based on above variables.
6777 int mXOffset;
6778 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 // This is set after IWindowSession.relayout() has been called at
6781 // least once for the window. It allows us to detect the situation
6782 // where we don't yet have a surface, but should have one soon, so
6783 // we can give the window focus before waiting for the relayout.
6784 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006786 // This is set after the Surface has been created but before the
6787 // window has been drawn. During this time the surface is hidden.
6788 boolean mDrawPending;
6789
6790 // This is set after the window has finished drawing for the first
6791 // time but before its surface is shown. The surface will be
6792 // displayed when the next layout is run.
6793 boolean mCommitDrawPending;
6794
6795 // This is set during the time after the window's drawing has been
6796 // committed, and before its surface is actually shown. It is used
6797 // to delay showing the surface until all windows in a token are ready
6798 // to be shown.
6799 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006801 // Set when the window has been shown in the screen the first time.
6802 boolean mHasDrawn;
6803
6804 // Currently running an exit animation?
6805 boolean mExiting;
6806
6807 // Currently on the mDestroySurface list?
6808 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810 // Completely remove from window manager after exit animation?
6811 boolean mRemoveOnExit;
6812
6813 // Set when the orientation is changing and this window has not yet
6814 // been updated for the new orientation.
6815 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006817 // Is this window now (or just being) removed?
6818 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006819
Dianne Hackborn16064f92010-03-25 00:47:24 -07006820 // For debugging, this is the last information given to the surface flinger.
6821 boolean mSurfaceShown;
6822 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6823 int mSurfaceLayer;
6824 float mSurfaceAlpha;
6825
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006826 // Input channel
6827 InputChannel mInputChannel;
6828
Mattias Petersson1622eee2010-12-21 10:15:11 +01006829 // Used to improve performance of toString()
6830 String mStringNameCache;
6831 CharSequence mLastTitle;
6832 boolean mWasPaused;
6833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 WindowState(Session s, IWindow c, WindowToken token,
6835 WindowState attachedWindow, WindowManager.LayoutParams a,
6836 int viewVisibility) {
6837 mSession = s;
6838 mClient = c;
6839 mToken = token;
6840 mAttrs.copyFrom(a);
6841 mViewVisibility = viewVisibility;
6842 DeathRecipient deathRecipient = new DeathRecipient();
6843 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006844 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845 TAG, "Window " + this + " client=" + c.asBinder()
6846 + " token=" + token + " (" + mAttrs.token + ")");
6847 try {
6848 c.asBinder().linkToDeath(deathRecipient, 0);
6849 } catch (RemoteException e) {
6850 mDeathRecipient = null;
6851 mAttachedWindow = null;
6852 mLayoutAttached = false;
6853 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006854 mIsWallpaper = false;
6855 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 mBaseLayer = 0;
6857 mSubLayer = 0;
6858 return;
6859 }
6860 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6863 mAttrs.type <= LAST_SUB_WINDOW)) {
6864 // The multiplier here is to reserve space for multiple
6865 // windows in the same type layer.
6866 mBaseLayer = mPolicy.windowTypeToLayerLw(
6867 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6868 + TYPE_LAYER_OFFSET;
6869 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6870 mAttachedWindow = attachedWindow;
6871 mAttachedWindow.mChildWindows.add(this);
6872 mLayoutAttached = mAttrs.type !=
6873 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6874 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6875 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006876 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6877 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 } else {
6879 // The multiplier here is to reserve space for multiple
6880 // windows in the same type layer.
6881 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6882 * TYPE_LAYER_MULTIPLIER
6883 + TYPE_LAYER_OFFSET;
6884 mSubLayer = 0;
6885 mAttachedWindow = null;
6886 mLayoutAttached = false;
6887 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6888 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006889 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6890 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 }
6892
6893 WindowState appWin = this;
6894 while (appWin.mAttachedWindow != null) {
6895 appWin = mAttachedWindow;
6896 }
6897 WindowToken appToken = appWin.mToken;
6898 while (appToken.appWindowToken == null) {
6899 WindowToken parent = mTokenMap.get(appToken.token);
6900 if (parent == null || appToken == parent) {
6901 break;
6902 }
6903 appToken = parent;
6904 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006905 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006906 mAppToken = appToken.appWindowToken;
6907
6908 mSurface = null;
6909 mRequestedWidth = 0;
6910 mRequestedHeight = 0;
6911 mLastRequestedWidth = 0;
6912 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006913 mXOffset = 0;
6914 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006915 mLayer = 0;
6916 mAnimLayer = 0;
6917 mLastLayer = 0;
6918 }
6919
6920 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006921 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 TAG, "Attaching " + this + " token=" + mToken
6923 + ", list=" + mToken.windows);
6924 mSession.windowAddedLocked();
6925 }
6926
6927 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6928 mHaveFrame = true;
6929
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006930 final Rect container = mContainingFrame;
6931 container.set(pf);
6932
6933 final Rect display = mDisplayFrame;
6934 display.set(df);
6935
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006936 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006937 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006938 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6939 display.intersect(mCompatibleScreenFrame);
6940 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006941 }
6942
6943 final int pw = container.right - container.left;
6944 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945
6946 int w,h;
6947 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6948 w = mAttrs.width < 0 ? pw : mAttrs.width;
6949 h = mAttrs.height< 0 ? ph : mAttrs.height;
6950 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006951 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6952 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006953 }
Romain Guy06882f82009-06-10 13:36:04 -07006954
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006955 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006956 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
6957 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006958 mParentFrame.set(pf);
6959 mContentChanged = true;
6960 }
6961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 final Rect content = mContentFrame;
6963 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006965 final Rect visible = mVisibleFrame;
6966 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006969 final int fw = frame.width();
6970 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006972 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6973 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6974
6975 Gravity.apply(mAttrs.gravity, w, h, container,
6976 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6977 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6978
6979 //System.out.println("Out: " + mFrame);
6980
6981 // Now make sure the window fits in the overall display.
6982 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006984 // Make sure the content and visible frames are inside of the
6985 // final window frame.
6986 if (content.left < frame.left) content.left = frame.left;
6987 if (content.top < frame.top) content.top = frame.top;
6988 if (content.right > frame.right) content.right = frame.right;
6989 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6990 if (visible.left < frame.left) visible.left = frame.left;
6991 if (visible.top < frame.top) visible.top = frame.top;
6992 if (visible.right > frame.right) visible.right = frame.right;
6993 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006995 final Rect contentInsets = mContentInsets;
6996 contentInsets.left = content.left-frame.left;
6997 contentInsets.top = content.top-frame.top;
6998 contentInsets.right = frame.right-content.right;
6999 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007001 final Rect visibleInsets = mVisibleInsets;
7002 visibleInsets.left = visible.left-frame.left;
7003 visibleInsets.top = visible.top-frame.top;
7004 visibleInsets.right = frame.right-visible.right;
7005 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007006
Dianne Hackborn284ac932009-08-28 10:34:25 -07007007 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7008 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007009 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007010 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 if (localLOGV) {
7013 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7014 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007015 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007016 + mRequestedWidth + ", mRequestedheight="
7017 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7018 + "): frame=" + mFrame.toShortString()
7019 + " ci=" + contentInsets.toShortString()
7020 + " vi=" + visibleInsets.toShortString());
7021 //}
7022 }
7023 }
Romain Guy06882f82009-06-10 13:36:04 -07007024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007025 public Rect getFrameLw() {
7026 return mFrame;
7027 }
7028
7029 public Rect getShownFrameLw() {
7030 return mShownFrame;
7031 }
7032
7033 public Rect getDisplayFrameLw() {
7034 return mDisplayFrame;
7035 }
7036
7037 public Rect getContentFrameLw() {
7038 return mContentFrame;
7039 }
7040
7041 public Rect getVisibleFrameLw() {
7042 return mVisibleFrame;
7043 }
7044
7045 public boolean getGivenInsetsPendingLw() {
7046 return mGivenInsetsPending;
7047 }
7048
7049 public Rect getGivenContentInsetsLw() {
7050 return mGivenContentInsets;
7051 }
Romain Guy06882f82009-06-10 13:36:04 -07007052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007053 public Rect getGivenVisibleInsetsLw() {
7054 return mGivenVisibleInsets;
7055 }
Romain Guy06882f82009-06-10 13:36:04 -07007056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 public WindowManager.LayoutParams getAttrs() {
7058 return mAttrs;
7059 }
7060
7061 public int getSurfaceLayer() {
7062 return mLayer;
7063 }
Romain Guy06882f82009-06-10 13:36:04 -07007064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007065 public IApplicationToken getAppToken() {
7066 return mAppToken != null ? mAppToken.appToken : null;
7067 }
Jeff Brown349703e2010-06-22 01:27:15 -07007068
7069 public long getInputDispatchingTimeoutNanos() {
7070 return mAppToken != null
7071 ? mAppToken.inputDispatchingTimeoutNanos
7072 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7073 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074
7075 public boolean hasAppShownWindows() {
7076 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7077 }
7078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007080 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007081 TAG, "Setting animation in " + this + ": " + anim);
7082 mAnimating = false;
7083 mLocalAnimating = false;
7084 mAnimation = anim;
7085 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7086 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7087 }
7088
7089 public void clearAnimation() {
7090 if (mAnimation != null) {
7091 mAnimating = true;
7092 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007093 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 mAnimation = null;
7095 }
7096 }
Romain Guy06882f82009-06-10 13:36:04 -07007097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007098 Surface createSurfaceLocked() {
7099 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007100 mReportDestroySurface = false;
7101 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007102 mDrawPending = true;
7103 mCommitDrawPending = false;
7104 mReadyToShow = false;
7105 if (mAppToken != null) {
7106 mAppToken.allDrawn = false;
7107 }
7108
7109 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007110
7111 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7112 flags |= Surface.SECURE;
7113 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007114 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 TAG, "Creating surface in session "
7116 + mSession.mSurfaceSession + " window " + this
7117 + " w=" + mFrame.width()
7118 + " h=" + mFrame.height() + " format="
7119 + mAttrs.format + " flags=" + flags);
7120
7121 int w = mFrame.width();
7122 int h = mFrame.height();
7123 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7124 // for a scaled surface, we always want the requested
7125 // size.
7126 w = mRequestedWidth;
7127 h = mRequestedHeight;
7128 }
7129
Romain Guy9825ec62009-10-01 00:58:09 -07007130 // Something is wrong and SurfaceFlinger will not like this,
7131 // try to revert to sane values
7132 if (w <= 0) w = 1;
7133 if (h <= 0) h = 1;
7134
Dianne Hackborn16064f92010-03-25 00:47:24 -07007135 mSurfaceShown = false;
7136 mSurfaceLayer = 0;
7137 mSurfaceAlpha = 1;
7138 mSurfaceX = 0;
7139 mSurfaceY = 0;
7140 mSurfaceW = w;
7141 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007142 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007143 final boolean isHwAccelerated = (mAttrs.flags &
7144 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7145 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7146 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7147 flags |= Surface.OPAQUE;
7148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007150 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007151 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007152 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007153 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007154 + mSurface + " IN SESSION "
7155 + mSession.mSurfaceSession
7156 + ": pid=" + mSession.mPid + " format="
7157 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007158 + Integer.toHexString(flags)
7159 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007160 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007161 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 reclaimSomeSurfaceMemoryLocked(this, "create");
7163 return null;
7164 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007165 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007166 return null;
7167 }
Romain Guy06882f82009-06-10 13:36:04 -07007168
Joe Onorato8a9b2202010-02-26 18:56:32 -08007169 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007170 TAG, "Got surface: " + mSurface
7171 + ", set left=" + mFrame.left + " top=" + mFrame.top
7172 + ", animLayer=" + mAnimLayer);
7173 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007174 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007175 if (SHOW_TRANSACTIONS) logSurface(this,
7176 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7177 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7178 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007179 }
7180 Surface.openTransaction();
7181 try {
7182 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007183 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007184 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007185 mSurface.setPosition(mSurfaceX, mSurfaceY);
7186 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007187 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007188 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007189 mSurface.hide();
7190 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007191 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 mSurface.setFlags(Surface.SURFACE_DITHER,
7193 Surface.SURFACE_DITHER);
7194 }
7195 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007196 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007197 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7198 }
7199 mLastHidden = true;
7200 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007201 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202 Surface.closeTransaction();
7203 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007204 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 TAG, "Created surface " + this);
7206 }
7207 return mSurface;
7208 }
Romain Guy06882f82009-06-10 13:36:04 -07007209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007211 if (mAppToken != null && this == mAppToken.startingWindow) {
7212 mAppToken.startingDisplayed = false;
7213 }
Romain Guy06882f82009-06-10 13:36:04 -07007214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007216 mDrawPending = false;
7217 mCommitDrawPending = false;
7218 mReadyToShow = false;
7219
7220 int i = mChildWindows.size();
7221 while (i > 0) {
7222 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007223 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007224 c.mAttachedHidden = true;
7225 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007226
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007227 if (mReportDestroySurface) {
7228 mReportDestroySurface = false;
7229 mSurfacePendingDestroy = true;
7230 try {
7231 mClient.dispatchGetNewSurface();
7232 // We'll really destroy on the next time around.
7233 return;
7234 } catch (RemoteException e) {
7235 }
7236 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007238 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007239 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007240 RuntimeException e = null;
7241 if (!HIDE_STACK_CRAWLS) {
7242 e = new RuntimeException();
7243 e.fillInStackTrace();
7244 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007245 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007246 + mSurface + ", session " + mSession, e);
7247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007249 RuntimeException e = null;
7250 if (!HIDE_STACK_CRAWLS) {
7251 e = new RuntimeException();
7252 e.fillInStackTrace();
7253 }
7254 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007256 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007257 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007258 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259 + " surface " + mSurface + " session " + mSession
7260 + ": " + e.toString());
7261 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007262
Dianne Hackborn16064f92010-03-25 00:47:24 -07007263 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007264 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007265 }
7266 }
7267
7268 boolean finishDrawingLocked() {
7269 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007270 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 TAG, "finishDrawingLocked: " + mSurface);
7272 mCommitDrawPending = true;
7273 mDrawPending = false;
7274 return true;
7275 }
7276 return false;
7277 }
7278
7279 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007280 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007281 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007282 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007283 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 }
7285 mCommitDrawPending = false;
7286 mReadyToShow = true;
7287 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7288 final AppWindowToken atoken = mAppToken;
7289 if (atoken == null || atoken.allDrawn || starting) {
7290 performShowLocked();
7291 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007292 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 }
7294
7295 // This must be called while inside a transaction.
7296 boolean performShowLocked() {
7297 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007298 RuntimeException e = null;
7299 if (!HIDE_STACK_CRAWLS) {
7300 e = new RuntimeException();
7301 e.fillInStackTrace();
7302 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007303 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7305 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7306 }
7307 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007308 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7309 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007310 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007311 + " during animation: policyVis=" + mPolicyVisibility
7312 + " attHidden=" + mAttachedHidden
7313 + " tok.hiddenRequested="
7314 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007315 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 + (mAppToken != null ? mAppToken.hidden : false)
7317 + " animating=" + mAnimating
7318 + " tok animating="
7319 + (mAppToken != null ? mAppToken.animating : false));
7320 if (!showSurfaceRobustlyLocked(this)) {
7321 return false;
7322 }
7323 mLastAlpha = -1;
7324 mHasDrawn = true;
7325 mLastHidden = false;
7326 mReadyToShow = false;
7327 enableScreenIfNeededLocked();
7328
7329 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 int i = mChildWindows.size();
7332 while (i > 0) {
7333 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007334 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007335 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007337 if (c.mSurface != null) {
7338 c.performShowLocked();
7339 // It hadn't been shown, which means layout not
7340 // performed on it, so now we want to make sure to
7341 // do a layout. If called from within the transaction
7342 // loop, this will cause it to restart with a new
7343 // layout.
7344 mLayoutNeeded = true;
7345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 }
7347 }
Romain Guy06882f82009-06-10 13:36:04 -07007348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007349 if (mAttrs.type != TYPE_APPLICATION_STARTING
7350 && mAppToken != null) {
7351 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007352
Dianne Hackborn248b1882009-09-16 16:46:44 -07007353 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007354 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007355 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007356 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007357 // If this initial window is animating, stop it -- we
7358 // will do an animation to reveal it from behind the
7359 // starting window, so there is no need for it to also
7360 // be doing its own stuff.
7361 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007362 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007363 mAnimation = null;
7364 // Make sure we clean up the animation.
7365 mAnimating = true;
7366 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007367 mFinishedStarting.add(mAppToken);
7368 mH.sendEmptyMessage(H.FINISHED_STARTING);
7369 }
7370 mAppToken.updateReportedVisibilityLocked();
7371 }
7372 }
7373 return true;
7374 }
Romain Guy06882f82009-06-10 13:36:04 -07007375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 // This must be called while inside a transaction. Returns true if
7377 // there is more animation to run.
7378 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007379 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007380 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7383 mHasTransformation = true;
7384 mHasLocalTransformation = true;
7385 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007386 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 TAG, "Starting animation in " + this +
7388 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7389 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7390 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7391 mAnimation.setStartTime(currentTime);
7392 mLocalAnimating = true;
7393 mAnimating = true;
7394 }
7395 mTransformation.clear();
7396 final boolean more = mAnimation.getTransformation(
7397 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007398 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 TAG, "Stepped animation in " + this +
7400 ": more=" + more + ", xform=" + mTransformation);
7401 if (more) {
7402 // we're not done!
7403 return true;
7404 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007405 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 TAG, "Finished animation in " + this +
7407 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007408
7409 if (mAnimation != null) {
7410 mAnimation.cancel();
7411 mAnimation = null;
7412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 //WindowManagerService.this.dump();
7414 }
7415 mHasLocalTransformation = false;
7416 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007417 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 // When our app token is animating, we kind-of pretend like
7419 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7420 // part of this check means that we will only do this if
7421 // our window is not currently exiting, or it is not
7422 // locally animating itself. The idea being that one that
7423 // is exiting and doing a local animation should be removed
7424 // once that animation is done.
7425 mAnimating = true;
7426 mHasTransformation = true;
7427 mTransformation.clear();
7428 return false;
7429 } else if (mHasTransformation) {
7430 // Little trick to get through the path below to act like
7431 // we have finished an animation.
7432 mAnimating = true;
7433 } else if (isAnimating()) {
7434 mAnimating = true;
7435 }
7436 } else if (mAnimation != null) {
7437 // If the display is frozen, and there is a pending animation,
7438 // clear it and make sure we run the cleanup code.
7439 mAnimating = true;
7440 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007441 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 mAnimation = null;
7443 }
Romain Guy06882f82009-06-10 13:36:04 -07007444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 if (!mAnimating && !mLocalAnimating) {
7446 return false;
7447 }
7448
Joe Onorato8a9b2202010-02-26 18:56:32 -08007449 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 TAG, "Animation done in " + this + ": exiting=" + mExiting
7451 + ", reportedVisible="
7452 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 mAnimating = false;
7455 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007456 if (mAnimation != null) {
7457 mAnimation.cancel();
7458 mAnimation = null;
7459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 mAnimLayer = mLayer;
7461 if (mIsImWindow) {
7462 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007463 } else if (mIsWallpaper) {
7464 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007465 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007466 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 + " anim layer: " + mAnimLayer);
7468 mHasTransformation = false;
7469 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007470 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7471 if (DEBUG_VISIBILITY) {
7472 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7473 + mPolicyVisibilityAfterAnim);
7474 }
7475 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7476 if (!mPolicyVisibility) {
7477 if (mCurrentFocus == this) {
7478 mFocusMayChange = true;
7479 }
7480 // Window is no longer visible -- make sure if we were waiting
7481 // for it to be displayed before enabling the display, that
7482 // we allow the display to be enabled now.
7483 enableScreenIfNeededLocked();
7484 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007485 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 mTransformation.clear();
7487 if (mHasDrawn
7488 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7489 && mAppToken != null
7490 && mAppToken.firstWindowDrawn
7491 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007492 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 + mToken + ": first real window done animating");
7494 mFinishedStarting.add(mAppToken);
7495 mH.sendEmptyMessage(H.FINISHED_STARTING);
7496 }
Romain Guy06882f82009-06-10 13:36:04 -07007497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 finishExit();
7499
7500 if (mAppToken != null) {
7501 mAppToken.updateReportedVisibilityLocked();
7502 }
7503
7504 return false;
7505 }
7506
7507 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007508 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007509 TAG, "finishExit in " + this
7510 + ": exiting=" + mExiting
7511 + " remove=" + mRemoveOnExit
7512 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007514 final int N = mChildWindows.size();
7515 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007516 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 }
Romain Guy06882f82009-06-10 13:36:04 -07007518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007519 if (!mExiting) {
7520 return;
7521 }
Romain Guy06882f82009-06-10 13:36:04 -07007522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007523 if (isWindowAnimating()) {
7524 return;
7525 }
7526
Joe Onorato8a9b2202010-02-26 18:56:32 -08007527 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007528 TAG, "Exit animation finished in " + this
7529 + ": remove=" + mRemoveOnExit);
7530 if (mSurface != null) {
7531 mDestroySurface.add(this);
7532 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007533 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007534 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007535 try {
7536 mSurface.hide();
7537 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007538 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007539 }
7540 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007541 }
7542 mExiting = false;
7543 if (mRemoveOnExit) {
7544 mPendingRemove.add(this);
7545 mRemoveOnExit = false;
7546 }
7547 }
Romain Guy06882f82009-06-10 13:36:04 -07007548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007549 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7550 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7551 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7552 if (dtdx < -.000001f || dtdx > .000001f) return false;
7553 if (dsdy < -.000001f || dsdy > .000001f) return false;
7554 return true;
7555 }
Romain Guy06882f82009-06-10 13:36:04 -07007556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 void computeShownFrameLocked() {
7558 final boolean selfTransformation = mHasLocalTransformation;
7559 Transformation attachedTransformation =
7560 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7561 ? mAttachedWindow.mTransformation : null;
7562 Transformation appTransformation =
7563 (mAppToken != null && mAppToken.hasTransformation)
7564 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007565
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007566 // Wallpapers are animated based on the "real" window they
7567 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007568 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007569 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007570 if (mWallpaperTarget.mHasLocalTransformation &&
7571 mWallpaperTarget.mAnimation != null &&
7572 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007573 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007574 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007575 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007576 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007577 }
7578 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007579 mWallpaperTarget.mAppToken.hasTransformation &&
7580 mWallpaperTarget.mAppToken.animation != null &&
7581 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007582 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007583 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007584 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007585 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007586 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007587 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007588
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007589 final boolean screenAnimation = mScreenRotationAnimation != null
7590 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007592 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007593 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 final Rect frame = mFrame;
7595 final float tmpFloats[] = mTmpFloats;
7596 final Matrix tmpMatrix = mTmpMatrix;
7597
7598 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007599 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007600 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007601 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007603 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007604 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007605 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007606 }
7607 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007608 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007610 if (screenAnimation) {
7611 tmpMatrix.postConcat(
7612 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614
7615 // "convert" it into SurfaceFlinger's format
7616 // (a 2x2 matrix + an offset)
7617 // Here we must not transform the position of the surface
7618 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007619 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007620
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007621 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 tmpMatrix.getValues(tmpFloats);
7623 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007624 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7625 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007627 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7628 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 int w = frame.width();
7630 int h = frame.height();
7631 mShownFrame.set(x, y, x+w, y+h);
7632
7633 // Now set the alpha... but because our current hardware
7634 // can't do alpha transformation on a non-opaque surface,
7635 // turn it off if we are running an animation that is also
7636 // transforming since it is more important to have that
7637 // animation be smooth.
7638 mShownAlpha = mAlpha;
7639 if (!mLimitedAlphaCompositing
7640 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7641 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7642 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007643 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007644 if (selfTransformation) {
7645 mShownAlpha *= mTransformation.getAlpha();
7646 }
7647 if (attachedTransformation != null) {
7648 mShownAlpha *= attachedTransformation.getAlpha();
7649 }
7650 if (appTransformation != null) {
7651 mShownAlpha *= appTransformation.getAlpha();
7652 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007653 if (screenAnimation) {
7654 mShownAlpha *=
7655 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007657 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007658 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 }
Romain Guy06882f82009-06-10 13:36:04 -07007660
Joe Onorato8a9b2202010-02-26 18:56:32 -08007661 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007662 TAG, "Continuing animation in " + this +
7663 ": " + mShownFrame +
7664 ", alpha=" + mTransformation.getAlpha());
7665 return;
7666 }
Romain Guy06882f82009-06-10 13:36:04 -07007667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007668 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007669 if (mXOffset != 0 || mYOffset != 0) {
7670 mShownFrame.offset(mXOffset, mYOffset);
7671 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007672 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007673 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007674 mDsDx = 1;
7675 mDtDx = 0;
7676 mDsDy = 0;
7677 mDtDy = 1;
7678 }
Romain Guy06882f82009-06-10 13:36:04 -07007679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007680 /**
7681 * Is this window visible? It is not visible if there is no
7682 * surface, or we are in the process of running an exit animation
7683 * that will remove the surface, or its app token has been hidden.
7684 */
7685 public boolean isVisibleLw() {
7686 final AppWindowToken atoken = mAppToken;
7687 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7688 && (atoken == null || !atoken.hiddenRequested)
7689 && !mExiting && !mDestroying;
7690 }
7691
7692 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007693 * Like {@link #isVisibleLw}, but also counts a window that is currently
7694 * "hidden" behind the keyguard as visible. This allows us to apply
7695 * things like window flags that impact the keyguard.
7696 * XXX I am starting to think we need to have ANOTHER visibility flag
7697 * for this "hidden behind keyguard" state rather than overloading
7698 * mPolicyVisibility. Ungh.
7699 */
7700 public boolean isVisibleOrBehindKeyguardLw() {
7701 final AppWindowToken atoken = mAppToken;
7702 return mSurface != null && !mAttachedHidden
7703 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007704 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007705 && !mExiting && !mDestroying;
7706 }
7707
7708 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007709 * Is this window visible, ignoring its app token? It is not visible
7710 * if there is no surface, or we are in the process of running an exit animation
7711 * that will remove the surface.
7712 */
7713 public boolean isWinVisibleLw() {
7714 final AppWindowToken atoken = mAppToken;
7715 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7716 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7717 && !mExiting && !mDestroying;
7718 }
7719
7720 /**
7721 * The same as isVisible(), but follows the current hidden state of
7722 * the associated app token, not the pending requested hidden state.
7723 */
7724 boolean isVisibleNow() {
7725 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007726 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007727 }
7728
7729 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007730 * Can this window possibly be a drag/drop target? The test here is
7731 * a combination of the above "visible now" with the check that the
7732 * Input Manager uses when discarding windows from input consideration.
7733 */
7734 boolean isPotentialDragTarget() {
7735 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7736 }
7737
7738 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007739 * Same as isVisible(), but we also count it as visible between the
7740 * call to IWindowSession.add() and the first relayout().
7741 */
7742 boolean isVisibleOrAdding() {
7743 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007744 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007745 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7746 && mPolicyVisibility && !mAttachedHidden
7747 && (atoken == null || !atoken.hiddenRequested)
7748 && !mExiting && !mDestroying;
7749 }
7750
7751 /**
7752 * Is this window currently on-screen? It is on-screen either if it
7753 * is visible or it is currently running an animation before no longer
7754 * being visible.
7755 */
7756 boolean isOnScreen() {
7757 final AppWindowToken atoken = mAppToken;
7758 if (atoken != null) {
7759 return mSurface != null && mPolicyVisibility && !mDestroying
7760 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007761 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007762 } else {
7763 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007764 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 }
7766 }
Romain Guy06882f82009-06-10 13:36:04 -07007767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007768 /**
7769 * Like isOnScreen(), but we don't return true if the window is part
7770 * of a transition that has not yet been started.
7771 */
7772 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007773 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007774 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007775 return false;
7776 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007778 final boolean animating = atoken != null
7779 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007780 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007781 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7782 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007783 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007784 }
7785
7786 /** Is the window or its container currently animating? */
7787 boolean isAnimating() {
7788 final WindowState attached = mAttachedWindow;
7789 final AppWindowToken atoken = mAppToken;
7790 return mAnimation != null
7791 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007792 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007793 (atoken.animation != null
7794 || atoken.inPendingTransaction));
7795 }
7796
7797 /** Is this window currently animating? */
7798 boolean isWindowAnimating() {
7799 return mAnimation != null;
7800 }
7801
7802 /**
7803 * Like isOnScreen, but returns false if the surface hasn't yet
7804 * been drawn.
7805 */
7806 public boolean isDisplayedLw() {
7807 final AppWindowToken atoken = mAppToken;
7808 return mSurface != null && mPolicyVisibility && !mDestroying
7809 && !mDrawPending && !mCommitDrawPending
7810 && ((!mAttachedHidden &&
7811 (atoken == null || !atoken.hiddenRequested))
7812 || mAnimating);
7813 }
7814
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007815 /**
7816 * Returns true if the window has a surface that it has drawn a
7817 * complete UI in to.
7818 */
7819 public boolean isDrawnLw() {
7820 final AppWindowToken atoken = mAppToken;
7821 return mSurface != null && !mDestroying
7822 && !mDrawPending && !mCommitDrawPending;
7823 }
7824
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007825 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007826 * Return true if the window is opaque and fully drawn. This indicates
7827 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007828 */
7829 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007830 return (mAttrs.format == PixelFormat.OPAQUE
7831 || mAttrs.type == TYPE_WALLPAPER)
7832 && mSurface != null && mAnimation == null
7833 && (mAppToken == null || mAppToken.animation == null)
7834 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007835 }
7836
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007837 /**
7838 * Return whether this window is wanting to have a translation
7839 * animation applied to it for an in-progress move. (Only makes
7840 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7841 */
7842 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007843 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007844 && (mFrame.top != mLastFrame.top
7845 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007846 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007847 && mPolicy.isScreenOn();
7848 }
7849
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007850 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7851 return
7852 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007853 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7854 // only if it's visible
7855 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007856 // and only if the application fills the compatible screen
7857 mFrame.left <= mCompatibleScreenFrame.left &&
7858 mFrame.top <= mCompatibleScreenFrame.top &&
7859 mFrame.right >= mCompatibleScreenFrame.right &&
7860 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007861 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007862 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007863 }
7864
7865 boolean isFullscreen(int screenWidth, int screenHeight) {
7866 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007867 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 }
7869
7870 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007871 disposeInputChannel();
7872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007873 if (mAttachedWindow != null) {
7874 mAttachedWindow.mChildWindows.remove(this);
7875 }
7876 destroySurfaceLocked();
7877 mSession.windowRemovedLocked();
7878 try {
7879 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7880 } catch (RuntimeException e) {
7881 // Ignore if it has already been removed (usually because
7882 // we are doing this as part of processing a death note.)
7883 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007884 }
7885
7886 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007887 if (mInputChannel != null) {
7888 mInputManager.unregisterInputChannel(mInputChannel);
7889
7890 mInputChannel.dispose();
7891 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007893 }
7894
7895 private class DeathRecipient implements IBinder.DeathRecipient {
7896 public void binderDied() {
7897 try {
7898 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007899 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007900 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 if (win != null) {
7902 removeWindowLocked(mSession, win);
7903 }
7904 }
7905 } catch (IllegalArgumentException ex) {
7906 // This will happen if the window has already been
7907 // removed.
7908 }
7909 }
7910 }
7911
7912 /** Returns true if this window desires key events. */
7913 public final boolean canReceiveKeys() {
7914 return isVisibleOrAdding()
7915 && (mViewVisibility == View.VISIBLE)
7916 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7917 }
7918
7919 public boolean hasDrawnLw() {
7920 return mHasDrawn;
7921 }
7922
7923 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007924 return showLw(doAnimation, true);
7925 }
7926
7927 boolean showLw(boolean doAnimation, boolean requestAnim) {
7928 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7929 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007930 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007931 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007932 if (doAnimation) {
7933 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7934 + mPolicyVisibility + " mAnimation=" + mAnimation);
7935 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7936 doAnimation = false;
7937 } else if (mPolicyVisibility && mAnimation == null) {
7938 // Check for the case where we are currently visible and
7939 // not animating; we do not want to do animation at such a
7940 // point to become visible when we already are.
7941 doAnimation = false;
7942 }
7943 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007944 mPolicyVisibility = true;
7945 mPolicyVisibilityAfterAnim = true;
7946 if (doAnimation) {
7947 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7948 }
7949 if (requestAnim) {
7950 requestAnimationLocked(0);
7951 }
7952 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007953 }
7954
7955 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007956 return hideLw(doAnimation, true);
7957 }
7958
7959 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007960 if (doAnimation) {
7961 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7962 doAnimation = false;
7963 }
7964 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007965 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7966 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007967 if (!current) {
7968 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007969 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007970 if (doAnimation) {
7971 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7972 if (mAnimation == null) {
7973 doAnimation = false;
7974 }
7975 }
7976 if (doAnimation) {
7977 mPolicyVisibilityAfterAnim = false;
7978 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007979 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007980 mPolicyVisibilityAfterAnim = false;
7981 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007982 // Window is no longer visible -- make sure if we were waiting
7983 // for it to be displayed before enabling the display, that
7984 // we allow the display to be enabled now.
7985 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007986 if (mCurrentFocus == this) {
7987 mFocusMayChange = true;
7988 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007989 }
7990 if (requestAnim) {
7991 requestAnimationLocked(0);
7992 }
7993 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007994 }
7995
7996 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007997 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7998 pw.print(" mClient="); pw.println(mClient.asBinder());
7999 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8000 if (mAttachedWindow != null || mLayoutAttached) {
8001 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8002 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8003 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008004 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8005 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8006 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008007 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8008 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008009 }
8010 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8011 pw.print(" mSubLayer="); pw.print(mSubLayer);
8012 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8013 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8014 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8015 pw.print("="); pw.print(mAnimLayer);
8016 pw.print(" mLastLayer="); pw.println(mLastLayer);
8017 if (mSurface != null) {
8018 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008019 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8020 pw.print(" layer="); pw.print(mSurfaceLayer);
8021 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8022 pw.print(" rect=("); pw.print(mSurfaceX);
8023 pw.print(","); pw.print(mSurfaceY);
8024 pw.print(") "); pw.print(mSurfaceW);
8025 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008026 }
8027 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8028 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8029 if (mAppToken != null) {
8030 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8031 }
8032 if (mTargetAppToken != null) {
8033 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8034 }
8035 pw.print(prefix); pw.print("mViewVisibility=0x");
8036 pw.print(Integer.toHexString(mViewVisibility));
8037 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008038 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8039 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008040 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8041 pw.print(prefix); pw.print("mPolicyVisibility=");
8042 pw.print(mPolicyVisibility);
8043 pw.print(" mPolicyVisibilityAfterAnim=");
8044 pw.print(mPolicyVisibilityAfterAnim);
8045 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8046 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008047 if (!mRelayoutCalled) {
8048 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8049 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008050 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008051 pw.print(" h="); pw.print(mRequestedHeight);
8052 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008053 if (mXOffset != 0 || mYOffset != 0) {
8054 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8055 pw.print(" y="); pw.println(mYOffset);
8056 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008057 pw.print(prefix); pw.print("mGivenContentInsets=");
8058 mGivenContentInsets.printShortString(pw);
8059 pw.print(" mGivenVisibleInsets=");
8060 mGivenVisibleInsets.printShortString(pw);
8061 pw.println();
8062 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8063 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8064 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8065 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008066 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008067 pw.print(prefix); pw.print("mShownFrame=");
8068 mShownFrame.printShortString(pw);
8069 pw.print(" last="); mLastShownFrame.printShortString(pw);
8070 pw.println();
8071 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8072 pw.print(" last="); mLastFrame.printShortString(pw);
8073 pw.println();
8074 pw.print(prefix); pw.print("mContainingFrame=");
8075 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008076 pw.print(" mParentFrame=");
8077 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008078 pw.print(" mDisplayFrame=");
8079 mDisplayFrame.printShortString(pw);
8080 pw.println();
8081 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8082 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8083 pw.println();
8084 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8085 pw.print(" last="); mLastContentInsets.printShortString(pw);
8086 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8087 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8088 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008089 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8090 || mAnimation != null) {
8091 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8092 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8093 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8094 pw.print(" mAnimation="); pw.println(mAnimation);
8095 }
8096 if (mHasTransformation || mHasLocalTransformation) {
8097 pw.print(prefix); pw.print("XForm: has=");
8098 pw.print(mHasTransformation);
8099 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8100 pw.print(" "); mTransformation.printShortString(pw);
8101 pw.println();
8102 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008103 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8104 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8105 pw.print(" mAlpha="); pw.print(mAlpha);
8106 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8107 }
8108 if (mHaveMatrix) {
8109 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8110 pw.print(" mDtDx="); pw.print(mDtDx);
8111 pw.print(" mDsDy="); pw.print(mDsDy);
8112 pw.print(" mDtDy="); pw.println(mDtDy);
8113 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008114 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8115 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8116 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8117 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8118 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8119 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8120 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8121 pw.print(" mDestroying="); pw.print(mDestroying);
8122 pw.print(" mRemoved="); pw.println(mRemoved);
8123 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008124 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008125 pw.print(prefix); pw.print("mOrientationChanging=");
8126 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008127 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8128 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008129 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008130 if (mHScale != 1 || mVScale != 1) {
8131 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8132 pw.print(" mVScale="); pw.println(mVScale);
8133 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008134 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008135 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8136 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8137 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008138 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8139 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8140 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008142 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008143
8144 String makeInputChannelName() {
8145 return Integer.toHexString(System.identityHashCode(this))
8146 + " " + mAttrs.getTitle();
8147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148
8149 @Override
8150 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008151 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8152 || mWasPaused != mToken.paused) {
8153 mLastTitle = mAttrs.getTitle();
8154 mWasPaused = mToken.paused;
8155 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8156 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8157 }
8158 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 }
8160 }
Romain Guy06882f82009-06-10 13:36:04 -07008161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 // -------------------------------------------------------------
8163 // Window Token State
8164 // -------------------------------------------------------------
8165
8166 class WindowToken {
8167 // The actual token.
8168 final IBinder token;
8169
8170 // The type of window this token is for, as per WindowManager.LayoutParams.
8171 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008173 // Set if this token was explicitly added by a client, so should
8174 // not be removed when all windows are removed.
8175 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008176
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008177 // For printing.
8178 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008180 // If this is an AppWindowToken, this is non-null.
8181 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008183 // All of the windows associated with this token.
8184 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8185
8186 // Is key dispatching paused for this token?
8187 boolean paused = false;
8188
8189 // Should this token's windows be hidden?
8190 boolean hidden;
8191
8192 // Temporary for finding which tokens no longer have visible windows.
8193 boolean hasVisible;
8194
Dianne Hackborna8f60182009-09-01 19:01:50 -07008195 // Set to true when this token is in a pending transaction where it
8196 // will be shown.
8197 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008198
Dianne Hackborna8f60182009-09-01 19:01:50 -07008199 // Set to true when this token is in a pending transaction where it
8200 // will be hidden.
8201 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008202
Dianne Hackborna8f60182009-09-01 19:01:50 -07008203 // Set to true when this token is in a pending transaction where its
8204 // windows will be put to the bottom of the list.
8205 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008206
Dianne Hackborna8f60182009-09-01 19:01:50 -07008207 // Set to true when this token is in a pending transaction where its
8208 // windows will be put to the top of the list.
8209 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008211 WindowToken(IBinder _token, int type, boolean _explicit) {
8212 token = _token;
8213 windowType = type;
8214 explicit = _explicit;
8215 }
8216
8217 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008218 pw.print(prefix); pw.print("token="); pw.println(token);
8219 pw.print(prefix); pw.print("windows="); pw.println(windows);
8220 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8221 pw.print(" hidden="); pw.print(hidden);
8222 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008223 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8224 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8225 pw.print(" waitingToHide="); pw.print(waitingToHide);
8226 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8227 pw.print(" sendingToTop="); pw.println(sendingToTop);
8228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008229 }
8230
8231 @Override
8232 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008233 if (stringName == null) {
8234 StringBuilder sb = new StringBuilder();
8235 sb.append("WindowToken{");
8236 sb.append(Integer.toHexString(System.identityHashCode(this)));
8237 sb.append(" token="); sb.append(token); sb.append('}');
8238 stringName = sb.toString();
8239 }
8240 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008241 }
8242 };
8243
8244 class AppWindowToken extends WindowToken {
8245 // Non-null only for application tokens.
8246 final IApplicationToken appToken;
8247
8248 // All of the windows and child windows that are included in this
8249 // application token. Note this list is NOT sorted!
8250 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8251
8252 int groupId = -1;
8253 boolean appFullscreen;
8254 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008255
8256 // The input dispatching timeout for this application token in nanoseconds.
8257 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008259 // These are used for determining when all windows associated with
8260 // an activity have been drawn, so they can be made visible together
8261 // at the same time.
8262 int lastTransactionSequence = mTransactionSequence-1;
8263 int numInterestingWindows;
8264 int numDrawnWindows;
8265 boolean inPendingTransaction;
8266 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 // Is this token going to be hidden in a little while? If so, it
8269 // won't be taken into account for setting the screen orientation.
8270 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008272 // Is this window's surface needed? This is almost like hidden, except
8273 // it will sometimes be true a little earlier: when the token has
8274 // been shown, but is still waiting for its app transition to execute
8275 // before making its windows shown.
8276 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008278 // Have we told the window clients to hide themselves?
8279 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008281 // Last visibility state we reported to the app token.
8282 boolean reportedVisible;
8283
8284 // Set to true when the token has been removed from the window mgr.
8285 boolean removed;
8286
8287 // Have we been asked to have this token keep the screen frozen?
8288 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008290 boolean animating;
8291 Animation animation;
8292 boolean hasTransformation;
8293 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008295 // Offset to the window of all layers in the token, for use by
8296 // AppWindowToken animations.
8297 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008299 // Information about an application starting window if displayed.
8300 StartingData startingData;
8301 WindowState startingWindow;
8302 View startingView;
8303 boolean startingDisplayed;
8304 boolean startingMoved;
8305 boolean firstWindowDrawn;
8306
8307 AppWindowToken(IApplicationToken _token) {
8308 super(_token.asBinder(),
8309 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8310 appWindowToken = this;
8311 appToken = _token;
8312 }
Romain Guy06882f82009-06-10 13:36:04 -07008313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008314 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008315 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316 TAG, "Setting animation in " + this + ": " + anim);
8317 animation = anim;
8318 animating = false;
8319 anim.restrictDuration(MAX_ANIMATION_DURATION);
8320 anim.scaleCurrentDuration(mTransitionAnimationScale);
8321 int zorder = anim.getZAdjustment();
8322 int adj = 0;
8323 if (zorder == Animation.ZORDER_TOP) {
8324 adj = TYPE_LAYER_OFFSET;
8325 } else if (zorder == Animation.ZORDER_BOTTOM) {
8326 adj = -TYPE_LAYER_OFFSET;
8327 }
Romain Guy06882f82009-06-10 13:36:04 -07008328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008329 if (animLayerAdjustment != adj) {
8330 animLayerAdjustment = adj;
8331 updateLayers();
8332 }
8333 }
Romain Guy06882f82009-06-10 13:36:04 -07008334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008335 public void setDummyAnimation() {
8336 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008337 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008338 TAG, "Setting dummy animation in " + this);
8339 animation = sDummyAnimation;
8340 }
8341 }
8342
8343 public void clearAnimation() {
8344 if (animation != null) {
8345 animation = null;
8346 animating = true;
8347 }
8348 }
Romain Guy06882f82009-06-10 13:36:04 -07008349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008350 void updateLayers() {
8351 final int N = allAppWindows.size();
8352 final int adj = animLayerAdjustment;
8353 for (int i=0; i<N; i++) {
8354 WindowState w = allAppWindows.get(i);
8355 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008356 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008357 + w.mAnimLayer);
8358 if (w == mInputMethodTarget) {
8359 setInputMethodAnimLayerAdjustment(adj);
8360 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008361 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008362 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008363 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008364 }
8365 }
Romain Guy06882f82009-06-10 13:36:04 -07008366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008367 void sendAppVisibilityToClients() {
8368 final int N = allAppWindows.size();
8369 for (int i=0; i<N; i++) {
8370 WindowState win = allAppWindows.get(i);
8371 if (win == startingWindow && clientHidden) {
8372 // Don't hide the starting window.
8373 continue;
8374 }
8375 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008376 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 "Setting visibility of " + win + ": " + (!clientHidden));
8378 win.mClient.dispatchAppVisibility(!clientHidden);
8379 } catch (RemoteException e) {
8380 }
8381 }
8382 }
Romain Guy06882f82009-06-10 13:36:04 -07008383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008384 void showAllWindowsLocked() {
8385 final int NW = allAppWindows.size();
8386 for (int i=0; i<NW; i++) {
8387 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008388 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008389 "performing show on: " + w);
8390 w.performShowLocked();
8391 }
8392 }
Romain Guy06882f82009-06-10 13:36:04 -07008393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008394 // This must be called while inside a transaction.
8395 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008396 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 if (animation == sDummyAnimation) {
8400 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008401 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008402 // when it is really time to animate, this will be set to
8403 // a real animation and the next call will execute normally.
8404 return false;
8405 }
Romain Guy06882f82009-06-10 13:36:04 -07008406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008407 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8408 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008409 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008410 TAG, "Starting animation in " + this +
8411 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8412 + " scale=" + mTransitionAnimationScale
8413 + " allDrawn=" + allDrawn + " animating=" + animating);
8414 animation.initialize(dw, dh, dw, dh);
8415 animation.setStartTime(currentTime);
8416 animating = true;
8417 }
8418 transformation.clear();
8419 final boolean more = animation.getTransformation(
8420 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008421 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008422 TAG, "Stepped animation in " + this +
8423 ": more=" + more + ", xform=" + transformation);
8424 if (more) {
8425 // we're done!
8426 hasTransformation = true;
8427 return true;
8428 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008429 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008430 TAG, "Finished animation in " + this +
8431 " @ " + currentTime);
8432 animation = null;
8433 }
8434 } else if (animation != null) {
8435 // If the display is frozen, and there is a pending animation,
8436 // clear it and make sure we run the cleanup code.
8437 animating = true;
8438 animation = null;
8439 }
8440
8441 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008443 if (!animating) {
8444 return false;
8445 }
8446
8447 clearAnimation();
8448 animating = false;
8449 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8450 moveInputMethodWindowsIfNeededLocked(true);
8451 }
Romain Guy06882f82009-06-10 13:36:04 -07008452
Joe Onorato8a9b2202010-02-26 18:56:32 -08008453 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008454 TAG, "Animation done in " + this
8455 + ": reportedVisible=" + reportedVisible);
8456
8457 transformation.clear();
8458 if (animLayerAdjustment != 0) {
8459 animLayerAdjustment = 0;
8460 updateLayers();
8461 }
Romain Guy06882f82009-06-10 13:36:04 -07008462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008463 final int N = windows.size();
8464 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008465 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 }
8467 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 return false;
8470 }
8471
8472 void updateReportedVisibilityLocked() {
8473 if (appToken == null) {
8474 return;
8475 }
Romain Guy06882f82009-06-10 13:36:04 -07008476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008477 int numInteresting = 0;
8478 int numVisible = 0;
8479 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008480
Joe Onorato8a9b2202010-02-26 18:56:32 -08008481 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008482 final int N = allAppWindows.size();
8483 for (int i=0; i<N; i++) {
8484 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008485 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008486 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008487 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8488 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008489 continue;
8490 }
8491 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008492 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008493 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008495 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008496 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008497 + " pv=" + win.mPolicyVisibility
8498 + " dp=" + win.mDrawPending
8499 + " cdp=" + win.mCommitDrawPending
8500 + " ah=" + win.mAttachedHidden
8501 + " th="
8502 + (win.mAppToken != null
8503 ? win.mAppToken.hiddenRequested : false)
8504 + " a=" + win.mAnimating);
8505 }
8506 }
8507 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008508 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008509 if (!win.isAnimating()) {
8510 numVisible++;
8511 }
8512 nowGone = false;
8513 } else if (win.isAnimating()) {
8514 nowGone = false;
8515 }
8516 }
Romain Guy06882f82009-06-10 13:36:04 -07008517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008519 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008520 + numInteresting + " visible=" + numVisible);
8521 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008522 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 TAG, "Visibility changed in " + this
8524 + ": vis=" + nowVisible);
8525 reportedVisible = nowVisible;
8526 Message m = mH.obtainMessage(
8527 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8528 nowVisible ? 1 : 0,
8529 nowGone ? 1 : 0,
8530 this);
8531 mH.sendMessage(m);
8532 }
8533 }
Romain Guy06882f82009-06-10 13:36:04 -07008534
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008535 WindowState findMainWindow() {
8536 int j = windows.size();
8537 while (j > 0) {
8538 j--;
8539 WindowState win = windows.get(j);
8540 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8541 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8542 return win;
8543 }
8544 }
8545 return null;
8546 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 void dump(PrintWriter pw, String prefix) {
8549 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008550 if (appToken != null) {
8551 pw.print(prefix); pw.println("app=true");
8552 }
8553 if (allAppWindows.size() > 0) {
8554 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8555 }
8556 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008557 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008558 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8559 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8560 pw.print(" clientHidden="); pw.print(clientHidden);
8561 pw.print(" willBeHidden="); pw.print(willBeHidden);
8562 pw.print(" reportedVisible="); pw.println(reportedVisible);
8563 if (paused || freezingScreen) {
8564 pw.print(prefix); pw.print("paused="); pw.print(paused);
8565 pw.print(" freezingScreen="); pw.println(freezingScreen);
8566 }
8567 if (numInterestingWindows != 0 || numDrawnWindows != 0
8568 || inPendingTransaction || allDrawn) {
8569 pw.print(prefix); pw.print("numInterestingWindows=");
8570 pw.print(numInterestingWindows);
8571 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8572 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8573 pw.print(" allDrawn="); pw.println(allDrawn);
8574 }
8575 if (animating || animation != null) {
8576 pw.print(prefix); pw.print("animating="); pw.print(animating);
8577 pw.print(" animation="); pw.println(animation);
8578 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008579 if (hasTransformation) {
8580 pw.print(prefix); pw.print("XForm: ");
8581 transformation.printShortString(pw);
8582 pw.println();
8583 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008584 if (animLayerAdjustment != 0) {
8585 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8586 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008587 if (startingData != null || removed || firstWindowDrawn) {
8588 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8589 pw.print(" removed="); pw.print(removed);
8590 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8591 }
8592 if (startingWindow != null || startingView != null
8593 || startingDisplayed || startingMoved) {
8594 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8595 pw.print(" startingView="); pw.print(startingView);
8596 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8597 pw.print(" startingMoved"); pw.println(startingMoved);
8598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 }
8600
8601 @Override
8602 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008603 if (stringName == null) {
8604 StringBuilder sb = new StringBuilder();
8605 sb.append("AppWindowToken{");
8606 sb.append(Integer.toHexString(System.identityHashCode(this)));
8607 sb.append(" token="); sb.append(token); sb.append('}');
8608 stringName = sb.toString();
8609 }
8610 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 }
8612 }
Romain Guy06882f82009-06-10 13:36:04 -07008613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008614 // -------------------------------------------------------------
8615 // DummyAnimation
8616 // -------------------------------------------------------------
8617
8618 // This is an animation that does nothing: it just immediately finishes
8619 // itself every time it is called. It is used as a stub animation in cases
8620 // where we want to synchronize multiple things that may be animating.
8621 static final class DummyAnimation extends Animation {
8622 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8623 return false;
8624 }
8625 }
8626 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 // -------------------------------------------------------------
8629 // Async Handler
8630 // -------------------------------------------------------------
8631
8632 static final class StartingData {
8633 final String pkg;
8634 final int theme;
8635 final CharSequence nonLocalizedLabel;
8636 final int labelRes;
8637 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008638 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008641 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008642 pkg = _pkg;
8643 theme = _theme;
8644 nonLocalizedLabel = _nonLocalizedLabel;
8645 labelRes = _labelRes;
8646 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008647 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 }
8649 }
8650
8651 private final class H extends Handler {
8652 public static final int REPORT_FOCUS_CHANGE = 2;
8653 public static final int REPORT_LOSING_FOCUS = 3;
8654 public static final int ANIMATE = 4;
8655 public static final int ADD_STARTING = 5;
8656 public static final int REMOVE_STARTING = 6;
8657 public static final int FINISHED_STARTING = 7;
8658 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8660 public static final int HOLD_SCREEN_CHANGED = 12;
8661 public static final int APP_TRANSITION_TIMEOUT = 13;
8662 public static final int PERSIST_ANIMATION_SCALE = 14;
8663 public static final int FORCE_GC = 15;
8664 public static final int ENABLE_SCREEN = 16;
8665 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008666 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008667 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008668 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008669 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 public H() {
8674 }
Romain Guy06882f82009-06-10 13:36:04 -07008675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008676 @Override
8677 public void handleMessage(Message msg) {
8678 switch (msg.what) {
8679 case REPORT_FOCUS_CHANGE: {
8680 WindowState lastFocus;
8681 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 synchronized(mWindowMap) {
8684 lastFocus = mLastFocus;
8685 newFocus = mCurrentFocus;
8686 if (lastFocus == newFocus) {
8687 // Focus is not changing, so nothing to do.
8688 return;
8689 }
8690 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008691 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008692 // + " to " + newFocus);
8693 if (newFocus != null && lastFocus != null
8694 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008695 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 mLosingFocus.add(lastFocus);
8697 lastFocus = null;
8698 }
8699 }
8700
8701 if (lastFocus != newFocus) {
8702 //System.out.println("Changing focus from " + lastFocus
8703 // + " to " + newFocus);
8704 if (newFocus != null) {
8705 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008706 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008707 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8708 } catch (RemoteException e) {
8709 // Ignore if process has died.
8710 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008711 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008712 }
8713
8714 if (lastFocus != null) {
8715 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008716 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008717 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8718 } catch (RemoteException e) {
8719 // Ignore if process has died.
8720 }
8721 }
8722 }
8723 } break;
8724
8725 case REPORT_LOSING_FOCUS: {
8726 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 synchronized(mWindowMap) {
8729 losers = mLosingFocus;
8730 mLosingFocus = new ArrayList<WindowState>();
8731 }
8732
8733 final int N = losers.size();
8734 for (int i=0; i<N; i++) {
8735 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008736 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8738 } catch (RemoteException e) {
8739 // Ignore if process has died.
8740 }
8741 }
8742 } break;
8743
8744 case ANIMATE: {
8745 synchronized(mWindowMap) {
8746 mAnimationPending = false;
8747 performLayoutAndPlaceSurfacesLocked();
8748 }
8749 } break;
8750
8751 case ADD_STARTING: {
8752 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8753 final StartingData sd = wtoken.startingData;
8754
8755 if (sd == null) {
8756 // Animation has been canceled... do nothing.
8757 return;
8758 }
Romain Guy06882f82009-06-10 13:36:04 -07008759
Joe Onorato8a9b2202010-02-26 18:56:32 -08008760 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008761 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008763 View view = null;
8764 try {
8765 view = mPolicy.addStartingWindow(
8766 wtoken.token, sd.pkg,
8767 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008768 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008769 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008770 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008771 }
8772
8773 if (view != null) {
8774 boolean abort = false;
8775
8776 synchronized(mWindowMap) {
8777 if (wtoken.removed || wtoken.startingData == null) {
8778 // If the window was successfully added, then
8779 // we need to remove it.
8780 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008781 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008782 "Aborted starting " + wtoken
8783 + ": removed=" + wtoken.removed
8784 + " startingData=" + wtoken.startingData);
8785 wtoken.startingWindow = null;
8786 wtoken.startingData = null;
8787 abort = true;
8788 }
8789 } else {
8790 wtoken.startingView = view;
8791 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008792 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008793 "Added starting " + wtoken
8794 + ": startingWindow="
8795 + wtoken.startingWindow + " startingView="
8796 + wtoken.startingView);
8797 }
8798
8799 if (abort) {
8800 try {
8801 mPolicy.removeStartingWindow(wtoken.token, view);
8802 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008803 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 }
8805 }
8806 }
8807 } break;
8808
8809 case REMOVE_STARTING: {
8810 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8811 IBinder token = null;
8812 View view = null;
8813 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008814 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008815 + wtoken + ": startingWindow="
8816 + wtoken.startingWindow + " startingView="
8817 + wtoken.startingView);
8818 if (wtoken.startingWindow != null) {
8819 view = wtoken.startingView;
8820 token = wtoken.token;
8821 wtoken.startingData = null;
8822 wtoken.startingView = null;
8823 wtoken.startingWindow = null;
8824 }
8825 }
8826 if (view != null) {
8827 try {
8828 mPolicy.removeStartingWindow(token, view);
8829 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008830 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008831 }
8832 }
8833 } break;
8834
8835 case FINISHED_STARTING: {
8836 IBinder token = null;
8837 View view = null;
8838 while (true) {
8839 synchronized (mWindowMap) {
8840 final int N = mFinishedStarting.size();
8841 if (N <= 0) {
8842 break;
8843 }
8844 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8845
Joe Onorato8a9b2202010-02-26 18:56:32 -08008846 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008847 "Finished starting " + wtoken
8848 + ": startingWindow=" + wtoken.startingWindow
8849 + " startingView=" + wtoken.startingView);
8850
8851 if (wtoken.startingWindow == null) {
8852 continue;
8853 }
8854
8855 view = wtoken.startingView;
8856 token = wtoken.token;
8857 wtoken.startingData = null;
8858 wtoken.startingView = null;
8859 wtoken.startingWindow = null;
8860 }
8861
8862 try {
8863 mPolicy.removeStartingWindow(token, view);
8864 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008865 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866 }
8867 }
8868 } break;
8869
8870 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8871 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8872
8873 boolean nowVisible = msg.arg1 != 0;
8874 boolean nowGone = msg.arg2 != 0;
8875
8876 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008877 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008878 TAG, "Reporting visible in " + wtoken
8879 + " visible=" + nowVisible
8880 + " gone=" + nowGone);
8881 if (nowVisible) {
8882 wtoken.appToken.windowsVisible();
8883 } else {
8884 wtoken.appToken.windowsGone();
8885 }
8886 } catch (RemoteException ex) {
8887 }
8888 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 case WINDOW_FREEZE_TIMEOUT: {
8891 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008892 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008893 int i = mWindows.size();
8894 while (i > 0) {
8895 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008896 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008897 if (w.mOrientationChanging) {
8898 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008899 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 }
8901 }
8902 performLayoutAndPlaceSurfacesLocked();
8903 }
8904 break;
8905 }
Romain Guy06882f82009-06-10 13:36:04 -07008906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008907 case HOLD_SCREEN_CHANGED: {
8908 Session oldHold;
8909 Session newHold;
8910 synchronized (mWindowMap) {
8911 oldHold = mLastReportedHold;
8912 newHold = (Session)msg.obj;
8913 mLastReportedHold = newHold;
8914 }
Romain Guy06882f82009-06-10 13:36:04 -07008915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008916 if (oldHold != newHold) {
8917 try {
8918 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008919 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008920 "window",
8921 BatteryStats.WAKE_TYPE_WINDOW);
8922 }
8923 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008924 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008925 "window",
8926 BatteryStats.WAKE_TYPE_WINDOW);
8927 }
8928 } catch (RemoteException e) {
8929 }
8930 }
8931 break;
8932 }
Romain Guy06882f82009-06-10 13:36:04 -07008933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008934 case APP_TRANSITION_TIMEOUT: {
8935 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008936 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008937 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008938 "*** APP TRANSITION TIMEOUT");
8939 mAppTransitionReady = true;
8940 mAppTransitionTimeout = true;
8941 performLayoutAndPlaceSurfacesLocked();
8942 }
8943 }
8944 break;
8945 }
Romain Guy06882f82009-06-10 13:36:04 -07008946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008947 case PERSIST_ANIMATION_SCALE: {
8948 Settings.System.putFloat(mContext.getContentResolver(),
8949 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8950 Settings.System.putFloat(mContext.getContentResolver(),
8951 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8952 break;
8953 }
Romain Guy06882f82009-06-10 13:36:04 -07008954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008955 case FORCE_GC: {
8956 synchronized(mWindowMap) {
8957 if (mAnimationPending) {
8958 // If we are animating, don't do the gc now but
8959 // delay a bit so we don't interrupt the animation.
8960 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8961 2000);
8962 return;
8963 }
8964 // If we are currently rotating the display, it will
8965 // schedule a new message when done.
8966 if (mDisplayFrozen) {
8967 return;
8968 }
8969 mFreezeGcPending = 0;
8970 }
8971 Runtime.getRuntime().gc();
8972 break;
8973 }
Romain Guy06882f82009-06-10 13:36:04 -07008974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008975 case ENABLE_SCREEN: {
8976 performEnableScreen();
8977 break;
8978 }
Romain Guy06882f82009-06-10 13:36:04 -07008979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008980 case APP_FREEZE_TIMEOUT: {
8981 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008982 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008983 int i = mAppTokens.size();
8984 while (i > 0) {
8985 i--;
8986 AppWindowToken tok = mAppTokens.get(i);
8987 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008988 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008989 unsetAppFreezingScreenLocked(tok, true, true);
8990 }
8991 }
8992 }
8993 break;
8994 }
Romain Guy06882f82009-06-10 13:36:04 -07008995
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008996 case SEND_NEW_CONFIGURATION: {
8997 removeMessages(SEND_NEW_CONFIGURATION);
8998 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008999 break;
9000 }
Romain Guy06882f82009-06-10 13:36:04 -07009001
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009002 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009003 if (mWindowsChanged) {
9004 synchronized (mWindowMap) {
9005 mWindowsChanged = false;
9006 }
9007 notifyWindowsChanged();
9008 }
9009 break;
9010 }
9011
Christopher Tatea53146c2010-09-07 11:57:52 -07009012 case DRAG_START_TIMEOUT: {
9013 IBinder win = (IBinder)msg.obj;
9014 if (DEBUG_DRAG) {
9015 Slog.w(TAG, "Timeout starting drag by win " + win);
9016 }
9017 synchronized (mWindowMap) {
9018 // !!! TODO: ANR the app that has failed to start the drag in time
9019 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009020 mDragState.unregister();
9021 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009022 mDragState.reset();
9023 mDragState = null;
9024 }
9025 }
Chris Tated4533f142010-10-19 15:15:08 -07009026 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009027 }
9028
Chris Tated4533f142010-10-19 15:15:08 -07009029 case DRAG_END_TIMEOUT: {
9030 IBinder win = (IBinder)msg.obj;
9031 if (DEBUG_DRAG) {
9032 Slog.w(TAG, "Timeout ending drag to win " + win);
9033 }
9034 synchronized (mWindowMap) {
9035 // !!! TODO: ANR the drag-receiving app
9036 mDragState.mDragResult = false;
9037 mDragState.endDragLw();
9038 }
9039 break;
9040 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009041 }
9042 }
9043 }
9044
9045 // -------------------------------------------------------------
9046 // IWindowManager API
9047 // -------------------------------------------------------------
9048
9049 public IWindowSession openSession(IInputMethodClient client,
9050 IInputContext inputContext) {
9051 if (client == null) throw new IllegalArgumentException("null client");
9052 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009053 Session session = new Session(client, inputContext);
9054 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009055 }
9056
9057 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9058 synchronized (mWindowMap) {
9059 // The focus for the client is the window immediately below
9060 // where we would place the input method window.
9061 int idx = findDesiredInputMethodWindowIndexLocked(false);
9062 WindowState imFocus;
9063 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009064 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009065 if (imFocus != null) {
9066 if (imFocus.mSession.mClient != null &&
9067 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9068 return true;
9069 }
9070 }
9071 }
9072 }
9073 return false;
9074 }
Romain Guy06882f82009-06-10 13:36:04 -07009075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009076 // -------------------------------------------------------------
9077 // Internals
9078 // -------------------------------------------------------------
9079
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009080 final WindowState windowForClientLocked(Session session, IWindow client,
9081 boolean throwOnError) {
9082 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009083 }
Romain Guy06882f82009-06-10 13:36:04 -07009084
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009085 final WindowState windowForClientLocked(Session session, IBinder client,
9086 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009087 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009088 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009089 TAG, "Looking up client " + client + ": " + win);
9090 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009091 RuntimeException ex = new IllegalArgumentException(
9092 "Requested window " + client + " does not exist");
9093 if (throwOnError) {
9094 throw ex;
9095 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009096 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009097 return null;
9098 }
9099 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009100 RuntimeException ex = new IllegalArgumentException(
9101 "Requested window " + client + " is in session " +
9102 win.mSession + ", not " + session);
9103 if (throwOnError) {
9104 throw ex;
9105 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009106 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009107 return null;
9108 }
9109
9110 return win;
9111 }
9112
Dianne Hackborna8f60182009-09-01 19:01:50 -07009113 final void rebuildAppWindowListLocked() {
9114 int NW = mWindows.size();
9115 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009116 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009117 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009118
Dianne Hackborna8f60182009-09-01 19:01:50 -07009119 // First remove all existing app windows.
9120 i=0;
9121 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009122 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009123 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009124 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009125 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009126 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009127 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009128 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009129 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009130 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009131 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9132 && lastWallpaper == i-1) {
9133 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009134 }
9135 i++;
9136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009137
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009138 // The wallpaper window(s) typically live at the bottom of the stack,
9139 // so skip them before adding app tokens.
9140 lastWallpaper++;
9141 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009142
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009143 // First add all of the exiting app tokens... these are no longer
9144 // in the main app list, but still have windows shown. We put them
9145 // in the back because now that the animation is over we no longer
9146 // will care about them.
9147 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009148 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009149 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9150 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009151
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009152 // And add in the still active app tokens in Z order.
9153 NT = mAppTokens.size();
9154 for (int j=0; j<NT; j++) {
9155 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009157
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009158 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009159 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009160 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009161 + " windows but added " + i);
9162 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009163 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009165 private final void assignLayersLocked() {
9166 int N = mWindows.size();
9167 int curBaseLayer = 0;
9168 int curLayer = 0;
9169 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009170
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009171 if (DEBUG_LAYERS) {
9172 RuntimeException here = new RuntimeException("here");
9173 here.fillInStackTrace();
9174 Log.v(TAG, "Assigning layers", here);
9175 }
9176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009177 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009178 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009179 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9180 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009181 curLayer += WINDOW_LAYER_MULTIPLIER;
9182 w.mLayer = curLayer;
9183 } else {
9184 curBaseLayer = curLayer = w.mBaseLayer;
9185 w.mLayer = curLayer;
9186 }
9187 if (w.mTargetAppToken != null) {
9188 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9189 } else if (w.mAppToken != null) {
9190 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9191 } else {
9192 w.mAnimLayer = w.mLayer;
9193 }
9194 if (w.mIsImWindow) {
9195 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009196 } else if (w.mIsWallpaper) {
9197 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009198 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009199 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009200 + w.mAnimLayer);
9201 //System.out.println(
9202 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9203 }
9204 }
9205
9206 private boolean mInLayout = false;
9207 private final void performLayoutAndPlaceSurfacesLocked() {
9208 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009209 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009210 throw new RuntimeException("Recursive call!");
9211 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009212 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009213 return;
9214 }
9215
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009216 if (mWaitingForConfig) {
9217 // Our configuration has changed (most likely rotation), but we
9218 // don't yet have the complete configuration to report to
9219 // applications. Don't do any window layout until we have it.
9220 return;
9221 }
9222
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009223 if (mDisplay == null) {
9224 // Not yet initialized, nothing to do.
9225 return;
9226 }
9227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009228 boolean recoveringMemory = false;
9229 if (mForceRemoves != null) {
9230 recoveringMemory = true;
9231 // Wait a little it for things to settle down, and off we go.
9232 for (int i=0; i<mForceRemoves.size(); i++) {
9233 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009234 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009235 removeWindowInnerLocked(ws.mSession, ws);
9236 }
9237 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009238 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009239 Object tmp = new Object();
9240 synchronized (tmp) {
9241 try {
9242 tmp.wait(250);
9243 } catch (InterruptedException e) {
9244 }
9245 }
9246 }
Romain Guy06882f82009-06-10 13:36:04 -07009247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009248 mInLayout = true;
9249 try {
9250 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009252 int i = mPendingRemove.size()-1;
9253 if (i >= 0) {
9254 while (i >= 0) {
9255 WindowState w = mPendingRemove.get(i);
9256 removeWindowInnerLocked(w.mSession, w);
9257 i--;
9258 }
9259 mPendingRemove.clear();
9260
9261 mInLayout = false;
9262 assignLayersLocked();
9263 mLayoutNeeded = true;
9264 performLayoutAndPlaceSurfacesLocked();
9265
9266 } else {
9267 mInLayout = false;
9268 if (mLayoutNeeded) {
9269 requestAnimationLocked(0);
9270 }
9271 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009272 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009273 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9274 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009276 } catch (RuntimeException e) {
9277 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009278 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009279 }
9280 }
9281
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009282 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009283 if (!mLayoutNeeded) {
9284 return 0;
9285 }
9286
9287 mLayoutNeeded = false;
9288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009289 final int dw = mDisplay.getWidth();
9290 final int dh = mDisplay.getHeight();
9291
9292 final int N = mWindows.size();
9293 int i;
9294
Joe Onorato8a9b2202010-02-26 18:56:32 -08009295 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009296 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9297
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009298 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009299
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009300 int seq = mLayoutSeq+1;
9301 if (seq < 0) seq = 0;
9302 mLayoutSeq = seq;
9303
9304 // First perform layout of any root windows (not attached
9305 // to another window).
9306 int topAttached = -1;
9307 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009308 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009309
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009310 // Don't do layout of a window if it is not visible, or
9311 // soon won't be visible, to avoid wasting time and funky
9312 // changes while a window is animating away.
9313 final AppWindowToken atoken = win.mAppToken;
9314 final boolean gone = win.mViewVisibility == View.GONE
9315 || !win.mRelayoutCalled
9316 || win.mRootToken.hidden
9317 || (atoken != null && atoken.hiddenRequested)
9318 || win.mAttachedHidden
9319 || win.mExiting || win.mDestroying;
9320
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009321 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9322 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009323 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9324 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009325 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009326 + win.mViewVisibility + " mRelayoutCalled="
9327 + win.mRelayoutCalled + " hidden="
9328 + win.mRootToken.hidden + " hiddenRequested="
9329 + (atoken != null && atoken.hiddenRequested)
9330 + " mAttachedHidden=" + win.mAttachedHidden);
9331 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009332
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009333 // If this view is GONE, then skip it -- keep the current
9334 // frame, and let the caller know so they can ignore it
9335 // if they want. (We do the normal layout for INVISIBLE
9336 // windows, since that means "perform layout as normal,
9337 // just don't display").
9338 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009339 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009340 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009341 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009342 win.mContentChanged = false;
9343 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009344 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9345 win.mLayoutSeq = seq;
9346 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9347 + win.mFrame + " mContainingFrame="
9348 + win.mContainingFrame + " mDisplayFrame="
9349 + win.mDisplayFrame);
9350 } else {
9351 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009352 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009355
9356 // Now perform layout of attached windows, which usually
9357 // depend on the position of the window they are attached to.
9358 // XXX does not deal with windows that are attached to windows
9359 // that are themselves attached.
9360 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009361 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009362
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009363 if (win.mLayoutAttached) {
9364 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9365 + " mHaveFrame=" + win.mHaveFrame
9366 + " mViewVisibility=" + win.mViewVisibility
9367 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009368 // If this view is GONE, then skip it -- keep the current
9369 // frame, and let the caller know so they can ignore it
9370 // if they want. (We do the normal layout for INVISIBLE
9371 // windows, since that means "perform layout as normal,
9372 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009373 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9374 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009375 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009376 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009377 win.mContentChanged = false;
9378 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009379 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9380 win.mLayoutSeq = seq;
9381 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9382 + win.mFrame + " mContainingFrame="
9383 + win.mContainingFrame + " mDisplayFrame="
9384 + win.mDisplayFrame);
9385 }
9386 }
9387 }
Jeff Brown349703e2010-06-22 01:27:15 -07009388
9389 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009390 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009391
9392 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393 }
Romain Guy06882f82009-06-10 13:36:04 -07009394
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009395 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009396 private final void performLayoutAndPlaceSurfacesLockedInner(
9397 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009398 if (mDisplay == null) {
9399 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9400 return;
9401 }
9402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009403 final long currentTime = SystemClock.uptimeMillis();
9404 final int dw = mDisplay.getWidth();
9405 final int dh = mDisplay.getHeight();
9406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 int i;
9408
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009409 if (mFocusMayChange) {
9410 mFocusMayChange = false;
9411 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9412 }
9413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009414 // Initialize state of exiting tokens.
9415 for (i=mExitingTokens.size()-1; i>=0; i--) {
9416 mExitingTokens.get(i).hasVisible = false;
9417 }
9418
9419 // Initialize state of exiting applications.
9420 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9421 mExitingAppTokens.get(i).hasVisible = false;
9422 }
9423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009424 boolean orientationChangeComplete = true;
9425 Session holdScreen = null;
9426 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009427 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009428 boolean focusDisplayed = false;
9429 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009430 boolean createWatermark = false;
9431
9432 if (mFxSession == null) {
9433 mFxSession = new SurfaceSession();
9434 createWatermark = true;
9435 }
9436
9437 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009438
9439 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009440
9441 if (createWatermark) {
9442 createWatermark();
9443 }
9444 if (mWatermark != null) {
9445 mWatermark.positionSurface(dw, dh);
9446 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009447 if (mStrictModeFlash != null) {
9448 mStrictModeFlash.positionSurface(dw, dh);
9449 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009451 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009452 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009453 int repeats = 0;
9454 int changes = 0;
9455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009456 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009457 repeats++;
9458 if (repeats > 6) {
9459 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9460 mLayoutNeeded = false;
9461 break;
9462 }
9463
9464 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9465 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9466 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9467 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9468 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9469 assignLayersLocked();
9470 mLayoutNeeded = true;
9471 }
9472 }
9473 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9474 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9475 if (updateOrientationFromAppTokensLocked()) {
9476 mLayoutNeeded = true;
9477 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9478 }
9479 }
9480 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9481 mLayoutNeeded = true;
9482 }
9483 }
9484
9485 // FIRST LOOP: Perform a layout, if needed.
9486 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009487 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009488 if (changes != 0) {
9489 continue;
9490 }
9491 } else {
9492 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9493 changes = 0;
9494 }
9495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009496 final int transactionSequence = ++mTransactionSequence;
9497
9498 // Update animations of all applications, including those
9499 // associated with exiting/removed apps
9500 boolean tokensAnimating = false;
9501 final int NAT = mAppTokens.size();
9502 for (i=0; i<NAT; i++) {
9503 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9504 tokensAnimating = true;
9505 }
9506 }
9507 final int NEAT = mExitingAppTokens.size();
9508 for (i=0; i<NEAT; i++) {
9509 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9510 tokensAnimating = true;
9511 }
9512 }
9513
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009514 // SECOND LOOP: Execute animations and update visibility of windows.
9515
Joe Onorato8a9b2202010-02-26 18:56:32 -08009516 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009517 + transactionSequence + " tokensAnimating="
9518 + tokensAnimating);
9519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009520 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009521
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009522 if (mScreenRotationAnimation != null) {
9523 if (mScreenRotationAnimation.isAnimating()) {
9524 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9525 animating = true;
9526 } else {
9527 mScreenRotationAnimation = null;
9528 }
9529 }
9530 }
9531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009532 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009533 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009534 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009535 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009536
9537 mPolicy.beginAnimationLw(dw, dh);
9538
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009539 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009541 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009542 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009543
9544 final WindowManager.LayoutParams attrs = w.mAttrs;
9545
9546 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009547 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009548 if (w.commitFinishDrawingLocked(currentTime)) {
9549 if ((w.mAttrs.flags
9550 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009551 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009552 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009553 wallpaperMayChange = true;
9554 }
9555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009556
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009557 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009558
9559 int animDw = dw;
9560 int animDh = dh;
9561
9562 // If the window has moved due to its containing
9563 // content frame changing, then we'd like to animate
9564 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009565 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009566 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009567 // Frame has moved, containing content frame
9568 // has also moved, and we're not currently animating...
9569 // let's do something.
9570 Animation a = AnimationUtils.loadAnimation(mContext,
9571 com.android.internal.R.anim.window_move_from_decor);
9572 w.setAnimation(a);
9573 animDw = w.mLastFrame.left - w.mFrame.left;
9574 animDh = w.mLastFrame.top - w.mFrame.top;
9575 }
9576
9577 // Execute animation.
9578 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9579 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009580
9581 // If this window is animating, make a note that we have
9582 // an animating window and take care of a request to run
9583 // a detached wallpaper animation.
9584 if (nowAnimating) {
9585 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9586 windowDetachedWallpaper = w;
9587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009588 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009590
9591 // If this window's app token is running a detached wallpaper
9592 // animation, make a note so we can ensure the wallpaper is
9593 // displayed behind it.
9594 if (w.mAppToken != null && w.mAppToken.animation != null
9595 && w.mAppToken.animation.getDetachWallpaper()) {
9596 windowDetachedWallpaper = w;
9597 }
9598
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009599 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9600 wallpaperMayChange = true;
9601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009603 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009604 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009605 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009606 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009607 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009608 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009609 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009610 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9611 forceHiding = true;
9612 }
9613 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9614 boolean changed;
9615 if (forceHiding) {
9616 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009617 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9618 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009619 } else {
9620 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009621 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9622 "Now policy shown: " + w);
9623 if (changed) {
9624 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009625 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009626 // Assume we will need to animate. If
9627 // we don't (because the wallpaper will
9628 // stay with the lock screen), then we will
9629 // clean up later.
9630 Animation a = mPolicy.createForceHideEnterAnimation();
9631 if (a != null) {
9632 w.setAnimation(a);
9633 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009634 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009635 if (mCurrentFocus == null ||
9636 mCurrentFocus.mLayer < w.mLayer) {
9637 // We are showing on to of the current
9638 // focus, so re-evaluate focus to make
9639 // sure it is correct.
9640 mFocusMayChange = true;
9641 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009642 }
9643 }
9644 if (changed && (attrs.flags
9645 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9646 wallpaperMayChange = true;
9647 }
9648 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009650 mPolicy.animatingWindowLw(w, attrs);
9651 }
9652
9653 final AppWindowToken atoken = w.mAppToken;
9654 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9655 if (atoken.lastTransactionSequence != transactionSequence) {
9656 atoken.lastTransactionSequence = transactionSequence;
9657 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9658 atoken.startingDisplayed = false;
9659 }
9660 if ((w.isOnScreen() || w.mAttrs.type
9661 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9662 && !w.mExiting && !w.mDestroying) {
9663 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009664 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009665 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009666 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009667 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009668 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009669 + " pv=" + w.mPolicyVisibility
9670 + " dp=" + w.mDrawPending
9671 + " cdp=" + w.mCommitDrawPending
9672 + " ah=" + w.mAttachedHidden
9673 + " th=" + atoken.hiddenRequested
9674 + " a=" + w.mAnimating);
9675 }
9676 }
9677 if (w != atoken.startingWindow) {
9678 if (!atoken.freezingScreen || !w.mAppFreezing) {
9679 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009680 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009681 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009682 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009683 "tokenMayBeDrawn: " + atoken
9684 + " freezingScreen=" + atoken.freezingScreen
9685 + " mAppFreezing=" + w.mAppFreezing);
9686 tokenMayBeDrawn = true;
9687 }
9688 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009689 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009690 atoken.startingDisplayed = true;
9691 }
9692 }
9693 } else if (w.mReadyToShow) {
9694 w.performShowLocked();
9695 }
9696 }
9697
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009698 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009699
9700 if (tokenMayBeDrawn) {
9701 // See if any windows have been drawn, so they (and others
9702 // associated with them) can now be shown.
9703 final int NT = mTokenList.size();
9704 for (i=0; i<NT; i++) {
9705 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9706 if (wtoken == null) {
9707 continue;
9708 }
9709 if (wtoken.freezingScreen) {
9710 int numInteresting = wtoken.numInterestingWindows;
9711 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009712 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009713 "allDrawn: " + wtoken
9714 + " interesting=" + numInteresting
9715 + " drawn=" + wtoken.numDrawnWindows);
9716 wtoken.showAllWindowsLocked();
9717 unsetAppFreezingScreenLocked(wtoken, false, true);
9718 orientationChangeComplete = true;
9719 }
9720 } else if (!wtoken.allDrawn) {
9721 int numInteresting = wtoken.numInterestingWindows;
9722 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009723 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009724 "allDrawn: " + wtoken
9725 + " interesting=" + numInteresting
9726 + " drawn=" + wtoken.numDrawnWindows);
9727 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009728 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009729
9730 // We can now show all of the drawn windows!
9731 if (!mOpeningApps.contains(wtoken)) {
9732 wtoken.showAllWindowsLocked();
9733 }
9734 }
9735 }
9736 }
9737 }
9738
9739 // If we are ready to perform an app transition, check through
9740 // all of the app tokens to be shown and see if they are ready
9741 // to go.
9742 if (mAppTransitionReady) {
9743 int NN = mOpeningApps.size();
9744 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009745 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 "Checking " + NN + " opening apps (frozen="
9747 + mDisplayFrozen + " timeout="
9748 + mAppTransitionTimeout + ")...");
9749 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9750 // If the display isn't frozen, wait to do anything until
9751 // all of the apps are ready. Otherwise just go because
9752 // we'll unfreeze the display when everyone is ready.
9753 for (i=0; i<NN && goodToGo; i++) {
9754 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009755 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009756 "Check opening app" + wtoken + ": allDrawn="
9757 + wtoken.allDrawn + " startingDisplayed="
9758 + wtoken.startingDisplayed);
9759 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9760 && !wtoken.startingMoved) {
9761 goodToGo = false;
9762 }
9763 }
9764 }
9765 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009766 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 int transit = mNextAppTransition;
9768 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009769 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009770 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009771 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009773 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009774 mAppTransitionTimeout = false;
9775 mStartingIconInTransition = false;
9776 mSkipAppTransitionAnimation = false;
9777
9778 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9779
Dianne Hackborna8f60182009-09-01 19:01:50 -07009780 // If there are applications waiting to come to the
9781 // top of the stack, now is the time to move their windows.
9782 // (Note that we don't do apps going to the bottom
9783 // here -- we want to keep their windows in the old
9784 // Z-order until the animation completes.)
9785 if (mToTopApps.size() > 0) {
9786 NN = mAppTokens.size();
9787 for (i=0; i<NN; i++) {
9788 AppWindowToken wtoken = mAppTokens.get(i);
9789 if (wtoken.sendingToTop) {
9790 wtoken.sendingToTop = false;
9791 moveAppWindowsLocked(wtoken, NN, false);
9792 }
9793 }
9794 mToTopApps.clear();
9795 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009796
Dianne Hackborn25994b42009-09-04 14:21:19 -07009797 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009798
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009799 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009800 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009801
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009802 // The top-most window will supply the layout params,
9803 // and we will determine it below.
9804 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009805 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009806 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009807
Joe Onorato8a9b2202010-02-26 18:56:32 -08009808 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009809 "New wallpaper target=" + mWallpaperTarget
9810 + ", lower target=" + mLowerWallpaperTarget
9811 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009812 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009813 // Do a first pass through the tokens for two
9814 // things:
9815 // (1) Determine if both the closing and opening
9816 // app token sets are wallpaper targets, in which
9817 // case special animations are needed
9818 // (since the wallpaper needs to stay static
9819 // behind them).
9820 // (2) Find the layout params of the top-most
9821 // application window in the tokens, which is
9822 // what will control the animation theme.
9823 final int NC = mClosingApps.size();
9824 NN = NC + mOpeningApps.size();
9825 for (i=0; i<NN; i++) {
9826 AppWindowToken wtoken;
9827 int mode;
9828 if (i < NC) {
9829 wtoken = mClosingApps.get(i);
9830 mode = 1;
9831 } else {
9832 wtoken = mOpeningApps.get(i-NC);
9833 mode = 2;
9834 }
9835 if (mLowerWallpaperTarget != null) {
9836 if (mLowerWallpaperTarget.mAppToken == wtoken
9837 || mUpperWallpaperTarget.mAppToken == wtoken) {
9838 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009839 }
9840 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009841 if (wtoken.appFullscreen) {
9842 WindowState ws = wtoken.findMainWindow();
9843 if (ws != null) {
9844 // If this is a compatibility mode
9845 // window, we will always use its anim.
9846 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9847 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009848 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009849 bestAnimLayer = Integer.MAX_VALUE;
9850 } else if (ws.mLayer > bestAnimLayer) {
9851 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009852 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009853 bestAnimLayer = ws.mLayer;
9854 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009855 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009856 }
9857 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009858
Dianne Hackborn25994b42009-09-04 14:21:19 -07009859 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009860 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009861 "Wallpaper animation!");
9862 switch (transit) {
9863 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9864 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9865 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9866 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9867 break;
9868 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9869 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9870 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9871 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9872 break;
9873 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009874 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009875 "New transit: " + transit);
9876 } else if (oldWallpaper != null) {
9877 // We are transitioning from an activity with
9878 // a wallpaper to one without.
9879 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009880 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009881 "New transit away from wallpaper: " + transit);
9882 } else if (mWallpaperTarget != null) {
9883 // We are transitioning from an activity without
9884 // a wallpaper to now showing the wallpaper
9885 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009886 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009887 "New transit into wallpaper: " + transit);
9888 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009889
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009890 // If all closing windows are obscured, then there is
9891 // no need to do an animation. This is the case, for
9892 // example, when this transition is being done behind
9893 // the lock screen.
9894 if (!mPolicy.allowAppAnimationsLw()) {
9895 animLp = null;
9896 }
9897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009898 NN = mOpeningApps.size();
9899 for (i=0; i<NN; i++) {
9900 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009901 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 "Now opening app" + wtoken);
9903 wtoken.reportedVisible = false;
9904 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009905 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009906 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009907 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009908 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 wtoken.showAllWindowsLocked();
9910 }
9911 NN = mClosingApps.size();
9912 for (i=0; i<NN; i++) {
9913 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009914 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 "Now closing app" + wtoken);
9916 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009917 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009918 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009919 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009920 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009921 // Force the allDrawn flag, because we want to start
9922 // this guy's animations regardless of whether it's
9923 // gotten drawn.
9924 wtoken.allDrawn = true;
9925 }
9926
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009927 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 mOpeningApps.clear();
9930 mClosingApps.clear();
9931
9932 // This has changed the visibility of windows, so perform
9933 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009934 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009935 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009936 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9937 assignLayersLocked();
9938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009940 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009941 }
9942 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009943
Dianne Hackborn16064f92010-03-25 00:47:24 -07009944 int adjResult = 0;
9945
Dianne Hackborna8f60182009-09-01 19:01:50 -07009946 if (!animating && mAppTransitionRunning) {
9947 // We have finished the animation of an app transition. To do
9948 // this, we have delayed a lot of operations like showing and
9949 // hiding apps, moving apps in Z-order, etc. The app token list
9950 // reflects the correct Z-order, but the window list may now
9951 // be out of sync with it. So here we will just rebuild the
9952 // entire app window list. Fun!
9953 mAppTransitionRunning = false;
9954 // Clear information about apps that were moving.
9955 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009956
Dianne Hackborna8f60182009-09-01 19:01:50 -07009957 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009958 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009959 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009960 moveInputMethodWindowsIfNeededLocked(false);
9961 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009962 // Since the window list has been rebuilt, focus might
9963 // have to be recomputed since the actual order of windows
9964 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009965 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009966 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009967
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009968 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009969 // At this point, there was a window with a wallpaper that
9970 // was force hiding other windows behind it, but now it
9971 // is going away. This may be simple -- just animate
9972 // away the wallpaper and its window -- or it may be
9973 // hard -- the wallpaper now needs to be shown behind
9974 // something that was hidden.
9975 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009976 if (mLowerWallpaperTarget != null
9977 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009978 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009979 "wallpaperForceHiding changed with lower="
9980 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009981 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009982 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9983 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9984 if (mLowerWallpaperTarget.mAppToken.hidden) {
9985 // The lower target has become hidden before we
9986 // actually started the animation... let's completely
9987 // re-evaluate everything.
9988 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009989 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009990 }
9991 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009992 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009993 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009994 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009995 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009996 + " NEW: " + mWallpaperTarget
9997 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009998 if (mLowerWallpaperTarget == null) {
9999 // Whoops, we don't need a special wallpaper animation.
10000 // Clear them out.
10001 forceHiding = false;
10002 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010003 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010004 if (w.mSurface != null) {
10005 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010006 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010007 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010008 forceHiding = true;
10009 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10010 if (!w.mAnimating) {
10011 // We set the animation above so it
10012 // is not yet running.
10013 w.clearAnimation();
10014 }
10015 }
10016 }
10017 }
10018 }
10019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010020
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010021 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10022 if (DEBUG_WALLPAPER) Slog.v(TAG,
10023 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10024 + windowDetachedWallpaper);
10025 mWindowDetachedWallpaper = windowDetachedWallpaper;
10026 wallpaperMayChange = true;
10027 }
10028
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010029 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010030 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010031 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010032 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010033 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010034
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010035 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010036 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010037 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010038 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010039 assignLayersLocked();
10040 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010041 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010042 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010043 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010045
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010046 if (mFocusMayChange) {
10047 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010048 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010049 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010050 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010051 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010052 }
10053
10054 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010055 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010056 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010057
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010058 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10059 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010060
Jeff Browne33348b2010-07-15 23:54:05 -070010061 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010062 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063
10064 // THIRD LOOP: Update the surfaces of all windows.
10065
10066 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10067
10068 boolean obscured = false;
10069 boolean blurring = false;
10070 boolean dimming = false;
10071 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010072 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010073 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010074
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010075 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010078 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010079
10080 boolean displayed = false;
10081 final WindowManager.LayoutParams attrs = w.mAttrs;
10082 final int attrFlags = attrs.flags;
10083
10084 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010085 // XXX NOTE: The logic here could be improved. We have
10086 // the decision about whether to resize a window separated
10087 // from whether to hide the surface. This can cause us to
10088 // resize a surface even if we are going to hide it. You
10089 // can see this by (1) holding device in landscape mode on
10090 // home screen; (2) tapping browser icon (device will rotate
10091 // to landscape; (3) tap home. The wallpaper will be resized
10092 // in step 2 but then immediately hidden, causing us to
10093 // have to resize and then redraw it again in step 3. It
10094 // would be nice to figure out how to avoid this, but it is
10095 // difficult because we do need to resize surfaces in some
10096 // cases while they are hidden such as when first showing a
10097 // window.
10098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010099 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010100 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010101 TAG, "Placing surface #" + i + " " + w.mSurface
10102 + ": new=" + w.mShownFrame + ", old="
10103 + w.mLastShownFrame);
10104
10105 boolean resize;
10106 int width, height;
10107 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10108 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10109 w.mLastRequestedHeight != w.mRequestedHeight;
10110 // for a scaled surface, we just want to use
10111 // the requested size.
10112 width = w.mRequestedWidth;
10113 height = w.mRequestedHeight;
10114 w.mLastRequestedWidth = width;
10115 w.mLastRequestedHeight = height;
10116 w.mLastShownFrame.set(w.mShownFrame);
10117 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010118 if (SHOW_TRANSACTIONS) logSurface(w,
10119 "POS " + w.mShownFrame.left
10120 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010121 w.mSurfaceX = w.mShownFrame.left;
10122 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10124 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010125 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010126 if (!recoveringMemory) {
10127 reclaimSomeSurfaceMemoryLocked(w, "position");
10128 }
10129 }
10130 } else {
10131 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10132 width = w.mShownFrame.width();
10133 height = w.mShownFrame.height();
10134 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010135 }
10136
10137 if (resize) {
10138 if (width < 1) width = 1;
10139 if (height < 1) height = 1;
10140 if (w.mSurface != null) {
10141 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010142 if (SHOW_TRANSACTIONS) logSurface(w,
10143 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010144 + w.mShownFrame.top + " SIZE "
10145 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010146 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010147 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010148 w.mSurfaceW = width;
10149 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010150 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010151 w.mSurfaceX = w.mShownFrame.left;
10152 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010153 w.mSurface.setPosition(w.mShownFrame.left,
10154 w.mShownFrame.top);
10155 } catch (RuntimeException e) {
10156 // If something goes wrong with the surface (such
10157 // as running out of memory), don't take down the
10158 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010159 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010160 + "size=(" + width + "x" + height
10161 + "), pos=(" + w.mShownFrame.left
10162 + "," + w.mShownFrame.top + ")", e);
10163 if (!recoveringMemory) {
10164 reclaimSomeSurfaceMemoryLocked(w, "size");
10165 }
10166 }
10167 }
10168 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010169 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010170 w.mContentInsetsChanged =
10171 !w.mLastContentInsets.equals(w.mContentInsets);
10172 w.mVisibleInsetsChanged =
10173 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010174 boolean configChanged =
10175 w.mConfiguration != mCurConfiguration
10176 && (w.mConfiguration == null
10177 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010178 if (DEBUG_CONFIGURATION && configChanged) {
10179 Slog.v(TAG, "Win " + w + " config changed: "
10180 + mCurConfiguration);
10181 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010182 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010183 + ": configChanged=" + configChanged
10184 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010185 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010186 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010187 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010188 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010189 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010190 w.mLastFrame.set(w.mFrame);
10191 w.mLastContentInsets.set(w.mContentInsets);
10192 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010193 // If the screen is currently frozen, then keep
10194 // it frozen until this window draws at its new
10195 // orientation.
10196 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010197 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010198 "Resizing while display frozen: " + w);
10199 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010200 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010201 mWindowsFreezingScreen = true;
10202 // XXX should probably keep timeout from
10203 // when we first froze the display.
10204 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10205 mH.sendMessageDelayed(mH.obtainMessage(
10206 H.WINDOW_FREEZE_TIMEOUT), 2000);
10207 }
10208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010209 // If the orientation is changing, then we need to
10210 // hold off on unfreezing the display until this
10211 // window has been redrawn; to do that, we need
10212 // to go through the process of getting informed
10213 // by the application when it has finished drawing.
10214 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010215 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010216 "Orientation start waiting for draw in "
10217 + w + ", surface " + w.mSurface);
10218 w.mDrawPending = true;
10219 w.mCommitDrawPending = false;
10220 w.mReadyToShow = false;
10221 if (w.mAppToken != null) {
10222 w.mAppToken.allDrawn = false;
10223 }
10224 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010225 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010226 "Resizing window " + w + " to " + w.mFrame);
10227 mResizingWindows.add(w);
10228 } else if (w.mOrientationChanging) {
10229 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010230 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010231 "Orientation not waiting for draw in "
10232 + w + ", surface " + w.mSurface);
10233 w.mOrientationChanging = false;
10234 }
10235 }
10236 }
10237
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010238 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010239 if (!w.mLastHidden) {
10240 //dump();
10241 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010242 if (SHOW_TRANSACTIONS) logSurface(w,
10243 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010244 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010245 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010246 try {
10247 w.mSurface.hide();
10248 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010249 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010250 }
10251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010252 }
10253 // If we are waiting for this window to handle an
10254 // orientation change, well, it is hidden, so
10255 // doesn't really matter. Note that this does
10256 // introduce a potential glitch if the window
10257 // becomes unhidden before it has drawn for the
10258 // new orientation.
10259 if (w.mOrientationChanging) {
10260 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010261 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010262 "Orientation change skips hidden " + w);
10263 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010264 } else if (w.mLastLayer != w.mAnimLayer
10265 || w.mLastAlpha != w.mShownAlpha
10266 || w.mLastDsDx != w.mDsDx
10267 || w.mLastDtDx != w.mDtDx
10268 || w.mLastDsDy != w.mDsDy
10269 || w.mLastDtDy != w.mDtDy
10270 || w.mLastHScale != w.mHScale
10271 || w.mLastVScale != w.mVScale
10272 || w.mLastHidden) {
10273 displayed = true;
10274 w.mLastAlpha = w.mShownAlpha;
10275 w.mLastLayer = w.mAnimLayer;
10276 w.mLastDsDx = w.mDsDx;
10277 w.mLastDtDx = w.mDtDx;
10278 w.mLastDsDy = w.mDsDy;
10279 w.mLastDtDy = w.mDtDy;
10280 w.mLastHScale = w.mHScale;
10281 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010282 if (SHOW_TRANSACTIONS) logSurface(w,
10283 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010284 + " matrix=[" + (w.mDsDx*w.mHScale)
10285 + "," + (w.mDtDx*w.mVScale)
10286 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010287 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010288 if (w.mSurface != null) {
10289 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010290 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010291 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010292 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 w.mSurface.setLayer(w.mAnimLayer);
10294 w.mSurface.setMatrix(
10295 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10296 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10297 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010298 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010299 if (!recoveringMemory) {
10300 reclaimSomeSurfaceMemoryLocked(w, "update");
10301 }
10302 }
10303 }
10304
10305 if (w.mLastHidden && !w.mDrawPending
10306 && !w.mCommitDrawPending
10307 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010308 if (SHOW_TRANSACTIONS) logSurface(w,
10309 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010310 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 + " during relayout");
10312 if (showSurfaceRobustlyLocked(w)) {
10313 w.mHasDrawn = true;
10314 w.mLastHidden = false;
10315 } else {
10316 w.mOrientationChanging = false;
10317 }
10318 }
10319 if (w.mSurface != null) {
10320 w.mToken.hasVisible = true;
10321 }
10322 } else {
10323 displayed = true;
10324 }
10325
10326 if (displayed) {
10327 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010328 if (attrs.width == LayoutParams.MATCH_PARENT
10329 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 covered = true;
10331 }
10332 }
10333 if (w.mOrientationChanging) {
10334 if (w.mDrawPending || w.mCommitDrawPending) {
10335 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010336 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010337 "Orientation continue waiting for draw in " + w);
10338 } else {
10339 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010340 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010341 "Orientation change complete in " + w);
10342 }
10343 }
10344 w.mToken.hasVisible = true;
10345 }
10346 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010347 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010348 "Orientation change skips hidden " + w);
10349 w.mOrientationChanging = false;
10350 }
10351
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010352 if (w.mContentChanged) {
10353 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10354 w.mContentChanged = false;
10355 }
10356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010357 final boolean canBeSeen = w.isDisplayedLw();
10358
10359 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10360 focusDisplayed = true;
10361 }
10362
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010363 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010365 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010366 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 if (w.mSurface != null) {
10368 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10369 holdScreen = w.mSession;
10370 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010371 if (!syswin && w.mAttrs.screenBrightness >= 0
10372 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 screenBrightness = w.mAttrs.screenBrightness;
10374 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010375 if (!syswin && w.mAttrs.buttonBrightness >= 0
10376 && buttonBrightness < 0) {
10377 buttonBrightness = w.mAttrs.buttonBrightness;
10378 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010379 if (canBeSeen
10380 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10381 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10382 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010383 syswin = true;
10384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010386
Dianne Hackborn25994b42009-09-04 14:21:19 -070010387 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10388 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010389 // This window completely covers everything behind it,
10390 // so we want to leave all of them as unblurred (for
10391 // performance reasons).
10392 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010393 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010394 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010395 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010396 obscured = true;
10397 if (mBackgroundFillerSurface == null) {
10398 try {
10399 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010400 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010401 0, dw, dh,
10402 PixelFormat.OPAQUE,
10403 Surface.FX_SURFACE_NORMAL);
10404 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010405 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010406 }
10407 }
10408 try {
10409 mBackgroundFillerSurface.setPosition(0, 0);
10410 mBackgroundFillerSurface.setSize(dw, dh);
10411 // Using the same layer as Dim because they will never be shown at the
10412 // same time.
10413 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10414 mBackgroundFillerSurface.show();
10415 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010416 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010417 }
10418 backgroundFillerShown = true;
10419 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010420 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010422 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423 + ": blurring=" + blurring
10424 + " obscured=" + obscured
10425 + " displayed=" + displayed);
10426 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10427 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010428 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010430 if (mDimAnimator == null) {
10431 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010433 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010434 mDimAnimator.updateParameters(mContext.getResources(),
10435 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010436 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 }
10438 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10439 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010440 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010441 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010443 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010444 + mBlurSurface + ": CREATE");
10445 try {
Romain Guy06882f82009-06-10 13:36:04 -070010446 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010447 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010448 -1, 16, 16,
10449 PixelFormat.OPAQUE,
10450 Surface.FX_SURFACE_BLUR);
10451 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010452 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010453 }
10454 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010456 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10457 + mBlurSurface + ": pos=(0,0) (" +
10458 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 mBlurSurface.setPosition(0, 0);
10460 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010461 mBlurSurface.setLayer(w.mAnimLayer-2);
10462 if (!mBlurShown) {
10463 try {
10464 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10465 + mBlurSurface + ": SHOW");
10466 mBlurSurface.show();
10467 } catch (RuntimeException e) {
10468 Slog.w(TAG, "Failure showing blur surface", e);
10469 }
10470 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010471 }
10472 }
10473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010474 }
10475 }
10476 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010477
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010478 if (obscuredChanged && mWallpaperTarget == w) {
10479 // This is the wallpaper target and its obscured state
10480 // changed... make sure the current wallaper's visibility
10481 // has been updated accordingly.
10482 updateWallpaperVisibilityLocked();
10483 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010484 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010485
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010486 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10487 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010488 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010489 try {
10490 mBackgroundFillerSurface.hide();
10491 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010492 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010493 }
10494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010495
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010496 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010497 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10498 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010499 }
Romain Guy06882f82009-06-10 13:36:04 -070010500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010502 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010503 + ": HIDE");
10504 try {
10505 mBlurSurface.hide();
10506 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010507 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010508 }
10509 mBlurShown = false;
10510 }
10511
Joe Onorato8a9b2202010-02-26 18:56:32 -080010512 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010514 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 }
10516
Jeff Browne33348b2010-07-15 23:54:05 -070010517 mInputMonitor.updateInputWindowsLw();
10518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010520
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010521 if (mWatermark != null) {
10522 mWatermark.drawIfNeeded();
10523 }
10524
Joe Onorato8a9b2202010-02-26 18:56:32 -080010525 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010526 "With display frozen, orientationChangeComplete="
10527 + orientationChangeComplete);
10528 if (orientationChangeComplete) {
10529 if (mWindowsFreezingScreen) {
10530 mWindowsFreezingScreen = false;
10531 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10532 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010533 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 }
Romain Guy06882f82009-06-10 13:36:04 -070010535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536 i = mResizingWindows.size();
10537 if (i > 0) {
10538 do {
10539 i--;
10540 WindowState win = mResizingWindows.get(i);
10541 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010542 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10543 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010544 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010545 boolean configChanged =
10546 win.mConfiguration != mCurConfiguration
10547 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010548 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10549 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10550 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010551 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010552 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010553 + " / " + mCurConfiguration + " / 0x"
10554 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010555 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010556 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010557 win.mClient.resized(win.mFrame.width(),
10558 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010559 win.mLastVisibleInsets, win.mDrawPending,
10560 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561 win.mContentInsetsChanged = false;
10562 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010563 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010564 } catch (RemoteException e) {
10565 win.mOrientationChanging = false;
10566 }
10567 } while (i > 0);
10568 mResizingWindows.clear();
10569 }
Romain Guy06882f82009-06-10 13:36:04 -070010570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010571 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010572 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 i = mDestroySurface.size();
10574 if (i > 0) {
10575 do {
10576 i--;
10577 WindowState win = mDestroySurface.get(i);
10578 win.mDestroying = false;
10579 if (mInputMethodWindow == win) {
10580 mInputMethodWindow = null;
10581 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010582 if (win == mWallpaperTarget) {
10583 wallpaperDestroyed = true;
10584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010585 win.destroySurfaceLocked();
10586 } while (i > 0);
10587 mDestroySurface.clear();
10588 }
10589
10590 // Time to remove any exiting tokens?
10591 for (i=mExitingTokens.size()-1; i>=0; i--) {
10592 WindowToken token = mExitingTokens.get(i);
10593 if (!token.hasVisible) {
10594 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010595 if (token.windowType == TYPE_WALLPAPER) {
10596 mWallpaperTokens.remove(token);
10597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010598 }
10599 }
10600
10601 // Time to remove any exiting applications?
10602 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10603 AppWindowToken token = mExitingAppTokens.get(i);
10604 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010605 // Make sure there is no animation running on this token,
10606 // so any windows associated with it will be removed as
10607 // soon as their animations are complete
10608 token.animation = null;
10609 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010610 mAppTokens.remove(token);
10611 mExitingAppTokens.remove(i);
10612 }
10613 }
10614
Dianne Hackborna8f60182009-09-01 19:01:50 -070010615 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010616
Dianne Hackborna8f60182009-09-01 19:01:50 -070010617 if (!animating && mAppTransitionRunning) {
10618 // We have finished the animation of an app transition. To do
10619 // this, we have delayed a lot of operations like showing and
10620 // hiding apps, moving apps in Z-order, etc. The app token list
10621 // reflects the correct Z-order, but the window list may now
10622 // be out of sync with it. So here we will just rebuild the
10623 // entire app window list. Fun!
10624 mAppTransitionRunning = false;
10625 needRelayout = true;
10626 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010627 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010628 // Clear information about apps that were moving.
10629 mToBottomApps.clear();
10630 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 if (focusDisplayed) {
10633 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10634 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010635 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010636 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010637 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010638 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010639 requestAnimationLocked(0);
10640 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010641 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10642 }
Jeff Browneb857f12010-07-16 10:06:33 -070010643
Jeff Browne33348b2010-07-15 23:54:05 -070010644 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010645
Jeff Brown8e03b752010-06-13 19:16:55 -070010646 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10648 mPowerManager.setScreenBrightnessOverride(-1);
10649 } else {
10650 mPowerManager.setScreenBrightnessOverride((int)
10651 (screenBrightness * Power.BRIGHTNESS_ON));
10652 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010653 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10654 mPowerManager.setButtonBrightnessOverride(-1);
10655 } else {
10656 mPowerManager.setButtonBrightnessOverride((int)
10657 (buttonBrightness * Power.BRIGHTNESS_ON));
10658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659 if (holdScreen != mHoldingScreenOn) {
10660 mHoldingScreenOn = holdScreen;
10661 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10662 mH.sendMessage(m);
10663 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010664
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010665 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010666 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010667 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10668 LocalPowerManager.BUTTON_EVENT, true);
10669 mTurnOnScreen = false;
10670 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010671
10672 // Check to see if we are now in a state where the screen should
10673 // be enabled, because the window obscured flags have changed.
10674 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010675 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010676
10677 /**
10678 * Must be called with the main window manager lock held.
10679 */
10680 void setHoldScreenLocked(boolean holding) {
10681 boolean state = mHoldingScreenWakeLock.isHeld();
10682 if (holding != state) {
10683 if (holding) {
10684 mHoldingScreenWakeLock.acquire();
10685 } else {
10686 mPolicy.screenOnStoppedLw();
10687 mHoldingScreenWakeLock.release();
10688 }
10689 }
10690 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010691
10692 void requestAnimationLocked(long delay) {
10693 if (!mAnimationPending) {
10694 mAnimationPending = true;
10695 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10696 }
10697 }
Romain Guy06882f82009-06-10 13:36:04 -070010698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010699 /**
10700 * Have the surface flinger show a surface, robustly dealing with
10701 * error conditions. In particular, if there is not enough memory
10702 * to show the surface, then we will try to get rid of other surfaces
10703 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010704 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010705 * @return Returns true if the surface was successfully shown.
10706 */
10707 boolean showSurfaceRobustlyLocked(WindowState win) {
10708 try {
10709 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010710 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010711 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010712 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010713 if (DEBUG_VISIBILITY) Slog.v(TAG,
10714 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010715 win.mTurnOnScreen = false;
10716 mTurnOnScreen = true;
10717 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010718 }
10719 return true;
10720 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010721 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010722 }
Romain Guy06882f82009-06-10 13:36:04 -070010723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010724 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010726 return false;
10727 }
Romain Guy06882f82009-06-10 13:36:04 -070010728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010729 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10730 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010731
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010732 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010733 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010735 if (mForceRemoves == null) {
10736 mForceRemoves = new ArrayList<WindowState>();
10737 }
Romain Guy06882f82009-06-10 13:36:04 -070010738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010739 long callingIdentity = Binder.clearCallingIdentity();
10740 try {
10741 // There was some problem... first, do a sanity check of the
10742 // window list to make sure we haven't left any dangling surfaces
10743 // around.
10744 int N = mWindows.size();
10745 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010746 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010747 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010748 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 if (ws.mSurface != null) {
10750 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010751 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010752 + ws + " surface=" + ws.mSurface
10753 + " token=" + win.mToken
10754 + " pid=" + ws.mSession.mPid
10755 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010756 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010757 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010758 ws.mSurface = null;
10759 mForceRemoves.add(ws);
10760 i--;
10761 N--;
10762 leakedSurface = true;
10763 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010764 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010765 + ws + " surface=" + ws.mSurface
10766 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010767 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010768 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010769 ws.mSurface = null;
10770 leakedSurface = true;
10771 }
10772 }
10773 }
Romain Guy06882f82009-06-10 13:36:04 -070010774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010775 boolean killedApps = false;
10776 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010777 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010778 SparseIntArray pidCandidates = new SparseIntArray();
10779 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010780 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010781 if (ws.mSurface != null) {
10782 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10783 }
10784 }
10785 if (pidCandidates.size() > 0) {
10786 int[] pids = new int[pidCandidates.size()];
10787 for (int i=0; i<pids.length; i++) {
10788 pids[i] = pidCandidates.keyAt(i);
10789 }
10790 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010791 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010792 killedApps = true;
10793 }
10794 } catch (RemoteException e) {
10795 }
10796 }
10797 }
Romain Guy06882f82009-06-10 13:36:04 -070010798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010799 if (leakedSurface || killedApps) {
10800 // We managed to reclaim some memory, so get rid of the trouble
10801 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010802 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010803 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010804 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010805 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010806 win.mSurface = null;
10807 }
Romain Guy06882f82009-06-10 13:36:04 -070010808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010809 try {
10810 win.mClient.dispatchGetNewSurface();
10811 } catch (RemoteException e) {
10812 }
10813 }
10814 } finally {
10815 Binder.restoreCallingIdentity(callingIdentity);
10816 }
10817 }
Romain Guy06882f82009-06-10 13:36:04 -070010818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010819 private boolean updateFocusedWindowLocked(int mode) {
10820 WindowState newFocus = computeFocusedWindowLocked();
10821 if (mCurrentFocus != newFocus) {
10822 // This check makes sure that we don't already have the focus
10823 // change message pending.
10824 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10825 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010826 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010827 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10828 final WindowState oldFocus = mCurrentFocus;
10829 mCurrentFocus = newFocus;
10830 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010832 final WindowState imWindow = mInputMethodWindow;
10833 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010834 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010835 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010836 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10837 mLayoutNeeded = true;
10838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010839 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080010840 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010841 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10842 // Client will do the layout, but we need to assign layers
10843 // for handleNewWindowLocked() below.
10844 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010845 }
10846 }
Jeff Brown349703e2010-06-22 01:27:15 -070010847
10848 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10849 // If we defer assigning layers, then the caller is responsible for
10850 // doing this part.
10851 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010853 return true;
10854 }
10855 return false;
10856 }
Jeff Brown349703e2010-06-22 01:27:15 -070010857
10858 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010859 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010860 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010861
10862 private WindowState computeFocusedWindowLocked() {
10863 WindowState result = null;
10864 WindowState win;
10865
10866 int i = mWindows.size() - 1;
10867 int nextAppIndex = mAppTokens.size()-1;
10868 WindowToken nextApp = nextAppIndex >= 0
10869 ? mAppTokens.get(nextAppIndex) : null;
10870
10871 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010872 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010873
Joe Onorato8a9b2202010-02-26 18:56:32 -080010874 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 TAG, "Looking for focus: " + i
10876 + " = " + win
10877 + ", flags=" + win.mAttrs.flags
10878 + ", canReceive=" + win.canReceiveKeys());
10879
10880 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010882 // If this window's application has been removed, just skip it.
10883 if (thisApp != null && thisApp.removed) {
10884 i--;
10885 continue;
10886 }
Romain Guy06882f82009-06-10 13:36:04 -070010887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010888 // If there is a focused app, don't allow focus to go to any
10889 // windows below it. If this is an application window, step
10890 // through the app tokens until we find its app.
10891 if (thisApp != null && nextApp != null && thisApp != nextApp
10892 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10893 int origAppIndex = nextAppIndex;
10894 while (nextAppIndex > 0) {
10895 if (nextApp == mFocusedApp) {
10896 // Whoops, we are below the focused app... no focus
10897 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010898 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010899 TAG, "Reached focused app: " + mFocusedApp);
10900 return null;
10901 }
10902 nextAppIndex--;
10903 nextApp = mAppTokens.get(nextAppIndex);
10904 if (nextApp == thisApp) {
10905 break;
10906 }
10907 }
10908 if (thisApp != nextApp) {
10909 // Uh oh, the app token doesn't exist! This shouldn't
10910 // happen, but if it does we can get totally hosed...
10911 // so restart at the original app.
10912 nextAppIndex = origAppIndex;
10913 nextApp = mAppTokens.get(nextAppIndex);
10914 }
10915 }
10916
10917 // Dispatch to this window if it is wants key events.
10918 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010919 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010920 TAG, "Found focus @ " + i + " = " + win);
10921 result = win;
10922 break;
10923 }
10924
10925 i--;
10926 }
10927
10928 return result;
10929 }
10930
10931 private void startFreezingDisplayLocked() {
10932 if (mDisplayFrozen) {
10933 return;
10934 }
Romain Guy06882f82009-06-10 13:36:04 -070010935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010936 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010938 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010939 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010940 if (mFreezeGcPending != 0) {
10941 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010942 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010943 mH.removeMessages(H.FORCE_GC);
10944 Runtime.getRuntime().gc();
10945 mFreezeGcPending = now;
10946 }
10947 } else {
10948 mFreezeGcPending = now;
10949 }
Romain Guy06882f82009-06-10 13:36:04 -070010950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010951 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010952
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010953 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010954
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010955 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10956 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010957 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010958 mAppTransitionReady = true;
10959 }
Romain Guy06882f82009-06-10 13:36:04 -070010960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010961 if (PROFILE_ORIENTATION) {
10962 File file = new File("/data/system/frozen");
10963 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10964 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010965
10966 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010967 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
10968 mScreenRotationAnimation.kill();
10969 mScreenRotationAnimation = null;
10970 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010971 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010972 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
10973 mDisplay, mFxSession);
Dianne Hackborna1111872010-11-23 20:55:11 -080010974 }
10975 } else {
10976 Surface.freezeDisplay(0);
10977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010978 }
Romain Guy06882f82009-06-10 13:36:04 -070010979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 private void stopFreezingDisplayLocked() {
10981 if (!mDisplayFrozen) {
10982 return;
10983 }
Romain Guy06882f82009-06-10 13:36:04 -070010984
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010985 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10986 return;
10987 }
10988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010989 mDisplayFrozen = false;
10990 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10991 if (PROFILE_ORIENTATION) {
10992 Debug.stopMethodTracing();
10993 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010994
10995 if (CUSTOM_SCREEN_ROTATION) {
10996 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010997 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
10998 mTransitionAnimationScale)) {
10999 requestAnimationLocked(0);
11000 } else {
11001 mScreenRotationAnimation = null;
11002 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011003 }
11004 } else {
11005 Surface.unfreezeDisplay(0);
11006 }
Romain Guy06882f82009-06-10 13:36:04 -070011007
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011008 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011009
Christopher Tateb696aee2010-04-02 19:08:30 -070011010 // While the display is frozen we don't re-compute the orientation
11011 // to avoid inconsistent states. However, something interesting
11012 // could have actually changed during that time so re-evaluate it
11013 // now to catch that.
11014 if (updateOrientationFromAppTokensLocked()) {
11015 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11016 }
11017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011018 // A little kludge: a lot could have happened while the
11019 // display was frozen, so now that we are coming back we
11020 // do a gc so that any remote references the system
11021 // processes holds on others can be released if they are
11022 // no longer needed.
11023 mH.removeMessages(H.FORCE_GC);
11024 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11025 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011027 mScreenFrozenLock.release();
11028 }
Romain Guy06882f82009-06-10 13:36:04 -070011029
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011030 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11031 DisplayMetrics dm) {
11032 if (index < tokens.length) {
11033 String str = tokens[index];
11034 if (str != null && str.length() > 0) {
11035 try {
11036 int val = Integer.parseInt(str);
11037 return val;
11038 } catch (Exception e) {
11039 }
11040 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011041 }
11042 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11043 return defDps;
11044 }
11045 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11046 return val;
11047 }
11048
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011049 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011050 final String[] mTokens;
11051 final String mText;
11052 final Paint mTextPaint;
11053 final int mTextWidth;
11054 final int mTextHeight;
11055 final int mTextAscent;
11056 final int mTextDescent;
11057 final int mDeltaX;
11058 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011059
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011060 Surface mSurface;
11061 int mLastDW;
11062 int mLastDH;
11063 boolean mDrawNeeded;
11064
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011065 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011066 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011067 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011068
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011069 if (false) {
11070 Log.i(TAG, "*********************** WATERMARK");
11071 for (int i=0; i<tokens.length; i++) {
11072 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11073 }
11074 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011075
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011076 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011077
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011078 StringBuilder builder = new StringBuilder(32);
11079 int len = mTokens[0].length();
11080 len = len & ~1;
11081 for (int i=0; i<len; i+=2) {
11082 int c1 = mTokens[0].charAt(i);
11083 int c2 = mTokens[0].charAt(i+1);
11084 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11085 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11086 else c1 -= '0';
11087 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11088 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11089 else c2 -= '0';
11090 builder.append((char)(255-((c1*16)+c2)));
11091 }
11092 mText = builder.toString();
11093 if (false) {
11094 Log.i(TAG, "Final text: " + mText);
11095 }
11096
11097 int fontSize = getPropertyInt(tokens, 1,
11098 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11099
11100 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11101 mTextPaint.setTextSize(fontSize);
11102 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11103
11104 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11105 mTextWidth = (int)mTextPaint.measureText(mText);
11106 mTextAscent = fm.ascent;
11107 mTextDescent = fm.descent;
11108 mTextHeight = fm.descent - fm.ascent;
11109
11110 mDeltaX = getPropertyInt(tokens, 2,
11111 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11112 mDeltaY = getPropertyInt(tokens, 3,
11113 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11114 int shadowColor = getPropertyInt(tokens, 4,
11115 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11116 int color = getPropertyInt(tokens, 5,
11117 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11118 int shadowRadius = getPropertyInt(tokens, 6,
11119 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11120 int shadowDx = getPropertyInt(tokens, 8,
11121 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11122 int shadowDy = getPropertyInt(tokens, 9,
11123 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11124
11125 mTextPaint.setColor(color);
11126 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011127
11128 try {
11129 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011130 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011131 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011132 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011133 mSurface.show();
11134 } catch (OutOfResourcesException e) {
11135 }
11136 }
11137
11138 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011139 if (mLastDW != dw || mLastDH != dh) {
11140 mLastDW = dw;
11141 mLastDH = dh;
11142 mSurface.setSize(dw, dh);
11143 mDrawNeeded = true;
11144 }
11145 }
11146
11147 void drawIfNeeded() {
11148 if (mDrawNeeded) {
11149 final int dw = mLastDW;
11150 final int dh = mLastDH;
11151
11152 mDrawNeeded = false;
11153 Rect dirty = new Rect(0, 0, dw, dh);
11154 Canvas c = null;
11155 try {
11156 c = mSurface.lockCanvas(dirty);
11157 } catch (IllegalArgumentException e) {
11158 } catch (OutOfResourcesException e) {
11159 }
11160 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011161 c.drawColor(0, PorterDuff.Mode.CLEAR);
11162
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011163 int deltaX = mDeltaX;
11164 int deltaY = mDeltaY;
11165
11166 // deltaX shouldn't be close to a round fraction of our
11167 // x step, or else things will line up too much.
11168 int div = (dw+mTextWidth)/deltaX;
11169 int rem = (dw+mTextWidth) - (div*deltaX);
11170 int qdelta = deltaX/4;
11171 if (rem < qdelta || rem > (deltaX-qdelta)) {
11172 deltaX += deltaX/3;
11173 }
11174
11175 int y = -mTextHeight;
11176 int x = -mTextWidth;
11177 while (y < (dh+mTextHeight)) {
11178 c.drawText(mText, x, y, mTextPaint);
11179 x += deltaX;
11180 if (x >= dw) {
11181 x -= (dw+mTextWidth);
11182 y += deltaY;
11183 }
11184 }
11185 mSurface.unlockCanvasAndPost(c);
11186 }
11187 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011188 }
11189 }
11190
11191 void createWatermark() {
11192 if (mWatermark != null) {
11193 return;
11194 }
11195
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011196 File file = new File("/system/etc/setup.conf");
11197 FileInputStream in = null;
11198 try {
11199 in = new FileInputStream(file);
11200 DataInputStream ind = new DataInputStream(in);
11201 String line = ind.readLine();
11202 if (line != null) {
11203 String[] toks = line.split("%");
11204 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011205 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011206 }
11207 }
11208 } catch (FileNotFoundException e) {
11209 } catch (IOException e) {
11210 } finally {
11211 if (in != null) {
11212 try {
11213 in.close();
11214 } catch (IOException e) {
11215 }
11216 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011217 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011218 }
11219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011220 @Override
11221 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11222 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11223 != PackageManager.PERMISSION_GRANTED) {
11224 pw.println("Permission Denial: can't dump WindowManager from from pid="
11225 + Binder.getCallingPid()
11226 + ", uid=" + Binder.getCallingUid());
11227 return;
11228 }
Romain Guy06882f82009-06-10 13:36:04 -070011229
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011230 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011231 pw.println(" ");
11232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011233 synchronized(mWindowMap) {
11234 pw.println("Current Window Manager state:");
11235 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011236 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011237 pw.print(" Window #"); pw.print(i); pw.print(' ');
11238 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011239 w.dump(pw, " ");
11240 }
11241 if (mInputMethodDialogs.size() > 0) {
11242 pw.println(" ");
11243 pw.println(" Input method dialogs:");
11244 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11245 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011246 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011247 }
11248 }
11249 if (mPendingRemove.size() > 0) {
11250 pw.println(" ");
11251 pw.println(" Remove pending for:");
11252 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11253 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011254 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11255 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011256 w.dump(pw, " ");
11257 }
11258 }
11259 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11260 pw.println(" ");
11261 pw.println(" Windows force removing:");
11262 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11263 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011264 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11265 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011266 w.dump(pw, " ");
11267 }
11268 }
11269 if (mDestroySurface.size() > 0) {
11270 pw.println(" ");
11271 pw.println(" Windows waiting to destroy their surface:");
11272 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11273 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011274 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11275 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011276 w.dump(pw, " ");
11277 }
11278 }
11279 if (mLosingFocus.size() > 0) {
11280 pw.println(" ");
11281 pw.println(" Windows losing focus:");
11282 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11283 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011284 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11285 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011286 w.dump(pw, " ");
11287 }
11288 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011289 if (mResizingWindows.size() > 0) {
11290 pw.println(" ");
11291 pw.println(" Windows waiting to resize:");
11292 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11293 WindowState w = mResizingWindows.get(i);
11294 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11295 pw.print(w); pw.println(":");
11296 w.dump(pw, " ");
11297 }
11298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011299 if (mSessions.size() > 0) {
11300 pw.println(" ");
11301 pw.println(" All active sessions:");
11302 Iterator<Session> it = mSessions.iterator();
11303 while (it.hasNext()) {
11304 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011305 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011306 s.dump(pw, " ");
11307 }
11308 }
11309 if (mTokenMap.size() > 0) {
11310 pw.println(" ");
11311 pw.println(" All tokens:");
11312 Iterator<WindowToken> it = mTokenMap.values().iterator();
11313 while (it.hasNext()) {
11314 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011315 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011316 token.dump(pw, " ");
11317 }
11318 }
11319 if (mTokenList.size() > 0) {
11320 pw.println(" ");
11321 pw.println(" Window token list:");
11322 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011323 pw.print(" #"); pw.print(i); pw.print(": ");
11324 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011325 }
11326 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011327 if (mWallpaperTokens.size() > 0) {
11328 pw.println(" ");
11329 pw.println(" Wallpaper tokens:");
11330 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11331 WindowToken token = mWallpaperTokens.get(i);
11332 pw.print(" Wallpaper #"); pw.print(i);
11333 pw.print(' '); pw.print(token); pw.println(':');
11334 token.dump(pw, " ");
11335 }
11336 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011337 if (mAppTokens.size() > 0) {
11338 pw.println(" ");
11339 pw.println(" Application tokens in Z order:");
11340 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011341 pw.print(" App #"); pw.print(i); pw.print(": ");
11342 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011343 }
11344 }
11345 if (mFinishedStarting.size() > 0) {
11346 pw.println(" ");
11347 pw.println(" Finishing start of application tokens:");
11348 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11349 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011350 pw.print(" Finished Starting #"); pw.print(i);
11351 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011352 token.dump(pw, " ");
11353 }
11354 }
11355 if (mExitingTokens.size() > 0) {
11356 pw.println(" ");
11357 pw.println(" Exiting tokens:");
11358 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11359 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011360 pw.print(" Exiting #"); pw.print(i);
11361 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011362 token.dump(pw, " ");
11363 }
11364 }
11365 if (mExitingAppTokens.size() > 0) {
11366 pw.println(" ");
11367 pw.println(" Exiting application tokens:");
11368 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11369 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011370 pw.print(" Exiting App #"); pw.print(i);
11371 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011372 token.dump(pw, " ");
11373 }
11374 }
11375 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011376 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11377 pw.print(" mLastFocus="); pw.println(mLastFocus);
11378 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11379 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11380 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011381 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011382 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11383 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11384 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11385 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011386 if (mWindowDetachedWallpaper != null) {
11387 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11388 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011389 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11390 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11391 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011392 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11393 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11394 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11395 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011396 if (mDimAnimator != null) {
11397 mDimAnimator.printTo(pw);
11398 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011399 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011400 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011401 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011402 pw.print(mInputMethodAnimLayerAdjustment);
11403 pw.print(" mWallpaperAnimLayerAdjustment=");
11404 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011405 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11406 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011407 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11408 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011409 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11410 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011411 pw.print(" mRotation="); pw.print(mRotation);
11412 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11413 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11414 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11415 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11416 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11417 pw.print(" mNextAppTransition=0x");
11418 pw.print(Integer.toHexString(mNextAppTransition));
11419 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011420 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011421 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011422 if (mNextAppTransitionPackage != null) {
11423 pw.print(" mNextAppTransitionPackage=");
11424 pw.print(mNextAppTransitionPackage);
11425 pw.print(", mNextAppTransitionEnter=0x");
11426 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11427 pw.print(", mNextAppTransitionExit=0x");
11428 pw.print(Integer.toHexString(mNextAppTransitionExit));
11429 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011430 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11431 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11432 if (mOpeningApps.size() > 0) {
11433 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11434 }
11435 if (mClosingApps.size() > 0) {
11436 pw.print(" mClosingApps="); pw.println(mClosingApps);
11437 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011438 if (mToTopApps.size() > 0) {
11439 pw.print(" mToTopApps="); pw.println(mToTopApps);
11440 }
11441 if (mToBottomApps.size() > 0) {
11442 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11443 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011444 if (mDisplay != null) {
11445 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11446 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11447 } else {
11448 pw.println(" NO DISPLAY");
11449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011450 }
11451 }
11452
Jeff Brown349703e2010-06-22 01:27:15 -070011453 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011454 public void monitor() {
11455 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011456 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011457 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011458
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011459 /**
11460 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011461 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011462 */
11463 private static class DimAnimator {
11464 Surface mDimSurface;
11465 boolean mDimShown = false;
11466 float mDimCurrentAlpha;
11467 float mDimTargetAlpha;
11468 float mDimDeltaPerMs;
11469 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011470
11471 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011472
11473 DimAnimator (SurfaceSession session) {
11474 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011475 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011476 + mDimSurface + ": CREATE");
11477 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011478 mDimSurface = new Surface(session, 0,
11479 "DimSurface",
11480 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011481 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011482 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011483 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011484 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011485 }
11486 }
11487 }
11488
11489 /**
11490 * Show the dim surface.
11491 */
11492 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011493 if (!mDimShown) {
11494 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11495 dw + "x" + dh + ")");
11496 mDimShown = true;
11497 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011498 mLastDimWidth = dw;
11499 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011500 mDimSurface.setPosition(0, 0);
11501 mDimSurface.setSize(dw, dh);
11502 mDimSurface.show();
11503 } catch (RuntimeException e) {
11504 Slog.w(TAG, "Failure showing dim surface", e);
11505 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011506 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11507 mLastDimWidth = dw;
11508 mLastDimHeight = dh;
11509 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011510 }
11511 }
11512
11513 /**
11514 * Set's the dim surface's layer and update dim parameters that will be used in
11515 * {@link updateSurface} after all windows are examined.
11516 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011517 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011518 mDimSurface.setLayer(w.mAnimLayer-1);
11519
11520 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011521 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011522 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011523 if (mDimTargetAlpha != target) {
11524 // If the desired dim level has changed, then
11525 // start an animation to it.
11526 mLastDimAnimTime = currentTime;
11527 long duration = (w.mAnimating && w.mAnimation != null)
11528 ? w.mAnimation.computeDurationHint()
11529 : DEFAULT_DIM_DURATION;
11530 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011531 TypedValue tv = new TypedValue();
11532 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11533 tv, true);
11534 if (tv.type == TypedValue.TYPE_FRACTION) {
11535 duration = (long)tv.getFraction((float)duration, (float)duration);
11536 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11537 && tv.type <= TypedValue.TYPE_LAST_INT) {
11538 duration = tv.data;
11539 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011540 }
11541 if (duration < 1) {
11542 // Don't divide by zero
11543 duration = 1;
11544 }
11545 mDimTargetAlpha = target;
11546 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11547 }
11548 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011549
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011550 /**
11551 * Updating the surface's alpha. Returns true if the animation continues, or returns
11552 * false when the animation is finished and the dim surface is hidden.
11553 */
11554 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11555 if (!dimming) {
11556 if (mDimTargetAlpha != 0) {
11557 mLastDimAnimTime = currentTime;
11558 mDimTargetAlpha = 0;
11559 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11560 }
11561 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011562
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011563 boolean animating = false;
11564 if (mLastDimAnimTime != 0) {
11565 mDimCurrentAlpha += mDimDeltaPerMs
11566 * (currentTime-mLastDimAnimTime);
11567 boolean more = true;
11568 if (displayFrozen) {
11569 // If the display is frozen, there is no reason to animate.
11570 more = false;
11571 } else if (mDimDeltaPerMs > 0) {
11572 if (mDimCurrentAlpha > mDimTargetAlpha) {
11573 more = false;
11574 }
11575 } else if (mDimDeltaPerMs < 0) {
11576 if (mDimCurrentAlpha < mDimTargetAlpha) {
11577 more = false;
11578 }
11579 } else {
11580 more = false;
11581 }
11582
11583 // Do we need to continue animating?
11584 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011585 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011586 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11587 mLastDimAnimTime = currentTime;
11588 mDimSurface.setAlpha(mDimCurrentAlpha);
11589 animating = true;
11590 } else {
11591 mDimCurrentAlpha = mDimTargetAlpha;
11592 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011593 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011594 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11595 mDimSurface.setAlpha(mDimCurrentAlpha);
11596 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011597 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011598 + ": HIDE");
11599 try {
11600 mDimSurface.hide();
11601 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011602 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011603 }
11604 mDimShown = false;
11605 }
11606 }
11607 }
11608 return animating;
11609 }
11610
11611 public void printTo(PrintWriter pw) {
11612 pw.print(" mDimShown="); pw.print(mDimShown);
11613 pw.print(" current="); pw.print(mDimCurrentAlpha);
11614 pw.print(" target="); pw.print(mDimTargetAlpha);
11615 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11616 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11617 }
11618 }
11619
11620 /**
11621 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11622 * This is used for opening/closing transition for apps in compatible mode.
11623 */
11624 private static class FadeInOutAnimation extends Animation {
11625 int mWidth;
11626 boolean mFadeIn;
11627
11628 public FadeInOutAnimation(boolean fadeIn) {
11629 setInterpolator(new AccelerateInterpolator());
11630 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11631 mFadeIn = fadeIn;
11632 }
11633
11634 @Override
11635 protected void applyTransformation(float interpolatedTime, Transformation t) {
11636 float x = interpolatedTime;
11637 if (!mFadeIn) {
11638 x = 1.0f - x; // reverse the interpolation for fade out
11639 }
11640 if (x < 0.5) {
11641 // move the window out of the screen.
11642 t.getMatrix().setTranslate(mWidth, 0);
11643 } else {
11644 t.getMatrix().setTranslate(0, 0);// show
11645 t.setAlpha((x - 0.5f) * 2);
11646 }
11647 }
11648
11649 @Override
11650 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11651 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11652 mWidth = width;
11653 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011654
11655 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011656 public int getZAdjustment() {
11657 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011658 }
11659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011660}