blob: 748f2e94291a40661e63eed0f82d38f710ed726e [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;
438 WindowState mUpcomingInputMethodTarget = null;
439 boolean mInputMethodTargetWaitingAnim;
440 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 WindowState mInputMethodWindow = null;
443 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
444
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700445 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800446
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700447 // If non-null, this is the currently visible window that is associated
448 // with the wallpaper.
449 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700450 // If non-null, we are in the middle of animating from one wallpaper target
451 // to another, and this is the lower one in Z-order.
452 WindowState mLowerWallpaperTarget = null;
453 // If non-null, we are in the middle of animating from one wallpaper target
454 // to another, and this is the higher one in Z-order.
455 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800456 // Window currently running an animation that has requested it be detached
457 // from the wallpaper. This means we need to ensure the wallpaper is
458 // visible behind it in case it animates in a way that would allow it to be
459 // seen.
460 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700461 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700462 float mLastWallpaperX = -1;
463 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800464 float mLastWallpaperXStep = -1;
465 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700466 // This is set when we are waiting for a wallpaper to tell us it is done
467 // changing its scroll position.
468 WindowState mWaitingOnWallpaper;
469 // The last time we had a timeout when waiting for a wallpaper.
470 long mLastWallpaperTimeoutTime;
471 // We give a wallpaper up to 150ms to finish scrolling.
472 static final long WALLPAPER_TIMEOUT = 150;
473 // Time we wait after a timeout before trying to wait again.
474 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 AppWindowToken mFocusedApp = null;
477
478 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 float mWindowAnimationScale = 1.0f;
481 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700482
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700483 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484
485 // Who is holding the screen on.
486 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700487 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700488
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700489 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700492 * Drag/drop state
493 */
494 class DragState {
495 IBinder mToken;
496 Surface mSurface;
497 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700498 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700499 ClipData mData;
500 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700501 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700502 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700503 float mThumbOffsetX, mThumbOffsetY;
504 InputChannel mServerChannel, mClientChannel;
505 WindowState mTargetWindow;
506 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700507 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700508
509 private final Rect tmpRect = new Rect();
510
Chris Tate7b362e42010-11-04 16:02:52 -0700511 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700512 mToken = token;
513 mSurface = surface;
514 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700515 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700516 mNotifiedWindows = new ArrayList<WindowState>();
517 }
518
519 void reset() {
520 if (mSurface != null) {
521 mSurface.destroy();
522 }
523 mSurface = null;
524 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700525 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700526 mToken = null;
527 mData = null;
528 mThumbOffsetX = mThumbOffsetY = 0;
529 mNotifiedWindows = null;
530 }
531
532 void register() {
533 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
534 if (mClientChannel != null) {
535 Slog.e(TAG, "Duplicate register of drag input channel");
536 } else {
537 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
538 mServerChannel = channels[0];
539 mClientChannel = channels[1];
540 mInputManager.registerInputChannel(mServerChannel);
541 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
542 mH.getLooper().getQueue());
543 }
544 }
545
546 void unregister() {
547 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
548 if (mClientChannel == null) {
549 Slog.e(TAG, "Unregister of nonexistent drag input channel");
550 } else {
551 mInputManager.unregisterInputChannel(mServerChannel);
552 InputQueue.unregisterInputChannel(mClientChannel);
553 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700554 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700555 mClientChannel = null;
556 mServerChannel = null;
557 }
558 }
559
Chris Tatea32dcf72010-10-14 12:13:50 -0700560 int getDragLayerLw() {
561 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
562 * TYPE_LAYER_MULTIPLIER
563 + TYPE_LAYER_OFFSET;
564 }
565
Christopher Tatea53146c2010-09-07 11:57:52 -0700566 /* call out to each visible window/session informing it about the drag
567 */
Chris Tateb8203e92010-10-12 14:23:21 -0700568 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700569 // Cache a base-class instance of the clip metadata so that parceling
570 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700571 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700572 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700573 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700574
575 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700576 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700577 }
578
Christopher Tate2c095f32010-10-04 14:13:40 -0700579 final int N = mWindows.size();
580 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700581 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700582 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 }
584
585 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
586 * designated window is potentially a drop recipient. There are race situations
587 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
588 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700589 *
590 * This method clones the 'event' parameter if it's being delivered to the same
591 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700592 */
Chris Tateb478f462010-10-15 16:02:26 -0700593 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
594 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700595 // Don't actually send the event if the drag is supposed to be pinned
596 // to the originating window but 'newWin' is not that window.
597 if (mLocalOnly) {
598 final IBinder winBinder = newWin.mClient.asBinder();
599 if (winBinder != mLocalWin) {
600 if (DEBUG_DRAG) {
601 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
602 }
603 return;
604 }
605 }
606
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700607 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700608 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
609 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800610 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700611 try {
612 newWin.mClient.dispatchDragEvent(event);
613 // track each window that we've notified that the drag is starting
614 mNotifiedWindows.add(newWin);
615 } catch (RemoteException e) {
616 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700617 } finally {
618 // if the callee was local, the dispatch has already recycled the event
619 if (Process.myPid() != newWin.mSession.mPid) {
620 event.recycle();
621 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700622 }
623 }
624 }
625
626 /* helper - construct and send a DRAG_STARTED event only if the window has not
627 * previously been notified, i.e. it became visible after the drag operation
628 * was begun. This is a rare case.
629 */
630 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700631 if (mDragInProgress) {
632 // If we have sent the drag-started, we needn't do so again
633 for (WindowState ws : mNotifiedWindows) {
634 if (ws == newWin) {
635 return;
636 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700637 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700638 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700639 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700640 }
Chris Tateb478f462010-10-15 16:02:26 -0700641 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700642 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700643 }
644
Chris Tated4533f142010-10-19 15:15:08 -0700645 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700646 if (DEBUG_DRAG) {
647 Slog.d(TAG, "broadcasting DRAG_ENDED");
648 }
Chris Tated4533f142010-10-19 15:15:08 -0700649 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800650 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700651 for (WindowState ws: mNotifiedWindows) {
652 try {
653 ws.mClient.dispatchDragEvent(evt);
654 } catch (RemoteException e) {
655 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700656 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700657 }
Chris Tated4533f142010-10-19 15:15:08 -0700658 mNotifiedWindows.clear();
659 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700660 evt.recycle();
661 }
662
Chris Tated4533f142010-10-19 15:15:08 -0700663 void endDragLw() {
664 mDragState.broadcastDragEndedLw();
665
666 // stop intercepting input
667 mDragState.unregister();
668 mInputMonitor.updateInputWindowsLw();
669
670 // free our resources and drop all the object references
671 mDragState.reset();
672 mDragState = null;
673 }
674
Christopher Tatea53146c2010-09-07 11:57:52 -0700675 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700676 final int myPid = Process.myPid();
677
678 // Move the surface to the given touch
679 mSurface.openTransaction();
680 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
681 mSurface.closeTransaction();
682
683 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700684 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700685 if (mLocalOnly) {
686 final IBinder touchedBinder = touchedWin.mClient.asBinder();
687 if (touchedBinder != mLocalWin) {
688 // This drag is pinned only to the originating window, but the drag
689 // point is outside that window. Pretend it's over empty space.
690 touchedWin = null;
691 }
692 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700693 try {
694 // have we dragged over a new window?
695 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
696 if (DEBUG_DRAG) {
697 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
698 }
699 // force DRAG_EXITED_EVENT if appropriate
700 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700701 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800702 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700703 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700704 if (myPid != mTargetWindow.mSession.mPid) {
705 evt.recycle();
706 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700707 }
708 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700709 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700710 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
711 }
712 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700713 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800714 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700715 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700716 if (myPid != touchedWin.mSession.mPid) {
717 evt.recycle();
718 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700719 }
720 } catch (RemoteException e) {
721 Slog.w(TAG, "can't send drag notification to windows");
722 }
723 mTargetWindow = touchedWin;
724 }
725
Chris Tated4533f142010-10-19 15:15:08 -0700726 // Tell the drop target about the data. Returns 'true' if we can immediately
727 // dispatch the global drag-ended message, 'false' if we need to wait for a
728 // result from the recipient.
729 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700730 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700731 if (touchedWin == null) {
732 // "drop" outside a valid window -- no recipient to apply a
733 // timeout to, and we can send the drag-ended message immediately.
734 mDragResult = false;
735 return true;
736 }
737
738 if (DEBUG_DRAG) {
739 Slog.d(TAG, "sending DROP to " + touchedWin);
740 }
741 final int myPid = Process.myPid();
742 final IBinder token = touchedWin.mClient.asBinder();
743 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
744 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800745 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700746 try {
747 touchedWin.mClient.dispatchDragEvent(evt);
748
749 // 5 second timeout for this window to respond to the drop
750 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
751 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
752 mH.sendMessageDelayed(msg, 5000);
753 } catch (RemoteException e) {
754 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
755 return true;
756 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700757 if (myPid != touchedWin.mSession.mPid) {
758 evt.recycle();
759 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700760 }
Chris Tated4533f142010-10-19 15:15:08 -0700761 mToken = token;
762 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700763 }
764
765 // Find the visible, touch-deliverable window under the given point
766 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
767 WindowState touchedWin = null;
768 final int x = (int) xf;
769 final int y = (int) yf;
770 final ArrayList<WindowState> windows = mWindows;
771 final int N = windows.size();
772 for (int i = N - 1; i >= 0; i--) {
773 WindowState child = windows.get(i);
774 final int flags = child.mAttrs.flags;
775 if (!child.isVisibleLw()) {
776 // not visible == don't tell about drags
777 continue;
778 }
779 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
780 // not touchable == don't tell about drags
781 continue;
782 }
783 // account for the window's decor etc
784 tmpRect.set(child.mFrame);
785 if (child.mTouchableInsets == ViewTreeObserver
786 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
787 // The point is inside of the window if it is
788 // inside the frame, AND the content part of that
789 // frame that was given by the application.
790 tmpRect.left += child.mGivenContentInsets.left;
791 tmpRect.top += child.mGivenContentInsets.top;
792 tmpRect.right -= child.mGivenContentInsets.right;
793 tmpRect.bottom -= child.mGivenContentInsets.bottom;
794 } else if (child.mTouchableInsets == ViewTreeObserver
795 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
796 // The point is inside of the window if it is
797 // inside the frame, AND the visible part of that
798 // frame that was given by the application.
799 tmpRect.left += child.mGivenVisibleInsets.left;
800 tmpRect.top += child.mGivenVisibleInsets.top;
801 tmpRect.right -= child.mGivenVisibleInsets.right;
802 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
803 }
804 final int touchFlags = flags &
805 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
806 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
807 if (tmpRect.contains(x, y) || touchFlags == 0) {
808 // Found it
809 touchedWin = child;
810 break;
811 }
812 }
813
814 return touchedWin;
815 }
816 }
817
818 DragState mDragState = null;
819 private final InputHandler mDragInputHandler = new BaseInputHandler() {
820 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700821 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
822 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700823 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700824 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
825 && mDragState != null) {
826 boolean endDrag = false;
827 final float newX = event.getRawX();
828 final float newY = event.getRawY();
829
Christopher Tatea53146c2010-09-07 11:57:52 -0700830 switch (event.getAction()) {
831 case MotionEvent.ACTION_DOWN: {
832 if (DEBUG_DRAG) {
833 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
834 }
835 } break;
836
837 case MotionEvent.ACTION_MOVE: {
838 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700839 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700840 mDragState.notifyMoveLw(newX, newY);
841 }
842 } break;
843
844 case MotionEvent.ACTION_UP: {
845 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
846 + newX + "," + newY);
847 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700848 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700849 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700850 } break;
851
852 case MotionEvent.ACTION_CANCEL: {
853 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
854 endDrag = true;
855 } break;
856 }
857
858 if (endDrag) {
859 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
860 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700861 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700862 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700863 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700864 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700865
866 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700867 }
868 } catch (Exception e) {
869 Slog.e(TAG, "Exception caught by drag handleMotion", e);
870 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700871 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700872 }
873 }
874 };
875
876 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 * Whether the UI is currently running in touch mode (not showing
878 * navigational focus because the user is directly pressing the screen).
879 */
880 boolean mInTouchMode = false;
881
882 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700883 private ArrayList<WindowChangeListener> mWindowChangeListeners =
884 new ArrayList<WindowChangeListener>();
885 private boolean mWindowsChanged = false;
886
887 public interface WindowChangeListener {
888 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700889 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700890 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891
Dianne Hackbornc485a602009-03-24 22:39:49 -0700892 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700893 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700894
895 // The frame use to limit the size of the app running in compatibility mode.
896 Rect mCompatibleScreenFrame = new Rect();
897 // The surface used to fill the outer rim of the app running in compatibility mode.
898 Surface mBackgroundFillerSurface = null;
899 boolean mBackgroundFillerShown = false;
900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 public static WindowManagerService main(Context context,
902 PowerManagerService pm, boolean haveInputMethods) {
903 WMThread thr = new WMThread(context, pm, haveInputMethods);
904 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 synchronized (thr) {
907 while (thr.mService == null) {
908 try {
909 thr.wait();
910 } catch (InterruptedException e) {
911 }
912 }
913 }
Romain Guy06882f82009-06-10 13:36:04 -0700914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 return thr.mService;
916 }
Romain Guy06882f82009-06-10 13:36:04 -0700917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 static class WMThread extends Thread {
919 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 private final Context mContext;
922 private final PowerManagerService mPM;
923 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 public WMThread(Context context, PowerManagerService pm,
926 boolean haveInputMethods) {
927 super("WindowManager");
928 mContext = context;
929 mPM = pm;
930 mHaveInputMethods = haveInputMethods;
931 }
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 public void run() {
934 Looper.prepare();
935 WindowManagerService s = new WindowManagerService(mContext, mPM,
936 mHaveInputMethods);
937 android.os.Process.setThreadPriority(
938 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700939 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 synchronized (this) {
942 mService = s;
943 notifyAll();
944 }
Romain Guy06882f82009-06-10 13:36:04 -0700945
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700946 // For debug builds, log event loop stalls to dropbox for analysis.
947 if (StrictMode.conditionallyEnableDebugLogging()) {
948 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
949 }
950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 Looper.loop();
952 }
953 }
954
955 static class PolicyThread extends Thread {
956 private final WindowManagerPolicy mPolicy;
957 private final WindowManagerService mService;
958 private final Context mContext;
959 private final PowerManagerService mPM;
960 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 public PolicyThread(WindowManagerPolicy policy,
963 WindowManagerService service, Context context,
964 PowerManagerService pm) {
965 super("WindowManagerPolicy");
966 mPolicy = policy;
967 mService = service;
968 mContext = context;
969 mPM = pm;
970 }
Romain Guy06882f82009-06-10 13:36:04 -0700971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 public void run() {
973 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800974 WindowManagerPolicyThread.set(this, Looper.myLooper());
975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800977 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 android.os.Process.setThreadPriority(
979 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700980 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 synchronized (this) {
984 mRunning = true;
985 notifyAll();
986 }
Romain Guy06882f82009-06-10 13:36:04 -0700987
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700988 // For debug builds, log event loop stalls to dropbox for analysis.
989 if (StrictMode.conditionallyEnableDebugLogging()) {
990 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
991 }
992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 Looper.loop();
994 }
995 }
996
997 private WindowManagerService(Context context, PowerManagerService pm,
998 boolean haveInputMethods) {
999 mContext = context;
1000 mHaveInputMethods = haveInputMethods;
1001 mLimitedAlphaCompositing = context.getResources().getBoolean(
1002 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 mPowerManager = pm;
1005 mPowerManager.setPolicy(mPolicy);
1006 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1007 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1008 "SCREEN_FROZEN");
1009 mScreenFrozenLock.setReferenceCounted(false);
1010
1011 mActivityManager = ActivityManagerNative.getDefault();
1012 mBatteryStats = BatteryStatsService.getService();
1013
1014 // Get persisted window scale setting
1015 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1016 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1017 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1018 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001019
Jim Miller284b62e2010-06-08 14:27:42 -07001020 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1021 IntentFilter filter = new IntentFilter();
1022 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1023 mContext.registerReceiver(mBroadcastReceiver, filter);
1024
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001025 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1026 "KEEP_SCREEN_ON_FLAG");
1027 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028
Jeff Browne33348b2010-07-15 23:54:05 -07001029 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1032 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 synchronized (thr) {
1035 while (!thr.mRunning) {
1036 try {
1037 thr.wait();
1038 } catch (InterruptedException e) {
1039 }
1040 }
1041 }
Romain Guy06882f82009-06-10 13:36:04 -07001042
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001043 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 // Add ourself to the Watchdog monitors.
1046 Watchdog.getInstance().addMonitor(this);
1047 }
1048
1049 @Override
1050 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1051 throws RemoteException {
1052 try {
1053 return super.onTransact(code, data, reply, flags);
1054 } catch (RuntimeException e) {
1055 // The window manager only throws security exceptions, so let's
1056 // log all others.
1057 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001058 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 }
1060 throw e;
1061 }
1062 }
1063
Jeff Browne33348b2010-07-15 23:54:05 -07001064 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 TAG, "Adding window " + window + " at "
1068 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1069 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001070 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 }
1072
Jeff Browne33348b2010-07-15 23:54:05 -07001073 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001075 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 TAG, "Adding window " + window + " at "
1077 + i + " of " + mWindows.size() + " (before " + pos + ")");
1078 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001079 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 }
1081
1082 //This method finds out the index of a window that has the same app token as
1083 //win. used for z ordering the windows in mWindows
1084 private int findIdxBasedOnAppTokens(WindowState win) {
1085 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001086 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 int jmax = localmWindows.size();
1088 if(jmax == 0) {
1089 return -1;
1090 }
1091 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001092 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 if(wentry.mAppToken == win.mAppToken) {
1094 return j;
1095 }
1096 }
1097 return -1;
1098 }
Romain Guy06882f82009-06-10 13:36:04 -07001099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1101 final IWindow client = win.mClient;
1102 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001103 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 final int N = localmWindows.size();
1106 final WindowState attached = win.mAttachedWindow;
1107 int i;
1108 if (attached == null) {
1109 int tokenWindowsPos = token.windows.size();
1110 if (token.appWindowToken != null) {
1111 int index = tokenWindowsPos-1;
1112 if (index >= 0) {
1113 // If this application has existing windows, we
1114 // simply place the new window on top of them... but
1115 // keep the starting window on top.
1116 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1117 // Base windows go behind everything else.
1118 placeWindowBefore(token.windows.get(0), win);
1119 tokenWindowsPos = 0;
1120 } else {
1121 AppWindowToken atoken = win.mAppToken;
1122 if (atoken != null &&
1123 token.windows.get(index) == atoken.startingWindow) {
1124 placeWindowBefore(token.windows.get(index), win);
1125 tokenWindowsPos--;
1126 } else {
1127 int newIdx = findIdxBasedOnAppTokens(win);
1128 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001129 //there is a window above this one associated with the same
1130 //apptoken note that the window could be a floating window
1131 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001133 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001134 TAG, "Adding window " + win + " at "
1135 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001137 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001138 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 }
1140 }
1141 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001142 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 TAG, "Figuring out where to add app window "
1144 + client.asBinder() + " (token=" + token + ")");
1145 // Figure out where the window should go, based on the
1146 // order of applications.
1147 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001148 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 for (i=NA-1; i>=0; i--) {
1150 AppWindowToken t = mAppTokens.get(i);
1151 if (t == token) {
1152 i--;
1153 break;
1154 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001155
Dianne Hackborna8f60182009-09-01 19:01:50 -07001156 // We haven't reached the token yet; if this token
1157 // is not going to the bottom and has windows, we can
1158 // use it as an anchor for when we do reach the token.
1159 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 pos = t.windows.get(0);
1161 }
1162 }
1163 // We now know the index into the apps. If we found
1164 // an app window above, that gives us the position; else
1165 // we need to look some more.
1166 if (pos != null) {
1167 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001168 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 if (atoken != null) {
1170 final int NC = atoken.windows.size();
1171 if (NC > 0) {
1172 WindowState bottom = atoken.windows.get(0);
1173 if (bottom.mSubLayer < 0) {
1174 pos = bottom;
1175 }
1176 }
1177 }
1178 placeWindowBefore(pos, win);
1179 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001180 // Continue looking down until we find the first
1181 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 while (i >= 0) {
1183 AppWindowToken t = mAppTokens.get(i);
1184 final int NW = t.windows.size();
1185 if (NW > 0) {
1186 pos = t.windows.get(NW-1);
1187 break;
1188 }
1189 i--;
1190 }
1191 if (pos != null) {
1192 // Move in front of any windows attached to this
1193 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001194 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 if (atoken != null) {
1196 final int NC = atoken.windows.size();
1197 if (NC > 0) {
1198 WindowState top = atoken.windows.get(NC-1);
1199 if (top.mSubLayer >= 0) {
1200 pos = top;
1201 }
1202 }
1203 }
1204 placeWindowAfter(pos, win);
1205 } else {
1206 // Just search for the start of this layer.
1207 final int myLayer = win.mBaseLayer;
1208 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001209 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 if (w.mBaseLayer > myLayer) {
1211 break;
1212 }
1213 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001214 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001215 TAG, "Adding window " + win + " at "
1216 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001218 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 }
1220 }
1221 }
1222 } else {
1223 // Figure out where window should go, based on layer.
1224 final int myLayer = win.mBaseLayer;
1225 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001226 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 i++;
1228 break;
1229 }
1230 }
1231 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001232 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001233 TAG, "Adding window " + win + " at "
1234 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001236 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 }
1238 if (addToToken) {
1239 token.windows.add(tokenWindowsPos, win);
1240 }
1241
1242 } else {
1243 // Figure out this window's ordering relative to the window
1244 // it is attached to.
1245 final int NA = token.windows.size();
1246 final int sublayer = win.mSubLayer;
1247 int largestSublayer = Integer.MIN_VALUE;
1248 WindowState windowWithLargestSublayer = null;
1249 for (i=0; i<NA; i++) {
1250 WindowState w = token.windows.get(i);
1251 final int wSublayer = w.mSubLayer;
1252 if (wSublayer >= largestSublayer) {
1253 largestSublayer = wSublayer;
1254 windowWithLargestSublayer = w;
1255 }
1256 if (sublayer < 0) {
1257 // For negative sublayers, we go below all windows
1258 // in the same sublayer.
1259 if (wSublayer >= sublayer) {
1260 if (addToToken) {
1261 token.windows.add(i, win);
1262 }
1263 placeWindowBefore(
1264 wSublayer >= 0 ? attached : w, win);
1265 break;
1266 }
1267 } else {
1268 // For positive sublayers, we go above all windows
1269 // in the same sublayer.
1270 if (wSublayer > sublayer) {
1271 if (addToToken) {
1272 token.windows.add(i, win);
1273 }
1274 placeWindowBefore(w, win);
1275 break;
1276 }
1277 }
1278 }
1279 if (i >= NA) {
1280 if (addToToken) {
1281 token.windows.add(win);
1282 }
1283 if (sublayer < 0) {
1284 placeWindowBefore(attached, win);
1285 } else {
1286 placeWindowAfter(largestSublayer >= 0
1287 ? windowWithLargestSublayer
1288 : attached,
1289 win);
1290 }
1291 }
1292 }
Romain Guy06882f82009-06-10 13:36:04 -07001293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 if (win.mAppToken != null && addToToken) {
1295 win.mAppToken.allAppWindows.add(win);
1296 }
1297 }
Romain Guy06882f82009-06-10 13:36:04 -07001298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 static boolean canBeImeTarget(WindowState w) {
1300 final int fl = w.mAttrs.flags
1301 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1302 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1303 return w.isVisibleOrAdding();
1304 }
1305 return false;
1306 }
Romain Guy06882f82009-06-10 13:36:04 -07001307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001309 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 final int N = localmWindows.size();
1311 WindowState w = null;
1312 int i = N;
1313 while (i > 0) {
1314 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001315 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001316
Joe Onorato8a9b2202010-02-26 18:56:32 -08001317 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 // + Integer.toHexString(w.mAttrs.flags));
1319 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001320 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 // Yet more tricksyness! If this window is a "starting"
1323 // window, we do actually want to be on top of it, but
1324 // it is not -really- where input will go. So if the caller
1325 // is not actually looking to move the IME, look down below
1326 // for a real window to target...
1327 if (!willMove
1328 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1329 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001330 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1332 i--;
1333 w = wb;
1334 }
1335 }
1336 break;
1337 }
1338 }
Romain Guy06882f82009-06-10 13:36:04 -07001339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001341
Joe Onorato8a9b2202010-02-26 18:56:32 -08001342 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 if (willMove && w != null) {
1346 final WindowState curTarget = mInputMethodTarget;
1347 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 // Now some fun for dealing with window animations that
1350 // modify the Z order. We need to look at all windows below
1351 // the current target that are in this app, finding the highest
1352 // visible one in layering.
1353 AppWindowToken token = curTarget.mAppToken;
1354 WindowState highestTarget = null;
1355 int highestPos = 0;
1356 if (token.animating || token.animation != null) {
1357 int pos = 0;
1358 pos = localmWindows.indexOf(curTarget);
1359 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001360 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 if (win.mAppToken != token) {
1362 break;
1363 }
1364 if (!win.mRemoved) {
1365 if (highestTarget == null || win.mAnimLayer >
1366 highestTarget.mAnimLayer) {
1367 highestTarget = win;
1368 highestPos = pos;
1369 }
1370 }
1371 pos--;
1372 }
1373 }
Romain Guy06882f82009-06-10 13:36:04 -07001374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001376 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 + mNextAppTransition + " " + highestTarget
1378 + " animating=" + highestTarget.isAnimating()
1379 + " layer=" + highestTarget.mAnimLayer
1380 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001381
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001382 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 // If we are currently setting up for an animation,
1384 // hold everything until we can find out what will happen.
1385 mInputMethodTargetWaitingAnim = true;
1386 mInputMethodTarget = highestTarget;
1387 return highestPos + 1;
1388 } else if (highestTarget.isAnimating() &&
1389 highestTarget.mAnimLayer > w.mAnimLayer) {
1390 // If the window we are currently targeting is involved
1391 // with an animation, and it is on top of the next target
1392 // we will be over, then hold off on moving until
1393 // that is done.
1394 mInputMethodTarget = highestTarget;
1395 return highestPos + 1;
1396 }
1397 }
1398 }
1399 }
Romain Guy06882f82009-06-10 13:36:04 -07001400
Joe Onorato8a9b2202010-02-26 18:56:32 -08001401 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 if (w != null) {
1403 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001404 if (DEBUG_INPUT_METHOD) {
1405 RuntimeException e = null;
1406 if (!HIDE_STACK_CRAWLS) {
1407 e = new RuntimeException();
1408 e.fillInStackTrace();
1409 }
1410 Slog.w(TAG, "Moving IM target from "
1411 + mInputMethodTarget + " to " + w, e);
1412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 mInputMethodTarget = w;
1414 if (w.mAppToken != null) {
1415 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1416 } else {
1417 setInputMethodAnimLayerAdjustment(0);
1418 }
1419 }
1420 return i+1;
1421 }
1422 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001423 if (DEBUG_INPUT_METHOD) {
1424 RuntimeException e = null;
1425 if (!HIDE_STACK_CRAWLS) {
1426 e = new RuntimeException();
1427 e.fillInStackTrace();
1428 }
1429 Slog.w(TAG, "Moving IM target from "
1430 + mInputMethodTarget + " to null", e);
1431 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 mInputMethodTarget = null;
1433 setInputMethodAnimLayerAdjustment(0);
1434 }
1435 return -1;
1436 }
Romain Guy06882f82009-06-10 13:36:04 -07001437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 void addInputMethodWindowToListLocked(WindowState win) {
1439 int pos = findDesiredInputMethodWindowIndexLocked(true);
1440 if (pos >= 0) {
1441 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001442 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001443 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001445 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 moveInputMethodDialogsLocked(pos+1);
1447 return;
1448 }
1449 win.mTargetAppToken = null;
1450 addWindowToListInOrderLocked(win, true);
1451 moveInputMethodDialogsLocked(pos);
1452 }
Romain Guy06882f82009-06-10 13:36:04 -07001453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001455 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 mInputMethodAnimLayerAdjustment = adj;
1457 WindowState imw = mInputMethodWindow;
1458 if (imw != null) {
1459 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001460 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 + " anim layer: " + imw.mAnimLayer);
1462 int wi = imw.mChildWindows.size();
1463 while (wi > 0) {
1464 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001465 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 + " anim layer: " + cw.mAnimLayer);
1469 }
1470 }
1471 int di = mInputMethodDialogs.size();
1472 while (di > 0) {
1473 di --;
1474 imw = mInputMethodDialogs.get(di);
1475 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001476 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 + " anim layer: " + imw.mAnimLayer);
1478 }
1479 }
Romain Guy06882f82009-06-10 13:36:04 -07001480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1482 int wpos = mWindows.indexOf(win);
1483 if (wpos >= 0) {
1484 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001485 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001487 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 int NC = win.mChildWindows.size();
1489 while (NC > 0) {
1490 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001491 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 int cpos = mWindows.indexOf(cw);
1493 if (cpos >= 0) {
1494 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001495 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001496 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 mWindows.remove(cpos);
1498 }
1499 }
1500 }
1501 return interestingPos;
1502 }
Romain Guy06882f82009-06-10 13:36:04 -07001503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 private void reAddWindowToListInOrderLocked(WindowState win) {
1505 addWindowToListInOrderLocked(win, false);
1506 // This is a hack to get all of the child windows added as well
1507 // at the right position. Child windows should be rare and
1508 // this case should be rare, so it shouldn't be that big a deal.
1509 int wpos = mWindows.indexOf(win);
1510 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001511 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001512 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001514 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 reAddWindowLocked(wpos, win);
1516 }
1517 }
Romain Guy06882f82009-06-10 13:36:04 -07001518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 void logWindowList(String prefix) {
1520 int N = mWindows.size();
1521 while (N > 0) {
1522 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001523 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 }
1525 }
Romain Guy06882f82009-06-10 13:36:04 -07001526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 void moveInputMethodDialogsLocked(int pos) {
1528 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001531 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 for (int i=0; i<N; i++) {
1533 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1534 }
1535 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001536 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 logWindowList(" ");
1538 }
Romain Guy06882f82009-06-10 13:36:04 -07001539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 if (pos >= 0) {
1541 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1542 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001543 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 if (wp == mInputMethodWindow) {
1545 pos++;
1546 }
1547 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001548 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 for (int i=0; i<N; i++) {
1550 WindowState win = dialogs.get(i);
1551 win.mTargetAppToken = targetAppToken;
1552 pos = reAddWindowLocked(pos, win);
1553 }
1554 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001555 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 logWindowList(" ");
1557 }
1558 return;
1559 }
1560 for (int i=0; i<N; i++) {
1561 WindowState win = dialogs.get(i);
1562 win.mTargetAppToken = null;
1563 reAddWindowToListInOrderLocked(win);
1564 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001565 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 logWindowList(" ");
1567 }
1568 }
1569 }
Romain Guy06882f82009-06-10 13:36:04 -07001570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1572 final WindowState imWin = mInputMethodWindow;
1573 final int DN = mInputMethodDialogs.size();
1574 if (imWin == null && DN == 0) {
1575 return false;
1576 }
Romain Guy06882f82009-06-10 13:36:04 -07001577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1579 if (imPos >= 0) {
1580 // In this case, the input method windows are to be placed
1581 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 // First check to see if the input method windows are already
1584 // located here, and contiguous.
1585 final int N = mWindows.size();
1586 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001587 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 // Figure out the actual input method window that should be
1590 // at the bottom of their stack.
1591 WindowState baseImWin = imWin != null
1592 ? imWin : mInputMethodDialogs.get(0);
1593 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001594 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 if (cw.mSubLayer < 0) baseImWin = cw;
1596 }
Romain Guy06882f82009-06-10 13:36:04 -07001597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 if (firstImWin == baseImWin) {
1599 // The windows haven't moved... but are they still contiguous?
1600 // First find the top IM window.
1601 int pos = imPos+1;
1602 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001603 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 break;
1605 }
1606 pos++;
1607 }
1608 pos++;
1609 // Now there should be no more input method windows above.
1610 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001611 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 break;
1613 }
1614 pos++;
1615 }
1616 if (pos >= N) {
1617 // All is good!
1618 return false;
1619 }
1620 }
Romain Guy06882f82009-06-10 13:36:04 -07001621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622 if (imWin != null) {
1623 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001624 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 logWindowList(" ");
1626 }
1627 imPos = tmpRemoveWindowLocked(imPos, imWin);
1628 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001629 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 logWindowList(" ");
1631 }
1632 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1633 reAddWindowLocked(imPos, imWin);
1634 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001635 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 logWindowList(" ");
1637 }
1638 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1639 } else {
1640 moveInputMethodDialogsLocked(imPos);
1641 }
Romain Guy06882f82009-06-10 13:36:04 -07001642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 } else {
1644 // In this case, the input method windows go in a fixed layer,
1645 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001648 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 tmpRemoveWindowLocked(0, imWin);
1650 imWin.mTargetAppToken = null;
1651 reAddWindowToListInOrderLocked(imWin);
1652 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001653 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 logWindowList(" ");
1655 }
1656 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1657 } else {
1658 moveInputMethodDialogsLocked(-1);;
1659 }
Romain Guy06882f82009-06-10 13:36:04 -07001660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 }
Romain Guy06882f82009-06-10 13:36:04 -07001662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 if (needAssignLayers) {
1664 assignLayersLocked();
1665 }
Romain Guy06882f82009-06-10 13:36:04 -07001666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 return true;
1668 }
Romain Guy06882f82009-06-10 13:36:04 -07001669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 void adjustInputMethodDialogsLocked() {
1671 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1672 }
Romain Guy06882f82009-06-10 13:36:04 -07001673
Dianne Hackborn25994b42009-09-04 14:21:19 -07001674 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001675 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001676 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1677 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1678 ? wallpaperTarget.mAppToken.animation : null)
1679 + " upper=" + mUpperWallpaperTarget
1680 + " lower=" + mLowerWallpaperTarget);
1681 return (wallpaperTarget != null
1682 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1683 && wallpaperTarget.mAppToken.animation != null)))
1684 || mUpperWallpaperTarget != null
1685 || mLowerWallpaperTarget != null;
1686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001687
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001688 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1689 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001690
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001691 int adjustWallpaperWindowsLocked() {
1692 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001693
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001694 final int dw = mDisplay.getWidth();
1695 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001696
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001697 // First find top-most window that has asked to be on top of the
1698 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001699 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001700 int N = localmWindows.size();
1701 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001702 WindowState foundW = null;
1703 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001704 WindowState topCurW = null;
1705 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001706 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001707 int i = N;
1708 while (i > 0) {
1709 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001710 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001711 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1712 if (topCurW == null) {
1713 topCurW = w;
1714 topCurI = i;
1715 }
1716 continue;
1717 }
1718 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001719 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001720 // If this window's app token is hidden and not animating,
1721 // it is of no interest to us.
1722 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001723 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001724 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001725 continue;
1726 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001727 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001728 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001729 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1730 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001731 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001732 && (mWallpaperTarget == w
1733 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001734 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001735 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001736 foundW = w;
1737 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001738 if (w == mWallpaperTarget && ((w.mAppToken != null
1739 && w.mAppToken.animation != null)
1740 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 // The current wallpaper target is animating, so we'll
1742 // look behind it for another possible target and figure
1743 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001744 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001745 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001746 continue;
1747 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001748 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001749 } else if (w == mWindowDetachedWallpaper) {
1750 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001751 }
1752 }
1753
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001754 if (foundW == null && windowDetachedI >= 0) {
1755 if (DEBUG_WALLPAPER) Slog.v(TAG,
1756 "Found animating detached wallpaper activity: #" + i + "=" + w);
1757 foundW = w;
1758 foundI = windowDetachedI;
1759 }
1760
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001761 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001762 // If we are currently waiting for an app transition, and either
1763 // the current target or the next target are involved with it,
1764 // then hold off on doing anything with the wallpaper.
1765 // Note that we are checking here for just whether the target
1766 // is part of an app token... which is potentially overly aggressive
1767 // (the app token may not be involved in the transition), but good
1768 // enough (we'll just wait until whatever transition is pending
1769 // executes).
1770 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001771 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001772 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001773 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001774 }
1775 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001776 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001777 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001778 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001779 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001780 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001781
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001782 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001783 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001784 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001785 + " oldTarget: " + mWallpaperTarget);
1786 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001787
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001788 mLowerWallpaperTarget = null;
1789 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001790
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001791 WindowState oldW = mWallpaperTarget;
1792 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001793
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001794 // Now what is happening... if the current and new targets are
1795 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001796 if (foundW != null && oldW != null) {
1797 boolean oldAnim = oldW.mAnimation != null
1798 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1799 boolean foundAnim = foundW.mAnimation != null
1800 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001802 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001803 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001804 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001805 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 int oldI = localmWindows.indexOf(oldW);
1807 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001808 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001809 }
1810 if (oldI >= 0) {
1811 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001812 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001813 + "=" + oldW + "; new#" + foundI
1814 + "=" + foundW);
1815 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001816
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001817 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001818 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001819 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001820 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001821 }
1822 mWallpaperTarget = oldW;
1823 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001824
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001825 // Now set the upper and lower wallpaper targets
1826 // correctly, and make sure that we are positioning
1827 // the wallpaper below the lower.
1828 if (foundI > oldI) {
1829 // The new target is on top of the old one.
1830 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001831 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001832 }
1833 mUpperWallpaperTarget = foundW;
1834 mLowerWallpaperTarget = oldW;
1835 foundW = oldW;
1836 foundI = oldI;
1837 } else {
1838 // The new target is below the old one.
1839 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001840 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001841 }
1842 mUpperWallpaperTarget = oldW;
1843 mLowerWallpaperTarget = foundW;
1844 }
1845 }
1846 }
1847 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001848
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001849 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001850 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001851 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1852 || (mLowerWallpaperTarget.mAppToken != null
1853 && mLowerWallpaperTarget.mAppToken.animation != null);
1854 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1855 || (mUpperWallpaperTarget.mAppToken != null
1856 && mUpperWallpaperTarget.mAppToken.animation != null);
1857 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001858 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001859 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001860 }
1861 mLowerWallpaperTarget = null;
1862 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001863 }
1864 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001865
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001866 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001867 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001868 // The window is visible to the compositor... but is it visible
1869 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001870 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001871 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001872
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001873 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001874 // its layer adjustment. Only do this if we are not transfering
1875 // between two wallpaper targets.
1876 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001877 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001878 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001879
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001880 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1881 * TYPE_LAYER_MULTIPLIER
1882 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001883
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001884 // Now w is the window we are supposed to be behind... but we
1885 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001886 // AND any starting window associated with it, AND below the
1887 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001888 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001889 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001890 if (wb.mBaseLayer < maxLayer &&
1891 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001892 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001893 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001894 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001895 // This window is not related to the previous one in any
1896 // interesting way, so stop here.
1897 break;
1898 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001899 foundW = wb;
1900 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001901 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001902 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001903 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001904 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001905
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001906 if (foundW == null && topCurW != null) {
1907 // There is no wallpaper target, so it goes at the bottom.
1908 // We will assume it is the same place as last time, if known.
1909 foundW = topCurW;
1910 foundI = topCurI+1;
1911 } else {
1912 // Okay i is the position immediately above the wallpaper. Look at
1913 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001914 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001915 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001916
Dianne Hackborn284ac932009-08-28 10:34:25 -07001917 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001918 if (mWallpaperTarget.mWallpaperX >= 0) {
1919 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001920 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001921 }
1922 if (mWallpaperTarget.mWallpaperY >= 0) {
1923 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001924 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001925 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001926 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001927
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001928 // Start stepping backwards from here, ensuring that our wallpaper windows
1929 // are correctly placed.
1930 int curTokenIndex = mWallpaperTokens.size();
1931 while (curTokenIndex > 0) {
1932 curTokenIndex--;
1933 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001934 if (token.hidden == visible) {
1935 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1936 token.hidden = !visible;
1937 // Need to do a layout to ensure the wallpaper now has the
1938 // correct size.
1939 mLayoutNeeded = true;
1940 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001941
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001942 int curWallpaperIndex = token.windows.size();
1943 while (curWallpaperIndex > 0) {
1944 curWallpaperIndex--;
1945 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001946
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001947 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001948 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001949 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001950
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001951 // First, make sure the client has the current visibility
1952 // state.
1953 if (wallpaper.mWallpaperVisible != visible) {
1954 wallpaper.mWallpaperVisible = visible;
1955 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001956 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001957 "Setting visibility of wallpaper " + wallpaper
1958 + ": " + visible);
1959 wallpaper.mClient.dispatchAppVisibility(visible);
1960 } catch (RemoteException e) {
1961 }
1962 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001963
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001964 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001965 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001966 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001967
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001968 // First, if this window is at the current index, then all
1969 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001970 if (wallpaper == foundW) {
1971 foundI--;
1972 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001973 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001974 continue;
1975 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001976
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001977 // The window didn't match... the current wallpaper window,
1978 // wherever it is, is in the wrong place, so make sure it is
1979 // not in the list.
1980 int oldIndex = localmWindows.indexOf(wallpaper);
1981 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001982 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001983 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001984 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001985 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001986 if (oldIndex < foundI) {
1987 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001988 }
1989 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001990
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001991 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001992 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001993 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001994 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001995
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001996 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001997 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001998 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001999 }
2000 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002001
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002002 return changed;
2003 }
2004
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002005 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002006 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002007 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002008 mWallpaperAnimLayerAdjustment = adj;
2009 int curTokenIndex = mWallpaperTokens.size();
2010 while (curTokenIndex > 0) {
2011 curTokenIndex--;
2012 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2013 int curWallpaperIndex = token.windows.size();
2014 while (curWallpaperIndex > 0) {
2015 curWallpaperIndex--;
2016 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2017 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002018 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002019 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002020 }
2021 }
2022 }
2023
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002024 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2025 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002026 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002027 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002028 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002029 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002030 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2031 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2032 changed = wallpaperWin.mXOffset != offset;
2033 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002034 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002035 + wallpaperWin + " x: " + offset);
2036 wallpaperWin.mXOffset = offset;
2037 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002038 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002039 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002040 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002041 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002042 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002043
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002044 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002045 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002046 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2047 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2048 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002049 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002050 + wallpaperWin + " y: " + offset);
2051 changed = true;
2052 wallpaperWin.mYOffset = offset;
2053 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002054 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002055 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002056 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002057 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002058 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002059
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002060 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002061 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002062 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002063 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2064 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002065 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002066 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002067 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002068 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002069 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2070 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002071 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002072 if (mWaitingOnWallpaper != null) {
2073 long start = SystemClock.uptimeMillis();
2074 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2075 < start) {
2076 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002077 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002078 "Waiting for offset complete...");
2079 mWindowMap.wait(WALLPAPER_TIMEOUT);
2080 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002081 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002082 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002083 if ((start+WALLPAPER_TIMEOUT)
2084 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002085 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002086 + wallpaperWin);
2087 mLastWallpaperTimeoutTime = start;
2088 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002089 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002090 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002091 }
2092 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002093 } catch (RemoteException e) {
2094 }
2095 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002096
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002097 return changed;
2098 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002099
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002100 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002101 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002102 if (mWaitingOnWallpaper != null &&
2103 mWaitingOnWallpaper.mClient.asBinder() == window) {
2104 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002105 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002106 }
2107 }
2108 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002109
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002110 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002111 final int dw = mDisplay.getWidth();
2112 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002113
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002114 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002115
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002116 WindowState target = mWallpaperTarget;
2117 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002118 if (target.mWallpaperX >= 0) {
2119 mLastWallpaperX = target.mWallpaperX;
2120 } else if (changingTarget.mWallpaperX >= 0) {
2121 mLastWallpaperX = changingTarget.mWallpaperX;
2122 }
2123 if (target.mWallpaperY >= 0) {
2124 mLastWallpaperY = target.mWallpaperY;
2125 } else if (changingTarget.mWallpaperY >= 0) {
2126 mLastWallpaperY = changingTarget.mWallpaperY;
2127 }
2128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002129
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002130 int curTokenIndex = mWallpaperTokens.size();
2131 while (curTokenIndex > 0) {
2132 curTokenIndex--;
2133 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2134 int curWallpaperIndex = token.windows.size();
2135 while (curWallpaperIndex > 0) {
2136 curWallpaperIndex--;
2137 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2138 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2139 wallpaper.computeShownFrameLocked();
2140 changed = true;
2141 // We only want to be synchronous with one wallpaper.
2142 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002143 }
2144 }
2145 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002146
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002147 return changed;
2148 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002149
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002150 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002151 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002152 final int dw = mDisplay.getWidth();
2153 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002154
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002155 int curTokenIndex = mWallpaperTokens.size();
2156 while (curTokenIndex > 0) {
2157 curTokenIndex--;
2158 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002159 if (token.hidden == visible) {
2160 token.hidden = !visible;
2161 // Need to do a layout to ensure the wallpaper now has the
2162 // correct size.
2163 mLayoutNeeded = true;
2164 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002165
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002166 int curWallpaperIndex = token.windows.size();
2167 while (curWallpaperIndex > 0) {
2168 curWallpaperIndex--;
2169 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2170 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002171 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002172 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002173
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002174 if (wallpaper.mWallpaperVisible != visible) {
2175 wallpaper.mWallpaperVisible = visible;
2176 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002177 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002178 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002179 + ": " + visible);
2180 wallpaper.mClient.dispatchAppVisibility(visible);
2181 } catch (RemoteException e) {
2182 }
2183 }
2184 }
2185 }
2186 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 public int addWindow(Session session, IWindow client,
2189 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002190 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 int res = mPolicy.checkAddPermission(attrs);
2192 if (res != WindowManagerImpl.ADD_OKAY) {
2193 return res;
2194 }
Romain Guy06882f82009-06-10 13:36:04 -07002195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 boolean reportNewConfig = false;
2197 WindowState attachedWindow = null;
2198 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002199 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002203 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 }
Romain Guy06882f82009-06-10 13:36:04 -07002205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002207 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2209 }
2210
2211 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002212 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002214 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 + attrs.token + ". Aborting.");
2216 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2217 }
2218 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2219 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002220 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 + attrs.token + ". Aborting.");
2222 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2223 }
2224 }
2225
2226 boolean addToken = false;
2227 WindowToken token = mTokenMap.get(attrs.token);
2228 if (token == null) {
2229 if (attrs.type >= FIRST_APPLICATION_WINDOW
2230 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002231 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 + attrs.token + ". Aborting.");
2233 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2234 }
2235 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002236 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 + attrs.token + ". Aborting.");
2238 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2239 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002240 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002241 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002242 + attrs.token + ". Aborting.");
2243 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 token = new WindowToken(attrs.token, -1, false);
2246 addToken = true;
2247 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2248 && attrs.type <= LAST_APPLICATION_WINDOW) {
2249 AppWindowToken atoken = token.appWindowToken;
2250 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002251 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 + token + ". Aborting.");
2253 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2254 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002255 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 + token + ". Aborting.");
2257 return WindowManagerImpl.ADD_APP_EXITING;
2258 }
2259 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2260 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002261 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2263 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2264 }
2265 } else if (attrs.type == TYPE_INPUT_METHOD) {
2266 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002267 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 + attrs.token + ". Aborting.");
2269 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2270 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002271 } else if (attrs.type == TYPE_WALLPAPER) {
2272 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002273 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002274 + attrs.token + ". Aborting.");
2275 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 }
2278
2279 win = new WindowState(session, client, token,
2280 attachedWindow, attrs, viewVisibility);
2281 if (win.mDeathRecipient == null) {
2282 // Client has apparently died, so there is no reason to
2283 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002284 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 + " that is dead, aborting.");
2286 return WindowManagerImpl.ADD_APP_EXITING;
2287 }
2288
2289 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 res = mPolicy.prepareAddWindowLw(win, attrs);
2292 if (res != WindowManagerImpl.ADD_OKAY) {
2293 return res;
2294 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002295
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002296 if (outInputChannel != null) {
2297 String name = win.makeInputChannelName();
2298 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2299 win.mInputChannel = inputChannels[0];
2300 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2301
2302 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002303 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304
2305 // From now on, no exceptions or errors allowed!
2306
2307 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002308
Dianne Hackborn5132b372010-07-29 12:51:35 -07002309 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 if (addToken) {
2312 mTokenMap.put(attrs.token, token);
2313 mTokenList.add(token);
2314 }
2315 win.attach();
2316 mWindowMap.put(client.asBinder(), win);
2317
2318 if (attrs.type == TYPE_APPLICATION_STARTING &&
2319 token.appWindowToken != null) {
2320 token.appWindowToken.startingWindow = win;
2321 }
2322
2323 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 if (attrs.type == TYPE_INPUT_METHOD) {
2326 mInputMethodWindow = win;
2327 addInputMethodWindowToListLocked(win);
2328 imMayMove = false;
2329 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2330 mInputMethodDialogs.add(win);
2331 addWindowToListInOrderLocked(win, true);
2332 adjustInputMethodDialogsLocked();
2333 imMayMove = false;
2334 } else {
2335 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002336 if (attrs.type == TYPE_WALLPAPER) {
2337 mLastWallpaperTimeoutTime = 0;
2338 adjustWallpaperWindowsLocked();
2339 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002340 adjustWallpaperWindowsLocked();
2341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 }
Romain Guy06882f82009-06-10 13:36:04 -07002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 if (mInTouchMode) {
2349 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2350 }
2351 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2352 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2353 }
Romain Guy06882f82009-06-10 13:36:04 -07002354
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002355 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002357 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2358 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 imMayMove = false;
2360 }
2361 }
Romain Guy06882f82009-06-10 13:36:04 -07002362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002364 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 }
Romain Guy06882f82009-06-10 13:36:04 -07002366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 assignLayersLocked();
2368 // Don't do layout here, the window must call
2369 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 //dump();
2372
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002373 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002374 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002375 }
Jeff Brown349703e2010-06-22 01:27:15 -07002376
Joe Onorato8a9b2202010-02-26 18:56:32 -08002377 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 TAG, "New client " + client.asBinder()
2379 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002380
2381 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2382 reportNewConfig = true;
2383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 }
2385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 if (reportNewConfig) {
2387 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 return res;
2393 }
Romain Guy06882f82009-06-10 13:36:04 -07002394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 public void removeWindow(Session session, IWindow client) {
2396 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002397 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 if (win == null) {
2399 return;
2400 }
2401 removeWindowLocked(session, win);
2402 }
2403 }
Romain Guy06882f82009-06-10 13:36:04 -07002404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 public void removeWindowLocked(Session session, WindowState win) {
2406
Joe Onorato8a9b2202010-02-26 18:56:32 -08002407 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 TAG, "Remove " + win + " client="
2409 + Integer.toHexString(System.identityHashCode(
2410 win.mClient.asBinder()))
2411 + ", surface=" + win.mSurface);
2412
2413 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002414
2415 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002416
Joe Onorato8a9b2202010-02-26 18:56:32 -08002417 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2419 + " mExiting=" + win.mExiting
2420 + " isAnimating=" + win.isAnimating()
2421 + " app-animation="
2422 + (win.mAppToken != null ? win.mAppToken.animation : null)
2423 + " inPendingTransaction="
2424 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2425 + " mDisplayFrozen=" + mDisplayFrozen);
2426 // Visibility of the removed window. Will be used later to update orientation later on.
2427 boolean wasVisible = false;
2428 // First, see if we need to run an animation. If we do, we have
2429 // to hold off on removing the window until the animation is done.
2430 // If the display is frozen, just remove immediately, since the
2431 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002432 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 // If we are not currently running the exit animation, we
2434 // need to see about starting one.
2435 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2438 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2439 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2440 }
2441 // Try starting an animation.
2442 if (applyAnimationLocked(win, transit, false)) {
2443 win.mExiting = true;
2444 }
2445 }
2446 if (win.mExiting || win.isAnimating()) {
2447 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002448 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 win.mExiting = true;
2450 win.mRemoveOnExit = true;
2451 mLayoutNeeded = true;
2452 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2453 performLayoutAndPlaceSurfacesLocked();
2454 if (win.mAppToken != null) {
2455 win.mAppToken.updateReportedVisibilityLocked();
2456 }
2457 //dump();
2458 Binder.restoreCallingIdentity(origId);
2459 return;
2460 }
2461 }
2462
2463 removeWindowInnerLocked(session, win);
2464 // Removing a visible window will effect the computed orientation
2465 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002466 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002467 != mForcedAppOrientation
2468 && updateOrientationFromAppTokensLocked()) {
2469 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 }
2471 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2472 Binder.restoreCallingIdentity(origId);
2473 }
Romain Guy06882f82009-06-10 13:36:04 -07002474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 if (mInputMethodTarget == win) {
2479 moveInputMethodWindowsIfNeededLocked(false);
2480 }
Romain Guy06882f82009-06-10 13:36:04 -07002481
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002482 if (false) {
2483 RuntimeException e = new RuntimeException("here");
2484 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002485 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002486 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 mPolicy.removeWindowLw(win);
2489 win.removeLocked();
2490
2491 mWindowMap.remove(win.mClient.asBinder());
2492 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002493 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002494 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495
2496 if (mInputMethodWindow == win) {
2497 mInputMethodWindow = null;
2498 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2499 mInputMethodDialogs.remove(win);
2500 }
Romain Guy06882f82009-06-10 13:36:04 -07002501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 final WindowToken token = win.mToken;
2503 final AppWindowToken atoken = win.mAppToken;
2504 token.windows.remove(win);
2505 if (atoken != null) {
2506 atoken.allAppWindows.remove(win);
2507 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002508 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 TAG, "**** Removing window " + win + ": count="
2510 + token.windows.size());
2511 if (token.windows.size() == 0) {
2512 if (!token.explicit) {
2513 mTokenMap.remove(token.token);
2514 mTokenList.remove(token);
2515 } else if (atoken != null) {
2516 atoken.firstWindowDrawn = false;
2517 }
2518 }
2519
2520 if (atoken != null) {
2521 if (atoken.startingWindow == win) {
2522 atoken.startingWindow = null;
2523 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2524 // If this is the last window and we had requested a starting
2525 // transition window, well there is no point now.
2526 atoken.startingData = null;
2527 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2528 // If this is the last window except for a starting transition
2529 // window, we need to get rid of the starting transition.
2530 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002531 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 + ": no more real windows");
2533 }
2534 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2535 mH.sendMessage(m);
2536 }
2537 }
Romain Guy06882f82009-06-10 13:36:04 -07002538
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002539 if (win.mAttrs.type == TYPE_WALLPAPER) {
2540 mLastWallpaperTimeoutTime = 0;
2541 adjustWallpaperWindowsLocked();
2542 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002543 adjustWallpaperWindowsLocked();
2544 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 if (!mInLayout) {
2547 assignLayersLocked();
2548 mLayoutNeeded = true;
2549 performLayoutAndPlaceSurfacesLocked();
2550 if (win.mAppToken != null) {
2551 win.mAppToken.updateReportedVisibilityLocked();
2552 }
2553 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002554
2555 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 }
2557
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002558 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2559 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2560 + ": " + msg + " / " + w.mAttrs.getTitle();
2561 if (where != null) {
2562 Slog.i(TAG, str, where);
2563 } else {
2564 Slog.i(TAG, str);
2565 }
2566 }
2567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2569 long origId = Binder.clearCallingIdentity();
2570 try {
2571 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002572 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002574 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 Surface.openTransaction();
2576 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002577 if (SHOW_TRANSACTIONS) logSurface(w,
2578 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 w.mSurface.setTransparentRegionHint(region);
2580 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002581 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 Surface.closeTransaction();
2583 }
2584 }
2585 }
2586 } finally {
2587 Binder.restoreCallingIdentity(origId);
2588 }
2589 }
2590
2591 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002592 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 Rect visibleInsets) {
2594 long origId = Binder.clearCallingIdentity();
2595 try {
2596 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002597 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 if (w != null) {
2599 w.mGivenInsetsPending = false;
2600 w.mGivenContentInsets.set(contentInsets);
2601 w.mGivenVisibleInsets.set(visibleInsets);
2602 w.mTouchableInsets = touchableInsets;
2603 mLayoutNeeded = true;
2604 performLayoutAndPlaceSurfacesLocked();
2605 }
2606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(origId);
2609 }
2610 }
Romain Guy06882f82009-06-10 13:36:04 -07002611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 public void getWindowDisplayFrame(Session session, IWindow client,
2613 Rect outDisplayFrame) {
2614 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002615 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002616 if (win == null) {
2617 outDisplayFrame.setEmpty();
2618 return;
2619 }
2620 outDisplayFrame.set(win.mDisplayFrame);
2621 }
2622 }
2623
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002624 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2625 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002626 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2627 window.mWallpaperX = x;
2628 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002629 window.mWallpaperXStep = xStep;
2630 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002631 if (updateWallpaperOffsetLocked(window, true)) {
2632 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002633 }
2634 }
2635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002636
Dianne Hackborn75804932009-10-20 20:15:20 -07002637 void wallpaperCommandComplete(IBinder window, Bundle result) {
2638 synchronized (mWindowMap) {
2639 if (mWaitingOnWallpaper != null &&
2640 mWaitingOnWallpaper.mClient.asBinder() == window) {
2641 mWaitingOnWallpaper = null;
2642 mWindowMap.notifyAll();
2643 }
2644 }
2645 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002646
Dianne Hackborn75804932009-10-20 20:15:20 -07002647 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2648 String action, int x, int y, int z, Bundle extras, boolean sync) {
2649 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2650 || window == mUpperWallpaperTarget) {
2651 boolean doWait = sync;
2652 int curTokenIndex = mWallpaperTokens.size();
2653 while (curTokenIndex > 0) {
2654 curTokenIndex--;
2655 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2656 int curWallpaperIndex = token.windows.size();
2657 while (curWallpaperIndex > 0) {
2658 curWallpaperIndex--;
2659 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2660 try {
2661 wallpaper.mClient.dispatchWallpaperCommand(action,
2662 x, y, z, extras, sync);
2663 // We only want to be synchronous with one wallpaper.
2664 sync = false;
2665 } catch (RemoteException e) {
2666 }
2667 }
2668 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002669
Dianne Hackborn75804932009-10-20 20:15:20 -07002670 if (doWait) {
2671 // XXX Need to wait for result.
2672 }
2673 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002674
Dianne Hackborn75804932009-10-20 20:15:20 -07002675 return null;
2676 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002678 public int relayoutWindow(Session session, IWindow client,
2679 WindowManager.LayoutParams attrs, int requestedWidth,
2680 int requestedHeight, int viewVisibility, boolean insetsPending,
2681 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002682 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 boolean displayed = false;
2684 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002685 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002689 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 if (win == null) {
2691 return 0;
2692 }
2693 win.mRequestedWidth = requestedWidth;
2694 win.mRequestedHeight = requestedHeight;
2695
2696 if (attrs != null) {
2697 mPolicy.adjustWindowParamsLw(attrs);
2698 }
Romain Guy06882f82009-06-10 13:36:04 -07002699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 int attrChanges = 0;
2701 int flagChanges = 0;
2702 if (attrs != null) {
2703 flagChanges = win.mAttrs.flags ^= attrs.flags;
2704 attrChanges = win.mAttrs.copyFrom(attrs);
2705 }
2706
Joe Onorato8a9b2202010-02-26 18:56:32 -08002707 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708
2709 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2710 win.mAlpha = attrs.alpha;
2711 }
2712
2713 final boolean scaledWindow =
2714 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2715
2716 if (scaledWindow) {
2717 // requested{Width|Height} Surface's physical size
2718 // attrs.{width|height} Size on screen
2719 win.mHScale = (attrs.width != requestedWidth) ?
2720 (attrs.width / (float)requestedWidth) : 1.0f;
2721 win.mVScale = (attrs.height != requestedHeight) ?
2722 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002723 } else {
2724 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002725 }
2726
2727 boolean imMayMove = (flagChanges&(
2728 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2729 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 boolean focusMayChange = win.mViewVisibility != viewVisibility
2732 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2733 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002734
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002735 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2736 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 win.mRelayoutCalled = true;
2739 final int oldVisibility = win.mViewVisibility;
2740 win.mViewVisibility = viewVisibility;
2741 if (viewVisibility == View.VISIBLE &&
2742 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2743 displayed = !win.isVisibleLw();
2744 if (win.mExiting) {
2745 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002746 if (win.mAnimation != null) {
2747 win.mAnimation.cancel();
2748 win.mAnimation = null;
2749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 }
2751 if (win.mDestroying) {
2752 win.mDestroying = false;
2753 mDestroySurface.remove(win);
2754 }
2755 if (oldVisibility == View.GONE) {
2756 win.mEnterAnimationPending = true;
2757 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002758 if (displayed) {
2759 if (win.mSurface != null && !win.mDrawPending
2760 && !win.mCommitDrawPending && !mDisplayFrozen
2761 && mPolicy.isScreenOn()) {
2762 applyEnterAnimationLocked(win);
2763 }
2764 if ((win.mAttrs.flags
2765 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2766 if (DEBUG_VISIBILITY) Slog.v(TAG,
2767 "Relayout window turning screen on: " + win);
2768 win.mTurnOnScreen = true;
2769 }
2770 int diff = 0;
2771 if (win.mConfiguration != mCurConfiguration
2772 && (win.mConfiguration == null
2773 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2774 win.mConfiguration = mCurConfiguration;
2775 if (DEBUG_CONFIGURATION) {
2776 Slog.i(TAG, "Window " + win + " visible with new config: "
2777 + win.mConfiguration + " / 0x"
2778 + Integer.toHexString(diff));
2779 }
2780 outConfig.setTo(mCurConfiguration);
2781 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002782 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2784 // To change the format, we need to re-build the surface.
2785 win.destroySurfaceLocked();
2786 displayed = true;
2787 }
2788 try {
2789 Surface surface = win.createSurfaceLocked();
2790 if (surface != null) {
2791 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002792 win.mReportDestroySurface = false;
2793 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002794 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002795 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002797 // For some reason there isn't a surface. Clear the
2798 // caller's object so they see the same state.
2799 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 }
2801 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002802 mInputMonitor.updateInputWindowsLw();
2803
Joe Onorato8a9b2202010-02-26 18:56:32 -08002804 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002805 + client + " (" + win.mAttrs.getTitle() + ")",
2806 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 Binder.restoreCallingIdentity(origId);
2808 return 0;
2809 }
2810 if (displayed) {
2811 focusMayChange = true;
2812 }
2813 if (win.mAttrs.type == TYPE_INPUT_METHOD
2814 && mInputMethodWindow == null) {
2815 mInputMethodWindow = win;
2816 imMayMove = true;
2817 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002818 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2819 && win.mAppToken != null
2820 && win.mAppToken.startingWindow != null) {
2821 // Special handling of starting window over the base
2822 // window of the app: propagate lock screen flags to it,
2823 // to provide the correct semantics while starting.
2824 final int mask =
2825 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002826 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2827 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002828 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2829 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831 } else {
2832 win.mEnterAnimationPending = false;
2833 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002834 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002835 + ": mExiting=" + win.mExiting
2836 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 // If we are not currently running the exit animation, we
2838 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002839 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 // Try starting an animation; if there isn't one, we
2841 // can destroy the surface right away.
2842 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2843 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2844 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2845 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002846 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002848 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 } else if (win.isAnimating()) {
2851 // Currently in a hide animation... turn this into
2852 // an exit.
2853 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002854 } else if (win == mWallpaperTarget) {
2855 // If the wallpaper is currently behind this
2856 // window, we need to change both of them inside
2857 // of a transaction to avoid artifacts.
2858 win.mExiting = true;
2859 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 } else {
2861 if (mInputMethodWindow == win) {
2862 mInputMethodWindow = null;
2863 }
2864 win.destroySurfaceLocked();
2865 }
2866 }
2867 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002868
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002869 if (win.mSurface == null || (win.getAttrs().flags
2870 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2871 || win.mSurfacePendingDestroy) {
2872 // We are being called from a local process, which
2873 // means outSurface holds its current surface. Ensure the
2874 // surface object is cleared, but we don't want it actually
2875 // destroyed at this point.
2876 win.mSurfacePendingDestroy = false;
2877 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002878 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002879 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002880 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002881 "Keeping surface, will report destroy: " + win);
2882 win.mReportDestroySurface = true;
2883 outSurface.copyFrom(win.mSurface);
2884 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 }
2886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 if (focusMayChange) {
2888 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2889 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 imMayMove = false;
2891 }
2892 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2893 }
Romain Guy06882f82009-06-10 13:36:04 -07002894
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002895 // updateFocusedWindowLocked() already assigned layers so we only need to
2896 // reassign them at this point if the IM window state gets shuffled
2897 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002900 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2901 // Little hack here -- we -should- be able to rely on the
2902 // function to return true if the IME has moved and needs
2903 // its layer recomputed. However, if the IME was hidden
2904 // and isn't actually moved in the list, its layer may be
2905 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 assignLayers = true;
2907 }
2908 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002909 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002910 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002911 assignLayers = true;
2912 }
2913 }
Romain Guy06882f82009-06-10 13:36:04 -07002914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 mLayoutNeeded = true;
2916 win.mGivenInsetsPending = insetsPending;
2917 if (assignLayers) {
2918 assignLayersLocked();
2919 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002920 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002922 if (displayed && win.mIsWallpaper) {
2923 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002924 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002925 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 if (win.mAppToken != null) {
2927 win.mAppToken.updateReportedVisibilityLocked();
2928 }
2929 outFrame.set(win.mFrame);
2930 outContentInsets.set(win.mContentInsets);
2931 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002932 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002934 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 + ", requestedHeight=" + requestedHeight
2936 + ", viewVisibility=" + viewVisibility
2937 + "\nRelayout returning frame=" + outFrame
2938 + ", surface=" + outSurface);
2939
Joe Onorato8a9b2202010-02-26 18:56:32 -08002940 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2942
2943 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002944
2945 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 }
2947
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002948 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 sendNewConfiguration();
2950 }
Romain Guy06882f82009-06-10 13:36:04 -07002951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2955 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2956 }
2957
2958 public void finishDrawingWindow(Session session, IWindow client) {
2959 final long origId = Binder.clearCallingIdentity();
2960 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002961 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002963 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2964 adjustWallpaperWindowsLocked();
2965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 mLayoutNeeded = true;
2967 performLayoutAndPlaceSurfacesLocked();
2968 }
2969 }
2970 Binder.restoreCallingIdentity(origId);
2971 }
2972
2973 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002974 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 + (lp != null ? lp.packageName : null)
2976 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2977 if (lp != null && lp.windowAnimations != 0) {
2978 // If this is a system resource, don't try to load it from the
2979 // application resources. It is nice to avoid loading application
2980 // resources if we can.
2981 String packageName = lp.packageName != null ? lp.packageName : "android";
2982 int resId = lp.windowAnimations;
2983 if ((resId&0xFF000000) == 0x01000000) {
2984 packageName = "android";
2985 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002986 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 + packageName);
2988 return AttributeCache.instance().get(packageName, resId,
2989 com.android.internal.R.styleable.WindowAnimation);
2990 }
2991 return null;
2992 }
Romain Guy06882f82009-06-10 13:36:04 -07002993
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002994 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002995 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002996 + packageName + " resId=0x" + Integer.toHexString(resId));
2997 if (packageName != null) {
2998 if ((resId&0xFF000000) == 0x01000000) {
2999 packageName = "android";
3000 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003001 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003002 + packageName);
3003 return AttributeCache.instance().get(packageName, resId,
3004 com.android.internal.R.styleable.WindowAnimation);
3005 }
3006 return null;
3007 }
3008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 private void applyEnterAnimationLocked(WindowState win) {
3010 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3011 if (win.mEnterAnimationPending) {
3012 win.mEnterAnimationPending = false;
3013 transit = WindowManagerPolicy.TRANSIT_ENTER;
3014 }
3015
3016 applyAnimationLocked(win, transit, true);
3017 }
3018
3019 private boolean applyAnimationLocked(WindowState win,
3020 int transit, boolean isEntrance) {
3021 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3022 // If we are trying to apply an animation, but already running
3023 // an animation of the same type, then just leave that one alone.
3024 return true;
3025 }
Romain Guy06882f82009-06-10 13:36:04 -07003026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 // Only apply an animation if the display isn't frozen. If it is
3028 // frozen, there is no reason to animate and it can cause strange
3029 // artifacts when we unfreeze the display if some different animation
3030 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003031 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 int anim = mPolicy.selectAnimationLw(win, transit);
3033 int attr = -1;
3034 Animation a = null;
3035 if (anim != 0) {
3036 a = AnimationUtils.loadAnimation(mContext, anim);
3037 } else {
3038 switch (transit) {
3039 case WindowManagerPolicy.TRANSIT_ENTER:
3040 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3041 break;
3042 case WindowManagerPolicy.TRANSIT_EXIT:
3043 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3044 break;
3045 case WindowManagerPolicy.TRANSIT_SHOW:
3046 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3047 break;
3048 case WindowManagerPolicy.TRANSIT_HIDE:
3049 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3050 break;
3051 }
3052 if (attr >= 0) {
3053 a = loadAnimation(win.mAttrs, attr);
3054 }
3055 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003056 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3058 + " mAnimation=" + win.mAnimation
3059 + " isEntrance=" + isEntrance);
3060 if (a != null) {
3061 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003062 RuntimeException e = null;
3063 if (!HIDE_STACK_CRAWLS) {
3064 e = new RuntimeException();
3065 e.fillInStackTrace();
3066 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003067 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 }
3069 win.setAnimation(a);
3070 win.mAnimationIsEntrance = isEntrance;
3071 }
3072 } else {
3073 win.clearAnimation();
3074 }
3075
3076 return win.mAnimation != null;
3077 }
3078
3079 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3080 int anim = 0;
3081 Context context = mContext;
3082 if (animAttr >= 0) {
3083 AttributeCache.Entry ent = getCachedAnimations(lp);
3084 if (ent != null) {
3085 context = ent.context;
3086 anim = ent.array.getResourceId(animAttr, 0);
3087 }
3088 }
3089 if (anim != 0) {
3090 return AnimationUtils.loadAnimation(context, anim);
3091 }
3092 return null;
3093 }
Romain Guy06882f82009-06-10 13:36:04 -07003094
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003095 private Animation loadAnimation(String packageName, int resId) {
3096 int anim = 0;
3097 Context context = mContext;
3098 if (resId >= 0) {
3099 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3100 if (ent != null) {
3101 context = ent.context;
3102 anim = resId;
3103 }
3104 }
3105 if (anim != 0) {
3106 return AnimationUtils.loadAnimation(context, anim);
3107 }
3108 return null;
3109 }
3110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003111 private boolean applyAnimationLocked(AppWindowToken wtoken,
3112 WindowManager.LayoutParams lp, int transit, boolean enter) {
3113 // Only apply an animation if the display isn't frozen. If it is
3114 // frozen, there is no reason to animate and it can cause strange
3115 // artifacts when we unfreeze the display if some different animation
3116 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003117 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003118 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003119 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003120 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003121 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003122 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003123 } else if (mNextAppTransitionPackage != null) {
3124 a = loadAnimation(mNextAppTransitionPackage, enter ?
3125 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003126 } else {
3127 int animAttr = 0;
3128 switch (transit) {
3129 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3130 animAttr = enter
3131 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3132 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3133 break;
3134 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3135 animAttr = enter
3136 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3137 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3138 break;
3139 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3140 animAttr = enter
3141 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3142 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3143 break;
3144 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3145 animAttr = enter
3146 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3147 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3148 break;
3149 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3150 animAttr = enter
3151 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3152 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3153 break;
3154 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3155 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003156 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003157 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3158 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003159 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003160 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003161 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3162 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003163 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003164 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003165 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003166 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3167 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3168 break;
3169 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3170 animAttr = enter
3171 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3172 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3173 break;
3174 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3175 animAttr = enter
3176 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3177 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003178 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003179 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003180 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003181 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003182 + " anim=" + a
3183 + " animAttr=0x" + Integer.toHexString(animAttr)
3184 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 if (a != null) {
3187 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003188 RuntimeException e = null;
3189 if (!HIDE_STACK_CRAWLS) {
3190 e = new RuntimeException();
3191 e.fillInStackTrace();
3192 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003193 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 }
3195 wtoken.setAnimation(a);
3196 }
3197 } else {
3198 wtoken.clearAnimation();
3199 }
3200
3201 return wtoken.animation != null;
3202 }
3203
3204 // -------------------------------------------------------------
3205 // Application Window Tokens
3206 // -------------------------------------------------------------
3207
3208 public void validateAppTokens(List tokens) {
3209 int v = tokens.size()-1;
3210 int m = mAppTokens.size()-1;
3211 while (v >= 0 && m >= 0) {
3212 AppWindowToken wtoken = mAppTokens.get(m);
3213 if (wtoken.removed) {
3214 m--;
3215 continue;
3216 }
3217 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003218 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3220 }
3221 v--;
3222 m--;
3223 }
3224 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003225 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 v--;
3227 }
3228 while (m >= 0) {
3229 AppWindowToken wtoken = mAppTokens.get(m);
3230 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003231 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 }
3233 m--;
3234 }
3235 }
3236
3237 boolean checkCallingPermission(String permission, String func) {
3238 // Quick check: if the calling permission is me, it's all okay.
3239 if (Binder.getCallingPid() == Process.myPid()) {
3240 return true;
3241 }
Romain Guy06882f82009-06-10 13:36:04 -07003242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243 if (mContext.checkCallingPermission(permission)
3244 == PackageManager.PERMISSION_GRANTED) {
3245 return true;
3246 }
3247 String msg = "Permission Denial: " + func + " from pid="
3248 + Binder.getCallingPid()
3249 + ", uid=" + Binder.getCallingUid()
3250 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003251 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 return false;
3253 }
Romain Guy06882f82009-06-10 13:36:04 -07003254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 AppWindowToken findAppWindowToken(IBinder token) {
3256 WindowToken wtoken = mTokenMap.get(token);
3257 if (wtoken == null) {
3258 return null;
3259 }
3260 return wtoken.appWindowToken;
3261 }
Romain Guy06882f82009-06-10 13:36:04 -07003262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 public void addWindowToken(IBinder token, int type) {
3264 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3265 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003266 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 }
Romain Guy06882f82009-06-10 13:36:04 -07003268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003269 synchronized(mWindowMap) {
3270 WindowToken wtoken = mTokenMap.get(token);
3271 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003272 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003273 return;
3274 }
3275 wtoken = new WindowToken(token, type, true);
3276 mTokenMap.put(token, wtoken);
3277 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003278 if (type == TYPE_WALLPAPER) {
3279 mWallpaperTokens.add(wtoken);
3280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 }
3282 }
Romain Guy06882f82009-06-10 13:36:04 -07003283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 public void removeWindowToken(IBinder token) {
3285 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3286 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003287 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 }
3289
3290 final long origId = Binder.clearCallingIdentity();
3291 synchronized(mWindowMap) {
3292 WindowToken wtoken = mTokenMap.remove(token);
3293 mTokenList.remove(wtoken);
3294 if (wtoken != null) {
3295 boolean delayed = false;
3296 if (!wtoken.hidden) {
3297 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 final int N = wtoken.windows.size();
3300 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 for (int i=0; i<N; i++) {
3303 WindowState win = wtoken.windows.get(i);
3304
3305 if (win.isAnimating()) {
3306 delayed = true;
3307 }
Romain Guy06882f82009-06-10 13:36:04 -07003308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 if (win.isVisibleNow()) {
3310 applyAnimationLocked(win,
3311 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 changed = true;
3313 }
3314 }
3315
3316 if (changed) {
3317 mLayoutNeeded = true;
3318 performLayoutAndPlaceSurfacesLocked();
3319 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3320 }
Romain Guy06882f82009-06-10 13:36:04 -07003321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 if (delayed) {
3323 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003324 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3325 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 }
3327 }
Romain Guy06882f82009-06-10 13:36:04 -07003328
Jeff Brownc5ed5912010-07-14 18:48:53 -07003329 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003331 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 }
3333 }
3334 Binder.restoreCallingIdentity(origId);
3335 }
3336
3337 public void addAppToken(int addPos, IApplicationToken token,
3338 int groupId, int requestedOrientation, boolean fullscreen) {
3339 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3340 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003341 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 }
Jeff Brown349703e2010-06-22 01:27:15 -07003343
3344 // Get the dispatching timeout here while we are not holding any locks so that it
3345 // can be cached by the AppWindowToken. The timeout value is used later by the
3346 // input dispatcher in code that does hold locks. If we did not cache the value
3347 // here we would run the chance of introducing a deadlock between the window manager
3348 // (which holds locks while updating the input dispatcher state) and the activity manager
3349 // (which holds locks while querying the application token).
3350 long inputDispatchingTimeoutNanos;
3351 try {
3352 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3353 } catch (RemoteException ex) {
3354 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3355 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3356 }
Romain Guy06882f82009-06-10 13:36:04 -07003357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 synchronized(mWindowMap) {
3359 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3360 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003361 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 return;
3363 }
3364 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003365 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 wtoken.groupId = groupId;
3367 wtoken.appFullscreen = fullscreen;
3368 wtoken.requestedOrientation = requestedOrientation;
3369 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003370 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 mTokenMap.put(token.asBinder(), wtoken);
3372 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 // Application tokens start out hidden.
3375 wtoken.hidden = true;
3376 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 //dump();
3379 }
3380 }
Romain Guy06882f82009-06-10 13:36:04 -07003381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 public void setAppGroupId(IBinder token, int groupId) {
3383 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3384 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003385 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 }
3387
3388 synchronized(mWindowMap) {
3389 AppWindowToken wtoken = findAppWindowToken(token);
3390 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003391 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 return;
3393 }
3394 wtoken.groupId = groupId;
3395 }
3396 }
Romain Guy06882f82009-06-10 13:36:04 -07003397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 public int getOrientationFromWindowsLocked() {
3399 int pos = mWindows.size() - 1;
3400 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003401 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 pos--;
3403 if (wtoken.mAppToken != null) {
3404 // We hit an application window. so the orientation will be determined by the
3405 // app window. No point in continuing further.
3406 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3407 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003408 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 continue;
3410 }
3411 int req = wtoken.mAttrs.screenOrientation;
3412 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3413 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3414 continue;
3415 } else {
3416 return req;
3417 }
3418 }
3419 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3420 }
Romain Guy06882f82009-06-10 13:36:04 -07003421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003423 int pos = mAppTokens.size() - 1;
3424 int curGroup = 0;
3425 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3426 boolean findingBehind = false;
3427 boolean haveGroup = false;
3428 boolean lastFullscreen = false;
3429 while (pos >= 0) {
3430 AppWindowToken wtoken = mAppTokens.get(pos);
3431 pos--;
3432 // if we're about to tear down this window and not seek for
3433 // the behind activity, don't use it for orientation
3434 if (!findingBehind
3435 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3436 continue;
3437 }
3438
3439 if (!haveGroup) {
3440 // We ignore any hidden applications on the top.
3441 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003442 continue;
3443 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003444 haveGroup = true;
3445 curGroup = wtoken.groupId;
3446 lastOrientation = wtoken.requestedOrientation;
3447 } else if (curGroup != wtoken.groupId) {
3448 // If we have hit a new application group, and the bottom
3449 // of the previous group didn't explicitly say to use
3450 // the orientation behind it, and the last app was
3451 // full screen, then we'll stick with the
3452 // user's orientation.
3453 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3454 && lastFullscreen) {
3455 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003457 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003458 int or = wtoken.requestedOrientation;
3459 // If this application is fullscreen, and didn't explicitly say
3460 // to use the orientation behind it, then just take whatever
3461 // orientation it has and ignores whatever is under it.
3462 lastFullscreen = wtoken.appFullscreen;
3463 if (lastFullscreen
3464 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3465 return or;
3466 }
3467 // If this application has requested an explicit orientation,
3468 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003469 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3470 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003471 return or;
3472 }
3473 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3474 }
3475 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 }
Romain Guy06882f82009-06-10 13:36:04 -07003477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003478 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003479 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003480 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3481 "updateOrientationFromAppTokens()")) {
3482 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3483 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003484
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003485 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003487
3488 synchronized(mWindowMap) {
3489 if (updateOrientationFromAppTokensLocked()) {
3490 if (freezeThisOneIfNeeded != null) {
3491 AppWindowToken wtoken = findAppWindowToken(
3492 freezeThisOneIfNeeded);
3493 if (wtoken != null) {
3494 startAppFreezingScreenLocked(wtoken,
3495 ActivityInfo.CONFIG_ORIENTATION);
3496 }
3497 }
3498 config = computeNewConfigurationLocked();
3499
3500 } else if (currentConfig != null) {
3501 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003502 // state mismatches the activity manager's, update it,
3503 // disregarding font scale, which should remain set to
3504 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003505 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003506 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003507 if (computeNewConfigurationLocked(mTempConfiguration)) {
3508 if (currentConfig.diff(mTempConfiguration) != 0) {
3509 mWaitingForConfig = true;
3510 mLayoutNeeded = true;
3511 startFreezingDisplayLocked();
3512 config = new Configuration(mTempConfiguration);
3513 }
3514 }
3515 }
3516 }
3517
Dianne Hackborncfaef692009-06-15 14:24:44 -07003518 Binder.restoreCallingIdentity(ident);
3519 return config;
3520 }
3521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003523 * Determine the new desired orientation of the display, returning
3524 * a non-null new Configuration if it has changed from the current
3525 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3526 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3527 * SCREEN. This will typically be done for you if you call
3528 * sendNewConfiguration().
3529 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 * The orientation is computed from non-application windows first. If none of
3531 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003532 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3534 * android.os.IBinder)
3535 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003536 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003537 if (mDisplayFrozen) {
3538 // If the display is frozen, some activities may be in the middle
3539 // of restarting, and thus have removed their old window. If the
3540 // window has the flag to hide the lock screen, then the lock screen
3541 // can re-appear and inflict its own orientation on us. Keep the
3542 // orientation stable until this all settles down.
3543 return false;
3544 }
3545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 long ident = Binder.clearCallingIdentity();
3548 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003549 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003551 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 mForcedAppOrientation = req;
3553 //send a message to Policy indicating orientation change to take
3554 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003555 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003556 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3557 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3558 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 }
3560 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003561
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003562 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 } finally {
3564 Binder.restoreCallingIdentity(ident);
3565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 }
Romain Guy06882f82009-06-10 13:36:04 -07003567
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003568 int computeForcedAppOrientationLocked() {
3569 int req = getOrientationFromWindowsLocked();
3570 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3571 req = getOrientationFromAppTokensLocked();
3572 }
3573 return req;
3574 }
Romain Guy06882f82009-06-10 13:36:04 -07003575
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003576 public void setNewConfiguration(Configuration config) {
3577 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3578 "setNewConfiguration()")) {
3579 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3580 }
3581
3582 synchronized(mWindowMap) {
3583 mCurConfiguration = new Configuration(config);
3584 mWaitingForConfig = false;
3585 performLayoutAndPlaceSurfacesLocked();
3586 }
3587 }
3588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003589 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3590 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3591 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003592 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 }
Romain Guy06882f82009-06-10 13:36:04 -07003594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 synchronized(mWindowMap) {
3596 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3597 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003598 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 return;
3600 }
Romain Guy06882f82009-06-10 13:36:04 -07003601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 wtoken.requestedOrientation = requestedOrientation;
3603 }
3604 }
Romain Guy06882f82009-06-10 13:36:04 -07003605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 public int getAppOrientation(IApplicationToken token) {
3607 synchronized(mWindowMap) {
3608 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3609 if (wtoken == null) {
3610 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3611 }
Romain Guy06882f82009-06-10 13:36:04 -07003612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 return wtoken.requestedOrientation;
3614 }
3615 }
Romain Guy06882f82009-06-10 13:36:04 -07003616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3618 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3619 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003620 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 }
3622
3623 synchronized(mWindowMap) {
3624 boolean changed = false;
3625 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003626 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 changed = mFocusedApp != null;
3628 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003629 if (changed) {
3630 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003631 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 } else {
3633 AppWindowToken newFocus = findAppWindowToken(token);
3634 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003635 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 return;
3637 }
3638 changed = mFocusedApp != newFocus;
3639 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003640 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003641 if (changed) {
3642 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003643 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 }
3645
3646 if (moveFocusNow && changed) {
3647 final long origId = Binder.clearCallingIdentity();
3648 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3649 Binder.restoreCallingIdentity(origId);
3650 }
3651 }
3652 }
3653
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003654 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3656 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003657 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 }
Romain Guy06882f82009-06-10 13:36:04 -07003659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003661 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 TAG, "Prepare app transition: transit=" + transit
3663 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003664 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003665 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3666 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003668 } else if (!alwaysKeepCurrent) {
3669 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3670 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3671 // Opening a new task always supersedes a close for the anim.
3672 mNextAppTransition = transit;
3673 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3674 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3675 // Opening a new activity always supersedes a close for the anim.
3676 mNextAppTransition = transit;
3677 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 }
3679 mAppTransitionReady = false;
3680 mAppTransitionTimeout = false;
3681 mStartingIconInTransition = false;
3682 mSkipAppTransitionAnimation = false;
3683 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3684 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3685 5000);
3686 }
3687 }
3688 }
3689
3690 public int getPendingAppTransition() {
3691 return mNextAppTransition;
3692 }
Romain Guy06882f82009-06-10 13:36:04 -07003693
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003694 public void overridePendingAppTransition(String packageName,
3695 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003696 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003697 mNextAppTransitionPackage = packageName;
3698 mNextAppTransitionEnter = enterAnim;
3699 mNextAppTransitionExit = exitAnim;
3700 }
3701 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 public void executeAppTransition() {
3704 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3705 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003706 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 }
Romain Guy06882f82009-06-10 13:36:04 -07003708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003710 if (DEBUG_APP_TRANSITIONS) {
3711 RuntimeException e = new RuntimeException("here");
3712 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003713 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003714 + mNextAppTransition, e);
3715 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003716 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 mAppTransitionReady = true;
3718 final long origId = Binder.clearCallingIdentity();
3719 performLayoutAndPlaceSurfacesLocked();
3720 Binder.restoreCallingIdentity(origId);
3721 }
3722 }
3723 }
3724
3725 public void setAppStartingWindow(IBinder token, String pkg,
3726 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003727 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3729 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003730 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 }
3732
3733 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003734 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3736 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 AppWindowToken wtoken = findAppWindowToken(token);
3739 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003740 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 return;
3742 }
3743
3744 // If the display is frozen, we won't do anything until the
3745 // actual window is displayed so there is no reason to put in
3746 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003747 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 return;
3749 }
Romain Guy06882f82009-06-10 13:36:04 -07003750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 if (wtoken.startingData != null) {
3752 return;
3753 }
Romain Guy06882f82009-06-10 13:36:04 -07003754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755 if (transferFrom != null) {
3756 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3757 if (ttoken != null) {
3758 WindowState startingWindow = ttoken.startingWindow;
3759 if (startingWindow != null) {
3760 if (mStartingIconInTransition) {
3761 // In this case, the starting icon has already
3762 // been displayed, so start letting windows get
3763 // shown immediately without any more transitions.
3764 mSkipAppTransitionAnimation = true;
3765 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003766 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 "Moving existing starting from " + ttoken
3768 + " to " + wtoken);
3769 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 // Transfer the starting window over to the new
3772 // token.
3773 wtoken.startingData = ttoken.startingData;
3774 wtoken.startingView = ttoken.startingView;
3775 wtoken.startingWindow = startingWindow;
3776 ttoken.startingData = null;
3777 ttoken.startingView = null;
3778 ttoken.startingWindow = null;
3779 ttoken.startingMoved = true;
3780 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003781 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003783 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003784 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003785 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003786 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 ttoken.windows.remove(startingWindow);
3788 ttoken.allAppWindows.remove(startingWindow);
3789 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 // Propagate other interesting state between the
3792 // tokens. If the old token is displayed, we should
3793 // immediately force the new one to be displayed. If
3794 // it is animating, we need to move that animation to
3795 // the new one.
3796 if (ttoken.allDrawn) {
3797 wtoken.allDrawn = true;
3798 }
3799 if (ttoken.firstWindowDrawn) {
3800 wtoken.firstWindowDrawn = true;
3801 }
3802 if (!ttoken.hidden) {
3803 wtoken.hidden = false;
3804 wtoken.hiddenRequested = false;
3805 wtoken.willBeHidden = false;
3806 }
3807 if (wtoken.clientHidden != ttoken.clientHidden) {
3808 wtoken.clientHidden = ttoken.clientHidden;
3809 wtoken.sendAppVisibilityToClients();
3810 }
3811 if (ttoken.animation != null) {
3812 wtoken.animation = ttoken.animation;
3813 wtoken.animating = ttoken.animating;
3814 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3815 ttoken.animation = null;
3816 ttoken.animLayerAdjustment = 0;
3817 wtoken.updateLayers();
3818 ttoken.updateLayers();
3819 }
Romain Guy06882f82009-06-10 13:36:04 -07003820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 mLayoutNeeded = true;
3823 performLayoutAndPlaceSurfacesLocked();
3824 Binder.restoreCallingIdentity(origId);
3825 return;
3826 } else if (ttoken.startingData != null) {
3827 // The previous app was getting ready to show a
3828 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003829 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 "Moving pending starting from " + ttoken
3831 + " to " + wtoken);
3832 wtoken.startingData = ttoken.startingData;
3833 ttoken.startingData = null;
3834 ttoken.startingMoved = true;
3835 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3836 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3837 // want to process the message ASAP, before any other queued
3838 // messages.
3839 mH.sendMessageAtFrontOfQueue(m);
3840 return;
3841 }
3842 }
3843 }
3844
3845 // There is no existing starting window, and the caller doesn't
3846 // want us to create one, so that's it!
3847 if (!createIfNeeded) {
3848 return;
3849 }
Romain Guy06882f82009-06-10 13:36:04 -07003850
Dianne Hackborn284ac932009-08-28 10:34:25 -07003851 // If this is a translucent or wallpaper window, then don't
3852 // show a starting window -- the current effect (a full-screen
3853 // opaque starting window that fades away to the real contents
3854 // when it is ready) does not work for this.
3855 if (theme != 0) {
3856 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3857 com.android.internal.R.styleable.Window);
3858 if (ent.array.getBoolean(
3859 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3860 return;
3861 }
3862 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003863 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3864 return;
3865 }
3866 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003867 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3868 return;
3869 }
3870 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 mStartingIconInTransition = true;
3873 wtoken.startingData = new StartingData(
3874 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003875 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3877 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3878 // want to process the message ASAP, before any other queued
3879 // messages.
3880 mH.sendMessageAtFrontOfQueue(m);
3881 }
3882 }
3883
3884 public void setAppWillBeHidden(IBinder token) {
3885 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3886 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003887 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 }
3889
3890 AppWindowToken wtoken;
3891
3892 synchronized(mWindowMap) {
3893 wtoken = findAppWindowToken(token);
3894 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003895 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 -08003896 return;
3897 }
3898 wtoken.willBeHidden = true;
3899 }
3900 }
Romain Guy06882f82009-06-10 13:36:04 -07003901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003902 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3903 boolean visible, int transit, boolean performLayout) {
3904 boolean delayed = false;
3905
3906 if (wtoken.clientHidden == visible) {
3907 wtoken.clientHidden = !visible;
3908 wtoken.sendAppVisibilityToClients();
3909 }
Romain Guy06882f82009-06-10 13:36:04 -07003910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 wtoken.willBeHidden = false;
3912 if (wtoken.hidden == visible) {
3913 final int N = wtoken.allAppWindows.size();
3914 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003915 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3917 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003920
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003921 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922 if (wtoken.animation == sDummyAnimation) {
3923 wtoken.animation = null;
3924 }
3925 applyAnimationLocked(wtoken, lp, transit, visible);
3926 changed = true;
3927 if (wtoken.animation != null) {
3928 delayed = runningAppAnimation = true;
3929 }
3930 }
Romain Guy06882f82009-06-10 13:36:04 -07003931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 for (int i=0; i<N; i++) {
3933 WindowState win = wtoken.allAppWindows.get(i);
3934 if (win == wtoken.startingWindow) {
3935 continue;
3936 }
3937
3938 if (win.isAnimating()) {
3939 delayed = true;
3940 }
Romain Guy06882f82009-06-10 13:36:04 -07003941
Joe Onorato8a9b2202010-02-26 18:56:32 -08003942 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 //win.dump(" ");
3944 if (visible) {
3945 if (!win.isVisibleNow()) {
3946 if (!runningAppAnimation) {
3947 applyAnimationLocked(win,
3948 WindowManagerPolicy.TRANSIT_ENTER, true);
3949 }
3950 changed = true;
3951 }
3952 } else if (win.isVisibleNow()) {
3953 if (!runningAppAnimation) {
3954 applyAnimationLocked(win,
3955 WindowManagerPolicy.TRANSIT_EXIT, false);
3956 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 changed = true;
3958 }
3959 }
3960
3961 wtoken.hidden = wtoken.hiddenRequested = !visible;
3962 if (!visible) {
3963 unsetAppFreezingScreenLocked(wtoken, true, true);
3964 } else {
3965 // If we are being set visible, and the starting window is
3966 // not yet displayed, then make sure it doesn't get displayed.
3967 WindowState swin = wtoken.startingWindow;
3968 if (swin != null && (swin.mDrawPending
3969 || swin.mCommitDrawPending)) {
3970 swin.mPolicyVisibility = false;
3971 swin.mPolicyVisibilityAfterAnim = false;
3972 }
3973 }
Romain Guy06882f82009-06-10 13:36:04 -07003974
Joe Onorato8a9b2202010-02-26 18:56:32 -08003975 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3977 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003978
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003979 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003981 if (performLayout) {
3982 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3983 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003984 } else {
3985 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 }
3988 }
3989
3990 if (wtoken.animation != null) {
3991 delayed = true;
3992 }
Romain Guy06882f82009-06-10 13:36:04 -07003993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 return delayed;
3995 }
3996
3997 public void setAppVisibility(IBinder token, boolean visible) {
3998 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3999 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004000 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004001 }
4002
4003 AppWindowToken wtoken;
4004
4005 synchronized(mWindowMap) {
4006 wtoken = findAppWindowToken(token);
4007 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004008 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 return;
4010 }
4011
4012 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004013 RuntimeException e = null;
4014 if (!HIDE_STACK_CRAWLS) {
4015 e = new RuntimeException();
4016 e.fillInStackTrace();
4017 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004018 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 + "): mNextAppTransition=" + mNextAppTransition
4020 + " hidden=" + wtoken.hidden
4021 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4022 }
Romain Guy06882f82009-06-10 13:36:04 -07004023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 // If we are preparing an app transition, then delay changing
4025 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004026 if (!mDisplayFrozen && mPolicy.isScreenOn()
4027 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004028 // Already in requested state, don't do anything more.
4029 if (wtoken.hiddenRequested != visible) {
4030 return;
4031 }
4032 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004033
Joe Onorato8a9b2202010-02-26 18:56:32 -08004034 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 TAG, "Setting dummy animation on: " + wtoken);
4036 wtoken.setDummyAnimation();
4037 mOpeningApps.remove(wtoken);
4038 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004039 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 wtoken.inPendingTransaction = true;
4041 if (visible) {
4042 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004043 wtoken.startingDisplayed = false;
4044 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004045
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004046 // If the token is currently hidden (should be the
4047 // common case), then we need to set up to wait for
4048 // its windows to be ready.
4049 if (wtoken.hidden) {
4050 wtoken.allDrawn = false;
4051 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004052
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004053 if (wtoken.clientHidden) {
4054 // In the case where we are making an app visible
4055 // but holding off for a transition, we still need
4056 // to tell the client to make its windows visible so
4057 // they get drawn. Otherwise, we will wait on
4058 // performing the transition until all windows have
4059 // been drawn, they never will be, and we are sad.
4060 wtoken.clientHidden = false;
4061 wtoken.sendAppVisibilityToClients();
4062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004063 }
4064 } else {
4065 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004066
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004067 // If the token is currently visible (should be the
4068 // common case), then set up to wait for it to be hidden.
4069 if (!wtoken.hidden) {
4070 wtoken.waitingToHide = true;
4071 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004072 }
4073 return;
4074 }
Romain Guy06882f82009-06-10 13:36:04 -07004075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004077 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 wtoken.updateReportedVisibilityLocked();
4079 Binder.restoreCallingIdentity(origId);
4080 }
4081 }
4082
4083 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4084 boolean unfreezeSurfaceNow, boolean force) {
4085 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004086 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004087 + " force=" + force);
4088 final int N = wtoken.allAppWindows.size();
4089 boolean unfrozeWindows = false;
4090 for (int i=0; i<N; i++) {
4091 WindowState w = wtoken.allAppWindows.get(i);
4092 if (w.mAppFreezing) {
4093 w.mAppFreezing = false;
4094 if (w.mSurface != null && !w.mOrientationChanging) {
4095 w.mOrientationChanging = true;
4096 }
4097 unfrozeWindows = true;
4098 }
4099 }
4100 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004101 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 wtoken.freezingScreen = false;
4103 mAppsFreezingScreen--;
4104 }
4105 if (unfreezeSurfaceNow) {
4106 if (unfrozeWindows) {
4107 mLayoutNeeded = true;
4108 performLayoutAndPlaceSurfacesLocked();
4109 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004110 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 }
4112 }
4113 }
Romain Guy06882f82009-06-10 13:36:04 -07004114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4116 int configChanges) {
4117 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004118 RuntimeException e = null;
4119 if (!HIDE_STACK_CRAWLS) {
4120 e = new RuntimeException();
4121 e.fillInStackTrace();
4122 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004123 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004124 + ": hidden=" + wtoken.hidden + " freezing="
4125 + wtoken.freezingScreen, e);
4126 }
4127 if (!wtoken.hiddenRequested) {
4128 if (!wtoken.freezingScreen) {
4129 wtoken.freezingScreen = true;
4130 mAppsFreezingScreen++;
4131 if (mAppsFreezingScreen == 1) {
4132 startFreezingDisplayLocked();
4133 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4134 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4135 5000);
4136 }
4137 }
4138 final int N = wtoken.allAppWindows.size();
4139 for (int i=0; i<N; i++) {
4140 WindowState w = wtoken.allAppWindows.get(i);
4141 w.mAppFreezing = true;
4142 }
4143 }
4144 }
Romain Guy06882f82009-06-10 13:36:04 -07004145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004146 public void startAppFreezingScreen(IBinder token, int configChanges) {
4147 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4148 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004149 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004150 }
4151
4152 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004153 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004154 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004155 return;
4156 }
Romain Guy06882f82009-06-10 13:36:04 -07004157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 AppWindowToken wtoken = findAppWindowToken(token);
4159 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004160 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 return;
4162 }
4163 final long origId = Binder.clearCallingIdentity();
4164 startAppFreezingScreenLocked(wtoken, configChanges);
4165 Binder.restoreCallingIdentity(origId);
4166 }
4167 }
Romain Guy06882f82009-06-10 13:36:04 -07004168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 public void stopAppFreezingScreen(IBinder token, boolean force) {
4170 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4171 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004172 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 }
4174
4175 synchronized(mWindowMap) {
4176 AppWindowToken wtoken = findAppWindowToken(token);
4177 if (wtoken == null || wtoken.appToken == null) {
4178 return;
4179 }
4180 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004181 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4183 unsetAppFreezingScreenLocked(wtoken, true, force);
4184 Binder.restoreCallingIdentity(origId);
4185 }
4186 }
Romain Guy06882f82009-06-10 13:36:04 -07004187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 public void removeAppToken(IBinder token) {
4189 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4190 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004191 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 }
4193
4194 AppWindowToken wtoken = null;
4195 AppWindowToken startingToken = null;
4196 boolean delayed = false;
4197
4198 final long origId = Binder.clearCallingIdentity();
4199 synchronized(mWindowMap) {
4200 WindowToken basewtoken = mTokenMap.remove(token);
4201 mTokenList.remove(basewtoken);
4202 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004203 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004204 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 wtoken.inPendingTransaction = false;
4206 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004207 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 if (mClosingApps.contains(wtoken)) {
4209 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004210 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004212 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 delayed = true;
4214 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004215 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 TAG, "Removing app " + wtoken + " delayed=" + delayed
4217 + " animation=" + wtoken.animation
4218 + " animating=" + wtoken.animating);
4219 if (delayed) {
4220 // set the token aside because it has an active animation to be finished
4221 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004222 } else {
4223 // Make sure there is no animation running on this token,
4224 // so any windows associated with it will be removed as
4225 // soon as their animations are complete
4226 wtoken.animation = null;
4227 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004228 }
4229 mAppTokens.remove(wtoken);
4230 wtoken.removed = true;
4231 if (wtoken.startingData != null) {
4232 startingToken = wtoken;
4233 }
4234 unsetAppFreezingScreenLocked(wtoken, true, true);
4235 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004236 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004237 mFocusedApp = null;
4238 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004239 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004240 }
4241 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004242 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004243 }
Romain Guy06882f82009-06-10 13:36:04 -07004244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 if (!delayed && wtoken != null) {
4246 wtoken.updateReportedVisibilityLocked();
4247 }
4248 }
4249 Binder.restoreCallingIdentity(origId);
4250
4251 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004252 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004253 + startingToken + ": app token removed");
4254 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4255 mH.sendMessage(m);
4256 }
4257 }
4258
4259 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4260 final int NW = token.windows.size();
4261 for (int i=0; i<NW; i++) {
4262 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004263 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004264 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004265 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 int j = win.mChildWindows.size();
4267 while (j > 0) {
4268 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004269 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004270 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004271 "Tmp removing child window " + cwin);
4272 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 }
4274 }
4275 return NW > 0;
4276 }
4277
4278 void dumpAppTokensLocked() {
4279 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004280 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 }
4282 }
Romain Guy06882f82009-06-10 13:36:04 -07004283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 void dumpWindowsLocked() {
4285 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004286 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 }
4288 }
Romain Guy06882f82009-06-10 13:36:04 -07004289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 private int findWindowOffsetLocked(int tokenPos) {
4291 final int NW = mWindows.size();
4292
4293 if (tokenPos >= mAppTokens.size()) {
4294 int i = NW;
4295 while (i > 0) {
4296 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004297 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004298 if (win.getAppToken() != null) {
4299 return i+1;
4300 }
4301 }
4302 }
4303
4304 while (tokenPos > 0) {
4305 // Find the first app token below the new position that has
4306 // a window displayed.
4307 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004308 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004310 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004311 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004312 "Skipping token -- currently sending to bottom");
4313 tokenPos--;
4314 continue;
4315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 int i = wtoken.windows.size();
4317 while (i > 0) {
4318 i--;
4319 WindowState win = wtoken.windows.get(i);
4320 int j = win.mChildWindows.size();
4321 while (j > 0) {
4322 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004323 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004324 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 for (int pos=NW-1; pos>=0; pos--) {
4326 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004327 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 "Found child win @" + (pos+1));
4329 return pos+1;
4330 }
4331 }
4332 }
4333 }
4334 for (int pos=NW-1; pos>=0; pos--) {
4335 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004336 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 return pos+1;
4338 }
4339 }
4340 }
4341 tokenPos--;
4342 }
4343
4344 return 0;
4345 }
4346
4347 private final int reAddWindowLocked(int index, WindowState win) {
4348 final int NCW = win.mChildWindows.size();
4349 boolean added = false;
4350 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004351 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004353 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004354 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 mWindows.add(index, win);
4356 index++;
4357 added = true;
4358 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004359 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004360 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 mWindows.add(index, cwin);
4362 index++;
4363 }
4364 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004365 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004366 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 mWindows.add(index, win);
4368 index++;
4369 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004370 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004371 return index;
4372 }
Romain Guy06882f82009-06-10 13:36:04 -07004373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004374 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4375 final int NW = token.windows.size();
4376 for (int i=0; i<NW; i++) {
4377 index = reAddWindowLocked(index, token.windows.get(i));
4378 }
4379 return index;
4380 }
4381
4382 public void moveAppToken(int index, IBinder token) {
4383 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4384 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004385 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 }
4387
4388 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004389 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 if (DEBUG_REORDER) dumpAppTokensLocked();
4391 final AppWindowToken wtoken = findAppWindowToken(token);
4392 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004393 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 + token + " (" + wtoken + ")");
4395 return;
4396 }
4397 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004398 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004399 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004402 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 if (DEBUG_REORDER) dumpWindowsLocked();
4404 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004405 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 if (DEBUG_REORDER) dumpWindowsLocked();
4407 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004408 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 if (DEBUG_REORDER) dumpWindowsLocked();
4410 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 mLayoutNeeded = true;
4412 performLayoutAndPlaceSurfacesLocked();
4413 }
4414 Binder.restoreCallingIdentity(origId);
4415 }
4416 }
4417
4418 private void removeAppTokensLocked(List<IBinder> tokens) {
4419 // XXX This should be done more efficiently!
4420 // (take advantage of the fact that both lists should be
4421 // ordered in the same way.)
4422 int N = tokens.size();
4423 for (int i=0; i<N; i++) {
4424 IBinder token = tokens.get(i);
4425 final AppWindowToken wtoken = findAppWindowToken(token);
4426 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004427 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 + token + " (" + wtoken + ")");
4429 i--;
4430 N--;
4431 }
4432 }
4433 }
4434
Dianne Hackborna8f60182009-09-01 19:01:50 -07004435 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4436 boolean updateFocusAndLayout) {
4437 // First remove all of the windows from the list.
4438 tmpRemoveAppWindowsLocked(wtoken);
4439
4440 // Where to start adding?
4441 int pos = findWindowOffsetLocked(tokenPos);
4442
4443 // And now add them back at the correct place.
4444 pos = reAddAppWindowsLocked(pos, wtoken);
4445
4446 if (updateFocusAndLayout) {
4447 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4448 assignLayersLocked();
4449 }
4450 mLayoutNeeded = true;
4451 performLayoutAndPlaceSurfacesLocked();
4452 }
4453 }
4454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4456 // First remove all of the windows from the list.
4457 final int N = tokens.size();
4458 int i;
4459 for (i=0; i<N; i++) {
4460 WindowToken token = mTokenMap.get(tokens.get(i));
4461 if (token != null) {
4462 tmpRemoveAppWindowsLocked(token);
4463 }
4464 }
4465
4466 // Where to start adding?
4467 int pos = findWindowOffsetLocked(tokenPos);
4468
4469 // And now add them back at the correct place.
4470 for (i=0; i<N; i++) {
4471 WindowToken token = mTokenMap.get(tokens.get(i));
4472 if (token != null) {
4473 pos = reAddAppWindowsLocked(pos, token);
4474 }
4475 }
4476
Dianne Hackborna8f60182009-09-01 19:01:50 -07004477 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4478 assignLayersLocked();
4479 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 mLayoutNeeded = true;
4481 performLayoutAndPlaceSurfacesLocked();
4482
4483 //dump();
4484 }
4485
4486 public void moveAppTokensToTop(List<IBinder> tokens) {
4487 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4488 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004489 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 }
4491
4492 final long origId = Binder.clearCallingIdentity();
4493 synchronized(mWindowMap) {
4494 removeAppTokensLocked(tokens);
4495 final int N = tokens.size();
4496 for (int i=0; i<N; i++) {
4497 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4498 if (wt != null) {
4499 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004500 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004501 mToTopApps.remove(wt);
4502 mToBottomApps.remove(wt);
4503 mToTopApps.add(wt);
4504 wt.sendingToBottom = false;
4505 wt.sendingToTop = true;
4506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 }
4508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004509
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004510 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004511 moveAppWindowsLocked(tokens, mAppTokens.size());
4512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 }
4514 Binder.restoreCallingIdentity(origId);
4515 }
4516
4517 public void moveAppTokensToBottom(List<IBinder> tokens) {
4518 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4519 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004520 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 }
4522
4523 final long origId = Binder.clearCallingIdentity();
4524 synchronized(mWindowMap) {
4525 removeAppTokensLocked(tokens);
4526 final int N = tokens.size();
4527 int pos = 0;
4528 for (int i=0; i<N; i++) {
4529 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4530 if (wt != null) {
4531 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004532 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004533 mToTopApps.remove(wt);
4534 mToBottomApps.remove(wt);
4535 mToBottomApps.add(i, wt);
4536 wt.sendingToTop = false;
4537 wt.sendingToBottom = true;
4538 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004539 pos++;
4540 }
4541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004542
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004543 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004544 moveAppWindowsLocked(tokens, 0);
4545 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004546 }
4547 Binder.restoreCallingIdentity(origId);
4548 }
4549
4550 // -------------------------------------------------------------
4551 // Misc IWindowSession methods
4552 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004553
Jim Miller284b62e2010-06-08 14:27:42 -07004554 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004555 {
Jim Miller284b62e2010-06-08 14:27:42 -07004556 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4557 // called before DevicePolicyManagerService has started.
4558 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4559 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4560 Context.DEVICE_POLICY_SERVICE);
4561 if (dpm != null) {
4562 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4563 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4564 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4565 }
Jim Millerd6b57052010-06-07 17:52:42 -07004566 }
Jim Miller284b62e2010-06-08 14:27:42 -07004567 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004568 }
4569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004570 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004571 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004572 != PackageManager.PERMISSION_GRANTED) {
4573 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4574 }
Jim Millerd6b57052010-06-07 17:52:42 -07004575
Jim Miller284b62e2010-06-08 14:27:42 -07004576 synchronized (mKeyguardTokenWatcher) {
4577 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 }
4580
4581 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004582 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004583 != PackageManager.PERMISSION_GRANTED) {
4584 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586
Jim Miller284b62e2010-06-08 14:27:42 -07004587 synchronized (mKeyguardTokenWatcher) {
4588 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004589
Jim Miller284b62e2010-06-08 14:27:42 -07004590 if (!mKeyguardTokenWatcher.isAcquired()) {
4591 // If we are the last one to reenable the keyguard wait until
4592 // we have actually finished reenabling until returning.
4593 // It is possible that reenableKeyguard() can be called before
4594 // the previous disableKeyguard() is handled, in which case
4595 // neither mKeyguardTokenWatcher.acquired() or released() would
4596 // be called. In that case mKeyguardDisabled will be false here
4597 // and we have nothing to wait for.
4598 while (mKeyguardDisabled) {
4599 try {
4600 mKeyguardTokenWatcher.wait();
4601 } catch (InterruptedException e) {
4602 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004603 }
4604 }
4605 }
4606 }
4607 }
4608
4609 /**
4610 * @see android.app.KeyguardManager#exitKeyguardSecurely
4611 */
4612 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004613 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004614 != PackageManager.PERMISSION_GRANTED) {
4615 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4616 }
4617 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4618 public void onKeyguardExitResult(boolean success) {
4619 try {
4620 callback.onKeyguardExitResult(success);
4621 } catch (RemoteException e) {
4622 // Client has died, we don't care.
4623 }
4624 }
4625 });
4626 }
4627
4628 public boolean inKeyguardRestrictedInputMode() {
4629 return mPolicy.inKeyguardRestrictedKeyInputMode();
4630 }
Romain Guy06882f82009-06-10 13:36:04 -07004631
Dianne Hackbornffa42482009-09-23 22:20:11 -07004632 public void closeSystemDialogs(String reason) {
4633 synchronized(mWindowMap) {
4634 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004635 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004636 if (w.mSurface != null) {
4637 try {
4638 w.mClient.closeSystemDialogs(reason);
4639 } catch (RemoteException e) {
4640 }
4641 }
4642 }
4643 }
4644 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004646 static float fixScale(float scale) {
4647 if (scale < 0) scale = 0;
4648 else if (scale > 20) scale = 20;
4649 return Math.abs(scale);
4650 }
Romain Guy06882f82009-06-10 13:36:04 -07004651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004652 public void setAnimationScale(int which, float scale) {
4653 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4654 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004655 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004656 }
4657
4658 if (scale < 0) scale = 0;
4659 else if (scale > 20) scale = 20;
4660 scale = Math.abs(scale);
4661 switch (which) {
4662 case 0: mWindowAnimationScale = fixScale(scale); break;
4663 case 1: mTransitionAnimationScale = fixScale(scale); break;
4664 }
Romain Guy06882f82009-06-10 13:36:04 -07004665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 // Persist setting
4667 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4668 }
Romain Guy06882f82009-06-10 13:36:04 -07004669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004670 public void setAnimationScales(float[] scales) {
4671 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4672 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004673 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004674 }
4675
4676 if (scales != null) {
4677 if (scales.length >= 1) {
4678 mWindowAnimationScale = fixScale(scales[0]);
4679 }
4680 if (scales.length >= 2) {
4681 mTransitionAnimationScale = fixScale(scales[1]);
4682 }
4683 }
Romain Guy06882f82009-06-10 13:36:04 -07004684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 // Persist setting
4686 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4687 }
Romain Guy06882f82009-06-10 13:36:04 -07004688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 public float getAnimationScale(int which) {
4690 switch (which) {
4691 case 0: return mWindowAnimationScale;
4692 case 1: return mTransitionAnimationScale;
4693 }
4694 return 0;
4695 }
Romain Guy06882f82009-06-10 13:36:04 -07004696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 public float[] getAnimationScales() {
4698 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4699 }
Romain Guy06882f82009-06-10 13:36:04 -07004700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004701 public int getSwitchState(int sw) {
4702 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4703 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004704 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004705 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004706 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 }
Romain Guy06882f82009-06-10 13:36:04 -07004708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 public int getSwitchStateForDevice(int devid, int sw) {
4710 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4711 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004712 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004713 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004714 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004715 }
Romain Guy06882f82009-06-10 13:36:04 -07004716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 public int getScancodeState(int sw) {
4718 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4719 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004720 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004721 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004722 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004723 }
Romain Guy06882f82009-06-10 13:36:04 -07004724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004725 public int getScancodeStateForDevice(int devid, int sw) {
4726 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4727 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004728 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004729 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004730 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004731 }
Romain Guy06882f82009-06-10 13:36:04 -07004732
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004733 public int getTrackballScancodeState(int sw) {
4734 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4735 "getTrackballScancodeState()")) {
4736 throw new SecurityException("Requires READ_INPUT_STATE permission");
4737 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004738 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004739 }
4740
4741 public int getDPadScancodeState(int sw) {
4742 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4743 "getDPadScancodeState()")) {
4744 throw new SecurityException("Requires READ_INPUT_STATE permission");
4745 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004746 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004747 }
4748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004749 public int getKeycodeState(int sw) {
4750 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4751 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004752 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004753 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004754 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004755 }
Romain Guy06882f82009-06-10 13:36:04 -07004756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004757 public int getKeycodeStateForDevice(int devid, int sw) {
4758 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4759 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004760 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004761 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004762 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004763 }
Romain Guy06882f82009-06-10 13:36:04 -07004764
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004765 public int getTrackballKeycodeState(int sw) {
4766 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4767 "getTrackballKeycodeState()")) {
4768 throw new SecurityException("Requires READ_INPUT_STATE permission");
4769 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004770 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004771 }
4772
4773 public int getDPadKeycodeState(int sw) {
4774 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4775 "getDPadKeycodeState()")) {
4776 throw new SecurityException("Requires READ_INPUT_STATE permission");
4777 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004778 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004779 }
Jeff Browna41ca772010-08-11 14:46:32 -07004780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004781 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004782 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 }
Romain Guy06882f82009-06-10 13:36:04 -07004784
Jeff Browna41ca772010-08-11 14:46:32 -07004785 public InputChannel monitorInput(String inputChannelName) {
4786 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4787 "monitorInput()")) {
4788 throw new SecurityException("Requires READ_INPUT_STATE permission");
4789 }
4790 return mInputManager.monitorInput(inputChannelName);
4791 }
4792
Jeff Brown8d608662010-08-30 03:02:23 -07004793 public InputDevice getInputDevice(int deviceId) {
4794 return mInputManager.getInputDevice(deviceId);
4795 }
4796
4797 public int[] getInputDeviceIds() {
4798 return mInputManager.getInputDeviceIds();
4799 }
4800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 public void enableScreenAfterBoot() {
4802 synchronized(mWindowMap) {
4803 if (mSystemBooted) {
4804 return;
4805 }
4806 mSystemBooted = true;
4807 }
Romain Guy06882f82009-06-10 13:36:04 -07004808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004809 performEnableScreen();
4810 }
Romain Guy06882f82009-06-10 13:36:04 -07004811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 public void enableScreenIfNeededLocked() {
4813 if (mDisplayEnabled) {
4814 return;
4815 }
4816 if (!mSystemBooted) {
4817 return;
4818 }
4819 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4820 }
Romain Guy06882f82009-06-10 13:36:04 -07004821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822 public void performEnableScreen() {
4823 synchronized(mWindowMap) {
4824 if (mDisplayEnabled) {
4825 return;
4826 }
4827 if (!mSystemBooted) {
4828 return;
4829 }
Romain Guy06882f82009-06-10 13:36:04 -07004830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 // Don't enable the screen until all existing windows
4832 // have been drawn.
4833 final int N = mWindows.size();
4834 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004835 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004836 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 return;
4838 }
4839 }
Romain Guy06882f82009-06-10 13:36:04 -07004840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004841 mDisplayEnabled = true;
4842 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004843 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004844 StringWriter sw = new StringWriter();
4845 PrintWriter pw = new PrintWriter(sw);
4846 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004847 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 }
4849 try {
4850 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4851 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004852 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 Parcel data = Parcel.obtain();
4854 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4855 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4856 data, null, 0);
4857 data.recycle();
4858 }
4859 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004860 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004861 }
4862 }
Romain Guy06882f82009-06-10 13:36:04 -07004863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004866 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004867 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4868 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004869 }
Romain Guy06882f82009-06-10 13:36:04 -07004870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 public void setInTouchMode(boolean mode) {
4872 synchronized(mWindowMap) {
4873 mInTouchMode = mode;
4874 }
4875 }
4876
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004877 // TODO: more accounting of which pid(s) turned it on, keep count,
4878 // only allow disables from pids which have count on, etc.
4879 public void showStrictModeViolation(boolean on) {
4880 int pid = Binder.getCallingPid();
4881 synchronized(mWindowMap) {
4882 // Ignoring requests to enable the red border from clients
4883 // which aren't on screen. (e.g. Broadcast Receivers in
4884 // the background..)
4885 if (on) {
4886 boolean isVisible = false;
4887 for (WindowState ws : mWindows) {
4888 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4889 isVisible = true;
4890 break;
4891 }
4892 }
4893 if (!isVisible) {
4894 return;
4895 }
4896 }
4897
4898 Surface.openTransaction();
4899 if (mStrictModeFlash == null) {
4900 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4901 }
4902 mStrictModeFlash.setVisibility(on);
4903 Surface.closeTransaction();
4904 }
4905 }
4906
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004907 public void setStrictModeVisualIndicatorPreference(String value) {
4908 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4909 }
4910
Dianne Hackbornd2835932010-12-13 16:28:46 -08004911 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004912 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4913 "screenshotApplications()")) {
4914 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
4915 }
4916
4917 Bitmap rawss;
4918
Dianne Hackbornd2835932010-12-13 16:28:46 -08004919 int maxLayer = 0;
4920 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004921 final Rect frame = new Rect();
4922
4923 float scale;
4924 int sw, sh, dw, dh;
4925 int rot;
4926
4927 synchronized(mWindowMap) {
4928 long ident = Binder.clearCallingIdentity();
4929
4930 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
4931 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
4932 + TYPE_LAYER_OFFSET;
4933 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
4934
4935 // Figure out the part of the screen that is actually the app.
4936 for (int i=0; i<mWindows.size(); i++) {
4937 WindowState ws = mWindows.get(i);
4938 if (ws.mSurface == null) {
4939 continue;
4940 }
4941 if (ws.mLayer >= aboveAppLayer) {
4942 break;
4943 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08004944 if (appToken != null && (ws.mAppToken == null
4945 || ws.mAppToken.token != appToken)) {
4946 continue;
4947 }
4948 if (maxLayer < ws.mAnimLayer) {
4949 maxLayer = ws.mAnimLayer;
4950 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004951 final Rect wf = ws.mFrame;
4952 final Rect cr = ws.mContentInsets;
4953 int left = wf.left + cr.left;
4954 int top = wf.top + cr.top;
4955 int right = wf.right - cr.right;
4956 int bottom = wf.bottom - cr.bottom;
4957 frame.union(left, top, right, bottom);
4958 }
4959 Binder.restoreCallingIdentity(ident);
4960
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004961 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004962 return null;
4963 }
4964
4965 // The screenshot API does not apply the current screen rotation.
4966 rot = mDisplay.getRotation();
4967 int fw = frame.width();
4968 int fh = frame.height();
4969
4970 // First try reducing to fit in x dimension.
4971 scale = maxWidth/(float)fw;
4972 sw = maxWidth;
4973 sh = (int)(fh*scale);
4974 if (sh > maxHeight) {
4975 // y dimension became too long; constrain by that.
4976 scale = maxHeight/(float)fh;
4977 sw = (int)(fw*scale);
4978 sh = maxHeight;
4979 }
4980
4981 // The screen shot will contain the entire screen.
4982 dw = (int)(mDisplay.getWidth()*scale);
4983 dh = (int)(mDisplay.getHeight()*scale);
4984 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
4985 int tmp = dw;
4986 dw = dh;
4987 dh = tmp;
4988 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
4989 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08004990 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004991 }
4992
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004993 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08004994 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
4995 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08004996 return null;
4997 }
4998
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004999 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5000 Matrix matrix = new Matrix();
5001 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5002 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5003 Canvas canvas = new Canvas(bm);
5004 canvas.drawBitmap(rawss, matrix, null);
5005
5006 rawss.recycle();
5007 return bm;
5008 }
5009
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005010 public void freezeRotation() {
5011 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5012 "setRotation()")) {
5013 throw new SecurityException("Requires SET_ORIENTATION permission");
5014 }
5015
5016 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5017 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5018 }
5019
5020 public void thawRotation() {
5021 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5022 "setRotation()")) {
5023 throw new SecurityException("Requires SET_ORIENTATION permission");
5024 }
5025
5026 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5027 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5028 }
5029
Romain Guy06882f82009-06-10 13:36:04 -07005030 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005031 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005032 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005033 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005034 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 }
5036
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005037 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005038 }
Romain Guy06882f82009-06-10 13:36:04 -07005039
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005040 public void setRotationUnchecked(int rotation,
5041 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005042 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005043 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 long origId = Binder.clearCallingIdentity();
5046 boolean changed;
5047 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005048 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005049 }
Romain Guy06882f82009-06-10 13:36:04 -07005050
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005051 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005052 sendNewConfiguration();
5053 }
Romain Guy06882f82009-06-10 13:36:04 -07005054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 Binder.restoreCallingIdentity(origId);
5056 }
Romain Guy06882f82009-06-10 13:36:04 -07005057
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005058 /**
5059 * Apply a new rotation to the screen, respecting the requests of
5060 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5061 * re-evaluate the desired rotation.
5062 *
5063 * Returns null if the rotation has been changed. In this case YOU
5064 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5065 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005066 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005067 boolean changed;
5068 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5069 rotation = mRequestedRotation;
5070 } else {
5071 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005072 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005074 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005075 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005076 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005077 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005078 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005080 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005081 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005082 "Rotation changed to " + rotation
5083 + " from " + mRotation
5084 + " (forceApp=" + mForcedAppOrientation
5085 + ", req=" + mRequestedRotation + ")");
5086 mRotation = rotation;
5087 mWindowsFreezingScreen = true;
5088 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5089 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5090 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005091 mWaitingForConfig = true;
5092 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005093 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005094 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005095 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005096 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005097 if (CUSTOM_SCREEN_ROTATION) {
5098 Surface.freezeDisplay(0);
5099 Surface.openTransaction();
5100 if (mScreenRotationAnimation != null) {
5101 mScreenRotationAnimation.setRotation(rotation);
5102 }
5103 Surface.closeTransaction();
5104 Surface.setOrientation(0, rotation, animFlags);
5105 Surface.unfreezeDisplay(0);
5106 } else {
5107 Surface.setOrientation(0, rotation, animFlags);
5108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005109 }
5110 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005111 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005112 if (w.mSurface != null) {
5113 w.mOrientationChanging = true;
5114 }
5115 }
5116 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5117 try {
5118 mRotationWatchers.get(i).onRotationChanged(rotation);
5119 } catch (RemoteException e) {
5120 }
5121 }
5122 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 return changed;
5125 }
Romain Guy06882f82009-06-10 13:36:04 -07005126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005127 public int getRotation() {
5128 return mRotation;
5129 }
5130
5131 public int watchRotation(IRotationWatcher watcher) {
5132 final IBinder watcherBinder = watcher.asBinder();
5133 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5134 public void binderDied() {
5135 synchronized (mWindowMap) {
5136 for (int i=0; i<mRotationWatchers.size(); i++) {
5137 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005138 IRotationWatcher removed = mRotationWatchers.remove(i);
5139 if (removed != null) {
5140 removed.asBinder().unlinkToDeath(this, 0);
5141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005142 i--;
5143 }
5144 }
5145 }
5146 }
5147 };
Romain Guy06882f82009-06-10 13:36:04 -07005148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005149 synchronized (mWindowMap) {
5150 try {
5151 watcher.asBinder().linkToDeath(dr, 0);
5152 mRotationWatchers.add(watcher);
5153 } catch (RemoteException e) {
5154 // Client died, no cleanup needed.
5155 }
Romain Guy06882f82009-06-10 13:36:04 -07005156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005157 return mRotation;
5158 }
5159 }
5160
5161 /**
5162 * Starts the view server on the specified port.
5163 *
5164 * @param port The port to listener to.
5165 *
5166 * @return True if the server was successfully started, false otherwise.
5167 *
5168 * @see com.android.server.ViewServer
5169 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5170 */
5171 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005172 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005173 return false;
5174 }
5175
5176 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5177 return false;
5178 }
5179
5180 if (port < 1024) {
5181 return false;
5182 }
5183
5184 if (mViewServer != null) {
5185 if (!mViewServer.isRunning()) {
5186 try {
5187 return mViewServer.start();
5188 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005189 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005190 }
5191 }
5192 return false;
5193 }
5194
5195 try {
5196 mViewServer = new ViewServer(this, port);
5197 return mViewServer.start();
5198 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005199 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005200 }
5201 return false;
5202 }
5203
Romain Guy06882f82009-06-10 13:36:04 -07005204 private boolean isSystemSecure() {
5205 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5206 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5207 }
5208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005209 /**
5210 * Stops the view server if it exists.
5211 *
5212 * @return True if the server stopped, false if it wasn't started or
5213 * couldn't be stopped.
5214 *
5215 * @see com.android.server.ViewServer
5216 */
5217 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005218 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005219 return false;
5220 }
5221
5222 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5223 return false;
5224 }
5225
5226 if (mViewServer != null) {
5227 return mViewServer.stop();
5228 }
5229 return false;
5230 }
5231
5232 /**
5233 * Indicates whether the view server is running.
5234 *
5235 * @return True if the server is running, false otherwise.
5236 *
5237 * @see com.android.server.ViewServer
5238 */
5239 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005240 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 return false;
5242 }
5243
5244 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5245 return false;
5246 }
5247
5248 return mViewServer != null && mViewServer.isRunning();
5249 }
5250
5251 /**
5252 * Lists all availble windows in the system. The listing is written in the
5253 * specified Socket's output stream with the following syntax:
5254 * windowHashCodeInHexadecimal windowName
5255 * Each line of the ouput represents a different window.
5256 *
5257 * @param client The remote client to send the listing to.
5258 * @return False if an error occured, true otherwise.
5259 */
5260 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005261 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 return false;
5263 }
5264
5265 boolean result = true;
5266
Jeff Browne33348b2010-07-15 23:54:05 -07005267 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005268 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005269 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005270 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005271 }
5272
5273 BufferedWriter out = null;
5274
5275 // Any uncaught exception will crash the system process
5276 try {
5277 OutputStream clientStream = client.getOutputStream();
5278 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5279
5280 final int count = windows.length;
5281 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005282 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005283 out.write(Integer.toHexString(System.identityHashCode(w)));
5284 out.write(' ');
5285 out.append(w.mAttrs.getTitle());
5286 out.write('\n');
5287 }
5288
5289 out.write("DONE.\n");
5290 out.flush();
5291 } catch (Exception e) {
5292 result = false;
5293 } finally {
5294 if (out != null) {
5295 try {
5296 out.close();
5297 } catch (IOException e) {
5298 result = false;
5299 }
5300 }
5301 }
5302
5303 return result;
5304 }
5305
5306 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005307 * Returns the focused window in the following format:
5308 * windowHashCodeInHexadecimal windowName
5309 *
5310 * @param client The remote client to send the listing to.
5311 * @return False if an error occurred, true otherwise.
5312 */
5313 boolean viewServerGetFocusedWindow(Socket client) {
5314 if (isSystemSecure()) {
5315 return false;
5316 }
5317
5318 boolean result = true;
5319
5320 WindowState focusedWindow = getFocusedWindow();
5321
5322 BufferedWriter out = null;
5323
5324 // Any uncaught exception will crash the system process
5325 try {
5326 OutputStream clientStream = client.getOutputStream();
5327 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5328
5329 if(focusedWindow != null) {
5330 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5331 out.write(' ');
5332 out.append(focusedWindow.mAttrs.getTitle());
5333 }
5334 out.write('\n');
5335 out.flush();
5336 } catch (Exception e) {
5337 result = false;
5338 } finally {
5339 if (out != null) {
5340 try {
5341 out.close();
5342 } catch (IOException e) {
5343 result = false;
5344 }
5345 }
5346 }
5347
5348 return result;
5349 }
5350
5351 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005352 * Sends a command to a target window. The result of the command, if any, will be
5353 * written in the output stream of the specified socket.
5354 *
5355 * The parameters must follow this syntax:
5356 * windowHashcode extra
5357 *
5358 * Where XX is the length in characeters of the windowTitle.
5359 *
5360 * The first parameter is the target window. The window with the specified hashcode
5361 * will be the target. If no target can be found, nothing happens. The extra parameters
5362 * will be delivered to the target window and as parameters to the command itself.
5363 *
5364 * @param client The remote client to sent the result, if any, to.
5365 * @param command The command to execute.
5366 * @param parameters The command parameters.
5367 *
5368 * @return True if the command was successfully delivered, false otherwise. This does
5369 * not indicate whether the command itself was successful.
5370 */
5371 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005372 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005373 return false;
5374 }
5375
5376 boolean success = true;
5377 Parcel data = null;
5378 Parcel reply = null;
5379
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005380 BufferedWriter out = null;
5381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 // Any uncaught exception will crash the system process
5383 try {
5384 // Find the hashcode of the window
5385 int index = parameters.indexOf(' ');
5386 if (index == -1) {
5387 index = parameters.length();
5388 }
5389 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005390 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005391
5392 // Extract the command's parameter after the window description
5393 if (index < parameters.length()) {
5394 parameters = parameters.substring(index + 1);
5395 } else {
5396 parameters = "";
5397 }
5398
5399 final WindowManagerService.WindowState window = findWindow(hashCode);
5400 if (window == null) {
5401 return false;
5402 }
5403
5404 data = Parcel.obtain();
5405 data.writeInterfaceToken("android.view.IWindow");
5406 data.writeString(command);
5407 data.writeString(parameters);
5408 data.writeInt(1);
5409 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5410
5411 reply = Parcel.obtain();
5412
5413 final IBinder binder = window.mClient.asBinder();
5414 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5415 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5416
5417 reply.readException();
5418
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005419 if (!client.isOutputShutdown()) {
5420 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5421 out.write("DONE\n");
5422 out.flush();
5423 }
5424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005425 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005426 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427 success = false;
5428 } finally {
5429 if (data != null) {
5430 data.recycle();
5431 }
5432 if (reply != null) {
5433 reply.recycle();
5434 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005435 if (out != null) {
5436 try {
5437 out.close();
5438 } catch (IOException e) {
5439
5440 }
5441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005442 }
5443
5444 return success;
5445 }
5446
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005447 public void addWindowChangeListener(WindowChangeListener listener) {
5448 synchronized(mWindowMap) {
5449 mWindowChangeListeners.add(listener);
5450 }
5451 }
5452
5453 public void removeWindowChangeListener(WindowChangeListener listener) {
5454 synchronized(mWindowMap) {
5455 mWindowChangeListeners.remove(listener);
5456 }
5457 }
5458
5459 private void notifyWindowsChanged() {
5460 WindowChangeListener[] windowChangeListeners;
5461 synchronized(mWindowMap) {
5462 if(mWindowChangeListeners.isEmpty()) {
5463 return;
5464 }
5465 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5466 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5467 }
5468 int N = windowChangeListeners.length;
5469 for(int i = 0; i < N; i++) {
5470 windowChangeListeners[i].windowsChanged();
5471 }
5472 }
5473
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005474 private void notifyFocusChanged() {
5475 WindowChangeListener[] windowChangeListeners;
5476 synchronized(mWindowMap) {
5477 if(mWindowChangeListeners.isEmpty()) {
5478 return;
5479 }
5480 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5481 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5482 }
5483 int N = windowChangeListeners.length;
5484 for(int i = 0; i < N; i++) {
5485 windowChangeListeners[i].focusChanged();
5486 }
5487 }
5488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005489 private WindowState findWindow(int hashCode) {
5490 if (hashCode == -1) {
5491 return getFocusedWindow();
5492 }
5493
5494 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005495 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 final int count = windows.size();
5497
5498 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005499 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005500 if (System.identityHashCode(w) == hashCode) {
5501 return w;
5502 }
5503 }
5504 }
5505
5506 return null;
5507 }
5508
5509 /*
5510 * Instruct the Activity Manager to fetch the current configuration and broadcast
5511 * that to config-changed listeners if appropriate.
5512 */
5513 void sendNewConfiguration() {
5514 try {
5515 mActivityManager.updateConfiguration(null);
5516 } catch (RemoteException e) {
5517 }
5518 }
Romain Guy06882f82009-06-10 13:36:04 -07005519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005520 public Configuration computeNewConfiguration() {
5521 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005522 return computeNewConfigurationLocked();
5523 }
5524 }
Romain Guy06882f82009-06-10 13:36:04 -07005525
Dianne Hackbornc485a602009-03-24 22:39:49 -07005526 Configuration computeNewConfigurationLocked() {
5527 Configuration config = new Configuration();
5528 if (!computeNewConfigurationLocked(config)) {
5529 return null;
5530 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005531 return config;
5532 }
Romain Guy06882f82009-06-10 13:36:04 -07005533
Dianne Hackbornc485a602009-03-24 22:39:49 -07005534 boolean computeNewConfigurationLocked(Configuration config) {
5535 if (mDisplay == null) {
5536 return false;
5537 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005538
5539 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005540
5541 // Use the effective "visual" dimensions based on current rotation
5542 final boolean rotated = (mRotation == Surface.ROTATION_90
5543 || mRotation == Surface.ROTATION_270);
5544 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5545 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5546
Dianne Hackbornc485a602009-03-24 22:39:49 -07005547 int orientation = Configuration.ORIENTATION_SQUARE;
5548 if (dw < dh) {
5549 orientation = Configuration.ORIENTATION_PORTRAIT;
5550 } else if (dw > dh) {
5551 orientation = Configuration.ORIENTATION_LANDSCAPE;
5552 }
5553 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005554
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005555 DisplayMetrics dm = new DisplayMetrics();
5556 mDisplay.getMetrics(dm);
5557 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5558
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005559 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005560 // Note we only do this once because at this point we don't
5561 // expect the screen to change in this way at runtime, and want
5562 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005563 int longSize = dw;
5564 int shortSize = dh;
5565 if (longSize < shortSize) {
5566 int tmp = longSize;
5567 longSize = shortSize;
5568 shortSize = tmp;
5569 }
5570 longSize = (int)(longSize/dm.density);
5571 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005572
Dianne Hackborn723738c2009-06-25 19:48:04 -07005573 // These semi-magic numbers define our compatibility modes for
5574 // applications with different screens. Don't change unless you
5575 // make sure to test lots and lots of apps!
5576 if (longSize < 470) {
5577 // This is shorter than an HVGA normal density screen (which
5578 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005579 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5580 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005581 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005582 // What size is this screen screen?
5583 if (longSize >= 800 && shortSize >= 600) {
5584 // SVGA or larger screens at medium density are the point
5585 // at which we consider it to be an extra large screen.
5586 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005587 } else if (longSize >= 530 && shortSize >= 400) {
5588 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005589 // at which we consider it to be a large screen.
5590 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5591 } else {
5592 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005593
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005594 // If this screen is wider than normal HVGA, or taller
5595 // than FWVGA, then for old apps we want to run in size
5596 // compatibility mode.
5597 if (shortSize > 321 || longSize > 570) {
5598 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5599 }
5600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005601
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005602 // Is this a long screen?
5603 if (((longSize*3)/5) >= (shortSize-1)) {
5604 // Anything wider than WVGA (5:3) is considering to be long.
5605 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5606 } else {
5607 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5608 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005609 }
5610 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005611 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005612
Dianne Hackbornc485a602009-03-24 22:39:49 -07005613 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5614 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5615 mPolicy.adjustConfigurationLw(config);
5616 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005617 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005618
5619 // -------------------------------------------------------------
5620 // Drag and drop
5621 // -------------------------------------------------------------
5622
5623 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5624 boolean localOnly, int width, int height, Surface outSurface) {
5625 if (DEBUG_DRAG) {
5626 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5627 + " local=" + localOnly + " win=" + window
5628 + " asbinder=" + window.asBinder());
5629 }
5630
5631 final int callerPid = Binder.getCallingPid();
5632 final long origId = Binder.clearCallingIdentity();
5633 IBinder token = null;
5634
5635 try {
5636 synchronized (mWindowMap) {
5637 try {
5638 // !!! TODO: fail if the given window does not currently have touch focus?
5639
5640 if (mDragState == null) {
5641 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5642 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5643 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005644 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005645 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005646 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005647 mDragState.mSurface = surface;
5648 mDragState.mLocalOnly = localOnly;
5649 token = mDragState.mToken = new Binder();
5650
5651 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005652 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5653 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005654 mH.sendMessageDelayed(msg, 5000);
5655 } else {
5656 Slog.w(TAG, "Drag already in progress");
5657 }
5658 } catch (Surface.OutOfResourcesException e) {
5659 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5660 if (mDragState != null) {
5661 mDragState.reset();
5662 mDragState = null;
5663 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005664 }
5665 }
5666 } finally {
5667 Binder.restoreCallingIdentity(origId);
5668 }
5669
5670 return token;
5671 }
5672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005673 // -------------------------------------------------------------
5674 // Input Events and Focus Management
5675 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005676
Jeff Brown349703e2010-06-22 01:27:15 -07005677 InputMonitor mInputMonitor = new InputMonitor();
5678
5679 /* Tracks the progress of input dispatch and ensures that input dispatch state
5680 * is kept in sync with changes in window focus, visibility, registration, and
5681 * other relevant Window Manager state transitions. */
5682 final class InputMonitor {
5683 // Current window with input focus for keys and other non-touch events. May be null.
5684 private WindowState mInputFocus;
5685
5686 // When true, prevents input dispatch from proceeding until set to false again.
5687 private boolean mInputDispatchFrozen;
5688
5689 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5690 private boolean mInputDispatchEnabled = true;
5691
5692 // Temporary list of windows information to provide to the input dispatcher.
5693 private InputWindowList mTempInputWindows = new InputWindowList();
5694
5695 // Temporary input application object to provide to the input dispatcher.
5696 private InputApplication mTempInputApplication = new InputApplication();
5697
5698 /* Notifies the window manager about a broken input channel.
5699 *
5700 * Called by the InputManager.
5701 */
5702 public void notifyInputChannelBroken(InputChannel inputChannel) {
5703 synchronized (mWindowMap) {
5704 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5705 if (windowState == null) {
5706 return; // irrelevant
5707 }
5708
5709 Slog.i(TAG, "WINDOW DIED " + windowState);
5710 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005711 }
5712 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005713
Jeff Brown519e0242010-09-15 15:18:56 -07005714 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005715 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005716 *
5717 * Called by the InputManager.
5718 */
Jeff Brown519e0242010-09-15 15:18:56 -07005719 public long notifyANR(Object token, InputChannel inputChannel) {
5720 AppWindowToken appWindowToken = null;
5721 if (inputChannel != null) {
5722 synchronized (mWindowMap) {
5723 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5724 if (windowState != null) {
5725 Slog.i(TAG, "Input event dispatching timed out sending to "
5726 + windowState.mAttrs.getTitle());
5727 appWindowToken = windowState.mAppToken;
5728 }
Jeff Brown349703e2010-06-22 01:27:15 -07005729 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005730 }
5731
Jeff Brown519e0242010-09-15 15:18:56 -07005732 if (appWindowToken == null && token != null) {
5733 appWindowToken = (AppWindowToken) token;
5734 Slog.i(TAG, "Input event dispatching timed out sending to application "
5735 + appWindowToken.stringName);
5736 }
Jeff Brown349703e2010-06-22 01:27:15 -07005737
Jeff Brown519e0242010-09-15 15:18:56 -07005738 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005739 try {
5740 // Notify the activity manager about the timeout and let it decide whether
5741 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005742 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005743 if (! abort) {
5744 // The activity manager declined to abort dispatching.
5745 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005746 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005747 }
Jeff Brown349703e2010-06-22 01:27:15 -07005748 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005749 }
5750 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005751 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005752 }
5753
Jeff Brown349703e2010-06-22 01:27:15 -07005754 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5755 synchronized (mWindowMap) {
5756 return getWindowStateForInputChannelLocked(inputChannel);
5757 }
5758 }
5759
5760 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5761 int windowCount = mWindows.size();
5762 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005763 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005764 if (windowState.mInputChannel == inputChannel) {
5765 return windowState;
5766 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005767 }
5768
Jeff Brown349703e2010-06-22 01:27:15 -07005769 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005770 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005771
Chris Tatea32dcf72010-10-14 12:13:50 -07005772 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005773 final InputWindow inputWindow = windowList.add();
5774 inputWindow.inputChannel = mDragState.mServerChannel;
5775 inputWindow.name = "drag";
5776 inputWindow.layoutParamsFlags = 0;
5777 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5778 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5779 inputWindow.visible = true;
5780 inputWindow.canReceiveKeys = false;
5781 inputWindow.hasFocus = true;
5782 inputWindow.hasWallpaper = false;
5783 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005784 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005785 inputWindow.ownerPid = Process.myPid();
5786 inputWindow.ownerUid = Process.myUid();
5787
5788 // The drag window covers the entire display
5789 inputWindow.frameLeft = 0;
5790 inputWindow.frameTop = 0;
5791 inputWindow.frameRight = mDisplay.getWidth();
5792 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005793
Christopher Tatea53146c2010-09-07 11:57:52 -07005794 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5795 inputWindow.visibleFrameTop = inputWindow.frameTop;
5796 inputWindow.visibleFrameRight = inputWindow.frameRight;
5797 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5798
5799 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5800 inputWindow.touchableAreaTop = inputWindow.frameTop;
5801 inputWindow.touchableAreaRight = inputWindow.frameRight;
5802 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5803 }
5804
Jeff Brown349703e2010-06-22 01:27:15 -07005805 /* Updates the cached window information provided to the input dispatcher. */
5806 public void updateInputWindowsLw() {
5807 // Populate the input window list with information about all of the windows that
5808 // could potentially receive input.
5809 // As an optimization, we could try to prune the list of windows but this turns
5810 // out to be difficult because only the native code knows for sure which window
5811 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005812 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005813
5814 // If there's a drag in flight, provide a pseudowindow to catch drag input
5815 final boolean inDrag = (mDragState != null);
5816 if (inDrag) {
5817 if (DEBUG_DRAG) {
5818 Log.d(TAG, "Inserting drag window");
5819 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005820 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005821 }
5822
Jeff Brown7fbdc842010-06-17 20:52:56 -07005823 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005824 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005825 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005826 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005827 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005828 continue;
5829 }
5830
Jeff Brown349703e2010-06-22 01:27:15 -07005831 final int flags = child.mAttrs.flags;
5832 final int type = child.mAttrs.type;
5833
5834 final boolean hasFocus = (child == mInputFocus);
5835 final boolean isVisible = child.isVisibleLw();
5836 final boolean hasWallpaper = (child == mWallpaperTarget)
5837 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005838
5839 // If there's a drag in progress and 'child' is a potential drop target,
5840 // make sure it's been told about the drag
5841 if (inDrag && isVisible) {
5842 mDragState.sendDragStartedIfNeededLw(child);
5843 }
5844
Jeff Brown349703e2010-06-22 01:27:15 -07005845 // Add a window to our list of input windows.
5846 final InputWindow inputWindow = mTempInputWindows.add();
5847 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005848 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005849 inputWindow.layoutParamsFlags = flags;
5850 inputWindow.layoutParamsType = type;
5851 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5852 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005853 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005854 inputWindow.hasFocus = hasFocus;
5855 inputWindow.hasWallpaper = hasWallpaper;
5856 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005857 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005858 inputWindow.ownerPid = child.mSession.mPid;
5859 inputWindow.ownerUid = child.mSession.mUid;
5860
5861 final Rect frame = child.mFrame;
5862 inputWindow.frameLeft = frame.left;
5863 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005864 inputWindow.frameRight = frame.right;
5865 inputWindow.frameBottom = frame.bottom;
5866
5867 final Rect visibleFrame = child.mVisibleFrame;
5868 inputWindow.visibleFrameLeft = visibleFrame.left;
5869 inputWindow.visibleFrameTop = visibleFrame.top;
5870 inputWindow.visibleFrameRight = visibleFrame.right;
5871 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005872
5873 switch (child.mTouchableInsets) {
5874 default:
5875 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5876 inputWindow.touchableAreaLeft = frame.left;
5877 inputWindow.touchableAreaTop = frame.top;
5878 inputWindow.touchableAreaRight = frame.right;
5879 inputWindow.touchableAreaBottom = frame.bottom;
5880 break;
5881
5882 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5883 Rect inset = child.mGivenContentInsets;
5884 inputWindow.touchableAreaLeft = frame.left + inset.left;
5885 inputWindow.touchableAreaTop = frame.top + inset.top;
5886 inputWindow.touchableAreaRight = frame.right - inset.right;
5887 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5888 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005889 }
Jeff Brown349703e2010-06-22 01:27:15 -07005890
5891 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5892 Rect inset = child.mGivenVisibleInsets;
5893 inputWindow.touchableAreaLeft = frame.left + inset.left;
5894 inputWindow.touchableAreaTop = frame.top + inset.top;
5895 inputWindow.touchableAreaRight = frame.right - inset.right;
5896 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005897 break;
5898 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005899 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005900 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005901
Jeff Brown349703e2010-06-22 01:27:15 -07005902 // Send windows to native code.
5903 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005904
Jeff Brown349703e2010-06-22 01:27:15 -07005905 // Clear the list in preparation for the next round.
5906 // Also avoids keeping InputChannel objects referenced unnecessarily.
5907 mTempInputWindows.clear();
5908 }
5909
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005910 /* Notifies that the lid switch changed state. */
5911 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5912 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5913 }
5914
Jeff Brown349703e2010-06-22 01:27:15 -07005915 /* Provides an opportunity for the window manager policy to intercept early key
5916 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08005917 public int interceptKeyBeforeQueueing(
5918 KeyEvent event, int policyFlags, boolean isScreenOn) {
5919 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005920 }
5921
5922 /* Provides an opportunity for the window manager policy to process a key before
5923 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08005924 public boolean interceptKeyBeforeDispatching(
5925 InputChannel focus, KeyEvent event, int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005926 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown1f245102010-11-18 20:53:46 -08005927 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005928 }
5929
Jeff Brown3915bb82010-11-05 15:02:16 -07005930 /* Provides an opportunity for the window manager policy to process a key that
5931 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08005932 public KeyEvent dispatchUnhandledKey(
Jeff Brown1f245102010-11-18 20:53:46 -08005933 InputChannel focus, KeyEvent event, int policyFlags) {
Jeff Brown3915bb82010-11-05 15:02:16 -07005934 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown1f245102010-11-18 20:53:46 -08005935 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07005936 }
5937
Jeff Brown349703e2010-06-22 01:27:15 -07005938 /* Called when the current input focus changes.
5939 * Layer assignment is assumed to be complete by the time this is called.
5940 */
5941 public void setInputFocusLw(WindowState newWindow) {
5942 if (DEBUG_INPUT) {
5943 Slog.d(TAG, "Input focus has changed to " + newWindow);
5944 }
5945
5946 if (newWindow != mInputFocus) {
5947 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005948 // Displaying a window implicitly causes dispatching to be unpaused.
5949 // This is to protect against bugs if someone pauses dispatching but
5950 // forgets to resume.
5951 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005952 }
Jeff Brown349703e2010-06-22 01:27:15 -07005953
5954 mInputFocus = newWindow;
5955 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005956 }
5957 }
5958
Jeff Brown349703e2010-06-22 01:27:15 -07005959 public void setFocusedAppLw(AppWindowToken newApp) {
5960 // Focused app has changed.
5961 if (newApp == null) {
5962 mInputManager.setFocusedApplication(null);
5963 } else {
5964 mTempInputApplication.name = newApp.toString();
5965 mTempInputApplication.dispatchingTimeoutNanos =
5966 newApp.inputDispatchingTimeoutNanos;
5967 mTempInputApplication.token = newApp;
5968
5969 mInputManager.setFocusedApplication(mTempInputApplication);
5970 }
5971 }
5972
Jeff Brown349703e2010-06-22 01:27:15 -07005973 public void pauseDispatchingLw(WindowToken window) {
5974 if (! window.paused) {
5975 if (DEBUG_INPUT) {
5976 Slog.v(TAG, "Pausing WindowToken " + window);
5977 }
5978
5979 window.paused = true;
5980 updateInputWindowsLw();
5981 }
5982 }
5983
5984 public void resumeDispatchingLw(WindowToken window) {
5985 if (window.paused) {
5986 if (DEBUG_INPUT) {
5987 Slog.v(TAG, "Resuming WindowToken " + window);
5988 }
5989
5990 window.paused = false;
5991 updateInputWindowsLw();
5992 }
5993 }
5994
5995 public void freezeInputDispatchingLw() {
5996 if (! mInputDispatchFrozen) {
5997 if (DEBUG_INPUT) {
5998 Slog.v(TAG, "Freezing input dispatching");
5999 }
6000
6001 mInputDispatchFrozen = true;
6002 updateInputDispatchModeLw();
6003 }
6004 }
6005
6006 public void thawInputDispatchingLw() {
6007 if (mInputDispatchFrozen) {
6008 if (DEBUG_INPUT) {
6009 Slog.v(TAG, "Thawing input dispatching");
6010 }
6011
6012 mInputDispatchFrozen = false;
6013 updateInputDispatchModeLw();
6014 }
6015 }
6016
6017 public void setEventDispatchingLw(boolean enabled) {
6018 if (mInputDispatchEnabled != enabled) {
6019 if (DEBUG_INPUT) {
6020 Slog.v(TAG, "Setting event dispatching to " + enabled);
6021 }
6022
6023 mInputDispatchEnabled = enabled;
6024 updateInputDispatchModeLw();
6025 }
6026 }
6027
6028 private void updateInputDispatchModeLw() {
6029 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6030 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006033 public void pauseKeyDispatching(IBinder _token) {
6034 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6035 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006036 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006037 }
6038
6039 synchronized (mWindowMap) {
6040 WindowToken token = mTokenMap.get(_token);
6041 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006042 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006043 }
6044 }
6045 }
6046
6047 public void resumeKeyDispatching(IBinder _token) {
6048 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6049 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006050 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006051 }
6052
6053 synchronized (mWindowMap) {
6054 WindowToken token = mTokenMap.get(_token);
6055 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006056 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006057 }
6058 }
6059 }
6060
6061 public void setEventDispatching(boolean enabled) {
6062 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6063 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006064 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006065 }
6066
6067 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006068 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006069 }
6070 }
Romain Guy06882f82009-06-10 13:36:04 -07006071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 /**
6073 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006074 * Even when sync is false, this method may block while waiting for current
6075 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006076 *
6077 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 * {@link SystemClock#uptimeMillis()} as the timebase.)
6079 * @param sync If true, wait for the event to be completed before returning to the caller.
6080 * @return Returns true if event was dispatched, false if it was dropped for any reason
6081 */
6082 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6083 long downTime = ev.getDownTime();
6084 long eventTime = ev.getEventTime();
6085
6086 int action = ev.getAction();
6087 int code = ev.getKeyCode();
6088 int repeatCount = ev.getRepeatCount();
6089 int metaState = ev.getMetaState();
6090 int deviceId = ev.getDeviceId();
6091 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006092 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006093 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006094
6095 if (source == InputDevice.SOURCE_UNKNOWN) {
6096 source = InputDevice.SOURCE_KEYBOARD;
6097 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098
6099 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6100 if (downTime == 0) downTime = eventTime;
6101
6102 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006103 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006104
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006105 final int pid = Binder.getCallingPid();
6106 final int uid = Binder.getCallingUid();
6107 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006108
Jeff Brownbbda99d2010-07-28 15:48:59 -07006109 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6110 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6111 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6112 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006113
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006114 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006115 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116 }
6117
6118 /**
6119 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006120 * Even when sync is false, this method may block while waiting for current
6121 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006122 *
6123 * @param ev A motion event describing the pointer (touch) action. (As noted in
6124 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006125 * {@link SystemClock#uptimeMillis()} as the timebase.)
6126 * @param sync If true, wait for the event to be completed before returning to the caller.
6127 * @return Returns true if event was dispatched, false if it was dropped for any reason
6128 */
6129 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006130 final int pid = Binder.getCallingPid();
6131 final int uid = Binder.getCallingUid();
6132 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006133
Jeff Brownc5ed5912010-07-14 18:48:53 -07006134 MotionEvent newEvent = MotionEvent.obtain(ev);
6135 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6136 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6137 }
6138
Jeff Brownbbda99d2010-07-28 15:48:59 -07006139 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6140 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6141 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6142 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006143
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006144 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006145 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 }
Romain Guy06882f82009-06-10 13:36:04 -07006147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 /**
6149 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006150 * Even when sync is false, this method may block while waiting for current
6151 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006152 *
6153 * @param ev A motion event describing the trackball action. (As noted in
6154 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155 * {@link SystemClock#uptimeMillis()} as the timebase.)
6156 * @param sync If true, wait for the event to be completed before returning to the caller.
6157 * @return Returns true if event was dispatched, false if it was dropped for any reason
6158 */
6159 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006160 final int pid = Binder.getCallingPid();
6161 final int uid = Binder.getCallingUid();
6162 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006163
Jeff Brownc5ed5912010-07-14 18:48:53 -07006164 MotionEvent newEvent = MotionEvent.obtain(ev);
6165 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6166 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6167 }
6168
Jeff Brownbbda99d2010-07-28 15:48:59 -07006169 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6170 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6171 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6172 INJECTION_TIMEOUT_MILLIS);
6173
6174 Binder.restoreCallingIdentity(ident);
6175 return reportInjectionResult(result);
6176 }
6177
6178 /**
6179 * Inject an input event into the UI without waiting for dispatch to commence.
6180 * This variant is useful for fire-and-forget input event injection. It does not
6181 * block any longer than it takes to enqueue the input event.
6182 *
6183 * @param ev An input event. (Be sure to set the input source correctly.)
6184 * @return Returns true if event was dispatched, false if it was dropped for any reason
6185 */
6186 public boolean injectInputEventNoWait(InputEvent ev) {
6187 final int pid = Binder.getCallingPid();
6188 final int uid = Binder.getCallingUid();
6189 final long ident = Binder.clearCallingIdentity();
6190
6191 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6192 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6193 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006194
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006195 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006196 return reportInjectionResult(result);
6197 }
6198
6199 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006200 switch (result) {
6201 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6202 Slog.w(TAG, "Input event injection permission denied.");
6203 throw new SecurityException(
6204 "Injecting to another application requires INJECT_EVENTS permission");
6205 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006206 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006207 return true;
6208 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6209 Slog.w(TAG, "Input event injection timed out.");
6210 return false;
6211 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6212 default:
6213 Slog.w(TAG, "Input event injection failed.");
6214 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006215 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 }
Romain Guy06882f82009-06-10 13:36:04 -07006217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 private WindowState getFocusedWindow() {
6219 synchronized (mWindowMap) {
6220 return getFocusedWindowLocked();
6221 }
6222 }
6223
6224 private WindowState getFocusedWindowLocked() {
6225 return mCurrentFocus;
6226 }
Romain Guy06882f82009-06-10 13:36:04 -07006227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 public boolean detectSafeMode() {
6229 mSafeMode = mPolicy.detectSafeMode();
6230 return mSafeMode;
6231 }
Romain Guy06882f82009-06-10 13:36:04 -07006232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006233 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006234 synchronized(mWindowMap) {
6235 if (mDisplay != null) {
6236 throw new IllegalStateException("Display already initialized");
6237 }
6238 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6239 mDisplay = wm.getDefaultDisplay();
6240 mInitialDisplayWidth = mDisplay.getWidth();
6241 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006242 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6243 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006244 }
6245
6246 try {
6247 mActivityManager.updateConfiguration(null);
6248 } catch (RemoteException e) {
6249 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006250
6251 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006252 }
6253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254 // -------------------------------------------------------------
6255 // Client Session State
6256 // -------------------------------------------------------------
6257
6258 private final class Session extends IWindowSession.Stub
6259 implements IBinder.DeathRecipient {
6260 final IInputMethodClient mClient;
6261 final IInputContext mInputContext;
6262 final int mUid;
6263 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006264 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006265 SurfaceSession mSurfaceSession;
6266 int mNumWindow = 0;
6267 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006269 public Session(IInputMethodClient client, IInputContext inputContext) {
6270 mClient = client;
6271 mInputContext = inputContext;
6272 mUid = Binder.getCallingUid();
6273 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006274 StringBuilder sb = new StringBuilder();
6275 sb.append("Session{");
6276 sb.append(Integer.toHexString(System.identityHashCode(this)));
6277 sb.append(" uid ");
6278 sb.append(mUid);
6279 sb.append("}");
6280 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006282 synchronized (mWindowMap) {
6283 if (mInputMethodManager == null && mHaveInputMethods) {
6284 IBinder b = ServiceManager.getService(
6285 Context.INPUT_METHOD_SERVICE);
6286 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6287 }
6288 }
6289 long ident = Binder.clearCallingIdentity();
6290 try {
6291 // Note: it is safe to call in to the input method manager
6292 // here because we are not holding our lock.
6293 if (mInputMethodManager != null) {
6294 mInputMethodManager.addClient(client, inputContext,
6295 mUid, mPid);
6296 } else {
6297 client.setUsingInputMethod(false);
6298 }
6299 client.asBinder().linkToDeath(this, 0);
6300 } catch (RemoteException e) {
6301 // The caller has died, so we can just forget about this.
6302 try {
6303 if (mInputMethodManager != null) {
6304 mInputMethodManager.removeClient(client);
6305 }
6306 } catch (RemoteException ee) {
6307 }
6308 } finally {
6309 Binder.restoreCallingIdentity(ident);
6310 }
6311 }
Romain Guy06882f82009-06-10 13:36:04 -07006312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 @Override
6314 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6315 throws RemoteException {
6316 try {
6317 return super.onTransact(code, data, reply, flags);
6318 } catch (RuntimeException e) {
6319 // Log all 'real' exceptions thrown to the caller
6320 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006321 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006322 }
6323 throw e;
6324 }
6325 }
6326
6327 public void binderDied() {
6328 // Note: it is safe to call in to the input method manager
6329 // here because we are not holding our lock.
6330 try {
6331 if (mInputMethodManager != null) {
6332 mInputMethodManager.removeClient(mClient);
6333 }
6334 } catch (RemoteException e) {
6335 }
6336 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006337 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 mClientDead = true;
6339 killSessionLocked();
6340 }
6341 }
6342
6343 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006344 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6345 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6346 outInputChannel);
6347 }
6348
6349 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006350 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006351 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 }
Romain Guy06882f82009-06-10 13:36:04 -07006353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 public void remove(IWindow window) {
6355 removeWindow(this, window);
6356 }
Romain Guy06882f82009-06-10 13:36:04 -07006357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006358 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6359 int requestedWidth, int requestedHeight, int viewFlags,
6360 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006361 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006362 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6363 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006364 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006365 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006366 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6367 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 }
Romain Guy06882f82009-06-10 13:36:04 -07006369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 public void setTransparentRegion(IWindow window, Region region) {
6371 setTransparentRegionWindow(this, window, region);
6372 }
Romain Guy06882f82009-06-10 13:36:04 -07006373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 public void setInsets(IWindow window, int touchableInsets,
6375 Rect contentInsets, Rect visibleInsets) {
6376 setInsetsWindow(this, window, touchableInsets, contentInsets,
6377 visibleInsets);
6378 }
Romain Guy06882f82009-06-10 13:36:04 -07006379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006380 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6381 getWindowDisplayFrame(this, window, outDisplayFrame);
6382 }
Romain Guy06882f82009-06-10 13:36:04 -07006383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006384 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006385 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 TAG, "IWindow finishDrawing called for " + window);
6387 finishDrawingWindow(this, window);
6388 }
6389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006390 public void setInTouchMode(boolean mode) {
6391 synchronized(mWindowMap) {
6392 mInTouchMode = mode;
6393 }
6394 }
6395
6396 public boolean getInTouchMode() {
6397 synchronized(mWindowMap) {
6398 return mInTouchMode;
6399 }
6400 }
6401
6402 public boolean performHapticFeedback(IWindow window, int effectId,
6403 boolean always) {
6404 synchronized(mWindowMap) {
6405 long ident = Binder.clearCallingIdentity();
6406 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006407 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006408 windowForClientLocked(this, window, true),
6409 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006410 } finally {
6411 Binder.restoreCallingIdentity(ident);
6412 }
6413 }
6414 }
Romain Guy06882f82009-06-10 13:36:04 -07006415
Christopher Tatea53146c2010-09-07 11:57:52 -07006416 /* Drag/drop */
6417 public IBinder prepareDrag(IWindow window, boolean localOnly,
6418 int width, int height, Surface outSurface) {
6419 return prepareDragSurface(window, mSurfaceSession, localOnly,
6420 width, height, outSurface);
6421 }
6422
6423 public boolean performDrag(IWindow window, IBinder dragToken,
6424 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6425 ClipData data) {
6426 if (DEBUG_DRAG) {
6427 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6428 }
6429
6430 synchronized (mWindowMap) {
6431 if (mDragState == null) {
6432 Slog.w(TAG, "No drag prepared");
6433 throw new IllegalStateException("performDrag() without prepareDrag()");
6434 }
6435
6436 if (dragToken != mDragState.mToken) {
6437 Slog.w(TAG, "Performing mismatched drag");
6438 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6439 }
6440
6441 WindowState callingWin = windowForClientLocked(null, window, false);
6442 if (callingWin == null) {
6443 Slog.w(TAG, "Bad requesting window " + window);
6444 return false; // !!! TODO: throw here?
6445 }
6446
6447 // !!! TODO: if input is not still focused on the initiating window, fail
6448 // the drag initiation (e.g. an alarm window popped up just as the application
6449 // called performDrag()
6450
6451 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6452
Christopher Tate2c095f32010-10-04 14:13:40 -07006453 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6454 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006455
Chris Tateb478f462010-10-15 16:02:26 -07006456 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6457 // the actual drag event dispatch stuff in the dragstate
6458
Christopher Tatea53146c2010-09-07 11:57:52 -07006459 mDragState.register();
6460 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006461 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6462 mDragState.mServerChannel)) {
6463 Slog.e(TAG, "Unable to transfer touch focus");
6464 mDragState.unregister();
6465 mDragState = null;
6466 mInputMonitor.updateInputWindowsLw();
6467 return false;
6468 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006469
6470 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006471 mDragState.mCurrentX = touchX;
6472 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006473 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006474
6475 // remember the thumb offsets for later
6476 mDragState.mThumbOffsetX = thumbCenterX;
6477 mDragState.mThumbOffsetY = thumbCenterY;
6478
6479 // Make the surface visible at the proper location
6480 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006481 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006482 try {
6483 surface.setPosition((int)(touchX - thumbCenterX),
6484 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006485 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006486 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006487 surface.show();
6488 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006489 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006490 }
6491 }
6492
6493 return true; // success!
6494 }
6495
Chris Tated4533f142010-10-19 15:15:08 -07006496 public void reportDropResult(IWindow window, boolean consumed) {
6497 IBinder token = window.asBinder();
6498 if (DEBUG_DRAG) {
6499 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6500 }
6501
6502 synchronized (mWindowMap) {
6503 if (mDragState.mToken != token) {
6504 Slog.w(TAG, "Invalid drop-result claim by " + window);
6505 throw new IllegalStateException("reportDropResult() by non-recipient");
6506 }
6507
6508 // The right window has responded, even if it's no longer around,
6509 // so be sure to halt the timeout even if the later WindowState
6510 // lookup fails.
6511 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6512
6513 WindowState callingWin = windowForClientLocked(null, window, false);
6514 if (callingWin == null) {
6515 Slog.w(TAG, "Bad result-reporting window " + window);
6516 return; // !!! TODO: throw here?
6517 }
6518
6519 mDragState.mDragResult = consumed;
6520 mDragState.endDragLw();
6521 }
6522 }
6523
Christopher Tatea53146c2010-09-07 11:57:52 -07006524 public void dragRecipientEntered(IWindow window) {
6525 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006526 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006527 }
6528 }
6529
6530 public void dragRecipientExited(IWindow window) {
6531 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006532 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006533 }
6534 }
6535
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006536 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006537 synchronized(mWindowMap) {
6538 long ident = Binder.clearCallingIdentity();
6539 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006540 setWindowWallpaperPositionLocked(
6541 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006542 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006543 } finally {
6544 Binder.restoreCallingIdentity(ident);
6545 }
6546 }
6547 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006548
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006549 public void wallpaperOffsetsComplete(IBinder window) {
6550 WindowManagerService.this.wallpaperOffsetsComplete(window);
6551 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006552
Dianne Hackborn75804932009-10-20 20:15:20 -07006553 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6554 int z, Bundle extras, boolean sync) {
6555 synchronized(mWindowMap) {
6556 long ident = Binder.clearCallingIdentity();
6557 try {
6558 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006559 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006560 action, x, y, z, extras, sync);
6561 } finally {
6562 Binder.restoreCallingIdentity(ident);
6563 }
6564 }
6565 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006566
Dianne Hackborn75804932009-10-20 20:15:20 -07006567 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6568 WindowManagerService.this.wallpaperCommandComplete(window, result);
6569 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 void windowAddedLocked() {
6572 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006573 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 TAG, "First window added to " + this + ", creating SurfaceSession");
6575 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006576 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006577 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006578 mSessions.add(this);
6579 }
6580 mNumWindow++;
6581 }
6582
6583 void windowRemovedLocked() {
6584 mNumWindow--;
6585 killSessionLocked();
6586 }
Romain Guy06882f82009-06-10 13:36:04 -07006587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006588 void killSessionLocked() {
6589 if (mNumWindow <= 0 && mClientDead) {
6590 mSessions.remove(this);
6591 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006592 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 TAG, "Last window removed from " + this
6594 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006595 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006596 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 try {
6598 mSurfaceSession.kill();
6599 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006600 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006601 + mSurfaceSession + " in session " + this
6602 + ": " + e.toString());
6603 }
6604 mSurfaceSession = null;
6605 }
6606 }
6607 }
Romain Guy06882f82009-06-10 13:36:04 -07006608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006610 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6611 pw.print(" mClientDead="); pw.print(mClientDead);
6612 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 }
6614
6615 @Override
6616 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006617 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006618 }
6619 }
6620
6621 // -------------------------------------------------------------
6622 // Client Window State
6623 // -------------------------------------------------------------
6624
6625 private final class WindowState implements WindowManagerPolicy.WindowState {
6626 final Session mSession;
6627 final IWindow mClient;
6628 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006629 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006630 AppWindowToken mAppToken;
6631 AppWindowToken mTargetAppToken;
6632 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6633 final DeathRecipient mDeathRecipient;
6634 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006635 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006636 final int mBaseLayer;
6637 final int mSubLayer;
6638 final boolean mLayoutAttached;
6639 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006640 final boolean mIsWallpaper;
6641 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642 int mViewVisibility;
6643 boolean mPolicyVisibility = true;
6644 boolean mPolicyVisibilityAfterAnim = true;
6645 boolean mAppFreezing;
6646 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006647 boolean mReportDestroySurface;
6648 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006649 boolean mAttachedHidden; // is our parent window hidden?
6650 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006651 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006652 int mRequestedWidth;
6653 int mRequestedHeight;
6654 int mLastRequestedWidth;
6655 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 int mLayer;
6657 int mAnimLayer;
6658 int mLastLayer;
6659 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006660 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006661 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006662
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006663 int mLayoutSeq = -1;
6664
6665 Configuration mConfiguration = null;
6666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006667 // Actual frame shown on-screen (may be modified by animation)
6668 final Rect mShownFrame = new Rect();
6669 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006672 * Set when we have changed the size of the surface, to know that
6673 * we must tell them application to resize (and thus redraw itself).
6674 */
6675 boolean mSurfaceResized;
6676
6677 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006678 * Insets that determine the actually visible area
6679 */
6680 final Rect mVisibleInsets = new Rect();
6681 final Rect mLastVisibleInsets = new Rect();
6682 boolean mVisibleInsetsChanged;
6683
6684 /**
6685 * Insets that are covered by system windows
6686 */
6687 final Rect mContentInsets = new Rect();
6688 final Rect mLastContentInsets = new Rect();
6689 boolean mContentInsetsChanged;
6690
6691 /**
6692 * Set to true if we are waiting for this window to receive its
6693 * given internal insets before laying out other windows based on it.
6694 */
6695 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006697 /**
6698 * These are the content insets that were given during layout for
6699 * this window, to be applied to windows behind it.
6700 */
6701 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 /**
6704 * These are the visible insets that were given during layout for
6705 * this window, to be applied to windows behind it.
6706 */
6707 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709 /**
6710 * Flag indicating whether the touchable region should be adjusted by
6711 * the visible insets; if false the area outside the visible insets is
6712 * NOT touchable, so we must use those to adjust the frame during hit
6713 * tests.
6714 */
6715 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006718 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006719 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6720 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6721 float mHScale=1, mVScale=1;
6722 float mLastHScale=1, mLastVScale=1;
6723 final Matrix mTmpMatrix = new Matrix();
6724
6725 // "Real" frame that the application sees.
6726 final Rect mFrame = new Rect();
6727 final Rect mLastFrame = new Rect();
6728
6729 final Rect mContainingFrame = new Rect();
6730 final Rect mDisplayFrame = new Rect();
6731 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006732 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006733 final Rect mVisibleFrame = new Rect();
6734
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006735 boolean mContentChanged;
6736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 float mShownAlpha = 1;
6738 float mAlpha = 1;
6739 float mLastAlpha = 1;
6740
6741 // Set to true if, when the window gets displayed, it should perform
6742 // an enter animation.
6743 boolean mEnterAnimationPending;
6744
6745 // Currently running animation.
6746 boolean mAnimating;
6747 boolean mLocalAnimating;
6748 Animation mAnimation;
6749 boolean mAnimationIsEntrance;
6750 boolean mHasTransformation;
6751 boolean mHasLocalTransformation;
6752 final Transformation mTransformation = new Transformation();
6753
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006754 // If a window showing a wallpaper: the requested offset for the
6755 // wallpaper; if a wallpaper window: the currently applied offset.
6756 float mWallpaperX = -1;
6757 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006758
6759 // If a window showing a wallpaper: what fraction of the offset
6760 // range corresponds to a full virtual screen.
6761 float mWallpaperXStep = -1;
6762 float mWallpaperYStep = -1;
6763
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006764 // Wallpaper windows: pixels offset based on above variables.
6765 int mXOffset;
6766 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006768 // This is set after IWindowSession.relayout() has been called at
6769 // least once for the window. It allows us to detect the situation
6770 // where we don't yet have a surface, but should have one soon, so
6771 // we can give the window focus before waiting for the relayout.
6772 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006774 // This is set after the Surface has been created but before the
6775 // window has been drawn. During this time the surface is hidden.
6776 boolean mDrawPending;
6777
6778 // This is set after the window has finished drawing for the first
6779 // time but before its surface is shown. The surface will be
6780 // displayed when the next layout is run.
6781 boolean mCommitDrawPending;
6782
6783 // This is set during the time after the window's drawing has been
6784 // committed, and before its surface is actually shown. It is used
6785 // to delay showing the surface until all windows in a token are ready
6786 // to be shown.
6787 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006789 // Set when the window has been shown in the screen the first time.
6790 boolean mHasDrawn;
6791
6792 // Currently running an exit animation?
6793 boolean mExiting;
6794
6795 // Currently on the mDestroySurface list?
6796 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 // Completely remove from window manager after exit animation?
6799 boolean mRemoveOnExit;
6800
6801 // Set when the orientation is changing and this window has not yet
6802 // been updated for the new orientation.
6803 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006805 // Is this window now (or just being) removed?
6806 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006807
Dianne Hackborn16064f92010-03-25 00:47:24 -07006808 // For debugging, this is the last information given to the surface flinger.
6809 boolean mSurfaceShown;
6810 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6811 int mSurfaceLayer;
6812 float mSurfaceAlpha;
6813
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006814 // Input channel
6815 InputChannel mInputChannel;
6816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006817 WindowState(Session s, IWindow c, WindowToken token,
6818 WindowState attachedWindow, WindowManager.LayoutParams a,
6819 int viewVisibility) {
6820 mSession = s;
6821 mClient = c;
6822 mToken = token;
6823 mAttrs.copyFrom(a);
6824 mViewVisibility = viewVisibility;
6825 DeathRecipient deathRecipient = new DeathRecipient();
6826 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006827 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006828 TAG, "Window " + this + " client=" + c.asBinder()
6829 + " token=" + token + " (" + mAttrs.token + ")");
6830 try {
6831 c.asBinder().linkToDeath(deathRecipient, 0);
6832 } catch (RemoteException e) {
6833 mDeathRecipient = null;
6834 mAttachedWindow = null;
6835 mLayoutAttached = false;
6836 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006837 mIsWallpaper = false;
6838 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006839 mBaseLayer = 0;
6840 mSubLayer = 0;
6841 return;
6842 }
6843 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6846 mAttrs.type <= LAST_SUB_WINDOW)) {
6847 // The multiplier here is to reserve space for multiple
6848 // windows in the same type layer.
6849 mBaseLayer = mPolicy.windowTypeToLayerLw(
6850 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6851 + TYPE_LAYER_OFFSET;
6852 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6853 mAttachedWindow = attachedWindow;
6854 mAttachedWindow.mChildWindows.add(this);
6855 mLayoutAttached = mAttrs.type !=
6856 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6857 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6858 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006859 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6860 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006861 } else {
6862 // The multiplier here is to reserve space for multiple
6863 // windows in the same type layer.
6864 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6865 * TYPE_LAYER_MULTIPLIER
6866 + TYPE_LAYER_OFFSET;
6867 mSubLayer = 0;
6868 mAttachedWindow = null;
6869 mLayoutAttached = false;
6870 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6871 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006872 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6873 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006874 }
6875
6876 WindowState appWin = this;
6877 while (appWin.mAttachedWindow != null) {
6878 appWin = mAttachedWindow;
6879 }
6880 WindowToken appToken = appWin.mToken;
6881 while (appToken.appWindowToken == null) {
6882 WindowToken parent = mTokenMap.get(appToken.token);
6883 if (parent == null || appToken == parent) {
6884 break;
6885 }
6886 appToken = parent;
6887 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006888 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006889 mAppToken = appToken.appWindowToken;
6890
6891 mSurface = null;
6892 mRequestedWidth = 0;
6893 mRequestedHeight = 0;
6894 mLastRequestedWidth = 0;
6895 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006896 mXOffset = 0;
6897 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006898 mLayer = 0;
6899 mAnimLayer = 0;
6900 mLastLayer = 0;
6901 }
6902
6903 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006904 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 TAG, "Attaching " + this + " token=" + mToken
6906 + ", list=" + mToken.windows);
6907 mSession.windowAddedLocked();
6908 }
6909
6910 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6911 mHaveFrame = true;
6912
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006913 final Rect container = mContainingFrame;
6914 container.set(pf);
6915
6916 final Rect display = mDisplayFrame;
6917 display.set(df);
6918
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006919 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006920 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006921 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6922 display.intersect(mCompatibleScreenFrame);
6923 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006924 }
6925
6926 final int pw = container.right - container.left;
6927 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006928
6929 int w,h;
6930 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6931 w = mAttrs.width < 0 ? pw : mAttrs.width;
6932 h = mAttrs.height< 0 ? ph : mAttrs.height;
6933 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006934 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6935 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006936 }
Romain Guy06882f82009-06-10 13:36:04 -07006937
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006938 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08006939 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
6940 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006941 mParentFrame.set(pf);
6942 mContentChanged = true;
6943 }
6944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 final Rect content = mContentFrame;
6946 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 final Rect visible = mVisibleFrame;
6949 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006952 final int fw = frame.width();
6953 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6956 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6957
6958 Gravity.apply(mAttrs.gravity, w, h, container,
6959 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6960 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6961
6962 //System.out.println("Out: " + mFrame);
6963
6964 // Now make sure the window fits in the overall display.
6965 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006967 // Make sure the content and visible frames are inside of the
6968 // final window frame.
6969 if (content.left < frame.left) content.left = frame.left;
6970 if (content.top < frame.top) content.top = frame.top;
6971 if (content.right > frame.right) content.right = frame.right;
6972 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6973 if (visible.left < frame.left) visible.left = frame.left;
6974 if (visible.top < frame.top) visible.top = frame.top;
6975 if (visible.right > frame.right) visible.right = frame.right;
6976 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 final Rect contentInsets = mContentInsets;
6979 contentInsets.left = content.left-frame.left;
6980 contentInsets.top = content.top-frame.top;
6981 contentInsets.right = frame.right-content.right;
6982 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006984 final Rect visibleInsets = mVisibleInsets;
6985 visibleInsets.left = visible.left-frame.left;
6986 visibleInsets.top = visible.top-frame.top;
6987 visibleInsets.right = frame.right-visible.right;
6988 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006989
Dianne Hackborn284ac932009-08-28 10:34:25 -07006990 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6991 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006992 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006993 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006995 if (localLOGV) {
6996 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6997 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006998 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 + mRequestedWidth + ", mRequestedheight="
7000 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7001 + "): frame=" + mFrame.toShortString()
7002 + " ci=" + contentInsets.toShortString()
7003 + " vi=" + visibleInsets.toShortString());
7004 //}
7005 }
7006 }
Romain Guy06882f82009-06-10 13:36:04 -07007007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 public Rect getFrameLw() {
7009 return mFrame;
7010 }
7011
7012 public Rect getShownFrameLw() {
7013 return mShownFrame;
7014 }
7015
7016 public Rect getDisplayFrameLw() {
7017 return mDisplayFrame;
7018 }
7019
7020 public Rect getContentFrameLw() {
7021 return mContentFrame;
7022 }
7023
7024 public Rect getVisibleFrameLw() {
7025 return mVisibleFrame;
7026 }
7027
7028 public boolean getGivenInsetsPendingLw() {
7029 return mGivenInsetsPending;
7030 }
7031
7032 public Rect getGivenContentInsetsLw() {
7033 return mGivenContentInsets;
7034 }
Romain Guy06882f82009-06-10 13:36:04 -07007035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007036 public Rect getGivenVisibleInsetsLw() {
7037 return mGivenVisibleInsets;
7038 }
Romain Guy06882f82009-06-10 13:36:04 -07007039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007040 public WindowManager.LayoutParams getAttrs() {
7041 return mAttrs;
7042 }
7043
7044 public int getSurfaceLayer() {
7045 return mLayer;
7046 }
Romain Guy06882f82009-06-10 13:36:04 -07007047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007048 public IApplicationToken getAppToken() {
7049 return mAppToken != null ? mAppToken.appToken : null;
7050 }
Jeff Brown349703e2010-06-22 01:27:15 -07007051
7052 public long getInputDispatchingTimeoutNanos() {
7053 return mAppToken != null
7054 ? mAppToken.inputDispatchingTimeoutNanos
7055 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057
7058 public boolean hasAppShownWindows() {
7059 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7060 }
7061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007062 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007063 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007064 TAG, "Setting animation in " + this + ": " + anim);
7065 mAnimating = false;
7066 mLocalAnimating = false;
7067 mAnimation = anim;
7068 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7069 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7070 }
7071
7072 public void clearAnimation() {
7073 if (mAnimation != null) {
7074 mAnimating = true;
7075 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007076 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007077 mAnimation = null;
7078 }
7079 }
Romain Guy06882f82009-06-10 13:36:04 -07007080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007081 Surface createSurfaceLocked() {
7082 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007083 mReportDestroySurface = false;
7084 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007085 mDrawPending = true;
7086 mCommitDrawPending = false;
7087 mReadyToShow = false;
7088 if (mAppToken != null) {
7089 mAppToken.allDrawn = false;
7090 }
7091
7092 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007093
7094 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7095 flags |= Surface.SECURE;
7096 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007097 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007098 TAG, "Creating surface in session "
7099 + mSession.mSurfaceSession + " window " + this
7100 + " w=" + mFrame.width()
7101 + " h=" + mFrame.height() + " format="
7102 + mAttrs.format + " flags=" + flags);
7103
7104 int w = mFrame.width();
7105 int h = mFrame.height();
7106 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7107 // for a scaled surface, we always want the requested
7108 // size.
7109 w = mRequestedWidth;
7110 h = mRequestedHeight;
7111 }
7112
Romain Guy9825ec62009-10-01 00:58:09 -07007113 // Something is wrong and SurfaceFlinger will not like this,
7114 // try to revert to sane values
7115 if (w <= 0) w = 1;
7116 if (h <= 0) h = 1;
7117
Dianne Hackborn16064f92010-03-25 00:47:24 -07007118 mSurfaceShown = false;
7119 mSurfaceLayer = 0;
7120 mSurfaceAlpha = 1;
7121 mSurfaceX = 0;
7122 mSurfaceY = 0;
7123 mSurfaceW = w;
7124 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007125 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007126 final boolean isHwAccelerated = (mAttrs.flags &
7127 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7128 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7129 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7130 flags |= Surface.OPAQUE;
7131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007132 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007133 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007134 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007135 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007136 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007137 + mSurface + " IN SESSION "
7138 + mSession.mSurfaceSession
7139 + ": pid=" + mSession.mPid + " format="
7140 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007141 + Integer.toHexString(flags)
7142 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007143 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007144 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007145 reclaimSomeSurfaceMemoryLocked(this, "create");
7146 return null;
7147 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007148 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 return null;
7150 }
Romain Guy06882f82009-06-10 13:36:04 -07007151
Joe Onorato8a9b2202010-02-26 18:56:32 -08007152 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007153 TAG, "Got surface: " + mSurface
7154 + ", set left=" + mFrame.left + " top=" + mFrame.top
7155 + ", animLayer=" + mAnimLayer);
7156 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007157 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007158 if (SHOW_TRANSACTIONS) logSurface(this,
7159 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7160 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7161 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 }
7163 Surface.openTransaction();
7164 try {
7165 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007166 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007167 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007168 mSurface.setPosition(mSurfaceX, mSurfaceY);
7169 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007170 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007171 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007172 mSurface.hide();
7173 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007174 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007175 mSurface.setFlags(Surface.SURFACE_DITHER,
7176 Surface.SURFACE_DITHER);
7177 }
7178 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007179 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007180 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7181 }
7182 mLastHidden = true;
7183 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007184 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007185 Surface.closeTransaction();
7186 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007187 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007188 TAG, "Created surface " + this);
7189 }
7190 return mSurface;
7191 }
Romain Guy06882f82009-06-10 13:36:04 -07007192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 if (mAppToken != null && this == mAppToken.startingWindow) {
7195 mAppToken.startingDisplayed = false;
7196 }
Romain Guy06882f82009-06-10 13:36:04 -07007197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007198 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007199 mDrawPending = false;
7200 mCommitDrawPending = false;
7201 mReadyToShow = false;
7202
7203 int i = mChildWindows.size();
7204 while (i > 0) {
7205 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007206 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007207 c.mAttachedHidden = true;
7208 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007209
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007210 if (mReportDestroySurface) {
7211 mReportDestroySurface = false;
7212 mSurfacePendingDestroy = true;
7213 try {
7214 mClient.dispatchGetNewSurface();
7215 // We'll really destroy on the next time around.
7216 return;
7217 } catch (RemoteException e) {
7218 }
7219 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007221 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007222 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007223 RuntimeException e = null;
7224 if (!HIDE_STACK_CRAWLS) {
7225 e = new RuntimeException();
7226 e.fillInStackTrace();
7227 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007228 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007229 + mSurface + ", session " + mSession, e);
7230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007231 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007232 RuntimeException e = null;
7233 if (!HIDE_STACK_CRAWLS) {
7234 e = new RuntimeException();
7235 e.fillInStackTrace();
7236 }
7237 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007238 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007239 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007240 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007241 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007242 + " surface " + mSurface + " session " + mSession
7243 + ": " + e.toString());
7244 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007245
Dianne Hackborn16064f92010-03-25 00:47:24 -07007246 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007247 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 }
7249 }
7250
7251 boolean finishDrawingLocked() {
7252 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007253 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007254 TAG, "finishDrawingLocked: " + mSurface);
7255 mCommitDrawPending = true;
7256 mDrawPending = false;
7257 return true;
7258 }
7259 return false;
7260 }
7261
7262 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007263 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007264 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007265 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007266 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007267 }
7268 mCommitDrawPending = false;
7269 mReadyToShow = true;
7270 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7271 final AppWindowToken atoken = mAppToken;
7272 if (atoken == null || atoken.allDrawn || starting) {
7273 performShowLocked();
7274 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007275 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007276 }
7277
7278 // This must be called while inside a transaction.
7279 boolean performShowLocked() {
7280 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007281 RuntimeException e = null;
7282 if (!HIDE_STACK_CRAWLS) {
7283 e = new RuntimeException();
7284 e.fillInStackTrace();
7285 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007286 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7288 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7289 }
7290 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007291 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7292 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007293 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007294 + " during animation: policyVis=" + mPolicyVisibility
7295 + " attHidden=" + mAttachedHidden
7296 + " tok.hiddenRequested="
7297 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007298 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 + (mAppToken != null ? mAppToken.hidden : false)
7300 + " animating=" + mAnimating
7301 + " tok animating="
7302 + (mAppToken != null ? mAppToken.animating : false));
7303 if (!showSurfaceRobustlyLocked(this)) {
7304 return false;
7305 }
7306 mLastAlpha = -1;
7307 mHasDrawn = true;
7308 mLastHidden = false;
7309 mReadyToShow = false;
7310 enableScreenIfNeededLocked();
7311
7312 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007314 int i = mChildWindows.size();
7315 while (i > 0) {
7316 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007317 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007318 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007319 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007320 if (c.mSurface != null) {
7321 c.performShowLocked();
7322 // It hadn't been shown, which means layout not
7323 // performed on it, so now we want to make sure to
7324 // do a layout. If called from within the transaction
7325 // loop, this will cause it to restart with a new
7326 // layout.
7327 mLayoutNeeded = true;
7328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 }
7330 }
Romain Guy06882f82009-06-10 13:36:04 -07007331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 if (mAttrs.type != TYPE_APPLICATION_STARTING
7333 && mAppToken != null) {
7334 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007335
Dianne Hackborn248b1882009-09-16 16:46:44 -07007336 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007337 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007338 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007340 // If this initial window is animating, stop it -- we
7341 // will do an animation to reveal it from behind the
7342 // starting window, so there is no need for it to also
7343 // be doing its own stuff.
7344 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007345 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007346 mAnimation = null;
7347 // Make sure we clean up the animation.
7348 mAnimating = true;
7349 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 mFinishedStarting.add(mAppToken);
7351 mH.sendEmptyMessage(H.FINISHED_STARTING);
7352 }
7353 mAppToken.updateReportedVisibilityLocked();
7354 }
7355 }
7356 return true;
7357 }
Romain Guy06882f82009-06-10 13:36:04 -07007358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 // This must be called while inside a transaction. Returns true if
7360 // there is more animation to run.
7361 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007362 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007363 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7366 mHasTransformation = true;
7367 mHasLocalTransformation = true;
7368 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007369 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007370 TAG, "Starting animation in " + this +
7371 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7372 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7373 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7374 mAnimation.setStartTime(currentTime);
7375 mLocalAnimating = true;
7376 mAnimating = true;
7377 }
7378 mTransformation.clear();
7379 final boolean more = mAnimation.getTransformation(
7380 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007381 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 TAG, "Stepped animation in " + this +
7383 ": more=" + more + ", xform=" + mTransformation);
7384 if (more) {
7385 // we're not done!
7386 return true;
7387 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007388 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007389 TAG, "Finished animation in " + this +
7390 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007391
7392 if (mAnimation != null) {
7393 mAnimation.cancel();
7394 mAnimation = null;
7395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007396 //WindowManagerService.this.dump();
7397 }
7398 mHasLocalTransformation = false;
7399 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007400 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401 // When our app token is animating, we kind-of pretend like
7402 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7403 // part of this check means that we will only do this if
7404 // our window is not currently exiting, or it is not
7405 // locally animating itself. The idea being that one that
7406 // is exiting and doing a local animation should be removed
7407 // once that animation is done.
7408 mAnimating = true;
7409 mHasTransformation = true;
7410 mTransformation.clear();
7411 return false;
7412 } else if (mHasTransformation) {
7413 // Little trick to get through the path below to act like
7414 // we have finished an animation.
7415 mAnimating = true;
7416 } else if (isAnimating()) {
7417 mAnimating = true;
7418 }
7419 } else if (mAnimation != null) {
7420 // If the display is frozen, and there is a pending animation,
7421 // clear it and make sure we run the cleanup code.
7422 mAnimating = true;
7423 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007424 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007425 mAnimation = null;
7426 }
Romain Guy06882f82009-06-10 13:36:04 -07007427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 if (!mAnimating && !mLocalAnimating) {
7429 return false;
7430 }
7431
Joe Onorato8a9b2202010-02-26 18:56:32 -08007432 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 TAG, "Animation done in " + this + ": exiting=" + mExiting
7434 + ", reportedVisible="
7435 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007437 mAnimating = false;
7438 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007439 if (mAnimation != null) {
7440 mAnimation.cancel();
7441 mAnimation = null;
7442 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 mAnimLayer = mLayer;
7444 if (mIsImWindow) {
7445 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007446 } else if (mIsWallpaper) {
7447 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007449 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 + " anim layer: " + mAnimLayer);
7451 mHasTransformation = false;
7452 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007453 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7454 if (DEBUG_VISIBILITY) {
7455 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7456 + mPolicyVisibilityAfterAnim);
7457 }
7458 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7459 if (!mPolicyVisibility) {
7460 if (mCurrentFocus == this) {
7461 mFocusMayChange = true;
7462 }
7463 // Window is no longer visible -- make sure if we were waiting
7464 // for it to be displayed before enabling the display, that
7465 // we allow the display to be enabled now.
7466 enableScreenIfNeededLocked();
7467 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007469 mTransformation.clear();
7470 if (mHasDrawn
7471 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7472 && mAppToken != null
7473 && mAppToken.firstWindowDrawn
7474 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007475 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 + mToken + ": first real window done animating");
7477 mFinishedStarting.add(mAppToken);
7478 mH.sendEmptyMessage(H.FINISHED_STARTING);
7479 }
Romain Guy06882f82009-06-10 13:36:04 -07007480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 finishExit();
7482
7483 if (mAppToken != null) {
7484 mAppToken.updateReportedVisibilityLocked();
7485 }
7486
7487 return false;
7488 }
7489
7490 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007491 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007492 TAG, "finishExit in " + this
7493 + ": exiting=" + mExiting
7494 + " remove=" + mRemoveOnExit
7495 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 final int N = mChildWindows.size();
7498 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007499 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 }
Romain Guy06882f82009-06-10 13:36:04 -07007501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007502 if (!mExiting) {
7503 return;
7504 }
Romain Guy06882f82009-06-10 13:36:04 -07007505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007506 if (isWindowAnimating()) {
7507 return;
7508 }
7509
Joe Onorato8a9b2202010-02-26 18:56:32 -08007510 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 TAG, "Exit animation finished in " + this
7512 + ": remove=" + mRemoveOnExit);
7513 if (mSurface != null) {
7514 mDestroySurface.add(this);
7515 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007516 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007517 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007518 try {
7519 mSurface.hide();
7520 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007521 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 }
7523 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 }
7525 mExiting = false;
7526 if (mRemoveOnExit) {
7527 mPendingRemove.add(this);
7528 mRemoveOnExit = false;
7529 }
7530 }
Romain Guy06882f82009-06-10 13:36:04 -07007531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7533 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7534 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7535 if (dtdx < -.000001f || dtdx > .000001f) return false;
7536 if (dsdy < -.000001f || dsdy > .000001f) return false;
7537 return true;
7538 }
Romain Guy06882f82009-06-10 13:36:04 -07007539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 void computeShownFrameLocked() {
7541 final boolean selfTransformation = mHasLocalTransformation;
7542 Transformation attachedTransformation =
7543 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7544 ? mAttachedWindow.mTransformation : null;
7545 Transformation appTransformation =
7546 (mAppToken != null && mAppToken.hasTransformation)
7547 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007548
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007549 // Wallpapers are animated based on the "real" window they
7550 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007551 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007552 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007553 if (mWallpaperTarget.mHasLocalTransformation &&
7554 mWallpaperTarget.mAnimation != null &&
7555 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007556 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007557 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007558 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007559 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007560 }
7561 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007562 mWallpaperTarget.mAppToken.hasTransformation &&
7563 mWallpaperTarget.mAppToken.animation != null &&
7564 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007565 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007566 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007567 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007568 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007569 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007570 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007571
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007572 final boolean screenAnimation = mScreenRotationAnimation != null
7573 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007574 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007575 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007576 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007577 final Rect frame = mFrame;
7578 final float tmpFloats[] = mTmpFloats;
7579 final Matrix tmpMatrix = mTmpMatrix;
7580
7581 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007582 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007583 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007584 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007586 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007588 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007589 }
7590 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007591 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007593 if (screenAnimation) {
7594 tmpMatrix.postConcat(
7595 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7596 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597
7598 // "convert" it into SurfaceFlinger's format
7599 // (a 2x2 matrix + an offset)
7600 // Here we must not transform the position of the surface
7601 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007602 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007603
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007604 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 tmpMatrix.getValues(tmpFloats);
7606 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007607 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7608 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007610 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7611 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 int w = frame.width();
7613 int h = frame.height();
7614 mShownFrame.set(x, y, x+w, y+h);
7615
7616 // Now set the alpha... but because our current hardware
7617 // can't do alpha transformation on a non-opaque surface,
7618 // turn it off if we are running an animation that is also
7619 // transforming since it is more important to have that
7620 // animation be smooth.
7621 mShownAlpha = mAlpha;
7622 if (!mLimitedAlphaCompositing
7623 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7624 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7625 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007626 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 if (selfTransformation) {
7628 mShownAlpha *= mTransformation.getAlpha();
7629 }
7630 if (attachedTransformation != null) {
7631 mShownAlpha *= attachedTransformation.getAlpha();
7632 }
7633 if (appTransformation != null) {
7634 mShownAlpha *= appTransformation.getAlpha();
7635 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007636 if (screenAnimation) {
7637 mShownAlpha *=
7638 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007641 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007642 }
Romain Guy06882f82009-06-10 13:36:04 -07007643
Joe Onorato8a9b2202010-02-26 18:56:32 -08007644 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007645 TAG, "Continuing animation in " + this +
7646 ": " + mShownFrame +
7647 ", alpha=" + mTransformation.getAlpha());
7648 return;
7649 }
Romain Guy06882f82009-06-10 13:36:04 -07007650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007652 if (mXOffset != 0 || mYOffset != 0) {
7653 mShownFrame.offset(mXOffset, mYOffset);
7654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007655 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007656 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007657 mDsDx = 1;
7658 mDtDx = 0;
7659 mDsDy = 0;
7660 mDtDy = 1;
7661 }
Romain Guy06882f82009-06-10 13:36:04 -07007662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 /**
7664 * Is this window visible? It is not visible if there is no
7665 * surface, or we are in the process of running an exit animation
7666 * that will remove the surface, or its app token has been hidden.
7667 */
7668 public boolean isVisibleLw() {
7669 final AppWindowToken atoken = mAppToken;
7670 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7671 && (atoken == null || !atoken.hiddenRequested)
7672 && !mExiting && !mDestroying;
7673 }
7674
7675 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007676 * Like {@link #isVisibleLw}, but also counts a window that is currently
7677 * "hidden" behind the keyguard as visible. This allows us to apply
7678 * things like window flags that impact the keyguard.
7679 * XXX I am starting to think we need to have ANOTHER visibility flag
7680 * for this "hidden behind keyguard" state rather than overloading
7681 * mPolicyVisibility. Ungh.
7682 */
7683 public boolean isVisibleOrBehindKeyguardLw() {
7684 final AppWindowToken atoken = mAppToken;
7685 return mSurface != null && !mAttachedHidden
7686 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007687 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007688 && !mExiting && !mDestroying;
7689 }
7690
7691 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007692 * Is this window visible, ignoring its app token? It is not visible
7693 * if there is no surface, or we are in the process of running an exit animation
7694 * that will remove the surface.
7695 */
7696 public boolean isWinVisibleLw() {
7697 final AppWindowToken atoken = mAppToken;
7698 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7699 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7700 && !mExiting && !mDestroying;
7701 }
7702
7703 /**
7704 * The same as isVisible(), but follows the current hidden state of
7705 * the associated app token, not the pending requested hidden state.
7706 */
7707 boolean isVisibleNow() {
7708 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007709 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007710 }
7711
7712 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007713 * Can this window possibly be a drag/drop target? The test here is
7714 * a combination of the above "visible now" with the check that the
7715 * Input Manager uses when discarding windows from input consideration.
7716 */
7717 boolean isPotentialDragTarget() {
7718 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7719 }
7720
7721 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007722 * Same as isVisible(), but we also count it as visible between the
7723 * call to IWindowSession.add() and the first relayout().
7724 */
7725 boolean isVisibleOrAdding() {
7726 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007727 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007728 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7729 && mPolicyVisibility && !mAttachedHidden
7730 && (atoken == null || !atoken.hiddenRequested)
7731 && !mExiting && !mDestroying;
7732 }
7733
7734 /**
7735 * Is this window currently on-screen? It is on-screen either if it
7736 * is visible or it is currently running an animation before no longer
7737 * being visible.
7738 */
7739 boolean isOnScreen() {
7740 final AppWindowToken atoken = mAppToken;
7741 if (atoken != null) {
7742 return mSurface != null && mPolicyVisibility && !mDestroying
7743 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007744 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007745 } else {
7746 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007747 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007748 }
7749 }
Romain Guy06882f82009-06-10 13:36:04 -07007750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007751 /**
7752 * Like isOnScreen(), but we don't return true if the window is part
7753 * of a transition that has not yet been started.
7754 */
7755 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007756 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007757 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007758 return false;
7759 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007760 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007761 final boolean animating = atoken != null
7762 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007763 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007764 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7765 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007766 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 }
7768
7769 /** Is the window or its container currently animating? */
7770 boolean isAnimating() {
7771 final WindowState attached = mAttachedWindow;
7772 final AppWindowToken atoken = mAppToken;
7773 return mAnimation != null
7774 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007775 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 (atoken.animation != null
7777 || atoken.inPendingTransaction));
7778 }
7779
7780 /** Is this window currently animating? */
7781 boolean isWindowAnimating() {
7782 return mAnimation != null;
7783 }
7784
7785 /**
7786 * Like isOnScreen, but returns false if the surface hasn't yet
7787 * been drawn.
7788 */
7789 public boolean isDisplayedLw() {
7790 final AppWindowToken atoken = mAppToken;
7791 return mSurface != null && mPolicyVisibility && !mDestroying
7792 && !mDrawPending && !mCommitDrawPending
7793 && ((!mAttachedHidden &&
7794 (atoken == null || !atoken.hiddenRequested))
7795 || mAnimating);
7796 }
7797
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007798 /**
7799 * Returns true if the window has a surface that it has drawn a
7800 * complete UI in to.
7801 */
7802 public boolean isDrawnLw() {
7803 final AppWindowToken atoken = mAppToken;
7804 return mSurface != null && !mDestroying
7805 && !mDrawPending && !mCommitDrawPending;
7806 }
7807
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007808 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007809 * Return true if the window is opaque and fully drawn. This indicates
7810 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007811 */
7812 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007813 return (mAttrs.format == PixelFormat.OPAQUE
7814 || mAttrs.type == TYPE_WALLPAPER)
7815 && mSurface != null && mAnimation == null
7816 && (mAppToken == null || mAppToken.animation == null)
7817 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007818 }
7819
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007820 /**
7821 * Return whether this window is wanting to have a translation
7822 * animation applied to it for an in-progress move. (Only makes
7823 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7824 */
7825 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007826 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007827 && (mFrame.top != mLastFrame.top
7828 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007829 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007830 && mPolicy.isScreenOn();
7831 }
7832
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007833 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7834 return
7835 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007836 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7837 // only if it's visible
7838 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007839 // and only if the application fills the compatible screen
7840 mFrame.left <= mCompatibleScreenFrame.left &&
7841 mFrame.top <= mCompatibleScreenFrame.top &&
7842 mFrame.right >= mCompatibleScreenFrame.right &&
7843 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007844 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007845 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007846 }
7847
7848 boolean isFullscreen(int screenWidth, int screenHeight) {
7849 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007850 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007851 }
7852
7853 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007854 disposeInputChannel();
7855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007856 if (mAttachedWindow != null) {
7857 mAttachedWindow.mChildWindows.remove(this);
7858 }
7859 destroySurfaceLocked();
7860 mSession.windowRemovedLocked();
7861 try {
7862 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7863 } catch (RuntimeException e) {
7864 // Ignore if it has already been removed (usually because
7865 // we are doing this as part of processing a death note.)
7866 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007867 }
7868
7869 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007870 if (mInputChannel != null) {
7871 mInputManager.unregisterInputChannel(mInputChannel);
7872
7873 mInputChannel.dispose();
7874 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876 }
7877
7878 private class DeathRecipient implements IBinder.DeathRecipient {
7879 public void binderDied() {
7880 try {
7881 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007882 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007883 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007884 if (win != null) {
7885 removeWindowLocked(mSession, win);
7886 }
7887 }
7888 } catch (IllegalArgumentException ex) {
7889 // This will happen if the window has already been
7890 // removed.
7891 }
7892 }
7893 }
7894
7895 /** Returns true if this window desires key events. */
7896 public final boolean canReceiveKeys() {
7897 return isVisibleOrAdding()
7898 && (mViewVisibility == View.VISIBLE)
7899 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7900 }
7901
7902 public boolean hasDrawnLw() {
7903 return mHasDrawn;
7904 }
7905
7906 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007907 return showLw(doAnimation, true);
7908 }
7909
7910 boolean showLw(boolean doAnimation, boolean requestAnim) {
7911 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7912 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007914 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007915 if (doAnimation) {
7916 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7917 + mPolicyVisibility + " mAnimation=" + mAnimation);
7918 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7919 doAnimation = false;
7920 } else if (mPolicyVisibility && mAnimation == null) {
7921 // Check for the case where we are currently visible and
7922 // not animating; we do not want to do animation at such a
7923 // point to become visible when we already are.
7924 doAnimation = false;
7925 }
7926 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007927 mPolicyVisibility = true;
7928 mPolicyVisibilityAfterAnim = true;
7929 if (doAnimation) {
7930 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7931 }
7932 if (requestAnim) {
7933 requestAnimationLocked(0);
7934 }
7935 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 }
7937
7938 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007939 return hideLw(doAnimation, true);
7940 }
7941
7942 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007943 if (doAnimation) {
7944 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7945 doAnimation = false;
7946 }
7947 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007948 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7949 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007950 if (!current) {
7951 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007952 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007953 if (doAnimation) {
7954 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7955 if (mAnimation == null) {
7956 doAnimation = false;
7957 }
7958 }
7959 if (doAnimation) {
7960 mPolicyVisibilityAfterAnim = false;
7961 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007962 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007963 mPolicyVisibilityAfterAnim = false;
7964 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007965 // Window is no longer visible -- make sure if we were waiting
7966 // for it to be displayed before enabling the display, that
7967 // we allow the display to be enabled now.
7968 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007969 if (mCurrentFocus == this) {
7970 mFocusMayChange = true;
7971 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007972 }
7973 if (requestAnim) {
7974 requestAnimationLocked(0);
7975 }
7976 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 }
7978
7979 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007980 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7981 pw.print(" mClient="); pw.println(mClient.asBinder());
7982 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7983 if (mAttachedWindow != null || mLayoutAttached) {
7984 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7985 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7986 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007987 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7988 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7989 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007990 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7991 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007992 }
7993 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7994 pw.print(" mSubLayer="); pw.print(mSubLayer);
7995 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7996 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7997 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7998 pw.print("="); pw.print(mAnimLayer);
7999 pw.print(" mLastLayer="); pw.println(mLastLayer);
8000 if (mSurface != null) {
8001 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008002 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8003 pw.print(" layer="); pw.print(mSurfaceLayer);
8004 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8005 pw.print(" rect=("); pw.print(mSurfaceX);
8006 pw.print(","); pw.print(mSurfaceY);
8007 pw.print(") "); pw.print(mSurfaceW);
8008 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008009 }
8010 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8011 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8012 if (mAppToken != null) {
8013 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8014 }
8015 if (mTargetAppToken != null) {
8016 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8017 }
8018 pw.print(prefix); pw.print("mViewVisibility=0x");
8019 pw.print(Integer.toHexString(mViewVisibility));
8020 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008021 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8022 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008023 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8024 pw.print(prefix); pw.print("mPolicyVisibility=");
8025 pw.print(mPolicyVisibility);
8026 pw.print(" mPolicyVisibilityAfterAnim=");
8027 pw.print(mPolicyVisibilityAfterAnim);
8028 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8029 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008030 if (!mRelayoutCalled) {
8031 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8032 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008033 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008034 pw.print(" h="); pw.print(mRequestedHeight);
8035 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008036 if (mXOffset != 0 || mYOffset != 0) {
8037 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8038 pw.print(" y="); pw.println(mYOffset);
8039 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008040 pw.print(prefix); pw.print("mGivenContentInsets=");
8041 mGivenContentInsets.printShortString(pw);
8042 pw.print(" mGivenVisibleInsets=");
8043 mGivenVisibleInsets.printShortString(pw);
8044 pw.println();
8045 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8046 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8047 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8048 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008049 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008050 pw.print(prefix); pw.print("mShownFrame=");
8051 mShownFrame.printShortString(pw);
8052 pw.print(" last="); mLastShownFrame.printShortString(pw);
8053 pw.println();
8054 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8055 pw.print(" last="); mLastFrame.printShortString(pw);
8056 pw.println();
8057 pw.print(prefix); pw.print("mContainingFrame=");
8058 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008059 pw.print(" mParentFrame=");
8060 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008061 pw.print(" mDisplayFrame=");
8062 mDisplayFrame.printShortString(pw);
8063 pw.println();
8064 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8065 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8066 pw.println();
8067 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8068 pw.print(" last="); mLastContentInsets.printShortString(pw);
8069 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8070 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8071 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008072 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8073 || mAnimation != null) {
8074 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8075 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8076 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8077 pw.print(" mAnimation="); pw.println(mAnimation);
8078 }
8079 if (mHasTransformation || mHasLocalTransformation) {
8080 pw.print(prefix); pw.print("XForm: has=");
8081 pw.print(mHasTransformation);
8082 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8083 pw.print(" "); mTransformation.printShortString(pw);
8084 pw.println();
8085 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008086 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8087 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8088 pw.print(" mAlpha="); pw.print(mAlpha);
8089 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8090 }
8091 if (mHaveMatrix) {
8092 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8093 pw.print(" mDtDx="); pw.print(mDtDx);
8094 pw.print(" mDsDy="); pw.print(mDsDy);
8095 pw.print(" mDtDy="); pw.println(mDtDy);
8096 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008097 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8098 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8099 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8100 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8101 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8102 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8103 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8104 pw.print(" mDestroying="); pw.print(mDestroying);
8105 pw.print(" mRemoved="); pw.println(mRemoved);
8106 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008107 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008108 pw.print(prefix); pw.print("mOrientationChanging=");
8109 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008110 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8111 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008112 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008113 if (mHScale != 1 || mVScale != 1) {
8114 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8115 pw.print(" mVScale="); pw.println(mVScale);
8116 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008117 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008118 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8119 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8120 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008121 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8122 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8123 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008126
8127 String makeInputChannelName() {
8128 return Integer.toHexString(System.identityHashCode(this))
8129 + " " + mAttrs.getTitle();
8130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008131
8132 @Override
8133 public String toString() {
8134 return "Window{"
8135 + Integer.toHexString(System.identityHashCode(this))
8136 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8137 }
8138 }
Romain Guy06882f82009-06-10 13:36:04 -07008139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 // -------------------------------------------------------------
8141 // Window Token State
8142 // -------------------------------------------------------------
8143
8144 class WindowToken {
8145 // The actual token.
8146 final IBinder token;
8147
8148 // The type of window this token is for, as per WindowManager.LayoutParams.
8149 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 // Set if this token was explicitly added by a client, so should
8152 // not be removed when all windows are removed.
8153 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008154
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008155 // For printing.
8156 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008158 // If this is an AppWindowToken, this is non-null.
8159 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008161 // All of the windows associated with this token.
8162 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8163
8164 // Is key dispatching paused for this token?
8165 boolean paused = false;
8166
8167 // Should this token's windows be hidden?
8168 boolean hidden;
8169
8170 // Temporary for finding which tokens no longer have visible windows.
8171 boolean hasVisible;
8172
Dianne Hackborna8f60182009-09-01 19:01:50 -07008173 // Set to true when this token is in a pending transaction where it
8174 // will be shown.
8175 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008176
Dianne Hackborna8f60182009-09-01 19:01:50 -07008177 // Set to true when this token is in a pending transaction where it
8178 // will be hidden.
8179 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008180
Dianne Hackborna8f60182009-09-01 19:01:50 -07008181 // Set to true when this token is in a pending transaction where its
8182 // windows will be put to the bottom of the list.
8183 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008184
Dianne Hackborna8f60182009-09-01 19:01:50 -07008185 // Set to true when this token is in a pending transaction where its
8186 // windows will be put to the top of the list.
8187 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 WindowToken(IBinder _token, int type, boolean _explicit) {
8190 token = _token;
8191 windowType = type;
8192 explicit = _explicit;
8193 }
8194
8195 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008196 pw.print(prefix); pw.print("token="); pw.println(token);
8197 pw.print(prefix); pw.print("windows="); pw.println(windows);
8198 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8199 pw.print(" hidden="); pw.print(hidden);
8200 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008201 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8202 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8203 pw.print(" waitingToHide="); pw.print(waitingToHide);
8204 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8205 pw.print(" sendingToTop="); pw.println(sendingToTop);
8206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008207 }
8208
8209 @Override
8210 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008211 if (stringName == null) {
8212 StringBuilder sb = new StringBuilder();
8213 sb.append("WindowToken{");
8214 sb.append(Integer.toHexString(System.identityHashCode(this)));
8215 sb.append(" token="); sb.append(token); sb.append('}');
8216 stringName = sb.toString();
8217 }
8218 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008219 }
8220 };
8221
8222 class AppWindowToken extends WindowToken {
8223 // Non-null only for application tokens.
8224 final IApplicationToken appToken;
8225
8226 // All of the windows and child windows that are included in this
8227 // application token. Note this list is NOT sorted!
8228 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8229
8230 int groupId = -1;
8231 boolean appFullscreen;
8232 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008233
8234 // The input dispatching timeout for this application token in nanoseconds.
8235 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008237 // These are used for determining when all windows associated with
8238 // an activity have been drawn, so they can be made visible together
8239 // at the same time.
8240 int lastTransactionSequence = mTransactionSequence-1;
8241 int numInterestingWindows;
8242 int numDrawnWindows;
8243 boolean inPendingTransaction;
8244 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008246 // Is this token going to be hidden in a little while? If so, it
8247 // won't be taken into account for setting the screen orientation.
8248 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250 // Is this window's surface needed? This is almost like hidden, except
8251 // it will sometimes be true a little earlier: when the token has
8252 // been shown, but is still waiting for its app transition to execute
8253 // before making its windows shown.
8254 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008256 // Have we told the window clients to hide themselves?
8257 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008259 // Last visibility state we reported to the app token.
8260 boolean reportedVisible;
8261
8262 // Set to true when the token has been removed from the window mgr.
8263 boolean removed;
8264
8265 // Have we been asked to have this token keep the screen frozen?
8266 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 boolean animating;
8269 Animation animation;
8270 boolean hasTransformation;
8271 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008273 // Offset to the window of all layers in the token, for use by
8274 // AppWindowToken animations.
8275 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008277 // Information about an application starting window if displayed.
8278 StartingData startingData;
8279 WindowState startingWindow;
8280 View startingView;
8281 boolean startingDisplayed;
8282 boolean startingMoved;
8283 boolean firstWindowDrawn;
8284
8285 AppWindowToken(IApplicationToken _token) {
8286 super(_token.asBinder(),
8287 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8288 appWindowToken = this;
8289 appToken = _token;
8290 }
Romain Guy06882f82009-06-10 13:36:04 -07008291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008292 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008293 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008294 TAG, "Setting animation in " + this + ": " + anim);
8295 animation = anim;
8296 animating = false;
8297 anim.restrictDuration(MAX_ANIMATION_DURATION);
8298 anim.scaleCurrentDuration(mTransitionAnimationScale);
8299 int zorder = anim.getZAdjustment();
8300 int adj = 0;
8301 if (zorder == Animation.ZORDER_TOP) {
8302 adj = TYPE_LAYER_OFFSET;
8303 } else if (zorder == Animation.ZORDER_BOTTOM) {
8304 adj = -TYPE_LAYER_OFFSET;
8305 }
Romain Guy06882f82009-06-10 13:36:04 -07008306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008307 if (animLayerAdjustment != adj) {
8308 animLayerAdjustment = adj;
8309 updateLayers();
8310 }
8311 }
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 public void setDummyAnimation() {
8314 if (animation == null) {
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 dummy animation in " + this);
8317 animation = sDummyAnimation;
8318 }
8319 }
8320
8321 public void clearAnimation() {
8322 if (animation != null) {
8323 animation = null;
8324 animating = true;
8325 }
8326 }
Romain Guy06882f82009-06-10 13:36:04 -07008327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 void updateLayers() {
8329 final int N = allAppWindows.size();
8330 final int adj = animLayerAdjustment;
8331 for (int i=0; i<N; i++) {
8332 WindowState w = allAppWindows.get(i);
8333 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008334 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008335 + w.mAnimLayer);
8336 if (w == mInputMethodTarget) {
8337 setInputMethodAnimLayerAdjustment(adj);
8338 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008339 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008340 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008342 }
8343 }
Romain Guy06882f82009-06-10 13:36:04 -07008344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008345 void sendAppVisibilityToClients() {
8346 final int N = allAppWindows.size();
8347 for (int i=0; i<N; i++) {
8348 WindowState win = allAppWindows.get(i);
8349 if (win == startingWindow && clientHidden) {
8350 // Don't hide the starting window.
8351 continue;
8352 }
8353 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008354 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008355 "Setting visibility of " + win + ": " + (!clientHidden));
8356 win.mClient.dispatchAppVisibility(!clientHidden);
8357 } catch (RemoteException e) {
8358 }
8359 }
8360 }
Romain Guy06882f82009-06-10 13:36:04 -07008361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008362 void showAllWindowsLocked() {
8363 final int NW = allAppWindows.size();
8364 for (int i=0; i<NW; i++) {
8365 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008366 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008367 "performing show on: " + w);
8368 w.performShowLocked();
8369 }
8370 }
Romain Guy06882f82009-06-10 13:36:04 -07008371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008372 // This must be called while inside a transaction.
8373 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008374 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008375 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 if (animation == sDummyAnimation) {
8378 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008379 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008380 // when it is really time to animate, this will be set to
8381 // a real animation and the next call will execute normally.
8382 return false;
8383 }
Romain Guy06882f82009-06-10 13:36:04 -07008384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008385 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8386 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008387 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008388 TAG, "Starting animation in " + this +
8389 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8390 + " scale=" + mTransitionAnimationScale
8391 + " allDrawn=" + allDrawn + " animating=" + animating);
8392 animation.initialize(dw, dh, dw, dh);
8393 animation.setStartTime(currentTime);
8394 animating = true;
8395 }
8396 transformation.clear();
8397 final boolean more = animation.getTransformation(
8398 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008399 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008400 TAG, "Stepped animation in " + this +
8401 ": more=" + more + ", xform=" + transformation);
8402 if (more) {
8403 // we're done!
8404 hasTransformation = true;
8405 return true;
8406 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008407 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008408 TAG, "Finished animation in " + this +
8409 " @ " + currentTime);
8410 animation = null;
8411 }
8412 } else if (animation != null) {
8413 // If the display is frozen, and there is a pending animation,
8414 // clear it and make sure we run the cleanup code.
8415 animating = true;
8416 animation = null;
8417 }
8418
8419 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008421 if (!animating) {
8422 return false;
8423 }
8424
8425 clearAnimation();
8426 animating = false;
8427 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8428 moveInputMethodWindowsIfNeededLocked(true);
8429 }
Romain Guy06882f82009-06-10 13:36:04 -07008430
Joe Onorato8a9b2202010-02-26 18:56:32 -08008431 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008432 TAG, "Animation done in " + this
8433 + ": reportedVisible=" + reportedVisible);
8434
8435 transformation.clear();
8436 if (animLayerAdjustment != 0) {
8437 animLayerAdjustment = 0;
8438 updateLayers();
8439 }
Romain Guy06882f82009-06-10 13:36:04 -07008440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 final int N = windows.size();
8442 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008443 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008444 }
8445 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 return false;
8448 }
8449
8450 void updateReportedVisibilityLocked() {
8451 if (appToken == null) {
8452 return;
8453 }
Romain Guy06882f82009-06-10 13:36:04 -07008454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008455 int numInteresting = 0;
8456 int numVisible = 0;
8457 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008458
Joe Onorato8a9b2202010-02-26 18:56:32 -08008459 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008460 final int N = allAppWindows.size();
8461 for (int i=0; i<N; i++) {
8462 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008463 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008464 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008465 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8466 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 continue;
8468 }
8469 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008470 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008471 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008472 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008473 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008474 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008475 + " pv=" + win.mPolicyVisibility
8476 + " dp=" + win.mDrawPending
8477 + " cdp=" + win.mCommitDrawPending
8478 + " ah=" + win.mAttachedHidden
8479 + " th="
8480 + (win.mAppToken != null
8481 ? win.mAppToken.hiddenRequested : false)
8482 + " a=" + win.mAnimating);
8483 }
8484 }
8485 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008486 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008487 if (!win.isAnimating()) {
8488 numVisible++;
8489 }
8490 nowGone = false;
8491 } else if (win.isAnimating()) {
8492 nowGone = false;
8493 }
8494 }
Romain Guy06882f82009-06-10 13:36:04 -07008495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008497 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 + numInteresting + " visible=" + numVisible);
8499 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008500 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 TAG, "Visibility changed in " + this
8502 + ": vis=" + nowVisible);
8503 reportedVisible = nowVisible;
8504 Message m = mH.obtainMessage(
8505 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8506 nowVisible ? 1 : 0,
8507 nowGone ? 1 : 0,
8508 this);
8509 mH.sendMessage(m);
8510 }
8511 }
Romain Guy06882f82009-06-10 13:36:04 -07008512
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008513 WindowState findMainWindow() {
8514 int j = windows.size();
8515 while (j > 0) {
8516 j--;
8517 WindowState win = windows.get(j);
8518 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8519 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8520 return win;
8521 }
8522 }
8523 return null;
8524 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 void dump(PrintWriter pw, String prefix) {
8527 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008528 if (appToken != null) {
8529 pw.print(prefix); pw.println("app=true");
8530 }
8531 if (allAppWindows.size() > 0) {
8532 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8533 }
8534 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008535 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008536 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8537 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8538 pw.print(" clientHidden="); pw.print(clientHidden);
8539 pw.print(" willBeHidden="); pw.print(willBeHidden);
8540 pw.print(" reportedVisible="); pw.println(reportedVisible);
8541 if (paused || freezingScreen) {
8542 pw.print(prefix); pw.print("paused="); pw.print(paused);
8543 pw.print(" freezingScreen="); pw.println(freezingScreen);
8544 }
8545 if (numInterestingWindows != 0 || numDrawnWindows != 0
8546 || inPendingTransaction || allDrawn) {
8547 pw.print(prefix); pw.print("numInterestingWindows=");
8548 pw.print(numInterestingWindows);
8549 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8550 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8551 pw.print(" allDrawn="); pw.println(allDrawn);
8552 }
8553 if (animating || animation != null) {
8554 pw.print(prefix); pw.print("animating="); pw.print(animating);
8555 pw.print(" animation="); pw.println(animation);
8556 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008557 if (hasTransformation) {
8558 pw.print(prefix); pw.print("XForm: ");
8559 transformation.printShortString(pw);
8560 pw.println();
8561 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008562 if (animLayerAdjustment != 0) {
8563 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8564 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008565 if (startingData != null || removed || firstWindowDrawn) {
8566 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8567 pw.print(" removed="); pw.print(removed);
8568 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8569 }
8570 if (startingWindow != null || startingView != null
8571 || startingDisplayed || startingMoved) {
8572 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8573 pw.print(" startingView="); pw.print(startingView);
8574 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8575 pw.print(" startingMoved"); pw.println(startingMoved);
8576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008577 }
8578
8579 @Override
8580 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008581 if (stringName == null) {
8582 StringBuilder sb = new StringBuilder();
8583 sb.append("AppWindowToken{");
8584 sb.append(Integer.toHexString(System.identityHashCode(this)));
8585 sb.append(" token="); sb.append(token); sb.append('}');
8586 stringName = sb.toString();
8587 }
8588 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008589 }
8590 }
Romain Guy06882f82009-06-10 13:36:04 -07008591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008592 // -------------------------------------------------------------
8593 // DummyAnimation
8594 // -------------------------------------------------------------
8595
8596 // This is an animation that does nothing: it just immediately finishes
8597 // itself every time it is called. It is used as a stub animation in cases
8598 // where we want to synchronize multiple things that may be animating.
8599 static final class DummyAnimation extends Animation {
8600 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8601 return false;
8602 }
8603 }
8604 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 // -------------------------------------------------------------
8607 // Async Handler
8608 // -------------------------------------------------------------
8609
8610 static final class StartingData {
8611 final String pkg;
8612 final int theme;
8613 final CharSequence nonLocalizedLabel;
8614 final int labelRes;
8615 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008616 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008619 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 pkg = _pkg;
8621 theme = _theme;
8622 nonLocalizedLabel = _nonLocalizedLabel;
8623 labelRes = _labelRes;
8624 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008625 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 }
8627 }
8628
8629 private final class H extends Handler {
8630 public static final int REPORT_FOCUS_CHANGE = 2;
8631 public static final int REPORT_LOSING_FOCUS = 3;
8632 public static final int ANIMATE = 4;
8633 public static final int ADD_STARTING = 5;
8634 public static final int REMOVE_STARTING = 6;
8635 public static final int FINISHED_STARTING = 7;
8636 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8638 public static final int HOLD_SCREEN_CHANGED = 12;
8639 public static final int APP_TRANSITION_TIMEOUT = 13;
8640 public static final int PERSIST_ANIMATION_SCALE = 14;
8641 public static final int FORCE_GC = 15;
8642 public static final int ENABLE_SCREEN = 16;
8643 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008644 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008645 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008646 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008647 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008649 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008651 public H() {
8652 }
Romain Guy06882f82009-06-10 13:36:04 -07008653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654 @Override
8655 public void handleMessage(Message msg) {
8656 switch (msg.what) {
8657 case REPORT_FOCUS_CHANGE: {
8658 WindowState lastFocus;
8659 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008661 synchronized(mWindowMap) {
8662 lastFocus = mLastFocus;
8663 newFocus = mCurrentFocus;
8664 if (lastFocus == newFocus) {
8665 // Focus is not changing, so nothing to do.
8666 return;
8667 }
8668 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008669 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008670 // + " to " + newFocus);
8671 if (newFocus != null && lastFocus != null
8672 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008673 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008674 mLosingFocus.add(lastFocus);
8675 lastFocus = null;
8676 }
8677 }
8678
8679 if (lastFocus != newFocus) {
8680 //System.out.println("Changing focus from " + lastFocus
8681 // + " to " + newFocus);
8682 if (newFocus != null) {
8683 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008684 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008685 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8686 } catch (RemoteException e) {
8687 // Ignore if process has died.
8688 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008689 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008690 }
8691
8692 if (lastFocus != null) {
8693 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008694 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008695 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8696 } catch (RemoteException e) {
8697 // Ignore if process has died.
8698 }
8699 }
8700 }
8701 } break;
8702
8703 case REPORT_LOSING_FOCUS: {
8704 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008706 synchronized(mWindowMap) {
8707 losers = mLosingFocus;
8708 mLosingFocus = new ArrayList<WindowState>();
8709 }
8710
8711 final int N = losers.size();
8712 for (int i=0; i<N; i++) {
8713 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008714 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008715 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8716 } catch (RemoteException e) {
8717 // Ignore if process has died.
8718 }
8719 }
8720 } break;
8721
8722 case ANIMATE: {
8723 synchronized(mWindowMap) {
8724 mAnimationPending = false;
8725 performLayoutAndPlaceSurfacesLocked();
8726 }
8727 } break;
8728
8729 case ADD_STARTING: {
8730 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8731 final StartingData sd = wtoken.startingData;
8732
8733 if (sd == null) {
8734 // Animation has been canceled... do nothing.
8735 return;
8736 }
Romain Guy06882f82009-06-10 13:36:04 -07008737
Joe Onorato8a9b2202010-02-26 18:56:32 -08008738 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008739 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008741 View view = null;
8742 try {
8743 view = mPolicy.addStartingWindow(
8744 wtoken.token, sd.pkg,
8745 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008746 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008747 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008748 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008749 }
8750
8751 if (view != null) {
8752 boolean abort = false;
8753
8754 synchronized(mWindowMap) {
8755 if (wtoken.removed || wtoken.startingData == null) {
8756 // If the window was successfully added, then
8757 // we need to remove it.
8758 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008759 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008760 "Aborted starting " + wtoken
8761 + ": removed=" + wtoken.removed
8762 + " startingData=" + wtoken.startingData);
8763 wtoken.startingWindow = null;
8764 wtoken.startingData = null;
8765 abort = true;
8766 }
8767 } else {
8768 wtoken.startingView = view;
8769 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008770 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008771 "Added starting " + wtoken
8772 + ": startingWindow="
8773 + wtoken.startingWindow + " startingView="
8774 + wtoken.startingView);
8775 }
8776
8777 if (abort) {
8778 try {
8779 mPolicy.removeStartingWindow(wtoken.token, view);
8780 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008781 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008782 }
8783 }
8784 }
8785 } break;
8786
8787 case REMOVE_STARTING: {
8788 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8789 IBinder token = null;
8790 View view = null;
8791 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008792 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008793 + wtoken + ": startingWindow="
8794 + wtoken.startingWindow + " startingView="
8795 + wtoken.startingView);
8796 if (wtoken.startingWindow != null) {
8797 view = wtoken.startingView;
8798 token = wtoken.token;
8799 wtoken.startingData = null;
8800 wtoken.startingView = null;
8801 wtoken.startingWindow = null;
8802 }
8803 }
8804 if (view != null) {
8805 try {
8806 mPolicy.removeStartingWindow(token, view);
8807 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008808 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008809 }
8810 }
8811 } break;
8812
8813 case FINISHED_STARTING: {
8814 IBinder token = null;
8815 View view = null;
8816 while (true) {
8817 synchronized (mWindowMap) {
8818 final int N = mFinishedStarting.size();
8819 if (N <= 0) {
8820 break;
8821 }
8822 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8823
Joe Onorato8a9b2202010-02-26 18:56:32 -08008824 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008825 "Finished starting " + wtoken
8826 + ": startingWindow=" + wtoken.startingWindow
8827 + " startingView=" + wtoken.startingView);
8828
8829 if (wtoken.startingWindow == null) {
8830 continue;
8831 }
8832
8833 view = wtoken.startingView;
8834 token = wtoken.token;
8835 wtoken.startingData = null;
8836 wtoken.startingView = null;
8837 wtoken.startingWindow = null;
8838 }
8839
8840 try {
8841 mPolicy.removeStartingWindow(token, view);
8842 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008843 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008844 }
8845 }
8846 } break;
8847
8848 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8849 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8850
8851 boolean nowVisible = msg.arg1 != 0;
8852 boolean nowGone = msg.arg2 != 0;
8853
8854 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008855 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008856 TAG, "Reporting visible in " + wtoken
8857 + " visible=" + nowVisible
8858 + " gone=" + nowGone);
8859 if (nowVisible) {
8860 wtoken.appToken.windowsVisible();
8861 } else {
8862 wtoken.appToken.windowsGone();
8863 }
8864 } catch (RemoteException ex) {
8865 }
8866 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 case WINDOW_FREEZE_TIMEOUT: {
8869 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008870 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008871 int i = mWindows.size();
8872 while (i > 0) {
8873 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008874 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 if (w.mOrientationChanging) {
8876 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008877 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008878 }
8879 }
8880 performLayoutAndPlaceSurfacesLocked();
8881 }
8882 break;
8883 }
Romain Guy06882f82009-06-10 13:36:04 -07008884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 case HOLD_SCREEN_CHANGED: {
8886 Session oldHold;
8887 Session newHold;
8888 synchronized (mWindowMap) {
8889 oldHold = mLastReportedHold;
8890 newHold = (Session)msg.obj;
8891 mLastReportedHold = newHold;
8892 }
Romain Guy06882f82009-06-10 13:36:04 -07008893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008894 if (oldHold != newHold) {
8895 try {
8896 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008897 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008898 "window",
8899 BatteryStats.WAKE_TYPE_WINDOW);
8900 }
8901 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008902 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008903 "window",
8904 BatteryStats.WAKE_TYPE_WINDOW);
8905 }
8906 } catch (RemoteException e) {
8907 }
8908 }
8909 break;
8910 }
Romain Guy06882f82009-06-10 13:36:04 -07008911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008912 case APP_TRANSITION_TIMEOUT: {
8913 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008914 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008915 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008916 "*** APP TRANSITION TIMEOUT");
8917 mAppTransitionReady = true;
8918 mAppTransitionTimeout = true;
8919 performLayoutAndPlaceSurfacesLocked();
8920 }
8921 }
8922 break;
8923 }
Romain Guy06882f82009-06-10 13:36:04 -07008924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008925 case PERSIST_ANIMATION_SCALE: {
8926 Settings.System.putFloat(mContext.getContentResolver(),
8927 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8928 Settings.System.putFloat(mContext.getContentResolver(),
8929 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8930 break;
8931 }
Romain Guy06882f82009-06-10 13:36:04 -07008932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008933 case FORCE_GC: {
8934 synchronized(mWindowMap) {
8935 if (mAnimationPending) {
8936 // If we are animating, don't do the gc now but
8937 // delay a bit so we don't interrupt the animation.
8938 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8939 2000);
8940 return;
8941 }
8942 // If we are currently rotating the display, it will
8943 // schedule a new message when done.
8944 if (mDisplayFrozen) {
8945 return;
8946 }
8947 mFreezeGcPending = 0;
8948 }
8949 Runtime.getRuntime().gc();
8950 break;
8951 }
Romain Guy06882f82009-06-10 13:36:04 -07008952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008953 case ENABLE_SCREEN: {
8954 performEnableScreen();
8955 break;
8956 }
Romain Guy06882f82009-06-10 13:36:04 -07008957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008958 case APP_FREEZE_TIMEOUT: {
8959 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008960 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008961 int i = mAppTokens.size();
8962 while (i > 0) {
8963 i--;
8964 AppWindowToken tok = mAppTokens.get(i);
8965 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008966 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 unsetAppFreezingScreenLocked(tok, true, true);
8968 }
8969 }
8970 }
8971 break;
8972 }
Romain Guy06882f82009-06-10 13:36:04 -07008973
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008974 case SEND_NEW_CONFIGURATION: {
8975 removeMessages(SEND_NEW_CONFIGURATION);
8976 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008977 break;
8978 }
Romain Guy06882f82009-06-10 13:36:04 -07008979
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008980 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008981 if (mWindowsChanged) {
8982 synchronized (mWindowMap) {
8983 mWindowsChanged = false;
8984 }
8985 notifyWindowsChanged();
8986 }
8987 break;
8988 }
8989
Christopher Tatea53146c2010-09-07 11:57:52 -07008990 case DRAG_START_TIMEOUT: {
8991 IBinder win = (IBinder)msg.obj;
8992 if (DEBUG_DRAG) {
8993 Slog.w(TAG, "Timeout starting drag by win " + win);
8994 }
8995 synchronized (mWindowMap) {
8996 // !!! TODO: ANR the app that has failed to start the drag in time
8997 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008998 mDragState.unregister();
8999 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009000 mDragState.reset();
9001 mDragState = null;
9002 }
9003 }
Chris Tated4533f142010-10-19 15:15:08 -07009004 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009005 }
9006
Chris Tated4533f142010-10-19 15:15:08 -07009007 case DRAG_END_TIMEOUT: {
9008 IBinder win = (IBinder)msg.obj;
9009 if (DEBUG_DRAG) {
9010 Slog.w(TAG, "Timeout ending drag to win " + win);
9011 }
9012 synchronized (mWindowMap) {
9013 // !!! TODO: ANR the drag-receiving app
9014 mDragState.mDragResult = false;
9015 mDragState.endDragLw();
9016 }
9017 break;
9018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 }
9020 }
9021 }
9022
9023 // -------------------------------------------------------------
9024 // IWindowManager API
9025 // -------------------------------------------------------------
9026
9027 public IWindowSession openSession(IInputMethodClient client,
9028 IInputContext inputContext) {
9029 if (client == null) throw new IllegalArgumentException("null client");
9030 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009031 Session session = new Session(client, inputContext);
9032 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009033 }
9034
9035 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9036 synchronized (mWindowMap) {
9037 // The focus for the client is the window immediately below
9038 // where we would place the input method window.
9039 int idx = findDesiredInputMethodWindowIndexLocked(false);
9040 WindowState imFocus;
9041 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009042 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 if (imFocus != null) {
9044 if (imFocus.mSession.mClient != null &&
9045 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9046 return true;
9047 }
9048 }
9049 }
9050 }
9051 return false;
9052 }
Romain Guy06882f82009-06-10 13:36:04 -07009053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009054 // -------------------------------------------------------------
9055 // Internals
9056 // -------------------------------------------------------------
9057
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009058 final WindowState windowForClientLocked(Session session, IWindow client,
9059 boolean throwOnError) {
9060 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009061 }
Romain Guy06882f82009-06-10 13:36:04 -07009062
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009063 final WindowState windowForClientLocked(Session session, IBinder client,
9064 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009065 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009066 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009067 TAG, "Looking up client " + client + ": " + win);
9068 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009069 RuntimeException ex = new IllegalArgumentException(
9070 "Requested window " + client + " does not exist");
9071 if (throwOnError) {
9072 throw ex;
9073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009074 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009075 return null;
9076 }
9077 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009078 RuntimeException ex = new IllegalArgumentException(
9079 "Requested window " + client + " is in session " +
9080 win.mSession + ", not " + session);
9081 if (throwOnError) {
9082 throw ex;
9083 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009084 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009085 return null;
9086 }
9087
9088 return win;
9089 }
9090
Dianne Hackborna8f60182009-09-01 19:01:50 -07009091 final void rebuildAppWindowListLocked() {
9092 int NW = mWindows.size();
9093 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009094 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009095 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009096
Dianne Hackborna8f60182009-09-01 19:01:50 -07009097 // First remove all existing app windows.
9098 i=0;
9099 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009100 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009101 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009102 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009103 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009104 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009105 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009106 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009107 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009108 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009109 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9110 && lastWallpaper == i-1) {
9111 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009112 }
9113 i++;
9114 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009115
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009116 // The wallpaper window(s) typically live at the bottom of the stack,
9117 // so skip them before adding app tokens.
9118 lastWallpaper++;
9119 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009120
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009121 // First add all of the exiting app tokens... these are no longer
9122 // in the main app list, but still have windows shown. We put them
9123 // in the back because now that the animation is over we no longer
9124 // will care about them.
9125 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009126 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009127 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009129
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009130 // And add in the still active app tokens in Z order.
9131 NT = mAppTokens.size();
9132 for (int j=0; j<NT; j++) {
9133 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009134 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009135
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009136 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009137 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009138 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009139 + " windows but added " + i);
9140 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009141 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 private final void assignLayersLocked() {
9144 int N = mWindows.size();
9145 int curBaseLayer = 0;
9146 int curLayer = 0;
9147 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009148
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009149 if (DEBUG_LAYERS) {
9150 RuntimeException here = new RuntimeException("here");
9151 here.fillInStackTrace();
9152 Log.v(TAG, "Assigning layers", here);
9153 }
9154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009155 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009156 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009157 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9158 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009159 curLayer += WINDOW_LAYER_MULTIPLIER;
9160 w.mLayer = curLayer;
9161 } else {
9162 curBaseLayer = curLayer = w.mBaseLayer;
9163 w.mLayer = curLayer;
9164 }
9165 if (w.mTargetAppToken != null) {
9166 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9167 } else if (w.mAppToken != null) {
9168 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9169 } else {
9170 w.mAnimLayer = w.mLayer;
9171 }
9172 if (w.mIsImWindow) {
9173 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009174 } else if (w.mIsWallpaper) {
9175 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009176 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009177 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009178 + w.mAnimLayer);
9179 //System.out.println(
9180 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9181 }
9182 }
9183
9184 private boolean mInLayout = false;
9185 private final void performLayoutAndPlaceSurfacesLocked() {
9186 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009187 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009188 throw new RuntimeException("Recursive call!");
9189 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009190 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009191 return;
9192 }
9193
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009194 if (mWaitingForConfig) {
9195 // Our configuration has changed (most likely rotation), but we
9196 // don't yet have the complete configuration to report to
9197 // applications. Don't do any window layout until we have it.
9198 return;
9199 }
9200
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009201 if (mDisplay == null) {
9202 // Not yet initialized, nothing to do.
9203 return;
9204 }
9205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009206 boolean recoveringMemory = false;
9207 if (mForceRemoves != null) {
9208 recoveringMemory = true;
9209 // Wait a little it for things to settle down, and off we go.
9210 for (int i=0; i<mForceRemoves.size(); i++) {
9211 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009212 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009213 removeWindowInnerLocked(ws.mSession, ws);
9214 }
9215 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009216 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009217 Object tmp = new Object();
9218 synchronized (tmp) {
9219 try {
9220 tmp.wait(250);
9221 } catch (InterruptedException e) {
9222 }
9223 }
9224 }
Romain Guy06882f82009-06-10 13:36:04 -07009225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 mInLayout = true;
9227 try {
9228 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009230 int i = mPendingRemove.size()-1;
9231 if (i >= 0) {
9232 while (i >= 0) {
9233 WindowState w = mPendingRemove.get(i);
9234 removeWindowInnerLocked(w.mSession, w);
9235 i--;
9236 }
9237 mPendingRemove.clear();
9238
9239 mInLayout = false;
9240 assignLayersLocked();
9241 mLayoutNeeded = true;
9242 performLayoutAndPlaceSurfacesLocked();
9243
9244 } else {
9245 mInLayout = false;
9246 if (mLayoutNeeded) {
9247 requestAnimationLocked(0);
9248 }
9249 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009250 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009251 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9252 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009254 } catch (RuntimeException e) {
9255 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009256 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 }
9258 }
9259
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009260 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009261 if (!mLayoutNeeded) {
9262 return 0;
9263 }
9264
9265 mLayoutNeeded = false;
9266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009267 final int dw = mDisplay.getWidth();
9268 final int dh = mDisplay.getHeight();
9269
9270 final int N = mWindows.size();
9271 int i;
9272
Joe Onorato8a9b2202010-02-26 18:56:32 -08009273 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009274 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9275
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009276 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009277
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009278 int seq = mLayoutSeq+1;
9279 if (seq < 0) seq = 0;
9280 mLayoutSeq = seq;
9281
9282 // First perform layout of any root windows (not attached
9283 // to another window).
9284 int topAttached = -1;
9285 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009286 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009287
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009288 // Don't do layout of a window if it is not visible, or
9289 // soon won't be visible, to avoid wasting time and funky
9290 // changes while a window is animating away.
9291 final AppWindowToken atoken = win.mAppToken;
9292 final boolean gone = win.mViewVisibility == View.GONE
9293 || !win.mRelayoutCalled
9294 || win.mRootToken.hidden
9295 || (atoken != null && atoken.hiddenRequested)
9296 || win.mAttachedHidden
9297 || win.mExiting || win.mDestroying;
9298
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009299 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9300 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009301 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9302 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009303 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009304 + win.mViewVisibility + " mRelayoutCalled="
9305 + win.mRelayoutCalled + " hidden="
9306 + win.mRootToken.hidden + " hiddenRequested="
9307 + (atoken != null && atoken.hiddenRequested)
9308 + " mAttachedHidden=" + win.mAttachedHidden);
9309 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009310
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009311 // If this view is GONE, then skip it -- keep the current
9312 // frame, and let the caller know so they can ignore it
9313 // if they want. (We do the normal layout for INVISIBLE
9314 // windows, since that means "perform layout as normal,
9315 // just don't display").
9316 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009317 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009318 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009319 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009320 win.mContentChanged = false;
9321 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009322 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9323 win.mLayoutSeq = seq;
9324 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9325 + win.mFrame + " mContainingFrame="
9326 + win.mContainingFrame + " mDisplayFrame="
9327 + win.mDisplayFrame);
9328 } else {
9329 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009330 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009331 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009332 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009333
9334 // Now perform layout of attached windows, which usually
9335 // depend on the position of the window they are attached to.
9336 // XXX does not deal with windows that are attached to windows
9337 // that are themselves attached.
9338 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009339 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009340
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009341 if (win.mLayoutAttached) {
9342 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9343 + " mHaveFrame=" + win.mHaveFrame
9344 + " mViewVisibility=" + win.mViewVisibility
9345 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009346 // If this view is GONE, then skip it -- keep the current
9347 // frame, and let the caller know so they can ignore it
9348 // if they want. (We do the normal layout for INVISIBLE
9349 // windows, since that means "perform layout as normal,
9350 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009351 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9352 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009353 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009354 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009355 win.mContentChanged = false;
9356 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009357 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9358 win.mLayoutSeq = seq;
9359 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9360 + win.mFrame + " mContainingFrame="
9361 + win.mContainingFrame + " mDisplayFrame="
9362 + win.mDisplayFrame);
9363 }
9364 }
9365 }
Jeff Brown349703e2010-06-22 01:27:15 -07009366
9367 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009368 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009369
9370 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009371 }
Romain Guy06882f82009-06-10 13:36:04 -07009372
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009373 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009374 private final void performLayoutAndPlaceSurfacesLockedInner(
9375 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009376 if (mDisplay == null) {
9377 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9378 return;
9379 }
9380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009381 final long currentTime = SystemClock.uptimeMillis();
9382 final int dw = mDisplay.getWidth();
9383 final int dh = mDisplay.getHeight();
9384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009385 int i;
9386
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009387 if (mFocusMayChange) {
9388 mFocusMayChange = false;
9389 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9390 }
9391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009392 // Initialize state of exiting tokens.
9393 for (i=mExitingTokens.size()-1; i>=0; i--) {
9394 mExitingTokens.get(i).hasVisible = false;
9395 }
9396
9397 // Initialize state of exiting applications.
9398 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9399 mExitingAppTokens.get(i).hasVisible = false;
9400 }
9401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009402 boolean orientationChangeComplete = true;
9403 Session holdScreen = null;
9404 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009405 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009406 boolean focusDisplayed = false;
9407 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009408 boolean createWatermark = false;
9409
9410 if (mFxSession == null) {
9411 mFxSession = new SurfaceSession();
9412 createWatermark = true;
9413 }
9414
9415 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009416
9417 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009418
9419 if (createWatermark) {
9420 createWatermark();
9421 }
9422 if (mWatermark != null) {
9423 mWatermark.positionSurface(dw, dh);
9424 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009425 if (mStrictModeFlash != null) {
9426 mStrictModeFlash.positionSurface(dw, dh);
9427 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009430 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009431 int repeats = 0;
9432 int changes = 0;
9433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009435 repeats++;
9436 if (repeats > 6) {
9437 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9438 mLayoutNeeded = false;
9439 break;
9440 }
9441
9442 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9443 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9444 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9445 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9446 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9447 assignLayersLocked();
9448 mLayoutNeeded = true;
9449 }
9450 }
9451 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9452 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9453 if (updateOrientationFromAppTokensLocked()) {
9454 mLayoutNeeded = true;
9455 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9456 }
9457 }
9458 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9459 mLayoutNeeded = true;
9460 }
9461 }
9462
9463 // FIRST LOOP: Perform a layout, if needed.
9464 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009465 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009466 if (changes != 0) {
9467 continue;
9468 }
9469 } else {
9470 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9471 changes = 0;
9472 }
9473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 final int transactionSequence = ++mTransactionSequence;
9475
9476 // Update animations of all applications, including those
9477 // associated with exiting/removed apps
9478 boolean tokensAnimating = false;
9479 final int NAT = mAppTokens.size();
9480 for (i=0; i<NAT; i++) {
9481 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9482 tokensAnimating = true;
9483 }
9484 }
9485 final int NEAT = mExitingAppTokens.size();
9486 for (i=0; i<NEAT; i++) {
9487 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9488 tokensAnimating = true;
9489 }
9490 }
9491
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009492 // SECOND LOOP: Execute animations and update visibility of windows.
9493
Joe Onorato8a9b2202010-02-26 18:56:32 -08009494 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009495 + transactionSequence + " tokensAnimating="
9496 + tokensAnimating);
9497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009498 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009500 if (mScreenRotationAnimation != null) {
9501 if (mScreenRotationAnimation.isAnimating()) {
9502 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9503 animating = true;
9504 } else {
9505 mScreenRotationAnimation = null;
9506 }
9507 }
9508 }
9509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009511 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009512 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009513 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514
9515 mPolicy.beginAnimationLw(dw, dh);
9516
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009517 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009520 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009521
9522 final WindowManager.LayoutParams attrs = w.mAttrs;
9523
9524 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009525 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009526 if (w.commitFinishDrawingLocked(currentTime)) {
9527 if ((w.mAttrs.flags
9528 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009529 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009530 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009531 wallpaperMayChange = true;
9532 }
9533 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009534
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009535 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009536
9537 int animDw = dw;
9538 int animDh = dh;
9539
9540 // If the window has moved due to its containing
9541 // content frame changing, then we'd like to animate
9542 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009543 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009544 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009545 // Frame has moved, containing content frame
9546 // has also moved, and we're not currently animating...
9547 // let's do something.
9548 Animation a = AnimationUtils.loadAnimation(mContext,
9549 com.android.internal.R.anim.window_move_from_decor);
9550 w.setAnimation(a);
9551 animDw = w.mLastFrame.left - w.mFrame.left;
9552 animDh = w.mLastFrame.top - w.mFrame.top;
9553 }
9554
9555 // Execute animation.
9556 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9557 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009558
9559 // If this window is animating, make a note that we have
9560 // an animating window and take care of a request to run
9561 // a detached wallpaper animation.
9562 if (nowAnimating) {
9563 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9564 windowDetachedWallpaper = w;
9565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009566 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009567 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009568
9569 // If this window's app token is running a detached wallpaper
9570 // animation, make a note so we can ensure the wallpaper is
9571 // displayed behind it.
9572 if (w.mAppToken != null && w.mAppToken.animation != null
9573 && w.mAppToken.animation.getDetachWallpaper()) {
9574 windowDetachedWallpaper = w;
9575 }
9576
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009577 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9578 wallpaperMayChange = true;
9579 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009580
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009581 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009582 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009583 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009584 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009585 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009586 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009587 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009588 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9589 forceHiding = true;
9590 }
9591 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9592 boolean changed;
9593 if (forceHiding) {
9594 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009595 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9596 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009597 } else {
9598 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009599 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9600 "Now policy shown: " + w);
9601 if (changed) {
9602 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009603 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009604 // Assume we will need to animate. If
9605 // we don't (because the wallpaper will
9606 // stay with the lock screen), then we will
9607 // clean up later.
9608 Animation a = mPolicy.createForceHideEnterAnimation();
9609 if (a != null) {
9610 w.setAnimation(a);
9611 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009612 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009613 if (mCurrentFocus == null ||
9614 mCurrentFocus.mLayer < w.mLayer) {
9615 // We are showing on to of the current
9616 // focus, so re-evaluate focus to make
9617 // sure it is correct.
9618 mFocusMayChange = true;
9619 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009620 }
9621 }
9622 if (changed && (attrs.flags
9623 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9624 wallpaperMayChange = true;
9625 }
9626 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009628 mPolicy.animatingWindowLw(w, attrs);
9629 }
9630
9631 final AppWindowToken atoken = w.mAppToken;
9632 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9633 if (atoken.lastTransactionSequence != transactionSequence) {
9634 atoken.lastTransactionSequence = transactionSequence;
9635 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9636 atoken.startingDisplayed = false;
9637 }
9638 if ((w.isOnScreen() || w.mAttrs.type
9639 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9640 && !w.mExiting && !w.mDestroying) {
9641 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009642 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009643 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009644 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009645 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009646 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009647 + " pv=" + w.mPolicyVisibility
9648 + " dp=" + w.mDrawPending
9649 + " cdp=" + w.mCommitDrawPending
9650 + " ah=" + w.mAttachedHidden
9651 + " th=" + atoken.hiddenRequested
9652 + " a=" + w.mAnimating);
9653 }
9654 }
9655 if (w != atoken.startingWindow) {
9656 if (!atoken.freezingScreen || !w.mAppFreezing) {
9657 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009658 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009659 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009660 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 "tokenMayBeDrawn: " + atoken
9662 + " freezingScreen=" + atoken.freezingScreen
9663 + " mAppFreezing=" + w.mAppFreezing);
9664 tokenMayBeDrawn = true;
9665 }
9666 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009667 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009668 atoken.startingDisplayed = true;
9669 }
9670 }
9671 } else if (w.mReadyToShow) {
9672 w.performShowLocked();
9673 }
9674 }
9675
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009676 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009677
9678 if (tokenMayBeDrawn) {
9679 // See if any windows have been drawn, so they (and others
9680 // associated with them) can now be shown.
9681 final int NT = mTokenList.size();
9682 for (i=0; i<NT; i++) {
9683 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9684 if (wtoken == null) {
9685 continue;
9686 }
9687 if (wtoken.freezingScreen) {
9688 int numInteresting = wtoken.numInterestingWindows;
9689 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009690 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009691 "allDrawn: " + wtoken
9692 + " interesting=" + numInteresting
9693 + " drawn=" + wtoken.numDrawnWindows);
9694 wtoken.showAllWindowsLocked();
9695 unsetAppFreezingScreenLocked(wtoken, false, true);
9696 orientationChangeComplete = true;
9697 }
9698 } else if (!wtoken.allDrawn) {
9699 int numInteresting = wtoken.numInterestingWindows;
9700 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009701 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009702 "allDrawn: " + wtoken
9703 + " interesting=" + numInteresting
9704 + " drawn=" + wtoken.numDrawnWindows);
9705 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009706 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009707
9708 // We can now show all of the drawn windows!
9709 if (!mOpeningApps.contains(wtoken)) {
9710 wtoken.showAllWindowsLocked();
9711 }
9712 }
9713 }
9714 }
9715 }
9716
9717 // If we are ready to perform an app transition, check through
9718 // all of the app tokens to be shown and see if they are ready
9719 // to go.
9720 if (mAppTransitionReady) {
9721 int NN = mOpeningApps.size();
9722 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009723 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009724 "Checking " + NN + " opening apps (frozen="
9725 + mDisplayFrozen + " timeout="
9726 + mAppTransitionTimeout + ")...");
9727 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9728 // If the display isn't frozen, wait to do anything until
9729 // all of the apps are ready. Otherwise just go because
9730 // we'll unfreeze the display when everyone is ready.
9731 for (i=0; i<NN && goodToGo; i++) {
9732 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009733 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009734 "Check opening app" + wtoken + ": allDrawn="
9735 + wtoken.allDrawn + " startingDisplayed="
9736 + wtoken.startingDisplayed);
9737 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9738 && !wtoken.startingMoved) {
9739 goodToGo = false;
9740 }
9741 }
9742 }
9743 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009744 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009745 int transit = mNextAppTransition;
9746 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009747 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009748 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009749 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009750 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009751 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009752 mAppTransitionTimeout = false;
9753 mStartingIconInTransition = false;
9754 mSkipAppTransitionAnimation = false;
9755
9756 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9757
Dianne Hackborna8f60182009-09-01 19:01:50 -07009758 // If there are applications waiting to come to the
9759 // top of the stack, now is the time to move their windows.
9760 // (Note that we don't do apps going to the bottom
9761 // here -- we want to keep their windows in the old
9762 // Z-order until the animation completes.)
9763 if (mToTopApps.size() > 0) {
9764 NN = mAppTokens.size();
9765 for (i=0; i<NN; i++) {
9766 AppWindowToken wtoken = mAppTokens.get(i);
9767 if (wtoken.sendingToTop) {
9768 wtoken.sendingToTop = false;
9769 moveAppWindowsLocked(wtoken, NN, false);
9770 }
9771 }
9772 mToTopApps.clear();
9773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009774
Dianne Hackborn25994b42009-09-04 14:21:19 -07009775 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009776
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009777 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009778 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009779
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009780 // The top-most window will supply the layout params,
9781 // and we will determine it below.
9782 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009783 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009784 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009785
Joe Onorato8a9b2202010-02-26 18:56:32 -08009786 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009787 "New wallpaper target=" + mWallpaperTarget
9788 + ", lower target=" + mLowerWallpaperTarget
9789 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009790 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009791 // Do a first pass through the tokens for two
9792 // things:
9793 // (1) Determine if both the closing and opening
9794 // app token sets are wallpaper targets, in which
9795 // case special animations are needed
9796 // (since the wallpaper needs to stay static
9797 // behind them).
9798 // (2) Find the layout params of the top-most
9799 // application window in the tokens, which is
9800 // what will control the animation theme.
9801 final int NC = mClosingApps.size();
9802 NN = NC + mOpeningApps.size();
9803 for (i=0; i<NN; i++) {
9804 AppWindowToken wtoken;
9805 int mode;
9806 if (i < NC) {
9807 wtoken = mClosingApps.get(i);
9808 mode = 1;
9809 } else {
9810 wtoken = mOpeningApps.get(i-NC);
9811 mode = 2;
9812 }
9813 if (mLowerWallpaperTarget != null) {
9814 if (mLowerWallpaperTarget.mAppToken == wtoken
9815 || mUpperWallpaperTarget.mAppToken == wtoken) {
9816 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009817 }
9818 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009819 if (wtoken.appFullscreen) {
9820 WindowState ws = wtoken.findMainWindow();
9821 if (ws != null) {
9822 // If this is a compatibility mode
9823 // window, we will always use its anim.
9824 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9825 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009826 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009827 bestAnimLayer = Integer.MAX_VALUE;
9828 } else if (ws.mLayer > bestAnimLayer) {
9829 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009830 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009831 bestAnimLayer = ws.mLayer;
9832 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009833 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009834 }
9835 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009836
Dianne Hackborn25994b42009-09-04 14:21:19 -07009837 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009838 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009839 "Wallpaper animation!");
9840 switch (transit) {
9841 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9842 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9843 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9844 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9845 break;
9846 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9847 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9848 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9849 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9850 break;
9851 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009852 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009853 "New transit: " + transit);
9854 } else if (oldWallpaper != null) {
9855 // We are transitioning from an activity with
9856 // a wallpaper to one without.
9857 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009858 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009859 "New transit away from wallpaper: " + transit);
9860 } else if (mWallpaperTarget != null) {
9861 // We are transitioning from an activity without
9862 // a wallpaper to now showing the wallpaper
9863 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009864 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009865 "New transit into wallpaper: " + transit);
9866 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009867
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009868 // If all closing windows are obscured, then there is
9869 // no need to do an animation. This is the case, for
9870 // example, when this transition is being done behind
9871 // the lock screen.
9872 if (!mPolicy.allowAppAnimationsLw()) {
9873 animLp = null;
9874 }
9875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009876 NN = mOpeningApps.size();
9877 for (i=0; i<NN; i++) {
9878 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009879 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009880 "Now opening app" + wtoken);
9881 wtoken.reportedVisible = false;
9882 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009883 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009884 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009886 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 wtoken.showAllWindowsLocked();
9888 }
9889 NN = mClosingApps.size();
9890 for (i=0; i<NN; i++) {
9891 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009892 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893 "Now closing app" + wtoken);
9894 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009895 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009896 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009897 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009898 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 // Force the allDrawn flag, because we want to start
9900 // this guy's animations regardless of whether it's
9901 // gotten drawn.
9902 wtoken.allDrawn = true;
9903 }
9904
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009905 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009907 mOpeningApps.clear();
9908 mClosingApps.clear();
9909
9910 // This has changed the visibility of windows, so perform
9911 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009912 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009913 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009914 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9915 assignLayersLocked();
9916 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009918 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009919 }
9920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009921
Dianne Hackborn16064f92010-03-25 00:47:24 -07009922 int adjResult = 0;
9923
Dianne Hackborna8f60182009-09-01 19:01:50 -07009924 if (!animating && mAppTransitionRunning) {
9925 // We have finished the animation of an app transition. To do
9926 // this, we have delayed a lot of operations like showing and
9927 // hiding apps, moving apps in Z-order, etc. The app token list
9928 // reflects the correct Z-order, but the window list may now
9929 // be out of sync with it. So here we will just rebuild the
9930 // entire app window list. Fun!
9931 mAppTransitionRunning = false;
9932 // Clear information about apps that were moving.
9933 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009934
Dianne Hackborna8f60182009-09-01 19:01:50 -07009935 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009936 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009937 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009938 moveInputMethodWindowsIfNeededLocked(false);
9939 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009940 // Since the window list has been rebuilt, focus might
9941 // have to be recomputed since the actual order of windows
9942 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009943 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009945
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009946 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009947 // At this point, there was a window with a wallpaper that
9948 // was force hiding other windows behind it, but now it
9949 // is going away. This may be simple -- just animate
9950 // away the wallpaper and its window -- or it may be
9951 // hard -- the wallpaper now needs to be shown behind
9952 // something that was hidden.
9953 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009954 if (mLowerWallpaperTarget != null
9955 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009956 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009957 "wallpaperForceHiding changed with lower="
9958 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009959 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009960 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9961 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9962 if (mLowerWallpaperTarget.mAppToken.hidden) {
9963 // The lower target has become hidden before we
9964 // actually started the animation... let's completely
9965 // re-evaluate everything.
9966 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009967 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009968 }
9969 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009970 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009971 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009972 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009973 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009974 + " NEW: " + mWallpaperTarget
9975 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009976 if (mLowerWallpaperTarget == null) {
9977 // Whoops, we don't need a special wallpaper animation.
9978 // Clear them out.
9979 forceHiding = false;
9980 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009981 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009982 if (w.mSurface != null) {
9983 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009984 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009985 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009986 forceHiding = true;
9987 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9988 if (!w.mAnimating) {
9989 // We set the animation above so it
9990 // is not yet running.
9991 w.clearAnimation();
9992 }
9993 }
9994 }
9995 }
9996 }
9997 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009998
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009999 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10000 if (DEBUG_WALLPAPER) Slog.v(TAG,
10001 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10002 + windowDetachedWallpaper);
10003 mWindowDetachedWallpaper = windowDetachedWallpaper;
10004 wallpaperMayChange = true;
10005 }
10006
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010007 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010008 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010009 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010010 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010011 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010012
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010013 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010014 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010015 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010016 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010017 assignLayersLocked();
10018 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010019 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010020 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010021 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010022 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010023
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010024 if (mFocusMayChange) {
10025 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010026 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010027 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010028 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010029 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010030 }
10031
10032 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010033 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010034 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010035
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010036 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10037 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010038
Jeff Browne33348b2010-07-15 23:54:05 -070010039 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010040 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010041
10042 // THIRD LOOP: Update the surfaces of all windows.
10043
10044 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10045
10046 boolean obscured = false;
10047 boolean blurring = false;
10048 boolean dimming = false;
10049 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010050 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010051 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010052
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010053 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010056 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010057
10058 boolean displayed = false;
10059 final WindowManager.LayoutParams attrs = w.mAttrs;
10060 final int attrFlags = attrs.flags;
10061
10062 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010063 // XXX NOTE: The logic here could be improved. We have
10064 // the decision about whether to resize a window separated
10065 // from whether to hide the surface. This can cause us to
10066 // resize a surface even if we are going to hide it. You
10067 // can see this by (1) holding device in landscape mode on
10068 // home screen; (2) tapping browser icon (device will rotate
10069 // to landscape; (3) tap home. The wallpaper will be resized
10070 // in step 2 but then immediately hidden, causing us to
10071 // have to resize and then redraw it again in step 3. It
10072 // would be nice to figure out how to avoid this, but it is
10073 // difficult because we do need to resize surfaces in some
10074 // cases while they are hidden such as when first showing a
10075 // window.
10076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010078 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010079 TAG, "Placing surface #" + i + " " + w.mSurface
10080 + ": new=" + w.mShownFrame + ", old="
10081 + w.mLastShownFrame);
10082
10083 boolean resize;
10084 int width, height;
10085 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10086 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10087 w.mLastRequestedHeight != w.mRequestedHeight;
10088 // for a scaled surface, we just want to use
10089 // the requested size.
10090 width = w.mRequestedWidth;
10091 height = w.mRequestedHeight;
10092 w.mLastRequestedWidth = width;
10093 w.mLastRequestedHeight = height;
10094 w.mLastShownFrame.set(w.mShownFrame);
10095 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010096 if (SHOW_TRANSACTIONS) logSurface(w,
10097 "POS " + w.mShownFrame.left
10098 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010099 w.mSurfaceX = w.mShownFrame.left;
10100 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010101 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10102 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010103 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010104 if (!recoveringMemory) {
10105 reclaimSomeSurfaceMemoryLocked(w, "position");
10106 }
10107 }
10108 } else {
10109 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10110 width = w.mShownFrame.width();
10111 height = w.mShownFrame.height();
10112 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010113 }
10114
10115 if (resize) {
10116 if (width < 1) width = 1;
10117 if (height < 1) height = 1;
10118 if (w.mSurface != null) {
10119 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010120 if (SHOW_TRANSACTIONS) logSurface(w,
10121 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010122 + w.mShownFrame.top + " SIZE "
10123 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010124 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010125 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010126 w.mSurfaceW = width;
10127 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010128 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010129 w.mSurfaceX = w.mShownFrame.left;
10130 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010131 w.mSurface.setPosition(w.mShownFrame.left,
10132 w.mShownFrame.top);
10133 } catch (RuntimeException e) {
10134 // If something goes wrong with the surface (such
10135 // as running out of memory), don't take down the
10136 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010137 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010138 + "size=(" + width + "x" + height
10139 + "), pos=(" + w.mShownFrame.left
10140 + "," + w.mShownFrame.top + ")", e);
10141 if (!recoveringMemory) {
10142 reclaimSomeSurfaceMemoryLocked(w, "size");
10143 }
10144 }
10145 }
10146 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010147 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010148 w.mContentInsetsChanged =
10149 !w.mLastContentInsets.equals(w.mContentInsets);
10150 w.mVisibleInsetsChanged =
10151 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010152 boolean configChanged =
10153 w.mConfiguration != mCurConfiguration
10154 && (w.mConfiguration == null
10155 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010156 if (DEBUG_CONFIGURATION && configChanged) {
10157 Slog.v(TAG, "Win " + w + " config changed: "
10158 + mCurConfiguration);
10159 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010160 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010161 + ": configChanged=" + configChanged
10162 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010163 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010164 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010165 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010166 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010167 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010168 w.mLastFrame.set(w.mFrame);
10169 w.mLastContentInsets.set(w.mContentInsets);
10170 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010171 // If the screen is currently frozen, then keep
10172 // it frozen until this window draws at its new
10173 // orientation.
10174 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010175 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010176 "Resizing while display frozen: " + w);
10177 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010178 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010179 mWindowsFreezingScreen = true;
10180 // XXX should probably keep timeout from
10181 // when we first froze the display.
10182 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10183 mH.sendMessageDelayed(mH.obtainMessage(
10184 H.WINDOW_FREEZE_TIMEOUT), 2000);
10185 }
10186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010187 // If the orientation is changing, then we need to
10188 // hold off on unfreezing the display until this
10189 // window has been redrawn; to do that, we need
10190 // to go through the process of getting informed
10191 // by the application when it has finished drawing.
10192 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010193 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010194 "Orientation start waiting for draw in "
10195 + w + ", surface " + w.mSurface);
10196 w.mDrawPending = true;
10197 w.mCommitDrawPending = false;
10198 w.mReadyToShow = false;
10199 if (w.mAppToken != null) {
10200 w.mAppToken.allDrawn = false;
10201 }
10202 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010203 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010204 "Resizing window " + w + " to " + w.mFrame);
10205 mResizingWindows.add(w);
10206 } else if (w.mOrientationChanging) {
10207 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010208 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010209 "Orientation not waiting for draw in "
10210 + w + ", surface " + w.mSurface);
10211 w.mOrientationChanging = false;
10212 }
10213 }
10214 }
10215
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010216 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010217 if (!w.mLastHidden) {
10218 //dump();
10219 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010220 if (SHOW_TRANSACTIONS) logSurface(w,
10221 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010222 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010223 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010224 try {
10225 w.mSurface.hide();
10226 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010227 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010228 }
10229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010230 }
10231 // If we are waiting for this window to handle an
10232 // orientation change, well, it is hidden, so
10233 // doesn't really matter. Note that this does
10234 // introduce a potential glitch if the window
10235 // becomes unhidden before it has drawn for the
10236 // new orientation.
10237 if (w.mOrientationChanging) {
10238 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010239 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010240 "Orientation change skips hidden " + w);
10241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010242 } else if (w.mLastLayer != w.mAnimLayer
10243 || w.mLastAlpha != w.mShownAlpha
10244 || w.mLastDsDx != w.mDsDx
10245 || w.mLastDtDx != w.mDtDx
10246 || w.mLastDsDy != w.mDsDy
10247 || w.mLastDtDy != w.mDtDy
10248 || w.mLastHScale != w.mHScale
10249 || w.mLastVScale != w.mVScale
10250 || w.mLastHidden) {
10251 displayed = true;
10252 w.mLastAlpha = w.mShownAlpha;
10253 w.mLastLayer = w.mAnimLayer;
10254 w.mLastDsDx = w.mDsDx;
10255 w.mLastDtDx = w.mDtDx;
10256 w.mLastDsDy = w.mDsDy;
10257 w.mLastDtDy = w.mDtDy;
10258 w.mLastHScale = w.mHScale;
10259 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010260 if (SHOW_TRANSACTIONS) logSurface(w,
10261 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010262 + " matrix=[" + (w.mDsDx*w.mHScale)
10263 + "," + (w.mDtDx*w.mVScale)
10264 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010265 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 if (w.mSurface != null) {
10267 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010268 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010269 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010270 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010271 w.mSurface.setLayer(w.mAnimLayer);
10272 w.mSurface.setMatrix(
10273 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10274 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10275 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010276 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 if (!recoveringMemory) {
10278 reclaimSomeSurfaceMemoryLocked(w, "update");
10279 }
10280 }
10281 }
10282
10283 if (w.mLastHidden && !w.mDrawPending
10284 && !w.mCommitDrawPending
10285 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010286 if (SHOW_TRANSACTIONS) logSurface(w,
10287 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010288 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 + " during relayout");
10290 if (showSurfaceRobustlyLocked(w)) {
10291 w.mHasDrawn = true;
10292 w.mLastHidden = false;
10293 } else {
10294 w.mOrientationChanging = false;
10295 }
10296 }
10297 if (w.mSurface != null) {
10298 w.mToken.hasVisible = true;
10299 }
10300 } else {
10301 displayed = true;
10302 }
10303
10304 if (displayed) {
10305 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010306 if (attrs.width == LayoutParams.MATCH_PARENT
10307 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010308 covered = true;
10309 }
10310 }
10311 if (w.mOrientationChanging) {
10312 if (w.mDrawPending || w.mCommitDrawPending) {
10313 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010314 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010315 "Orientation continue waiting for draw in " + w);
10316 } else {
10317 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010318 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010319 "Orientation change complete in " + w);
10320 }
10321 }
10322 w.mToken.hasVisible = true;
10323 }
10324 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010325 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010326 "Orientation change skips hidden " + w);
10327 w.mOrientationChanging = false;
10328 }
10329
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010330 if (w.mContentChanged) {
10331 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10332 w.mContentChanged = false;
10333 }
10334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 final boolean canBeSeen = w.isDisplayedLw();
10336
10337 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10338 focusDisplayed = true;
10339 }
10340
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010341 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010343 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010344 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010345 if (w.mSurface != null) {
10346 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10347 holdScreen = w.mSession;
10348 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010349 if (!syswin && w.mAttrs.screenBrightness >= 0
10350 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010351 screenBrightness = w.mAttrs.screenBrightness;
10352 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010353 if (!syswin && w.mAttrs.buttonBrightness >= 0
10354 && buttonBrightness < 0) {
10355 buttonBrightness = w.mAttrs.buttonBrightness;
10356 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010357 if (canBeSeen
10358 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10359 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10360 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010361 syswin = true;
10362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010364
Dianne Hackborn25994b42009-09-04 14:21:19 -070010365 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10366 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 // This window completely covers everything behind it,
10368 // so we want to leave all of them as unblurred (for
10369 // performance reasons).
10370 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010371 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010372 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010373 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010374 obscured = true;
10375 if (mBackgroundFillerSurface == null) {
10376 try {
10377 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010378 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010379 0, dw, dh,
10380 PixelFormat.OPAQUE,
10381 Surface.FX_SURFACE_NORMAL);
10382 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010383 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010384 }
10385 }
10386 try {
10387 mBackgroundFillerSurface.setPosition(0, 0);
10388 mBackgroundFillerSurface.setSize(dw, dh);
10389 // Using the same layer as Dim because they will never be shown at the
10390 // same time.
10391 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10392 mBackgroundFillerSurface.show();
10393 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010394 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010395 }
10396 backgroundFillerShown = true;
10397 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010398 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010399 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010400 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 + ": blurring=" + blurring
10402 + " obscured=" + obscured
10403 + " displayed=" + displayed);
10404 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10405 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010406 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010407 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010408 if (mDimAnimator == null) {
10409 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010410 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010411 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010412 mDimAnimator.updateParameters(mContext.getResources(),
10413 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010415 }
10416 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10417 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010418 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010419 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010420 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010421 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010422 + mBlurSurface + ": CREATE");
10423 try {
Romain Guy06882f82009-06-10 13:36:04 -070010424 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010425 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010426 -1, 16, 16,
10427 PixelFormat.OPAQUE,
10428 Surface.FX_SURFACE_BLUR);
10429 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010430 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010431 }
10432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010434 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10435 + mBlurSurface + ": pos=(0,0) (" +
10436 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 mBlurSurface.setPosition(0, 0);
10438 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010439 mBlurSurface.setLayer(w.mAnimLayer-2);
10440 if (!mBlurShown) {
10441 try {
10442 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10443 + mBlurSurface + ": SHOW");
10444 mBlurSurface.show();
10445 } catch (RuntimeException e) {
10446 Slog.w(TAG, "Failure showing blur surface", e);
10447 }
10448 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010449 }
10450 }
10451 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 }
10453 }
10454 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010455
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010456 if (obscuredChanged && mWallpaperTarget == w) {
10457 // This is the wallpaper target and its obscured state
10458 // changed... make sure the current wallaper's visibility
10459 // has been updated accordingly.
10460 updateWallpaperVisibilityLocked();
10461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010462 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010463
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010464 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10465 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010466 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010467 try {
10468 mBackgroundFillerSurface.hide();
10469 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010470 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010471 }
10472 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010474 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010475 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10476 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 }
Romain Guy06882f82009-06-10 13:36:04 -070010478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010479 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010480 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010481 + ": HIDE");
10482 try {
10483 mBlurSurface.hide();
10484 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010485 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010486 }
10487 mBlurShown = false;
10488 }
10489
Joe Onorato8a9b2202010-02-26 18:56:32 -080010490 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010492 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 }
10494
Jeff Browne33348b2010-07-15 23:54:05 -070010495 mInputMonitor.updateInputWindowsLw();
10496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010497 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010498
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010499 if (mWatermark != null) {
10500 mWatermark.drawIfNeeded();
10501 }
10502
Joe Onorato8a9b2202010-02-26 18:56:32 -080010503 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 "With display frozen, orientationChangeComplete="
10505 + orientationChangeComplete);
10506 if (orientationChangeComplete) {
10507 if (mWindowsFreezingScreen) {
10508 mWindowsFreezingScreen = false;
10509 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10510 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010511 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010512 }
Romain Guy06882f82009-06-10 13:36:04 -070010513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 i = mResizingWindows.size();
10515 if (i > 0) {
10516 do {
10517 i--;
10518 WindowState win = mResizingWindows.get(i);
10519 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010520 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10521 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010522 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010523 boolean configChanged =
10524 win.mConfiguration != mCurConfiguration
10525 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010526 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10527 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10528 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010529 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010530 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010531 + " / " + mCurConfiguration + " / 0x"
10532 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010533 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010534 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010535 win.mClient.resized(win.mFrame.width(),
10536 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010537 win.mLastVisibleInsets, win.mDrawPending,
10538 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010539 win.mContentInsetsChanged = false;
10540 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010541 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010542 } catch (RemoteException e) {
10543 win.mOrientationChanging = false;
10544 }
10545 } while (i > 0);
10546 mResizingWindows.clear();
10547 }
Romain Guy06882f82009-06-10 13:36:04 -070010548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010549 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010550 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010551 i = mDestroySurface.size();
10552 if (i > 0) {
10553 do {
10554 i--;
10555 WindowState win = mDestroySurface.get(i);
10556 win.mDestroying = false;
10557 if (mInputMethodWindow == win) {
10558 mInputMethodWindow = null;
10559 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010560 if (win == mWallpaperTarget) {
10561 wallpaperDestroyed = true;
10562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010563 win.destroySurfaceLocked();
10564 } while (i > 0);
10565 mDestroySurface.clear();
10566 }
10567
10568 // Time to remove any exiting tokens?
10569 for (i=mExitingTokens.size()-1; i>=0; i--) {
10570 WindowToken token = mExitingTokens.get(i);
10571 if (!token.hasVisible) {
10572 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010573 if (token.windowType == TYPE_WALLPAPER) {
10574 mWallpaperTokens.remove(token);
10575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010576 }
10577 }
10578
10579 // Time to remove any exiting applications?
10580 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10581 AppWindowToken token = mExitingAppTokens.get(i);
10582 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010583 // Make sure there is no animation running on this token,
10584 // so any windows associated with it will be removed as
10585 // soon as their animations are complete
10586 token.animation = null;
10587 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588 mAppTokens.remove(token);
10589 mExitingAppTokens.remove(i);
10590 }
10591 }
10592
Dianne Hackborna8f60182009-09-01 19:01:50 -070010593 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010594
Dianne Hackborna8f60182009-09-01 19:01:50 -070010595 if (!animating && mAppTransitionRunning) {
10596 // We have finished the animation of an app transition. To do
10597 // this, we have delayed a lot of operations like showing and
10598 // hiding apps, moving apps in Z-order, etc. The app token list
10599 // reflects the correct Z-order, but the window list may now
10600 // be out of sync with it. So here we will just rebuild the
10601 // entire app window list. Fun!
10602 mAppTransitionRunning = false;
10603 needRelayout = true;
10604 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010605 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010606 // Clear information about apps that were moving.
10607 mToBottomApps.clear();
10608 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010610 if (focusDisplayed) {
10611 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10612 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010613 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010614 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010615 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010616 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010617 requestAnimationLocked(0);
10618 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010619 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10620 }
Jeff Browneb857f12010-07-16 10:06:33 -070010621
Jeff Browne33348b2010-07-15 23:54:05 -070010622 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010623
Jeff Brown8e03b752010-06-13 19:16:55 -070010624 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010625 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10626 mPowerManager.setScreenBrightnessOverride(-1);
10627 } else {
10628 mPowerManager.setScreenBrightnessOverride((int)
10629 (screenBrightness * Power.BRIGHTNESS_ON));
10630 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010631 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10632 mPowerManager.setButtonBrightnessOverride(-1);
10633 } else {
10634 mPowerManager.setButtonBrightnessOverride((int)
10635 (buttonBrightness * Power.BRIGHTNESS_ON));
10636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010637 if (holdScreen != mHoldingScreenOn) {
10638 mHoldingScreenOn = holdScreen;
10639 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10640 mH.sendMessage(m);
10641 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010642
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010643 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010644 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010645 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10646 LocalPowerManager.BUTTON_EVENT, true);
10647 mTurnOnScreen = false;
10648 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010649
10650 // Check to see if we are now in a state where the screen should
10651 // be enabled, because the window obscured flags have changed.
10652 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010653 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010654
10655 /**
10656 * Must be called with the main window manager lock held.
10657 */
10658 void setHoldScreenLocked(boolean holding) {
10659 boolean state = mHoldingScreenWakeLock.isHeld();
10660 if (holding != state) {
10661 if (holding) {
10662 mHoldingScreenWakeLock.acquire();
10663 } else {
10664 mPolicy.screenOnStoppedLw();
10665 mHoldingScreenWakeLock.release();
10666 }
10667 }
10668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010669
10670 void requestAnimationLocked(long delay) {
10671 if (!mAnimationPending) {
10672 mAnimationPending = true;
10673 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10674 }
10675 }
Romain Guy06882f82009-06-10 13:36:04 -070010676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010677 /**
10678 * Have the surface flinger show a surface, robustly dealing with
10679 * error conditions. In particular, if there is not enough memory
10680 * to show the surface, then we will try to get rid of other surfaces
10681 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010682 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010683 * @return Returns true if the surface was successfully shown.
10684 */
10685 boolean showSurfaceRobustlyLocked(WindowState win) {
10686 try {
10687 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010688 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010689 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010690 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010691 if (DEBUG_VISIBILITY) Slog.v(TAG,
10692 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010693 win.mTurnOnScreen = false;
10694 mTurnOnScreen = true;
10695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010696 }
10697 return true;
10698 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010699 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010700 }
Romain Guy06882f82009-06-10 13:36:04 -070010701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010702 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010704 return false;
10705 }
Romain Guy06882f82009-06-10 13:36:04 -070010706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010707 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10708 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010709
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010710 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010711 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010713 if (mForceRemoves == null) {
10714 mForceRemoves = new ArrayList<WindowState>();
10715 }
Romain Guy06882f82009-06-10 13:36:04 -070010716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010717 long callingIdentity = Binder.clearCallingIdentity();
10718 try {
10719 // There was some problem... first, do a sanity check of the
10720 // window list to make sure we haven't left any dangling surfaces
10721 // around.
10722 int N = mWindows.size();
10723 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010724 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010725 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010726 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010727 if (ws.mSurface != null) {
10728 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010729 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010730 + ws + " surface=" + ws.mSurface
10731 + " token=" + win.mToken
10732 + " pid=" + ws.mSession.mPid
10733 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010734 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010735 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010736 ws.mSurface = null;
10737 mForceRemoves.add(ws);
10738 i--;
10739 N--;
10740 leakedSurface = true;
10741 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010742 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010743 + ws + " surface=" + ws.mSurface
10744 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010745 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010746 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010747 ws.mSurface = null;
10748 leakedSurface = true;
10749 }
10750 }
10751 }
Romain Guy06882f82009-06-10 13:36:04 -070010752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010753 boolean killedApps = false;
10754 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010755 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010756 SparseIntArray pidCandidates = new SparseIntArray();
10757 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010758 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010759 if (ws.mSurface != null) {
10760 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10761 }
10762 }
10763 if (pidCandidates.size() > 0) {
10764 int[] pids = new int[pidCandidates.size()];
10765 for (int i=0; i<pids.length; i++) {
10766 pids[i] = pidCandidates.keyAt(i);
10767 }
10768 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010769 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770 killedApps = true;
10771 }
10772 } catch (RemoteException e) {
10773 }
10774 }
10775 }
Romain Guy06882f82009-06-10 13:36:04 -070010776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010777 if (leakedSurface || killedApps) {
10778 // We managed to reclaim some memory, so get rid of the trouble
10779 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010780 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010781 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010782 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010783 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010784 win.mSurface = null;
10785 }
Romain Guy06882f82009-06-10 13:36:04 -070010786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010787 try {
10788 win.mClient.dispatchGetNewSurface();
10789 } catch (RemoteException e) {
10790 }
10791 }
10792 } finally {
10793 Binder.restoreCallingIdentity(callingIdentity);
10794 }
10795 }
Romain Guy06882f82009-06-10 13:36:04 -070010796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 private boolean updateFocusedWindowLocked(int mode) {
10798 WindowState newFocus = computeFocusedWindowLocked();
10799 if (mCurrentFocus != newFocus) {
10800 // This check makes sure that we don't already have the focus
10801 // change message pending.
10802 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10803 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010804 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010805 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10806 final WindowState oldFocus = mCurrentFocus;
10807 mCurrentFocus = newFocus;
10808 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 final WindowState imWindow = mInputMethodWindow;
10811 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010812 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010813 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010814 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10815 mLayoutNeeded = true;
10816 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010817 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080010818 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010819 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10820 // Client will do the layout, but we need to assign layers
10821 // for handleNewWindowLocked() below.
10822 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010823 }
10824 }
Jeff Brown349703e2010-06-22 01:27:15 -070010825
10826 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10827 // If we defer assigning layers, then the caller is responsible for
10828 // doing this part.
10829 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010831 return true;
10832 }
10833 return false;
10834 }
Jeff Brown349703e2010-06-22 01:27:15 -070010835
10836 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010837 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010839
10840 private WindowState computeFocusedWindowLocked() {
10841 WindowState result = null;
10842 WindowState win;
10843
10844 int i = mWindows.size() - 1;
10845 int nextAppIndex = mAppTokens.size()-1;
10846 WindowToken nextApp = nextAppIndex >= 0
10847 ? mAppTokens.get(nextAppIndex) : null;
10848
10849 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010850 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010851
Joe Onorato8a9b2202010-02-26 18:56:32 -080010852 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010853 TAG, "Looking for focus: " + i
10854 + " = " + win
10855 + ", flags=" + win.mAttrs.flags
10856 + ", canReceive=" + win.canReceiveKeys());
10857
10858 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010860 // If this window's application has been removed, just skip it.
10861 if (thisApp != null && thisApp.removed) {
10862 i--;
10863 continue;
10864 }
Romain Guy06882f82009-06-10 13:36:04 -070010865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 // If there is a focused app, don't allow focus to go to any
10867 // windows below it. If this is an application window, step
10868 // through the app tokens until we find its app.
10869 if (thisApp != null && nextApp != null && thisApp != nextApp
10870 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10871 int origAppIndex = nextAppIndex;
10872 while (nextAppIndex > 0) {
10873 if (nextApp == mFocusedApp) {
10874 // Whoops, we are below the focused app... no focus
10875 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010876 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010877 TAG, "Reached focused app: " + mFocusedApp);
10878 return null;
10879 }
10880 nextAppIndex--;
10881 nextApp = mAppTokens.get(nextAppIndex);
10882 if (nextApp == thisApp) {
10883 break;
10884 }
10885 }
10886 if (thisApp != nextApp) {
10887 // Uh oh, the app token doesn't exist! This shouldn't
10888 // happen, but if it does we can get totally hosed...
10889 // so restart at the original app.
10890 nextAppIndex = origAppIndex;
10891 nextApp = mAppTokens.get(nextAppIndex);
10892 }
10893 }
10894
10895 // Dispatch to this window if it is wants key events.
10896 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010897 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 TAG, "Found focus @ " + i + " = " + win);
10899 result = win;
10900 break;
10901 }
10902
10903 i--;
10904 }
10905
10906 return result;
10907 }
10908
10909 private void startFreezingDisplayLocked() {
10910 if (mDisplayFrozen) {
10911 return;
10912 }
Romain Guy06882f82009-06-10 13:36:04 -070010913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010914 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010916 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010917 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010918 if (mFreezeGcPending != 0) {
10919 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010920 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010921 mH.removeMessages(H.FORCE_GC);
10922 Runtime.getRuntime().gc();
10923 mFreezeGcPending = now;
10924 }
10925 } else {
10926 mFreezeGcPending = now;
10927 }
Romain Guy06882f82009-06-10 13:36:04 -070010928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010929 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010930
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010931 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010932
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010933 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10934 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010935 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010936 mAppTransitionReady = true;
10937 }
Romain Guy06882f82009-06-10 13:36:04 -070010938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 if (PROFILE_ORIENTATION) {
10940 File file = new File("/data/system/frozen");
10941 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10942 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010943
10944 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010945 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
10946 mScreenRotationAnimation.kill();
10947 mScreenRotationAnimation = null;
10948 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010949 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010950 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
10951 mDisplay, mFxSession);
Dianne Hackborna1111872010-11-23 20:55:11 -080010952 }
10953 } else {
10954 Surface.freezeDisplay(0);
10955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010956 }
Romain Guy06882f82009-06-10 13:36:04 -070010957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010958 private void stopFreezingDisplayLocked() {
10959 if (!mDisplayFrozen) {
10960 return;
10961 }
Romain Guy06882f82009-06-10 13:36:04 -070010962
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010963 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10964 return;
10965 }
10966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010967 mDisplayFrozen = false;
10968 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10969 if (PROFILE_ORIENTATION) {
10970 Debug.stopMethodTracing();
10971 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010972
10973 if (CUSTOM_SCREEN_ROTATION) {
10974 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010975 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
10976 mTransitionAnimationScale)) {
10977 requestAnimationLocked(0);
10978 } else {
10979 mScreenRotationAnimation = null;
10980 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010981 }
10982 } else {
10983 Surface.unfreezeDisplay(0);
10984 }
Romain Guy06882f82009-06-10 13:36:04 -070010985
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010986 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987
Christopher Tateb696aee2010-04-02 19:08:30 -070010988 // While the display is frozen we don't re-compute the orientation
10989 // to avoid inconsistent states. However, something interesting
10990 // could have actually changed during that time so re-evaluate it
10991 // now to catch that.
10992 if (updateOrientationFromAppTokensLocked()) {
10993 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10994 }
10995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010996 // A little kludge: a lot could have happened while the
10997 // display was frozen, so now that we are coming back we
10998 // do a gc so that any remote references the system
10999 // processes holds on others can be released if they are
11000 // no longer needed.
11001 mH.removeMessages(H.FORCE_GC);
11002 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11003 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011005 mScreenFrozenLock.release();
11006 }
Romain Guy06882f82009-06-10 13:36:04 -070011007
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011008 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11009 DisplayMetrics dm) {
11010 if (index < tokens.length) {
11011 String str = tokens[index];
11012 if (str != null && str.length() > 0) {
11013 try {
11014 int val = Integer.parseInt(str);
11015 return val;
11016 } catch (Exception e) {
11017 }
11018 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011019 }
11020 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11021 return defDps;
11022 }
11023 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11024 return val;
11025 }
11026
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011027 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011028 final String[] mTokens;
11029 final String mText;
11030 final Paint mTextPaint;
11031 final int mTextWidth;
11032 final int mTextHeight;
11033 final int mTextAscent;
11034 final int mTextDescent;
11035 final int mDeltaX;
11036 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011037
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011038 Surface mSurface;
11039 int mLastDW;
11040 int mLastDH;
11041 boolean mDrawNeeded;
11042
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011043 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011044 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011045 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011046
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011047 if (false) {
11048 Log.i(TAG, "*********************** WATERMARK");
11049 for (int i=0; i<tokens.length; i++) {
11050 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11051 }
11052 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011053
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011054 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011055
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011056 StringBuilder builder = new StringBuilder(32);
11057 int len = mTokens[0].length();
11058 len = len & ~1;
11059 for (int i=0; i<len; i+=2) {
11060 int c1 = mTokens[0].charAt(i);
11061 int c2 = mTokens[0].charAt(i+1);
11062 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11063 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11064 else c1 -= '0';
11065 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11066 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11067 else c2 -= '0';
11068 builder.append((char)(255-((c1*16)+c2)));
11069 }
11070 mText = builder.toString();
11071 if (false) {
11072 Log.i(TAG, "Final text: " + mText);
11073 }
11074
11075 int fontSize = getPropertyInt(tokens, 1,
11076 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11077
11078 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11079 mTextPaint.setTextSize(fontSize);
11080 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11081
11082 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11083 mTextWidth = (int)mTextPaint.measureText(mText);
11084 mTextAscent = fm.ascent;
11085 mTextDescent = fm.descent;
11086 mTextHeight = fm.descent - fm.ascent;
11087
11088 mDeltaX = getPropertyInt(tokens, 2,
11089 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11090 mDeltaY = getPropertyInt(tokens, 3,
11091 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11092 int shadowColor = getPropertyInt(tokens, 4,
11093 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11094 int color = getPropertyInt(tokens, 5,
11095 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11096 int shadowRadius = getPropertyInt(tokens, 6,
11097 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11098 int shadowDx = getPropertyInt(tokens, 8,
11099 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11100 int shadowDy = getPropertyInt(tokens, 9,
11101 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11102
11103 mTextPaint.setColor(color);
11104 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011105
11106 try {
11107 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011108 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011109 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011110 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011111 mSurface.show();
11112 } catch (OutOfResourcesException e) {
11113 }
11114 }
11115
11116 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011117 if (mLastDW != dw || mLastDH != dh) {
11118 mLastDW = dw;
11119 mLastDH = dh;
11120 mSurface.setSize(dw, dh);
11121 mDrawNeeded = true;
11122 }
11123 }
11124
11125 void drawIfNeeded() {
11126 if (mDrawNeeded) {
11127 final int dw = mLastDW;
11128 final int dh = mLastDH;
11129
11130 mDrawNeeded = false;
11131 Rect dirty = new Rect(0, 0, dw, dh);
11132 Canvas c = null;
11133 try {
11134 c = mSurface.lockCanvas(dirty);
11135 } catch (IllegalArgumentException e) {
11136 } catch (OutOfResourcesException e) {
11137 }
11138 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011139 c.drawColor(0, PorterDuff.Mode.CLEAR);
11140
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011141 int deltaX = mDeltaX;
11142 int deltaY = mDeltaY;
11143
11144 // deltaX shouldn't be close to a round fraction of our
11145 // x step, or else things will line up too much.
11146 int div = (dw+mTextWidth)/deltaX;
11147 int rem = (dw+mTextWidth) - (div*deltaX);
11148 int qdelta = deltaX/4;
11149 if (rem < qdelta || rem > (deltaX-qdelta)) {
11150 deltaX += deltaX/3;
11151 }
11152
11153 int y = -mTextHeight;
11154 int x = -mTextWidth;
11155 while (y < (dh+mTextHeight)) {
11156 c.drawText(mText, x, y, mTextPaint);
11157 x += deltaX;
11158 if (x >= dw) {
11159 x -= (dw+mTextWidth);
11160 y += deltaY;
11161 }
11162 }
11163 mSurface.unlockCanvasAndPost(c);
11164 }
11165 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011166 }
11167 }
11168
11169 void createWatermark() {
11170 if (mWatermark != null) {
11171 return;
11172 }
11173
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011174 File file = new File("/system/etc/setup.conf");
11175 FileInputStream in = null;
11176 try {
11177 in = new FileInputStream(file);
11178 DataInputStream ind = new DataInputStream(in);
11179 String line = ind.readLine();
11180 if (line != null) {
11181 String[] toks = line.split("%");
11182 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011183 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011184 }
11185 }
11186 } catch (FileNotFoundException e) {
11187 } catch (IOException e) {
11188 } finally {
11189 if (in != null) {
11190 try {
11191 in.close();
11192 } catch (IOException e) {
11193 }
11194 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011195 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011196 }
11197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011198 @Override
11199 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11200 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11201 != PackageManager.PERMISSION_GRANTED) {
11202 pw.println("Permission Denial: can't dump WindowManager from from pid="
11203 + Binder.getCallingPid()
11204 + ", uid=" + Binder.getCallingUid());
11205 return;
11206 }
Romain Guy06882f82009-06-10 13:36:04 -070011207
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011208 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011209 pw.println(" ");
11210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011211 synchronized(mWindowMap) {
11212 pw.println("Current Window Manager state:");
11213 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011214 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011215 pw.print(" Window #"); pw.print(i); pw.print(' ');
11216 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011217 w.dump(pw, " ");
11218 }
11219 if (mInputMethodDialogs.size() > 0) {
11220 pw.println(" ");
11221 pw.println(" Input method dialogs:");
11222 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11223 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011224 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011225 }
11226 }
11227 if (mPendingRemove.size() > 0) {
11228 pw.println(" ");
11229 pw.println(" Remove pending for:");
11230 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11231 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011232 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11233 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011234 w.dump(pw, " ");
11235 }
11236 }
11237 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11238 pw.println(" ");
11239 pw.println(" Windows force removing:");
11240 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11241 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011242 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11243 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011244 w.dump(pw, " ");
11245 }
11246 }
11247 if (mDestroySurface.size() > 0) {
11248 pw.println(" ");
11249 pw.println(" Windows waiting to destroy their surface:");
11250 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11251 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011252 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11253 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011254 w.dump(pw, " ");
11255 }
11256 }
11257 if (mLosingFocus.size() > 0) {
11258 pw.println(" ");
11259 pw.println(" Windows losing focus:");
11260 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11261 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011262 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11263 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011264 w.dump(pw, " ");
11265 }
11266 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011267 if (mResizingWindows.size() > 0) {
11268 pw.println(" ");
11269 pw.println(" Windows waiting to resize:");
11270 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11271 WindowState w = mResizingWindows.get(i);
11272 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11273 pw.print(w); pw.println(":");
11274 w.dump(pw, " ");
11275 }
11276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011277 if (mSessions.size() > 0) {
11278 pw.println(" ");
11279 pw.println(" All active sessions:");
11280 Iterator<Session> it = mSessions.iterator();
11281 while (it.hasNext()) {
11282 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011283 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011284 s.dump(pw, " ");
11285 }
11286 }
11287 if (mTokenMap.size() > 0) {
11288 pw.println(" ");
11289 pw.println(" All tokens:");
11290 Iterator<WindowToken> it = mTokenMap.values().iterator();
11291 while (it.hasNext()) {
11292 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011293 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011294 token.dump(pw, " ");
11295 }
11296 }
11297 if (mTokenList.size() > 0) {
11298 pw.println(" ");
11299 pw.println(" Window token list:");
11300 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011301 pw.print(" #"); pw.print(i); pw.print(": ");
11302 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011303 }
11304 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011305 if (mWallpaperTokens.size() > 0) {
11306 pw.println(" ");
11307 pw.println(" Wallpaper tokens:");
11308 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11309 WindowToken token = mWallpaperTokens.get(i);
11310 pw.print(" Wallpaper #"); pw.print(i);
11311 pw.print(' '); pw.print(token); pw.println(':');
11312 token.dump(pw, " ");
11313 }
11314 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011315 if (mAppTokens.size() > 0) {
11316 pw.println(" ");
11317 pw.println(" Application tokens in Z order:");
11318 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011319 pw.print(" App #"); pw.print(i); pw.print(": ");
11320 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011321 }
11322 }
11323 if (mFinishedStarting.size() > 0) {
11324 pw.println(" ");
11325 pw.println(" Finishing start of application tokens:");
11326 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11327 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011328 pw.print(" Finished Starting #"); pw.print(i);
11329 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011330 token.dump(pw, " ");
11331 }
11332 }
11333 if (mExitingTokens.size() > 0) {
11334 pw.println(" ");
11335 pw.println(" Exiting tokens:");
11336 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11337 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011338 pw.print(" Exiting #"); pw.print(i);
11339 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011340 token.dump(pw, " ");
11341 }
11342 }
11343 if (mExitingAppTokens.size() > 0) {
11344 pw.println(" ");
11345 pw.println(" Exiting application tokens:");
11346 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11347 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011348 pw.print(" Exiting App #"); pw.print(i);
11349 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011350 token.dump(pw, " ");
11351 }
11352 }
11353 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011354 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11355 pw.print(" mLastFocus="); pw.println(mLastFocus);
11356 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11357 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11358 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011359 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011360 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11361 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11362 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11363 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011364 if (mWindowDetachedWallpaper != null) {
11365 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11366 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011367 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11368 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11369 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011370 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11371 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11372 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11373 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011374 if (mDimAnimator != null) {
11375 mDimAnimator.printTo(pw);
11376 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011377 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011378 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011379 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011380 pw.print(mInputMethodAnimLayerAdjustment);
11381 pw.print(" mWallpaperAnimLayerAdjustment=");
11382 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011383 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11384 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011385 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11386 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011387 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11388 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011389 pw.print(" mRotation="); pw.print(mRotation);
11390 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11391 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11392 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11393 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11394 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11395 pw.print(" mNextAppTransition=0x");
11396 pw.print(Integer.toHexString(mNextAppTransition));
11397 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011398 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011399 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011400 if (mNextAppTransitionPackage != null) {
11401 pw.print(" mNextAppTransitionPackage=");
11402 pw.print(mNextAppTransitionPackage);
11403 pw.print(", mNextAppTransitionEnter=0x");
11404 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11405 pw.print(", mNextAppTransitionExit=0x");
11406 pw.print(Integer.toHexString(mNextAppTransitionExit));
11407 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011408 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11409 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11410 if (mOpeningApps.size() > 0) {
11411 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11412 }
11413 if (mClosingApps.size() > 0) {
11414 pw.print(" mClosingApps="); pw.println(mClosingApps);
11415 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011416 if (mToTopApps.size() > 0) {
11417 pw.print(" mToTopApps="); pw.println(mToTopApps);
11418 }
11419 if (mToBottomApps.size() > 0) {
11420 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11421 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011422 if (mDisplay != null) {
11423 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11424 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11425 } else {
11426 pw.println(" NO DISPLAY");
11427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011428 }
11429 }
11430
Jeff Brown349703e2010-06-22 01:27:15 -070011431 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011432 public void monitor() {
11433 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011434 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011435 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011436
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011437 /**
11438 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011439 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011440 */
11441 private static class DimAnimator {
11442 Surface mDimSurface;
11443 boolean mDimShown = false;
11444 float mDimCurrentAlpha;
11445 float mDimTargetAlpha;
11446 float mDimDeltaPerMs;
11447 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011448
11449 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011450
11451 DimAnimator (SurfaceSession session) {
11452 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011453 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011454 + mDimSurface + ": CREATE");
11455 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011456 mDimSurface = new Surface(session, 0,
11457 "DimSurface",
11458 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011459 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011460 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011461 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011462 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011463 }
11464 }
11465 }
11466
11467 /**
11468 * Show the dim surface.
11469 */
11470 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011471 if (!mDimShown) {
11472 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11473 dw + "x" + dh + ")");
11474 mDimShown = true;
11475 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011476 mLastDimWidth = dw;
11477 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011478 mDimSurface.setPosition(0, 0);
11479 mDimSurface.setSize(dw, dh);
11480 mDimSurface.show();
11481 } catch (RuntimeException e) {
11482 Slog.w(TAG, "Failure showing dim surface", e);
11483 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011484 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11485 mLastDimWidth = dw;
11486 mLastDimHeight = dh;
11487 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011488 }
11489 }
11490
11491 /**
11492 * Set's the dim surface's layer and update dim parameters that will be used in
11493 * {@link updateSurface} after all windows are examined.
11494 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011495 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011496 mDimSurface.setLayer(w.mAnimLayer-1);
11497
11498 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011499 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011500 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011501 if (mDimTargetAlpha != target) {
11502 // If the desired dim level has changed, then
11503 // start an animation to it.
11504 mLastDimAnimTime = currentTime;
11505 long duration = (w.mAnimating && w.mAnimation != null)
11506 ? w.mAnimation.computeDurationHint()
11507 : DEFAULT_DIM_DURATION;
11508 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011509 TypedValue tv = new TypedValue();
11510 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11511 tv, true);
11512 if (tv.type == TypedValue.TYPE_FRACTION) {
11513 duration = (long)tv.getFraction((float)duration, (float)duration);
11514 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11515 && tv.type <= TypedValue.TYPE_LAST_INT) {
11516 duration = tv.data;
11517 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011518 }
11519 if (duration < 1) {
11520 // Don't divide by zero
11521 duration = 1;
11522 }
11523 mDimTargetAlpha = target;
11524 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11525 }
11526 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011527
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011528 /**
11529 * Updating the surface's alpha. Returns true if the animation continues, or returns
11530 * false when the animation is finished and the dim surface is hidden.
11531 */
11532 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11533 if (!dimming) {
11534 if (mDimTargetAlpha != 0) {
11535 mLastDimAnimTime = currentTime;
11536 mDimTargetAlpha = 0;
11537 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11538 }
11539 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011540
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011541 boolean animating = false;
11542 if (mLastDimAnimTime != 0) {
11543 mDimCurrentAlpha += mDimDeltaPerMs
11544 * (currentTime-mLastDimAnimTime);
11545 boolean more = true;
11546 if (displayFrozen) {
11547 // If the display is frozen, there is no reason to animate.
11548 more = false;
11549 } else if (mDimDeltaPerMs > 0) {
11550 if (mDimCurrentAlpha > mDimTargetAlpha) {
11551 more = false;
11552 }
11553 } else if (mDimDeltaPerMs < 0) {
11554 if (mDimCurrentAlpha < mDimTargetAlpha) {
11555 more = false;
11556 }
11557 } else {
11558 more = false;
11559 }
11560
11561 // Do we need to continue animating?
11562 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011563 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011564 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11565 mLastDimAnimTime = currentTime;
11566 mDimSurface.setAlpha(mDimCurrentAlpha);
11567 animating = true;
11568 } else {
11569 mDimCurrentAlpha = mDimTargetAlpha;
11570 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011571 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011572 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11573 mDimSurface.setAlpha(mDimCurrentAlpha);
11574 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011575 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011576 + ": HIDE");
11577 try {
11578 mDimSurface.hide();
11579 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011580 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011581 }
11582 mDimShown = false;
11583 }
11584 }
11585 }
11586 return animating;
11587 }
11588
11589 public void printTo(PrintWriter pw) {
11590 pw.print(" mDimShown="); pw.print(mDimShown);
11591 pw.print(" current="); pw.print(mDimCurrentAlpha);
11592 pw.print(" target="); pw.print(mDimTargetAlpha);
11593 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11594 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11595 }
11596 }
11597
11598 /**
11599 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11600 * This is used for opening/closing transition for apps in compatible mode.
11601 */
11602 private static class FadeInOutAnimation extends Animation {
11603 int mWidth;
11604 boolean mFadeIn;
11605
11606 public FadeInOutAnimation(boolean fadeIn) {
11607 setInterpolator(new AccelerateInterpolator());
11608 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11609 mFadeIn = fadeIn;
11610 }
11611
11612 @Override
11613 protected void applyTransformation(float interpolatedTime, Transformation t) {
11614 float x = interpolatedTime;
11615 if (!mFadeIn) {
11616 x = 1.0f - x; // reverse the interpolation for fade out
11617 }
11618 if (x < 0.5) {
11619 // move the window out of the screen.
11620 t.getMatrix().setTranslate(mWidth, 0);
11621 } else {
11622 t.getMatrix().setTranslate(0, 0);// show
11623 t.setAlpha((x - 0.5f) * 2);
11624 }
11625 }
11626
11627 @Override
11628 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11629 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11630 mWidth = width;
11631 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011632
11633 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011634 public int getZAdjustment() {
11635 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011636 }
11637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011638}