blob: cbb35c656bb39444633de7dbc7a73f21458c8060 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
32import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
33import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
35import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070036import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38import com.android.internal.app.IBatteryStats;
39import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080040import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070041import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import com.android.internal.view.IInputContext;
43import com.android.internal.view.IInputMethodClient;
44import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080045import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import com.android.server.am.BatteryStatsService;
47
48import android.Manifest;
49import android.app.ActivityManagerNative;
50import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070053import android.content.ClipData;
54import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070056import android.content.Intent;
57import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080062import android.content.res.Resources;
Dianne 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 Brown46b9ac02010-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 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700330 * This was the app token that was used to retrieve the last enter
331 * animation. It will be used for the next exit animation.
332 */
333 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800334
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700335 /**
336 * These were the layout params used to retrieve the last enter animation.
337 * They will be used for the next exit animation.
338 */
339 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800340
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700341 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 * Z-ordered (bottom-most first) list of all Window objects.
343 */
Jeff Browne33348b2010-07-15 23:54:05 -0700344 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345
346 /**
347 * Windows that are being resized. Used so we can tell the client about
348 * the resize after closing the transaction in which we resized the
349 * underlying surface.
350 */
351 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
352
353 /**
354 * Windows whose animations have ended and now must be removed.
355 */
356 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
357
358 /**
359 * Windows whose surface should be destroyed.
360 */
361 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
362
363 /**
364 * Windows that have lost input focus and are waiting for the new
365 * focus window to be displayed before they are told about this.
366 */
367 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
368
369 /**
370 * This is set when we have run out of memory, and will either be an empty
371 * list or contain windows that need to be force removed.
372 */
373 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700378 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 Surface mBlurSurface;
380 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700381 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800382 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800383 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 final float[] mTmpFloats = new float[9];
388
389 boolean mSafeMode;
390 boolean mDisplayEnabled = false;
391 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700392 int mInitialDisplayWidth = 0;
393 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 int mRotation = 0;
395 int mRequestedRotation = 0;
396 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700397 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 ArrayList<IRotationWatcher> mRotationWatchers
399 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 boolean mLayoutNeeded = true;
402 boolean mAnimationPending = false;
403 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800404 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 boolean mWindowsFreezingScreen = false;
406 long mFreezeGcPending = 0;
407 int mAppsFreezingScreen = 0;
408
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800409 int mLayoutSeq = 0;
410
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800411 // State while inside of layoutAndPlaceSurfacesLocked().
412 boolean mFocusMayChange;
413
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800414 Configuration mCurConfiguration = new Configuration();
415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 // This is held as long as we have the screen frozen, to give us time to
417 // perform a rotation animation when turning off shows the lock screen which
418 // changes the orientation.
419 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 // State management of app transitions. When we are preparing for a
422 // transition, mNextAppTransition will be the kind of transition to
423 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
424 // mOpeningApps and mClosingApps are the lists of tokens that will be
425 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700426 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700427 String mNextAppTransitionPackage;
428 int mNextAppTransitionEnter;
429 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700431 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 boolean mAppTransitionTimeout = false;
433 boolean mStartingIconInTransition = false;
434 boolean mSkipAppTransitionAnimation = false;
435 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
436 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700437 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
438 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 H mH = new H();
443
444 WindowState mCurrentFocus = null;
445 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 // This just indicates the window the input method is on top of, not
448 // necessarily the window its input is going to.
449 WindowState mInputMethodTarget = null;
450 WindowState mUpcomingInputMethodTarget = null;
451 boolean mInputMethodTargetWaitingAnim;
452 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 WindowState mInputMethodWindow = null;
455 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
456
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700457 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800458
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700459 // If non-null, this is the currently visible window that is associated
460 // with the wallpaper.
461 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the lower one in Z-order.
464 WindowState mLowerWallpaperTarget = null;
465 // If non-null, we are in the middle of animating from one wallpaper target
466 // to another, and this is the higher one in Z-order.
467 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800468 // Window currently running an animation that has requested it be detached
469 // from the wallpaper. This means we need to ensure the wallpaper is
470 // visible behind it in case it animates in a way that would allow it to be
471 // seen.
472 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700473 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700474 float mLastWallpaperX = -1;
475 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800476 float mLastWallpaperXStep = -1;
477 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700478 // This is set when we are waiting for a wallpaper to tell us it is done
479 // changing its scroll position.
480 WindowState mWaitingOnWallpaper;
481 // The last time we had a timeout when waiting for a wallpaper.
482 long mLastWallpaperTimeoutTime;
483 // We give a wallpaper up to 150ms to finish scrolling.
484 static final long WALLPAPER_TIMEOUT = 150;
485 // Time we wait after a timeout before trying to wait again.
486 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 AppWindowToken mFocusedApp = null;
489
490 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 float mWindowAnimationScale = 1.0f;
493 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700494
Jeff Brown46b9ac02010-04-22 18:58:52 -0700495 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496
497 // Who is holding the screen on.
498 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700499 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700500
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700501 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700504 * Drag/drop state
505 */
506 class DragState {
507 IBinder mToken;
508 Surface mSurface;
509 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700510 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700511 ClipData mData;
512 ClipDescription mDataDescription;
Chris Tated4533f12010-10-19 15:15:08 -0700513 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700514 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 float mThumbOffsetX, mThumbOffsetY;
516 InputChannel mServerChannel, mClientChannel;
517 WindowState mTargetWindow;
518 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700519 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700520
521 private final Rect tmpRect = new Rect();
522
Chris Tate7b362e42010-11-04 16:02:52 -0700523 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700524 mToken = token;
525 mSurface = surface;
526 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700527 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700528 mNotifiedWindows = new ArrayList<WindowState>();
529 }
530
531 void reset() {
532 if (mSurface != null) {
533 mSurface.destroy();
534 }
535 mSurface = null;
536 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700537 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700538 mToken = null;
539 mData = null;
540 mThumbOffsetX = mThumbOffsetY = 0;
541 mNotifiedWindows = null;
542 }
543
544 void register() {
545 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
546 if (mClientChannel != null) {
547 Slog.e(TAG, "Duplicate register of drag input channel");
548 } else {
549 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
550 mServerChannel = channels[0];
551 mClientChannel = channels[1];
552 mInputManager.registerInputChannel(mServerChannel);
553 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
554 mH.getLooper().getQueue());
555 }
556 }
557
558 void unregister() {
559 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
560 if (mClientChannel == null) {
561 Slog.e(TAG, "Unregister of nonexistent drag input channel");
562 } else {
563 mInputManager.unregisterInputChannel(mServerChannel);
564 InputQueue.unregisterInputChannel(mClientChannel);
565 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700566 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 mClientChannel = null;
568 mServerChannel = null;
569 }
570 }
571
Chris Tatea32dcf72010-10-14 12:13:50 -0700572 int getDragLayerLw() {
573 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
574 * TYPE_LAYER_MULTIPLIER
575 + TYPE_LAYER_OFFSET;
576 }
577
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 /* call out to each visible window/session informing it about the drag
579 */
Chris Tateb8203e92010-10-12 14:23:21 -0700580 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 // Cache a base-class instance of the clip metadata so that parceling
582 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700583 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700585 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700586
587 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700588 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
590
Christopher Tate2c095f32010-10-04 14:13:40 -0700591 final int N = mWindows.size();
592 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700593 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700594 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700595 }
596
597 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
598 * designated window is potentially a drop recipient. There are race situations
599 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
600 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700601 *
602 * This method clones the 'event' parameter if it's being delivered to the same
603 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700604 */
Chris Tateb478f462010-10-15 16:02:26 -0700605 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
606 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700607 // Don't actually send the event if the drag is supposed to be pinned
608 // to the originating window but 'newWin' is not that window.
609 if (mLocalOnly) {
610 final IBinder winBinder = newWin.mClient.asBinder();
611 if (winBinder != mLocalWin) {
612 if (DEBUG_DRAG) {
613 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
614 }
615 return;
616 }
617 }
618
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700619 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700620 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
621 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700622 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700623 try {
624 newWin.mClient.dispatchDragEvent(event);
625 // track each window that we've notified that the drag is starting
626 mNotifiedWindows.add(newWin);
627 } catch (RemoteException e) {
628 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700629 } finally {
630 // if the callee was local, the dispatch has already recycled the event
631 if (Process.myPid() != newWin.mSession.mPid) {
632 event.recycle();
633 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700634 }
635 }
636 }
637
638 /* helper - construct and send a DRAG_STARTED event only if the window has not
639 * previously been notified, i.e. it became visible after the drag operation
640 * was begun. This is a rare case.
641 */
642 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700643 if (mDragInProgress) {
644 // If we have sent the drag-started, we needn't do so again
645 for (WindowState ws : mNotifiedWindows) {
646 if (ws == newWin) {
647 return;
648 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700650 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700651 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700652 }
Chris Tateb478f462010-10-15 16:02:26 -0700653 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700654 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700655 }
656
Chris Tated4533f12010-10-19 15:15:08 -0700657 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700658 if (DEBUG_DRAG) {
659 Slog.d(TAG, "broadcasting DRAG_ENDED");
660 }
Chris Tated4533f12010-10-19 15:15:08 -0700661 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
662 0, 0, null, null, mDragResult);
663 for (WindowState ws: mNotifiedWindows) {
664 try {
665 ws.mClient.dispatchDragEvent(evt);
666 } catch (RemoteException e) {
667 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700668 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700669 }
Chris Tated4533f12010-10-19 15:15:08 -0700670 mNotifiedWindows.clear();
671 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 evt.recycle();
673 }
674
Chris Tated4533f12010-10-19 15:15:08 -0700675 void endDragLw() {
676 mDragState.broadcastDragEndedLw();
677
678 // stop intercepting input
679 mDragState.unregister();
680 mInputMonitor.updateInputWindowsLw();
681
682 // free our resources and drop all the object references
683 mDragState.reset();
684 mDragState = null;
685 }
686
Christopher Tatea53146c2010-09-07 11:57:52 -0700687 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700688 final int myPid = Process.myPid();
689
690 // Move the surface to the given touch
691 mSurface.openTransaction();
692 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
693 mSurface.closeTransaction();
694
695 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700696 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700697 if (mLocalOnly) {
698 final IBinder touchedBinder = touchedWin.mClient.asBinder();
699 if (touchedBinder != mLocalWin) {
700 // This drag is pinned only to the originating window, but the drag
701 // point is outside that window. Pretend it's over empty space.
702 touchedWin = null;
703 }
704 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700705 try {
706 // have we dragged over a new window?
707 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
708 if (DEBUG_DRAG) {
709 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
710 }
711 // force DRAG_EXITED_EVENT if appropriate
712 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700713 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700714 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700715 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700716 if (myPid != mTargetWindow.mSession.mPid) {
717 evt.recycle();
718 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700719 }
720 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700721 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700722 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
723 }
724 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700725 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700726 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700727 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700728 if (myPid != touchedWin.mSession.mPid) {
729 evt.recycle();
730 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700731 }
732 } catch (RemoteException e) {
733 Slog.w(TAG, "can't send drag notification to windows");
734 }
735 mTargetWindow = touchedWin;
736 }
737
Chris Tated4533f12010-10-19 15:15:08 -0700738 // Tell the drop target about the data. Returns 'true' if we can immediately
739 // dispatch the global drag-ended message, 'false' if we need to wait for a
740 // result from the recipient.
741 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700742 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f12010-10-19 15:15:08 -0700743 if (touchedWin == null) {
744 // "drop" outside a valid window -- no recipient to apply a
745 // timeout to, and we can send the drag-ended message immediately.
746 mDragResult = false;
747 return true;
748 }
749
750 if (DEBUG_DRAG) {
751 Slog.d(TAG, "sending DROP to " + touchedWin);
752 }
753 final int myPid = Process.myPid();
754 final IBinder token = touchedWin.mClient.asBinder();
755 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
756 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
757 null, mData, false);
758 try {
759 touchedWin.mClient.dispatchDragEvent(evt);
760
761 // 5 second timeout for this window to respond to the drop
762 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
763 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
764 mH.sendMessageDelayed(msg, 5000);
765 } catch (RemoteException e) {
766 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
767 return true;
768 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700769 if (myPid != touchedWin.mSession.mPid) {
770 evt.recycle();
771 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700772 }
Chris Tated4533f12010-10-19 15:15:08 -0700773 mToken = token;
774 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700775 }
776
777 // Find the visible, touch-deliverable window under the given point
778 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
779 WindowState touchedWin = null;
780 final int x = (int) xf;
781 final int y = (int) yf;
782 final ArrayList<WindowState> windows = mWindows;
783 final int N = windows.size();
784 for (int i = N - 1; i >= 0; i--) {
785 WindowState child = windows.get(i);
786 final int flags = child.mAttrs.flags;
787 if (!child.isVisibleLw()) {
788 // not visible == don't tell about drags
789 continue;
790 }
791 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
792 // not touchable == don't tell about drags
793 continue;
794 }
795 // account for the window's decor etc
796 tmpRect.set(child.mFrame);
797 if (child.mTouchableInsets == ViewTreeObserver
798 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
799 // The point is inside of the window if it is
800 // inside the frame, AND the content part of that
801 // frame that was given by the application.
802 tmpRect.left += child.mGivenContentInsets.left;
803 tmpRect.top += child.mGivenContentInsets.top;
804 tmpRect.right -= child.mGivenContentInsets.right;
805 tmpRect.bottom -= child.mGivenContentInsets.bottom;
806 } else if (child.mTouchableInsets == ViewTreeObserver
807 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
808 // The point is inside of the window if it is
809 // inside the frame, AND the visible part of that
810 // frame that was given by the application.
811 tmpRect.left += child.mGivenVisibleInsets.left;
812 tmpRect.top += child.mGivenVisibleInsets.top;
813 tmpRect.right -= child.mGivenVisibleInsets.right;
814 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
815 }
816 final int touchFlags = flags &
817 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
818 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
819 if (tmpRect.contains(x, y) || touchFlags == 0) {
820 // Found it
821 touchedWin = child;
822 break;
823 }
824 }
825
826 return touchedWin;
827 }
828 }
829
830 DragState mDragState = null;
831 private final InputHandler mDragInputHandler = new BaseInputHandler() {
832 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700833 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
834 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700835 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700836 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
837 && mDragState != null) {
838 boolean endDrag = false;
839 final float newX = event.getRawX();
840 final float newY = event.getRawY();
841
Christopher Tatea53146c2010-09-07 11:57:52 -0700842 switch (event.getAction()) {
843 case MotionEvent.ACTION_DOWN: {
844 if (DEBUG_DRAG) {
845 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
846 }
847 } break;
848
849 case MotionEvent.ACTION_MOVE: {
850 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700851 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700852 mDragState.notifyMoveLw(newX, newY);
853 }
854 } break;
855
856 case MotionEvent.ACTION_UP: {
857 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
858 + newX + "," + newY);
859 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700860 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700861 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700862 } break;
863
864 case MotionEvent.ACTION_CANCEL: {
865 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
866 endDrag = true;
867 } break;
868 }
869
870 if (endDrag) {
871 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
872 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700873 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700874 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700875 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700876 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700877
878 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700879 }
880 } catch (Exception e) {
881 Slog.e(TAG, "Exception caught by drag handleMotion", e);
882 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700883 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700884 }
885 }
886 };
887
888 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 * Whether the UI is currently running in touch mode (not showing
890 * navigational focus because the user is directly pressing the screen).
891 */
892 boolean mInTouchMode = false;
893
894 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700895 private ArrayList<WindowChangeListener> mWindowChangeListeners =
896 new ArrayList<WindowChangeListener>();
897 private boolean mWindowsChanged = false;
898
899 public interface WindowChangeListener {
900 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700901 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903
Dianne Hackbornc485a602009-03-24 22:39:49 -0700904 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700905 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700906
907 // The frame use to limit the size of the app running in compatibility mode.
908 Rect mCompatibleScreenFrame = new Rect();
909 // The surface used to fill the outer rim of the app running in compatibility mode.
910 Surface mBackgroundFillerSurface = null;
911 boolean mBackgroundFillerShown = false;
912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 public static WindowManagerService main(Context context,
914 PowerManagerService pm, boolean haveInputMethods) {
915 WMThread thr = new WMThread(context, pm, haveInputMethods);
916 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 synchronized (thr) {
919 while (thr.mService == null) {
920 try {
921 thr.wait();
922 } catch (InterruptedException e) {
923 }
924 }
925 }
Romain Guy06882f82009-06-10 13:36:04 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 return thr.mService;
928 }
Romain Guy06882f82009-06-10 13:36:04 -0700929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 static class WMThread extends Thread {
931 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 private final Context mContext;
934 private final PowerManagerService mPM;
935 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 public WMThread(Context context, PowerManagerService pm,
938 boolean haveInputMethods) {
939 super("WindowManager");
940 mContext = context;
941 mPM = pm;
942 mHaveInputMethods = haveInputMethods;
943 }
Romain Guy06882f82009-06-10 13:36:04 -0700944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 public void run() {
946 Looper.prepare();
947 WindowManagerService s = new WindowManagerService(mContext, mPM,
948 mHaveInputMethods);
949 android.os.Process.setThreadPriority(
950 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700951 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 synchronized (this) {
954 mService = s;
955 notifyAll();
956 }
Romain Guy06882f82009-06-10 13:36:04 -0700957
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700958 // For debug builds, log event loop stalls to dropbox for analysis.
959 if (StrictMode.conditionallyEnableDebugLogging()) {
960 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
961 }
962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 Looper.loop();
964 }
965 }
966
967 static class PolicyThread extends Thread {
968 private final WindowManagerPolicy mPolicy;
969 private final WindowManagerService mService;
970 private final Context mContext;
971 private final PowerManagerService mPM;
972 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 public PolicyThread(WindowManagerPolicy policy,
975 WindowManagerService service, Context context,
976 PowerManagerService pm) {
977 super("WindowManagerPolicy");
978 mPolicy = policy;
979 mService = service;
980 mContext = context;
981 mPM = pm;
982 }
Romain Guy06882f82009-06-10 13:36:04 -0700983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 public void run() {
985 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800986 WindowManagerPolicyThread.set(this, Looper.myLooper());
987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800989 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 android.os.Process.setThreadPriority(
991 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700992 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 synchronized (this) {
996 mRunning = true;
997 notifyAll();
998 }
Romain Guy06882f82009-06-10 13:36:04 -0700999
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001000 // For debug builds, log event loop stalls to dropbox for analysis.
1001 if (StrictMode.conditionallyEnableDebugLogging()) {
1002 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1003 }
1004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 Looper.loop();
1006 }
1007 }
1008
1009 private WindowManagerService(Context context, PowerManagerService pm,
1010 boolean haveInputMethods) {
1011 mContext = context;
1012 mHaveInputMethods = haveInputMethods;
1013 mLimitedAlphaCompositing = context.getResources().getBoolean(
1014 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 mPowerManager = pm;
1017 mPowerManager.setPolicy(mPolicy);
1018 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1019 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1020 "SCREEN_FROZEN");
1021 mScreenFrozenLock.setReferenceCounted(false);
1022
1023 mActivityManager = ActivityManagerNative.getDefault();
1024 mBatteryStats = BatteryStatsService.getService();
1025
1026 // Get persisted window scale setting
1027 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1028 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1029 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1030 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001031
Jim Miller284b62e2010-06-08 14:27:42 -07001032 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1033 IntentFilter filter = new IntentFilter();
1034 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1035 mContext.registerReceiver(mBroadcastReceiver, filter);
1036
Jeff Brown46b9ac02010-04-22 18:58:52 -07001037 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1038 "KEEP_SCREEN_ON_FLAG");
1039 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040
Jeff Browne33348b2010-07-15 23:54:05 -07001041 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1044 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 synchronized (thr) {
1047 while (!thr.mRunning) {
1048 try {
1049 thr.wait();
1050 } catch (InterruptedException e) {
1051 }
1052 }
1053 }
Romain Guy06882f82009-06-10 13:36:04 -07001054
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001055 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 // Add ourself to the Watchdog monitors.
1058 Watchdog.getInstance().addMonitor(this);
1059 }
1060
1061 @Override
1062 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1063 throws RemoteException {
1064 try {
1065 return super.onTransact(code, data, reply, flags);
1066 } catch (RuntimeException e) {
1067 // The window manager only throws security exceptions, so let's
1068 // log all others.
1069 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001070 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 }
1072 throw e;
1073 }
1074 }
1075
Jeff Browne33348b2010-07-15 23:54:05 -07001076 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001078 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 TAG, "Adding window " + window + " at "
1080 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1081 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001082 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 }
1084
Jeff Browne33348b2010-07-15 23:54:05 -07001085 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001087 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 TAG, "Adding window " + window + " at "
1089 + i + " of " + mWindows.size() + " (before " + pos + ")");
1090 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001091 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 }
1093
1094 //This method finds out the index of a window that has the same app token as
1095 //win. used for z ordering the windows in mWindows
1096 private int findIdxBasedOnAppTokens(WindowState win) {
1097 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001098 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 int jmax = localmWindows.size();
1100 if(jmax == 0) {
1101 return -1;
1102 }
1103 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001104 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 if(wentry.mAppToken == win.mAppToken) {
1106 return j;
1107 }
1108 }
1109 return -1;
1110 }
Romain Guy06882f82009-06-10 13:36:04 -07001111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1113 final IWindow client = win.mClient;
1114 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001115 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 final int N = localmWindows.size();
1118 final WindowState attached = win.mAttachedWindow;
1119 int i;
1120 if (attached == null) {
1121 int tokenWindowsPos = token.windows.size();
1122 if (token.appWindowToken != null) {
1123 int index = tokenWindowsPos-1;
1124 if (index >= 0) {
1125 // If this application has existing windows, we
1126 // simply place the new window on top of them... but
1127 // keep the starting window on top.
1128 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1129 // Base windows go behind everything else.
1130 placeWindowBefore(token.windows.get(0), win);
1131 tokenWindowsPos = 0;
1132 } else {
1133 AppWindowToken atoken = win.mAppToken;
1134 if (atoken != null &&
1135 token.windows.get(index) == atoken.startingWindow) {
1136 placeWindowBefore(token.windows.get(index), win);
1137 tokenWindowsPos--;
1138 } else {
1139 int newIdx = findIdxBasedOnAppTokens(win);
1140 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001141 //there is a window above this one associated with the same
1142 //apptoken note that the window could be a floating window
1143 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001145 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001146 TAG, "Adding window " + win + " at "
1147 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001149 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
1152 }
1153 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001154 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 TAG, "Figuring out where to add app window "
1156 + client.asBinder() + " (token=" + token + ")");
1157 // Figure out where the window should go, based on the
1158 // order of applications.
1159 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001160 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 for (i=NA-1; i>=0; i--) {
1162 AppWindowToken t = mAppTokens.get(i);
1163 if (t == token) {
1164 i--;
1165 break;
1166 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001167
Dianne Hackborna8f60182009-09-01 19:01:50 -07001168 // We haven't reached the token yet; if this token
1169 // is not going to the bottom and has windows, we can
1170 // use it as an anchor for when we do reach the token.
1171 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 pos = t.windows.get(0);
1173 }
1174 }
1175 // We now know the index into the apps. If we found
1176 // an app window above, that gives us the position; else
1177 // we need to look some more.
1178 if (pos != null) {
1179 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001180 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 if (atoken != null) {
1182 final int NC = atoken.windows.size();
1183 if (NC > 0) {
1184 WindowState bottom = atoken.windows.get(0);
1185 if (bottom.mSubLayer < 0) {
1186 pos = bottom;
1187 }
1188 }
1189 }
1190 placeWindowBefore(pos, win);
1191 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001192 // Continue looking down until we find the first
1193 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 while (i >= 0) {
1195 AppWindowToken t = mAppTokens.get(i);
1196 final int NW = t.windows.size();
1197 if (NW > 0) {
1198 pos = t.windows.get(NW-1);
1199 break;
1200 }
1201 i--;
1202 }
1203 if (pos != null) {
1204 // Move in front of any windows attached to this
1205 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001206 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 if (atoken != null) {
1208 final int NC = atoken.windows.size();
1209 if (NC > 0) {
1210 WindowState top = atoken.windows.get(NC-1);
1211 if (top.mSubLayer >= 0) {
1212 pos = top;
1213 }
1214 }
1215 }
1216 placeWindowAfter(pos, win);
1217 } else {
1218 // Just search for the start of this layer.
1219 final int myLayer = win.mBaseLayer;
1220 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001221 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 if (w.mBaseLayer > myLayer) {
1223 break;
1224 }
1225 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001226 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001227 TAG, "Adding window " + win + " at "
1228 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001230 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 }
1232 }
1233 }
1234 } else {
1235 // Figure out where window should go, based on layer.
1236 final int myLayer = win.mBaseLayer;
1237 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001238 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 i++;
1240 break;
1241 }
1242 }
1243 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001244 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001245 TAG, "Adding window " + win + " at "
1246 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001248 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 }
1250 if (addToToken) {
1251 token.windows.add(tokenWindowsPos, win);
1252 }
1253
1254 } else {
1255 // Figure out this window's ordering relative to the window
1256 // it is attached to.
1257 final int NA = token.windows.size();
1258 final int sublayer = win.mSubLayer;
1259 int largestSublayer = Integer.MIN_VALUE;
1260 WindowState windowWithLargestSublayer = null;
1261 for (i=0; i<NA; i++) {
1262 WindowState w = token.windows.get(i);
1263 final int wSublayer = w.mSubLayer;
1264 if (wSublayer >= largestSublayer) {
1265 largestSublayer = wSublayer;
1266 windowWithLargestSublayer = w;
1267 }
1268 if (sublayer < 0) {
1269 // For negative sublayers, we go below all windows
1270 // in the same sublayer.
1271 if (wSublayer >= sublayer) {
1272 if (addToToken) {
1273 token.windows.add(i, win);
1274 }
1275 placeWindowBefore(
1276 wSublayer >= 0 ? attached : w, win);
1277 break;
1278 }
1279 } else {
1280 // For positive sublayers, we go above all windows
1281 // in the same sublayer.
1282 if (wSublayer > sublayer) {
1283 if (addToToken) {
1284 token.windows.add(i, win);
1285 }
1286 placeWindowBefore(w, win);
1287 break;
1288 }
1289 }
1290 }
1291 if (i >= NA) {
1292 if (addToToken) {
1293 token.windows.add(win);
1294 }
1295 if (sublayer < 0) {
1296 placeWindowBefore(attached, win);
1297 } else {
1298 placeWindowAfter(largestSublayer >= 0
1299 ? windowWithLargestSublayer
1300 : attached,
1301 win);
1302 }
1303 }
1304 }
Romain Guy06882f82009-06-10 13:36:04 -07001305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 if (win.mAppToken != null && addToToken) {
1307 win.mAppToken.allAppWindows.add(win);
1308 }
1309 }
Romain Guy06882f82009-06-10 13:36:04 -07001310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 static boolean canBeImeTarget(WindowState w) {
1312 final int fl = w.mAttrs.flags
1313 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1314 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1315 return w.isVisibleOrAdding();
1316 }
1317 return false;
1318 }
Romain Guy06882f82009-06-10 13:36:04 -07001319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001321 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 final int N = localmWindows.size();
1323 WindowState w = null;
1324 int i = N;
1325 while (i > 0) {
1326 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001327 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001328
Joe Onorato8a9b2202010-02-26 18:56:32 -08001329 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 // + Integer.toHexString(w.mAttrs.flags));
1331 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001332 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 // Yet more tricksyness! If this window is a "starting"
1335 // window, we do actually want to be on top of it, but
1336 // it is not -really- where input will go. So if the caller
1337 // is not actually looking to move the IME, look down below
1338 // for a real window to target...
1339 if (!willMove
1340 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1341 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001342 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1344 i--;
1345 w = wb;
1346 }
1347 }
1348 break;
1349 }
1350 }
Romain Guy06882f82009-06-10 13:36:04 -07001351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001353
Joe Onorato8a9b2202010-02-26 18:56:32 -08001354 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001355 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001357 if (willMove && w != null) {
1358 final WindowState curTarget = mInputMethodTarget;
1359 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 // Now some fun for dealing with window animations that
1362 // modify the Z order. We need to look at all windows below
1363 // the current target that are in this app, finding the highest
1364 // visible one in layering.
1365 AppWindowToken token = curTarget.mAppToken;
1366 WindowState highestTarget = null;
1367 int highestPos = 0;
1368 if (token.animating || token.animation != null) {
1369 int pos = 0;
1370 pos = localmWindows.indexOf(curTarget);
1371 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001372 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 if (win.mAppToken != token) {
1374 break;
1375 }
1376 if (!win.mRemoved) {
1377 if (highestTarget == null || win.mAnimLayer >
1378 highestTarget.mAnimLayer) {
1379 highestTarget = win;
1380 highestPos = pos;
1381 }
1382 }
1383 pos--;
1384 }
1385 }
Romain Guy06882f82009-06-10 13:36:04 -07001386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001387 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001388 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 + mNextAppTransition + " " + highestTarget
1390 + " animating=" + highestTarget.isAnimating()
1391 + " layer=" + highestTarget.mAnimLayer
1392 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001393
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001394 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 // If we are currently setting up for an animation,
1396 // hold everything until we can find out what will happen.
1397 mInputMethodTargetWaitingAnim = true;
1398 mInputMethodTarget = highestTarget;
1399 return highestPos + 1;
1400 } else if (highestTarget.isAnimating() &&
1401 highestTarget.mAnimLayer > w.mAnimLayer) {
1402 // If the window we are currently targeting is involved
1403 // with an animation, and it is on top of the next target
1404 // we will be over, then hold off on moving until
1405 // that is done.
1406 mInputMethodTarget = highestTarget;
1407 return highestPos + 1;
1408 }
1409 }
1410 }
1411 }
Romain Guy06882f82009-06-10 13:36:04 -07001412
Joe Onorato8a9b2202010-02-26 18:56:32 -08001413 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 if (w != null) {
1415 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001416 if (DEBUG_INPUT_METHOD) {
1417 RuntimeException e = null;
1418 if (!HIDE_STACK_CRAWLS) {
1419 e = new RuntimeException();
1420 e.fillInStackTrace();
1421 }
1422 Slog.w(TAG, "Moving IM target from "
1423 + mInputMethodTarget + " to " + w, e);
1424 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 mInputMethodTarget = w;
1426 if (w.mAppToken != null) {
1427 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1428 } else {
1429 setInputMethodAnimLayerAdjustment(0);
1430 }
1431 }
1432 return i+1;
1433 }
1434 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001435 if (DEBUG_INPUT_METHOD) {
1436 RuntimeException e = null;
1437 if (!HIDE_STACK_CRAWLS) {
1438 e = new RuntimeException();
1439 e.fillInStackTrace();
1440 }
1441 Slog.w(TAG, "Moving IM target from "
1442 + mInputMethodTarget + " to null", e);
1443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 mInputMethodTarget = null;
1445 setInputMethodAnimLayerAdjustment(0);
1446 }
1447 return -1;
1448 }
Romain Guy06882f82009-06-10 13:36:04 -07001449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 void addInputMethodWindowToListLocked(WindowState win) {
1451 int pos = findDesiredInputMethodWindowIndexLocked(true);
1452 if (pos >= 0) {
1453 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001454 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001455 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001457 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 moveInputMethodDialogsLocked(pos+1);
1459 return;
1460 }
1461 win.mTargetAppToken = null;
1462 addWindowToListInOrderLocked(win, true);
1463 moveInputMethodDialogsLocked(pos);
1464 }
Romain Guy06882f82009-06-10 13:36:04 -07001465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 mInputMethodAnimLayerAdjustment = adj;
1469 WindowState imw = mInputMethodWindow;
1470 if (imw != null) {
1471 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001472 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 + " anim layer: " + imw.mAnimLayer);
1474 int wi = imw.mChildWindows.size();
1475 while (wi > 0) {
1476 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001477 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001479 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 + " anim layer: " + cw.mAnimLayer);
1481 }
1482 }
1483 int di = mInputMethodDialogs.size();
1484 while (di > 0) {
1485 di --;
1486 imw = mInputMethodDialogs.get(di);
1487 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001488 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 + " anim layer: " + imw.mAnimLayer);
1490 }
1491 }
Romain Guy06882f82009-06-10 13:36:04 -07001492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1494 int wpos = mWindows.indexOf(win);
1495 if (wpos >= 0) {
1496 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001497 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001499 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 int NC = win.mChildWindows.size();
1501 while (NC > 0) {
1502 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001503 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 int cpos = mWindows.indexOf(cw);
1505 if (cpos >= 0) {
1506 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001508 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 mWindows.remove(cpos);
1510 }
1511 }
1512 }
1513 return interestingPos;
1514 }
Romain Guy06882f82009-06-10 13:36:04 -07001515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 private void reAddWindowToListInOrderLocked(WindowState win) {
1517 addWindowToListInOrderLocked(win, false);
1518 // This is a hack to get all of the child windows added as well
1519 // at the right position. Child windows should be rare and
1520 // this case should be rare, so it shouldn't be that big a deal.
1521 int wpos = mWindows.indexOf(win);
1522 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001523 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001524 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001526 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 reAddWindowLocked(wpos, win);
1528 }
1529 }
Romain Guy06882f82009-06-10 13:36:04 -07001530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 void logWindowList(String prefix) {
1532 int N = mWindows.size();
1533 while (N > 0) {
1534 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001535 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 }
1537 }
Romain Guy06882f82009-06-10 13:36:04 -07001538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 void moveInputMethodDialogsLocked(int pos) {
1540 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 for (int i=0; i<N; i++) {
1545 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1546 }
1547 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001548 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 logWindowList(" ");
1550 }
Romain Guy06882f82009-06-10 13:36:04 -07001551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 if (pos >= 0) {
1553 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1554 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001555 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 if (wp == mInputMethodWindow) {
1557 pos++;
1558 }
1559 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 for (int i=0; i<N; i++) {
1562 WindowState win = dialogs.get(i);
1563 win.mTargetAppToken = targetAppToken;
1564 pos = reAddWindowLocked(pos, win);
1565 }
1566 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 logWindowList(" ");
1569 }
1570 return;
1571 }
1572 for (int i=0; i<N; i++) {
1573 WindowState win = dialogs.get(i);
1574 win.mTargetAppToken = null;
1575 reAddWindowToListInOrderLocked(win);
1576 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001577 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 logWindowList(" ");
1579 }
1580 }
1581 }
Romain Guy06882f82009-06-10 13:36:04 -07001582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1584 final WindowState imWin = mInputMethodWindow;
1585 final int DN = mInputMethodDialogs.size();
1586 if (imWin == null && DN == 0) {
1587 return false;
1588 }
Romain Guy06882f82009-06-10 13:36:04 -07001589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1591 if (imPos >= 0) {
1592 // In this case, the input method windows are to be placed
1593 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 // First check to see if the input method windows are already
1596 // located here, and contiguous.
1597 final int N = mWindows.size();
1598 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001599 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 // Figure out the actual input method window that should be
1602 // at the bottom of their stack.
1603 WindowState baseImWin = imWin != null
1604 ? imWin : mInputMethodDialogs.get(0);
1605 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001606 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 if (cw.mSubLayer < 0) baseImWin = cw;
1608 }
Romain Guy06882f82009-06-10 13:36:04 -07001609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 if (firstImWin == baseImWin) {
1611 // The windows haven't moved... but are they still contiguous?
1612 // First find the top IM window.
1613 int pos = imPos+1;
1614 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001615 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 break;
1617 }
1618 pos++;
1619 }
1620 pos++;
1621 // Now there should be no more input method windows above.
1622 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001623 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 break;
1625 }
1626 pos++;
1627 }
1628 if (pos >= N) {
1629 // All is good!
1630 return false;
1631 }
1632 }
Romain Guy06882f82009-06-10 13:36:04 -07001633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 if (imWin != null) {
1635 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001636 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 logWindowList(" ");
1638 }
1639 imPos = tmpRemoveWindowLocked(imPos, imWin);
1640 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001641 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 logWindowList(" ");
1643 }
1644 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1645 reAddWindowLocked(imPos, imWin);
1646 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001647 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 logWindowList(" ");
1649 }
1650 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1651 } else {
1652 moveInputMethodDialogsLocked(imPos);
1653 }
Romain Guy06882f82009-06-10 13:36:04 -07001654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 } else {
1656 // In this case, the input method windows go in a fixed layer,
1657 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001660 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 tmpRemoveWindowLocked(0, imWin);
1662 imWin.mTargetAppToken = null;
1663 reAddWindowToListInOrderLocked(imWin);
1664 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001665 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 logWindowList(" ");
1667 }
1668 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1669 } else {
1670 moveInputMethodDialogsLocked(-1);;
1671 }
Romain Guy06882f82009-06-10 13:36:04 -07001672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 }
Romain Guy06882f82009-06-10 13:36:04 -07001674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 if (needAssignLayers) {
1676 assignLayersLocked();
1677 }
Romain Guy06882f82009-06-10 13:36:04 -07001678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 return true;
1680 }
Romain Guy06882f82009-06-10 13:36:04 -07001681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 void adjustInputMethodDialogsLocked() {
1683 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1684 }
Romain Guy06882f82009-06-10 13:36:04 -07001685
Dianne Hackborn25994b42009-09-04 14:21:19 -07001686 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001687 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001688 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1689 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1690 ? wallpaperTarget.mAppToken.animation : null)
1691 + " upper=" + mUpperWallpaperTarget
1692 + " lower=" + mLowerWallpaperTarget);
1693 return (wallpaperTarget != null
1694 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1695 && wallpaperTarget.mAppToken.animation != null)))
1696 || mUpperWallpaperTarget != null
1697 || mLowerWallpaperTarget != null;
1698 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001699
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001700 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1701 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001702
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001703 int adjustWallpaperWindowsLocked() {
1704 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001706 final int dw = mDisplay.getWidth();
1707 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001709 // First find top-most window that has asked to be on top of the
1710 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001711 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001712 int N = localmWindows.size();
1713 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001714 WindowState foundW = null;
1715 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001716 WindowState topCurW = null;
1717 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001718 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001719 int i = N;
1720 while (i > 0) {
1721 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001722 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001723 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1724 if (topCurW == null) {
1725 topCurW = w;
1726 topCurI = i;
1727 }
1728 continue;
1729 }
1730 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001731 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001732 // If this window's app token is hidden and not animating,
1733 // it is of no interest to us.
1734 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001735 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001736 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001737 continue;
1738 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001739 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001740 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1742 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001743 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001744 && (mWallpaperTarget == w
1745 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001746 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001747 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001748 foundW = w;
1749 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001750 if (w == mWallpaperTarget && ((w.mAppToken != null
1751 && w.mAppToken.animation != null)
1752 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001753 // The current wallpaper target is animating, so we'll
1754 // look behind it for another possible target and figure
1755 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001756 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001757 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001758 continue;
1759 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001760 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001761 } else if (w == mWindowDetachedWallpaper) {
1762 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001763 }
1764 }
1765
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001766 if (foundW == null && windowDetachedI >= 0) {
1767 if (DEBUG_WALLPAPER) Slog.v(TAG,
1768 "Found animating detached wallpaper activity: #" + i + "=" + w);
1769 foundW = w;
1770 foundI = windowDetachedI;
1771 }
1772
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001773 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001774 // If we are currently waiting for an app transition, and either
1775 // the current target or the next target are involved with it,
1776 // then hold off on doing anything with the wallpaper.
1777 // Note that we are checking here for just whether the target
1778 // is part of an app token... which is potentially overly aggressive
1779 // (the app token may not be involved in the transition), but good
1780 // enough (we'll just wait until whatever transition is pending
1781 // executes).
1782 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001783 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001784 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001785 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001786 }
1787 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001788 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001789 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001790 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001791 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001792 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001793
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001794 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001795 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001796 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 + " oldTarget: " + mWallpaperTarget);
1798 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001799
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001800 mLowerWallpaperTarget = null;
1801 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001802
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001803 WindowState oldW = mWallpaperTarget;
1804 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001805
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 // Now what is happening... if the current and new targets are
1807 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001808 if (foundW != null && oldW != null) {
1809 boolean oldAnim = oldW.mAnimation != null
1810 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1811 boolean foundAnim = foundW.mAnimation != null
1812 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001813 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001814 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001815 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001816 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001817 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 int oldI = localmWindows.indexOf(oldW);
1819 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001820 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001821 }
1822 if (oldI >= 0) {
1823 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001824 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001825 + "=" + oldW + "; new#" + foundI
1826 + "=" + foundW);
1827 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001828
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001829 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001830 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001831 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001833 }
1834 mWallpaperTarget = oldW;
1835 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001836
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001837 // Now set the upper and lower wallpaper targets
1838 // correctly, and make sure that we are positioning
1839 // the wallpaper below the lower.
1840 if (foundI > oldI) {
1841 // The new target is on top of the old one.
1842 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001843 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001844 }
1845 mUpperWallpaperTarget = foundW;
1846 mLowerWallpaperTarget = oldW;
1847 foundW = oldW;
1848 foundI = oldI;
1849 } else {
1850 // The new target is below the old one.
1851 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001852 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001853 }
1854 mUpperWallpaperTarget = oldW;
1855 mLowerWallpaperTarget = foundW;
1856 }
1857 }
1858 }
1859 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001860
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001861 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001862 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001863 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1864 || (mLowerWallpaperTarget.mAppToken != null
1865 && mLowerWallpaperTarget.mAppToken.animation != null);
1866 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1867 || (mUpperWallpaperTarget.mAppToken != null
1868 && mUpperWallpaperTarget.mAppToken.animation != null);
1869 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001871 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001872 }
1873 mLowerWallpaperTarget = null;
1874 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001875 }
1876 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001877
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001878 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001879 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001880 // The window is visible to the compositor... but is it visible
1881 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001882 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001884
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001885 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001886 // its layer adjustment. Only do this if we are not transfering
1887 // between two wallpaper targets.
1888 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001889 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001890 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001891
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001892 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1893 * TYPE_LAYER_MULTIPLIER
1894 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001895
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001896 // Now w is the window we are supposed to be behind... but we
1897 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001898 // AND any starting window associated with it, AND below the
1899 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001900 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001901 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001902 if (wb.mBaseLayer < maxLayer &&
1903 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001904 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001905 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001906 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001907 // This window is not related to the previous one in any
1908 // interesting way, so stop here.
1909 break;
1910 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001911 foundW = wb;
1912 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001913 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001914 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001915 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001916 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001917
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001918 if (foundW == null && topCurW != null) {
1919 // There is no wallpaper target, so it goes at the bottom.
1920 // We will assume it is the same place as last time, if known.
1921 foundW = topCurW;
1922 foundI = topCurI+1;
1923 } else {
1924 // Okay i is the position immediately above the wallpaper. Look at
1925 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001926 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001927 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001928
Dianne Hackborn284ac932009-08-28 10:34:25 -07001929 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001930 if (mWallpaperTarget.mWallpaperX >= 0) {
1931 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001932 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001933 }
1934 if (mWallpaperTarget.mWallpaperY >= 0) {
1935 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001936 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001937 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001938 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001939
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001940 // Start stepping backwards from here, ensuring that our wallpaper windows
1941 // are correctly placed.
1942 int curTokenIndex = mWallpaperTokens.size();
1943 while (curTokenIndex > 0) {
1944 curTokenIndex--;
1945 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001946 if (token.hidden == visible) {
1947 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1948 token.hidden = !visible;
1949 // Need to do a layout to ensure the wallpaper now has the
1950 // correct size.
1951 mLayoutNeeded = true;
1952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001953
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001954 int curWallpaperIndex = token.windows.size();
1955 while (curWallpaperIndex > 0) {
1956 curWallpaperIndex--;
1957 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001958
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001959 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001960 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001961 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001962
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001963 // First, make sure the client has the current visibility
1964 // state.
1965 if (wallpaper.mWallpaperVisible != visible) {
1966 wallpaper.mWallpaperVisible = visible;
1967 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001968 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001969 "Setting visibility of wallpaper " + wallpaper
1970 + ": " + visible);
1971 wallpaper.mClient.dispatchAppVisibility(visible);
1972 } catch (RemoteException e) {
1973 }
1974 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001975
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001976 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001977 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001978 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001979
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001980 // First, if this window is at the current index, then all
1981 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001982 if (wallpaper == foundW) {
1983 foundI--;
1984 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001985 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001986 continue;
1987 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001989 // The window didn't match... the current wallpaper window,
1990 // wherever it is, is in the wrong place, so make sure it is
1991 // not in the list.
1992 int oldIndex = localmWindows.indexOf(wallpaper);
1993 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001994 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001995 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001996 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001997 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001998 if (oldIndex < foundI) {
1999 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002000 }
2001 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002002
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002003 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002004 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002005 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002006 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002007
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002008 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002009 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002010 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002011 }
2012 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002013
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002014 return changed;
2015 }
2016
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002017 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002018 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002019 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002020 mWallpaperAnimLayerAdjustment = adj;
2021 int curTokenIndex = mWallpaperTokens.size();
2022 while (curTokenIndex > 0) {
2023 curTokenIndex--;
2024 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2025 int curWallpaperIndex = token.windows.size();
2026 while (curWallpaperIndex > 0) {
2027 curWallpaperIndex--;
2028 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2029 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002030 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002031 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002032 }
2033 }
2034 }
2035
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002036 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2037 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002038 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002039 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002040 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002041 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002042 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2043 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2044 changed = wallpaperWin.mXOffset != offset;
2045 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002046 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002047 + wallpaperWin + " x: " + offset);
2048 wallpaperWin.mXOffset = offset;
2049 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002050 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002051 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002052 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002053 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002054 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002055
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002056 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002057 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002058 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2059 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2060 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002061 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002062 + wallpaperWin + " y: " + offset);
2063 changed = true;
2064 wallpaperWin.mYOffset = offset;
2065 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002066 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002067 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002068 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002069 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002070 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002071
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002072 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002073 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002074 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002075 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2076 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002077 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002078 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002079 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002080 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002081 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2082 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002083 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002084 if (mWaitingOnWallpaper != null) {
2085 long start = SystemClock.uptimeMillis();
2086 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2087 < start) {
2088 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002089 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002090 "Waiting for offset complete...");
2091 mWindowMap.wait(WALLPAPER_TIMEOUT);
2092 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002093 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002094 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002095 if ((start+WALLPAPER_TIMEOUT)
2096 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002097 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002098 + wallpaperWin);
2099 mLastWallpaperTimeoutTime = start;
2100 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002101 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002102 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002103 }
2104 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002105 } catch (RemoteException e) {
2106 }
2107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002108
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002109 return changed;
2110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002111
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002112 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002113 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002114 if (mWaitingOnWallpaper != null &&
2115 mWaitingOnWallpaper.mClient.asBinder() == window) {
2116 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002117 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002118 }
2119 }
2120 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002121
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002122 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002123 final int dw = mDisplay.getWidth();
2124 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002125
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002126 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002127
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002128 WindowState target = mWallpaperTarget;
2129 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002130 if (target.mWallpaperX >= 0) {
2131 mLastWallpaperX = target.mWallpaperX;
2132 } else if (changingTarget.mWallpaperX >= 0) {
2133 mLastWallpaperX = changingTarget.mWallpaperX;
2134 }
2135 if (target.mWallpaperY >= 0) {
2136 mLastWallpaperY = target.mWallpaperY;
2137 } else if (changingTarget.mWallpaperY >= 0) {
2138 mLastWallpaperY = changingTarget.mWallpaperY;
2139 }
2140 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002141
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002142 int curTokenIndex = mWallpaperTokens.size();
2143 while (curTokenIndex > 0) {
2144 curTokenIndex--;
2145 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2146 int curWallpaperIndex = token.windows.size();
2147 while (curWallpaperIndex > 0) {
2148 curWallpaperIndex--;
2149 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2150 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2151 wallpaper.computeShownFrameLocked();
2152 changed = true;
2153 // We only want to be synchronous with one wallpaper.
2154 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002155 }
2156 }
2157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002158
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002159 return changed;
2160 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002161
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002162 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002163 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002164 final int dw = mDisplay.getWidth();
2165 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002166
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002167 int curTokenIndex = mWallpaperTokens.size();
2168 while (curTokenIndex > 0) {
2169 curTokenIndex--;
2170 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002171 if (token.hidden == visible) {
2172 token.hidden = !visible;
2173 // Need to do a layout to ensure the wallpaper now has the
2174 // correct size.
2175 mLayoutNeeded = true;
2176 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002177
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002178 int curWallpaperIndex = token.windows.size();
2179 while (curWallpaperIndex > 0) {
2180 curWallpaperIndex--;
2181 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2182 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002183 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002184 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002185
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002186 if (wallpaper.mWallpaperVisible != visible) {
2187 wallpaper.mWallpaperVisible = visible;
2188 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002189 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002190 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002191 + ": " + visible);
2192 wallpaper.mClient.dispatchAppVisibility(visible);
2193 } catch (RemoteException e) {
2194 }
2195 }
2196 }
2197 }
2198 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002200 public int addWindow(Session session, IWindow client,
2201 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07002202 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 int res = mPolicy.checkAddPermission(attrs);
2204 if (res != WindowManagerImpl.ADD_OKAY) {
2205 return res;
2206 }
Romain Guy06882f82009-06-10 13:36:04 -07002207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 boolean reportNewConfig = false;
2209 WindowState attachedWindow = null;
2210 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002211 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002215 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 }
Romain Guy06882f82009-06-10 13:36:04 -07002217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002219 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2221 }
2222
2223 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002224 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002226 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 + attrs.token + ". Aborting.");
2228 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2229 }
2230 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2231 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002232 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233 + attrs.token + ". Aborting.");
2234 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2235 }
2236 }
2237
2238 boolean addToken = false;
2239 WindowToken token = mTokenMap.get(attrs.token);
2240 if (token == null) {
2241 if (attrs.type >= FIRST_APPLICATION_WINDOW
2242 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002243 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 + attrs.token + ". Aborting.");
2245 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2246 }
2247 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002248 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 + attrs.token + ". Aborting.");
2250 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2251 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002252 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002253 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002254 + attrs.token + ". Aborting.");
2255 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 token = new WindowToken(attrs.token, -1, false);
2258 addToken = true;
2259 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2260 && attrs.type <= LAST_APPLICATION_WINDOW) {
2261 AppWindowToken atoken = token.appWindowToken;
2262 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002263 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 + token + ". Aborting.");
2265 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2266 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002267 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 + token + ". Aborting.");
2269 return WindowManagerImpl.ADD_APP_EXITING;
2270 }
2271 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2272 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002273 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002274 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2275 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2276 }
2277 } else if (attrs.type == TYPE_INPUT_METHOD) {
2278 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002279 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 + attrs.token + ". Aborting.");
2281 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2282 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002283 } else if (attrs.type == TYPE_WALLPAPER) {
2284 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002285 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002286 + attrs.token + ". Aborting.");
2287 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2288 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 }
2290
2291 win = new WindowState(session, client, token,
2292 attachedWindow, attrs, viewVisibility);
2293 if (win.mDeathRecipient == null) {
2294 // Client has apparently died, so there is no reason to
2295 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002296 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 + " that is dead, aborting.");
2298 return WindowManagerImpl.ADD_APP_EXITING;
2299 }
2300
2301 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 res = mPolicy.prepareAddWindowLw(win, attrs);
2304 if (res != WindowManagerImpl.ADD_OKAY) {
2305 return res;
2306 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002307
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002308 if (outInputChannel != null) {
2309 String name = win.makeInputChannelName();
2310 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2311 win.mInputChannel = inputChannels[0];
2312 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2313
2314 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316
2317 // From now on, no exceptions or errors allowed!
2318
2319 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002320
Dianne Hackborn5132b372010-07-29 12:51:35 -07002321 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 if (addToken) {
2324 mTokenMap.put(attrs.token, token);
2325 mTokenList.add(token);
2326 }
2327 win.attach();
2328 mWindowMap.put(client.asBinder(), win);
2329
2330 if (attrs.type == TYPE_APPLICATION_STARTING &&
2331 token.appWindowToken != null) {
2332 token.appWindowToken.startingWindow = win;
2333 }
2334
2335 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 if (attrs.type == TYPE_INPUT_METHOD) {
2338 mInputMethodWindow = win;
2339 addInputMethodWindowToListLocked(win);
2340 imMayMove = false;
2341 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2342 mInputMethodDialogs.add(win);
2343 addWindowToListInOrderLocked(win, true);
2344 adjustInputMethodDialogsLocked();
2345 imMayMove = false;
2346 } else {
2347 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002348 if (attrs.type == TYPE_WALLPAPER) {
2349 mLastWallpaperTimeoutTime = 0;
2350 adjustWallpaperWindowsLocked();
2351 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002352 adjustWallpaperWindowsLocked();
2353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 }
Romain Guy06882f82009-06-10 13:36:04 -07002355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 if (mInTouchMode) {
2361 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2362 }
2363 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2364 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2365 }
Romain Guy06882f82009-06-10 13:36:04 -07002366
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002367 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002369 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2370 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 imMayMove = false;
2372 }
2373 }
Romain Guy06882f82009-06-10 13:36:04 -07002374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002376 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 }
Romain Guy06882f82009-06-10 13:36:04 -07002378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002379 assignLayersLocked();
2380 // Don't do layout here, the window must call
2381 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 //dump();
2384
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002385 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002386 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002387 }
Jeff Brown349703e2010-06-22 01:27:15 -07002388
Joe Onorato8a9b2202010-02-26 18:56:32 -08002389 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 TAG, "New client " + client.asBinder()
2391 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002392
2393 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2394 reportNewConfig = true;
2395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 }
2397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 if (reportNewConfig) {
2399 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 return res;
2405 }
Romain Guy06882f82009-06-10 13:36:04 -07002406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 public void removeWindow(Session session, IWindow client) {
2408 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002409 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 if (win == null) {
2411 return;
2412 }
2413 removeWindowLocked(session, win);
2414 }
2415 }
Romain Guy06882f82009-06-10 13:36:04 -07002416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 public void removeWindowLocked(Session session, WindowState win) {
2418
Joe Onorato8a9b2202010-02-26 18:56:32 -08002419 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 TAG, "Remove " + win + " client="
2421 + Integer.toHexString(System.identityHashCode(
2422 win.mClient.asBinder()))
2423 + ", surface=" + win.mSurface);
2424
2425 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002426
2427 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002428
Joe Onorato8a9b2202010-02-26 18:56:32 -08002429 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2431 + " mExiting=" + win.mExiting
2432 + " isAnimating=" + win.isAnimating()
2433 + " app-animation="
2434 + (win.mAppToken != null ? win.mAppToken.animation : null)
2435 + " inPendingTransaction="
2436 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2437 + " mDisplayFrozen=" + mDisplayFrozen);
2438 // Visibility of the removed window. Will be used later to update orientation later on.
2439 boolean wasVisible = false;
2440 // First, see if we need to run an animation. If we do, we have
2441 // to hold off on removing the window until the animation is done.
2442 // If the display is frozen, just remove immediately, since the
2443 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002444 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 // If we are not currently running the exit animation, we
2446 // need to see about starting one.
2447 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2450 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2451 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2452 }
2453 // Try starting an animation.
2454 if (applyAnimationLocked(win, transit, false)) {
2455 win.mExiting = true;
2456 }
2457 }
2458 if (win.mExiting || win.isAnimating()) {
2459 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002460 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 win.mExiting = true;
2462 win.mRemoveOnExit = true;
2463 mLayoutNeeded = true;
2464 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2465 performLayoutAndPlaceSurfacesLocked();
2466 if (win.mAppToken != null) {
2467 win.mAppToken.updateReportedVisibilityLocked();
2468 }
2469 //dump();
2470 Binder.restoreCallingIdentity(origId);
2471 return;
2472 }
2473 }
2474
2475 removeWindowInnerLocked(session, win);
2476 // Removing a visible window will effect the computed orientation
2477 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002478 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002479 != mForcedAppOrientation
2480 && updateOrientationFromAppTokensLocked()) {
2481 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 }
2483 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2484 Binder.restoreCallingIdentity(origId);
2485 }
Romain Guy06882f82009-06-10 13:36:04 -07002486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 if (mInputMethodTarget == win) {
2491 moveInputMethodWindowsIfNeededLocked(false);
2492 }
Romain Guy06882f82009-06-10 13:36:04 -07002493
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002494 if (false) {
2495 RuntimeException e = new RuntimeException("here");
2496 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002497 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002498 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 mPolicy.removeWindowLw(win);
2501 win.removeLocked();
2502
2503 mWindowMap.remove(win.mClient.asBinder());
2504 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002505 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002506 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507
2508 if (mInputMethodWindow == win) {
2509 mInputMethodWindow = null;
2510 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2511 mInputMethodDialogs.remove(win);
2512 }
Romain Guy06882f82009-06-10 13:36:04 -07002513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 final WindowToken token = win.mToken;
2515 final AppWindowToken atoken = win.mAppToken;
2516 token.windows.remove(win);
2517 if (atoken != null) {
2518 atoken.allAppWindows.remove(win);
2519 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002520 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 TAG, "**** Removing window " + win + ": count="
2522 + token.windows.size());
2523 if (token.windows.size() == 0) {
2524 if (!token.explicit) {
2525 mTokenMap.remove(token.token);
2526 mTokenList.remove(token);
2527 } else if (atoken != null) {
2528 atoken.firstWindowDrawn = false;
2529 }
2530 }
2531
2532 if (atoken != null) {
2533 if (atoken.startingWindow == win) {
2534 atoken.startingWindow = null;
2535 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2536 // If this is the last window and we had requested a starting
2537 // transition window, well there is no point now.
2538 atoken.startingData = null;
2539 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2540 // If this is the last window except for a starting transition
2541 // window, we need to get rid of the starting transition.
2542 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002543 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 + ": no more real windows");
2545 }
2546 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2547 mH.sendMessage(m);
2548 }
2549 }
Romain Guy06882f82009-06-10 13:36:04 -07002550
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002551 if (win.mAttrs.type == TYPE_WALLPAPER) {
2552 mLastWallpaperTimeoutTime = 0;
2553 adjustWallpaperWindowsLocked();
2554 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002555 adjustWallpaperWindowsLocked();
2556 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 if (!mInLayout) {
2559 assignLayersLocked();
2560 mLayoutNeeded = true;
2561 performLayoutAndPlaceSurfacesLocked();
2562 if (win.mAppToken != null) {
2563 win.mAppToken.updateReportedVisibilityLocked();
2564 }
2565 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002566
2567 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 }
2569
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002570 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2571 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2572 + ": " + msg + " / " + w.mAttrs.getTitle();
2573 if (where != null) {
2574 Slog.i(TAG, str, where);
2575 } else {
2576 Slog.i(TAG, str);
2577 }
2578 }
2579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2581 long origId = Binder.clearCallingIdentity();
2582 try {
2583 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002584 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002586 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 Surface.openTransaction();
2588 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002589 if (SHOW_TRANSACTIONS) logSurface(w,
2590 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 w.mSurface.setTransparentRegionHint(region);
2592 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002593 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 Surface.closeTransaction();
2595 }
2596 }
2597 }
2598 } finally {
2599 Binder.restoreCallingIdentity(origId);
2600 }
2601 }
2602
2603 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002604 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 Rect visibleInsets) {
2606 long origId = Binder.clearCallingIdentity();
2607 try {
2608 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002609 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 if (w != null) {
2611 w.mGivenInsetsPending = false;
2612 w.mGivenContentInsets.set(contentInsets);
2613 w.mGivenVisibleInsets.set(visibleInsets);
2614 w.mTouchableInsets = touchableInsets;
2615 mLayoutNeeded = true;
2616 performLayoutAndPlaceSurfacesLocked();
2617 }
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(origId);
2621 }
2622 }
Romain Guy06882f82009-06-10 13:36:04 -07002623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 public void getWindowDisplayFrame(Session session, IWindow client,
2625 Rect outDisplayFrame) {
2626 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002627 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 if (win == null) {
2629 outDisplayFrame.setEmpty();
2630 return;
2631 }
2632 outDisplayFrame.set(win.mDisplayFrame);
2633 }
2634 }
2635
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002636 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2637 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002638 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2639 window.mWallpaperX = x;
2640 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002641 window.mWallpaperXStep = xStep;
2642 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002643 if (updateWallpaperOffsetLocked(window, true)) {
2644 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002645 }
2646 }
2647 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002648
Dianne Hackborn75804932009-10-20 20:15:20 -07002649 void wallpaperCommandComplete(IBinder window, Bundle result) {
2650 synchronized (mWindowMap) {
2651 if (mWaitingOnWallpaper != null &&
2652 mWaitingOnWallpaper.mClient.asBinder() == window) {
2653 mWaitingOnWallpaper = null;
2654 mWindowMap.notifyAll();
2655 }
2656 }
2657 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002658
Dianne Hackborn75804932009-10-20 20:15:20 -07002659 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2660 String action, int x, int y, int z, Bundle extras, boolean sync) {
2661 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2662 || window == mUpperWallpaperTarget) {
2663 boolean doWait = sync;
2664 int curTokenIndex = mWallpaperTokens.size();
2665 while (curTokenIndex > 0) {
2666 curTokenIndex--;
2667 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2668 int curWallpaperIndex = token.windows.size();
2669 while (curWallpaperIndex > 0) {
2670 curWallpaperIndex--;
2671 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2672 try {
2673 wallpaper.mClient.dispatchWallpaperCommand(action,
2674 x, y, z, extras, sync);
2675 // We only want to be synchronous with one wallpaper.
2676 sync = false;
2677 } catch (RemoteException e) {
2678 }
2679 }
2680 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002681
Dianne Hackborn75804932009-10-20 20:15:20 -07002682 if (doWait) {
2683 // XXX Need to wait for result.
2684 }
2685 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002686
Dianne Hackborn75804932009-10-20 20:15:20 -07002687 return null;
2688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 public int relayoutWindow(Session session, IWindow client,
2691 WindowManager.LayoutParams attrs, int requestedWidth,
2692 int requestedHeight, int viewVisibility, boolean insetsPending,
2693 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002694 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 boolean displayed = false;
2696 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002697 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002701 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 if (win == null) {
2703 return 0;
2704 }
2705 win.mRequestedWidth = requestedWidth;
2706 win.mRequestedHeight = requestedHeight;
2707
2708 if (attrs != null) {
2709 mPolicy.adjustWindowParamsLw(attrs);
2710 }
Romain Guy06882f82009-06-10 13:36:04 -07002711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 int attrChanges = 0;
2713 int flagChanges = 0;
2714 if (attrs != null) {
2715 flagChanges = win.mAttrs.flags ^= attrs.flags;
2716 attrChanges = win.mAttrs.copyFrom(attrs);
2717 }
2718
Joe Onorato8a9b2202010-02-26 18:56:32 -08002719 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002720
2721 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2722 win.mAlpha = attrs.alpha;
2723 }
2724
2725 final boolean scaledWindow =
2726 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2727
2728 if (scaledWindow) {
2729 // requested{Width|Height} Surface's physical size
2730 // attrs.{width|height} Size on screen
2731 win.mHScale = (attrs.width != requestedWidth) ?
2732 (attrs.width / (float)requestedWidth) : 1.0f;
2733 win.mVScale = (attrs.height != requestedHeight) ?
2734 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002735 } else {
2736 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 }
2738
2739 boolean imMayMove = (flagChanges&(
2740 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2741 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 boolean focusMayChange = win.mViewVisibility != viewVisibility
2744 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2745 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002746
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002747 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2748 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 win.mRelayoutCalled = true;
2751 final int oldVisibility = win.mViewVisibility;
2752 win.mViewVisibility = viewVisibility;
2753 if (viewVisibility == View.VISIBLE &&
2754 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2755 displayed = !win.isVisibleLw();
2756 if (win.mExiting) {
2757 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002758 if (win.mAnimation != null) {
2759 win.mAnimation.cancel();
2760 win.mAnimation = null;
2761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 }
2763 if (win.mDestroying) {
2764 win.mDestroying = false;
2765 mDestroySurface.remove(win);
2766 }
2767 if (oldVisibility == View.GONE) {
2768 win.mEnterAnimationPending = true;
2769 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002770 if (displayed) {
2771 if (win.mSurface != null && !win.mDrawPending
2772 && !win.mCommitDrawPending && !mDisplayFrozen
2773 && mPolicy.isScreenOn()) {
2774 applyEnterAnimationLocked(win);
2775 }
2776 if ((win.mAttrs.flags
2777 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2778 if (DEBUG_VISIBILITY) Slog.v(TAG,
2779 "Relayout window turning screen on: " + win);
2780 win.mTurnOnScreen = true;
2781 }
2782 int diff = 0;
2783 if (win.mConfiguration != mCurConfiguration
2784 && (win.mConfiguration == null
2785 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2786 win.mConfiguration = mCurConfiguration;
2787 if (DEBUG_CONFIGURATION) {
2788 Slog.i(TAG, "Window " + win + " visible with new config: "
2789 + win.mConfiguration + " / 0x"
2790 + Integer.toHexString(diff));
2791 }
2792 outConfig.setTo(mCurConfiguration);
2793 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2796 // To change the format, we need to re-build the surface.
2797 win.destroySurfaceLocked();
2798 displayed = true;
2799 }
2800 try {
2801 Surface surface = win.createSurfaceLocked();
2802 if (surface != null) {
2803 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002804 win.mReportDestroySurface = false;
2805 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002806 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002807 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002809 // For some reason there isn't a surface. Clear the
2810 // caller's object so they see the same state.
2811 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 }
2813 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002814 mInputMonitor.updateInputWindowsLw();
2815
Joe Onorato8a9b2202010-02-26 18:56:32 -08002816 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002817 + client + " (" + win.mAttrs.getTitle() + ")",
2818 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 Binder.restoreCallingIdentity(origId);
2820 return 0;
2821 }
2822 if (displayed) {
2823 focusMayChange = true;
2824 }
2825 if (win.mAttrs.type == TYPE_INPUT_METHOD
2826 && mInputMethodWindow == null) {
2827 mInputMethodWindow = win;
2828 imMayMove = true;
2829 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002830 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2831 && win.mAppToken != null
2832 && win.mAppToken.startingWindow != null) {
2833 // Special handling of starting window over the base
2834 // window of the app: propagate lock screen flags to it,
2835 // to provide the correct semantics while starting.
2836 final int mask =
2837 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002838 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2839 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002840 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2841 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2842 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 } else {
2844 win.mEnterAnimationPending = false;
2845 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002846 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002847 + ": mExiting=" + win.mExiting
2848 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 // If we are not currently running the exit animation, we
2850 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002851 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 // Try starting an animation; if there isn't one, we
2853 // can destroy the surface right away.
2854 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2855 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2856 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2857 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002858 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002860 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 } else if (win.isAnimating()) {
2863 // Currently in a hide animation... turn this into
2864 // an exit.
2865 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002866 } else if (win == mWallpaperTarget) {
2867 // If the wallpaper is currently behind this
2868 // window, we need to change both of them inside
2869 // of a transaction to avoid artifacts.
2870 win.mExiting = true;
2871 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 } else {
2873 if (mInputMethodWindow == win) {
2874 mInputMethodWindow = null;
2875 }
2876 win.destroySurfaceLocked();
2877 }
2878 }
2879 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002880
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002881 if (win.mSurface == null || (win.getAttrs().flags
2882 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2883 || win.mSurfacePendingDestroy) {
2884 // We are being called from a local process, which
2885 // means outSurface holds its current surface. Ensure the
2886 // surface object is cleared, but we don't want it actually
2887 // destroyed at this point.
2888 win.mSurfacePendingDestroy = false;
2889 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002890 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002891 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002892 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002893 "Keeping surface, will report destroy: " + win);
2894 win.mReportDestroySurface = true;
2895 outSurface.copyFrom(win.mSurface);
2896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 }
2898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 if (focusMayChange) {
2900 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2901 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 imMayMove = false;
2903 }
2904 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2905 }
Romain Guy06882f82009-06-10 13:36:04 -07002906
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002907 // updateFocusedWindowLocked() already assigned layers so we only need to
2908 // reassign them at this point if the IM window state gets shuffled
2909 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002912 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2913 // Little hack here -- we -should- be able to rely on the
2914 // function to return true if the IME has moved and needs
2915 // its layer recomputed. However, if the IME was hidden
2916 // and isn't actually moved in the list, its layer may be
2917 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 assignLayers = true;
2919 }
2920 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002921 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002922 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002923 assignLayers = true;
2924 }
2925 }
Romain Guy06882f82009-06-10 13:36:04 -07002926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 mLayoutNeeded = true;
2928 win.mGivenInsetsPending = insetsPending;
2929 if (assignLayers) {
2930 assignLayersLocked();
2931 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002932 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002934 if (displayed && win.mIsWallpaper) {
2935 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002936 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 if (win.mAppToken != null) {
2939 win.mAppToken.updateReportedVisibilityLocked();
2940 }
2941 outFrame.set(win.mFrame);
2942 outContentInsets.set(win.mContentInsets);
2943 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002944 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002946 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 + ", requestedHeight=" + requestedHeight
2948 + ", viewVisibility=" + viewVisibility
2949 + "\nRelayout returning frame=" + outFrame
2950 + ", surface=" + outSurface);
2951
Joe Onorato8a9b2202010-02-26 18:56:32 -08002952 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2954
2955 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002956
2957 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 }
2959
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002960 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 sendNewConfiguration();
2962 }
Romain Guy06882f82009-06-10 13:36:04 -07002963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2967 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2968 }
2969
2970 public void finishDrawingWindow(Session session, IWindow client) {
2971 final long origId = Binder.clearCallingIdentity();
2972 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002973 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002975 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2976 adjustWallpaperWindowsLocked();
2977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 mLayoutNeeded = true;
2979 performLayoutAndPlaceSurfacesLocked();
2980 }
2981 }
2982 Binder.restoreCallingIdentity(origId);
2983 }
2984
2985 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002986 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 + (lp != null ? lp.packageName : null)
2988 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2989 if (lp != null && lp.windowAnimations != 0) {
2990 // If this is a system resource, don't try to load it from the
2991 // application resources. It is nice to avoid loading application
2992 // resources if we can.
2993 String packageName = lp.packageName != null ? lp.packageName : "android";
2994 int resId = lp.windowAnimations;
2995 if ((resId&0xFF000000) == 0x01000000) {
2996 packageName = "android";
2997 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002998 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 + packageName);
3000 return AttributeCache.instance().get(packageName, resId,
3001 com.android.internal.R.styleable.WindowAnimation);
3002 }
3003 return null;
3004 }
Romain Guy06882f82009-06-10 13:36:04 -07003005
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003006 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003007 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003008 + packageName + " resId=0x" + Integer.toHexString(resId));
3009 if (packageName != null) {
3010 if ((resId&0xFF000000) == 0x01000000) {
3011 packageName = "android";
3012 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003013 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003014 + packageName);
3015 return AttributeCache.instance().get(packageName, resId,
3016 com.android.internal.R.styleable.WindowAnimation);
3017 }
3018 return null;
3019 }
3020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 private void applyEnterAnimationLocked(WindowState win) {
3022 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3023 if (win.mEnterAnimationPending) {
3024 win.mEnterAnimationPending = false;
3025 transit = WindowManagerPolicy.TRANSIT_ENTER;
3026 }
3027
3028 applyAnimationLocked(win, transit, true);
3029 }
3030
3031 private boolean applyAnimationLocked(WindowState win,
3032 int transit, boolean isEntrance) {
3033 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3034 // If we are trying to apply an animation, but already running
3035 // an animation of the same type, then just leave that one alone.
3036 return true;
3037 }
Romain Guy06882f82009-06-10 13:36:04 -07003038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 // Only apply an animation if the display isn't frozen. If it is
3040 // frozen, there is no reason to animate and it can cause strange
3041 // artifacts when we unfreeze the display if some different animation
3042 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003043 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003044 int anim = mPolicy.selectAnimationLw(win, transit);
3045 int attr = -1;
3046 Animation a = null;
3047 if (anim != 0) {
3048 a = AnimationUtils.loadAnimation(mContext, anim);
3049 } else {
3050 switch (transit) {
3051 case WindowManagerPolicy.TRANSIT_ENTER:
3052 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3053 break;
3054 case WindowManagerPolicy.TRANSIT_EXIT:
3055 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3056 break;
3057 case WindowManagerPolicy.TRANSIT_SHOW:
3058 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3059 break;
3060 case WindowManagerPolicy.TRANSIT_HIDE:
3061 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3062 break;
3063 }
3064 if (attr >= 0) {
3065 a = loadAnimation(win.mAttrs, attr);
3066 }
3067 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003068 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003069 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3070 + " mAnimation=" + win.mAnimation
3071 + " isEntrance=" + isEntrance);
3072 if (a != null) {
3073 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003074 RuntimeException e = null;
3075 if (!HIDE_STACK_CRAWLS) {
3076 e = new RuntimeException();
3077 e.fillInStackTrace();
3078 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003079 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 }
3081 win.setAnimation(a);
3082 win.mAnimationIsEntrance = isEntrance;
3083 }
3084 } else {
3085 win.clearAnimation();
3086 }
3087
3088 return win.mAnimation != null;
3089 }
3090
3091 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3092 int anim = 0;
3093 Context context = mContext;
3094 if (animAttr >= 0) {
3095 AttributeCache.Entry ent = getCachedAnimations(lp);
3096 if (ent != null) {
3097 context = ent.context;
3098 anim = ent.array.getResourceId(animAttr, 0);
3099 }
3100 }
3101 if (anim != 0) {
3102 return AnimationUtils.loadAnimation(context, anim);
3103 }
3104 return null;
3105 }
Romain Guy06882f82009-06-10 13:36:04 -07003106
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003107 private Animation loadAnimation(String packageName, int resId) {
3108 int anim = 0;
3109 Context context = mContext;
3110 if (resId >= 0) {
3111 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3112 if (ent != null) {
3113 context = ent.context;
3114 anim = resId;
3115 }
3116 }
3117 if (anim != 0) {
3118 return AnimationUtils.loadAnimation(context, anim);
3119 }
3120 return null;
3121 }
3122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 private boolean applyAnimationLocked(AppWindowToken wtoken,
3124 WindowManager.LayoutParams lp, int transit, boolean enter) {
3125 // Only apply an animation if the display isn't frozen. If it is
3126 // frozen, there is no reason to animate and it can cause strange
3127 // artifacts when we unfreeze the display if some different animation
3128 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003129 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003130 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003131 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003132 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003133 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003134 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003135 } else if (mNextAppTransitionPackage != null) {
3136 a = loadAnimation(mNextAppTransitionPackage, enter ?
3137 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003138 } else {
3139 int animAttr = 0;
3140 switch (transit) {
3141 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3142 animAttr = enter
3143 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3144 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3145 break;
3146 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3147 animAttr = enter
3148 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3149 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3150 break;
3151 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3152 animAttr = enter
3153 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3154 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3155 break;
3156 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3157 animAttr = enter
3158 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3159 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3160 break;
3161 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3162 animAttr = enter
3163 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3164 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3165 break;
3166 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3167 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003168 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003169 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3170 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003171 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003172 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003173 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3174 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003175 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003176 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003177 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003178 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3179 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3180 break;
3181 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3182 animAttr = enter
3183 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3184 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3185 break;
3186 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3187 animAttr = enter
3188 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3189 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003190 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003191 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003192 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003193 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003194 + " anim=" + a
3195 + " animAttr=0x" + Integer.toHexString(animAttr)
3196 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 if (a != null) {
3199 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003200 RuntimeException e = null;
3201 if (!HIDE_STACK_CRAWLS) {
3202 e = new RuntimeException();
3203 e.fillInStackTrace();
3204 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003205 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 }
3207 wtoken.setAnimation(a);
3208 }
3209 } else {
3210 wtoken.clearAnimation();
3211 }
3212
3213 return wtoken.animation != null;
3214 }
3215
3216 // -------------------------------------------------------------
3217 // Application Window Tokens
3218 // -------------------------------------------------------------
3219
3220 public void validateAppTokens(List tokens) {
3221 int v = tokens.size()-1;
3222 int m = mAppTokens.size()-1;
3223 while (v >= 0 && m >= 0) {
3224 AppWindowToken wtoken = mAppTokens.get(m);
3225 if (wtoken.removed) {
3226 m--;
3227 continue;
3228 }
3229 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003230 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3232 }
3233 v--;
3234 m--;
3235 }
3236 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003237 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 v--;
3239 }
3240 while (m >= 0) {
3241 AppWindowToken wtoken = mAppTokens.get(m);
3242 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003243 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003244 }
3245 m--;
3246 }
3247 }
3248
3249 boolean checkCallingPermission(String permission, String func) {
3250 // Quick check: if the calling permission is me, it's all okay.
3251 if (Binder.getCallingPid() == Process.myPid()) {
3252 return true;
3253 }
Romain Guy06882f82009-06-10 13:36:04 -07003254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 if (mContext.checkCallingPermission(permission)
3256 == PackageManager.PERMISSION_GRANTED) {
3257 return true;
3258 }
3259 String msg = "Permission Denial: " + func + " from pid="
3260 + Binder.getCallingPid()
3261 + ", uid=" + Binder.getCallingUid()
3262 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003263 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 return false;
3265 }
Romain Guy06882f82009-06-10 13:36:04 -07003266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 AppWindowToken findAppWindowToken(IBinder token) {
3268 WindowToken wtoken = mTokenMap.get(token);
3269 if (wtoken == null) {
3270 return null;
3271 }
3272 return wtoken.appWindowToken;
3273 }
Romain Guy06882f82009-06-10 13:36:04 -07003274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 public void addWindowToken(IBinder token, int type) {
3276 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3277 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003278 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 }
Romain Guy06882f82009-06-10 13:36:04 -07003280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 synchronized(mWindowMap) {
3282 WindowToken wtoken = mTokenMap.get(token);
3283 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003284 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 return;
3286 }
3287 wtoken = new WindowToken(token, type, true);
3288 mTokenMap.put(token, wtoken);
3289 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003290 if (type == TYPE_WALLPAPER) {
3291 mWallpaperTokens.add(wtoken);
3292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 }
3294 }
Romain Guy06882f82009-06-10 13:36:04 -07003295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 public void removeWindowToken(IBinder token) {
3297 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3298 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003299 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 }
3301
3302 final long origId = Binder.clearCallingIdentity();
3303 synchronized(mWindowMap) {
3304 WindowToken wtoken = mTokenMap.remove(token);
3305 mTokenList.remove(wtoken);
3306 if (wtoken != null) {
3307 boolean delayed = false;
3308 if (!wtoken.hidden) {
3309 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 final int N = wtoken.windows.size();
3312 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003314 for (int i=0; i<N; i++) {
3315 WindowState win = wtoken.windows.get(i);
3316
3317 if (win.isAnimating()) {
3318 delayed = true;
3319 }
Romain Guy06882f82009-06-10 13:36:04 -07003320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 if (win.isVisibleNow()) {
3322 applyAnimationLocked(win,
3323 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 changed = true;
3325 }
3326 }
3327
3328 if (changed) {
3329 mLayoutNeeded = true;
3330 performLayoutAndPlaceSurfacesLocked();
3331 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3332 }
Romain Guy06882f82009-06-10 13:36:04 -07003333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 if (delayed) {
3335 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003336 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3337 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 }
3339 }
Romain Guy06882f82009-06-10 13:36:04 -07003340
Jeff Brownc5ed5912010-07-14 18:48:53 -07003341 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003343 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 }
3345 }
3346 Binder.restoreCallingIdentity(origId);
3347 }
3348
3349 public void addAppToken(int addPos, IApplicationToken token,
3350 int groupId, int requestedOrientation, boolean fullscreen) {
3351 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3352 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003353 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 }
Jeff Brown349703e2010-06-22 01:27:15 -07003355
3356 // Get the dispatching timeout here while we are not holding any locks so that it
3357 // can be cached by the AppWindowToken. The timeout value is used later by the
3358 // input dispatcher in code that does hold locks. If we did not cache the value
3359 // here we would run the chance of introducing a deadlock between the window manager
3360 // (which holds locks while updating the input dispatcher state) and the activity manager
3361 // (which holds locks while querying the application token).
3362 long inputDispatchingTimeoutNanos;
3363 try {
3364 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3365 } catch (RemoteException ex) {
3366 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3367 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3368 }
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 synchronized(mWindowMap) {
3371 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3372 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003373 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 return;
3375 }
3376 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003377 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 wtoken.groupId = groupId;
3379 wtoken.appFullscreen = fullscreen;
3380 wtoken.requestedOrientation = requestedOrientation;
3381 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003382 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 mTokenMap.put(token.asBinder(), wtoken);
3384 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 // Application tokens start out hidden.
3387 wtoken.hidden = true;
3388 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 //dump();
3391 }
3392 }
Romain Guy06882f82009-06-10 13:36:04 -07003393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003394 public void setAppGroupId(IBinder token, int groupId) {
3395 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3396 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003397 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 }
3399
3400 synchronized(mWindowMap) {
3401 AppWindowToken wtoken = findAppWindowToken(token);
3402 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003403 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 return;
3405 }
3406 wtoken.groupId = groupId;
3407 }
3408 }
Romain Guy06882f82009-06-10 13:36:04 -07003409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 public int getOrientationFromWindowsLocked() {
3411 int pos = mWindows.size() - 1;
3412 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003413 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 pos--;
3415 if (wtoken.mAppToken != null) {
3416 // We hit an application window. so the orientation will be determined by the
3417 // app window. No point in continuing further.
3418 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3419 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003420 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 continue;
3422 }
3423 int req = wtoken.mAttrs.screenOrientation;
3424 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3425 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3426 continue;
3427 } else {
3428 return req;
3429 }
3430 }
3431 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3432 }
Romain Guy06882f82009-06-10 13:36:04 -07003433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003435 int pos = mAppTokens.size() - 1;
3436 int curGroup = 0;
3437 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3438 boolean findingBehind = false;
3439 boolean haveGroup = false;
3440 boolean lastFullscreen = false;
3441 while (pos >= 0) {
3442 AppWindowToken wtoken = mAppTokens.get(pos);
3443 pos--;
3444 // if we're about to tear down this window and not seek for
3445 // the behind activity, don't use it for orientation
3446 if (!findingBehind
3447 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3448 continue;
3449 }
3450
3451 if (!haveGroup) {
3452 // We ignore any hidden applications on the top.
3453 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003454 continue;
3455 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003456 haveGroup = true;
3457 curGroup = wtoken.groupId;
3458 lastOrientation = wtoken.requestedOrientation;
3459 } else if (curGroup != wtoken.groupId) {
3460 // If we have hit a new application group, and the bottom
3461 // of the previous group didn't explicitly say to use
3462 // the orientation behind it, and the last app was
3463 // full screen, then we'll stick with the
3464 // user's orientation.
3465 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3466 && lastFullscreen) {
3467 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003469 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003470 int or = wtoken.requestedOrientation;
3471 // If this application is fullscreen, and didn't explicitly say
3472 // to use the orientation behind it, then just take whatever
3473 // orientation it has and ignores whatever is under it.
3474 lastFullscreen = wtoken.appFullscreen;
3475 if (lastFullscreen
3476 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3477 return or;
3478 }
3479 // If this application has requested an explicit orientation,
3480 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003481 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3482 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003483 return or;
3484 }
3485 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3486 }
3487 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 }
Romain Guy06882f82009-06-10 13:36:04 -07003489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003491 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003492 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3493 "updateOrientationFromAppTokens()")) {
3494 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3495 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003496
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003497 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003499
3500 synchronized(mWindowMap) {
3501 if (updateOrientationFromAppTokensLocked()) {
3502 if (freezeThisOneIfNeeded != null) {
3503 AppWindowToken wtoken = findAppWindowToken(
3504 freezeThisOneIfNeeded);
3505 if (wtoken != null) {
3506 startAppFreezingScreenLocked(wtoken,
3507 ActivityInfo.CONFIG_ORIENTATION);
3508 }
3509 }
3510 config = computeNewConfigurationLocked();
3511
3512 } else if (currentConfig != null) {
3513 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003514 // state mismatches the activity manager's, update it,
3515 // disregarding font scale, which should remain set to
3516 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003517 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003518 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003519 if (computeNewConfigurationLocked(mTempConfiguration)) {
3520 if (currentConfig.diff(mTempConfiguration) != 0) {
3521 mWaitingForConfig = true;
3522 mLayoutNeeded = true;
3523 startFreezingDisplayLocked();
3524 config = new Configuration(mTempConfiguration);
3525 }
3526 }
3527 }
3528 }
3529
Dianne Hackborncfaef692009-06-15 14:24:44 -07003530 Binder.restoreCallingIdentity(ident);
3531 return config;
3532 }
3533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003535 * Determine the new desired orientation of the display, returning
3536 * a non-null new Configuration if it has changed from the current
3537 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3538 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3539 * SCREEN. This will typically be done for you if you call
3540 * sendNewConfiguration().
3541 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 * The orientation is computed from non-application windows first. If none of
3543 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003544 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3546 * android.os.IBinder)
3547 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003548 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003549 if (mDisplayFrozen) {
3550 // If the display is frozen, some activities may be in the middle
3551 // of restarting, and thus have removed their old window. If the
3552 // window has the flag to hide the lock screen, then the lock screen
3553 // can re-appear and inflict its own orientation on us. Keep the
3554 // orientation stable until this all settles down.
3555 return false;
3556 }
3557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 long ident = Binder.clearCallingIdentity();
3560 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003561 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 mForcedAppOrientation = req;
3565 //send a message to Policy indicating orientation change to take
3566 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003567 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003568 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3569 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3570 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 }
3572 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003573
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003574 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 } finally {
3576 Binder.restoreCallingIdentity(ident);
3577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 }
Romain Guy06882f82009-06-10 13:36:04 -07003579
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003580 int computeForcedAppOrientationLocked() {
3581 int req = getOrientationFromWindowsLocked();
3582 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3583 req = getOrientationFromAppTokensLocked();
3584 }
3585 return req;
3586 }
Romain Guy06882f82009-06-10 13:36:04 -07003587
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003588 public void setNewConfiguration(Configuration config) {
3589 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3590 "setNewConfiguration()")) {
3591 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3592 }
3593
3594 synchronized(mWindowMap) {
3595 mCurConfiguration = new Configuration(config);
3596 mWaitingForConfig = false;
3597 performLayoutAndPlaceSurfacesLocked();
3598 }
3599 }
3600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3602 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3603 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003604 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 }
Romain Guy06882f82009-06-10 13:36:04 -07003606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 synchronized(mWindowMap) {
3608 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3609 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003610 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 return;
3612 }
Romain Guy06882f82009-06-10 13:36:04 -07003613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 wtoken.requestedOrientation = requestedOrientation;
3615 }
3616 }
Romain Guy06882f82009-06-10 13:36:04 -07003617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 public int getAppOrientation(IApplicationToken token) {
3619 synchronized(mWindowMap) {
3620 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3621 if (wtoken == null) {
3622 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3623 }
Romain Guy06882f82009-06-10 13:36:04 -07003624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 return wtoken.requestedOrientation;
3626 }
3627 }
Romain Guy06882f82009-06-10 13:36:04 -07003628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3630 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3631 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003632 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 }
3634
3635 synchronized(mWindowMap) {
3636 boolean changed = false;
3637 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003638 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 changed = mFocusedApp != null;
3640 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003641 if (changed) {
3642 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003643 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 } else {
3645 AppWindowToken newFocus = findAppWindowToken(token);
3646 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003647 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 return;
3649 }
3650 changed = mFocusedApp != newFocus;
3651 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003652 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003653 if (changed) {
3654 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656 }
3657
3658 if (moveFocusNow && changed) {
3659 final long origId = Binder.clearCallingIdentity();
3660 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3661 Binder.restoreCallingIdentity(origId);
3662 }
3663 }
3664 }
3665
3666 public void prepareAppTransition(int transit) {
3667 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3668 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003669 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 }
Romain Guy06882f82009-06-10 13:36:04 -07003671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003673 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 TAG, "Prepare app transition: transit=" + transit
3675 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003676 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003677 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3678 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003680 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3681 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3682 // Opening a new task always supersedes a close for the anim.
3683 mNextAppTransition = transit;
3684 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3685 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3686 // Opening a new activity always supersedes a close for the anim.
3687 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 }
3689 mAppTransitionReady = false;
3690 mAppTransitionTimeout = false;
3691 mStartingIconInTransition = false;
3692 mSkipAppTransitionAnimation = false;
3693 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3694 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3695 5000);
3696 }
3697 }
3698 }
3699
3700 public int getPendingAppTransition() {
3701 return mNextAppTransition;
3702 }
Romain Guy06882f82009-06-10 13:36:04 -07003703
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003704 public void overridePendingAppTransition(String packageName,
3705 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003706 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003707 mNextAppTransitionPackage = packageName;
3708 mNextAppTransitionEnter = enterAnim;
3709 mNextAppTransitionExit = exitAnim;
3710 }
3711 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 public void executeAppTransition() {
3714 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3715 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003716 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 }
Romain Guy06882f82009-06-10 13:36:04 -07003718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003720 if (DEBUG_APP_TRANSITIONS) {
3721 RuntimeException e = new RuntimeException("here");
3722 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003723 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003724 + mNextAppTransition, e);
3725 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003726 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003727 mAppTransitionReady = true;
3728 final long origId = Binder.clearCallingIdentity();
3729 performLayoutAndPlaceSurfacesLocked();
3730 Binder.restoreCallingIdentity(origId);
3731 }
3732 }
3733 }
3734
3735 public void setAppStartingWindow(IBinder token, String pkg,
3736 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003737 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3739 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003740 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 }
3742
3743 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003744 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3746 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 AppWindowToken wtoken = findAppWindowToken(token);
3749 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003750 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 return;
3752 }
3753
3754 // If the display is frozen, we won't do anything until the
3755 // actual window is displayed so there is no reason to put in
3756 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003757 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 return;
3759 }
Romain Guy06882f82009-06-10 13:36:04 -07003760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 if (wtoken.startingData != null) {
3762 return;
3763 }
Romain Guy06882f82009-06-10 13:36:04 -07003764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003765 if (transferFrom != null) {
3766 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3767 if (ttoken != null) {
3768 WindowState startingWindow = ttoken.startingWindow;
3769 if (startingWindow != null) {
3770 if (mStartingIconInTransition) {
3771 // In this case, the starting icon has already
3772 // been displayed, so start letting windows get
3773 // shown immediately without any more transitions.
3774 mSkipAppTransitionAnimation = true;
3775 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003776 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 "Moving existing starting from " + ttoken
3778 + " to " + wtoken);
3779 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 // Transfer the starting window over to the new
3782 // token.
3783 wtoken.startingData = ttoken.startingData;
3784 wtoken.startingView = ttoken.startingView;
3785 wtoken.startingWindow = startingWindow;
3786 ttoken.startingData = null;
3787 ttoken.startingView = null;
3788 ttoken.startingWindow = null;
3789 ttoken.startingMoved = true;
3790 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003791 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003793 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003794 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003795 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003796 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 ttoken.windows.remove(startingWindow);
3798 ttoken.allAppWindows.remove(startingWindow);
3799 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 // Propagate other interesting state between the
3802 // tokens. If the old token is displayed, we should
3803 // immediately force the new one to be displayed. If
3804 // it is animating, we need to move that animation to
3805 // the new one.
3806 if (ttoken.allDrawn) {
3807 wtoken.allDrawn = true;
3808 }
3809 if (ttoken.firstWindowDrawn) {
3810 wtoken.firstWindowDrawn = true;
3811 }
3812 if (!ttoken.hidden) {
3813 wtoken.hidden = false;
3814 wtoken.hiddenRequested = false;
3815 wtoken.willBeHidden = false;
3816 }
3817 if (wtoken.clientHidden != ttoken.clientHidden) {
3818 wtoken.clientHidden = ttoken.clientHidden;
3819 wtoken.sendAppVisibilityToClients();
3820 }
3821 if (ttoken.animation != null) {
3822 wtoken.animation = ttoken.animation;
3823 wtoken.animating = ttoken.animating;
3824 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3825 ttoken.animation = null;
3826 ttoken.animLayerAdjustment = 0;
3827 wtoken.updateLayers();
3828 ttoken.updateLayers();
3829 }
Romain Guy06882f82009-06-10 13:36:04 -07003830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003831 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 mLayoutNeeded = true;
3833 performLayoutAndPlaceSurfacesLocked();
3834 Binder.restoreCallingIdentity(origId);
3835 return;
3836 } else if (ttoken.startingData != null) {
3837 // The previous app was getting ready to show a
3838 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003839 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 "Moving pending starting from " + ttoken
3841 + " to " + wtoken);
3842 wtoken.startingData = ttoken.startingData;
3843 ttoken.startingData = null;
3844 ttoken.startingMoved = true;
3845 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3846 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3847 // want to process the message ASAP, before any other queued
3848 // messages.
3849 mH.sendMessageAtFrontOfQueue(m);
3850 return;
3851 }
3852 }
3853 }
3854
3855 // There is no existing starting window, and the caller doesn't
3856 // want us to create one, so that's it!
3857 if (!createIfNeeded) {
3858 return;
3859 }
Romain Guy06882f82009-06-10 13:36:04 -07003860
Dianne Hackborn284ac932009-08-28 10:34:25 -07003861 // If this is a translucent or wallpaper window, then don't
3862 // show a starting window -- the current effect (a full-screen
3863 // opaque starting window that fades away to the real contents
3864 // when it is ready) does not work for this.
3865 if (theme != 0) {
3866 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3867 com.android.internal.R.styleable.Window);
3868 if (ent.array.getBoolean(
3869 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3870 return;
3871 }
3872 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003873 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3874 return;
3875 }
3876 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003877 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3878 return;
3879 }
3880 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 mStartingIconInTransition = true;
3883 wtoken.startingData = new StartingData(
3884 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003885 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3887 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3888 // want to process the message ASAP, before any other queued
3889 // messages.
3890 mH.sendMessageAtFrontOfQueue(m);
3891 }
3892 }
3893
3894 public void setAppWillBeHidden(IBinder token) {
3895 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3896 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003897 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003898 }
3899
3900 AppWindowToken wtoken;
3901
3902 synchronized(mWindowMap) {
3903 wtoken = findAppWindowToken(token);
3904 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003905 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 -08003906 return;
3907 }
3908 wtoken.willBeHidden = true;
3909 }
3910 }
Romain Guy06882f82009-06-10 13:36:04 -07003911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003912 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3913 boolean visible, int transit, boolean performLayout) {
3914 boolean delayed = false;
3915
3916 if (wtoken.clientHidden == visible) {
3917 wtoken.clientHidden = !visible;
3918 wtoken.sendAppVisibilityToClients();
3919 }
Romain Guy06882f82009-06-10 13:36:04 -07003920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 wtoken.willBeHidden = false;
3922 if (wtoken.hidden == visible) {
3923 final int N = wtoken.allAppWindows.size();
3924 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003925 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003926 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3927 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003930
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003931 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 if (wtoken.animation == sDummyAnimation) {
3933 wtoken.animation = null;
3934 }
3935 applyAnimationLocked(wtoken, lp, transit, visible);
3936 changed = true;
3937 if (wtoken.animation != null) {
3938 delayed = runningAppAnimation = true;
3939 }
3940 }
Romain Guy06882f82009-06-10 13:36:04 -07003941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003942 for (int i=0; i<N; i++) {
3943 WindowState win = wtoken.allAppWindows.get(i);
3944 if (win == wtoken.startingWindow) {
3945 continue;
3946 }
3947
3948 if (win.isAnimating()) {
3949 delayed = true;
3950 }
Romain Guy06882f82009-06-10 13:36:04 -07003951
Joe Onorato8a9b2202010-02-26 18:56:32 -08003952 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003953 //win.dump(" ");
3954 if (visible) {
3955 if (!win.isVisibleNow()) {
3956 if (!runningAppAnimation) {
3957 applyAnimationLocked(win,
3958 WindowManagerPolicy.TRANSIT_ENTER, true);
3959 }
3960 changed = true;
3961 }
3962 } else if (win.isVisibleNow()) {
3963 if (!runningAppAnimation) {
3964 applyAnimationLocked(win,
3965 WindowManagerPolicy.TRANSIT_EXIT, false);
3966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 changed = true;
3968 }
3969 }
3970
3971 wtoken.hidden = wtoken.hiddenRequested = !visible;
3972 if (!visible) {
3973 unsetAppFreezingScreenLocked(wtoken, true, true);
3974 } else {
3975 // If we are being set visible, and the starting window is
3976 // not yet displayed, then make sure it doesn't get displayed.
3977 WindowState swin = wtoken.startingWindow;
3978 if (swin != null && (swin.mDrawPending
3979 || swin.mCommitDrawPending)) {
3980 swin.mPolicyVisibility = false;
3981 swin.mPolicyVisibilityAfterAnim = false;
3982 }
3983 }
Romain Guy06882f82009-06-10 13:36:04 -07003984
Joe Onorato8a9b2202010-02-26 18:56:32 -08003985 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3987 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003988
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003989 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003991 if (performLayout) {
3992 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3993 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003994 } else {
3995 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003996 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 }
3998 }
3999
4000 if (wtoken.animation != null) {
4001 delayed = true;
4002 }
Romain Guy06882f82009-06-10 13:36:04 -07004003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 return delayed;
4005 }
4006
4007 public void setAppVisibility(IBinder token, boolean visible) {
4008 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4009 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004010 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 }
4012
4013 AppWindowToken wtoken;
4014
4015 synchronized(mWindowMap) {
4016 wtoken = findAppWindowToken(token);
4017 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004018 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 return;
4020 }
4021
4022 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004023 RuntimeException e = null;
4024 if (!HIDE_STACK_CRAWLS) {
4025 e = new RuntimeException();
4026 e.fillInStackTrace();
4027 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004028 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 + "): mNextAppTransition=" + mNextAppTransition
4030 + " hidden=" + wtoken.hidden
4031 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4032 }
Romain Guy06882f82009-06-10 13:36:04 -07004033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 // If we are preparing an app transition, then delay changing
4035 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004036 if (!mDisplayFrozen && mPolicy.isScreenOn()
4037 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004038 // Already in requested state, don't do anything more.
4039 if (wtoken.hiddenRequested != visible) {
4040 return;
4041 }
4042 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004043
Joe Onorato8a9b2202010-02-26 18:56:32 -08004044 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 TAG, "Setting dummy animation on: " + wtoken);
4046 wtoken.setDummyAnimation();
4047 mOpeningApps.remove(wtoken);
4048 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004049 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050 wtoken.inPendingTransaction = true;
4051 if (visible) {
4052 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004053 wtoken.startingDisplayed = false;
4054 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004055
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004056 // If the token is currently hidden (should be the
4057 // common case), then we need to set up to wait for
4058 // its windows to be ready.
4059 if (wtoken.hidden) {
4060 wtoken.allDrawn = false;
4061 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004062
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004063 if (wtoken.clientHidden) {
4064 // In the case where we are making an app visible
4065 // but holding off for a transition, we still need
4066 // to tell the client to make its windows visible so
4067 // they get drawn. Otherwise, we will wait on
4068 // performing the transition until all windows have
4069 // been drawn, they never will be, and we are sad.
4070 wtoken.clientHidden = false;
4071 wtoken.sendAppVisibilityToClients();
4072 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004073 }
4074 } else {
4075 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004076
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004077 // If the token is currently visible (should be the
4078 // common case), then set up to wait for it to be hidden.
4079 if (!wtoken.hidden) {
4080 wtoken.waitingToHide = true;
4081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 }
4083 return;
4084 }
Romain Guy06882f82009-06-10 13:36:04 -07004085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004087 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 wtoken.updateReportedVisibilityLocked();
4089 Binder.restoreCallingIdentity(origId);
4090 }
4091 }
4092
4093 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4094 boolean unfreezeSurfaceNow, boolean force) {
4095 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004096 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097 + " force=" + force);
4098 final int N = wtoken.allAppWindows.size();
4099 boolean unfrozeWindows = false;
4100 for (int i=0; i<N; i++) {
4101 WindowState w = wtoken.allAppWindows.get(i);
4102 if (w.mAppFreezing) {
4103 w.mAppFreezing = false;
4104 if (w.mSurface != null && !w.mOrientationChanging) {
4105 w.mOrientationChanging = true;
4106 }
4107 unfrozeWindows = true;
4108 }
4109 }
4110 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004111 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 wtoken.freezingScreen = false;
4113 mAppsFreezingScreen--;
4114 }
4115 if (unfreezeSurfaceNow) {
4116 if (unfrozeWindows) {
4117 mLayoutNeeded = true;
4118 performLayoutAndPlaceSurfacesLocked();
4119 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004120 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004121 }
4122 }
4123 }
Romain Guy06882f82009-06-10 13:36:04 -07004124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4126 int configChanges) {
4127 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004128 RuntimeException e = null;
4129 if (!HIDE_STACK_CRAWLS) {
4130 e = new RuntimeException();
4131 e.fillInStackTrace();
4132 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004133 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004134 + ": hidden=" + wtoken.hidden + " freezing="
4135 + wtoken.freezingScreen, e);
4136 }
4137 if (!wtoken.hiddenRequested) {
4138 if (!wtoken.freezingScreen) {
4139 wtoken.freezingScreen = true;
4140 mAppsFreezingScreen++;
4141 if (mAppsFreezingScreen == 1) {
4142 startFreezingDisplayLocked();
4143 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4144 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4145 5000);
4146 }
4147 }
4148 final int N = wtoken.allAppWindows.size();
4149 for (int i=0; i<N; i++) {
4150 WindowState w = wtoken.allAppWindows.get(i);
4151 w.mAppFreezing = true;
4152 }
4153 }
4154 }
Romain Guy06882f82009-06-10 13:36:04 -07004155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004156 public void startAppFreezingScreen(IBinder token, int configChanges) {
4157 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4158 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004159 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 }
4161
4162 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004163 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004164 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 return;
4166 }
Romain Guy06882f82009-06-10 13:36:04 -07004167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 AppWindowToken wtoken = findAppWindowToken(token);
4169 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004170 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 return;
4172 }
4173 final long origId = Binder.clearCallingIdentity();
4174 startAppFreezingScreenLocked(wtoken, configChanges);
4175 Binder.restoreCallingIdentity(origId);
4176 }
4177 }
Romain Guy06882f82009-06-10 13:36:04 -07004178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 public void stopAppFreezingScreen(IBinder token, boolean force) {
4180 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4181 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004182 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004183 }
4184
4185 synchronized(mWindowMap) {
4186 AppWindowToken wtoken = findAppWindowToken(token);
4187 if (wtoken == null || wtoken.appToken == null) {
4188 return;
4189 }
4190 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004191 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4193 unsetAppFreezingScreenLocked(wtoken, true, force);
4194 Binder.restoreCallingIdentity(origId);
4195 }
4196 }
Romain Guy06882f82009-06-10 13:36:04 -07004197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004198 public void removeAppToken(IBinder token) {
4199 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4200 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004201 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 }
4203
4204 AppWindowToken wtoken = null;
4205 AppWindowToken startingToken = null;
4206 boolean delayed = false;
4207
4208 final long origId = Binder.clearCallingIdentity();
4209 synchronized(mWindowMap) {
4210 WindowToken basewtoken = mTokenMap.remove(token);
4211 mTokenList.remove(basewtoken);
4212 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004213 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004214 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 wtoken.inPendingTransaction = false;
4216 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004217 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 if (mClosingApps.contains(wtoken)) {
4219 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004220 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004222 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 delayed = true;
4224 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004225 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 TAG, "Removing app " + wtoken + " delayed=" + delayed
4227 + " animation=" + wtoken.animation
4228 + " animating=" + wtoken.animating);
4229 if (delayed) {
4230 // set the token aside because it has an active animation to be finished
4231 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004232 } else {
4233 // Make sure there is no animation running on this token,
4234 // so any windows associated with it will be removed as
4235 // soon as their animations are complete
4236 wtoken.animation = null;
4237 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 }
4239 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004240 if (mLastEnterAnimToken == wtoken) {
4241 mLastEnterAnimToken = null;
4242 mLastEnterAnimParams = null;
4243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 wtoken.removed = true;
4245 if (wtoken.startingData != null) {
4246 startingToken = wtoken;
4247 }
4248 unsetAppFreezingScreenLocked(wtoken, true, true);
4249 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004250 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 mFocusedApp = null;
4252 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004253 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 }
4255 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004256 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 }
Romain Guy06882f82009-06-10 13:36:04 -07004258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004259 if (!delayed && wtoken != null) {
4260 wtoken.updateReportedVisibilityLocked();
4261 }
4262 }
4263 Binder.restoreCallingIdentity(origId);
4264
4265 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004266 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 + startingToken + ": app token removed");
4268 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4269 mH.sendMessage(m);
4270 }
4271 }
4272
4273 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4274 final int NW = token.windows.size();
4275 for (int i=0; i<NW; i++) {
4276 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004277 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004279 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 int j = win.mChildWindows.size();
4281 while (j > 0) {
4282 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004283 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004284 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004285 "Tmp removing child window " + cwin);
4286 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 }
4288 }
4289 return NW > 0;
4290 }
4291
4292 void dumpAppTokensLocked() {
4293 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004294 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004295 }
4296 }
Romain Guy06882f82009-06-10 13:36:04 -07004297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004298 void dumpWindowsLocked() {
4299 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004300 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 }
4302 }
Romain Guy06882f82009-06-10 13:36:04 -07004303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 private int findWindowOffsetLocked(int tokenPos) {
4305 final int NW = mWindows.size();
4306
4307 if (tokenPos >= mAppTokens.size()) {
4308 int i = NW;
4309 while (i > 0) {
4310 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004311 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 if (win.getAppToken() != null) {
4313 return i+1;
4314 }
4315 }
4316 }
4317
4318 while (tokenPos > 0) {
4319 // Find the first app token below the new position that has
4320 // a window displayed.
4321 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004322 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004324 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004325 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004326 "Skipping token -- currently sending to bottom");
4327 tokenPos--;
4328 continue;
4329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 int i = wtoken.windows.size();
4331 while (i > 0) {
4332 i--;
4333 WindowState win = wtoken.windows.get(i);
4334 int j = win.mChildWindows.size();
4335 while (j > 0) {
4336 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004337 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004338 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 for (int pos=NW-1; pos>=0; pos--) {
4340 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004341 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004342 "Found child win @" + (pos+1));
4343 return pos+1;
4344 }
4345 }
4346 }
4347 }
4348 for (int pos=NW-1; pos>=0; pos--) {
4349 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004350 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 return pos+1;
4352 }
4353 }
4354 }
4355 tokenPos--;
4356 }
4357
4358 return 0;
4359 }
4360
4361 private final int reAddWindowLocked(int index, WindowState win) {
4362 final int NCW = win.mChildWindows.size();
4363 boolean added = false;
4364 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004365 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004367 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004368 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 mWindows.add(index, win);
4370 index++;
4371 added = true;
4372 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004373 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004374 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004375 mWindows.add(index, cwin);
4376 index++;
4377 }
4378 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004379 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004380 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004381 mWindows.add(index, win);
4382 index++;
4383 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004384 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 return index;
4386 }
Romain Guy06882f82009-06-10 13:36:04 -07004387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004388 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4389 final int NW = token.windows.size();
4390 for (int i=0; i<NW; i++) {
4391 index = reAddWindowLocked(index, token.windows.get(i));
4392 }
4393 return index;
4394 }
4395
4396 public void moveAppToken(int index, IBinder token) {
4397 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4398 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004399 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004400 }
4401
4402 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004403 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404 if (DEBUG_REORDER) dumpAppTokensLocked();
4405 final AppWindowToken wtoken = findAppWindowToken(token);
4406 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004407 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 + token + " (" + wtoken + ")");
4409 return;
4410 }
4411 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004412 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004416 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 if (DEBUG_REORDER) dumpWindowsLocked();
4418 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004419 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 if (DEBUG_REORDER) dumpWindowsLocked();
4421 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004422 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 if (DEBUG_REORDER) dumpWindowsLocked();
4424 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425 mLayoutNeeded = true;
4426 performLayoutAndPlaceSurfacesLocked();
4427 }
4428 Binder.restoreCallingIdentity(origId);
4429 }
4430 }
4431
4432 private void removeAppTokensLocked(List<IBinder> tokens) {
4433 // XXX This should be done more efficiently!
4434 // (take advantage of the fact that both lists should be
4435 // ordered in the same way.)
4436 int N = tokens.size();
4437 for (int i=0; i<N; i++) {
4438 IBinder token = tokens.get(i);
4439 final AppWindowToken wtoken = findAppWindowToken(token);
4440 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004441 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004442 + token + " (" + wtoken + ")");
4443 i--;
4444 N--;
4445 }
4446 }
4447 }
4448
Dianne Hackborna8f60182009-09-01 19:01:50 -07004449 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4450 boolean updateFocusAndLayout) {
4451 // First remove all of the windows from the list.
4452 tmpRemoveAppWindowsLocked(wtoken);
4453
4454 // Where to start adding?
4455 int pos = findWindowOffsetLocked(tokenPos);
4456
4457 // And now add them back at the correct place.
4458 pos = reAddAppWindowsLocked(pos, wtoken);
4459
4460 if (updateFocusAndLayout) {
4461 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4462 assignLayersLocked();
4463 }
4464 mLayoutNeeded = true;
4465 performLayoutAndPlaceSurfacesLocked();
4466 }
4467 }
4468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4470 // First remove all of the windows from the list.
4471 final int N = tokens.size();
4472 int i;
4473 for (i=0; i<N; i++) {
4474 WindowToken token = mTokenMap.get(tokens.get(i));
4475 if (token != null) {
4476 tmpRemoveAppWindowsLocked(token);
4477 }
4478 }
4479
4480 // Where to start adding?
4481 int pos = findWindowOffsetLocked(tokenPos);
4482
4483 // And now add them back at the correct place.
4484 for (i=0; i<N; i++) {
4485 WindowToken token = mTokenMap.get(tokens.get(i));
4486 if (token != null) {
4487 pos = reAddAppWindowsLocked(pos, token);
4488 }
4489 }
4490
Dianne Hackborna8f60182009-09-01 19:01:50 -07004491 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4492 assignLayersLocked();
4493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 mLayoutNeeded = true;
4495 performLayoutAndPlaceSurfacesLocked();
4496
4497 //dump();
4498 }
4499
4500 public void moveAppTokensToTop(List<IBinder> tokens) {
4501 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4502 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004503 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004504 }
4505
4506 final long origId = Binder.clearCallingIdentity();
4507 synchronized(mWindowMap) {
4508 removeAppTokensLocked(tokens);
4509 final int N = tokens.size();
4510 for (int i=0; i<N; i++) {
4511 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4512 if (wt != null) {
4513 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004514 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004515 mToTopApps.remove(wt);
4516 mToBottomApps.remove(wt);
4517 mToTopApps.add(wt);
4518 wt.sendingToBottom = false;
4519 wt.sendingToTop = true;
4520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 }
4522 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004523
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004524 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004525 moveAppWindowsLocked(tokens, mAppTokens.size());
4526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 }
4528 Binder.restoreCallingIdentity(origId);
4529 }
4530
4531 public void moveAppTokensToBottom(List<IBinder> tokens) {
4532 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4533 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004534 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 }
4536
4537 final long origId = Binder.clearCallingIdentity();
4538 synchronized(mWindowMap) {
4539 removeAppTokensLocked(tokens);
4540 final int N = tokens.size();
4541 int pos = 0;
4542 for (int i=0; i<N; i++) {
4543 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4544 if (wt != null) {
4545 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004546 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004547 mToTopApps.remove(wt);
4548 mToBottomApps.remove(wt);
4549 mToBottomApps.add(i, wt);
4550 wt.sendingToTop = false;
4551 wt.sendingToBottom = true;
4552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004553 pos++;
4554 }
4555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004556
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004557 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004558 moveAppWindowsLocked(tokens, 0);
4559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004560 }
4561 Binder.restoreCallingIdentity(origId);
4562 }
4563
4564 // -------------------------------------------------------------
4565 // Misc IWindowSession methods
4566 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004567
Jim Miller284b62e2010-06-08 14:27:42 -07004568 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004569 {
Jim Miller284b62e2010-06-08 14:27:42 -07004570 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4571 // called before DevicePolicyManagerService has started.
4572 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4573 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4574 Context.DEVICE_POLICY_SERVICE);
4575 if (dpm != null) {
4576 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4577 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4578 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4579 }
Jim Millerd6b57052010-06-07 17:52:42 -07004580 }
Jim Miller284b62e2010-06-08 14:27:42 -07004581 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004582 }
4583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004584 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004585 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586 != PackageManager.PERMISSION_GRANTED) {
4587 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4588 }
Jim Millerd6b57052010-06-07 17:52:42 -07004589
Jim Miller284b62e2010-06-08 14:27:42 -07004590 synchronized (mKeyguardTokenWatcher) {
4591 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 }
4594
4595 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004596 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004597 != PackageManager.PERMISSION_GRANTED) {
4598 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600
Jim Miller284b62e2010-06-08 14:27:42 -07004601 synchronized (mKeyguardTokenWatcher) {
4602 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004603
Jim Miller284b62e2010-06-08 14:27:42 -07004604 if (!mKeyguardTokenWatcher.isAcquired()) {
4605 // If we are the last one to reenable the keyguard wait until
4606 // we have actually finished reenabling until returning.
4607 // It is possible that reenableKeyguard() can be called before
4608 // the previous disableKeyguard() is handled, in which case
4609 // neither mKeyguardTokenWatcher.acquired() or released() would
4610 // be called. In that case mKeyguardDisabled will be false here
4611 // and we have nothing to wait for.
4612 while (mKeyguardDisabled) {
4613 try {
4614 mKeyguardTokenWatcher.wait();
4615 } catch (InterruptedException e) {
4616 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004617 }
4618 }
4619 }
4620 }
4621 }
4622
4623 /**
4624 * @see android.app.KeyguardManager#exitKeyguardSecurely
4625 */
4626 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004627 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004628 != PackageManager.PERMISSION_GRANTED) {
4629 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4630 }
4631 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4632 public void onKeyguardExitResult(boolean success) {
4633 try {
4634 callback.onKeyguardExitResult(success);
4635 } catch (RemoteException e) {
4636 // Client has died, we don't care.
4637 }
4638 }
4639 });
4640 }
4641
4642 public boolean inKeyguardRestrictedInputMode() {
4643 return mPolicy.inKeyguardRestrictedKeyInputMode();
4644 }
Romain Guy06882f82009-06-10 13:36:04 -07004645
Dianne Hackbornffa42482009-09-23 22:20:11 -07004646 public void closeSystemDialogs(String reason) {
4647 synchronized(mWindowMap) {
4648 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004649 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004650 if (w.mSurface != null) {
4651 try {
4652 w.mClient.closeSystemDialogs(reason);
4653 } catch (RemoteException e) {
4654 }
4655 }
4656 }
4657 }
4658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 static float fixScale(float scale) {
4661 if (scale < 0) scale = 0;
4662 else if (scale > 20) scale = 20;
4663 return Math.abs(scale);
4664 }
Romain Guy06882f82009-06-10 13:36:04 -07004665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 public void setAnimationScale(int which, float scale) {
4667 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4668 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004669 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004670 }
4671
4672 if (scale < 0) scale = 0;
4673 else if (scale > 20) scale = 20;
4674 scale = Math.abs(scale);
4675 switch (which) {
4676 case 0: mWindowAnimationScale = fixScale(scale); break;
4677 case 1: mTransitionAnimationScale = fixScale(scale); break;
4678 }
Romain Guy06882f82009-06-10 13:36:04 -07004679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004680 // Persist setting
4681 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4682 }
Romain Guy06882f82009-06-10 13:36:04 -07004683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 public void setAnimationScales(float[] scales) {
4685 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4686 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004687 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 }
4689
4690 if (scales != null) {
4691 if (scales.length >= 1) {
4692 mWindowAnimationScale = fixScale(scales[0]);
4693 }
4694 if (scales.length >= 2) {
4695 mTransitionAnimationScale = fixScale(scales[1]);
4696 }
4697 }
Romain Guy06882f82009-06-10 13:36:04 -07004698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 // Persist setting
4700 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4701 }
Romain Guy06882f82009-06-10 13:36:04 -07004702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004703 public float getAnimationScale(int which) {
4704 switch (which) {
4705 case 0: return mWindowAnimationScale;
4706 case 1: return mTransitionAnimationScale;
4707 }
4708 return 0;
4709 }
Romain Guy06882f82009-06-10 13:36:04 -07004710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004711 public float[] getAnimationScales() {
4712 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4713 }
Romain Guy06882f82009-06-10 13:36:04 -07004714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004715 public int getSwitchState(int sw) {
4716 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4717 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004718 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004719 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004720 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004721 }
Romain Guy06882f82009-06-10 13:36:04 -07004722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004723 public int getSwitchStateForDevice(int devid, int sw) {
4724 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4725 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004726 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004727 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004728 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004729 }
Romain Guy06882f82009-06-10 13:36:04 -07004730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004731 public int getScancodeState(int sw) {
4732 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4733 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004734 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004735 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004736 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 }
Romain Guy06882f82009-06-10 13:36:04 -07004738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004739 public int getScancodeStateForDevice(int devid, int sw) {
4740 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4741 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004742 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004743 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004744 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004745 }
Romain Guy06882f82009-06-10 13:36:04 -07004746
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004747 public int getTrackballScancodeState(int sw) {
4748 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4749 "getTrackballScancodeState()")) {
4750 throw new SecurityException("Requires READ_INPUT_STATE permission");
4751 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004752 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004753 }
4754
4755 public int getDPadScancodeState(int sw) {
4756 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4757 "getDPadScancodeState()")) {
4758 throw new SecurityException("Requires READ_INPUT_STATE permission");
4759 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004760 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004761 }
4762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004763 public int getKeycodeState(int sw) {
4764 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4765 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004766 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004768 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 }
Romain Guy06882f82009-06-10 13:36:04 -07004770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004771 public int getKeycodeStateForDevice(int devid, int sw) {
4772 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4773 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004774 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004775 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004776 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004777 }
Romain Guy06882f82009-06-10 13:36:04 -07004778
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004779 public int getTrackballKeycodeState(int sw) {
4780 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4781 "getTrackballKeycodeState()")) {
4782 throw new SecurityException("Requires READ_INPUT_STATE permission");
4783 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004784 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004785 }
4786
4787 public int getDPadKeycodeState(int sw) {
4788 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4789 "getDPadKeycodeState()")) {
4790 throw new SecurityException("Requires READ_INPUT_STATE permission");
4791 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004792 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004793 }
Jeff Browna41ca772010-08-11 14:46:32 -07004794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004796 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 }
Romain Guy06882f82009-06-10 13:36:04 -07004798
Jeff Browna41ca772010-08-11 14:46:32 -07004799 public InputChannel monitorInput(String inputChannelName) {
4800 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4801 "monitorInput()")) {
4802 throw new SecurityException("Requires READ_INPUT_STATE permission");
4803 }
4804 return mInputManager.monitorInput(inputChannelName);
4805 }
4806
Jeff Brown8d608662010-08-30 03:02:23 -07004807 public InputDevice getInputDevice(int deviceId) {
4808 return mInputManager.getInputDevice(deviceId);
4809 }
4810
4811 public int[] getInputDeviceIds() {
4812 return mInputManager.getInputDeviceIds();
4813 }
4814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815 public void enableScreenAfterBoot() {
4816 synchronized(mWindowMap) {
4817 if (mSystemBooted) {
4818 return;
4819 }
4820 mSystemBooted = true;
4821 }
Romain Guy06882f82009-06-10 13:36:04 -07004822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823 performEnableScreen();
4824 }
Romain Guy06882f82009-06-10 13:36:04 -07004825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004826 public void enableScreenIfNeededLocked() {
4827 if (mDisplayEnabled) {
4828 return;
4829 }
4830 if (!mSystemBooted) {
4831 return;
4832 }
4833 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4834 }
Romain Guy06882f82009-06-10 13:36:04 -07004835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004836 public void performEnableScreen() {
4837 synchronized(mWindowMap) {
4838 if (mDisplayEnabled) {
4839 return;
4840 }
4841 if (!mSystemBooted) {
4842 return;
4843 }
Romain Guy06882f82009-06-10 13:36:04 -07004844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004845 // Don't enable the screen until all existing windows
4846 // have been drawn.
4847 final int N = mWindows.size();
4848 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004849 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004850 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004851 return;
4852 }
4853 }
Romain Guy06882f82009-06-10 13:36:04 -07004854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 mDisplayEnabled = true;
4856 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004857 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004858 StringWriter sw = new StringWriter();
4859 PrintWriter pw = new PrintWriter(sw);
4860 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004861 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 }
4863 try {
4864 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4865 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004866 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 Parcel data = Parcel.obtain();
4868 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4869 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4870 data, null, 0);
4871 data.recycle();
4872 }
4873 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004874 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004875 }
4876 }
Romain Guy06882f82009-06-10 13:36:04 -07004877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004878 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004881 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4882 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 }
Romain Guy06882f82009-06-10 13:36:04 -07004884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004885 public void setInTouchMode(boolean mode) {
4886 synchronized(mWindowMap) {
4887 mInTouchMode = mode;
4888 }
4889 }
4890
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004891 // TODO: more accounting of which pid(s) turned it on, keep count,
4892 // only allow disables from pids which have count on, etc.
4893 public void showStrictModeViolation(boolean on) {
4894 int pid = Binder.getCallingPid();
4895 synchronized(mWindowMap) {
4896 // Ignoring requests to enable the red border from clients
4897 // which aren't on screen. (e.g. Broadcast Receivers in
4898 // the background..)
4899 if (on) {
4900 boolean isVisible = false;
4901 for (WindowState ws : mWindows) {
4902 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4903 isVisible = true;
4904 break;
4905 }
4906 }
4907 if (!isVisible) {
4908 return;
4909 }
4910 }
4911
4912 Surface.openTransaction();
4913 if (mStrictModeFlash == null) {
4914 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4915 }
4916 mStrictModeFlash.setVisibility(on);
4917 Surface.closeTransaction();
4918 }
4919 }
4920
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004921 public void setStrictModeVisualIndicatorPreference(String value) {
4922 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4923 }
4924
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004925 public void freezeRotation() {
4926 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4927 "setRotation()")) {
4928 throw new SecurityException("Requires SET_ORIENTATION permission");
4929 }
4930
4931 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4932 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4933 }
4934
4935 public void thawRotation() {
4936 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4937 "setRotation()")) {
4938 throw new SecurityException("Requires SET_ORIENTATION permission");
4939 }
4940
4941 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4942 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4943 }
4944
Romain Guy06882f82009-06-10 13:36:04 -07004945 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004946 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004948 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004949 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 }
4951
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004952 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953 }
Romain Guy06882f82009-06-10 13:36:04 -07004954
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004955 public void setRotationUnchecked(int rotation,
4956 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004957 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004958 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004960 long origId = Binder.clearCallingIdentity();
4961 boolean changed;
4962 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004963 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 }
Romain Guy06882f82009-06-10 13:36:04 -07004965
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004966 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004967 sendNewConfiguration();
4968 }
Romain Guy06882f82009-06-10 13:36:04 -07004969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004970 Binder.restoreCallingIdentity(origId);
4971 }
Romain Guy06882f82009-06-10 13:36:04 -07004972
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004973 /**
4974 * Apply a new rotation to the screen, respecting the requests of
4975 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4976 * re-evaluate the desired rotation.
4977 *
4978 * Returns null if the rotation has been changed. In this case YOU
4979 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4980 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004981 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982 boolean changed;
4983 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4984 rotation = mRequestedRotation;
4985 } else {
4986 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004987 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004988 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004989 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004990 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004991 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004992 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004993 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004995 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004996 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004997 "Rotation changed to " + rotation
4998 + " from " + mRotation
4999 + " (forceApp=" + mForcedAppOrientation
5000 + ", req=" + mRequestedRotation + ")");
5001 mRotation = rotation;
5002 mWindowsFreezingScreen = true;
5003 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5004 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5005 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005006 mWaitingForConfig = true;
5007 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005008 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005009 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005010 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005011 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005012 if (CUSTOM_SCREEN_ROTATION) {
5013 Surface.freezeDisplay(0);
5014 Surface.openTransaction();
5015 if (mScreenRotationAnimation != null) {
5016 mScreenRotationAnimation.setRotation(rotation);
5017 }
5018 Surface.closeTransaction();
5019 Surface.setOrientation(0, rotation, animFlags);
5020 Surface.unfreezeDisplay(0);
5021 } else {
5022 Surface.setOrientation(0, rotation, animFlags);
5023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005024 }
5025 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005026 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005027 if (w.mSurface != null) {
5028 w.mOrientationChanging = true;
5029 }
5030 }
5031 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5032 try {
5033 mRotationWatchers.get(i).onRotationChanged(rotation);
5034 } catch (RemoteException e) {
5035 }
5036 }
5037 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005039 return changed;
5040 }
Romain Guy06882f82009-06-10 13:36:04 -07005041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005042 public int getRotation() {
5043 return mRotation;
5044 }
5045
5046 public int watchRotation(IRotationWatcher watcher) {
5047 final IBinder watcherBinder = watcher.asBinder();
5048 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5049 public void binderDied() {
5050 synchronized (mWindowMap) {
5051 for (int i=0; i<mRotationWatchers.size(); i++) {
5052 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005053 IRotationWatcher removed = mRotationWatchers.remove(i);
5054 if (removed != null) {
5055 removed.asBinder().unlinkToDeath(this, 0);
5056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005057 i--;
5058 }
5059 }
5060 }
5061 }
5062 };
Romain Guy06882f82009-06-10 13:36:04 -07005063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005064 synchronized (mWindowMap) {
5065 try {
5066 watcher.asBinder().linkToDeath(dr, 0);
5067 mRotationWatchers.add(watcher);
5068 } catch (RemoteException e) {
5069 // Client died, no cleanup needed.
5070 }
Romain Guy06882f82009-06-10 13:36:04 -07005071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005072 return mRotation;
5073 }
5074 }
5075
5076 /**
5077 * Starts the view server on the specified port.
5078 *
5079 * @param port The port to listener to.
5080 *
5081 * @return True if the server was successfully started, false otherwise.
5082 *
5083 * @see com.android.server.ViewServer
5084 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5085 */
5086 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005087 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005088 return false;
5089 }
5090
5091 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5092 return false;
5093 }
5094
5095 if (port < 1024) {
5096 return false;
5097 }
5098
5099 if (mViewServer != null) {
5100 if (!mViewServer.isRunning()) {
5101 try {
5102 return mViewServer.start();
5103 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005104 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005105 }
5106 }
5107 return false;
5108 }
5109
5110 try {
5111 mViewServer = new ViewServer(this, port);
5112 return mViewServer.start();
5113 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005114 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005115 }
5116 return false;
5117 }
5118
Romain Guy06882f82009-06-10 13:36:04 -07005119 private boolean isSystemSecure() {
5120 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5121 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5122 }
5123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 /**
5125 * Stops the view server if it exists.
5126 *
5127 * @return True if the server stopped, false if it wasn't started or
5128 * couldn't be stopped.
5129 *
5130 * @see com.android.server.ViewServer
5131 */
5132 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005133 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005134 return false;
5135 }
5136
5137 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5138 return false;
5139 }
5140
5141 if (mViewServer != null) {
5142 return mViewServer.stop();
5143 }
5144 return false;
5145 }
5146
5147 /**
5148 * Indicates whether the view server is running.
5149 *
5150 * @return True if the server is running, false otherwise.
5151 *
5152 * @see com.android.server.ViewServer
5153 */
5154 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005155 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005156 return false;
5157 }
5158
5159 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5160 return false;
5161 }
5162
5163 return mViewServer != null && mViewServer.isRunning();
5164 }
5165
5166 /**
5167 * Lists all availble windows in the system. The listing is written in the
5168 * specified Socket's output stream with the following syntax:
5169 * windowHashCodeInHexadecimal windowName
5170 * Each line of the ouput represents a different window.
5171 *
5172 * @param client The remote client to send the listing to.
5173 * @return False if an error occured, true otherwise.
5174 */
5175 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005176 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005177 return false;
5178 }
5179
5180 boolean result = true;
5181
Jeff Browne33348b2010-07-15 23:54:05 -07005182 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005183 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005185 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005186 }
5187
5188 BufferedWriter out = null;
5189
5190 // Any uncaught exception will crash the system process
5191 try {
5192 OutputStream clientStream = client.getOutputStream();
5193 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5194
5195 final int count = windows.length;
5196 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005197 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005198 out.write(Integer.toHexString(System.identityHashCode(w)));
5199 out.write(' ');
5200 out.append(w.mAttrs.getTitle());
5201 out.write('\n');
5202 }
5203
5204 out.write("DONE.\n");
5205 out.flush();
5206 } catch (Exception e) {
5207 result = false;
5208 } finally {
5209 if (out != null) {
5210 try {
5211 out.close();
5212 } catch (IOException e) {
5213 result = false;
5214 }
5215 }
5216 }
5217
5218 return result;
5219 }
5220
5221 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005222 * Returns the focused window in the following format:
5223 * windowHashCodeInHexadecimal windowName
5224 *
5225 * @param client The remote client to send the listing to.
5226 * @return False if an error occurred, true otherwise.
5227 */
5228 boolean viewServerGetFocusedWindow(Socket client) {
5229 if (isSystemSecure()) {
5230 return false;
5231 }
5232
5233 boolean result = true;
5234
5235 WindowState focusedWindow = getFocusedWindow();
5236
5237 BufferedWriter out = null;
5238
5239 // Any uncaught exception will crash the system process
5240 try {
5241 OutputStream clientStream = client.getOutputStream();
5242 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5243
5244 if(focusedWindow != null) {
5245 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5246 out.write(' ');
5247 out.append(focusedWindow.mAttrs.getTitle());
5248 }
5249 out.write('\n');
5250 out.flush();
5251 } catch (Exception e) {
5252 result = false;
5253 } finally {
5254 if (out != null) {
5255 try {
5256 out.close();
5257 } catch (IOException e) {
5258 result = false;
5259 }
5260 }
5261 }
5262
5263 return result;
5264 }
5265
5266 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005267 * Sends a command to a target window. The result of the command, if any, will be
5268 * written in the output stream of the specified socket.
5269 *
5270 * The parameters must follow this syntax:
5271 * windowHashcode extra
5272 *
5273 * Where XX is the length in characeters of the windowTitle.
5274 *
5275 * The first parameter is the target window. The window with the specified hashcode
5276 * will be the target. If no target can be found, nothing happens. The extra parameters
5277 * will be delivered to the target window and as parameters to the command itself.
5278 *
5279 * @param client The remote client to sent the result, if any, to.
5280 * @param command The command to execute.
5281 * @param parameters The command parameters.
5282 *
5283 * @return True if the command was successfully delivered, false otherwise. This does
5284 * not indicate whether the command itself was successful.
5285 */
5286 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005287 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005288 return false;
5289 }
5290
5291 boolean success = true;
5292 Parcel data = null;
5293 Parcel reply = null;
5294
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005295 BufferedWriter out = null;
5296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005297 // Any uncaught exception will crash the system process
5298 try {
5299 // Find the hashcode of the window
5300 int index = parameters.indexOf(' ');
5301 if (index == -1) {
5302 index = parameters.length();
5303 }
5304 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005305 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005306
5307 // Extract the command's parameter after the window description
5308 if (index < parameters.length()) {
5309 parameters = parameters.substring(index + 1);
5310 } else {
5311 parameters = "";
5312 }
5313
5314 final WindowManagerService.WindowState window = findWindow(hashCode);
5315 if (window == null) {
5316 return false;
5317 }
5318
5319 data = Parcel.obtain();
5320 data.writeInterfaceToken("android.view.IWindow");
5321 data.writeString(command);
5322 data.writeString(parameters);
5323 data.writeInt(1);
5324 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5325
5326 reply = Parcel.obtain();
5327
5328 final IBinder binder = window.mClient.asBinder();
5329 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5330 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5331
5332 reply.readException();
5333
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005334 if (!client.isOutputShutdown()) {
5335 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5336 out.write("DONE\n");
5337 out.flush();
5338 }
5339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005340 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005341 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005342 success = false;
5343 } finally {
5344 if (data != null) {
5345 data.recycle();
5346 }
5347 if (reply != null) {
5348 reply.recycle();
5349 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005350 if (out != null) {
5351 try {
5352 out.close();
5353 } catch (IOException e) {
5354
5355 }
5356 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005357 }
5358
5359 return success;
5360 }
5361
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005362 public void addWindowChangeListener(WindowChangeListener listener) {
5363 synchronized(mWindowMap) {
5364 mWindowChangeListeners.add(listener);
5365 }
5366 }
5367
5368 public void removeWindowChangeListener(WindowChangeListener listener) {
5369 synchronized(mWindowMap) {
5370 mWindowChangeListeners.remove(listener);
5371 }
5372 }
5373
5374 private void notifyWindowsChanged() {
5375 WindowChangeListener[] windowChangeListeners;
5376 synchronized(mWindowMap) {
5377 if(mWindowChangeListeners.isEmpty()) {
5378 return;
5379 }
5380 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5381 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5382 }
5383 int N = windowChangeListeners.length;
5384 for(int i = 0; i < N; i++) {
5385 windowChangeListeners[i].windowsChanged();
5386 }
5387 }
5388
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005389 private void notifyFocusChanged() {
5390 WindowChangeListener[] windowChangeListeners;
5391 synchronized(mWindowMap) {
5392 if(mWindowChangeListeners.isEmpty()) {
5393 return;
5394 }
5395 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5396 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5397 }
5398 int N = windowChangeListeners.length;
5399 for(int i = 0; i < N; i++) {
5400 windowChangeListeners[i].focusChanged();
5401 }
5402 }
5403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005404 private WindowState findWindow(int hashCode) {
5405 if (hashCode == -1) {
5406 return getFocusedWindow();
5407 }
5408
5409 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005410 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005411 final int count = windows.size();
5412
5413 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005414 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005415 if (System.identityHashCode(w) == hashCode) {
5416 return w;
5417 }
5418 }
5419 }
5420
5421 return null;
5422 }
5423
5424 /*
5425 * Instruct the Activity Manager to fetch the current configuration and broadcast
5426 * that to config-changed listeners if appropriate.
5427 */
5428 void sendNewConfiguration() {
5429 try {
5430 mActivityManager.updateConfiguration(null);
5431 } catch (RemoteException e) {
5432 }
5433 }
Romain Guy06882f82009-06-10 13:36:04 -07005434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005435 public Configuration computeNewConfiguration() {
5436 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005437 return computeNewConfigurationLocked();
5438 }
5439 }
Romain Guy06882f82009-06-10 13:36:04 -07005440
Dianne Hackbornc485a602009-03-24 22:39:49 -07005441 Configuration computeNewConfigurationLocked() {
5442 Configuration config = new Configuration();
5443 if (!computeNewConfigurationLocked(config)) {
5444 return null;
5445 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005446 return config;
5447 }
Romain Guy06882f82009-06-10 13:36:04 -07005448
Dianne Hackbornc485a602009-03-24 22:39:49 -07005449 boolean computeNewConfigurationLocked(Configuration config) {
5450 if (mDisplay == null) {
5451 return false;
5452 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005453
5454 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005455
5456 // Use the effective "visual" dimensions based on current rotation
5457 final boolean rotated = (mRotation == Surface.ROTATION_90
5458 || mRotation == Surface.ROTATION_270);
5459 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5460 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5461
Dianne Hackbornc485a602009-03-24 22:39:49 -07005462 int orientation = Configuration.ORIENTATION_SQUARE;
5463 if (dw < dh) {
5464 orientation = Configuration.ORIENTATION_PORTRAIT;
5465 } else if (dw > dh) {
5466 orientation = Configuration.ORIENTATION_LANDSCAPE;
5467 }
5468 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005469
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005470 DisplayMetrics dm = new DisplayMetrics();
5471 mDisplay.getMetrics(dm);
5472 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5473
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005474 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005475 // Note we only do this once because at this point we don't
5476 // expect the screen to change in this way at runtime, and want
5477 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005478 int longSize = dw;
5479 int shortSize = dh;
5480 if (longSize < shortSize) {
5481 int tmp = longSize;
5482 longSize = shortSize;
5483 shortSize = tmp;
5484 }
5485 longSize = (int)(longSize/dm.density);
5486 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005487
Dianne Hackborn723738c2009-06-25 19:48:04 -07005488 // These semi-magic numbers define our compatibility modes for
5489 // applications with different screens. Don't change unless you
5490 // make sure to test lots and lots of apps!
5491 if (longSize < 470) {
5492 // This is shorter than an HVGA normal density screen (which
5493 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005494 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5495 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005496 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005497 // What size is this screen screen?
5498 if (longSize >= 800 && shortSize >= 600) {
5499 // SVGA or larger screens at medium density are the point
5500 // at which we consider it to be an extra large screen.
5501 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005502 } else if (longSize >= 530 && shortSize >= 400) {
5503 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005504 // at which we consider it to be a large screen.
5505 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5506 } else {
5507 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005508
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005509 // If this screen is wider than normal HVGA, or taller
5510 // than FWVGA, then for old apps we want to run in size
5511 // compatibility mode.
5512 if (shortSize > 321 || longSize > 570) {
5513 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5514 }
5515 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005516
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005517 // Is this a long screen?
5518 if (((longSize*3)/5) >= (shortSize-1)) {
5519 // Anything wider than WVGA (5:3) is considering to be long.
5520 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5521 } else {
5522 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5523 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005524 }
5525 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005526 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005527
Dianne Hackbornc485a602009-03-24 22:39:49 -07005528 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5529 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5530 mPolicy.adjustConfigurationLw(config);
5531 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005532 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005533
5534 // -------------------------------------------------------------
5535 // Drag and drop
5536 // -------------------------------------------------------------
5537
5538 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5539 boolean localOnly, int width, int height, Surface outSurface) {
5540 if (DEBUG_DRAG) {
5541 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5542 + " local=" + localOnly + " win=" + window
5543 + " asbinder=" + window.asBinder());
5544 }
5545
5546 final int callerPid = Binder.getCallingPid();
5547 final long origId = Binder.clearCallingIdentity();
5548 IBinder token = null;
5549
5550 try {
5551 synchronized (mWindowMap) {
5552 try {
5553 // !!! TODO: fail if the given window does not currently have touch focus?
5554
5555 if (mDragState == null) {
5556 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5557 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5558 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005559 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005560 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005561 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005562 mDragState.mSurface = surface;
5563 mDragState.mLocalOnly = localOnly;
5564 token = mDragState.mToken = new Binder();
5565
5566 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005567 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5568 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005569 mH.sendMessageDelayed(msg, 5000);
5570 } else {
5571 Slog.w(TAG, "Drag already in progress");
5572 }
5573 } catch (Surface.OutOfResourcesException e) {
5574 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5575 if (mDragState != null) {
5576 mDragState.reset();
5577 mDragState = null;
5578 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005579 }
5580 }
5581 } finally {
5582 Binder.restoreCallingIdentity(origId);
5583 }
5584
5585 return token;
5586 }
5587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005588 // -------------------------------------------------------------
5589 // Input Events and Focus Management
5590 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005591
Jeff Brown349703e2010-06-22 01:27:15 -07005592 InputMonitor mInputMonitor = new InputMonitor();
5593
5594 /* Tracks the progress of input dispatch and ensures that input dispatch state
5595 * is kept in sync with changes in window focus, visibility, registration, and
5596 * other relevant Window Manager state transitions. */
5597 final class InputMonitor {
5598 // Current window with input focus for keys and other non-touch events. May be null.
5599 private WindowState mInputFocus;
5600
5601 // When true, prevents input dispatch from proceeding until set to false again.
5602 private boolean mInputDispatchFrozen;
5603
5604 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5605 private boolean mInputDispatchEnabled = true;
5606
5607 // Temporary list of windows information to provide to the input dispatcher.
5608 private InputWindowList mTempInputWindows = new InputWindowList();
5609
5610 // Temporary input application object to provide to the input dispatcher.
5611 private InputApplication mTempInputApplication = new InputApplication();
5612
5613 /* Notifies the window manager about a broken input channel.
5614 *
5615 * Called by the InputManager.
5616 */
5617 public void notifyInputChannelBroken(InputChannel inputChannel) {
5618 synchronized (mWindowMap) {
5619 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5620 if (windowState == null) {
5621 return; // irrelevant
5622 }
5623
5624 Slog.i(TAG, "WINDOW DIED " + windowState);
5625 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005626 }
5627 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005628
Jeff Brown519e0242010-09-15 15:18:56 -07005629 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005630 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005631 *
5632 * Called by the InputManager.
5633 */
Jeff Brown519e0242010-09-15 15:18:56 -07005634 public long notifyANR(Object token, InputChannel inputChannel) {
5635 AppWindowToken appWindowToken = null;
5636 if (inputChannel != null) {
5637 synchronized (mWindowMap) {
5638 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5639 if (windowState != null) {
5640 Slog.i(TAG, "Input event dispatching timed out sending to "
5641 + windowState.mAttrs.getTitle());
5642 appWindowToken = windowState.mAppToken;
5643 }
Jeff Brown349703e2010-06-22 01:27:15 -07005644 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005645 }
5646
Jeff Brown519e0242010-09-15 15:18:56 -07005647 if (appWindowToken == null && token != null) {
5648 appWindowToken = (AppWindowToken) token;
5649 Slog.i(TAG, "Input event dispatching timed out sending to application "
5650 + appWindowToken.stringName);
5651 }
Jeff Brown349703e2010-06-22 01:27:15 -07005652
Jeff Brown519e0242010-09-15 15:18:56 -07005653 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005654 try {
5655 // Notify the activity manager about the timeout and let it decide whether
5656 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005657 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005658 if (! abort) {
5659 // The activity manager declined to abort dispatching.
5660 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005661 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005662 }
Jeff Brown349703e2010-06-22 01:27:15 -07005663 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005664 }
5665 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005666 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005667 }
5668
Jeff Brown349703e2010-06-22 01:27:15 -07005669 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5670 synchronized (mWindowMap) {
5671 return getWindowStateForInputChannelLocked(inputChannel);
5672 }
5673 }
5674
5675 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5676 int windowCount = mWindows.size();
5677 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005678 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005679 if (windowState.mInputChannel == inputChannel) {
5680 return windowState;
5681 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005682 }
5683
Jeff Brown349703e2010-06-22 01:27:15 -07005684 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005685 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005686
Chris Tatea32dcf72010-10-14 12:13:50 -07005687 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005688 final InputWindow inputWindow = windowList.add();
5689 inputWindow.inputChannel = mDragState.mServerChannel;
5690 inputWindow.name = "drag";
5691 inputWindow.layoutParamsFlags = 0;
5692 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5693 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5694 inputWindow.visible = true;
5695 inputWindow.canReceiveKeys = false;
5696 inputWindow.hasFocus = true;
5697 inputWindow.hasWallpaper = false;
5698 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005699 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005700 inputWindow.ownerPid = Process.myPid();
5701 inputWindow.ownerUid = Process.myUid();
5702
5703 // The drag window covers the entire display
5704 inputWindow.frameLeft = 0;
5705 inputWindow.frameTop = 0;
5706 inputWindow.frameRight = mDisplay.getWidth();
5707 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005708
Christopher Tatea53146c2010-09-07 11:57:52 -07005709 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5710 inputWindow.visibleFrameTop = inputWindow.frameTop;
5711 inputWindow.visibleFrameRight = inputWindow.frameRight;
5712 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5713
5714 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5715 inputWindow.touchableAreaTop = inputWindow.frameTop;
5716 inputWindow.touchableAreaRight = inputWindow.frameRight;
5717 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5718 }
5719
Jeff Brown349703e2010-06-22 01:27:15 -07005720 /* Updates the cached window information provided to the input dispatcher. */
5721 public void updateInputWindowsLw() {
5722 // Populate the input window list with information about all of the windows that
5723 // could potentially receive input.
5724 // As an optimization, we could try to prune the list of windows but this turns
5725 // out to be difficult because only the native code knows for sure which window
5726 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005727 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005728
5729 // If there's a drag in flight, provide a pseudowindow to catch drag input
5730 final boolean inDrag = (mDragState != null);
5731 if (inDrag) {
5732 if (DEBUG_DRAG) {
5733 Log.d(TAG, "Inserting drag window");
5734 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005735 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005736 }
5737
Jeff Brown7fbdc842010-06-17 20:52:56 -07005738 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005739 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005740 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005741 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005742 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005743 continue;
5744 }
5745
Jeff Brown349703e2010-06-22 01:27:15 -07005746 final int flags = child.mAttrs.flags;
5747 final int type = child.mAttrs.type;
5748
5749 final boolean hasFocus = (child == mInputFocus);
5750 final boolean isVisible = child.isVisibleLw();
5751 final boolean hasWallpaper = (child == mWallpaperTarget)
5752 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005753
5754 // If there's a drag in progress and 'child' is a potential drop target,
5755 // make sure it's been told about the drag
5756 if (inDrag && isVisible) {
5757 mDragState.sendDragStartedIfNeededLw(child);
5758 }
5759
Jeff Brown349703e2010-06-22 01:27:15 -07005760 // Add a window to our list of input windows.
5761 final InputWindow inputWindow = mTempInputWindows.add();
5762 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005763 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005764 inputWindow.layoutParamsFlags = flags;
5765 inputWindow.layoutParamsType = type;
5766 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5767 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005768 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005769 inputWindow.hasFocus = hasFocus;
5770 inputWindow.hasWallpaper = hasWallpaper;
5771 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005772 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005773 inputWindow.ownerPid = child.mSession.mPid;
5774 inputWindow.ownerUid = child.mSession.mUid;
5775
5776 final Rect frame = child.mFrame;
5777 inputWindow.frameLeft = frame.left;
5778 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005779 inputWindow.frameRight = frame.right;
5780 inputWindow.frameBottom = frame.bottom;
5781
5782 final Rect visibleFrame = child.mVisibleFrame;
5783 inputWindow.visibleFrameLeft = visibleFrame.left;
5784 inputWindow.visibleFrameTop = visibleFrame.top;
5785 inputWindow.visibleFrameRight = visibleFrame.right;
5786 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005787
5788 switch (child.mTouchableInsets) {
5789 default:
5790 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5791 inputWindow.touchableAreaLeft = frame.left;
5792 inputWindow.touchableAreaTop = frame.top;
5793 inputWindow.touchableAreaRight = frame.right;
5794 inputWindow.touchableAreaBottom = frame.bottom;
5795 break;
5796
5797 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5798 Rect inset = child.mGivenContentInsets;
5799 inputWindow.touchableAreaLeft = frame.left + inset.left;
5800 inputWindow.touchableAreaTop = frame.top + inset.top;
5801 inputWindow.touchableAreaRight = frame.right - inset.right;
5802 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5803 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005804 }
Jeff Brown349703e2010-06-22 01:27:15 -07005805
5806 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5807 Rect inset = child.mGivenVisibleInsets;
5808 inputWindow.touchableAreaLeft = frame.left + inset.left;
5809 inputWindow.touchableAreaTop = frame.top + inset.top;
5810 inputWindow.touchableAreaRight = frame.right - inset.right;
5811 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005812 break;
5813 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005814 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005815 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005816
Jeff Brown349703e2010-06-22 01:27:15 -07005817 // Send windows to native code.
5818 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005819
Jeff Brown349703e2010-06-22 01:27:15 -07005820 // Clear the list in preparation for the next round.
5821 // Also avoids keeping InputChannel objects referenced unnecessarily.
5822 mTempInputWindows.clear();
5823 }
5824
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005825 /* Notifies that the lid switch changed state. */
5826 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5827 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5828 }
5829
Jeff Brown349703e2010-06-22 01:27:15 -07005830 /* Provides an opportunity for the window manager policy to intercept early key
5831 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005832 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5833 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5834 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5835 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005836 }
5837
5838 /* Provides an opportunity for the window manager policy to process a key before
5839 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005840 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005841 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005842 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005843 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005844 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005845 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005846 }
5847
Jeff Brown3915bb82010-11-05 15:02:16 -07005848 /* Provides an opportunity for the window manager policy to process a key that
5849 * the application did not handle. */
5850 public boolean dispatchUnhandledKey(InputChannel focus,
5851 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
5852 int policyFlags) {
5853 WindowState windowState = getWindowStateForInputChannel(focus);
5854 return mPolicy.dispatchUnhandledKey(windowState, action, flags,
5855 keyCode, scanCode, metaState, repeatCount, policyFlags);
5856 }
5857
Jeff Brown349703e2010-06-22 01:27:15 -07005858 /* Called when the current input focus changes.
5859 * Layer assignment is assumed to be complete by the time this is called.
5860 */
5861 public void setInputFocusLw(WindowState newWindow) {
5862 if (DEBUG_INPUT) {
5863 Slog.d(TAG, "Input focus has changed to " + newWindow);
5864 }
5865
5866 if (newWindow != mInputFocus) {
5867 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005868 // Displaying a window implicitly causes dispatching to be unpaused.
5869 // This is to protect against bugs if someone pauses dispatching but
5870 // forgets to resume.
5871 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005872 }
Jeff Brown349703e2010-06-22 01:27:15 -07005873
5874 mInputFocus = newWindow;
5875 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005876 }
5877 }
5878
Jeff Brown349703e2010-06-22 01:27:15 -07005879 public void setFocusedAppLw(AppWindowToken newApp) {
5880 // Focused app has changed.
5881 if (newApp == null) {
5882 mInputManager.setFocusedApplication(null);
5883 } else {
5884 mTempInputApplication.name = newApp.toString();
5885 mTempInputApplication.dispatchingTimeoutNanos =
5886 newApp.inputDispatchingTimeoutNanos;
5887 mTempInputApplication.token = newApp;
5888
5889 mInputManager.setFocusedApplication(mTempInputApplication);
5890 }
5891 }
5892
Jeff Brown349703e2010-06-22 01:27:15 -07005893 public void pauseDispatchingLw(WindowToken window) {
5894 if (! window.paused) {
5895 if (DEBUG_INPUT) {
5896 Slog.v(TAG, "Pausing WindowToken " + window);
5897 }
5898
5899 window.paused = true;
5900 updateInputWindowsLw();
5901 }
5902 }
5903
5904 public void resumeDispatchingLw(WindowToken window) {
5905 if (window.paused) {
5906 if (DEBUG_INPUT) {
5907 Slog.v(TAG, "Resuming WindowToken " + window);
5908 }
5909
5910 window.paused = false;
5911 updateInputWindowsLw();
5912 }
5913 }
5914
5915 public void freezeInputDispatchingLw() {
5916 if (! mInputDispatchFrozen) {
5917 if (DEBUG_INPUT) {
5918 Slog.v(TAG, "Freezing input dispatching");
5919 }
5920
5921 mInputDispatchFrozen = true;
5922 updateInputDispatchModeLw();
5923 }
5924 }
5925
5926 public void thawInputDispatchingLw() {
5927 if (mInputDispatchFrozen) {
5928 if (DEBUG_INPUT) {
5929 Slog.v(TAG, "Thawing input dispatching");
5930 }
5931
5932 mInputDispatchFrozen = false;
5933 updateInputDispatchModeLw();
5934 }
5935 }
5936
5937 public void setEventDispatchingLw(boolean enabled) {
5938 if (mInputDispatchEnabled != enabled) {
5939 if (DEBUG_INPUT) {
5940 Slog.v(TAG, "Setting event dispatching to " + enabled);
5941 }
5942
5943 mInputDispatchEnabled = enabled;
5944 updateInputDispatchModeLw();
5945 }
5946 }
5947
5948 private void updateInputDispatchModeLw() {
5949 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5950 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005953 public void pauseKeyDispatching(IBinder _token) {
5954 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5955 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005956 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005957 }
5958
5959 synchronized (mWindowMap) {
5960 WindowToken token = mTokenMap.get(_token);
5961 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005962 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963 }
5964 }
5965 }
5966
5967 public void resumeKeyDispatching(IBinder _token) {
5968 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5969 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005970 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 }
5972
5973 synchronized (mWindowMap) {
5974 WindowToken token = mTokenMap.get(_token);
5975 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005976 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005977 }
5978 }
5979 }
5980
5981 public void setEventDispatching(boolean enabled) {
5982 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5983 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005984 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005985 }
5986
5987 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005988 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005989 }
5990 }
Romain Guy06882f82009-06-10 13:36:04 -07005991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005992 /**
5993 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005994 * Even when sync is false, this method may block while waiting for current
5995 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005996 *
5997 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005998 * {@link SystemClock#uptimeMillis()} as the timebase.)
5999 * @param sync If true, wait for the event to be completed before returning to the caller.
6000 * @return Returns true if event was dispatched, false if it was dropped for any reason
6001 */
6002 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6003 long downTime = ev.getDownTime();
6004 long eventTime = ev.getEventTime();
6005
6006 int action = ev.getAction();
6007 int code = ev.getKeyCode();
6008 int repeatCount = ev.getRepeatCount();
6009 int metaState = ev.getMetaState();
6010 int deviceId = ev.getDeviceId();
6011 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006012 int source = ev.getSource();
6013
6014 if (source == InputDevice.SOURCE_UNKNOWN) {
6015 source = InputDevice.SOURCE_KEYBOARD;
6016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017
6018 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6019 if (downTime == 0) downTime = eventTime;
6020
6021 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07006022 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006023
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006024 final int pid = Binder.getCallingPid();
6025 final int uid = Binder.getCallingUid();
6026 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006027
Jeff Brownbbda99d2010-07-28 15:48:59 -07006028 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6029 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6030 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6031 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006032
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006033 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006034 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006035 }
6036
6037 /**
6038 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006039 * Even when sync is false, this method may block while waiting for current
6040 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006041 *
6042 * @param ev A motion event describing the pointer (touch) action. (As noted in
6043 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006044 * {@link SystemClock#uptimeMillis()} as the timebase.)
6045 * @param sync If true, wait for the event to be completed before returning to the caller.
6046 * @return Returns true if event was dispatched, false if it was dropped for any reason
6047 */
6048 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006049 final int pid = Binder.getCallingPid();
6050 final int uid = Binder.getCallingUid();
6051 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006052
Jeff Brownc5ed5912010-07-14 18:48:53 -07006053 MotionEvent newEvent = MotionEvent.obtain(ev);
6054 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6055 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6056 }
6057
Jeff Brownbbda99d2010-07-28 15:48:59 -07006058 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6059 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6060 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6061 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006062
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006063 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006064 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006065 }
Romain Guy06882f82009-06-10 13:36:04 -07006066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006067 /**
6068 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006069 * Even when sync is false, this method may block while waiting for current
6070 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006071 *
6072 * @param ev A motion event describing the trackball action. (As noted in
6073 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006074 * {@link SystemClock#uptimeMillis()} as the timebase.)
6075 * @param sync If true, wait for the event to be completed before returning to the caller.
6076 * @return Returns true if event was dispatched, false if it was dropped for any reason
6077 */
6078 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006079 final int pid = Binder.getCallingPid();
6080 final int uid = Binder.getCallingUid();
6081 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006082
Jeff Brownc5ed5912010-07-14 18:48:53 -07006083 MotionEvent newEvent = MotionEvent.obtain(ev);
6084 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6085 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6086 }
6087
Jeff Brownbbda99d2010-07-28 15:48:59 -07006088 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6089 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6090 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6091 INJECTION_TIMEOUT_MILLIS);
6092
6093 Binder.restoreCallingIdentity(ident);
6094 return reportInjectionResult(result);
6095 }
6096
6097 /**
6098 * Inject an input event into the UI without waiting for dispatch to commence.
6099 * This variant is useful for fire-and-forget input event injection. It does not
6100 * block any longer than it takes to enqueue the input event.
6101 *
6102 * @param ev An input event. (Be sure to set the input source correctly.)
6103 * @return Returns true if event was dispatched, false if it was dropped for any reason
6104 */
6105 public boolean injectInputEventNoWait(InputEvent ev) {
6106 final int pid = Binder.getCallingPid();
6107 final int uid = Binder.getCallingUid();
6108 final long ident = Binder.clearCallingIdentity();
6109
6110 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6111 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6112 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-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);
6116 }
6117
6118 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006119 switch (result) {
6120 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6121 Slog.w(TAG, "Input event injection permission denied.");
6122 throw new SecurityException(
6123 "Injecting to another application requires INJECT_EVENTS permission");
6124 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006125 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006126 return true;
6127 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6128 Slog.w(TAG, "Input event injection timed out.");
6129 return false;
6130 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6131 default:
6132 Slog.w(TAG, "Input event injection failed.");
6133 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006135 }
Romain Guy06882f82009-06-10 13:36:04 -07006136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006137 private WindowState getFocusedWindow() {
6138 synchronized (mWindowMap) {
6139 return getFocusedWindowLocked();
6140 }
6141 }
6142
6143 private WindowState getFocusedWindowLocked() {
6144 return mCurrentFocus;
6145 }
Romain Guy06882f82009-06-10 13:36:04 -07006146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006147 public boolean detectSafeMode() {
6148 mSafeMode = mPolicy.detectSafeMode();
6149 return mSafeMode;
6150 }
Romain Guy06882f82009-06-10 13:36:04 -07006151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006152 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006153 synchronized(mWindowMap) {
6154 if (mDisplay != null) {
6155 throw new IllegalStateException("Display already initialized");
6156 }
6157 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6158 mDisplay = wm.getDefaultDisplay();
6159 mInitialDisplayWidth = mDisplay.getWidth();
6160 mInitialDisplayHeight = mDisplay.getHeight();
6161 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6162 }
6163
6164 try {
6165 mActivityManager.updateConfiguration(null);
6166 } catch (RemoteException e) {
6167 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006168
6169 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006170 }
6171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 // -------------------------------------------------------------
6173 // Client Session State
6174 // -------------------------------------------------------------
6175
6176 private final class Session extends IWindowSession.Stub
6177 implements IBinder.DeathRecipient {
6178 final IInputMethodClient mClient;
6179 final IInputContext mInputContext;
6180 final int mUid;
6181 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006182 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006183 SurfaceSession mSurfaceSession;
6184 int mNumWindow = 0;
6185 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 public Session(IInputMethodClient client, IInputContext inputContext) {
6188 mClient = client;
6189 mInputContext = inputContext;
6190 mUid = Binder.getCallingUid();
6191 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006192 StringBuilder sb = new StringBuilder();
6193 sb.append("Session{");
6194 sb.append(Integer.toHexString(System.identityHashCode(this)));
6195 sb.append(" uid ");
6196 sb.append(mUid);
6197 sb.append("}");
6198 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 synchronized (mWindowMap) {
6201 if (mInputMethodManager == null && mHaveInputMethods) {
6202 IBinder b = ServiceManager.getService(
6203 Context.INPUT_METHOD_SERVICE);
6204 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6205 }
6206 }
6207 long ident = Binder.clearCallingIdentity();
6208 try {
6209 // Note: it is safe to call in to the input method manager
6210 // here because we are not holding our lock.
6211 if (mInputMethodManager != null) {
6212 mInputMethodManager.addClient(client, inputContext,
6213 mUid, mPid);
6214 } else {
6215 client.setUsingInputMethod(false);
6216 }
6217 client.asBinder().linkToDeath(this, 0);
6218 } catch (RemoteException e) {
6219 // The caller has died, so we can just forget about this.
6220 try {
6221 if (mInputMethodManager != null) {
6222 mInputMethodManager.removeClient(client);
6223 }
6224 } catch (RemoteException ee) {
6225 }
6226 } finally {
6227 Binder.restoreCallingIdentity(ident);
6228 }
6229 }
Romain Guy06882f82009-06-10 13:36:04 -07006230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006231 @Override
6232 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6233 throws RemoteException {
6234 try {
6235 return super.onTransact(code, data, reply, flags);
6236 } catch (RuntimeException e) {
6237 // Log all 'real' exceptions thrown to the caller
6238 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006239 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006240 }
6241 throw e;
6242 }
6243 }
6244
6245 public void binderDied() {
6246 // Note: it is safe to call in to the input method manager
6247 // here because we are not holding our lock.
6248 try {
6249 if (mInputMethodManager != null) {
6250 mInputMethodManager.removeClient(mClient);
6251 }
6252 } catch (RemoteException e) {
6253 }
6254 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006255 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006256 mClientDead = true;
6257 killSessionLocked();
6258 }
6259 }
6260
6261 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006262 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6263 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6264 outInputChannel);
6265 }
6266
6267 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006269 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270 }
Romain Guy06882f82009-06-10 13:36:04 -07006271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006272 public void remove(IWindow window) {
6273 removeWindow(this, window);
6274 }
Romain Guy06882f82009-06-10 13:36:04 -07006275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006276 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6277 int requestedWidth, int requestedHeight, int viewFlags,
6278 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006279 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006280 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6281 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006282 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006283 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006284 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6285 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006286 }
Romain Guy06882f82009-06-10 13:36:04 -07006287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006288 public void setTransparentRegion(IWindow window, Region region) {
6289 setTransparentRegionWindow(this, window, region);
6290 }
Romain Guy06882f82009-06-10 13:36:04 -07006291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 public void setInsets(IWindow window, int touchableInsets,
6293 Rect contentInsets, Rect visibleInsets) {
6294 setInsetsWindow(this, window, touchableInsets, contentInsets,
6295 visibleInsets);
6296 }
Romain Guy06882f82009-06-10 13:36:04 -07006297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006298 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6299 getWindowDisplayFrame(this, window, outDisplayFrame);
6300 }
Romain Guy06882f82009-06-10 13:36:04 -07006301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006302 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006303 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006304 TAG, "IWindow finishDrawing called for " + window);
6305 finishDrawingWindow(this, window);
6306 }
6307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006308 public void setInTouchMode(boolean mode) {
6309 synchronized(mWindowMap) {
6310 mInTouchMode = mode;
6311 }
6312 }
6313
6314 public boolean getInTouchMode() {
6315 synchronized(mWindowMap) {
6316 return mInTouchMode;
6317 }
6318 }
6319
6320 public boolean performHapticFeedback(IWindow window, int effectId,
6321 boolean always) {
6322 synchronized(mWindowMap) {
6323 long ident = Binder.clearCallingIdentity();
6324 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006325 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006326 windowForClientLocked(this, window, true),
6327 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006328 } finally {
6329 Binder.restoreCallingIdentity(ident);
6330 }
6331 }
6332 }
Romain Guy06882f82009-06-10 13:36:04 -07006333
Christopher Tatea53146c2010-09-07 11:57:52 -07006334 /* Drag/drop */
6335 public IBinder prepareDrag(IWindow window, boolean localOnly,
6336 int width, int height, Surface outSurface) {
6337 return prepareDragSurface(window, mSurfaceSession, localOnly,
6338 width, height, outSurface);
6339 }
6340
6341 public boolean performDrag(IWindow window, IBinder dragToken,
6342 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6343 ClipData data) {
6344 if (DEBUG_DRAG) {
6345 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6346 }
6347
6348 synchronized (mWindowMap) {
6349 if (mDragState == null) {
6350 Slog.w(TAG, "No drag prepared");
6351 throw new IllegalStateException("performDrag() without prepareDrag()");
6352 }
6353
6354 if (dragToken != mDragState.mToken) {
6355 Slog.w(TAG, "Performing mismatched drag");
6356 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6357 }
6358
6359 WindowState callingWin = windowForClientLocked(null, window, false);
6360 if (callingWin == null) {
6361 Slog.w(TAG, "Bad requesting window " + window);
6362 return false; // !!! TODO: throw here?
6363 }
6364
6365 // !!! TODO: if input is not still focused on the initiating window, fail
6366 // the drag initiation (e.g. an alarm window popped up just as the application
6367 // called performDrag()
6368
6369 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6370
Christopher Tate2c095f32010-10-04 14:13:40 -07006371 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6372 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006373
Chris Tateb478f462010-10-15 16:02:26 -07006374 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6375 // the actual drag event dispatch stuff in the dragstate
6376
Christopher Tatea53146c2010-09-07 11:57:52 -07006377 mDragState.register();
6378 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006379 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6380 mDragState.mServerChannel)) {
6381 Slog.e(TAG, "Unable to transfer touch focus");
6382 mDragState.unregister();
6383 mDragState = null;
6384 mInputMonitor.updateInputWindowsLw();
6385 return false;
6386 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006387
6388 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006389 mDragState.mCurrentX = touchX;
6390 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006391 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006392
6393 // remember the thumb offsets for later
6394 mDragState.mThumbOffsetX = thumbCenterX;
6395 mDragState.mThumbOffsetY = thumbCenterY;
6396
6397 // Make the surface visible at the proper location
6398 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006399 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006400 try {
6401 surface.setPosition((int)(touchX - thumbCenterX),
6402 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006403 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006404 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006405 surface.show();
6406 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006407 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006408 }
6409 }
6410
6411 return true; // success!
6412 }
6413
Chris Tated4533f12010-10-19 15:15:08 -07006414 public void reportDropResult(IWindow window, boolean consumed) {
6415 IBinder token = window.asBinder();
6416 if (DEBUG_DRAG) {
6417 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6418 }
6419
6420 synchronized (mWindowMap) {
6421 if (mDragState.mToken != token) {
6422 Slog.w(TAG, "Invalid drop-result claim by " + window);
6423 throw new IllegalStateException("reportDropResult() by non-recipient");
6424 }
6425
6426 // The right window has responded, even if it's no longer around,
6427 // so be sure to halt the timeout even if the later WindowState
6428 // lookup fails.
6429 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6430
6431 WindowState callingWin = windowForClientLocked(null, window, false);
6432 if (callingWin == null) {
6433 Slog.w(TAG, "Bad result-reporting window " + window);
6434 return; // !!! TODO: throw here?
6435 }
6436
6437 mDragState.mDragResult = consumed;
6438 mDragState.endDragLw();
6439 }
6440 }
6441
Christopher Tatea53146c2010-09-07 11:57:52 -07006442 public void dragRecipientEntered(IWindow window) {
6443 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006444 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006445 }
6446 }
6447
6448 public void dragRecipientExited(IWindow window) {
6449 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006450 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006451 }
6452 }
6453
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006454 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006455 synchronized(mWindowMap) {
6456 long ident = Binder.clearCallingIdentity();
6457 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006458 setWindowWallpaperPositionLocked(
6459 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006460 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006461 } finally {
6462 Binder.restoreCallingIdentity(ident);
6463 }
6464 }
6465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006466
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006467 public void wallpaperOffsetsComplete(IBinder window) {
6468 WindowManagerService.this.wallpaperOffsetsComplete(window);
6469 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006470
Dianne Hackborn75804932009-10-20 20:15:20 -07006471 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6472 int z, Bundle extras, boolean sync) {
6473 synchronized(mWindowMap) {
6474 long ident = Binder.clearCallingIdentity();
6475 try {
6476 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006477 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006478 action, x, y, z, extras, sync);
6479 } finally {
6480 Binder.restoreCallingIdentity(ident);
6481 }
6482 }
6483 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006484
Dianne Hackborn75804932009-10-20 20:15:20 -07006485 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6486 WindowManagerService.this.wallpaperCommandComplete(window, result);
6487 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006489 void windowAddedLocked() {
6490 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006491 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 TAG, "First window added to " + this + ", creating SurfaceSession");
6493 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006494 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006495 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 mSessions.add(this);
6497 }
6498 mNumWindow++;
6499 }
6500
6501 void windowRemovedLocked() {
6502 mNumWindow--;
6503 killSessionLocked();
6504 }
Romain Guy06882f82009-06-10 13:36:04 -07006505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006506 void killSessionLocked() {
6507 if (mNumWindow <= 0 && mClientDead) {
6508 mSessions.remove(this);
6509 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006510 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 TAG, "Last window removed from " + this
6512 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006513 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006514 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 try {
6516 mSurfaceSession.kill();
6517 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006518 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 + mSurfaceSession + " in session " + this
6520 + ": " + e.toString());
6521 }
6522 mSurfaceSession = null;
6523 }
6524 }
6525 }
Romain Guy06882f82009-06-10 13:36:04 -07006526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006527 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006528 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6529 pw.print(" mClientDead="); pw.print(mClientDead);
6530 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 }
6532
6533 @Override
6534 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006535 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006536 }
6537 }
6538
6539 // -------------------------------------------------------------
6540 // Client Window State
6541 // -------------------------------------------------------------
6542
6543 private final class WindowState implements WindowManagerPolicy.WindowState {
6544 final Session mSession;
6545 final IWindow mClient;
6546 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006547 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 AppWindowToken mAppToken;
6549 AppWindowToken mTargetAppToken;
6550 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6551 final DeathRecipient mDeathRecipient;
6552 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006553 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006554 final int mBaseLayer;
6555 final int mSubLayer;
6556 final boolean mLayoutAttached;
6557 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006558 final boolean mIsWallpaper;
6559 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006560 int mViewVisibility;
6561 boolean mPolicyVisibility = true;
6562 boolean mPolicyVisibilityAfterAnim = true;
6563 boolean mAppFreezing;
6564 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006565 boolean mReportDestroySurface;
6566 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 boolean mAttachedHidden; // is our parent window hidden?
6568 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006569 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 int mRequestedWidth;
6571 int mRequestedHeight;
6572 int mLastRequestedWidth;
6573 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 int mLayer;
6575 int mAnimLayer;
6576 int mLastLayer;
6577 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006578 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006579 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006580
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006581 int mLayoutSeq = -1;
6582
6583 Configuration mConfiguration = null;
6584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 // Actual frame shown on-screen (may be modified by animation)
6586 final Rect mShownFrame = new Rect();
6587 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006589 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006590 * Set when we have changed the size of the surface, to know that
6591 * we must tell them application to resize (and thus redraw itself).
6592 */
6593 boolean mSurfaceResized;
6594
6595 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006596 * Insets that determine the actually visible area
6597 */
6598 final Rect mVisibleInsets = new Rect();
6599 final Rect mLastVisibleInsets = new Rect();
6600 boolean mVisibleInsetsChanged;
6601
6602 /**
6603 * Insets that are covered by system windows
6604 */
6605 final Rect mContentInsets = new Rect();
6606 final Rect mLastContentInsets = new Rect();
6607 boolean mContentInsetsChanged;
6608
6609 /**
6610 * Set to true if we are waiting for this window to receive its
6611 * given internal insets before laying out other windows based on it.
6612 */
6613 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 /**
6616 * These are the content insets that were given during layout for
6617 * this window, to be applied to windows behind it.
6618 */
6619 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006621 /**
6622 * These are the visible insets that were given during layout for
6623 * this window, to be applied to windows behind it.
6624 */
6625 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006627 /**
6628 * Flag indicating whether the touchable region should be adjusted by
6629 * the visible insets; if false the area outside the visible insets is
6630 * NOT touchable, so we must use those to adjust the frame during hit
6631 * tests.
6632 */
6633 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 // Current transformation being applied.
6636 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6637 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6638 float mHScale=1, mVScale=1;
6639 float mLastHScale=1, mLastVScale=1;
6640 final Matrix mTmpMatrix = new Matrix();
6641
6642 // "Real" frame that the application sees.
6643 final Rect mFrame = new Rect();
6644 final Rect mLastFrame = new Rect();
6645
6646 final Rect mContainingFrame = new Rect();
6647 final Rect mDisplayFrame = new Rect();
6648 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006649 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006650 final Rect mVisibleFrame = new Rect();
6651
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006652 boolean mContentChanged;
6653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654 float mShownAlpha = 1;
6655 float mAlpha = 1;
6656 float mLastAlpha = 1;
6657
6658 // Set to true if, when the window gets displayed, it should perform
6659 // an enter animation.
6660 boolean mEnterAnimationPending;
6661
6662 // Currently running animation.
6663 boolean mAnimating;
6664 boolean mLocalAnimating;
6665 Animation mAnimation;
6666 boolean mAnimationIsEntrance;
6667 boolean mHasTransformation;
6668 boolean mHasLocalTransformation;
6669 final Transformation mTransformation = new Transformation();
6670
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006671 // If a window showing a wallpaper: the requested offset for the
6672 // wallpaper; if a wallpaper window: the currently applied offset.
6673 float mWallpaperX = -1;
6674 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006675
6676 // If a window showing a wallpaper: what fraction of the offset
6677 // range corresponds to a full virtual screen.
6678 float mWallpaperXStep = -1;
6679 float mWallpaperYStep = -1;
6680
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006681 // Wallpaper windows: pixels offset based on above variables.
6682 int mXOffset;
6683 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006685 // This is set after IWindowSession.relayout() has been called at
6686 // least once for the window. It allows us to detect the situation
6687 // where we don't yet have a surface, but should have one soon, so
6688 // we can give the window focus before waiting for the relayout.
6689 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006691 // This is set after the Surface has been created but before the
6692 // window has been drawn. During this time the surface is hidden.
6693 boolean mDrawPending;
6694
6695 // This is set after the window has finished drawing for the first
6696 // time but before its surface is shown. The surface will be
6697 // displayed when the next layout is run.
6698 boolean mCommitDrawPending;
6699
6700 // This is set during the time after the window's drawing has been
6701 // committed, and before its surface is actually shown. It is used
6702 // to delay showing the surface until all windows in a token are ready
6703 // to be shown.
6704 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 // Set when the window has been shown in the screen the first time.
6707 boolean mHasDrawn;
6708
6709 // Currently running an exit animation?
6710 boolean mExiting;
6711
6712 // Currently on the mDestroySurface list?
6713 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 // Completely remove from window manager after exit animation?
6716 boolean mRemoveOnExit;
6717
6718 // Set when the orientation is changing and this window has not yet
6719 // been updated for the new orientation.
6720 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 // Is this window now (or just being) removed?
6723 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006724
Dianne Hackborn16064f92010-03-25 00:47:24 -07006725 // For debugging, this is the last information given to the surface flinger.
6726 boolean mSurfaceShown;
6727 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6728 int mSurfaceLayer;
6729 float mSurfaceAlpha;
6730
Jeff Brown46b9ac02010-04-22 18:58:52 -07006731 // Input channel
6732 InputChannel mInputChannel;
6733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 WindowState(Session s, IWindow c, WindowToken token,
6735 WindowState attachedWindow, WindowManager.LayoutParams a,
6736 int viewVisibility) {
6737 mSession = s;
6738 mClient = c;
6739 mToken = token;
6740 mAttrs.copyFrom(a);
6741 mViewVisibility = viewVisibility;
6742 DeathRecipient deathRecipient = new DeathRecipient();
6743 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006744 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 TAG, "Window " + this + " client=" + c.asBinder()
6746 + " token=" + token + " (" + mAttrs.token + ")");
6747 try {
6748 c.asBinder().linkToDeath(deathRecipient, 0);
6749 } catch (RemoteException e) {
6750 mDeathRecipient = null;
6751 mAttachedWindow = null;
6752 mLayoutAttached = false;
6753 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006754 mIsWallpaper = false;
6755 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006756 mBaseLayer = 0;
6757 mSubLayer = 0;
6758 return;
6759 }
6760 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6763 mAttrs.type <= LAST_SUB_WINDOW)) {
6764 // The multiplier here is to reserve space for multiple
6765 // windows in the same type layer.
6766 mBaseLayer = mPolicy.windowTypeToLayerLw(
6767 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6768 + TYPE_LAYER_OFFSET;
6769 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6770 mAttachedWindow = attachedWindow;
6771 mAttachedWindow.mChildWindows.add(this);
6772 mLayoutAttached = mAttrs.type !=
6773 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6774 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6775 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006776 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6777 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006778 } else {
6779 // The multiplier here is to reserve space for multiple
6780 // windows in the same type layer.
6781 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6782 * TYPE_LAYER_MULTIPLIER
6783 + TYPE_LAYER_OFFSET;
6784 mSubLayer = 0;
6785 mAttachedWindow = null;
6786 mLayoutAttached = false;
6787 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6788 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006789 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6790 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 }
6792
6793 WindowState appWin = this;
6794 while (appWin.mAttachedWindow != null) {
6795 appWin = mAttachedWindow;
6796 }
6797 WindowToken appToken = appWin.mToken;
6798 while (appToken.appWindowToken == null) {
6799 WindowToken parent = mTokenMap.get(appToken.token);
6800 if (parent == null || appToken == parent) {
6801 break;
6802 }
6803 appToken = parent;
6804 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006805 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 mAppToken = appToken.appWindowToken;
6807
6808 mSurface = null;
6809 mRequestedWidth = 0;
6810 mRequestedHeight = 0;
6811 mLastRequestedWidth = 0;
6812 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006813 mXOffset = 0;
6814 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 mLayer = 0;
6816 mAnimLayer = 0;
6817 mLastLayer = 0;
6818 }
6819
6820 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006821 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006822 TAG, "Attaching " + this + " token=" + mToken
6823 + ", list=" + mToken.windows);
6824 mSession.windowAddedLocked();
6825 }
6826
6827 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6828 mHaveFrame = true;
6829
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006830 final Rect container = mContainingFrame;
6831 container.set(pf);
6832
6833 final Rect display = mDisplayFrame;
6834 display.set(df);
6835
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006836 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006837 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006838 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6839 display.intersect(mCompatibleScreenFrame);
6840 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006841 }
6842
6843 final int pw = container.right - container.left;
6844 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845
6846 int w,h;
6847 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6848 w = mAttrs.width < 0 ? pw : mAttrs.width;
6849 h = mAttrs.height< 0 ? ph : mAttrs.height;
6850 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006851 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6852 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 }
Romain Guy06882f82009-06-10 13:36:04 -07006854
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006855 if (!mParentFrame.equals(pf)) {
6856 mParentFrame.set(pf);
6857 mContentChanged = true;
6858 }
6859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 final Rect content = mContentFrame;
6861 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006863 final Rect visible = mVisibleFrame;
6864 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006867 final int fw = frame.width();
6868 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6871 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6872
6873 Gravity.apply(mAttrs.gravity, w, h, container,
6874 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6875 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6876
6877 //System.out.println("Out: " + mFrame);
6878
6879 // Now make sure the window fits in the overall display.
6880 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006882 // Make sure the content and visible frames are inside of the
6883 // final window frame.
6884 if (content.left < frame.left) content.left = frame.left;
6885 if (content.top < frame.top) content.top = frame.top;
6886 if (content.right > frame.right) content.right = frame.right;
6887 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6888 if (visible.left < frame.left) visible.left = frame.left;
6889 if (visible.top < frame.top) visible.top = frame.top;
6890 if (visible.right > frame.right) visible.right = frame.right;
6891 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 final Rect contentInsets = mContentInsets;
6894 contentInsets.left = content.left-frame.left;
6895 contentInsets.top = content.top-frame.top;
6896 contentInsets.right = frame.right-content.right;
6897 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006899 final Rect visibleInsets = mVisibleInsets;
6900 visibleInsets.left = visible.left-frame.left;
6901 visibleInsets.top = visible.top-frame.top;
6902 visibleInsets.right = frame.right-visible.right;
6903 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006904
Dianne Hackborn284ac932009-08-28 10:34:25 -07006905 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6906 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006907 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006910 if (localLOGV) {
6911 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6912 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006913 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 + mRequestedWidth + ", mRequestedheight="
6915 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6916 + "): frame=" + mFrame.toShortString()
6917 + " ci=" + contentInsets.toShortString()
6918 + " vi=" + visibleInsets.toShortString());
6919 //}
6920 }
6921 }
Romain Guy06882f82009-06-10 13:36:04 -07006922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006923 public Rect getFrameLw() {
6924 return mFrame;
6925 }
6926
6927 public Rect getShownFrameLw() {
6928 return mShownFrame;
6929 }
6930
6931 public Rect getDisplayFrameLw() {
6932 return mDisplayFrame;
6933 }
6934
6935 public Rect getContentFrameLw() {
6936 return mContentFrame;
6937 }
6938
6939 public Rect getVisibleFrameLw() {
6940 return mVisibleFrame;
6941 }
6942
6943 public boolean getGivenInsetsPendingLw() {
6944 return mGivenInsetsPending;
6945 }
6946
6947 public Rect getGivenContentInsetsLw() {
6948 return mGivenContentInsets;
6949 }
Romain Guy06882f82009-06-10 13:36:04 -07006950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951 public Rect getGivenVisibleInsetsLw() {
6952 return mGivenVisibleInsets;
6953 }
Romain Guy06882f82009-06-10 13:36:04 -07006954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 public WindowManager.LayoutParams getAttrs() {
6956 return mAttrs;
6957 }
6958
6959 public int getSurfaceLayer() {
6960 return mLayer;
6961 }
Romain Guy06882f82009-06-10 13:36:04 -07006962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 public IApplicationToken getAppToken() {
6964 return mAppToken != null ? mAppToken.appToken : null;
6965 }
Jeff Brown349703e2010-06-22 01:27:15 -07006966
6967 public long getInputDispatchingTimeoutNanos() {
6968 return mAppToken != null
6969 ? mAppToken.inputDispatchingTimeoutNanos
6970 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6971 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006972
6973 public boolean hasAppShownWindows() {
6974 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6975 }
6976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006978 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006979 TAG, "Setting animation in " + this + ": " + anim);
6980 mAnimating = false;
6981 mLocalAnimating = false;
6982 mAnimation = anim;
6983 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6984 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6985 }
6986
6987 public void clearAnimation() {
6988 if (mAnimation != null) {
6989 mAnimating = true;
6990 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07006991 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006992 mAnimation = null;
6993 }
6994 }
Romain Guy06882f82009-06-10 13:36:04 -07006995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006996 Surface createSurfaceLocked() {
6997 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006998 mReportDestroySurface = false;
6999 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007000 mDrawPending = true;
7001 mCommitDrawPending = false;
7002 mReadyToShow = false;
7003 if (mAppToken != null) {
7004 mAppToken.allDrawn = false;
7005 }
7006
7007 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007008 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 flags |= Surface.PUSH_BUFFERS;
7010 }
7011
7012 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7013 flags |= Surface.SECURE;
7014 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007015 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007016 TAG, "Creating surface in session "
7017 + mSession.mSurfaceSession + " window " + this
7018 + " w=" + mFrame.width()
7019 + " h=" + mFrame.height() + " format="
7020 + mAttrs.format + " flags=" + flags);
7021
7022 int w = mFrame.width();
7023 int h = mFrame.height();
7024 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7025 // for a scaled surface, we always want the requested
7026 // size.
7027 w = mRequestedWidth;
7028 h = mRequestedHeight;
7029 }
7030
Romain Guy9825ec62009-10-01 00:58:09 -07007031 // Something is wrong and SurfaceFlinger will not like this,
7032 // try to revert to sane values
7033 if (w <= 0) w = 1;
7034 if (h <= 0) h = 1;
7035
Dianne Hackborn16064f92010-03-25 00:47:24 -07007036 mSurfaceShown = false;
7037 mSurfaceLayer = 0;
7038 mSurfaceAlpha = 1;
7039 mSurfaceX = 0;
7040 mSurfaceY = 0;
7041 mSurfaceW = w;
7042 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007043 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007044 final boolean isHwAccelerated = (mAttrs.flags &
7045 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7046 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7047 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7048 flags |= Surface.OPAQUE;
7049 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007050 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007051 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007052 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007053 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007054 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007055 + mSurface + " IN SESSION "
7056 + mSession.mSurfaceSession
7057 + ": pid=" + mSession.mPid + " format="
7058 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007059 + Integer.toHexString(flags)
7060 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007062 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 reclaimSomeSurfaceMemoryLocked(this, "create");
7064 return null;
7065 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007066 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 return null;
7068 }
Romain Guy06882f82009-06-10 13:36:04 -07007069
Joe Onorato8a9b2202010-02-26 18:56:32 -08007070 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007071 TAG, "Got surface: " + mSurface
7072 + ", set left=" + mFrame.left + " top=" + mFrame.top
7073 + ", animLayer=" + mAnimLayer);
7074 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007075 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007076 if (SHOW_TRANSACTIONS) logSurface(this,
7077 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7078 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7079 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007080 }
7081 Surface.openTransaction();
7082 try {
7083 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007084 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007085 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007086 mSurface.setPosition(mSurfaceX, mSurfaceY);
7087 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007088 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007089 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 mSurface.hide();
7091 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007092 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007093 mSurface.setFlags(Surface.SURFACE_DITHER,
7094 Surface.SURFACE_DITHER);
7095 }
7096 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007097 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007098 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7099 }
7100 mLastHidden = true;
7101 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007102 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 Surface.closeTransaction();
7104 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007105 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 TAG, "Created surface " + this);
7107 }
7108 return mSurface;
7109 }
Romain Guy06882f82009-06-10 13:36:04 -07007110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007112 if (mAppToken != null && this == mAppToken.startingWindow) {
7113 mAppToken.startingDisplayed = false;
7114 }
Romain Guy06882f82009-06-10 13:36:04 -07007115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007116 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007117 mDrawPending = false;
7118 mCommitDrawPending = false;
7119 mReadyToShow = false;
7120
7121 int i = mChildWindows.size();
7122 while (i > 0) {
7123 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007124 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007125 c.mAttachedHidden = true;
7126 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007127
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007128 if (mReportDestroySurface) {
7129 mReportDestroySurface = false;
7130 mSurfacePendingDestroy = true;
7131 try {
7132 mClient.dispatchGetNewSurface();
7133 // We'll really destroy on the next time around.
7134 return;
7135 } catch (RemoteException e) {
7136 }
7137 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007139 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007140 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007141 RuntimeException e = null;
7142 if (!HIDE_STACK_CRAWLS) {
7143 e = new RuntimeException();
7144 e.fillInStackTrace();
7145 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007146 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007147 + mSurface + ", session " + mSession, e);
7148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007150 RuntimeException e = null;
7151 if (!HIDE_STACK_CRAWLS) {
7152 e = new RuntimeException();
7153 e.fillInStackTrace();
7154 }
7155 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007156 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007157 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007158 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007159 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007160 + " surface " + mSurface + " session " + mSession
7161 + ": " + e.toString());
7162 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007163
Dianne Hackborn16064f92010-03-25 00:47:24 -07007164 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007166 }
7167 }
7168
7169 boolean finishDrawingLocked() {
7170 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007171 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007172 TAG, "finishDrawingLocked: " + mSurface);
7173 mCommitDrawPending = true;
7174 mDrawPending = false;
7175 return true;
7176 }
7177 return false;
7178 }
7179
7180 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007181 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007182 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007183 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007184 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007185 }
7186 mCommitDrawPending = false;
7187 mReadyToShow = true;
7188 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7189 final AppWindowToken atoken = mAppToken;
7190 if (atoken == null || atoken.allDrawn || starting) {
7191 performShowLocked();
7192 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007193 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 }
7195
7196 // This must be called while inside a transaction.
7197 boolean performShowLocked() {
7198 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007199 RuntimeException e = null;
7200 if (!HIDE_STACK_CRAWLS) {
7201 e = new RuntimeException();
7202 e.fillInStackTrace();
7203 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007204 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7206 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7207 }
7208 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007209 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7210 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007211 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007212 + " during animation: policyVis=" + mPolicyVisibility
7213 + " attHidden=" + mAttachedHidden
7214 + " tok.hiddenRequested="
7215 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007216 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007217 + (mAppToken != null ? mAppToken.hidden : false)
7218 + " animating=" + mAnimating
7219 + " tok animating="
7220 + (mAppToken != null ? mAppToken.animating : false));
7221 if (!showSurfaceRobustlyLocked(this)) {
7222 return false;
7223 }
7224 mLastAlpha = -1;
7225 mHasDrawn = true;
7226 mLastHidden = false;
7227 mReadyToShow = false;
7228 enableScreenIfNeededLocked();
7229
7230 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 int i = mChildWindows.size();
7233 while (i > 0) {
7234 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007235 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007236 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007237 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007238 if (c.mSurface != null) {
7239 c.performShowLocked();
7240 // It hadn't been shown, which means layout not
7241 // performed on it, so now we want to make sure to
7242 // do a layout. If called from within the transaction
7243 // loop, this will cause it to restart with a new
7244 // layout.
7245 mLayoutNeeded = true;
7246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007247 }
7248 }
Romain Guy06882f82009-06-10 13:36:04 -07007249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007250 if (mAttrs.type != TYPE_APPLICATION_STARTING
7251 && mAppToken != null) {
7252 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007253
Dianne Hackborn248b1882009-09-16 16:46:44 -07007254 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007255 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007256 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007257 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007258 // If this initial window is animating, stop it -- we
7259 // will do an animation to reveal it from behind the
7260 // starting window, so there is no need for it to also
7261 // be doing its own stuff.
7262 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007263 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007264 mAnimation = null;
7265 // Make sure we clean up the animation.
7266 mAnimating = true;
7267 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 mFinishedStarting.add(mAppToken);
7269 mH.sendEmptyMessage(H.FINISHED_STARTING);
7270 }
7271 mAppToken.updateReportedVisibilityLocked();
7272 }
7273 }
7274 return true;
7275 }
Romain Guy06882f82009-06-10 13:36:04 -07007276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007277 // This must be called while inside a transaction. Returns true if
7278 // there is more animation to run.
7279 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007280 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007281 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7284 mHasTransformation = true;
7285 mHasLocalTransformation = true;
7286 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007287 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007288 TAG, "Starting animation in " + this +
7289 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7290 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7291 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7292 mAnimation.setStartTime(currentTime);
7293 mLocalAnimating = true;
7294 mAnimating = true;
7295 }
7296 mTransformation.clear();
7297 final boolean more = mAnimation.getTransformation(
7298 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007299 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 TAG, "Stepped animation in " + this +
7301 ": more=" + more + ", xform=" + mTransformation);
7302 if (more) {
7303 // we're not done!
7304 return true;
7305 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007306 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007307 TAG, "Finished animation in " + this +
7308 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007309
7310 if (mAnimation != null) {
7311 mAnimation.cancel();
7312 mAnimation = null;
7313 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007314 //WindowManagerService.this.dump();
7315 }
7316 mHasLocalTransformation = false;
7317 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007318 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007319 // When our app token is animating, we kind-of pretend like
7320 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7321 // part of this check means that we will only do this if
7322 // our window is not currently exiting, or it is not
7323 // locally animating itself. The idea being that one that
7324 // is exiting and doing a local animation should be removed
7325 // once that animation is done.
7326 mAnimating = true;
7327 mHasTransformation = true;
7328 mTransformation.clear();
7329 return false;
7330 } else if (mHasTransformation) {
7331 // Little trick to get through the path below to act like
7332 // we have finished an animation.
7333 mAnimating = true;
7334 } else if (isAnimating()) {
7335 mAnimating = true;
7336 }
7337 } else if (mAnimation != null) {
7338 // If the display is frozen, and there is a pending animation,
7339 // clear it and make sure we run the cleanup code.
7340 mAnimating = true;
7341 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007342 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 mAnimation = null;
7344 }
Romain Guy06882f82009-06-10 13:36:04 -07007345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 if (!mAnimating && !mLocalAnimating) {
7347 return false;
7348 }
7349
Joe Onorato8a9b2202010-02-26 18:56:32 -08007350 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007351 TAG, "Animation done in " + this + ": exiting=" + mExiting
7352 + ", reportedVisible="
7353 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007355 mAnimating = false;
7356 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007357 if (mAnimation != null) {
7358 mAnimation.cancel();
7359 mAnimation = null;
7360 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007361 mAnimLayer = mLayer;
7362 if (mIsImWindow) {
7363 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007364 } else if (mIsWallpaper) {
7365 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007366 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007367 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 + " anim layer: " + mAnimLayer);
7369 mHasTransformation = false;
7370 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007371 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7372 if (DEBUG_VISIBILITY) {
7373 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7374 + mPolicyVisibilityAfterAnim);
7375 }
7376 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7377 if (!mPolicyVisibility) {
7378 if (mCurrentFocus == this) {
7379 mFocusMayChange = true;
7380 }
7381 // Window is no longer visible -- make sure if we were waiting
7382 // for it to be displayed before enabling the display, that
7383 // we allow the display to be enabled now.
7384 enableScreenIfNeededLocked();
7385 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007386 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 mTransformation.clear();
7388 if (mHasDrawn
7389 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7390 && mAppToken != null
7391 && mAppToken.firstWindowDrawn
7392 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007393 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007394 + mToken + ": first real window done animating");
7395 mFinishedStarting.add(mAppToken);
7396 mH.sendEmptyMessage(H.FINISHED_STARTING);
7397 }
Romain Guy06882f82009-06-10 13:36:04 -07007398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 finishExit();
7400
7401 if (mAppToken != null) {
7402 mAppToken.updateReportedVisibilityLocked();
7403 }
7404
7405 return false;
7406 }
7407
7408 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007409 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 TAG, "finishExit in " + this
7411 + ": exiting=" + mExiting
7412 + " remove=" + mRemoveOnExit
7413 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 final int N = mChildWindows.size();
7416 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007417 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 }
Romain Guy06882f82009-06-10 13:36:04 -07007419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007420 if (!mExiting) {
7421 return;
7422 }
Romain Guy06882f82009-06-10 13:36:04 -07007423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007424 if (isWindowAnimating()) {
7425 return;
7426 }
7427
Joe Onorato8a9b2202010-02-26 18:56:32 -08007428 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 TAG, "Exit animation finished in " + this
7430 + ": remove=" + mRemoveOnExit);
7431 if (mSurface != null) {
7432 mDestroySurface.add(this);
7433 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007434 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007435 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 try {
7437 mSurface.hide();
7438 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007439 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 }
7441 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 }
7443 mExiting = false;
7444 if (mRemoveOnExit) {
7445 mPendingRemove.add(this);
7446 mRemoveOnExit = false;
7447 }
7448 }
Romain Guy06882f82009-06-10 13:36:04 -07007449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7451 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7452 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7453 if (dtdx < -.000001f || dtdx > .000001f) return false;
7454 if (dsdy < -.000001f || dsdy > .000001f) return false;
7455 return true;
7456 }
Romain Guy06882f82009-06-10 13:36:04 -07007457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007458 void computeShownFrameLocked() {
7459 final boolean selfTransformation = mHasLocalTransformation;
7460 Transformation attachedTransformation =
7461 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7462 ? mAttachedWindow.mTransformation : null;
7463 Transformation appTransformation =
7464 (mAppToken != null && mAppToken.hasTransformation)
7465 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007466
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007467 // Wallpapers are animated based on the "real" window they
7468 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007469 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007470 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007471 if (mWallpaperTarget.mHasLocalTransformation &&
7472 mWallpaperTarget.mAnimation != null &&
7473 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007474 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007475 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007476 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007477 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007478 }
7479 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007480 mWallpaperTarget.mAppToken.hasTransformation &&
7481 mWallpaperTarget.mAppToken.animation != null &&
7482 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007483 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007484 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007485 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007486 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007487 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007488 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007489
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007490 final boolean screenAnimation = mScreenRotationAnimation != null
7491 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007492 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007493 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007494 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 final Rect frame = mFrame;
7496 final float tmpFloats[] = mTmpFloats;
7497 final Matrix tmpMatrix = mTmpMatrix;
7498
7499 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007500 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007502 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007504 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007506 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 }
7508 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007509 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007511 if (screenAnimation) {
7512 tmpMatrix.postConcat(
7513 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007515
7516 // "convert" it into SurfaceFlinger's format
7517 // (a 2x2 matrix + an offset)
7518 // Here we must not transform the position of the surface
7519 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007520 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 tmpMatrix.getValues(tmpFloats);
7523 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007524 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7525 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007527 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7528 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007529 int w = frame.width();
7530 int h = frame.height();
7531 mShownFrame.set(x, y, x+w, y+h);
7532
7533 // Now set the alpha... but because our current hardware
7534 // can't do alpha transformation on a non-opaque surface,
7535 // turn it off if we are running an animation that is also
7536 // transforming since it is more important to have that
7537 // animation be smooth.
7538 mShownAlpha = mAlpha;
7539 if (!mLimitedAlphaCompositing
7540 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7541 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7542 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007543 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007544 if (selfTransformation) {
7545 mShownAlpha *= mTransformation.getAlpha();
7546 }
7547 if (attachedTransformation != null) {
7548 mShownAlpha *= attachedTransformation.getAlpha();
7549 }
7550 if (appTransformation != null) {
7551 mShownAlpha *= appTransformation.getAlpha();
7552 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007553 if (screenAnimation) {
7554 mShownAlpha *=
7555 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007558 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007559 }
Romain Guy06882f82009-06-10 13:36:04 -07007560
Joe Onorato8a9b2202010-02-26 18:56:32 -08007561 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 TAG, "Continuing animation in " + this +
7563 ": " + mShownFrame +
7564 ", alpha=" + mTransformation.getAlpha());
7565 return;
7566 }
Romain Guy06882f82009-06-10 13:36:04 -07007567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007568 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007569 if (mXOffset != 0 || mYOffset != 0) {
7570 mShownFrame.offset(mXOffset, mYOffset);
7571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 mShownAlpha = mAlpha;
7573 mDsDx = 1;
7574 mDtDx = 0;
7575 mDsDy = 0;
7576 mDtDy = 1;
7577 }
Romain Guy06882f82009-06-10 13:36:04 -07007578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007579 /**
7580 * Is this window visible? It is not visible if there is no
7581 * surface, or we are in the process of running an exit animation
7582 * that will remove the surface, or its app token has been hidden.
7583 */
7584 public boolean isVisibleLw() {
7585 final AppWindowToken atoken = mAppToken;
7586 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7587 && (atoken == null || !atoken.hiddenRequested)
7588 && !mExiting && !mDestroying;
7589 }
7590
7591 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007592 * Like {@link #isVisibleLw}, but also counts a window that is currently
7593 * "hidden" behind the keyguard as visible. This allows us to apply
7594 * things like window flags that impact the keyguard.
7595 * XXX I am starting to think we need to have ANOTHER visibility flag
7596 * for this "hidden behind keyguard" state rather than overloading
7597 * mPolicyVisibility. Ungh.
7598 */
7599 public boolean isVisibleOrBehindKeyguardLw() {
7600 final AppWindowToken atoken = mAppToken;
7601 return mSurface != null && !mAttachedHidden
7602 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007603 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007604 && !mExiting && !mDestroying;
7605 }
7606
7607 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007608 * Is this window visible, ignoring its app token? It is not visible
7609 * if there is no surface, or we are in the process of running an exit animation
7610 * that will remove the surface.
7611 */
7612 public boolean isWinVisibleLw() {
7613 final AppWindowToken atoken = mAppToken;
7614 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7615 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7616 && !mExiting && !mDestroying;
7617 }
7618
7619 /**
7620 * The same as isVisible(), but follows the current hidden state of
7621 * the associated app token, not the pending requested hidden state.
7622 */
7623 boolean isVisibleNow() {
7624 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007625 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 }
7627
7628 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007629 * Can this window possibly be a drag/drop target? The test here is
7630 * a combination of the above "visible now" with the check that the
7631 * Input Manager uses when discarding windows from input consideration.
7632 */
7633 boolean isPotentialDragTarget() {
7634 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7635 }
7636
7637 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 * Same as isVisible(), but we also count it as visible between the
7639 * call to IWindowSession.add() and the first relayout().
7640 */
7641 boolean isVisibleOrAdding() {
7642 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007643 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007644 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7645 && mPolicyVisibility && !mAttachedHidden
7646 && (atoken == null || !atoken.hiddenRequested)
7647 && !mExiting && !mDestroying;
7648 }
7649
7650 /**
7651 * Is this window currently on-screen? It is on-screen either if it
7652 * is visible or it is currently running an animation before no longer
7653 * being visible.
7654 */
7655 boolean isOnScreen() {
7656 final AppWindowToken atoken = mAppToken;
7657 if (atoken != null) {
7658 return mSurface != null && mPolicyVisibility && !mDestroying
7659 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007660 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007661 } else {
7662 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007663 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007664 }
7665 }
Romain Guy06882f82009-06-10 13:36:04 -07007666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007667 /**
7668 * Like isOnScreen(), but we don't return true if the window is part
7669 * of a transition that has not yet been started.
7670 */
7671 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007672 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007673 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007674 return false;
7675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007676 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007677 final boolean animating = atoken != null
7678 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007679 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007680 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7681 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007682 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007683 }
7684
7685 /** Is the window or its container currently animating? */
7686 boolean isAnimating() {
7687 final WindowState attached = mAttachedWindow;
7688 final AppWindowToken atoken = mAppToken;
7689 return mAnimation != null
7690 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007691 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007692 (atoken.animation != null
7693 || atoken.inPendingTransaction));
7694 }
7695
7696 /** Is this window currently animating? */
7697 boolean isWindowAnimating() {
7698 return mAnimation != null;
7699 }
7700
7701 /**
7702 * Like isOnScreen, but returns false if the surface hasn't yet
7703 * been drawn.
7704 */
7705 public boolean isDisplayedLw() {
7706 final AppWindowToken atoken = mAppToken;
7707 return mSurface != null && mPolicyVisibility && !mDestroying
7708 && !mDrawPending && !mCommitDrawPending
7709 && ((!mAttachedHidden &&
7710 (atoken == null || !atoken.hiddenRequested))
7711 || mAnimating);
7712 }
7713
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007714 /**
7715 * Returns true if the window has a surface that it has drawn a
7716 * complete UI in to.
7717 */
7718 public boolean isDrawnLw() {
7719 final AppWindowToken atoken = mAppToken;
7720 return mSurface != null && !mDestroying
7721 && !mDrawPending && !mCommitDrawPending;
7722 }
7723
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007724 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007725 * Return true if the window is opaque and fully drawn. This indicates
7726 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007727 */
7728 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007729 return (mAttrs.format == PixelFormat.OPAQUE
7730 || mAttrs.type == TYPE_WALLPAPER)
7731 && mSurface != null && mAnimation == null
7732 && (mAppToken == null || mAppToken.animation == null)
7733 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007734 }
7735
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007736 /**
7737 * Return whether this window is wanting to have a translation
7738 * animation applied to it for an in-progress move. (Only makes
7739 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7740 */
7741 boolean shouldAnimateMove() {
7742 return mContentChanged && !mAnimating && !mLastHidden && !mDisplayFrozen
7743 && (mFrame.top != mLastFrame.top
7744 || mFrame.left != mLastFrame.left)
7745 && (mAttachedWindow == null
7746 || (mAttachedWindow.mAnimation == null
7747 && !mAttachedWindow.shouldAnimateMove()))
7748 && mPolicy.isScreenOn();
7749 }
7750
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007751 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7752 return
7753 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007754 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7755 // only if it's visible
7756 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007757 // and only if the application fills the compatible screen
7758 mFrame.left <= mCompatibleScreenFrame.left &&
7759 mFrame.top <= mCompatibleScreenFrame.top &&
7760 mFrame.right >= mCompatibleScreenFrame.right &&
7761 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007762 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007763 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007764 }
7765
7766 boolean isFullscreen(int screenWidth, int screenHeight) {
7767 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007768 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007769 }
7770
7771 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007772 disposeInputChannel();
7773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 if (mAttachedWindow != null) {
7775 mAttachedWindow.mChildWindows.remove(this);
7776 }
7777 destroySurfaceLocked();
7778 mSession.windowRemovedLocked();
7779 try {
7780 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7781 } catch (RuntimeException e) {
7782 // Ignore if it has already been removed (usually because
7783 // we are doing this as part of processing a death note.)
7784 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007785 }
7786
7787 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007788 if (mInputChannel != null) {
7789 mInputManager.unregisterInputChannel(mInputChannel);
7790
7791 mInputChannel.dispose();
7792 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07007793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007794 }
7795
7796 private class DeathRecipient implements IBinder.DeathRecipient {
7797 public void binderDied() {
7798 try {
7799 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007800 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007801 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007802 if (win != null) {
7803 removeWindowLocked(mSession, win);
7804 }
7805 }
7806 } catch (IllegalArgumentException ex) {
7807 // This will happen if the window has already been
7808 // removed.
7809 }
7810 }
7811 }
7812
7813 /** Returns true if this window desires key events. */
7814 public final boolean canReceiveKeys() {
7815 return isVisibleOrAdding()
7816 && (mViewVisibility == View.VISIBLE)
7817 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7818 }
7819
7820 public boolean hasDrawnLw() {
7821 return mHasDrawn;
7822 }
7823
7824 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007825 return showLw(doAnimation, true);
7826 }
7827
7828 boolean showLw(boolean doAnimation, boolean requestAnim) {
7829 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7830 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007831 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007832 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007833 if (doAnimation) {
7834 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7835 + mPolicyVisibility + " mAnimation=" + mAnimation);
7836 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7837 doAnimation = false;
7838 } else if (mPolicyVisibility && mAnimation == null) {
7839 // Check for the case where we are currently visible and
7840 // not animating; we do not want to do animation at such a
7841 // point to become visible when we already are.
7842 doAnimation = false;
7843 }
7844 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007845 mPolicyVisibility = true;
7846 mPolicyVisibilityAfterAnim = true;
7847 if (doAnimation) {
7848 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7849 }
7850 if (requestAnim) {
7851 requestAnimationLocked(0);
7852 }
7853 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007854 }
7855
7856 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007857 return hideLw(doAnimation, true);
7858 }
7859
7860 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007861 if (doAnimation) {
7862 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7863 doAnimation = false;
7864 }
7865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7867 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007868 if (!current) {
7869 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007871 if (doAnimation) {
7872 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7873 if (mAnimation == null) {
7874 doAnimation = false;
7875 }
7876 }
7877 if (doAnimation) {
7878 mPolicyVisibilityAfterAnim = false;
7879 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007880 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007881 mPolicyVisibilityAfterAnim = false;
7882 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007883 // Window is no longer visible -- make sure if we were waiting
7884 // for it to be displayed before enabling the display, that
7885 // we allow the display to be enabled now.
7886 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007887 if (mCurrentFocus == this) {
7888 mFocusMayChange = true;
7889 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007890 }
7891 if (requestAnim) {
7892 requestAnimationLocked(0);
7893 }
7894 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 }
7896
7897 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007898 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7899 pw.print(" mClient="); pw.println(mClient.asBinder());
7900 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7901 if (mAttachedWindow != null || mLayoutAttached) {
7902 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7903 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7904 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007905 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7906 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7907 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007908 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7909 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007910 }
7911 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7912 pw.print(" mSubLayer="); pw.print(mSubLayer);
7913 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7914 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7915 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7916 pw.print("="); pw.print(mAnimLayer);
7917 pw.print(" mLastLayer="); pw.println(mLastLayer);
7918 if (mSurface != null) {
7919 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007920 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7921 pw.print(" layer="); pw.print(mSurfaceLayer);
7922 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7923 pw.print(" rect=("); pw.print(mSurfaceX);
7924 pw.print(","); pw.print(mSurfaceY);
7925 pw.print(") "); pw.print(mSurfaceW);
7926 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007927 }
7928 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7929 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7930 if (mAppToken != null) {
7931 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7932 }
7933 if (mTargetAppToken != null) {
7934 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7935 }
7936 pw.print(prefix); pw.print("mViewVisibility=0x");
7937 pw.print(Integer.toHexString(mViewVisibility));
7938 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007939 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7940 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007941 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7942 pw.print(prefix); pw.print("mPolicyVisibility=");
7943 pw.print(mPolicyVisibility);
7944 pw.print(" mPolicyVisibilityAfterAnim=");
7945 pw.print(mPolicyVisibilityAfterAnim);
7946 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7947 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007948 if (!mRelayoutCalled) {
7949 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7950 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007951 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007952 pw.print(" h="); pw.print(mRequestedHeight);
7953 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007954 if (mXOffset != 0 || mYOffset != 0) {
7955 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7956 pw.print(" y="); pw.println(mYOffset);
7957 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007958 pw.print(prefix); pw.print("mGivenContentInsets=");
7959 mGivenContentInsets.printShortString(pw);
7960 pw.print(" mGivenVisibleInsets=");
7961 mGivenVisibleInsets.printShortString(pw);
7962 pw.println();
7963 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7964 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7965 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7966 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007967 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007968 pw.print(prefix); pw.print("mShownFrame=");
7969 mShownFrame.printShortString(pw);
7970 pw.print(" last="); mLastShownFrame.printShortString(pw);
7971 pw.println();
7972 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7973 pw.print(" last="); mLastFrame.printShortString(pw);
7974 pw.println();
7975 pw.print(prefix); pw.print("mContainingFrame=");
7976 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007977 pw.print(" mParentFrame=");
7978 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007979 pw.print(" mDisplayFrame=");
7980 mDisplayFrame.printShortString(pw);
7981 pw.println();
7982 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7983 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7984 pw.println();
7985 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7986 pw.print(" last="); mLastContentInsets.printShortString(pw);
7987 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7988 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7989 pw.println();
7990 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7991 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7992 pw.print(" mAlpha="); pw.print(mAlpha);
7993 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7994 }
7995 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7996 || mAnimation != null) {
7997 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7998 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7999 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8000 pw.print(" mAnimation="); pw.println(mAnimation);
8001 }
8002 if (mHasTransformation || mHasLocalTransformation) {
8003 pw.print(prefix); pw.print("XForm: has=");
8004 pw.print(mHasTransformation);
8005 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8006 pw.print(" "); mTransformation.printShortString(pw);
8007 pw.println();
8008 }
8009 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8010 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8011 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8012 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8013 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8014 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8015 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8016 pw.print(" mDestroying="); pw.print(mDestroying);
8017 pw.print(" mRemoved="); pw.println(mRemoved);
8018 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008019 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008020 pw.print(prefix); pw.print("mOrientationChanging=");
8021 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008022 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8023 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008024 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008025 if (mHScale != 1 || mVScale != 1) {
8026 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8027 pw.print(" mVScale="); pw.println(mVScale);
8028 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008029 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008030 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8031 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8032 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008033 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8034 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8035 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008037 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07008038
8039 String makeInputChannelName() {
8040 return Integer.toHexString(System.identityHashCode(this))
8041 + " " + mAttrs.getTitle();
8042 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043
8044 @Override
8045 public String toString() {
8046 return "Window{"
8047 + Integer.toHexString(System.identityHashCode(this))
8048 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8049 }
8050 }
Romain Guy06882f82009-06-10 13:36:04 -07008051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008052 // -------------------------------------------------------------
8053 // Window Token State
8054 // -------------------------------------------------------------
8055
8056 class WindowToken {
8057 // The actual token.
8058 final IBinder token;
8059
8060 // The type of window this token is for, as per WindowManager.LayoutParams.
8061 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008063 // Set if this token was explicitly added by a client, so should
8064 // not be removed when all windows are removed.
8065 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008066
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008067 // For printing.
8068 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008070 // If this is an AppWindowToken, this is non-null.
8071 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008073 // All of the windows associated with this token.
8074 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8075
8076 // Is key dispatching paused for this token?
8077 boolean paused = false;
8078
8079 // Should this token's windows be hidden?
8080 boolean hidden;
8081
8082 // Temporary for finding which tokens no longer have visible windows.
8083 boolean hasVisible;
8084
Dianne Hackborna8f60182009-09-01 19:01:50 -07008085 // Set to true when this token is in a pending transaction where it
8086 // will be shown.
8087 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008088
Dianne Hackborna8f60182009-09-01 19:01:50 -07008089 // Set to true when this token is in a pending transaction where it
8090 // will be hidden.
8091 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008092
Dianne Hackborna8f60182009-09-01 19:01:50 -07008093 // Set to true when this token is in a pending transaction where its
8094 // windows will be put to the bottom of the list.
8095 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008096
Dianne Hackborna8f60182009-09-01 19:01:50 -07008097 // Set to true when this token is in a pending transaction where its
8098 // windows will be put to the top of the list.
8099 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008101 WindowToken(IBinder _token, int type, boolean _explicit) {
8102 token = _token;
8103 windowType = type;
8104 explicit = _explicit;
8105 }
8106
8107 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008108 pw.print(prefix); pw.print("token="); pw.println(token);
8109 pw.print(prefix); pw.print("windows="); pw.println(windows);
8110 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8111 pw.print(" hidden="); pw.print(hidden);
8112 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008113 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8114 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8115 pw.print(" waitingToHide="); pw.print(waitingToHide);
8116 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8117 pw.print(" sendingToTop="); pw.println(sendingToTop);
8118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008119 }
8120
8121 @Override
8122 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008123 if (stringName == null) {
8124 StringBuilder sb = new StringBuilder();
8125 sb.append("WindowToken{");
8126 sb.append(Integer.toHexString(System.identityHashCode(this)));
8127 sb.append(" token="); sb.append(token); sb.append('}');
8128 stringName = sb.toString();
8129 }
8130 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008131 }
8132 };
8133
8134 class AppWindowToken extends WindowToken {
8135 // Non-null only for application tokens.
8136 final IApplicationToken appToken;
8137
8138 // All of the windows and child windows that are included in this
8139 // application token. Note this list is NOT sorted!
8140 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8141
8142 int groupId = -1;
8143 boolean appFullscreen;
8144 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008145
8146 // The input dispatching timeout for this application token in nanoseconds.
8147 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008149 // These are used for determining when all windows associated with
8150 // an activity have been drawn, so they can be made visible together
8151 // at the same time.
8152 int lastTransactionSequence = mTransactionSequence-1;
8153 int numInterestingWindows;
8154 int numDrawnWindows;
8155 boolean inPendingTransaction;
8156 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008158 // Is this token going to be hidden in a little while? If so, it
8159 // won't be taken into account for setting the screen orientation.
8160 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 // Is this window's surface needed? This is almost like hidden, except
8163 // it will sometimes be true a little earlier: when the token has
8164 // been shown, but is still waiting for its app transition to execute
8165 // before making its windows shown.
8166 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008168 // Have we told the window clients to hide themselves?
8169 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008171 // Last visibility state we reported to the app token.
8172 boolean reportedVisible;
8173
8174 // Set to true when the token has been removed from the window mgr.
8175 boolean removed;
8176
8177 // Have we been asked to have this token keep the screen frozen?
8178 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008180 boolean animating;
8181 Animation animation;
8182 boolean hasTransformation;
8183 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008185 // Offset to the window of all layers in the token, for use by
8186 // AppWindowToken animations.
8187 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 // Information about an application starting window if displayed.
8190 StartingData startingData;
8191 WindowState startingWindow;
8192 View startingView;
8193 boolean startingDisplayed;
8194 boolean startingMoved;
8195 boolean firstWindowDrawn;
8196
8197 AppWindowToken(IApplicationToken _token) {
8198 super(_token.asBinder(),
8199 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8200 appWindowToken = this;
8201 appToken = _token;
8202 }
Romain Guy06882f82009-06-10 13:36:04 -07008203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008204 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008205 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008206 TAG, "Setting animation in " + this + ": " + anim);
8207 animation = anim;
8208 animating = false;
8209 anim.restrictDuration(MAX_ANIMATION_DURATION);
8210 anim.scaleCurrentDuration(mTransitionAnimationScale);
8211 int zorder = anim.getZAdjustment();
8212 int adj = 0;
8213 if (zorder == Animation.ZORDER_TOP) {
8214 adj = TYPE_LAYER_OFFSET;
8215 } else if (zorder == Animation.ZORDER_BOTTOM) {
8216 adj = -TYPE_LAYER_OFFSET;
8217 }
Romain Guy06882f82009-06-10 13:36:04 -07008218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008219 if (animLayerAdjustment != adj) {
8220 animLayerAdjustment = adj;
8221 updateLayers();
8222 }
8223 }
Romain Guy06882f82009-06-10 13:36:04 -07008224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008225 public void setDummyAnimation() {
8226 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008227 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008228 TAG, "Setting dummy animation in " + this);
8229 animation = sDummyAnimation;
8230 }
8231 }
8232
8233 public void clearAnimation() {
8234 if (animation != null) {
8235 animation = null;
8236 animating = true;
8237 }
8238 }
Romain Guy06882f82009-06-10 13:36:04 -07008239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008240 void updateLayers() {
8241 final int N = allAppWindows.size();
8242 final int adj = animLayerAdjustment;
8243 for (int i=0; i<N; i++) {
8244 WindowState w = allAppWindows.get(i);
8245 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008246 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008247 + w.mAnimLayer);
8248 if (w == mInputMethodTarget) {
8249 setInputMethodAnimLayerAdjustment(adj);
8250 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008251 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008252 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008254 }
8255 }
Romain Guy06882f82009-06-10 13:36:04 -07008256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008257 void sendAppVisibilityToClients() {
8258 final int N = allAppWindows.size();
8259 for (int i=0; i<N; i++) {
8260 WindowState win = allAppWindows.get(i);
8261 if (win == startingWindow && clientHidden) {
8262 // Don't hide the starting window.
8263 continue;
8264 }
8265 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008266 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008267 "Setting visibility of " + win + ": " + (!clientHidden));
8268 win.mClient.dispatchAppVisibility(!clientHidden);
8269 } catch (RemoteException e) {
8270 }
8271 }
8272 }
Romain Guy06882f82009-06-10 13:36:04 -07008273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008274 void showAllWindowsLocked() {
8275 final int NW = allAppWindows.size();
8276 for (int i=0; i<NW; i++) {
8277 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008278 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279 "performing show on: " + w);
8280 w.performShowLocked();
8281 }
8282 }
Romain Guy06882f82009-06-10 13:36:04 -07008283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008284 // This must be called while inside a transaction.
8285 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008286 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008287 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008289 if (animation == sDummyAnimation) {
8290 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008291 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008292 // when it is really time to animate, this will be set to
8293 // a real animation and the next call will execute normally.
8294 return false;
8295 }
Romain Guy06882f82009-06-10 13:36:04 -07008296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008297 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8298 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008299 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008300 TAG, "Starting animation in " + this +
8301 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8302 + " scale=" + mTransitionAnimationScale
8303 + " allDrawn=" + allDrawn + " animating=" + animating);
8304 animation.initialize(dw, dh, dw, dh);
8305 animation.setStartTime(currentTime);
8306 animating = true;
8307 }
8308 transformation.clear();
8309 final boolean more = animation.getTransformation(
8310 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008311 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008312 TAG, "Stepped animation in " + this +
8313 ": more=" + more + ", xform=" + transformation);
8314 if (more) {
8315 // we're done!
8316 hasTransformation = true;
8317 return true;
8318 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008319 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008320 TAG, "Finished animation in " + this +
8321 " @ " + currentTime);
8322 animation = null;
8323 }
8324 } else if (animation != null) {
8325 // If the display is frozen, and there is a pending animation,
8326 // clear it and make sure we run the cleanup code.
8327 animating = true;
8328 animation = null;
8329 }
8330
8331 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008333 if (!animating) {
8334 return false;
8335 }
8336
8337 clearAnimation();
8338 animating = false;
8339 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8340 moveInputMethodWindowsIfNeededLocked(true);
8341 }
Romain Guy06882f82009-06-10 13:36:04 -07008342
Joe Onorato8a9b2202010-02-26 18:56:32 -08008343 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008344 TAG, "Animation done in " + this
8345 + ": reportedVisible=" + reportedVisible);
8346
8347 transformation.clear();
8348 if (animLayerAdjustment != 0) {
8349 animLayerAdjustment = 0;
8350 updateLayers();
8351 }
Romain Guy06882f82009-06-10 13:36:04 -07008352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 final int N = windows.size();
8354 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008355 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008356 }
8357 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008359 return false;
8360 }
8361
8362 void updateReportedVisibilityLocked() {
8363 if (appToken == null) {
8364 return;
8365 }
Romain Guy06882f82009-06-10 13:36:04 -07008366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008367 int numInteresting = 0;
8368 int numVisible = 0;
8369 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008370
Joe Onorato8a9b2202010-02-26 18:56:32 -08008371 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008372 final int N = allAppWindows.size();
8373 for (int i=0; i<N; i++) {
8374 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008375 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008376 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008377 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8378 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 continue;
8380 }
8381 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008382 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008383 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008384 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008385 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008386 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008387 + " pv=" + win.mPolicyVisibility
8388 + " dp=" + win.mDrawPending
8389 + " cdp=" + win.mCommitDrawPending
8390 + " ah=" + win.mAttachedHidden
8391 + " th="
8392 + (win.mAppToken != null
8393 ? win.mAppToken.hiddenRequested : false)
8394 + " a=" + win.mAnimating);
8395 }
8396 }
8397 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008398 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 if (!win.isAnimating()) {
8400 numVisible++;
8401 }
8402 nowGone = false;
8403 } else if (win.isAnimating()) {
8404 nowGone = false;
8405 }
8406 }
Romain Guy06882f82009-06-10 13:36:04 -07008407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008408 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008409 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008410 + numInteresting + " visible=" + numVisible);
8411 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008412 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008413 TAG, "Visibility changed in " + this
8414 + ": vis=" + nowVisible);
8415 reportedVisible = nowVisible;
8416 Message m = mH.obtainMessage(
8417 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8418 nowVisible ? 1 : 0,
8419 nowGone ? 1 : 0,
8420 this);
8421 mH.sendMessage(m);
8422 }
8423 }
Romain Guy06882f82009-06-10 13:36:04 -07008424
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008425 WindowState findMainWindow() {
8426 int j = windows.size();
8427 while (j > 0) {
8428 j--;
8429 WindowState win = windows.get(j);
8430 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8431 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8432 return win;
8433 }
8434 }
8435 return null;
8436 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008438 void dump(PrintWriter pw, String prefix) {
8439 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008440 if (appToken != null) {
8441 pw.print(prefix); pw.println("app=true");
8442 }
8443 if (allAppWindows.size() > 0) {
8444 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8445 }
8446 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008447 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008448 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8449 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8450 pw.print(" clientHidden="); pw.print(clientHidden);
8451 pw.print(" willBeHidden="); pw.print(willBeHidden);
8452 pw.print(" reportedVisible="); pw.println(reportedVisible);
8453 if (paused || freezingScreen) {
8454 pw.print(prefix); pw.print("paused="); pw.print(paused);
8455 pw.print(" freezingScreen="); pw.println(freezingScreen);
8456 }
8457 if (numInterestingWindows != 0 || numDrawnWindows != 0
8458 || inPendingTransaction || allDrawn) {
8459 pw.print(prefix); pw.print("numInterestingWindows=");
8460 pw.print(numInterestingWindows);
8461 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8462 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8463 pw.print(" allDrawn="); pw.println(allDrawn);
8464 }
8465 if (animating || animation != null) {
8466 pw.print(prefix); pw.print("animating="); pw.print(animating);
8467 pw.print(" animation="); pw.println(animation);
8468 }
8469 if (animLayerAdjustment != 0) {
8470 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8471 }
8472 if (hasTransformation) {
8473 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8474 pw.print(" transformation="); transformation.printShortString(pw);
8475 pw.println();
8476 }
8477 if (startingData != null || removed || firstWindowDrawn) {
8478 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8479 pw.print(" removed="); pw.print(removed);
8480 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8481 }
8482 if (startingWindow != null || startingView != null
8483 || startingDisplayed || startingMoved) {
8484 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8485 pw.print(" startingView="); pw.print(startingView);
8486 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8487 pw.print(" startingMoved"); pw.println(startingMoved);
8488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008489 }
8490
8491 @Override
8492 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008493 if (stringName == null) {
8494 StringBuilder sb = new StringBuilder();
8495 sb.append("AppWindowToken{");
8496 sb.append(Integer.toHexString(System.identityHashCode(this)));
8497 sb.append(" token="); sb.append(token); sb.append('}');
8498 stringName = sb.toString();
8499 }
8500 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 }
8502 }
Romain Guy06882f82009-06-10 13:36:04 -07008503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008504 // -------------------------------------------------------------
8505 // DummyAnimation
8506 // -------------------------------------------------------------
8507
8508 // This is an animation that does nothing: it just immediately finishes
8509 // itself every time it is called. It is used as a stub animation in cases
8510 // where we want to synchronize multiple things that may be animating.
8511 static final class DummyAnimation extends Animation {
8512 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8513 return false;
8514 }
8515 }
8516 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 // -------------------------------------------------------------
8519 // Async Handler
8520 // -------------------------------------------------------------
8521
8522 static final class StartingData {
8523 final String pkg;
8524 final int theme;
8525 final CharSequence nonLocalizedLabel;
8526 final int labelRes;
8527 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008528 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008531 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008532 pkg = _pkg;
8533 theme = _theme;
8534 nonLocalizedLabel = _nonLocalizedLabel;
8535 labelRes = _labelRes;
8536 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008537 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 }
8539 }
8540
8541 private final class H extends Handler {
8542 public static final int REPORT_FOCUS_CHANGE = 2;
8543 public static final int REPORT_LOSING_FOCUS = 3;
8544 public static final int ANIMATE = 4;
8545 public static final int ADD_STARTING = 5;
8546 public static final int REMOVE_STARTING = 6;
8547 public static final int FINISHED_STARTING = 7;
8548 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8550 public static final int HOLD_SCREEN_CHANGED = 12;
8551 public static final int APP_TRANSITION_TIMEOUT = 13;
8552 public static final int PERSIST_ANIMATION_SCALE = 14;
8553 public static final int FORCE_GC = 15;
8554 public static final int ENABLE_SCREEN = 16;
8555 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008556 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008557 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008558 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07008559 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008563 public H() {
8564 }
Romain Guy06882f82009-06-10 13:36:04 -07008565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 @Override
8567 public void handleMessage(Message msg) {
8568 switch (msg.what) {
8569 case REPORT_FOCUS_CHANGE: {
8570 WindowState lastFocus;
8571 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573 synchronized(mWindowMap) {
8574 lastFocus = mLastFocus;
8575 newFocus = mCurrentFocus;
8576 if (lastFocus == newFocus) {
8577 // Focus is not changing, so nothing to do.
8578 return;
8579 }
8580 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008581 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 // + " to " + newFocus);
8583 if (newFocus != null && lastFocus != null
8584 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008585 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 mLosingFocus.add(lastFocus);
8587 lastFocus = null;
8588 }
8589 }
8590
8591 if (lastFocus != newFocus) {
8592 //System.out.println("Changing focus from " + lastFocus
8593 // + " to " + newFocus);
8594 if (newFocus != null) {
8595 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008596 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008597 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8598 } catch (RemoteException e) {
8599 // Ignore if process has died.
8600 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008601 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008602 }
8603
8604 if (lastFocus != null) {
8605 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008606 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8608 } catch (RemoteException e) {
8609 // Ignore if process has died.
8610 }
8611 }
8612 }
8613 } break;
8614
8615 case REPORT_LOSING_FOCUS: {
8616 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 synchronized(mWindowMap) {
8619 losers = mLosingFocus;
8620 mLosingFocus = new ArrayList<WindowState>();
8621 }
8622
8623 final int N = losers.size();
8624 for (int i=0; i<N; i++) {
8625 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008626 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8628 } catch (RemoteException e) {
8629 // Ignore if process has died.
8630 }
8631 }
8632 } break;
8633
8634 case ANIMATE: {
8635 synchronized(mWindowMap) {
8636 mAnimationPending = false;
8637 performLayoutAndPlaceSurfacesLocked();
8638 }
8639 } break;
8640
8641 case ADD_STARTING: {
8642 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8643 final StartingData sd = wtoken.startingData;
8644
8645 if (sd == null) {
8646 // Animation has been canceled... do nothing.
8647 return;
8648 }
Romain Guy06882f82009-06-10 13:36:04 -07008649
Joe Onorato8a9b2202010-02-26 18:56:32 -08008650 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008651 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 View view = null;
8654 try {
8655 view = mPolicy.addStartingWindow(
8656 wtoken.token, sd.pkg,
8657 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008658 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008660 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008661 }
8662
8663 if (view != null) {
8664 boolean abort = false;
8665
8666 synchronized(mWindowMap) {
8667 if (wtoken.removed || wtoken.startingData == null) {
8668 // If the window was successfully added, then
8669 // we need to remove it.
8670 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008671 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008672 "Aborted starting " + wtoken
8673 + ": removed=" + wtoken.removed
8674 + " startingData=" + wtoken.startingData);
8675 wtoken.startingWindow = null;
8676 wtoken.startingData = null;
8677 abort = true;
8678 }
8679 } else {
8680 wtoken.startingView = view;
8681 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008682 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 "Added starting " + wtoken
8684 + ": startingWindow="
8685 + wtoken.startingWindow + " startingView="
8686 + wtoken.startingView);
8687 }
8688
8689 if (abort) {
8690 try {
8691 mPolicy.removeStartingWindow(wtoken.token, view);
8692 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008693 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008694 }
8695 }
8696 }
8697 } break;
8698
8699 case REMOVE_STARTING: {
8700 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8701 IBinder token = null;
8702 View view = null;
8703 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008704 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008705 + wtoken + ": startingWindow="
8706 + wtoken.startingWindow + " startingView="
8707 + wtoken.startingView);
8708 if (wtoken.startingWindow != null) {
8709 view = wtoken.startingView;
8710 token = wtoken.token;
8711 wtoken.startingData = null;
8712 wtoken.startingView = null;
8713 wtoken.startingWindow = null;
8714 }
8715 }
8716 if (view != null) {
8717 try {
8718 mPolicy.removeStartingWindow(token, view);
8719 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008720 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008721 }
8722 }
8723 } break;
8724
8725 case FINISHED_STARTING: {
8726 IBinder token = null;
8727 View view = null;
8728 while (true) {
8729 synchronized (mWindowMap) {
8730 final int N = mFinishedStarting.size();
8731 if (N <= 0) {
8732 break;
8733 }
8734 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8735
Joe Onorato8a9b2202010-02-26 18:56:32 -08008736 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 "Finished starting " + wtoken
8738 + ": startingWindow=" + wtoken.startingWindow
8739 + " startingView=" + wtoken.startingView);
8740
8741 if (wtoken.startingWindow == null) {
8742 continue;
8743 }
8744
8745 view = wtoken.startingView;
8746 token = wtoken.token;
8747 wtoken.startingData = null;
8748 wtoken.startingView = null;
8749 wtoken.startingWindow = null;
8750 }
8751
8752 try {
8753 mPolicy.removeStartingWindow(token, view);
8754 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008755 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008756 }
8757 }
8758 } break;
8759
8760 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8761 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8762
8763 boolean nowVisible = msg.arg1 != 0;
8764 boolean nowGone = msg.arg2 != 0;
8765
8766 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008767 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768 TAG, "Reporting visible in " + wtoken
8769 + " visible=" + nowVisible
8770 + " gone=" + nowGone);
8771 if (nowVisible) {
8772 wtoken.appToken.windowsVisible();
8773 } else {
8774 wtoken.appToken.windowsGone();
8775 }
8776 } catch (RemoteException ex) {
8777 }
8778 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008780 case WINDOW_FREEZE_TIMEOUT: {
8781 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008782 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783 int i = mWindows.size();
8784 while (i > 0) {
8785 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008786 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008787 if (w.mOrientationChanging) {
8788 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008789 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008790 }
8791 }
8792 performLayoutAndPlaceSurfacesLocked();
8793 }
8794 break;
8795 }
Romain Guy06882f82009-06-10 13:36:04 -07008796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 case HOLD_SCREEN_CHANGED: {
8798 Session oldHold;
8799 Session newHold;
8800 synchronized (mWindowMap) {
8801 oldHold = mLastReportedHold;
8802 newHold = (Session)msg.obj;
8803 mLastReportedHold = newHold;
8804 }
Romain Guy06882f82009-06-10 13:36:04 -07008805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008806 if (oldHold != newHold) {
8807 try {
8808 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008809 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 "window",
8811 BatteryStats.WAKE_TYPE_WINDOW);
8812 }
8813 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008814 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008815 "window",
8816 BatteryStats.WAKE_TYPE_WINDOW);
8817 }
8818 } catch (RemoteException e) {
8819 }
8820 }
8821 break;
8822 }
Romain Guy06882f82009-06-10 13:36:04 -07008823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008824 case APP_TRANSITION_TIMEOUT: {
8825 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008826 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008827 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008828 "*** APP TRANSITION TIMEOUT");
8829 mAppTransitionReady = true;
8830 mAppTransitionTimeout = true;
8831 performLayoutAndPlaceSurfacesLocked();
8832 }
8833 }
8834 break;
8835 }
Romain Guy06882f82009-06-10 13:36:04 -07008836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008837 case PERSIST_ANIMATION_SCALE: {
8838 Settings.System.putFloat(mContext.getContentResolver(),
8839 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8840 Settings.System.putFloat(mContext.getContentResolver(),
8841 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8842 break;
8843 }
Romain Guy06882f82009-06-10 13:36:04 -07008844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008845 case FORCE_GC: {
8846 synchronized(mWindowMap) {
8847 if (mAnimationPending) {
8848 // If we are animating, don't do the gc now but
8849 // delay a bit so we don't interrupt the animation.
8850 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8851 2000);
8852 return;
8853 }
8854 // If we are currently rotating the display, it will
8855 // schedule a new message when done.
8856 if (mDisplayFrozen) {
8857 return;
8858 }
8859 mFreezeGcPending = 0;
8860 }
8861 Runtime.getRuntime().gc();
8862 break;
8863 }
Romain Guy06882f82009-06-10 13:36:04 -07008864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008865 case ENABLE_SCREEN: {
8866 performEnableScreen();
8867 break;
8868 }
Romain Guy06882f82009-06-10 13:36:04 -07008869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008870 case APP_FREEZE_TIMEOUT: {
8871 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008872 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008873 int i = mAppTokens.size();
8874 while (i > 0) {
8875 i--;
8876 AppWindowToken tok = mAppTokens.get(i);
8877 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008878 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008879 unsetAppFreezingScreenLocked(tok, true, true);
8880 }
8881 }
8882 }
8883 break;
8884 }
Romain Guy06882f82009-06-10 13:36:04 -07008885
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008886 case SEND_NEW_CONFIGURATION: {
8887 removeMessages(SEND_NEW_CONFIGURATION);
8888 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008889 break;
8890 }
Romain Guy06882f82009-06-10 13:36:04 -07008891
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008892 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008893 if (mWindowsChanged) {
8894 synchronized (mWindowMap) {
8895 mWindowsChanged = false;
8896 }
8897 notifyWindowsChanged();
8898 }
8899 break;
8900 }
8901
Christopher Tatea53146c2010-09-07 11:57:52 -07008902 case DRAG_START_TIMEOUT: {
8903 IBinder win = (IBinder)msg.obj;
8904 if (DEBUG_DRAG) {
8905 Slog.w(TAG, "Timeout starting drag by win " + win);
8906 }
8907 synchronized (mWindowMap) {
8908 // !!! TODO: ANR the app that has failed to start the drag in time
8909 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07008910 mDragState.unregister();
8911 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008912 mDragState.reset();
8913 mDragState = null;
8914 }
8915 }
Chris Tated4533f12010-10-19 15:15:08 -07008916 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008917 }
8918
Chris Tated4533f12010-10-19 15:15:08 -07008919 case DRAG_END_TIMEOUT: {
8920 IBinder win = (IBinder)msg.obj;
8921 if (DEBUG_DRAG) {
8922 Slog.w(TAG, "Timeout ending drag to win " + win);
8923 }
8924 synchronized (mWindowMap) {
8925 // !!! TODO: ANR the drag-receiving app
8926 mDragState.mDragResult = false;
8927 mDragState.endDragLw();
8928 }
8929 break;
8930 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008931 }
8932 }
8933 }
8934
8935 // -------------------------------------------------------------
8936 // IWindowManager API
8937 // -------------------------------------------------------------
8938
8939 public IWindowSession openSession(IInputMethodClient client,
8940 IInputContext inputContext) {
8941 if (client == null) throw new IllegalArgumentException("null client");
8942 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008943 Session session = new Session(client, inputContext);
8944 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008945 }
8946
8947 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8948 synchronized (mWindowMap) {
8949 // The focus for the client is the window immediately below
8950 // where we would place the input method window.
8951 int idx = findDesiredInputMethodWindowIndexLocked(false);
8952 WindowState imFocus;
8953 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008954 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008955 if (imFocus != null) {
8956 if (imFocus.mSession.mClient != null &&
8957 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8958 return true;
8959 }
8960 }
8961 }
8962 }
8963 return false;
8964 }
Romain Guy06882f82009-06-10 13:36:04 -07008965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008966 // -------------------------------------------------------------
8967 // Internals
8968 // -------------------------------------------------------------
8969
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008970 final WindowState windowForClientLocked(Session session, IWindow client,
8971 boolean throwOnError) {
8972 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 }
Romain Guy06882f82009-06-10 13:36:04 -07008974
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008975 final WindowState windowForClientLocked(Session session, IBinder client,
8976 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008977 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008978 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008979 TAG, "Looking up client " + client + ": " + win);
8980 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008981 RuntimeException ex = new IllegalArgumentException(
8982 "Requested window " + client + " does not exist");
8983 if (throwOnError) {
8984 throw ex;
8985 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008986 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 return null;
8988 }
8989 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008990 RuntimeException ex = new IllegalArgumentException(
8991 "Requested window " + client + " is in session " +
8992 win.mSession + ", not " + session);
8993 if (throwOnError) {
8994 throw ex;
8995 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008996 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 return null;
8998 }
8999
9000 return win;
9001 }
9002
Dianne Hackborna8f60182009-09-01 19:01:50 -07009003 final void rebuildAppWindowListLocked() {
9004 int NW = mWindows.size();
9005 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009006 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009007 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009008
Dianne Hackborna8f60182009-09-01 19:01:50 -07009009 // First remove all existing app windows.
9010 i=0;
9011 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009012 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009013 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009014 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009015 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009016 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009017 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009018 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009019 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009020 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009021 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9022 && lastWallpaper == i-1) {
9023 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009024 }
9025 i++;
9026 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009027
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009028 // The wallpaper window(s) typically live at the bottom of the stack,
9029 // so skip them before adding app tokens.
9030 lastWallpaper++;
9031 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009032
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009033 // First add all of the exiting app tokens... these are no longer
9034 // in the main app list, but still have windows shown. We put them
9035 // in the back because now that the animation is over we no longer
9036 // will care about them.
9037 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009038 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009039 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9040 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009041
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009042 // And add in the still active app tokens in Z order.
9043 NT = mAppTokens.size();
9044 for (int j=0; j<NT; j++) {
9045 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009046 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009047
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009048 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009049 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009050 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009051 + " windows but added " + i);
9052 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009053 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009055 private final void assignLayersLocked() {
9056 int N = mWindows.size();
9057 int curBaseLayer = 0;
9058 int curLayer = 0;
9059 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009060
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009061 if (DEBUG_LAYERS) {
9062 RuntimeException here = new RuntimeException("here");
9063 here.fillInStackTrace();
9064 Log.v(TAG, "Assigning layers", here);
9065 }
9066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009067 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009068 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009069 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9070 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009071 curLayer += WINDOW_LAYER_MULTIPLIER;
9072 w.mLayer = curLayer;
9073 } else {
9074 curBaseLayer = curLayer = w.mBaseLayer;
9075 w.mLayer = curLayer;
9076 }
9077 if (w.mTargetAppToken != null) {
9078 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9079 } else if (w.mAppToken != null) {
9080 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9081 } else {
9082 w.mAnimLayer = w.mLayer;
9083 }
9084 if (w.mIsImWindow) {
9085 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009086 } else if (w.mIsWallpaper) {
9087 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009088 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009089 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009090 + w.mAnimLayer);
9091 //System.out.println(
9092 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9093 }
9094 }
9095
9096 private boolean mInLayout = false;
9097 private final void performLayoutAndPlaceSurfacesLocked() {
9098 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009099 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009100 throw new RuntimeException("Recursive call!");
9101 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009102 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009103 return;
9104 }
9105
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009106 if (mWaitingForConfig) {
9107 // Our configuration has changed (most likely rotation), but we
9108 // don't yet have the complete configuration to report to
9109 // applications. Don't do any window layout until we have it.
9110 return;
9111 }
9112
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009113 if (mDisplay == null) {
9114 // Not yet initialized, nothing to do.
9115 return;
9116 }
9117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 boolean recoveringMemory = false;
9119 if (mForceRemoves != null) {
9120 recoveringMemory = true;
9121 // Wait a little it for things to settle down, and off we go.
9122 for (int i=0; i<mForceRemoves.size(); i++) {
9123 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009124 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009125 removeWindowInnerLocked(ws.mSession, ws);
9126 }
9127 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009128 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009129 Object tmp = new Object();
9130 synchronized (tmp) {
9131 try {
9132 tmp.wait(250);
9133 } catch (InterruptedException e) {
9134 }
9135 }
9136 }
Romain Guy06882f82009-06-10 13:36:04 -07009137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009138 mInLayout = true;
9139 try {
9140 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009142 int i = mPendingRemove.size()-1;
9143 if (i >= 0) {
9144 while (i >= 0) {
9145 WindowState w = mPendingRemove.get(i);
9146 removeWindowInnerLocked(w.mSession, w);
9147 i--;
9148 }
9149 mPendingRemove.clear();
9150
9151 mInLayout = false;
9152 assignLayersLocked();
9153 mLayoutNeeded = true;
9154 performLayoutAndPlaceSurfacesLocked();
9155
9156 } else {
9157 mInLayout = false;
9158 if (mLayoutNeeded) {
9159 requestAnimationLocked(0);
9160 }
9161 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009162 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009163 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9164 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009166 } catch (RuntimeException e) {
9167 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009168 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009169 }
9170 }
9171
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009172 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009173 if (!mLayoutNeeded) {
9174 return 0;
9175 }
9176
9177 mLayoutNeeded = false;
9178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009179 final int dw = mDisplay.getWidth();
9180 final int dh = mDisplay.getHeight();
9181
9182 final int N = mWindows.size();
9183 int i;
9184
Joe Onorato8a9b2202010-02-26 18:56:32 -08009185 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009186 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9187
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009188 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009189
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009190 int seq = mLayoutSeq+1;
9191 if (seq < 0) seq = 0;
9192 mLayoutSeq = seq;
9193
9194 // First perform layout of any root windows (not attached
9195 // to another window).
9196 int topAttached = -1;
9197 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009198 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009200 // Don't do layout of a window if it is not visible, or
9201 // soon won't be visible, to avoid wasting time and funky
9202 // changes while a window is animating away.
9203 final AppWindowToken atoken = win.mAppToken;
9204 final boolean gone = win.mViewVisibility == View.GONE
9205 || !win.mRelayoutCalled
9206 || win.mRootToken.hidden
9207 || (atoken != null && atoken.hiddenRequested)
9208 || win.mAttachedHidden
9209 || win.mExiting || win.mDestroying;
9210
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009211 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9212 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009213 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9214 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009215 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009216 + win.mViewVisibility + " mRelayoutCalled="
9217 + win.mRelayoutCalled + " hidden="
9218 + win.mRootToken.hidden + " hiddenRequested="
9219 + (atoken != null && atoken.hiddenRequested)
9220 + " mAttachedHidden=" + win.mAttachedHidden);
9221 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009222
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009223 // If this view is GONE, then skip it -- keep the current
9224 // frame, and let the caller know so they can ignore it
9225 // if they want. (We do the normal layout for INVISIBLE
9226 // windows, since that means "perform layout as normal,
9227 // just don't display").
9228 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009229 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009230 if (initial) {
9231 win.mContentChanged = false;
9232 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009233 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9234 win.mLayoutSeq = seq;
9235 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9236 + win.mFrame + " mContainingFrame="
9237 + win.mContainingFrame + " mDisplayFrame="
9238 + win.mDisplayFrame);
9239 } else {
9240 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009241 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009243 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009244
9245 // Now perform layout of attached windows, which usually
9246 // depend on the position of the window they are attached to.
9247 // XXX does not deal with windows that are attached to windows
9248 // that are themselves attached.
9249 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009250 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009251
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009252 if (win.mLayoutAttached) {
9253 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9254 + " mHaveFrame=" + win.mHaveFrame
9255 + " mViewVisibility=" + win.mViewVisibility
9256 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009257 // If this view is GONE, then skip it -- keep the current
9258 // frame, and let the caller know so they can ignore it
9259 // if they want. (We do the normal layout for INVISIBLE
9260 // windows, since that means "perform layout as normal,
9261 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009262 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9263 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009264 if (initial) {
9265 win.mContentChanged = false;
9266 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009267 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9268 win.mLayoutSeq = seq;
9269 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9270 + win.mFrame + " mContainingFrame="
9271 + win.mContainingFrame + " mDisplayFrame="
9272 + win.mDisplayFrame);
9273 }
9274 }
9275 }
Jeff Brown349703e2010-06-22 01:27:15 -07009276
9277 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009278 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009279
9280 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009281 }
Romain Guy06882f82009-06-10 13:36:04 -07009282
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009283 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009284 private final void performLayoutAndPlaceSurfacesLockedInner(
9285 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009286 if (mDisplay == null) {
9287 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9288 return;
9289 }
9290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009291 final long currentTime = SystemClock.uptimeMillis();
9292 final int dw = mDisplay.getWidth();
9293 final int dh = mDisplay.getHeight();
9294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 int i;
9296
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009297 if (mFocusMayChange) {
9298 mFocusMayChange = false;
9299 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9300 }
9301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009302 // Initialize state of exiting tokens.
9303 for (i=mExitingTokens.size()-1; i>=0; i--) {
9304 mExitingTokens.get(i).hasVisible = false;
9305 }
9306
9307 // Initialize state of exiting applications.
9308 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9309 mExitingAppTokens.get(i).hasVisible = false;
9310 }
9311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 boolean orientationChangeComplete = true;
9313 Session holdScreen = null;
9314 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009315 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009316 boolean focusDisplayed = false;
9317 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009318 boolean createWatermark = false;
9319
9320 if (mFxSession == null) {
9321 mFxSession = new SurfaceSession();
9322 createWatermark = true;
9323 }
9324
9325 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009326
9327 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009328
9329 if (createWatermark) {
9330 createWatermark();
9331 }
9332 if (mWatermark != null) {
9333 mWatermark.positionSurface(dw, dh);
9334 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009335 if (mStrictModeFlash != null) {
9336 mStrictModeFlash.positionSurface(dw, dh);
9337 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009339 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009340 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009341 int repeats = 0;
9342 int changes = 0;
9343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009344 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009345 repeats++;
9346 if (repeats > 6) {
9347 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9348 mLayoutNeeded = false;
9349 break;
9350 }
9351
9352 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9353 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9354 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9355 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9356 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9357 assignLayersLocked();
9358 mLayoutNeeded = true;
9359 }
9360 }
9361 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9362 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9363 if (updateOrientationFromAppTokensLocked()) {
9364 mLayoutNeeded = true;
9365 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9366 }
9367 }
9368 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9369 mLayoutNeeded = true;
9370 }
9371 }
9372
9373 // FIRST LOOP: Perform a layout, if needed.
9374 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009375 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009376 if (changes != 0) {
9377 continue;
9378 }
9379 } else {
9380 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9381 changes = 0;
9382 }
9383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 final int transactionSequence = ++mTransactionSequence;
9385
9386 // Update animations of all applications, including those
9387 // associated with exiting/removed apps
9388 boolean tokensAnimating = false;
9389 final int NAT = mAppTokens.size();
9390 for (i=0; i<NAT; i++) {
9391 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9392 tokensAnimating = true;
9393 }
9394 }
9395 final int NEAT = mExitingAppTokens.size();
9396 for (i=0; i<NEAT; i++) {
9397 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9398 tokensAnimating = true;
9399 }
9400 }
9401
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009402 // SECOND LOOP: Execute animations and update visibility of windows.
9403
Joe Onorato8a9b2202010-02-26 18:56:32 -08009404 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009405 + transactionSequence + " tokensAnimating="
9406 + tokensAnimating);
9407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009408 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009409
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009410 if (mScreenRotationAnimation != null) {
9411 if (mScreenRotationAnimation.isAnimating()) {
9412 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9413 animating = true;
9414 } else {
9415 mScreenRotationAnimation = null;
9416 }
9417 }
9418 }
9419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009420 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009421 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009422 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009423 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009424
9425 mPolicy.beginAnimationLw(dw, dh);
9426
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009427 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009430 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009431
9432 final WindowManager.LayoutParams attrs = w.mAttrs;
9433
9434 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009435 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009436 if (w.commitFinishDrawingLocked(currentTime)) {
9437 if ((w.mAttrs.flags
9438 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009439 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009440 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009441 wallpaperMayChange = true;
9442 }
9443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009444
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009445 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009446
9447 int animDw = dw;
9448 int animDh = dh;
9449
9450 // If the window has moved due to its containing
9451 // content frame changing, then we'd like to animate
9452 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009453 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009454 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009455 // Frame has moved, containing content frame
9456 // has also moved, and we're not currently animating...
9457 // let's do something.
9458 Animation a = AnimationUtils.loadAnimation(mContext,
9459 com.android.internal.R.anim.window_move_from_decor);
9460 w.setAnimation(a);
9461 animDw = w.mLastFrame.left - w.mFrame.left;
9462 animDh = w.mLastFrame.top - w.mFrame.top;
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009463 w.mContentChanged = false;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009464 }
9465
9466 // Execute animation.
9467 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9468 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009469
9470 // If this window is animating, make a note that we have
9471 // an animating window and take care of a request to run
9472 // a detached wallpaper animation.
9473 if (nowAnimating) {
9474 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9475 windowDetachedWallpaper = w;
9476 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009477 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009478 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009479
9480 // If this window's app token is running a detached wallpaper
9481 // animation, make a note so we can ensure the wallpaper is
9482 // displayed behind it.
9483 if (w.mAppToken != null && w.mAppToken.animation != null
9484 && w.mAppToken.animation.getDetachWallpaper()) {
9485 windowDetachedWallpaper = w;
9486 }
9487
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009488 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9489 wallpaperMayChange = true;
9490 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009491
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009492 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009493 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009494 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009495 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009496 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009497 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009498 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009499 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9500 forceHiding = true;
9501 }
9502 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9503 boolean changed;
9504 if (forceHiding) {
9505 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009506 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9507 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009508 } else {
9509 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009510 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9511 "Now policy shown: " + w);
9512 if (changed) {
9513 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009514 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009515 // Assume we will need to animate. If
9516 // we don't (because the wallpaper will
9517 // stay with the lock screen), then we will
9518 // clean up later.
9519 Animation a = mPolicy.createForceHideEnterAnimation();
9520 if (a != null) {
9521 w.setAnimation(a);
9522 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009523 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009524 if (mCurrentFocus == null ||
9525 mCurrentFocus.mLayer < w.mLayer) {
9526 // We are showing on to of the current
9527 // focus, so re-evaluate focus to make
9528 // sure it is correct.
9529 mFocusMayChange = true;
9530 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009531 }
9532 }
9533 if (changed && (attrs.flags
9534 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9535 wallpaperMayChange = true;
9536 }
9537 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 mPolicy.animatingWindowLw(w, attrs);
9540 }
9541
9542 final AppWindowToken atoken = w.mAppToken;
9543 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9544 if (atoken.lastTransactionSequence != transactionSequence) {
9545 atoken.lastTransactionSequence = transactionSequence;
9546 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9547 atoken.startingDisplayed = false;
9548 }
9549 if ((w.isOnScreen() || w.mAttrs.type
9550 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9551 && !w.mExiting && !w.mDestroying) {
9552 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009553 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009554 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009555 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009556 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009557 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 + " pv=" + w.mPolicyVisibility
9559 + " dp=" + w.mDrawPending
9560 + " cdp=" + w.mCommitDrawPending
9561 + " ah=" + w.mAttachedHidden
9562 + " th=" + atoken.hiddenRequested
9563 + " a=" + w.mAnimating);
9564 }
9565 }
9566 if (w != atoken.startingWindow) {
9567 if (!atoken.freezingScreen || !w.mAppFreezing) {
9568 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009569 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009570 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009571 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 "tokenMayBeDrawn: " + atoken
9573 + " freezingScreen=" + atoken.freezingScreen
9574 + " mAppFreezing=" + w.mAppFreezing);
9575 tokenMayBeDrawn = true;
9576 }
9577 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009578 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009579 atoken.startingDisplayed = true;
9580 }
9581 }
9582 } else if (w.mReadyToShow) {
9583 w.performShowLocked();
9584 }
9585 }
9586
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009587 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009588
9589 if (tokenMayBeDrawn) {
9590 // See if any windows have been drawn, so they (and others
9591 // associated with them) can now be shown.
9592 final int NT = mTokenList.size();
9593 for (i=0; i<NT; i++) {
9594 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9595 if (wtoken == null) {
9596 continue;
9597 }
9598 if (wtoken.freezingScreen) {
9599 int numInteresting = wtoken.numInterestingWindows;
9600 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009601 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009602 "allDrawn: " + wtoken
9603 + " interesting=" + numInteresting
9604 + " drawn=" + wtoken.numDrawnWindows);
9605 wtoken.showAllWindowsLocked();
9606 unsetAppFreezingScreenLocked(wtoken, false, true);
9607 orientationChangeComplete = true;
9608 }
9609 } else if (!wtoken.allDrawn) {
9610 int numInteresting = wtoken.numInterestingWindows;
9611 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009612 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 "allDrawn: " + wtoken
9614 + " interesting=" + numInteresting
9615 + " drawn=" + wtoken.numDrawnWindows);
9616 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009617 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009618
9619 // We can now show all of the drawn windows!
9620 if (!mOpeningApps.contains(wtoken)) {
9621 wtoken.showAllWindowsLocked();
9622 }
9623 }
9624 }
9625 }
9626 }
9627
9628 // If we are ready to perform an app transition, check through
9629 // all of the app tokens to be shown and see if they are ready
9630 // to go.
9631 if (mAppTransitionReady) {
9632 int NN = mOpeningApps.size();
9633 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009634 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009635 "Checking " + NN + " opening apps (frozen="
9636 + mDisplayFrozen + " timeout="
9637 + mAppTransitionTimeout + ")...");
9638 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9639 // If the display isn't frozen, wait to do anything until
9640 // all of the apps are ready. Otherwise just go because
9641 // we'll unfreeze the display when everyone is ready.
9642 for (i=0; i<NN && goodToGo; i++) {
9643 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009644 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009645 "Check opening app" + wtoken + ": allDrawn="
9646 + wtoken.allDrawn + " startingDisplayed="
9647 + wtoken.startingDisplayed);
9648 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9649 && !wtoken.startingMoved) {
9650 goodToGo = false;
9651 }
9652 }
9653 }
9654 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009655 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009656 int transit = mNextAppTransition;
9657 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009658 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009659 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009660 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009662 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009663 mAppTransitionTimeout = false;
9664 mStartingIconInTransition = false;
9665 mSkipAppTransitionAnimation = false;
9666
9667 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9668
Dianne Hackborna8f60182009-09-01 19:01:50 -07009669 // If there are applications waiting to come to the
9670 // top of the stack, now is the time to move their windows.
9671 // (Note that we don't do apps going to the bottom
9672 // here -- we want to keep their windows in the old
9673 // Z-order until the animation completes.)
9674 if (mToTopApps.size() > 0) {
9675 NN = mAppTokens.size();
9676 for (i=0; i<NN; i++) {
9677 AppWindowToken wtoken = mAppTokens.get(i);
9678 if (wtoken.sendingToTop) {
9679 wtoken.sendingToTop = false;
9680 moveAppWindowsLocked(wtoken, NN, false);
9681 }
9682 }
9683 mToTopApps.clear();
9684 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009685
Dianne Hackborn25994b42009-09-04 14:21:19 -07009686 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009687
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009688 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009689 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009690
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009691 // The top-most window will supply the layout params,
9692 // and we will determine it below.
9693 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009694 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009695 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009696
Joe Onorato8a9b2202010-02-26 18:56:32 -08009697 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009698 "New wallpaper target=" + mWallpaperTarget
9699 + ", lower target=" + mLowerWallpaperTarget
9700 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009701 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009702 // Do a first pass through the tokens for two
9703 // things:
9704 // (1) Determine if both the closing and opening
9705 // app token sets are wallpaper targets, in which
9706 // case special animations are needed
9707 // (since the wallpaper needs to stay static
9708 // behind them).
9709 // (2) Find the layout params of the top-most
9710 // application window in the tokens, which is
9711 // what will control the animation theme.
9712 final int NC = mClosingApps.size();
9713 NN = NC + mOpeningApps.size();
9714 for (i=0; i<NN; i++) {
9715 AppWindowToken wtoken;
9716 int mode;
9717 if (i < NC) {
9718 wtoken = mClosingApps.get(i);
9719 mode = 1;
9720 } else {
9721 wtoken = mOpeningApps.get(i-NC);
9722 mode = 2;
9723 }
9724 if (mLowerWallpaperTarget != null) {
9725 if (mLowerWallpaperTarget.mAppToken == wtoken
9726 || mUpperWallpaperTarget.mAppToken == wtoken) {
9727 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009728 }
9729 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009730 if (wtoken.appFullscreen) {
9731 WindowState ws = wtoken.findMainWindow();
9732 if (ws != null) {
9733 // If this is a compatibility mode
9734 // window, we will always use its anim.
9735 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9736 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009737 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009738 bestAnimLayer = Integer.MAX_VALUE;
9739 } else if (ws.mLayer > bestAnimLayer) {
9740 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009741 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009742 bestAnimLayer = ws.mLayer;
9743 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009744 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009745 }
9746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009747
Dianne Hackborn25994b42009-09-04 14:21:19 -07009748 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009749 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009750 "Wallpaper animation!");
9751 switch (transit) {
9752 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9753 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9754 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9755 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9756 break;
9757 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9758 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9759 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9760 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9761 break;
9762 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009763 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009764 "New transit: " + transit);
9765 } else if (oldWallpaper != null) {
9766 // We are transitioning from an activity with
9767 // a wallpaper to one without.
9768 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009769 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009770 "New transit away from wallpaper: " + transit);
9771 } else if (mWallpaperTarget != null) {
9772 // We are transitioning from an activity without
9773 // a wallpaper to now showing the wallpaper
9774 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009775 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009776 "New transit into wallpaper: " + transit);
9777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009778
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009779 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9780 mLastEnterAnimToken = animToken;
9781 mLastEnterAnimParams = animLp;
9782 } else if (mLastEnterAnimParams != null) {
9783 animLp = mLastEnterAnimParams;
9784 mLastEnterAnimToken = null;
9785 mLastEnterAnimParams = null;
9786 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009787
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009788 // If all closing windows are obscured, then there is
9789 // no need to do an animation. This is the case, for
9790 // example, when this transition is being done behind
9791 // the lock screen.
9792 if (!mPolicy.allowAppAnimationsLw()) {
9793 animLp = null;
9794 }
9795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009796 NN = mOpeningApps.size();
9797 for (i=0; i<NN; i++) {
9798 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009799 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 "Now opening app" + wtoken);
9801 wtoken.reportedVisible = false;
9802 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009803 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009804 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009806 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009807 wtoken.showAllWindowsLocked();
9808 }
9809 NN = mClosingApps.size();
9810 for (i=0; i<NN; i++) {
9811 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009812 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 "Now closing app" + wtoken);
9814 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009815 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009816 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009817 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009818 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009819 // Force the allDrawn flag, because we want to start
9820 // this guy's animations regardless of whether it's
9821 // gotten drawn.
9822 wtoken.allDrawn = true;
9823 }
9824
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009825 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 mOpeningApps.clear();
9828 mClosingApps.clear();
9829
9830 // This has changed the visibility of windows, so perform
9831 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009832 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009833 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009834 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9835 assignLayersLocked();
9836 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009837 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009838 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 }
9840 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009841
Dianne Hackborn16064f92010-03-25 00:47:24 -07009842 int adjResult = 0;
9843
Dianne Hackborna8f60182009-09-01 19:01:50 -07009844 if (!animating && mAppTransitionRunning) {
9845 // We have finished the animation of an app transition. To do
9846 // this, we have delayed a lot of operations like showing and
9847 // hiding apps, moving apps in Z-order, etc. The app token list
9848 // reflects the correct Z-order, but the window list may now
9849 // be out of sync with it. So here we will just rebuild the
9850 // entire app window list. Fun!
9851 mAppTransitionRunning = false;
9852 // Clear information about apps that were moving.
9853 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009854
Dianne Hackborna8f60182009-09-01 19:01:50 -07009855 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009856 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009857 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009858 moveInputMethodWindowsIfNeededLocked(false);
9859 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009860 // Since the window list has been rebuilt, focus might
9861 // have to be recomputed since the actual order of windows
9862 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009863 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009864 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009865
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009866 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009867 // At this point, there was a window with a wallpaper that
9868 // was force hiding other windows behind it, but now it
9869 // is going away. This may be simple -- just animate
9870 // away the wallpaper and its window -- or it may be
9871 // hard -- the wallpaper now needs to be shown behind
9872 // something that was hidden.
9873 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009874 if (mLowerWallpaperTarget != null
9875 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009876 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009877 "wallpaperForceHiding changed with lower="
9878 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009879 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009880 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9881 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9882 if (mLowerWallpaperTarget.mAppToken.hidden) {
9883 // The lower target has become hidden before we
9884 // actually started the animation... let's completely
9885 // re-evaluate everything.
9886 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009887 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009888 }
9889 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009890 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009891 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009892 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009893 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009894 + " NEW: " + mWallpaperTarget
9895 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009896 if (mLowerWallpaperTarget == null) {
9897 // Whoops, we don't need a special wallpaper animation.
9898 // Clear them out.
9899 forceHiding = false;
9900 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009901 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009902 if (w.mSurface != null) {
9903 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009904 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009905 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009906 forceHiding = true;
9907 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9908 if (!w.mAnimating) {
9909 // We set the animation above so it
9910 // is not yet running.
9911 w.clearAnimation();
9912 }
9913 }
9914 }
9915 }
9916 }
9917 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009918
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009919 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
9920 if (DEBUG_WALLPAPER) Slog.v(TAG,
9921 "Detached wallpaper changed from " + mWindowDetachedWallpaper
9922 + windowDetachedWallpaper);
9923 mWindowDetachedWallpaper = windowDetachedWallpaper;
9924 wallpaperMayChange = true;
9925 }
9926
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009927 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009928 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009929 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009930 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009931 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009932
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009933 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009934 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009935 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009936 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009937 assignLayersLocked();
9938 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009939 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009940 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009941 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009942 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009943
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009944 if (mFocusMayChange) {
9945 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009946 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009947 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009948 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009949 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009950 }
9951
9952 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009953 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009954 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009955
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009956 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9957 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009958
Jeff Browne33348b2010-07-15 23:54:05 -07009959 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009960 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009961
9962 // THIRD LOOP: Update the surfaces of all windows.
9963
9964 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9965
9966 boolean obscured = false;
9967 boolean blurring = false;
9968 boolean dimming = false;
9969 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009970 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009971 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009972
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009973 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009975 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009976 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009977
9978 boolean displayed = false;
9979 final WindowManager.LayoutParams attrs = w.mAttrs;
9980 final int attrFlags = attrs.flags;
9981
9982 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009983 // XXX NOTE: The logic here could be improved. We have
9984 // the decision about whether to resize a window separated
9985 // from whether to hide the surface. This can cause us to
9986 // resize a surface even if we are going to hide it. You
9987 // can see this by (1) holding device in landscape mode on
9988 // home screen; (2) tapping browser icon (device will rotate
9989 // to landscape; (3) tap home. The wallpaper will be resized
9990 // in step 2 but then immediately hidden, causing us to
9991 // have to resize and then redraw it again in step 3. It
9992 // would be nice to figure out how to avoid this, but it is
9993 // difficult because we do need to resize surfaces in some
9994 // cases while they are hidden such as when first showing a
9995 // window.
9996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009997 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009998 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009999 TAG, "Placing surface #" + i + " " + w.mSurface
10000 + ": new=" + w.mShownFrame + ", old="
10001 + w.mLastShownFrame);
10002
10003 boolean resize;
10004 int width, height;
10005 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10006 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10007 w.mLastRequestedHeight != w.mRequestedHeight;
10008 // for a scaled surface, we just want to use
10009 // the requested size.
10010 width = w.mRequestedWidth;
10011 height = w.mRequestedHeight;
10012 w.mLastRequestedWidth = width;
10013 w.mLastRequestedHeight = height;
10014 w.mLastShownFrame.set(w.mShownFrame);
10015 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010016 if (SHOW_TRANSACTIONS) logSurface(w,
10017 "POS " + w.mShownFrame.left
10018 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010019 w.mSurfaceX = w.mShownFrame.left;
10020 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10022 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010023 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010024 if (!recoveringMemory) {
10025 reclaimSomeSurfaceMemoryLocked(w, "position");
10026 }
10027 }
10028 } else {
10029 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10030 width = w.mShownFrame.width();
10031 height = w.mShownFrame.height();
10032 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 }
10034
10035 if (resize) {
10036 if (width < 1) width = 1;
10037 if (height < 1) height = 1;
10038 if (w.mSurface != null) {
10039 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010040 if (SHOW_TRANSACTIONS) logSurface(w,
10041 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010042 + w.mShownFrame.top + " SIZE "
10043 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010044 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010045 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010046 w.mSurfaceW = width;
10047 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010048 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010049 w.mSurfaceX = w.mShownFrame.left;
10050 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010051 w.mSurface.setPosition(w.mShownFrame.left,
10052 w.mShownFrame.top);
10053 } catch (RuntimeException e) {
10054 // If something goes wrong with the surface (such
10055 // as running out of memory), don't take down the
10056 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010057 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058 + "size=(" + width + "x" + height
10059 + "), pos=(" + w.mShownFrame.left
10060 + "," + w.mShownFrame.top + ")", e);
10061 if (!recoveringMemory) {
10062 reclaimSomeSurfaceMemoryLocked(w, "size");
10063 }
10064 }
10065 }
10066 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010067 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010068 w.mContentInsetsChanged =
10069 !w.mLastContentInsets.equals(w.mContentInsets);
10070 w.mVisibleInsetsChanged =
10071 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010072 boolean configChanged =
10073 w.mConfiguration != mCurConfiguration
10074 && (w.mConfiguration == null
10075 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010076 if (DEBUG_CONFIGURATION && configChanged) {
10077 Slog.v(TAG, "Win " + w + " config changed: "
10078 + mCurConfiguration);
10079 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010080 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010081 + ": configChanged=" + configChanged
10082 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010083 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010084 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010085 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010086 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010087 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010088 w.mLastFrame.set(w.mFrame);
10089 w.mLastContentInsets.set(w.mContentInsets);
10090 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010091 // If the screen is currently frozen, then keep
10092 // it frozen until this window draws at its new
10093 // orientation.
10094 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010095 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010096 "Resizing while display frozen: " + w);
10097 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010098 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010099 mWindowsFreezingScreen = true;
10100 // XXX should probably keep timeout from
10101 // when we first froze the display.
10102 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10103 mH.sendMessageDelayed(mH.obtainMessage(
10104 H.WINDOW_FREEZE_TIMEOUT), 2000);
10105 }
10106 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010107 // If the orientation is changing, then we need to
10108 // hold off on unfreezing the display until this
10109 // window has been redrawn; to do that, we need
10110 // to go through the process of getting informed
10111 // by the application when it has finished drawing.
10112 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010113 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010114 "Orientation start waiting for draw in "
10115 + w + ", surface " + w.mSurface);
10116 w.mDrawPending = true;
10117 w.mCommitDrawPending = false;
10118 w.mReadyToShow = false;
10119 if (w.mAppToken != null) {
10120 w.mAppToken.allDrawn = false;
10121 }
10122 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010123 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010124 "Resizing window " + w + " to " + w.mFrame);
10125 mResizingWindows.add(w);
10126 } else if (w.mOrientationChanging) {
10127 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010128 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010129 "Orientation not waiting for draw in "
10130 + w + ", surface " + w.mSurface);
10131 w.mOrientationChanging = false;
10132 }
10133 }
10134 }
10135
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010136 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010137 if (!w.mLastHidden) {
10138 //dump();
10139 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010140 if (SHOW_TRANSACTIONS) logSurface(w,
10141 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010142 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010143 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144 try {
10145 w.mSurface.hide();
10146 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010147 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010148 }
10149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010150 }
10151 // If we are waiting for this window to handle an
10152 // orientation change, well, it is hidden, so
10153 // doesn't really matter. Note that this does
10154 // introduce a potential glitch if the window
10155 // becomes unhidden before it has drawn for the
10156 // new orientation.
10157 if (w.mOrientationChanging) {
10158 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010159 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010160 "Orientation change skips hidden " + w);
10161 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010162 } else if (w.mLastLayer != w.mAnimLayer
10163 || w.mLastAlpha != w.mShownAlpha
10164 || w.mLastDsDx != w.mDsDx
10165 || w.mLastDtDx != w.mDtDx
10166 || w.mLastDsDy != w.mDsDy
10167 || w.mLastDtDy != w.mDtDy
10168 || w.mLastHScale != w.mHScale
10169 || w.mLastVScale != w.mVScale
10170 || w.mLastHidden) {
10171 displayed = true;
10172 w.mLastAlpha = w.mShownAlpha;
10173 w.mLastLayer = w.mAnimLayer;
10174 w.mLastDsDx = w.mDsDx;
10175 w.mLastDtDx = w.mDtDx;
10176 w.mLastDsDy = w.mDsDy;
10177 w.mLastDtDy = w.mDtDy;
10178 w.mLastHScale = w.mHScale;
10179 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010180 if (SHOW_TRANSACTIONS) logSurface(w,
10181 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010182 + " matrix=[" + (w.mDsDx*w.mHScale)
10183 + "," + (w.mDtDx*w.mVScale)
10184 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010185 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010186 if (w.mSurface != null) {
10187 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010188 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010189 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010190 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010191 w.mSurface.setLayer(w.mAnimLayer);
10192 w.mSurface.setMatrix(
10193 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10194 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10195 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010196 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010197 if (!recoveringMemory) {
10198 reclaimSomeSurfaceMemoryLocked(w, "update");
10199 }
10200 }
10201 }
10202
10203 if (w.mLastHidden && !w.mDrawPending
10204 && !w.mCommitDrawPending
10205 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010206 if (SHOW_TRANSACTIONS) logSurface(w,
10207 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010208 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010209 + " during relayout");
10210 if (showSurfaceRobustlyLocked(w)) {
10211 w.mHasDrawn = true;
10212 w.mLastHidden = false;
10213 } else {
10214 w.mOrientationChanging = false;
10215 }
10216 }
10217 if (w.mSurface != null) {
10218 w.mToken.hasVisible = true;
10219 }
10220 } else {
10221 displayed = true;
10222 }
10223
10224 if (displayed) {
10225 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010226 if (attrs.width == LayoutParams.MATCH_PARENT
10227 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010228 covered = true;
10229 }
10230 }
10231 if (w.mOrientationChanging) {
10232 if (w.mDrawPending || w.mCommitDrawPending) {
10233 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010234 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 "Orientation continue waiting for draw in " + w);
10236 } else {
10237 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010238 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010239 "Orientation change complete in " + w);
10240 }
10241 }
10242 w.mToken.hasVisible = true;
10243 }
10244 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010245 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010246 "Orientation change skips hidden " + w);
10247 w.mOrientationChanging = false;
10248 }
10249
10250 final boolean canBeSeen = w.isDisplayedLw();
10251
10252 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10253 focusDisplayed = true;
10254 }
10255
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010256 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010258 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010259 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010260 if (w.mSurface != null) {
10261 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10262 holdScreen = w.mSession;
10263 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010264 if (!syswin && w.mAttrs.screenBrightness >= 0
10265 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 screenBrightness = w.mAttrs.screenBrightness;
10267 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010268 if (!syswin && w.mAttrs.buttonBrightness >= 0
10269 && buttonBrightness < 0) {
10270 buttonBrightness = w.mAttrs.buttonBrightness;
10271 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010272 if (canBeSeen
10273 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10274 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10275 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010276 syswin = true;
10277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010279
Dianne Hackborn25994b42009-09-04 14:21:19 -070010280 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10281 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010282 // This window completely covers everything behind it,
10283 // so we want to leave all of them as unblurred (for
10284 // performance reasons).
10285 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010286 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010287 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010288 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010289 obscured = true;
10290 if (mBackgroundFillerSurface == null) {
10291 try {
10292 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010293 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010294 0, dw, dh,
10295 PixelFormat.OPAQUE,
10296 Surface.FX_SURFACE_NORMAL);
10297 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010298 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010299 }
10300 }
10301 try {
10302 mBackgroundFillerSurface.setPosition(0, 0);
10303 mBackgroundFillerSurface.setSize(dw, dh);
10304 // Using the same layer as Dim because they will never be shown at the
10305 // same time.
10306 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10307 mBackgroundFillerSurface.show();
10308 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010309 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010310 }
10311 backgroundFillerShown = true;
10312 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010313 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010314 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010315 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010316 + ": blurring=" + blurring
10317 + " obscured=" + obscured
10318 + " displayed=" + displayed);
10319 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10320 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010321 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010322 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010323 if (mDimAnimator == null) {
10324 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010325 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010326 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010327 mDimAnimator.updateParameters(mContext.getResources(),
10328 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 }
10331 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10332 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010333 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010334 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010336 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010337 + mBlurSurface + ": CREATE");
10338 try {
Romain Guy06882f82009-06-10 13:36:04 -070010339 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010340 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010341 -1, 16, 16,
10342 PixelFormat.OPAQUE,
10343 Surface.FX_SURFACE_BLUR);
10344 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010345 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346 }
10347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010348 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010349 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10350 + mBlurSurface + ": pos=(0,0) (" +
10351 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010352 mBlurSurface.setPosition(0, 0);
10353 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010354 mBlurSurface.setLayer(w.mAnimLayer-2);
10355 if (!mBlurShown) {
10356 try {
10357 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10358 + mBlurSurface + ": SHOW");
10359 mBlurSurface.show();
10360 } catch (RuntimeException e) {
10361 Slog.w(TAG, "Failure showing blur surface", e);
10362 }
10363 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010364 }
10365 }
10366 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 }
10368 }
10369 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010370
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010371 if (obscuredChanged && mWallpaperTarget == w) {
10372 // This is the wallpaper target and its obscured state
10373 // changed... make sure the current wallaper's visibility
10374 // has been updated accordingly.
10375 updateWallpaperVisibilityLocked();
10376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010377 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010378
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010379 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10380 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010381 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010382 try {
10383 mBackgroundFillerSurface.hide();
10384 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010385 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010386 }
10387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010388
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010389 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010390 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10391 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010392 }
Romain Guy06882f82009-06-10 13:36:04 -070010393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010395 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010396 + ": HIDE");
10397 try {
10398 mBlurSurface.hide();
10399 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010400 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 }
10402 mBlurShown = false;
10403 }
10404
Joe Onorato8a9b2202010-02-26 18:56:32 -080010405 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010406 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010407 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010408 }
10409
Jeff Browne33348b2010-07-15 23:54:05 -070010410 mInputMonitor.updateInputWindowsLw();
10411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010413
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010414 if (mWatermark != null) {
10415 mWatermark.drawIfNeeded();
10416 }
10417
Joe Onorato8a9b2202010-02-26 18:56:32 -080010418 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010419 "With display frozen, orientationChangeComplete="
10420 + orientationChangeComplete);
10421 if (orientationChangeComplete) {
10422 if (mWindowsFreezingScreen) {
10423 mWindowsFreezingScreen = false;
10424 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10425 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010426 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427 }
Romain Guy06882f82009-06-10 13:36:04 -070010428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429 i = mResizingWindows.size();
10430 if (i > 0) {
10431 do {
10432 i--;
10433 WindowState win = mResizingWindows.get(i);
10434 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010435 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10436 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010437 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010438 boolean configChanged =
10439 win.mConfiguration != mCurConfiguration
10440 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010441 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10442 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10443 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010444 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010445 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010446 + " / " + mCurConfiguration + " / 0x"
10447 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010448 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010449 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010450 win.mClient.resized(win.mFrame.width(),
10451 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010452 win.mLastVisibleInsets, win.mDrawPending,
10453 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 win.mContentInsetsChanged = false;
10455 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010456 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010457 } catch (RemoteException e) {
10458 win.mOrientationChanging = false;
10459 }
10460 } while (i > 0);
10461 mResizingWindows.clear();
10462 }
Romain Guy06882f82009-06-10 13:36:04 -070010463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010464 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010465 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 i = mDestroySurface.size();
10467 if (i > 0) {
10468 do {
10469 i--;
10470 WindowState win = mDestroySurface.get(i);
10471 win.mDestroying = false;
10472 if (mInputMethodWindow == win) {
10473 mInputMethodWindow = null;
10474 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010475 if (win == mWallpaperTarget) {
10476 wallpaperDestroyed = true;
10477 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 win.destroySurfaceLocked();
10479 } while (i > 0);
10480 mDestroySurface.clear();
10481 }
10482
10483 // Time to remove any exiting tokens?
10484 for (i=mExitingTokens.size()-1; i>=0; i--) {
10485 WindowToken token = mExitingTokens.get(i);
10486 if (!token.hasVisible) {
10487 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010488 if (token.windowType == TYPE_WALLPAPER) {
10489 mWallpaperTokens.remove(token);
10490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 }
10492 }
10493
10494 // Time to remove any exiting applications?
10495 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10496 AppWindowToken token = mExitingAppTokens.get(i);
10497 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010498 // Make sure there is no animation running on this token,
10499 // so any windows associated with it will be removed as
10500 // soon as their animations are complete
10501 token.animation = null;
10502 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010503 mAppTokens.remove(token);
10504 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010505 if (mLastEnterAnimToken == token) {
10506 mLastEnterAnimToken = null;
10507 mLastEnterAnimParams = null;
10508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509 }
10510 }
10511
Dianne Hackborna8f60182009-09-01 19:01:50 -070010512 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010513
Dianne Hackborna8f60182009-09-01 19:01:50 -070010514 if (!animating && mAppTransitionRunning) {
10515 // We have finished the animation of an app transition. To do
10516 // this, we have delayed a lot of operations like showing and
10517 // hiding apps, moving apps in Z-order, etc. The app token list
10518 // reflects the correct Z-order, but the window list may now
10519 // be out of sync with it. So here we will just rebuild the
10520 // entire app window list. Fun!
10521 mAppTransitionRunning = false;
10522 needRelayout = true;
10523 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010524 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010525 // Clear information about apps that were moving.
10526 mToBottomApps.clear();
10527 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010529 if (focusDisplayed) {
10530 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10531 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010532 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010533 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010534 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010535 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010536 requestAnimationLocked(0);
10537 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010538 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10539 }
Jeff Browneb857f12010-07-16 10:06:33 -070010540
Jeff Browne33348b2010-07-15 23:54:05 -070010541 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010542
Jeff Brown8e03b752010-06-13 19:16:55 -070010543 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010544 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10545 mPowerManager.setScreenBrightnessOverride(-1);
10546 } else {
10547 mPowerManager.setScreenBrightnessOverride((int)
10548 (screenBrightness * Power.BRIGHTNESS_ON));
10549 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010550 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10551 mPowerManager.setButtonBrightnessOverride(-1);
10552 } else {
10553 mPowerManager.setButtonBrightnessOverride((int)
10554 (buttonBrightness * Power.BRIGHTNESS_ON));
10555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010556 if (holdScreen != mHoldingScreenOn) {
10557 mHoldingScreenOn = holdScreen;
10558 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10559 mH.sendMessage(m);
10560 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010561
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010562 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010563 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010564 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10565 LocalPowerManager.BUTTON_EVENT, true);
10566 mTurnOnScreen = false;
10567 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010568
10569 // Check to see if we are now in a state where the screen should
10570 // be enabled, because the window obscured flags have changed.
10571 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010572 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010573
10574 /**
10575 * Must be called with the main window manager lock held.
10576 */
10577 void setHoldScreenLocked(boolean holding) {
10578 boolean state = mHoldingScreenWakeLock.isHeld();
10579 if (holding != state) {
10580 if (holding) {
10581 mHoldingScreenWakeLock.acquire();
10582 } else {
10583 mPolicy.screenOnStoppedLw();
10584 mHoldingScreenWakeLock.release();
10585 }
10586 }
10587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588
10589 void requestAnimationLocked(long delay) {
10590 if (!mAnimationPending) {
10591 mAnimationPending = true;
10592 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10593 }
10594 }
Romain Guy06882f82009-06-10 13:36:04 -070010595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010596 /**
10597 * Have the surface flinger show a surface, robustly dealing with
10598 * error conditions. In particular, if there is not enough memory
10599 * to show the surface, then we will try to get rid of other surfaces
10600 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010601 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010602 * @return Returns true if the surface was successfully shown.
10603 */
10604 boolean showSurfaceRobustlyLocked(WindowState win) {
10605 try {
10606 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010607 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010608 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010609 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010610 if (DEBUG_VISIBILITY) Slog.v(TAG,
10611 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010612 win.mTurnOnScreen = false;
10613 mTurnOnScreen = true;
10614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010615 }
10616 return true;
10617 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010618 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010619 }
Romain Guy06882f82009-06-10 13:36:04 -070010620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010621 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010623 return false;
10624 }
Romain Guy06882f82009-06-10 13:36:04 -070010625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010626 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10627 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010628
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010629 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010630 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 if (mForceRemoves == null) {
10633 mForceRemoves = new ArrayList<WindowState>();
10634 }
Romain Guy06882f82009-06-10 13:36:04 -070010635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010636 long callingIdentity = Binder.clearCallingIdentity();
10637 try {
10638 // There was some problem... first, do a sanity check of the
10639 // window list to make sure we haven't left any dangling surfaces
10640 // around.
10641 int N = mWindows.size();
10642 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010643 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010644 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010645 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010646 if (ws.mSurface != null) {
10647 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010648 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010649 + ws + " surface=" + ws.mSurface
10650 + " token=" + win.mToken
10651 + " pid=" + ws.mSession.mPid
10652 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010653 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010654 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 ws.mSurface = null;
10656 mForceRemoves.add(ws);
10657 i--;
10658 N--;
10659 leakedSurface = true;
10660 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010661 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662 + ws + " surface=" + ws.mSurface
10663 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010664 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010665 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 ws.mSurface = null;
10667 leakedSurface = true;
10668 }
10669 }
10670 }
Romain Guy06882f82009-06-10 13:36:04 -070010671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010672 boolean killedApps = false;
10673 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010674 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010675 SparseIntArray pidCandidates = new SparseIntArray();
10676 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010677 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010678 if (ws.mSurface != null) {
10679 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10680 }
10681 }
10682 if (pidCandidates.size() > 0) {
10683 int[] pids = new int[pidCandidates.size()];
10684 for (int i=0; i<pids.length; i++) {
10685 pids[i] = pidCandidates.keyAt(i);
10686 }
10687 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010688 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010689 killedApps = true;
10690 }
10691 } catch (RemoteException e) {
10692 }
10693 }
10694 }
Romain Guy06882f82009-06-10 13:36:04 -070010695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010696 if (leakedSurface || killedApps) {
10697 // We managed to reclaim some memory, so get rid of the trouble
10698 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010699 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010700 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010701 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010702 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010703 win.mSurface = null;
10704 }
Romain Guy06882f82009-06-10 13:36:04 -070010705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010706 try {
10707 win.mClient.dispatchGetNewSurface();
10708 } catch (RemoteException e) {
10709 }
10710 }
10711 } finally {
10712 Binder.restoreCallingIdentity(callingIdentity);
10713 }
10714 }
Romain Guy06882f82009-06-10 13:36:04 -070010715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010716 private boolean updateFocusedWindowLocked(int mode) {
10717 WindowState newFocus = computeFocusedWindowLocked();
10718 if (mCurrentFocus != newFocus) {
10719 // This check makes sure that we don't already have the focus
10720 // change message pending.
10721 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10722 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010723 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010724 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10725 final WindowState oldFocus = mCurrentFocus;
10726 mCurrentFocus = newFocus;
10727 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010729 final WindowState imWindow = mInputMethodWindow;
10730 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010731 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010732 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010733 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10734 mLayoutNeeded = true;
10735 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010736 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080010737 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010738 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10739 // Client will do the layout, but we need to assign layers
10740 // for handleNewWindowLocked() below.
10741 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010742 }
10743 }
Jeff Brown349703e2010-06-22 01:27:15 -070010744
10745 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10746 // If we defer assigning layers, then the caller is responsible for
10747 // doing this part.
10748 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010750 return true;
10751 }
10752 return false;
10753 }
Jeff Brown349703e2010-06-22 01:27:15 -070010754
10755 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010756 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010757 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010758
10759 private WindowState computeFocusedWindowLocked() {
10760 WindowState result = null;
10761 WindowState win;
10762
10763 int i = mWindows.size() - 1;
10764 int nextAppIndex = mAppTokens.size()-1;
10765 WindowToken nextApp = nextAppIndex >= 0
10766 ? mAppTokens.get(nextAppIndex) : null;
10767
10768 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010769 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770
Joe Onorato8a9b2202010-02-26 18:56:32 -080010771 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010772 TAG, "Looking for focus: " + i
10773 + " = " + win
10774 + ", flags=" + win.mAttrs.flags
10775 + ", canReceive=" + win.canReceiveKeys());
10776
10777 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 // If this window's application has been removed, just skip it.
10780 if (thisApp != null && thisApp.removed) {
10781 i--;
10782 continue;
10783 }
Romain Guy06882f82009-06-10 13:36:04 -070010784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 // If there is a focused app, don't allow focus to go to any
10786 // windows below it. If this is an application window, step
10787 // through the app tokens until we find its app.
10788 if (thisApp != null && nextApp != null && thisApp != nextApp
10789 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10790 int origAppIndex = nextAppIndex;
10791 while (nextAppIndex > 0) {
10792 if (nextApp == mFocusedApp) {
10793 // Whoops, we are below the focused app... no focus
10794 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010795 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 TAG, "Reached focused app: " + mFocusedApp);
10797 return null;
10798 }
10799 nextAppIndex--;
10800 nextApp = mAppTokens.get(nextAppIndex);
10801 if (nextApp == thisApp) {
10802 break;
10803 }
10804 }
10805 if (thisApp != nextApp) {
10806 // Uh oh, the app token doesn't exist! This shouldn't
10807 // happen, but if it does we can get totally hosed...
10808 // so restart at the original app.
10809 nextAppIndex = origAppIndex;
10810 nextApp = mAppTokens.get(nextAppIndex);
10811 }
10812 }
10813
10814 // Dispatch to this window if it is wants key events.
10815 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010816 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010817 TAG, "Found focus @ " + i + " = " + win);
10818 result = win;
10819 break;
10820 }
10821
10822 i--;
10823 }
10824
10825 return result;
10826 }
10827
10828 private void startFreezingDisplayLocked() {
10829 if (mDisplayFrozen) {
10830 return;
10831 }
Romain Guy06882f82009-06-10 13:36:04 -070010832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010833 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010835 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010836 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010837 if (mFreezeGcPending != 0) {
10838 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010839 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010840 mH.removeMessages(H.FORCE_GC);
10841 Runtime.getRuntime().gc();
10842 mFreezeGcPending = now;
10843 }
10844 } else {
10845 mFreezeGcPending = now;
10846 }
Romain Guy06882f82009-06-10 13:36:04 -070010847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010848 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010849
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010850 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010851
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010852 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10853 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010854 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010855 mAppTransitionReady = true;
10856 }
Romain Guy06882f82009-06-10 13:36:04 -070010857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010858 if (PROFILE_ORIENTATION) {
10859 File file = new File("/data/system/frozen");
10860 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10861 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010862
10863 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010864 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
10865 mScreenRotationAnimation.kill();
10866 mScreenRotationAnimation = null;
10867 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010868 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010869 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
10870 mDisplay, mFxSession);
Dianne Hackborna1111872010-11-23 20:55:11 -080010871 }
10872 } else {
10873 Surface.freezeDisplay(0);
10874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 }
Romain Guy06882f82009-06-10 13:36:04 -070010876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010877 private void stopFreezingDisplayLocked() {
10878 if (!mDisplayFrozen) {
10879 return;
10880 }
Romain Guy06882f82009-06-10 13:36:04 -070010881
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010882 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10883 return;
10884 }
10885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010886 mDisplayFrozen = false;
10887 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10888 if (PROFILE_ORIENTATION) {
10889 Debug.stopMethodTracing();
10890 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010891
10892 if (CUSTOM_SCREEN_ROTATION) {
10893 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080010894 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
10895 mTransitionAnimationScale)) {
10896 requestAnimationLocked(0);
10897 } else {
10898 mScreenRotationAnimation = null;
10899 }
Dianne Hackborna1111872010-11-23 20:55:11 -080010900 }
10901 } else {
10902 Surface.unfreezeDisplay(0);
10903 }
Romain Guy06882f82009-06-10 13:36:04 -070010904
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010905 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010906
Christopher Tateb696aee2010-04-02 19:08:30 -070010907 // While the display is frozen we don't re-compute the orientation
10908 // to avoid inconsistent states. However, something interesting
10909 // could have actually changed during that time so re-evaluate it
10910 // now to catch that.
10911 if (updateOrientationFromAppTokensLocked()) {
10912 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10913 }
10914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010915 // A little kludge: a lot could have happened while the
10916 // display was frozen, so now that we are coming back we
10917 // do a gc so that any remote references the system
10918 // processes holds on others can be released if they are
10919 // no longer needed.
10920 mH.removeMessages(H.FORCE_GC);
10921 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10922 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 mScreenFrozenLock.release();
10925 }
Romain Guy06882f82009-06-10 13:36:04 -070010926
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010927 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10928 DisplayMetrics dm) {
10929 if (index < tokens.length) {
10930 String str = tokens[index];
10931 if (str != null && str.length() > 0) {
10932 try {
10933 int val = Integer.parseInt(str);
10934 return val;
10935 } catch (Exception e) {
10936 }
10937 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010938 }
10939 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10940 return defDps;
10941 }
10942 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10943 return val;
10944 }
10945
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010946 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010947 final String[] mTokens;
10948 final String mText;
10949 final Paint mTextPaint;
10950 final int mTextWidth;
10951 final int mTextHeight;
10952 final int mTextAscent;
10953 final int mTextDescent;
10954 final int mDeltaX;
10955 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010956
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010957 Surface mSurface;
10958 int mLastDW;
10959 int mLastDH;
10960 boolean mDrawNeeded;
10961
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010962 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010963 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010964 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010965
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010966 if (false) {
10967 Log.i(TAG, "*********************** WATERMARK");
10968 for (int i=0; i<tokens.length; i++) {
10969 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10970 }
10971 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010972
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010973 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010974
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010975 StringBuilder builder = new StringBuilder(32);
10976 int len = mTokens[0].length();
10977 len = len & ~1;
10978 for (int i=0; i<len; i+=2) {
10979 int c1 = mTokens[0].charAt(i);
10980 int c2 = mTokens[0].charAt(i+1);
10981 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10982 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10983 else c1 -= '0';
10984 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10985 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10986 else c2 -= '0';
10987 builder.append((char)(255-((c1*16)+c2)));
10988 }
10989 mText = builder.toString();
10990 if (false) {
10991 Log.i(TAG, "Final text: " + mText);
10992 }
10993
10994 int fontSize = getPropertyInt(tokens, 1,
10995 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10996
10997 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10998 mTextPaint.setTextSize(fontSize);
10999 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11000
11001 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11002 mTextWidth = (int)mTextPaint.measureText(mText);
11003 mTextAscent = fm.ascent;
11004 mTextDescent = fm.descent;
11005 mTextHeight = fm.descent - fm.ascent;
11006
11007 mDeltaX = getPropertyInt(tokens, 2,
11008 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11009 mDeltaY = getPropertyInt(tokens, 3,
11010 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11011 int shadowColor = getPropertyInt(tokens, 4,
11012 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11013 int color = getPropertyInt(tokens, 5,
11014 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11015 int shadowRadius = getPropertyInt(tokens, 6,
11016 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11017 int shadowDx = getPropertyInt(tokens, 8,
11018 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11019 int shadowDy = getPropertyInt(tokens, 9,
11020 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11021
11022 mTextPaint.setColor(color);
11023 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011024
11025 try {
11026 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011027 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011028 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011029 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011030 mSurface.show();
11031 } catch (OutOfResourcesException e) {
11032 }
11033 }
11034
11035 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011036 if (mLastDW != dw || mLastDH != dh) {
11037 mLastDW = dw;
11038 mLastDH = dh;
11039 mSurface.setSize(dw, dh);
11040 mDrawNeeded = true;
11041 }
11042 }
11043
11044 void drawIfNeeded() {
11045 if (mDrawNeeded) {
11046 final int dw = mLastDW;
11047 final int dh = mLastDH;
11048
11049 mDrawNeeded = false;
11050 Rect dirty = new Rect(0, 0, dw, dh);
11051 Canvas c = null;
11052 try {
11053 c = mSurface.lockCanvas(dirty);
11054 } catch (IllegalArgumentException e) {
11055 } catch (OutOfResourcesException e) {
11056 }
11057 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011058 c.drawColor(0, PorterDuff.Mode.CLEAR);
11059
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011060 int deltaX = mDeltaX;
11061 int deltaY = mDeltaY;
11062
11063 // deltaX shouldn't be close to a round fraction of our
11064 // x step, or else things will line up too much.
11065 int div = (dw+mTextWidth)/deltaX;
11066 int rem = (dw+mTextWidth) - (div*deltaX);
11067 int qdelta = deltaX/4;
11068 if (rem < qdelta || rem > (deltaX-qdelta)) {
11069 deltaX += deltaX/3;
11070 }
11071
11072 int y = -mTextHeight;
11073 int x = -mTextWidth;
11074 while (y < (dh+mTextHeight)) {
11075 c.drawText(mText, x, y, mTextPaint);
11076 x += deltaX;
11077 if (x >= dw) {
11078 x -= (dw+mTextWidth);
11079 y += deltaY;
11080 }
11081 }
11082 mSurface.unlockCanvasAndPost(c);
11083 }
11084 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011085 }
11086 }
11087
11088 void createWatermark() {
11089 if (mWatermark != null) {
11090 return;
11091 }
11092
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011093 File file = new File("/system/etc/setup.conf");
11094 FileInputStream in = null;
11095 try {
11096 in = new FileInputStream(file);
11097 DataInputStream ind = new DataInputStream(in);
11098 String line = ind.readLine();
11099 if (line != null) {
11100 String[] toks = line.split("%");
11101 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011102 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011103 }
11104 }
11105 } catch (FileNotFoundException e) {
11106 } catch (IOException e) {
11107 } finally {
11108 if (in != null) {
11109 try {
11110 in.close();
11111 } catch (IOException e) {
11112 }
11113 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011114 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011115 }
11116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011117 @Override
11118 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11119 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11120 != PackageManager.PERMISSION_GRANTED) {
11121 pw.println("Permission Denial: can't dump WindowManager from from pid="
11122 + Binder.getCallingPid()
11123 + ", uid=" + Binder.getCallingUid());
11124 return;
11125 }
Romain Guy06882f82009-06-10 13:36:04 -070011126
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011127 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011128 pw.println(" ");
11129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011130 synchronized(mWindowMap) {
11131 pw.println("Current Window Manager state:");
11132 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011133 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011134 pw.print(" Window #"); pw.print(i); pw.print(' ');
11135 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011136 w.dump(pw, " ");
11137 }
11138 if (mInputMethodDialogs.size() > 0) {
11139 pw.println(" ");
11140 pw.println(" Input method dialogs:");
11141 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11142 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011143 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011144 }
11145 }
11146 if (mPendingRemove.size() > 0) {
11147 pw.println(" ");
11148 pw.println(" Remove pending for:");
11149 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11150 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011151 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11152 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011153 w.dump(pw, " ");
11154 }
11155 }
11156 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11157 pw.println(" ");
11158 pw.println(" Windows force removing:");
11159 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11160 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011161 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11162 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011163 w.dump(pw, " ");
11164 }
11165 }
11166 if (mDestroySurface.size() > 0) {
11167 pw.println(" ");
11168 pw.println(" Windows waiting to destroy their surface:");
11169 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11170 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011171 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11172 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011173 w.dump(pw, " ");
11174 }
11175 }
11176 if (mLosingFocus.size() > 0) {
11177 pw.println(" ");
11178 pw.println(" Windows losing focus:");
11179 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11180 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011181 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11182 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011183 w.dump(pw, " ");
11184 }
11185 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011186 if (mResizingWindows.size() > 0) {
11187 pw.println(" ");
11188 pw.println(" Windows waiting to resize:");
11189 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11190 WindowState w = mResizingWindows.get(i);
11191 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11192 pw.print(w); pw.println(":");
11193 w.dump(pw, " ");
11194 }
11195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011196 if (mSessions.size() > 0) {
11197 pw.println(" ");
11198 pw.println(" All active sessions:");
11199 Iterator<Session> it = mSessions.iterator();
11200 while (it.hasNext()) {
11201 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011202 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011203 s.dump(pw, " ");
11204 }
11205 }
11206 if (mTokenMap.size() > 0) {
11207 pw.println(" ");
11208 pw.println(" All tokens:");
11209 Iterator<WindowToken> it = mTokenMap.values().iterator();
11210 while (it.hasNext()) {
11211 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011212 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011213 token.dump(pw, " ");
11214 }
11215 }
11216 if (mTokenList.size() > 0) {
11217 pw.println(" ");
11218 pw.println(" Window token list:");
11219 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011220 pw.print(" #"); pw.print(i); pw.print(": ");
11221 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011222 }
11223 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011224 if (mWallpaperTokens.size() > 0) {
11225 pw.println(" ");
11226 pw.println(" Wallpaper tokens:");
11227 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11228 WindowToken token = mWallpaperTokens.get(i);
11229 pw.print(" Wallpaper #"); pw.print(i);
11230 pw.print(' '); pw.print(token); pw.println(':');
11231 token.dump(pw, " ");
11232 }
11233 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011234 if (mAppTokens.size() > 0) {
11235 pw.println(" ");
11236 pw.println(" Application tokens in Z order:");
11237 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011238 pw.print(" App #"); pw.print(i); pw.print(": ");
11239 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011240 }
11241 }
11242 if (mFinishedStarting.size() > 0) {
11243 pw.println(" ");
11244 pw.println(" Finishing start of application tokens:");
11245 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11246 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011247 pw.print(" Finished Starting #"); pw.print(i);
11248 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011249 token.dump(pw, " ");
11250 }
11251 }
11252 if (mExitingTokens.size() > 0) {
11253 pw.println(" ");
11254 pw.println(" Exiting tokens:");
11255 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11256 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011257 pw.print(" Exiting #"); pw.print(i);
11258 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011259 token.dump(pw, " ");
11260 }
11261 }
11262 if (mExitingAppTokens.size() > 0) {
11263 pw.println(" ");
11264 pw.println(" Exiting application tokens:");
11265 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11266 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011267 pw.print(" Exiting App #"); pw.print(i);
11268 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011269 token.dump(pw, " ");
11270 }
11271 }
11272 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011273 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11274 pw.print(" mLastFocus="); pw.println(mLastFocus);
11275 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11276 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11277 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011278 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011279 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11280 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11281 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11282 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011283 if (mWindowDetachedWallpaper != null) {
11284 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11285 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011286 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11287 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11288 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011289 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11290 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11291 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11292 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011293 if (mDimAnimator != null) {
11294 mDimAnimator.printTo(pw);
11295 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011296 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011297 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011298 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011299 pw.print(mInputMethodAnimLayerAdjustment);
11300 pw.print(" mWallpaperAnimLayerAdjustment=");
11301 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011302 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11303 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011304 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11305 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011306 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11307 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011308 pw.print(" mRotation="); pw.print(mRotation);
11309 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11310 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11311 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11312 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11313 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11314 pw.print(" mNextAppTransition=0x");
11315 pw.print(Integer.toHexString(mNextAppTransition));
11316 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011317 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011318 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011319 if (mNextAppTransitionPackage != null) {
11320 pw.print(" mNextAppTransitionPackage=");
11321 pw.print(mNextAppTransitionPackage);
11322 pw.print(", mNextAppTransitionEnter=0x");
11323 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11324 pw.print(", mNextAppTransitionExit=0x");
11325 pw.print(Integer.toHexString(mNextAppTransitionExit));
11326 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011327 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11328 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011329 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11330 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11331 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11332 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011333 if (mOpeningApps.size() > 0) {
11334 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11335 }
11336 if (mClosingApps.size() > 0) {
11337 pw.print(" mClosingApps="); pw.println(mClosingApps);
11338 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011339 if (mToTopApps.size() > 0) {
11340 pw.print(" mToTopApps="); pw.println(mToTopApps);
11341 }
11342 if (mToBottomApps.size() > 0) {
11343 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11344 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011345 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11346 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011347 }
11348 }
11349
Jeff Brown349703e2010-06-22 01:27:15 -070011350 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011351 public void monitor() {
11352 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011353 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011354 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011355
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011356 /**
11357 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011358 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011359 */
11360 private static class DimAnimator {
11361 Surface mDimSurface;
11362 boolean mDimShown = false;
11363 float mDimCurrentAlpha;
11364 float mDimTargetAlpha;
11365 float mDimDeltaPerMs;
11366 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011367
11368 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011369
11370 DimAnimator (SurfaceSession session) {
11371 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011372 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011373 + mDimSurface + ": CREATE");
11374 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011375 mDimSurface = new Surface(session, 0,
11376 "DimSurface",
11377 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011378 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011379 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011380 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011381 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011382 }
11383 }
11384 }
11385
11386 /**
11387 * Show the dim surface.
11388 */
11389 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011390 if (!mDimShown) {
11391 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11392 dw + "x" + dh + ")");
11393 mDimShown = true;
11394 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011395 mLastDimWidth = dw;
11396 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011397 mDimSurface.setPosition(0, 0);
11398 mDimSurface.setSize(dw, dh);
11399 mDimSurface.show();
11400 } catch (RuntimeException e) {
11401 Slog.w(TAG, "Failure showing dim surface", e);
11402 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011403 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11404 mLastDimWidth = dw;
11405 mLastDimHeight = dh;
11406 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011407 }
11408 }
11409
11410 /**
11411 * Set's the dim surface's layer and update dim parameters that will be used in
11412 * {@link updateSurface} after all windows are examined.
11413 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011414 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011415 mDimSurface.setLayer(w.mAnimLayer-1);
11416
11417 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011418 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011419 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011420 if (mDimTargetAlpha != target) {
11421 // If the desired dim level has changed, then
11422 // start an animation to it.
11423 mLastDimAnimTime = currentTime;
11424 long duration = (w.mAnimating && w.mAnimation != null)
11425 ? w.mAnimation.computeDurationHint()
11426 : DEFAULT_DIM_DURATION;
11427 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011428 TypedValue tv = new TypedValue();
11429 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11430 tv, true);
11431 if (tv.type == TypedValue.TYPE_FRACTION) {
11432 duration = (long)tv.getFraction((float)duration, (float)duration);
11433 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11434 && tv.type <= TypedValue.TYPE_LAST_INT) {
11435 duration = tv.data;
11436 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011437 }
11438 if (duration < 1) {
11439 // Don't divide by zero
11440 duration = 1;
11441 }
11442 mDimTargetAlpha = target;
11443 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11444 }
11445 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011446
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011447 /**
11448 * Updating the surface's alpha. Returns true if the animation continues, or returns
11449 * false when the animation is finished and the dim surface is hidden.
11450 */
11451 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11452 if (!dimming) {
11453 if (mDimTargetAlpha != 0) {
11454 mLastDimAnimTime = currentTime;
11455 mDimTargetAlpha = 0;
11456 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11457 }
11458 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011459
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011460 boolean animating = false;
11461 if (mLastDimAnimTime != 0) {
11462 mDimCurrentAlpha += mDimDeltaPerMs
11463 * (currentTime-mLastDimAnimTime);
11464 boolean more = true;
11465 if (displayFrozen) {
11466 // If the display is frozen, there is no reason to animate.
11467 more = false;
11468 } else if (mDimDeltaPerMs > 0) {
11469 if (mDimCurrentAlpha > mDimTargetAlpha) {
11470 more = false;
11471 }
11472 } else if (mDimDeltaPerMs < 0) {
11473 if (mDimCurrentAlpha < mDimTargetAlpha) {
11474 more = false;
11475 }
11476 } else {
11477 more = false;
11478 }
11479
11480 // Do we need to continue animating?
11481 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011482 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011483 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11484 mLastDimAnimTime = currentTime;
11485 mDimSurface.setAlpha(mDimCurrentAlpha);
11486 animating = true;
11487 } else {
11488 mDimCurrentAlpha = mDimTargetAlpha;
11489 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011490 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011491 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11492 mDimSurface.setAlpha(mDimCurrentAlpha);
11493 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011494 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011495 + ": HIDE");
11496 try {
11497 mDimSurface.hide();
11498 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011499 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011500 }
11501 mDimShown = false;
11502 }
11503 }
11504 }
11505 return animating;
11506 }
11507
11508 public void printTo(PrintWriter pw) {
11509 pw.print(" mDimShown="); pw.print(mDimShown);
11510 pw.print(" current="); pw.print(mDimCurrentAlpha);
11511 pw.print(" target="); pw.print(mDimTargetAlpha);
11512 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11513 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11514 }
11515 }
11516
11517 /**
11518 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11519 * This is used for opening/closing transition for apps in compatible mode.
11520 */
11521 private static class FadeInOutAnimation extends Animation {
11522 int mWidth;
11523 boolean mFadeIn;
11524
11525 public FadeInOutAnimation(boolean fadeIn) {
11526 setInterpolator(new AccelerateInterpolator());
11527 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11528 mFadeIn = fadeIn;
11529 }
11530
11531 @Override
11532 protected void applyTransformation(float interpolatedTime, Transformation t) {
11533 float x = interpolatedTime;
11534 if (!mFadeIn) {
11535 x = 1.0f - x; // reverse the interpolation for fade out
11536 }
11537 if (x < 0.5) {
11538 // move the window out of the screen.
11539 t.getMatrix().setTranslate(mWidth, 0);
11540 } else {
11541 t.getMatrix().setTranslate(0, 0);// show
11542 t.setAlpha((x - 0.5f) * 2);
11543 }
11544 }
11545
11546 @Override
11547 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11548 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11549 mWidth = width;
11550 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011551
11552 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011553 public int getZAdjustment() {
11554 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011555 }
11556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011557}