blob: 3e930aeb085d64f0f6cdb7df9296b7ee409322a6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
32import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070035import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37import com.android.internal.app.IBatteryStats;
38import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080039import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070040import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import com.android.internal.view.IInputContext;
42import com.android.internal.view.IInputMethodClient;
43import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080044import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import com.android.server.am.BatteryStatsService;
46
47import android.Manifest;
48import android.app.ActivityManagerNative;
49import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070050import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070051import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070052import android.content.ClipData;
53import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.Intent;
56import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080061import android.content.res.Resources;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080062import android.graphics.Bitmap;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070065import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070067import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070088import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.os.SystemClock;
90import android.os.SystemProperties;
91import android.os.TokenWatcher;
92import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070093import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070095import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080096import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070098import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700100import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101import android.view.Gravity;
102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
129import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.File;
132import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.FileInputStream;
134import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135import java.io.IOException;
136import java.io.OutputStream;
137import java.io.OutputStreamWriter;
138import java.io.PrintWriter;
139import java.io.StringWriter;
140import java.net.Socket;
141import java.util.ArrayList;
142import java.util.HashMap;
143import java.util.HashSet;
144import java.util.Iterator;
145import java.util.List;
146
147/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700148public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700149 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800152 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800162 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700164 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean DEBUG_APP_TRANSITIONS = false;
166 static final boolean DEBUG_STARTING_WINDOW = false;
167 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700168 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800169 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700171 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 static final boolean PROFILE_ORIENTATION = false;
174 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700175 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to multiply the policy's type layer, to reserve room
178 * for multiple windows of the same type and Z-ordering adjustment
179 * with TYPE_LAYER_OFFSET. */
180 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
183 * or below others in the same layer. */
184 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /** How much to increment the layer for each window, to reserve room
187 * for effect surfaces between them.
188 */
189 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /** The maximum length we will accept for a loaded animation duration:
192 * this is 10 seconds.
193 */
194 static final int MAX_ANIMATION_DURATION = 10*1000;
195
196 /** Amount of time (in milliseconds) to animate the dim surface from one
197 * value to another, when no window animation is driving it.
198 */
199 static final int DEFAULT_DIM_DURATION = 200;
200
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700201 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
202 * compatible windows.
203 */
204 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
205
Dianne Hackborna1111872010-11-23 20:55:11 -0800206 /**
207 * If true, the window manager will do its own custom freezing and general
208 * management of the screen during rotation.
209 */
210 static final boolean CUSTOM_SCREEN_ROTATION = true;
211
Jeff Brown7fbdc842010-06-17 20:52:56 -0700212 // Maximum number of milliseconds to wait for input event injection.
213 // FIXME is this value reasonable?
214 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800215
216 // Maximum number of milliseconds to wait for input devices to be enumerated before
217 // proceding with safe mode detection.
218 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700219
220 // Default input dispatching timeout in nanoseconds.
221 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 static final int UPDATE_FOCUS_NORMAL = 0;
224 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
225 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
226 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700229 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
231 /**
232 * Condition waited on by {@link #reenableKeyguard} to know the call to
233 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500234 * This is set to true only if mKeyguardTokenWatcher.acquired() has
235 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
Jim Miller284b62e2010-06-08 14:27:42 -0700239 private static final int ALLOW_DISABLE_YES = 1;
240 private static final int ALLOW_DISABLE_NO = 0;
241 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
242 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
243
Mike Lockwood983ee092009-11-22 01:42:24 -0500244 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
245 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700247 if (shouldAllowDisableKeyguard()) {
248 mPolicy.enableKeyguard(false);
249 mKeyguardDisabled = true;
250 } else {
251 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700255 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500256 synchronized (mKeyguardTokenWatcher) {
257 mKeyguardDisabled = false;
258 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260 }
261 };
262
Jim Miller284b62e2010-06-08 14:27:42 -0700263 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
264 @Override
265 public void onReceive(Context context, Intent intent) {
266 mPolicy.enableKeyguard(true);
267 synchronized(mKeyguardTokenWatcher) {
268 // lazily evaluate this next time we're asked to disable keyguard
269 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
270 mKeyguardDisabled = false;
271 }
272 }
273 };
274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final Context mContext;
276
277 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
282
283 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 /**
288 * All currently active sessions with clients.
289 */
290 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 /**
293 * Mapping from an IWindow IBinder to the server's Window object.
294 * This is also used as the lock for all of our state.
295 */
296 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
297
298 /**
299 * Mapping from a token IBinder to a WindowToken object.
300 */
301 final HashMap<IBinder, WindowToken> mTokenMap =
302 new HashMap<IBinder, WindowToken>();
303
304 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 * 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
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800313 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 */
315 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
316
317 /**
318 * Application tokens that are in the process of exiting, but still
319 * on screen for animations.
320 */
321 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
322
323 /**
324 * List of window tokens that have finished starting their application,
325 * and now need to have the policy remove their windows.
326 */
327 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
328
329 /**
330 * Z-ordered (bottom-most first) list of all Window objects.
331 */
Jeff Browne33348b2010-07-15 23:54:05 -0700332 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
334 /**
335 * Windows that are being resized. Used so we can tell the client about
336 * the resize after closing the transaction in which we resized the
337 * underlying surface.
338 */
339 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
340
341 /**
342 * Windows whose animations have ended and now must be removed.
343 */
344 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
345
346 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800347 * Used when processing mPendingRemove to avoid working on the original array.
348 */
349 WindowState[] mPendingRemoveTmp = new WindowState[20];
350
351 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 * Windows whose surface should be destroyed.
353 */
354 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
355
356 /**
357 * Windows that have lost input focus and are waiting for the new
358 * focus window to be displayed before they are told about this.
359 */
360 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
361
362 /**
363 * This is set when we have run out of memory, and will either be an empty
364 * list or contain windows that need to be force removed.
365 */
366 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700367
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800368 /**
369 * Used when rebuilding window list to keep track of windows that have
370 * been removed.
371 */
372 WindowState[] mRebuildTmp = new WindowState[20];
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800381 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800382 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 final float[] mTmpFloats = new float[9];
387
388 boolean mSafeMode;
389 boolean mDisplayEnabled = false;
390 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700391 int mInitialDisplayWidth = 0;
392 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 int mRotation = 0;
394 int mRequestedRotation = 0;
395 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700396 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 ArrayList<IRotationWatcher> mRotationWatchers
398 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 boolean mLayoutNeeded = true;
401 boolean mAnimationPending = false;
402 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800403 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 boolean mWindowsFreezingScreen = false;
405 long mFreezeGcPending = 0;
406 int mAppsFreezingScreen = 0;
407
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800408 int mLayoutSeq = 0;
409
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800410 // State while inside of layoutAndPlaceSurfacesLocked().
411 boolean mFocusMayChange;
412
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800413 Configuration mCurConfiguration = new Configuration();
414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 // This is held as long as we have the screen frozen, to give us time to
416 // perform a rotation animation when turning off shows the lock screen which
417 // changes the orientation.
418 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 // State management of app transitions. When we are preparing for a
421 // transition, mNextAppTransition will be the kind of transition to
422 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
423 // mOpeningApps and mClosingApps are the lists of tokens that will be
424 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700425 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700426 String mNextAppTransitionPackage;
427 int mNextAppTransitionEnter;
428 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700430 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionTimeout = false;
432 boolean mStartingIconInTransition = false;
433 boolean mSkipAppTransitionAnimation = false;
434 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700436 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 H mH = new H();
442
443 WindowState mCurrentFocus = null;
444 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 // This just indicates the window the input method is on top of, not
447 // necessarily the window its input is going to.
448 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 boolean mInputMethodTargetWaitingAnim;
450 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 WindowState mInputMethodWindow = null;
453 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
454
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700455 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800456
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700457 // If non-null, this is the currently visible window that is associated
458 // with the wallpaper.
459 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700460 // If non-null, we are in the middle of animating from one wallpaper target
461 // to another, and this is the lower one in Z-order.
462 WindowState mLowerWallpaperTarget = null;
463 // If non-null, we are in the middle of animating from one wallpaper target
464 // to another, and this is the higher one in Z-order.
465 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800466 // Window currently running an animation that has requested it be detached
467 // from the wallpaper. This means we need to ensure the wallpaper is
468 // visible behind it in case it animates in a way that would allow it to be
469 // seen.
470 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700471 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700472 float mLastWallpaperX = -1;
473 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800474 float mLastWallpaperXStep = -1;
475 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700476 // This is set when we are waiting for a wallpaper to tell us it is done
477 // changing its scroll position.
478 WindowState mWaitingOnWallpaper;
479 // The last time we had a timeout when waiting for a wallpaper.
480 long mLastWallpaperTimeoutTime;
481 // We give a wallpaper up to 150ms to finish scrolling.
482 static final long WALLPAPER_TIMEOUT = 150;
483 // Time we wait after a timeout before trying to wait again.
484 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 AppWindowToken mFocusedApp = null;
487
488 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 float mWindowAnimationScale = 1.0f;
491 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700493 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494
495 // Who is holding the screen on.
496 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700497 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700498
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700499 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700502 * Drag/drop state
503 */
504 class DragState {
505 IBinder mToken;
506 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800507 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700508 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 ClipData mData;
510 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700511 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700512 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700513 float mThumbOffsetX, mThumbOffsetY;
514 InputChannel mServerChannel, mClientChannel;
515 WindowState mTargetWindow;
516 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700517 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700518
Christopher Tateccd24de2011-01-12 15:02:55 -0800519 boolean mPerformDeferredRotation;
520 int mRotation;
521 int mAnimFlags;
522
Jeff Brownfbf09772011-01-16 14:06:57 -0800523 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700524
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800525 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700526 mToken = token;
527 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800528 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700529 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700530 mNotifiedWindows = new ArrayList<WindowState>();
531 }
532
533 void reset() {
534 if (mSurface != null) {
535 mSurface.destroy();
536 }
537 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800538 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700539 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700540 mToken = null;
541 mData = null;
542 mThumbOffsetX = mThumbOffsetY = 0;
543 mNotifiedWindows = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800544 mPerformDeferredRotation = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700545 }
546
547 void register() {
548 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
549 if (mClientChannel != null) {
550 Slog.e(TAG, "Duplicate register of drag input channel");
551 } else {
552 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
553 mServerChannel = channels[0];
554 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800555 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700556 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
557 mH.getLooper().getQueue());
558 }
559 }
560
561 void unregister() {
562 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
563 if (mClientChannel == null) {
564 Slog.e(TAG, "Unregister of nonexistent drag input channel");
565 } else {
566 mInputManager.unregisterInputChannel(mServerChannel);
567 InputQueue.unregisterInputChannel(mClientChannel);
568 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700569 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700570 mClientChannel = null;
571 mServerChannel = null;
572 }
573 }
574
Chris Tatea32dcf72010-10-14 12:13:50 -0700575 int getDragLayerLw() {
576 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
577 * TYPE_LAYER_MULTIPLIER
578 + TYPE_LAYER_OFFSET;
579 }
580
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 /* call out to each visible window/session informing it about the drag
582 */
Chris Tateb8203e92010-10-12 14:23:21 -0700583 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 // Cache a base-class instance of the clip metadata so that parceling
585 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700586 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700587 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700588 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700589
590 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700591 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700592 }
593
Christopher Tate2c095f32010-10-04 14:13:40 -0700594 final int N = mWindows.size();
595 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700596 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700597 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 }
599
600 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
601 * designated window is potentially a drop recipient. There are race situations
602 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
603 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700604 *
605 * This method clones the 'event' parameter if it's being delivered to the same
606 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700607 */
Chris Tateb478f462010-10-15 16:02:26 -0700608 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
609 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700610 // Don't actually send the event if the drag is supposed to be pinned
611 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800612 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700613 final IBinder winBinder = newWin.mClient.asBinder();
614 if (winBinder != mLocalWin) {
615 if (DEBUG_DRAG) {
616 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
617 }
618 return;
619 }
620 }
621
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700622 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700623 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
624 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800625 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700626 try {
627 newWin.mClient.dispatchDragEvent(event);
628 // track each window that we've notified that the drag is starting
629 mNotifiedWindows.add(newWin);
630 } catch (RemoteException e) {
631 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700632 } finally {
633 // if the callee was local, the dispatch has already recycled the event
634 if (Process.myPid() != newWin.mSession.mPid) {
635 event.recycle();
636 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700637 }
638 }
639 }
640
641 /* helper - construct and send a DRAG_STARTED event only if the window has not
642 * previously been notified, i.e. it became visible after the drag operation
643 * was begun. This is a rare case.
644 */
645 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700646 if (mDragInProgress) {
647 // If we have sent the drag-started, we needn't do so again
648 for (WindowState ws : mNotifiedWindows) {
649 if (ws == newWin) {
650 return;
651 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700652 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700653 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700654 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700655 }
Chris Tateb478f462010-10-15 16:02:26 -0700656 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700657 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700658 }
659
Chris Tated4533f142010-10-19 15:15:08 -0700660 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700661 if (DEBUG_DRAG) {
662 Slog.d(TAG, "broadcasting DRAG_ENDED");
663 }
Chris Tated4533f142010-10-19 15:15:08 -0700664 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800665 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700666 for (WindowState ws: mNotifiedWindows) {
667 try {
668 ws.mClient.dispatchDragEvent(evt);
669 } catch (RemoteException e) {
670 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700671 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 }
Chris Tated4533f142010-10-19 15:15:08 -0700673 mNotifiedWindows.clear();
674 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700675 evt.recycle();
676 }
677
Chris Tated4533f142010-10-19 15:15:08 -0700678 void endDragLw() {
679 mDragState.broadcastDragEndedLw();
680
681 // stop intercepting input
682 mDragState.unregister();
683 mInputMonitor.updateInputWindowsLw();
684
Christopher Tateccd24de2011-01-12 15:02:55 -0800685 // Retain the parameters of any deferred rotation operation so
686 // that we can perform it after the reset / unref of the drag state
687 final boolean performRotation = mPerformDeferredRotation;
688 final int rotation = mRotation;
689 final int animFlags = mAnimFlags;
690
Chris Tated4533f142010-10-19 15:15:08 -0700691 // free our resources and drop all the object references
692 mDragState.reset();
693 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800694
695 // Now that we've officially ended the drag, execute any
696 // deferred rotation
697 if (performRotation) {
698 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800699 boolean changed = setRotationUncheckedLocked(rotation, animFlags, false);
Christopher Tateccd24de2011-01-12 15:02:55 -0800700 if (changed) {
701 sendNewConfiguration();
702 }
703 }
Chris Tated4533f142010-10-19 15:15:08 -0700704 }
705
Christopher Tatea53146c2010-09-07 11:57:52 -0700706 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700707 final int myPid = Process.myPid();
708
709 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800710 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tate2c095f32010-10-04 14:13:40 -0700711 mSurface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800712 try {
713 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
714 } finally {
715 mSurface.closeTransaction();
716 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
717 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700718
719 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700720 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800721 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700722 final IBinder touchedBinder = touchedWin.mClient.asBinder();
723 if (touchedBinder != mLocalWin) {
724 // This drag is pinned only to the originating window, but the drag
725 // point is outside that window. Pretend it's over empty space.
726 touchedWin = null;
727 }
728 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700729 try {
730 // have we dragged over a new window?
731 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
732 if (DEBUG_DRAG) {
733 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
734 }
735 // force DRAG_EXITED_EVENT if appropriate
736 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700737 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800738 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700739 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700740 if (myPid != mTargetWindow.mSession.mPid) {
741 evt.recycle();
742 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 }
744 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700745 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700746 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
747 }
748 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700749 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800750 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700751 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700752 if (myPid != touchedWin.mSession.mPid) {
753 evt.recycle();
754 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700755 }
756 } catch (RemoteException e) {
757 Slog.w(TAG, "can't send drag notification to windows");
758 }
759 mTargetWindow = touchedWin;
760 }
761
Chris Tated4533f142010-10-19 15:15:08 -0700762 // Tell the drop target about the data. Returns 'true' if we can immediately
763 // dispatch the global drag-ended message, 'false' if we need to wait for a
764 // result from the recipient.
765 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700766 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700767 if (touchedWin == null) {
768 // "drop" outside a valid window -- no recipient to apply a
769 // timeout to, and we can send the drag-ended message immediately.
770 mDragResult = false;
771 return true;
772 }
773
774 if (DEBUG_DRAG) {
775 Slog.d(TAG, "sending DROP to " + touchedWin);
776 }
777 final int myPid = Process.myPid();
778 final IBinder token = touchedWin.mClient.asBinder();
779 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
780 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800781 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700782 try {
783 touchedWin.mClient.dispatchDragEvent(evt);
784
785 // 5 second timeout for this window to respond to the drop
786 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
787 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
788 mH.sendMessageDelayed(msg, 5000);
789 } catch (RemoteException e) {
790 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
791 return true;
792 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700793 if (myPid != touchedWin.mSession.mPid) {
794 evt.recycle();
795 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700796 }
Chris Tated4533f142010-10-19 15:15:08 -0700797 mToken = token;
798 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700799 }
800
801 // Find the visible, touch-deliverable window under the given point
802 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
803 WindowState touchedWin = null;
804 final int x = (int) xf;
805 final int y = (int) yf;
806 final ArrayList<WindowState> windows = mWindows;
807 final int N = windows.size();
808 for (int i = N - 1; i >= 0; i--) {
809 WindowState child = windows.get(i);
810 final int flags = child.mAttrs.flags;
811 if (!child.isVisibleLw()) {
812 // not visible == don't tell about drags
813 continue;
814 }
815 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
816 // not touchable == don't tell about drags
817 continue;
818 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800819
820 child.getTouchableRegion(mTmpRegion);
821
Christopher Tatea53146c2010-09-07 11:57:52 -0700822 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800823 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
824 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
825 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700826 // Found it
827 touchedWin = child;
828 break;
829 }
830 }
831
832 return touchedWin;
833 }
Christopher Tateccd24de2011-01-12 15:02:55 -0800834
835 void setDeferredRotation(int rotation, int animFlags) {
836 mRotation = rotation;
837 mAnimFlags = animFlags;
838 mPerformDeferredRotation = true;
839 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700840 }
841
842 DragState mDragState = null;
843 private final InputHandler mDragInputHandler = new BaseInputHandler() {
844 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700845 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
846 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700847 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700848 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
849 && mDragState != null) {
850 boolean endDrag = false;
851 final float newX = event.getRawX();
852 final float newY = event.getRawY();
853
Christopher Tatea53146c2010-09-07 11:57:52 -0700854 switch (event.getAction()) {
855 case MotionEvent.ACTION_DOWN: {
856 if (DEBUG_DRAG) {
857 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
858 }
859 } break;
860
861 case MotionEvent.ACTION_MOVE: {
862 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700863 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700864 mDragState.notifyMoveLw(newX, newY);
865 }
866 } break;
867
868 case MotionEvent.ACTION_UP: {
869 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
870 + newX + "," + newY);
871 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700872 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700873 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700874 } break;
875
876 case MotionEvent.ACTION_CANCEL: {
877 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
878 endDrag = true;
879 } break;
880 }
881
882 if (endDrag) {
883 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
884 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700885 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700886 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700887 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700888 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700889
890 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700891 }
892 } catch (Exception e) {
893 Slog.e(TAG, "Exception caught by drag handleMotion", e);
894 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700895 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700896 }
897 }
898 };
899
900 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 * Whether the UI is currently running in touch mode (not showing
902 * navigational focus because the user is directly pressing the screen).
903 */
904 boolean mInTouchMode = false;
905
906 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700907 private ArrayList<WindowChangeListener> mWindowChangeListeners =
908 new ArrayList<WindowChangeListener>();
909 private boolean mWindowsChanged = false;
910
911 public interface WindowChangeListener {
912 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700913 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700914 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915
Dianne Hackbornc485a602009-03-24 22:39:49 -0700916 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700917 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700918
919 // The frame use to limit the size of the app running in compatibility mode.
920 Rect mCompatibleScreenFrame = new Rect();
921 // The surface used to fill the outer rim of the app running in compatibility mode.
922 Surface mBackgroundFillerSurface = null;
923 boolean mBackgroundFillerShown = false;
924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 public static WindowManagerService main(Context context,
926 PowerManagerService pm, boolean haveInputMethods) {
927 WMThread thr = new WMThread(context, pm, haveInputMethods);
928 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 synchronized (thr) {
931 while (thr.mService == null) {
932 try {
933 thr.wait();
934 } catch (InterruptedException e) {
935 }
936 }
937 }
Romain Guy06882f82009-06-10 13:36:04 -0700938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 return thr.mService;
940 }
Romain Guy06882f82009-06-10 13:36:04 -0700941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 static class WMThread extends Thread {
943 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 private final Context mContext;
946 private final PowerManagerService mPM;
947 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 public WMThread(Context context, PowerManagerService pm,
950 boolean haveInputMethods) {
951 super("WindowManager");
952 mContext = context;
953 mPM = pm;
954 mHaveInputMethods = haveInputMethods;
955 }
Romain Guy06882f82009-06-10 13:36:04 -0700956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 public void run() {
958 Looper.prepare();
959 WindowManagerService s = new WindowManagerService(mContext, mPM,
960 mHaveInputMethods);
961 android.os.Process.setThreadPriority(
962 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700963 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 synchronized (this) {
966 mService = s;
967 notifyAll();
968 }
Romain Guy06882f82009-06-10 13:36:04 -0700969
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700970 // For debug builds, log event loop stalls to dropbox for analysis.
971 if (StrictMode.conditionallyEnableDebugLogging()) {
972 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
973 }
974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 Looper.loop();
976 }
977 }
978
979 static class PolicyThread extends Thread {
980 private final WindowManagerPolicy mPolicy;
981 private final WindowManagerService mService;
982 private final Context mContext;
983 private final PowerManagerService mPM;
984 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 public PolicyThread(WindowManagerPolicy policy,
987 WindowManagerService service, Context context,
988 PowerManagerService pm) {
989 super("WindowManagerPolicy");
990 mPolicy = policy;
991 mService = service;
992 mContext = context;
993 mPM = pm;
994 }
Romain Guy06882f82009-06-10 13:36:04 -0700995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 public void run() {
997 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800998 WindowManagerPolicyThread.set(this, Looper.myLooper());
999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -08001001 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 android.os.Process.setThreadPriority(
1003 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -07001004 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -07001006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 synchronized (this) {
1008 mRunning = true;
1009 notifyAll();
1010 }
Romain Guy06882f82009-06-10 13:36:04 -07001011
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001012 // For debug builds, log event loop stalls to dropbox for analysis.
1013 if (StrictMode.conditionallyEnableDebugLogging()) {
1014 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1015 }
1016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 Looper.loop();
1018 }
1019 }
1020
1021 private WindowManagerService(Context context, PowerManagerService pm,
1022 boolean haveInputMethods) {
1023 mContext = context;
1024 mHaveInputMethods = haveInputMethods;
1025 mLimitedAlphaCompositing = context.getResources().getBoolean(
1026 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 mPowerManager = pm;
1029 mPowerManager.setPolicy(mPolicy);
1030 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1031 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1032 "SCREEN_FROZEN");
1033 mScreenFrozenLock.setReferenceCounted(false);
1034
1035 mActivityManager = ActivityManagerNative.getDefault();
1036 mBatteryStats = BatteryStatsService.getService();
1037
1038 // Get persisted window scale setting
1039 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1040 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1041 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1042 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001043
Jim Miller284b62e2010-06-08 14:27:42 -07001044 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1045 IntentFilter filter = new IntentFilter();
1046 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1047 mContext.registerReceiver(mBroadcastReceiver, filter);
1048
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001049 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1050 "KEEP_SCREEN_ON_FLAG");
1051 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052
Jeff Browne33348b2010-07-15 23:54:05 -07001053 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1056 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 synchronized (thr) {
1059 while (!thr.mRunning) {
1060 try {
1061 thr.wait();
1062 } catch (InterruptedException e) {
1063 }
1064 }
1065 }
Romain Guy06882f82009-06-10 13:36:04 -07001066
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001067 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 // Add ourself to the Watchdog monitors.
1070 Watchdog.getInstance().addMonitor(this);
1071 }
1072
1073 @Override
1074 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1075 throws RemoteException {
1076 try {
1077 return super.onTransact(code, data, reply, flags);
1078 } catch (RuntimeException e) {
1079 // The window manager only throws security exceptions, so let's
1080 // log all others.
1081 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001082 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 }
1084 throw e;
1085 }
1086 }
1087
Jeff Browne33348b2010-07-15 23:54:05 -07001088 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001090 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 TAG, "Adding window " + window + " at "
1092 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1093 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001094 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 }
1096
Jeff Browne33348b2010-07-15 23:54:05 -07001097 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001099 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 TAG, "Adding window " + window + " at "
1101 + i + " of " + mWindows.size() + " (before " + pos + ")");
1102 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001103 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 }
1105
1106 //This method finds out the index of a window that has the same app token as
1107 //win. used for z ordering the windows in mWindows
1108 private int findIdxBasedOnAppTokens(WindowState win) {
1109 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001110 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 int jmax = localmWindows.size();
1112 if(jmax == 0) {
1113 return -1;
1114 }
1115 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001116 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 if(wentry.mAppToken == win.mAppToken) {
1118 return j;
1119 }
1120 }
1121 return -1;
1122 }
Romain Guy06882f82009-06-10 13:36:04 -07001123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1125 final IWindow client = win.mClient;
1126 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001127 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 final int N = localmWindows.size();
1130 final WindowState attached = win.mAttachedWindow;
1131 int i;
1132 if (attached == null) {
1133 int tokenWindowsPos = token.windows.size();
1134 if (token.appWindowToken != null) {
1135 int index = tokenWindowsPos-1;
1136 if (index >= 0) {
1137 // If this application has existing windows, we
1138 // simply place the new window on top of them... but
1139 // keep the starting window on top.
1140 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1141 // Base windows go behind everything else.
1142 placeWindowBefore(token.windows.get(0), win);
1143 tokenWindowsPos = 0;
1144 } else {
1145 AppWindowToken atoken = win.mAppToken;
1146 if (atoken != null &&
1147 token.windows.get(index) == atoken.startingWindow) {
1148 placeWindowBefore(token.windows.get(index), win);
1149 tokenWindowsPos--;
1150 } else {
1151 int newIdx = findIdxBasedOnAppTokens(win);
1152 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001153 //there is a window above this one associated with the same
1154 //apptoken note that the window could be a floating window
1155 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001157 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1158 Slog.v(TAG, "Adding window " + win + " at "
1159 + (newIdx+1) + " of " + N);
1160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001162 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001163 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 }
1165 }
1166 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001167 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 TAG, "Figuring out where to add app window "
1169 + client.asBinder() + " (token=" + token + ")");
1170 // Figure out where the window should go, based on the
1171 // order of applications.
1172 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001173 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 for (i=NA-1; i>=0; i--) {
1175 AppWindowToken t = mAppTokens.get(i);
1176 if (t == token) {
1177 i--;
1178 break;
1179 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001180
Dianne Hackborna8f60182009-09-01 19:01:50 -07001181 // We haven't reached the token yet; if this token
1182 // is not going to the bottom and has windows, we can
1183 // use it as an anchor for when we do reach the token.
1184 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 pos = t.windows.get(0);
1186 }
1187 }
1188 // We now know the index into the apps. If we found
1189 // an app window above, that gives us the position; else
1190 // we need to look some more.
1191 if (pos != null) {
1192 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001193 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 if (atoken != null) {
1195 final int NC = atoken.windows.size();
1196 if (NC > 0) {
1197 WindowState bottom = atoken.windows.get(0);
1198 if (bottom.mSubLayer < 0) {
1199 pos = bottom;
1200 }
1201 }
1202 }
1203 placeWindowBefore(pos, win);
1204 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001205 // Continue looking down until we find the first
1206 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 while (i >= 0) {
1208 AppWindowToken t = mAppTokens.get(i);
1209 final int NW = t.windows.size();
1210 if (NW > 0) {
1211 pos = t.windows.get(NW-1);
1212 break;
1213 }
1214 i--;
1215 }
1216 if (pos != null) {
1217 // Move in front of any windows attached to this
1218 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001219 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 if (atoken != null) {
1221 final int NC = atoken.windows.size();
1222 if (NC > 0) {
1223 WindowState top = atoken.windows.get(NC-1);
1224 if (top.mSubLayer >= 0) {
1225 pos = top;
1226 }
1227 }
1228 }
1229 placeWindowAfter(pos, win);
1230 } else {
1231 // Just search for the start of this layer.
1232 final int myLayer = win.mBaseLayer;
1233 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001234 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 if (w.mBaseLayer > myLayer) {
1236 break;
1237 }
1238 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001239 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1240 Slog.v(TAG, "Adding window " + win + " at "
1241 + i + " of " + N);
1242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001244 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 }
1246 }
1247 }
1248 } else {
1249 // Figure out where window should go, based on layer.
1250 final int myLayer = win.mBaseLayer;
1251 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001252 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 i++;
1254 break;
1255 }
1256 }
1257 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001258 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001259 TAG, "Adding window " + win + " at "
1260 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001262 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 }
1264 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001265 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 token.windows.add(tokenWindowsPos, win);
1267 }
1268
1269 } else {
1270 // Figure out this window's ordering relative to the window
1271 // it is attached to.
1272 final int NA = token.windows.size();
1273 final int sublayer = win.mSubLayer;
1274 int largestSublayer = Integer.MIN_VALUE;
1275 WindowState windowWithLargestSublayer = null;
1276 for (i=0; i<NA; i++) {
1277 WindowState w = token.windows.get(i);
1278 final int wSublayer = w.mSubLayer;
1279 if (wSublayer >= largestSublayer) {
1280 largestSublayer = wSublayer;
1281 windowWithLargestSublayer = w;
1282 }
1283 if (sublayer < 0) {
1284 // For negative sublayers, we go below all windows
1285 // in the same sublayer.
1286 if (wSublayer >= sublayer) {
1287 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001288 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 token.windows.add(i, win);
1290 }
1291 placeWindowBefore(
1292 wSublayer >= 0 ? attached : w, win);
1293 break;
1294 }
1295 } else {
1296 // For positive sublayers, we go above all windows
1297 // in the same sublayer.
1298 if (wSublayer > sublayer) {
1299 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001300 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 token.windows.add(i, win);
1302 }
1303 placeWindowBefore(w, win);
1304 break;
1305 }
1306 }
1307 }
1308 if (i >= NA) {
1309 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001310 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 token.windows.add(win);
1312 }
1313 if (sublayer < 0) {
1314 placeWindowBefore(attached, win);
1315 } else {
1316 placeWindowAfter(largestSublayer >= 0
1317 ? windowWithLargestSublayer
1318 : attached,
1319 win);
1320 }
1321 }
1322 }
Romain Guy06882f82009-06-10 13:36:04 -07001323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 if (win.mAppToken != null && addToToken) {
1325 win.mAppToken.allAppWindows.add(win);
1326 }
1327 }
Romain Guy06882f82009-06-10 13:36:04 -07001328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 static boolean canBeImeTarget(WindowState w) {
1330 final int fl = w.mAttrs.flags
1331 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1332 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1333 return w.isVisibleOrAdding();
1334 }
1335 return false;
1336 }
Romain Guy06882f82009-06-10 13:36:04 -07001337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001339 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 final int N = localmWindows.size();
1341 WindowState w = null;
1342 int i = N;
1343 while (i > 0) {
1344 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001345 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001346
Joe Onorato8a9b2202010-02-26 18:56:32 -08001347 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 // + Integer.toHexString(w.mAttrs.flags));
1349 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001350 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 // Yet more tricksyness! If this window is a "starting"
1353 // window, we do actually want to be on top of it, but
1354 // it is not -really- where input will go. So if the caller
1355 // is not actually looking to move the IME, look down below
1356 // for a real window to target...
1357 if (!willMove
1358 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1359 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001360 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1362 i--;
1363 w = wb;
1364 }
1365 }
1366 break;
1367 }
1368 }
Romain Guy06882f82009-06-10 13:36:04 -07001369
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001370 // Now, a special case -- if the last target's window is in the
1371 // process of exiting, and is above the new target, keep on the
1372 // last target to avoid flicker. Consider for example a Dialog with
1373 // the IME shown: when the Dialog is dismissed, we want to keep
1374 // the IME above it until it is completely gone so it doesn't drop
1375 // behind the dialog or its full-screen scrim.
1376 if (mInputMethodTarget != null && w != null
1377 && mInputMethodTarget.isDisplayedLw()
1378 && mInputMethodTarget.mExiting) {
1379 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1380 w = mInputMethodTarget;
1381 i = localmWindows.indexOf(w);
1382 }
1383 }
Romain Guy06882f82009-06-10 13:36:04 -07001384
Joe Onorato8a9b2202010-02-26 18:56:32 -08001385 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 if (willMove && w != null) {
1389 final WindowState curTarget = mInputMethodTarget;
1390 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 // Now some fun for dealing with window animations that
1393 // modify the Z order. We need to look at all windows below
1394 // the current target that are in this app, finding the highest
1395 // visible one in layering.
1396 AppWindowToken token = curTarget.mAppToken;
1397 WindowState highestTarget = null;
1398 int highestPos = 0;
1399 if (token.animating || token.animation != null) {
1400 int pos = 0;
1401 pos = localmWindows.indexOf(curTarget);
1402 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001403 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 if (win.mAppToken != token) {
1405 break;
1406 }
1407 if (!win.mRemoved) {
1408 if (highestTarget == null || win.mAnimLayer >
1409 highestTarget.mAnimLayer) {
1410 highestTarget = win;
1411 highestPos = pos;
1412 }
1413 }
1414 pos--;
1415 }
1416 }
Romain Guy06882f82009-06-10 13:36:04 -07001417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001419 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 + mNextAppTransition + " " + highestTarget
1421 + " animating=" + highestTarget.isAnimating()
1422 + " layer=" + highestTarget.mAnimLayer
1423 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001424
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001425 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 // If we are currently setting up for an animation,
1427 // hold everything until we can find out what will happen.
1428 mInputMethodTargetWaitingAnim = true;
1429 mInputMethodTarget = highestTarget;
1430 return highestPos + 1;
1431 } else if (highestTarget.isAnimating() &&
1432 highestTarget.mAnimLayer > w.mAnimLayer) {
1433 // If the window we are currently targeting is involved
1434 // with an animation, and it is on top of the next target
1435 // we will be over, then hold off on moving until
1436 // that is done.
1437 mInputMethodTarget = highestTarget;
1438 return highestPos + 1;
1439 }
1440 }
1441 }
1442 }
Romain Guy06882f82009-06-10 13:36:04 -07001443
Joe Onorato8a9b2202010-02-26 18:56:32 -08001444 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 if (w != null) {
1446 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001447 if (DEBUG_INPUT_METHOD) {
1448 RuntimeException e = null;
1449 if (!HIDE_STACK_CRAWLS) {
1450 e = new RuntimeException();
1451 e.fillInStackTrace();
1452 }
1453 Slog.w(TAG, "Moving IM target from "
1454 + mInputMethodTarget + " to " + w, e);
1455 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 mInputMethodTarget = w;
1457 if (w.mAppToken != null) {
1458 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1459 } else {
1460 setInputMethodAnimLayerAdjustment(0);
1461 }
1462 }
1463 return i+1;
1464 }
1465 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001466 if (DEBUG_INPUT_METHOD) {
1467 RuntimeException e = null;
1468 if (!HIDE_STACK_CRAWLS) {
1469 e = new RuntimeException();
1470 e.fillInStackTrace();
1471 }
1472 Slog.w(TAG, "Moving IM target from "
1473 + mInputMethodTarget + " to null", e);
1474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 mInputMethodTarget = null;
1476 setInputMethodAnimLayerAdjustment(0);
1477 }
1478 return -1;
1479 }
Romain Guy06882f82009-06-10 13:36:04 -07001480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 void addInputMethodWindowToListLocked(WindowState win) {
1482 int pos = findDesiredInputMethodWindowIndexLocked(true);
1483 if (pos >= 0) {
1484 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001485 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001486 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001488 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 moveInputMethodDialogsLocked(pos+1);
1490 return;
1491 }
1492 win.mTargetAppToken = null;
1493 addWindowToListInOrderLocked(win, true);
1494 moveInputMethodDialogsLocked(pos);
1495 }
Romain Guy06882f82009-06-10 13:36:04 -07001496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001498 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 mInputMethodAnimLayerAdjustment = adj;
1500 WindowState imw = mInputMethodWindow;
1501 if (imw != null) {
1502 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001503 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 + " anim layer: " + imw.mAnimLayer);
1505 int wi = imw.mChildWindows.size();
1506 while (wi > 0) {
1507 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001508 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001510 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 + " anim layer: " + cw.mAnimLayer);
1512 }
1513 }
1514 int di = mInputMethodDialogs.size();
1515 while (di > 0) {
1516 di --;
1517 imw = mInputMethodDialogs.get(di);
1518 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001519 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 + " anim layer: " + imw.mAnimLayer);
1521 }
1522 }
Romain Guy06882f82009-06-10 13:36:04 -07001523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1525 int wpos = mWindows.indexOf(win);
1526 if (wpos >= 0) {
1527 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001528 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001530 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 int NC = win.mChildWindows.size();
1532 while (NC > 0) {
1533 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001534 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 int cpos = mWindows.indexOf(cw);
1536 if (cpos >= 0) {
1537 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001538 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001539 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 mWindows.remove(cpos);
1541 }
1542 }
1543 }
1544 return interestingPos;
1545 }
Romain Guy06882f82009-06-10 13:36:04 -07001546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 private void reAddWindowToListInOrderLocked(WindowState win) {
1548 addWindowToListInOrderLocked(win, false);
1549 // This is a hack to get all of the child windows added as well
1550 // at the right position. Child windows should be rare and
1551 // this case should be rare, so it shouldn't be that big a deal.
1552 int wpos = mWindows.indexOf(win);
1553 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001554 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001555 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001557 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 reAddWindowLocked(wpos, win);
1559 }
1560 }
Romain Guy06882f82009-06-10 13:36:04 -07001561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 void logWindowList(String prefix) {
1563 int N = mWindows.size();
1564 while (N > 0) {
1565 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001566 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 }
1568 }
Romain Guy06882f82009-06-10 13:36:04 -07001569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 void moveInputMethodDialogsLocked(int pos) {
1571 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001574 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 for (int i=0; i<N; i++) {
1576 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1577 }
1578 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001579 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 logWindowList(" ");
1581 }
Romain Guy06882f82009-06-10 13:36:04 -07001582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 if (pos >= 0) {
1584 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1585 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001586 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 if (wp == mInputMethodWindow) {
1588 pos++;
1589 }
1590 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001591 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 for (int i=0; i<N; i++) {
1593 WindowState win = dialogs.get(i);
1594 win.mTargetAppToken = targetAppToken;
1595 pos = reAddWindowLocked(pos, win);
1596 }
1597 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001598 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 logWindowList(" ");
1600 }
1601 return;
1602 }
1603 for (int i=0; i<N; i++) {
1604 WindowState win = dialogs.get(i);
1605 win.mTargetAppToken = null;
1606 reAddWindowToListInOrderLocked(win);
1607 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001608 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 logWindowList(" ");
1610 }
1611 }
1612 }
Romain Guy06882f82009-06-10 13:36:04 -07001613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1615 final WindowState imWin = mInputMethodWindow;
1616 final int DN = mInputMethodDialogs.size();
1617 if (imWin == null && DN == 0) {
1618 return false;
1619 }
Romain Guy06882f82009-06-10 13:36:04 -07001620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1622 if (imPos >= 0) {
1623 // In this case, the input method windows are to be placed
1624 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001626 // First check to see if the input method windows are already
1627 // located here, and contiguous.
1628 final int N = mWindows.size();
1629 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001630 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 // Figure out the actual input method window that should be
1633 // at the bottom of their stack.
1634 WindowState baseImWin = imWin != null
1635 ? imWin : mInputMethodDialogs.get(0);
1636 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001637 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 if (cw.mSubLayer < 0) baseImWin = cw;
1639 }
Romain Guy06882f82009-06-10 13:36:04 -07001640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 if (firstImWin == baseImWin) {
1642 // The windows haven't moved... but are they still contiguous?
1643 // First find the top IM window.
1644 int pos = imPos+1;
1645 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001646 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 break;
1648 }
1649 pos++;
1650 }
1651 pos++;
1652 // Now there should be no more input method windows above.
1653 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001654 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 break;
1656 }
1657 pos++;
1658 }
1659 if (pos >= N) {
1660 // All is good!
1661 return false;
1662 }
1663 }
Romain Guy06882f82009-06-10 13:36:04 -07001664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 if (imWin != null) {
1666 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001667 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 logWindowList(" ");
1669 }
1670 imPos = tmpRemoveWindowLocked(imPos, imWin);
1671 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001672 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 logWindowList(" ");
1674 }
1675 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1676 reAddWindowLocked(imPos, imWin);
1677 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001678 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 logWindowList(" ");
1680 }
1681 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1682 } else {
1683 moveInputMethodDialogsLocked(imPos);
1684 }
Romain Guy06882f82009-06-10 13:36:04 -07001685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686 } else {
1687 // In this case, the input method windows go in a fixed layer,
1688 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001691 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 tmpRemoveWindowLocked(0, imWin);
1693 imWin.mTargetAppToken = null;
1694 reAddWindowToListInOrderLocked(imWin);
1695 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001696 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 logWindowList(" ");
1698 }
1699 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1700 } else {
1701 moveInputMethodDialogsLocked(-1);;
1702 }
Romain Guy06882f82009-06-10 13:36:04 -07001703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 }
Romain Guy06882f82009-06-10 13:36:04 -07001705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 if (needAssignLayers) {
1707 assignLayersLocked();
1708 }
Romain Guy06882f82009-06-10 13:36:04 -07001709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 return true;
1711 }
Romain Guy06882f82009-06-10 13:36:04 -07001712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 void adjustInputMethodDialogsLocked() {
1714 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1715 }
Romain Guy06882f82009-06-10 13:36:04 -07001716
Dianne Hackborn25994b42009-09-04 14:21:19 -07001717 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001718 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001719 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1720 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1721 ? wallpaperTarget.mAppToken.animation : null)
1722 + " upper=" + mUpperWallpaperTarget
1723 + " lower=" + mLowerWallpaperTarget);
1724 return (wallpaperTarget != null
1725 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1726 && wallpaperTarget.mAppToken.animation != null)))
1727 || mUpperWallpaperTarget != null
1728 || mLowerWallpaperTarget != null;
1729 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001730
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001731 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1732 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001733
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001734 int adjustWallpaperWindowsLocked() {
1735 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001736
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001737 final int dw = mDisplay.getWidth();
1738 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001740 // First find top-most window that has asked to be on top of the
1741 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001742 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001743 int N = localmWindows.size();
1744 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001745 WindowState foundW = null;
1746 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001747 WindowState topCurW = null;
1748 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001749 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001750 int i = N;
1751 while (i > 0) {
1752 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001753 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001754 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1755 if (topCurW == null) {
1756 topCurW = w;
1757 topCurI = i;
1758 }
1759 continue;
1760 }
1761 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001762 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001763 // If this window's app token is hidden and not animating,
1764 // it is of no interest to us.
1765 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001766 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001767 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001768 continue;
1769 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001770 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001771 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001772 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1773 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001774 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001775 && (mWallpaperTarget == w
1776 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001777 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001778 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001779 foundW = w;
1780 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001781 if (w == mWallpaperTarget && ((w.mAppToken != null
1782 && w.mAppToken.animation != null)
1783 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001784 // The current wallpaper target is animating, so we'll
1785 // look behind it for another possible target and figure
1786 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001787 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001788 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001789 continue;
1790 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001791 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001792 } else if (w == mWindowDetachedWallpaper) {
1793 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001794 }
1795 }
1796
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001797 if (foundW == null && windowDetachedI >= 0) {
1798 if (DEBUG_WALLPAPER) Slog.v(TAG,
1799 "Found animating detached wallpaper activity: #" + i + "=" + w);
1800 foundW = w;
1801 foundI = windowDetachedI;
1802 }
1803
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001804 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001805 // If we are currently waiting for an app transition, and either
1806 // the current target or the next target are involved with it,
1807 // then hold off on doing anything with the wallpaper.
1808 // Note that we are checking here for just whether the target
1809 // is part of an app token... which is potentially overly aggressive
1810 // (the app token may not be involved in the transition), but good
1811 // enough (we'll just wait until whatever transition is pending
1812 // executes).
1813 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001814 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001815 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001816 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001817 }
1818 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001819 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001820 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001821 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001822 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001823 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001824
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001825 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001826 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001827 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001828 + " oldTarget: " + mWallpaperTarget);
1829 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001830
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001831 mLowerWallpaperTarget = null;
1832 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001833
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001834 WindowState oldW = mWallpaperTarget;
1835 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001836
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001837 // Now what is happening... if the current and new targets are
1838 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001839 if (foundW != null && oldW != null) {
1840 boolean oldAnim = oldW.mAnimation != null
1841 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1842 boolean foundAnim = foundW.mAnimation != null
1843 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001844 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001845 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001846 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001847 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001848 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001849 int oldI = localmWindows.indexOf(oldW);
1850 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001851 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001852 }
1853 if (oldI >= 0) {
1854 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001855 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001856 + "=" + oldW + "; new#" + foundI
1857 + "=" + foundW);
1858 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001859
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001860 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001861 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001862 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001864 }
1865 mWallpaperTarget = oldW;
1866 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001867
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001868 // Now set the upper and lower wallpaper targets
1869 // correctly, and make sure that we are positioning
1870 // the wallpaper below the lower.
1871 if (foundI > oldI) {
1872 // The new target is on top of the old one.
1873 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001874 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001875 }
1876 mUpperWallpaperTarget = foundW;
1877 mLowerWallpaperTarget = oldW;
1878 foundW = oldW;
1879 foundI = oldI;
1880 } else {
1881 // The new target is below the old one.
1882 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001884 }
1885 mUpperWallpaperTarget = oldW;
1886 mLowerWallpaperTarget = foundW;
1887 }
1888 }
1889 }
1890 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001891
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001892 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001893 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001894 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1895 || (mLowerWallpaperTarget.mAppToken != null
1896 && mLowerWallpaperTarget.mAppToken.animation != null);
1897 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1898 || (mUpperWallpaperTarget.mAppToken != null
1899 && mUpperWallpaperTarget.mAppToken.animation != null);
1900 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001901 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001902 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001903 }
1904 mLowerWallpaperTarget = null;
1905 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001906 }
1907 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001908
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001909 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001910 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001911 // The window is visible to the compositor... but is it visible
1912 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001913 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001914 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001915
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001916 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001917 // its layer adjustment. Only do this if we are not transfering
1918 // between two wallpaper targets.
1919 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001920 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001921 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001922
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001923 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1924 * TYPE_LAYER_MULTIPLIER
1925 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001926
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001927 // Now w is the window we are supposed to be behind... but we
1928 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001929 // AND any starting window associated with it, AND below the
1930 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001931 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001932 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001933 if (wb.mBaseLayer < maxLayer &&
1934 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001935 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001936 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001937 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001938 // This window is not related to the previous one in any
1939 // interesting way, so stop here.
1940 break;
1941 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001942 foundW = wb;
1943 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001944 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001945 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001946 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001948
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001949 if (foundW == null && topCurW != null) {
1950 // There is no wallpaper target, so it goes at the bottom.
1951 // We will assume it is the same place as last time, if known.
1952 foundW = topCurW;
1953 foundI = topCurI+1;
1954 } else {
1955 // Okay i is the position immediately above the wallpaper. Look at
1956 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001957 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001958 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001959
Dianne Hackborn284ac932009-08-28 10:34:25 -07001960 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001961 if (mWallpaperTarget.mWallpaperX >= 0) {
1962 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001963 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001964 }
1965 if (mWallpaperTarget.mWallpaperY >= 0) {
1966 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001967 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001968 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001969 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001970
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001971 // Start stepping backwards from here, ensuring that our wallpaper windows
1972 // are correctly placed.
1973 int curTokenIndex = mWallpaperTokens.size();
1974 while (curTokenIndex > 0) {
1975 curTokenIndex--;
1976 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001977 if (token.hidden == visible) {
1978 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1979 token.hidden = !visible;
1980 // Need to do a layout to ensure the wallpaper now has the
1981 // correct size.
1982 mLayoutNeeded = true;
1983 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001984
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001985 int curWallpaperIndex = token.windows.size();
1986 while (curWallpaperIndex > 0) {
1987 curWallpaperIndex--;
1988 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001989
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001990 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001991 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001992 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001993
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001994 // First, make sure the client has the current visibility
1995 // state.
1996 if (wallpaper.mWallpaperVisible != visible) {
1997 wallpaper.mWallpaperVisible = visible;
1998 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001999 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002000 "Setting visibility of wallpaper " + wallpaper
2001 + ": " + visible);
2002 wallpaper.mClient.dispatchAppVisibility(visible);
2003 } catch (RemoteException e) {
2004 }
2005 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002006
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002007 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002008 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002009 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002010
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002011 // First, if this window is at the current index, then all
2012 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002013 if (wallpaper == foundW) {
2014 foundI--;
2015 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002016 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002017 continue;
2018 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002019
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002020 // The window didn't match... the current wallpaper window,
2021 // wherever it is, is in the wrong place, so make sure it is
2022 // not in the list.
2023 int oldIndex = localmWindows.indexOf(wallpaper);
2024 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002025 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002026 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002027 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002028 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002029 if (oldIndex < foundI) {
2030 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002031 }
2032 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002033
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002034 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002035 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2036 Slog.v(TAG, "Moving wallpaper " + wallpaper
2037 + " from " + oldIndex + " to " + foundI);
2038 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002039
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002040 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002041 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002042 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002043 }
2044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002045
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002046 return changed;
2047 }
2048
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002049 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002050 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002051 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002052 mWallpaperAnimLayerAdjustment = adj;
2053 int curTokenIndex = mWallpaperTokens.size();
2054 while (curTokenIndex > 0) {
2055 curTokenIndex--;
2056 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2057 int curWallpaperIndex = token.windows.size();
2058 while (curWallpaperIndex > 0) {
2059 curWallpaperIndex--;
2060 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2061 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002062 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002063 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002064 }
2065 }
2066 }
2067
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002068 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2069 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002070 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002071 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002072 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002073 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002074 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2075 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2076 changed = wallpaperWin.mXOffset != offset;
2077 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002078 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002079 + wallpaperWin + " x: " + offset);
2080 wallpaperWin.mXOffset = offset;
2081 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002082 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002083 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002084 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002085 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002086 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002087
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002089 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002090 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2091 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2092 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002093 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002094 + wallpaperWin + " y: " + offset);
2095 changed = true;
2096 wallpaperWin.mYOffset = offset;
2097 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002098 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002099 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002100 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002101 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002103
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002104 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002105 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002106 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002107 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2108 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002109 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002110 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002111 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002112 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002113 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2114 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002115 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002116 if (mWaitingOnWallpaper != null) {
2117 long start = SystemClock.uptimeMillis();
2118 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2119 < start) {
2120 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002121 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002122 "Waiting for offset complete...");
2123 mWindowMap.wait(WALLPAPER_TIMEOUT);
2124 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002125 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002126 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002127 if ((start+WALLPAPER_TIMEOUT)
2128 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002129 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002130 + wallpaperWin);
2131 mLastWallpaperTimeoutTime = start;
2132 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002133 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002134 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002135 }
2136 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002137 } catch (RemoteException e) {
2138 }
2139 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002140
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002141 return changed;
2142 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002143
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002144 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002145 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002146 if (mWaitingOnWallpaper != null &&
2147 mWaitingOnWallpaper.mClient.asBinder() == window) {
2148 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002149 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002150 }
2151 }
2152 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002153
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002154 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002155 final int dw = mDisplay.getWidth();
2156 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002157
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002158 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002159
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002160 WindowState target = mWallpaperTarget;
2161 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002162 if (target.mWallpaperX >= 0) {
2163 mLastWallpaperX = target.mWallpaperX;
2164 } else if (changingTarget.mWallpaperX >= 0) {
2165 mLastWallpaperX = changingTarget.mWallpaperX;
2166 }
2167 if (target.mWallpaperY >= 0) {
2168 mLastWallpaperY = target.mWallpaperY;
2169 } else if (changingTarget.mWallpaperY >= 0) {
2170 mLastWallpaperY = changingTarget.mWallpaperY;
2171 }
2172 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002173
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002174 int curTokenIndex = mWallpaperTokens.size();
2175 while (curTokenIndex > 0) {
2176 curTokenIndex--;
2177 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2178 int curWallpaperIndex = token.windows.size();
2179 while (curWallpaperIndex > 0) {
2180 curWallpaperIndex--;
2181 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2182 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2183 wallpaper.computeShownFrameLocked();
2184 changed = true;
2185 // We only want to be synchronous with one wallpaper.
2186 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002187 }
2188 }
2189 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002190
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002191 return changed;
2192 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002193
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002194 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002195 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002196 final int dw = mDisplay.getWidth();
2197 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002198
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002199 int curTokenIndex = mWallpaperTokens.size();
2200 while (curTokenIndex > 0) {
2201 curTokenIndex--;
2202 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002203 if (token.hidden == visible) {
2204 token.hidden = !visible;
2205 // Need to do a layout to ensure the wallpaper now has the
2206 // correct size.
2207 mLayoutNeeded = true;
2208 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002209
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002210 int curWallpaperIndex = token.windows.size();
2211 while (curWallpaperIndex > 0) {
2212 curWallpaperIndex--;
2213 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2214 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002215 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002216 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002217
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002218 if (wallpaper.mWallpaperVisible != visible) {
2219 wallpaper.mWallpaperVisible = visible;
2220 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002221 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002222 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002223 + ": " + visible);
2224 wallpaper.mClient.dispatchAppVisibility(visible);
2225 } catch (RemoteException e) {
2226 }
2227 }
2228 }
2229 }
2230 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 public int addWindow(Session session, IWindow client,
2233 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002234 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 int res = mPolicy.checkAddPermission(attrs);
2236 if (res != WindowManagerImpl.ADD_OKAY) {
2237 return res;
2238 }
Romain Guy06882f82009-06-10 13:36:04 -07002239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002240 boolean reportNewConfig = false;
2241 WindowState attachedWindow = null;
2242 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002243 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002247 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002248 }
Romain Guy06882f82009-06-10 13:36:04 -07002249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002251 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2253 }
2254
2255 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002256 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002258 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 + attrs.token + ". Aborting.");
2260 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2261 }
2262 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2263 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002264 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 + attrs.token + ". Aborting.");
2266 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2267 }
2268 }
2269
2270 boolean addToken = false;
2271 WindowToken token = mTokenMap.get(attrs.token);
2272 if (token == null) {
2273 if (attrs.type >= FIRST_APPLICATION_WINDOW
2274 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002275 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 + attrs.token + ". Aborting.");
2277 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2278 }
2279 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002280 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 + attrs.token + ". Aborting.");
2282 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2283 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002284 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002285 Slog.w(TAG, "Attempted to add wallpaper window with unknown 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 token = new WindowToken(attrs.token, -1, false);
2290 addToken = true;
2291 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2292 && attrs.type <= LAST_APPLICATION_WINDOW) {
2293 AppWindowToken atoken = token.appWindowToken;
2294 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002295 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 + token + ". Aborting.");
2297 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2298 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002299 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 + token + ". Aborting.");
2301 return WindowManagerImpl.ADD_APP_EXITING;
2302 }
2303 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2304 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002305 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2307 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2308 }
2309 } else if (attrs.type == TYPE_INPUT_METHOD) {
2310 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002311 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312 + attrs.token + ". Aborting.");
2313 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2314 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002315 } else if (attrs.type == TYPE_WALLPAPER) {
2316 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002317 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002318 + attrs.token + ". Aborting.");
2319 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2320 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 }
2322
2323 win = new WindowState(session, client, token,
2324 attachedWindow, attrs, viewVisibility);
2325 if (win.mDeathRecipient == null) {
2326 // Client has apparently died, so there is no reason to
2327 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002328 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 + " that is dead, aborting.");
2330 return WindowManagerImpl.ADD_APP_EXITING;
2331 }
2332
2333 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 res = mPolicy.prepareAddWindowLw(win, attrs);
2336 if (res != WindowManagerImpl.ADD_OKAY) {
2337 return res;
2338 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002339
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002340 if (outInputChannel != null) {
2341 String name = win.makeInputChannelName();
2342 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2343 win.mInputChannel = inputChannels[0];
2344 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2345
Jeff Brown928e0542011-01-10 11:17:36 -08002346 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348
2349 // From now on, no exceptions or errors allowed!
2350
2351 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002352
Dianne Hackborn5132b372010-07-29 12:51:35 -07002353 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 if (addToken) {
2356 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 }
2358 win.attach();
2359 mWindowMap.put(client.asBinder(), win);
2360
2361 if (attrs.type == TYPE_APPLICATION_STARTING &&
2362 token.appWindowToken != null) {
2363 token.appWindowToken.startingWindow = win;
2364 }
2365
2366 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 if (attrs.type == TYPE_INPUT_METHOD) {
2369 mInputMethodWindow = win;
2370 addInputMethodWindowToListLocked(win);
2371 imMayMove = false;
2372 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2373 mInputMethodDialogs.add(win);
2374 addWindowToListInOrderLocked(win, true);
2375 adjustInputMethodDialogsLocked();
2376 imMayMove = false;
2377 } else {
2378 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002379 if (attrs.type == TYPE_WALLPAPER) {
2380 mLastWallpaperTimeoutTime = 0;
2381 adjustWallpaperWindowsLocked();
2382 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002383 adjustWallpaperWindowsLocked();
2384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 }
Romain Guy06882f82009-06-10 13:36:04 -07002386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 if (mInTouchMode) {
2392 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2393 }
2394 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2395 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2396 }
Romain Guy06882f82009-06-10 13:36:04 -07002397
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002398 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002400 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2401 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 imMayMove = false;
2403 }
2404 }
Romain Guy06882f82009-06-10 13:36:04 -07002405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002407 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 }
Romain Guy06882f82009-06-10 13:36:04 -07002409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 assignLayersLocked();
2411 // Don't do layout here, the window must call
2412 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 //dump();
2415
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002416 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002417 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002418 }
Jeff Brown349703e2010-06-22 01:27:15 -07002419
Joe Onorato8a9b2202010-02-26 18:56:32 -08002420 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 TAG, "New client " + client.asBinder()
2422 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002423
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002424 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002425 reportNewConfig = true;
2426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 }
2428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 if (reportNewConfig) {
2430 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 return res;
2436 }
Romain Guy06882f82009-06-10 13:36:04 -07002437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 public void removeWindow(Session session, IWindow client) {
2439 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002440 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 if (win == null) {
2442 return;
2443 }
2444 removeWindowLocked(session, win);
2445 }
2446 }
Romain Guy06882f82009-06-10 13:36:04 -07002447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 public void removeWindowLocked(Session session, WindowState win) {
2449
Joe Onorato8a9b2202010-02-26 18:56:32 -08002450 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 TAG, "Remove " + win + " client="
2452 + Integer.toHexString(System.identityHashCode(
2453 win.mClient.asBinder()))
2454 + ", surface=" + win.mSurface);
2455
2456 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002457
2458 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002459
Joe Onorato8a9b2202010-02-26 18:56:32 -08002460 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2462 + " mExiting=" + win.mExiting
2463 + " isAnimating=" + win.isAnimating()
2464 + " app-animation="
2465 + (win.mAppToken != null ? win.mAppToken.animation : null)
2466 + " inPendingTransaction="
2467 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2468 + " mDisplayFrozen=" + mDisplayFrozen);
2469 // Visibility of the removed window. Will be used later to update orientation later on.
2470 boolean wasVisible = false;
2471 // First, see if we need to run an animation. If we do, we have
2472 // to hold off on removing the window until the animation is done.
2473 // If the display is frozen, just remove immediately, since the
2474 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002475 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 // If we are not currently running the exit animation, we
2477 // need to see about starting one.
2478 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2481 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2482 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2483 }
2484 // Try starting an animation.
2485 if (applyAnimationLocked(win, transit, false)) {
2486 win.mExiting = true;
2487 }
2488 }
2489 if (win.mExiting || win.isAnimating()) {
2490 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002491 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 win.mExiting = true;
2493 win.mRemoveOnExit = true;
2494 mLayoutNeeded = true;
2495 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2496 performLayoutAndPlaceSurfacesLocked();
2497 if (win.mAppToken != null) {
2498 win.mAppToken.updateReportedVisibilityLocked();
2499 }
2500 //dump();
2501 Binder.restoreCallingIdentity(origId);
2502 return;
2503 }
2504 }
2505
2506 removeWindowInnerLocked(session, win);
2507 // Removing a visible window will effect the computed orientation
2508 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002509 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002510 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002511 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002512 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 }
2514 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2515 Binder.restoreCallingIdentity(origId);
2516 }
Romain Guy06882f82009-06-10 13:36:04 -07002517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002519 if (win.mRemoved) {
2520 // Nothing to do.
2521 return;
2522 }
2523
2524 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2525 WindowState cwin = win.mChildWindows.get(i);
2526 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2527 + win);
2528 removeWindowInnerLocked(cwin.mSession, cwin);
2529 }
2530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 if (mInputMethodTarget == win) {
2534 moveInputMethodWindowsIfNeededLocked(false);
2535 }
Romain Guy06882f82009-06-10 13:36:04 -07002536
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002537 if (false) {
2538 RuntimeException e = new RuntimeException("here");
2539 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002540 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 mPolicy.removeWindowLw(win);
2544 win.removeLocked();
2545
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002546 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 mWindowMap.remove(win.mClient.asBinder());
2548 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002549 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002550 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002551 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552
2553 if (mInputMethodWindow == win) {
2554 mInputMethodWindow = null;
2555 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2556 mInputMethodDialogs.remove(win);
2557 }
Romain Guy06882f82009-06-10 13:36:04 -07002558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 final WindowToken token = win.mToken;
2560 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002561 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 token.windows.remove(win);
2563 if (atoken != null) {
2564 atoken.allAppWindows.remove(win);
2565 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002566 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 TAG, "**** Removing window " + win + ": count="
2568 + token.windows.size());
2569 if (token.windows.size() == 0) {
2570 if (!token.explicit) {
2571 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 } else if (atoken != null) {
2573 atoken.firstWindowDrawn = false;
2574 }
2575 }
2576
2577 if (atoken != null) {
2578 if (atoken.startingWindow == win) {
2579 atoken.startingWindow = null;
2580 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2581 // If this is the last window and we had requested a starting
2582 // transition window, well there is no point now.
2583 atoken.startingData = null;
2584 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2585 // If this is the last window except for a starting transition
2586 // window, we need to get rid of the starting transition.
2587 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002588 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 + ": no more real windows");
2590 }
2591 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2592 mH.sendMessage(m);
2593 }
2594 }
Romain Guy06882f82009-06-10 13:36:04 -07002595
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002596 if (win.mAttrs.type == TYPE_WALLPAPER) {
2597 mLastWallpaperTimeoutTime = 0;
2598 adjustWallpaperWindowsLocked();
2599 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002600 adjustWallpaperWindowsLocked();
2601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 if (!mInLayout) {
2604 assignLayersLocked();
2605 mLayoutNeeded = true;
2606 performLayoutAndPlaceSurfacesLocked();
2607 if (win.mAppToken != null) {
2608 win.mAppToken.updateReportedVisibilityLocked();
2609 }
2610 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002611
2612 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 }
2614
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002615 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2616 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2617 + ": " + msg + " / " + w.mAttrs.getTitle();
2618 if (where != null) {
2619 Slog.i(TAG, str, where);
2620 } else {
2621 Slog.i(TAG, str);
2622 }
2623 }
2624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2626 long origId = Binder.clearCallingIdentity();
2627 try {
2628 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002629 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002630 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002631 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2632 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 Surface.openTransaction();
2634 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002635 if (SHOW_TRANSACTIONS) logSurface(w,
2636 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637 w.mSurface.setTransparentRegionHint(region);
2638 } finally {
2639 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002640 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2641 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 }
2643 }
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(origId);
2647 }
2648 }
2649
2650 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002651 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002652 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 long origId = Binder.clearCallingIdentity();
2654 try {
2655 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002656 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 if (w != null) {
2658 w.mGivenInsetsPending = false;
2659 w.mGivenContentInsets.set(contentInsets);
2660 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002661 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002662 w.mTouchableInsets = touchableInsets;
2663 mLayoutNeeded = true;
2664 performLayoutAndPlaceSurfacesLocked();
2665 }
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(origId);
2669 }
2670 }
Romain Guy06882f82009-06-10 13:36:04 -07002671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 public void getWindowDisplayFrame(Session session, IWindow client,
2673 Rect outDisplayFrame) {
2674 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002675 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 if (win == null) {
2677 outDisplayFrame.setEmpty();
2678 return;
2679 }
2680 outDisplayFrame.set(win.mDisplayFrame);
2681 }
2682 }
2683
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002684 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2685 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002686 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2687 window.mWallpaperX = x;
2688 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002689 window.mWallpaperXStep = xStep;
2690 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002691 if (updateWallpaperOffsetLocked(window, true)) {
2692 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002693 }
2694 }
2695 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002696
Dianne Hackborn75804932009-10-20 20:15:20 -07002697 void wallpaperCommandComplete(IBinder window, Bundle result) {
2698 synchronized (mWindowMap) {
2699 if (mWaitingOnWallpaper != null &&
2700 mWaitingOnWallpaper.mClient.asBinder() == window) {
2701 mWaitingOnWallpaper = null;
2702 mWindowMap.notifyAll();
2703 }
2704 }
2705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002706
Dianne Hackborn75804932009-10-20 20:15:20 -07002707 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2708 String action, int x, int y, int z, Bundle extras, boolean sync) {
2709 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2710 || window == mUpperWallpaperTarget) {
2711 boolean doWait = sync;
2712 int curTokenIndex = mWallpaperTokens.size();
2713 while (curTokenIndex > 0) {
2714 curTokenIndex--;
2715 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2716 int curWallpaperIndex = token.windows.size();
2717 while (curWallpaperIndex > 0) {
2718 curWallpaperIndex--;
2719 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2720 try {
2721 wallpaper.mClient.dispatchWallpaperCommand(action,
2722 x, y, z, extras, sync);
2723 // We only want to be synchronous with one wallpaper.
2724 sync = false;
2725 } catch (RemoteException e) {
2726 }
2727 }
2728 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002729
Dianne Hackborn75804932009-10-20 20:15:20 -07002730 if (doWait) {
2731 // XXX Need to wait for result.
2732 }
2733 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002734
Dianne Hackborn75804932009-10-20 20:15:20 -07002735 return null;
2736 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 public int relayoutWindow(Session session, IWindow client,
2739 WindowManager.LayoutParams attrs, int requestedWidth,
2740 int requestedHeight, int viewVisibility, boolean insetsPending,
2741 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002742 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 boolean displayed = false;
2744 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002745 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002746 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002749 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 if (win == null) {
2751 return 0;
2752 }
2753 win.mRequestedWidth = requestedWidth;
2754 win.mRequestedHeight = requestedHeight;
2755
2756 if (attrs != null) {
2757 mPolicy.adjustWindowParamsLw(attrs);
2758 }
Romain Guy06882f82009-06-10 13:36:04 -07002759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002760 int attrChanges = 0;
2761 int flagChanges = 0;
2762 if (attrs != null) {
2763 flagChanges = win.mAttrs.flags ^= attrs.flags;
2764 attrChanges = win.mAttrs.copyFrom(attrs);
2765 }
2766
Joe Onorato8a9b2202010-02-26 18:56:32 -08002767 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002768
2769 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2770 win.mAlpha = attrs.alpha;
2771 }
2772
2773 final boolean scaledWindow =
2774 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2775
2776 if (scaledWindow) {
2777 // requested{Width|Height} Surface's physical size
2778 // attrs.{width|height} Size on screen
2779 win.mHScale = (attrs.width != requestedWidth) ?
2780 (attrs.width / (float)requestedWidth) : 1.0f;
2781 win.mVScale = (attrs.height != requestedHeight) ?
2782 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002783 } else {
2784 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 }
2786
2787 boolean imMayMove = (flagChanges&(
2788 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2789 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 boolean focusMayChange = win.mViewVisibility != viewVisibility
2792 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2793 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002794
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002795 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2796 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 win.mRelayoutCalled = true;
2799 final int oldVisibility = win.mViewVisibility;
2800 win.mViewVisibility = viewVisibility;
2801 if (viewVisibility == View.VISIBLE &&
2802 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2803 displayed = !win.isVisibleLw();
2804 if (win.mExiting) {
2805 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002806 if (win.mAnimation != null) {
2807 win.mAnimation.cancel();
2808 win.mAnimation = null;
2809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 }
2811 if (win.mDestroying) {
2812 win.mDestroying = false;
2813 mDestroySurface.remove(win);
2814 }
2815 if (oldVisibility == View.GONE) {
2816 win.mEnterAnimationPending = true;
2817 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002818 if (displayed) {
2819 if (win.mSurface != null && !win.mDrawPending
2820 && !win.mCommitDrawPending && !mDisplayFrozen
2821 && mPolicy.isScreenOn()) {
2822 applyEnterAnimationLocked(win);
2823 }
2824 if ((win.mAttrs.flags
2825 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2826 if (DEBUG_VISIBILITY) Slog.v(TAG,
2827 "Relayout window turning screen on: " + win);
2828 win.mTurnOnScreen = true;
2829 }
2830 int diff = 0;
2831 if (win.mConfiguration != mCurConfiguration
2832 && (win.mConfiguration == null
2833 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2834 win.mConfiguration = mCurConfiguration;
2835 if (DEBUG_CONFIGURATION) {
2836 Slog.i(TAG, "Window " + win + " visible with new config: "
2837 + win.mConfiguration + " / 0x"
2838 + Integer.toHexString(diff));
2839 }
2840 outConfig.setTo(mCurConfiguration);
2841 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002842 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2844 // To change the format, we need to re-build the surface.
2845 win.destroySurfaceLocked();
2846 displayed = true;
2847 }
2848 try {
2849 Surface surface = win.createSurfaceLocked();
2850 if (surface != null) {
2851 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002852 win.mReportDestroySurface = false;
2853 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002854 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002855 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002857 // For some reason there isn't a surface. Clear the
2858 // caller's object so they see the same state.
2859 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 }
2861 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002862 mInputMonitor.updateInputWindowsLw();
2863
Joe Onorato8a9b2202010-02-26 18:56:32 -08002864 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002865 + client + " (" + win.mAttrs.getTitle() + ")",
2866 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 Binder.restoreCallingIdentity(origId);
2868 return 0;
2869 }
2870 if (displayed) {
2871 focusMayChange = true;
2872 }
2873 if (win.mAttrs.type == TYPE_INPUT_METHOD
2874 && mInputMethodWindow == null) {
2875 mInputMethodWindow = win;
2876 imMayMove = true;
2877 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002878 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2879 && win.mAppToken != null
2880 && win.mAppToken.startingWindow != null) {
2881 // Special handling of starting window over the base
2882 // window of the app: propagate lock screen flags to it,
2883 // to provide the correct semantics while starting.
2884 final int mask =
2885 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002886 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2887 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002888 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2889 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2890 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 } else {
2892 win.mEnterAnimationPending = false;
2893 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002894 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002895 + ": mExiting=" + win.mExiting
2896 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 // If we are not currently running the exit animation, we
2898 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002899 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 // Try starting an animation; if there isn't one, we
2901 // can destroy the surface right away.
2902 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2903 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2904 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2905 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002906 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002908 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 } else if (win.isAnimating()) {
2911 // Currently in a hide animation... turn this into
2912 // an exit.
2913 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002914 } else if (win == mWallpaperTarget) {
2915 // If the wallpaper is currently behind this
2916 // window, we need to change both of them inside
2917 // of a transaction to avoid artifacts.
2918 win.mExiting = true;
2919 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 } else {
2921 if (mInputMethodWindow == win) {
2922 mInputMethodWindow = null;
2923 }
2924 win.destroySurfaceLocked();
2925 }
2926 }
2927 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002928
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002929 if (win.mSurface == null || (win.getAttrs().flags
2930 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2931 || win.mSurfacePendingDestroy) {
2932 // We are being called from a local process, which
2933 // means outSurface holds its current surface. Ensure the
2934 // surface object is cleared, but we don't want it actually
2935 // destroyed at this point.
2936 win.mSurfacePendingDestroy = false;
2937 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002938 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002939 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002940 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002941 "Keeping surface, will report destroy: " + win);
2942 win.mReportDestroySurface = true;
2943 outSurface.copyFrom(win.mSurface);
2944 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 }
2946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 if (focusMayChange) {
2948 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2949 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950 imMayMove = false;
2951 }
2952 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2953 }
Romain Guy06882f82009-06-10 13:36:04 -07002954
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002955 // updateFocusedWindowLocked() already assigned layers so we only need to
2956 // reassign them at this point if the IM window state gets shuffled
2957 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002960 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2961 // Little hack here -- we -should- be able to rely on the
2962 // function to return true if the IME has moved and needs
2963 // its layer recomputed. However, if the IME was hidden
2964 // and isn't actually moved in the list, its layer may be
2965 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 assignLayers = true;
2967 }
2968 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002969 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002970 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002971 assignLayers = true;
2972 }
2973 }
Romain Guy06882f82009-06-10 13:36:04 -07002974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 mLayoutNeeded = true;
2976 win.mGivenInsetsPending = insetsPending;
2977 if (assignLayers) {
2978 assignLayersLocked();
2979 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002980 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002982 if (displayed && win.mIsWallpaper) {
2983 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002984 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 if (win.mAppToken != null) {
2987 win.mAppToken.updateReportedVisibilityLocked();
2988 }
2989 outFrame.set(win.mFrame);
2990 outContentInsets.set(win.mContentInsets);
2991 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002992 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002994 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 + ", requestedHeight=" + requestedHeight
2996 + ", viewVisibility=" + viewVisibility
2997 + "\nRelayout returning frame=" + outFrame
2998 + ", surface=" + outSurface);
2999
Joe Onorato8a9b2202010-02-26 18:56:32 -08003000 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3002
3003 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003004
3005 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 }
3007
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003008 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 sendNewConfiguration();
3010 }
Romain Guy06882f82009-06-10 13:36:04 -07003011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3015 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3016 }
3017
3018 public void finishDrawingWindow(Session session, IWindow client) {
3019 final long origId = Binder.clearCallingIdentity();
3020 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003021 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003023 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3024 adjustWallpaperWindowsLocked();
3025 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 mLayoutNeeded = true;
3027 performLayoutAndPlaceSurfacesLocked();
3028 }
3029 }
3030 Binder.restoreCallingIdentity(origId);
3031 }
3032
3033 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003034 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 + (lp != null ? lp.packageName : null)
3036 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3037 if (lp != null && lp.windowAnimations != 0) {
3038 // If this is a system resource, don't try to load it from the
3039 // application resources. It is nice to avoid loading application
3040 // resources if we can.
3041 String packageName = lp.packageName != null ? lp.packageName : "android";
3042 int resId = lp.windowAnimations;
3043 if ((resId&0xFF000000) == 0x01000000) {
3044 packageName = "android";
3045 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003046 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 + packageName);
3048 return AttributeCache.instance().get(packageName, resId,
3049 com.android.internal.R.styleable.WindowAnimation);
3050 }
3051 return null;
3052 }
Romain Guy06882f82009-06-10 13:36:04 -07003053
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003054 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003055 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003056 + packageName + " resId=0x" + Integer.toHexString(resId));
3057 if (packageName != null) {
3058 if ((resId&0xFF000000) == 0x01000000) {
3059 packageName = "android";
3060 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003061 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003062 + packageName);
3063 return AttributeCache.instance().get(packageName, resId,
3064 com.android.internal.R.styleable.WindowAnimation);
3065 }
3066 return null;
3067 }
3068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003069 private void applyEnterAnimationLocked(WindowState win) {
3070 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3071 if (win.mEnterAnimationPending) {
3072 win.mEnterAnimationPending = false;
3073 transit = WindowManagerPolicy.TRANSIT_ENTER;
3074 }
3075
3076 applyAnimationLocked(win, transit, true);
3077 }
3078
3079 private boolean applyAnimationLocked(WindowState win,
3080 int transit, boolean isEntrance) {
3081 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3082 // If we are trying to apply an animation, but already running
3083 // an animation of the same type, then just leave that one alone.
3084 return true;
3085 }
Romain Guy06882f82009-06-10 13:36:04 -07003086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 // Only apply an animation if the display isn't frozen. If it is
3088 // frozen, there is no reason to animate and it can cause strange
3089 // artifacts when we unfreeze the display if some different animation
3090 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003091 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003092 int anim = mPolicy.selectAnimationLw(win, transit);
3093 int attr = -1;
3094 Animation a = null;
3095 if (anim != 0) {
3096 a = AnimationUtils.loadAnimation(mContext, anim);
3097 } else {
3098 switch (transit) {
3099 case WindowManagerPolicy.TRANSIT_ENTER:
3100 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3101 break;
3102 case WindowManagerPolicy.TRANSIT_EXIT:
3103 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3104 break;
3105 case WindowManagerPolicy.TRANSIT_SHOW:
3106 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3107 break;
3108 case WindowManagerPolicy.TRANSIT_HIDE:
3109 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3110 break;
3111 }
3112 if (attr >= 0) {
3113 a = loadAnimation(win.mAttrs, attr);
3114 }
3115 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003116 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3118 + " mAnimation=" + win.mAnimation
3119 + " isEntrance=" + isEntrance);
3120 if (a != null) {
3121 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003122 RuntimeException e = null;
3123 if (!HIDE_STACK_CRAWLS) {
3124 e = new RuntimeException();
3125 e.fillInStackTrace();
3126 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003127 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 }
3129 win.setAnimation(a);
3130 win.mAnimationIsEntrance = isEntrance;
3131 }
3132 } else {
3133 win.clearAnimation();
3134 }
3135
3136 return win.mAnimation != null;
3137 }
3138
3139 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3140 int anim = 0;
3141 Context context = mContext;
3142 if (animAttr >= 0) {
3143 AttributeCache.Entry ent = getCachedAnimations(lp);
3144 if (ent != null) {
3145 context = ent.context;
3146 anim = ent.array.getResourceId(animAttr, 0);
3147 }
3148 }
3149 if (anim != 0) {
3150 return AnimationUtils.loadAnimation(context, anim);
3151 }
3152 return null;
3153 }
Romain Guy06882f82009-06-10 13:36:04 -07003154
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003155 private Animation loadAnimation(String packageName, int resId) {
3156 int anim = 0;
3157 Context context = mContext;
3158 if (resId >= 0) {
3159 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3160 if (ent != null) {
3161 context = ent.context;
3162 anim = resId;
3163 }
3164 }
3165 if (anim != 0) {
3166 return AnimationUtils.loadAnimation(context, anim);
3167 }
3168 return null;
3169 }
3170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003171 private boolean applyAnimationLocked(AppWindowToken wtoken,
3172 WindowManager.LayoutParams lp, int transit, boolean enter) {
3173 // Only apply an animation if the display isn't frozen. If it is
3174 // frozen, there is no reason to animate and it can cause strange
3175 // artifacts when we unfreeze the display if some different animation
3176 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003177 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003178 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003179 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003180 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003181 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003182 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003183 } else if (mNextAppTransitionPackage != null) {
3184 a = loadAnimation(mNextAppTransitionPackage, enter ?
3185 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003186 } else {
3187 int animAttr = 0;
3188 switch (transit) {
3189 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3190 animAttr = enter
3191 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3192 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3193 break;
3194 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3195 animAttr = enter
3196 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3197 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3198 break;
3199 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3200 animAttr = enter
3201 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3202 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3203 break;
3204 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3205 animAttr = enter
3206 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3207 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3208 break;
3209 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3210 animAttr = enter
3211 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3212 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3213 break;
3214 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3215 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003216 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003217 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3218 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003219 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003220 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003221 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3222 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003223 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003224 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003225 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003226 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3227 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3228 break;
3229 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3230 animAttr = enter
3231 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3232 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3233 break;
3234 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3235 animAttr = enter
3236 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3237 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003238 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003239 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003240 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003241 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003242 + " anim=" + a
3243 + " animAttr=0x" + Integer.toHexString(animAttr)
3244 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 if (a != null) {
3247 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003248 RuntimeException e = null;
3249 if (!HIDE_STACK_CRAWLS) {
3250 e = new RuntimeException();
3251 e.fillInStackTrace();
3252 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003253 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 }
3255 wtoken.setAnimation(a);
3256 }
3257 } else {
3258 wtoken.clearAnimation();
3259 }
3260
3261 return wtoken.animation != null;
3262 }
3263
3264 // -------------------------------------------------------------
3265 // Application Window Tokens
3266 // -------------------------------------------------------------
3267
3268 public void validateAppTokens(List tokens) {
3269 int v = tokens.size()-1;
3270 int m = mAppTokens.size()-1;
3271 while (v >= 0 && m >= 0) {
3272 AppWindowToken wtoken = mAppTokens.get(m);
3273 if (wtoken.removed) {
3274 m--;
3275 continue;
3276 }
3277 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003278 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3280 }
3281 v--;
3282 m--;
3283 }
3284 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003285 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 v--;
3287 }
3288 while (m >= 0) {
3289 AppWindowToken wtoken = mAppTokens.get(m);
3290 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003291 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 }
3293 m--;
3294 }
3295 }
3296
3297 boolean checkCallingPermission(String permission, String func) {
3298 // Quick check: if the calling permission is me, it's all okay.
3299 if (Binder.getCallingPid() == Process.myPid()) {
3300 return true;
3301 }
Romain Guy06882f82009-06-10 13:36:04 -07003302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 if (mContext.checkCallingPermission(permission)
3304 == PackageManager.PERMISSION_GRANTED) {
3305 return true;
3306 }
3307 String msg = "Permission Denial: " + func + " from pid="
3308 + Binder.getCallingPid()
3309 + ", uid=" + Binder.getCallingUid()
3310 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003311 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 return false;
3313 }
Romain Guy06882f82009-06-10 13:36:04 -07003314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 AppWindowToken findAppWindowToken(IBinder token) {
3316 WindowToken wtoken = mTokenMap.get(token);
3317 if (wtoken == null) {
3318 return null;
3319 }
3320 return wtoken.appWindowToken;
3321 }
Romain Guy06882f82009-06-10 13:36:04 -07003322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 public void addWindowToken(IBinder token, int type) {
3324 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3325 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003326 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 }
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 synchronized(mWindowMap) {
3330 WindowToken wtoken = mTokenMap.get(token);
3331 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003332 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 return;
3334 }
3335 wtoken = new WindowToken(token, type, true);
3336 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003337 if (type == TYPE_WALLPAPER) {
3338 mWallpaperTokens.add(wtoken);
3339 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 }
3341 }
Romain Guy06882f82009-06-10 13:36:04 -07003342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 public void removeWindowToken(IBinder token) {
3344 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3345 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003346 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 }
3348
3349 final long origId = Binder.clearCallingIdentity();
3350 synchronized(mWindowMap) {
3351 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 if (wtoken != null) {
3353 boolean delayed = false;
3354 if (!wtoken.hidden) {
3355 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 final int N = wtoken.windows.size();
3358 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 for (int i=0; i<N; i++) {
3361 WindowState win = wtoken.windows.get(i);
3362
3363 if (win.isAnimating()) {
3364 delayed = true;
3365 }
Romain Guy06882f82009-06-10 13:36:04 -07003366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 if (win.isVisibleNow()) {
3368 applyAnimationLocked(win,
3369 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 changed = true;
3371 }
3372 }
3373
3374 if (changed) {
3375 mLayoutNeeded = true;
3376 performLayoutAndPlaceSurfacesLocked();
3377 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3378 }
Romain Guy06882f82009-06-10 13:36:04 -07003379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 if (delayed) {
3381 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003382 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3383 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 }
3385 }
Romain Guy06882f82009-06-10 13:36:04 -07003386
Jeff Brownc5ed5912010-07-14 18:48:53 -07003387 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003388 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003389 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 }
3391 }
3392 Binder.restoreCallingIdentity(origId);
3393 }
3394
3395 public void addAppToken(int addPos, IApplicationToken token,
3396 int groupId, int requestedOrientation, boolean fullscreen) {
3397 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3398 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003399 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 }
Jeff Brown349703e2010-06-22 01:27:15 -07003401
3402 // Get the dispatching timeout here while we are not holding any locks so that it
3403 // can be cached by the AppWindowToken. The timeout value is used later by the
3404 // input dispatcher in code that does hold locks. If we did not cache the value
3405 // here we would run the chance of introducing a deadlock between the window manager
3406 // (which holds locks while updating the input dispatcher state) and the activity manager
3407 // (which holds locks while querying the application token).
3408 long inputDispatchingTimeoutNanos;
3409 try {
3410 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3411 } catch (RemoteException ex) {
3412 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3413 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3414 }
Romain Guy06882f82009-06-10 13:36:04 -07003415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003416 synchronized(mWindowMap) {
3417 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3418 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003419 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 return;
3421 }
3422 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003423 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 wtoken.groupId = groupId;
3425 wtoken.appFullscreen = fullscreen;
3426 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003427 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 // Application tokens start out hidden.
3432 wtoken.hidden = true;
3433 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 //dump();
3436 }
3437 }
Romain Guy06882f82009-06-10 13:36:04 -07003438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 public void setAppGroupId(IBinder token, int groupId) {
3440 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3441 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003442 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443 }
3444
3445 synchronized(mWindowMap) {
3446 AppWindowToken wtoken = findAppWindowToken(token);
3447 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003448 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003449 return;
3450 }
3451 wtoken.groupId = groupId;
3452 }
3453 }
Romain Guy06882f82009-06-10 13:36:04 -07003454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003455 public int getOrientationFromWindowsLocked() {
3456 int pos = mWindows.size() - 1;
3457 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003458 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003459 pos--;
3460 if (wtoken.mAppToken != null) {
3461 // We hit an application window. so the orientation will be determined by the
3462 // app window. No point in continuing further.
3463 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3464 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003465 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 continue;
3467 }
3468 int req = wtoken.mAttrs.screenOrientation;
3469 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3470 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3471 continue;
3472 } else {
3473 return req;
3474 }
3475 }
3476 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3477 }
Romain Guy06882f82009-06-10 13:36:04 -07003478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003479 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003480 int pos = mAppTokens.size() - 1;
3481 int curGroup = 0;
3482 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3483 boolean findingBehind = false;
3484 boolean haveGroup = false;
3485 boolean lastFullscreen = false;
3486 while (pos >= 0) {
3487 AppWindowToken wtoken = mAppTokens.get(pos);
3488 pos--;
3489 // if we're about to tear down this window and not seek for
3490 // the behind activity, don't use it for orientation
3491 if (!findingBehind
3492 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3493 continue;
3494 }
3495
3496 if (!haveGroup) {
3497 // We ignore any hidden applications on the top.
3498 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003499 continue;
3500 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003501 haveGroup = true;
3502 curGroup = wtoken.groupId;
3503 lastOrientation = wtoken.requestedOrientation;
3504 } else if (curGroup != wtoken.groupId) {
3505 // If we have hit a new application group, and the bottom
3506 // of the previous group didn't explicitly say to use
3507 // the orientation behind it, and the last app was
3508 // full screen, then we'll stick with the
3509 // user's orientation.
3510 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3511 && lastFullscreen) {
3512 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003515 int or = wtoken.requestedOrientation;
3516 // If this application is fullscreen, and didn't explicitly say
3517 // to use the orientation behind it, then just take whatever
3518 // orientation it has and ignores whatever is under it.
3519 lastFullscreen = wtoken.appFullscreen;
3520 if (lastFullscreen
3521 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3522 return or;
3523 }
3524 // If this application has requested an explicit orientation,
3525 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003526 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3527 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003528 return or;
3529 }
3530 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3531 }
3532 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 }
Romain Guy06882f82009-06-10 13:36:04 -07003534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003536 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003537 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3538 "updateOrientationFromAppTokens()")) {
3539 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3540 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003541
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003542 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003544
3545 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003546 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003547 if (freezeThisOneIfNeeded != null) {
3548 AppWindowToken wtoken = findAppWindowToken(
3549 freezeThisOneIfNeeded);
3550 if (wtoken != null) {
3551 startAppFreezingScreenLocked(wtoken,
3552 ActivityInfo.CONFIG_ORIENTATION);
3553 }
3554 }
3555 config = computeNewConfigurationLocked();
3556
3557 } else if (currentConfig != null) {
3558 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003559 // state mismatches the activity manager's, update it,
3560 // disregarding font scale, which should remain set to
3561 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003562 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003563 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003564 if (computeNewConfigurationLocked(mTempConfiguration)) {
3565 if (currentConfig.diff(mTempConfiguration) != 0) {
3566 mWaitingForConfig = true;
3567 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003568 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003569 config = new Configuration(mTempConfiguration);
3570 }
3571 }
3572 }
3573 }
3574
Dianne Hackborncfaef692009-06-15 14:24:44 -07003575 Binder.restoreCallingIdentity(ident);
3576 return config;
3577 }
3578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003580 * Determine the new desired orientation of the display, returning
3581 * a non-null new Configuration if it has changed from the current
3582 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3583 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3584 * SCREEN. This will typically be done for you if you call
3585 * sendNewConfiguration().
3586 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 * The orientation is computed from non-application windows first. If none of
3588 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003589 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3591 * android.os.IBinder)
3592 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003593 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3594 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003595 // If the display is frozen, some activities may be in the middle
3596 // of restarting, and thus have removed their old window. If the
3597 // window has the flag to hide the lock screen, then the lock screen
3598 // can re-appear and inflict its own orientation on us. Keep the
3599 // orientation stable until this all settles down.
3600 return false;
3601 }
3602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 long ident = Binder.clearCallingIdentity();
3605 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003606 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 mForcedAppOrientation = req;
3610 //send a message to Policy indicating orientation change to take
3611 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003612 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003613 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003614 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3615 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003616 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 }
3618 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003619
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003620 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 } finally {
3622 Binder.restoreCallingIdentity(ident);
3623 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 }
Romain Guy06882f82009-06-10 13:36:04 -07003625
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003626 int computeForcedAppOrientationLocked() {
3627 int req = getOrientationFromWindowsLocked();
3628 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3629 req = getOrientationFromAppTokensLocked();
3630 }
3631 return req;
3632 }
Romain Guy06882f82009-06-10 13:36:04 -07003633
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003634 public void setNewConfiguration(Configuration config) {
3635 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3636 "setNewConfiguration()")) {
3637 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3638 }
3639
3640 synchronized(mWindowMap) {
3641 mCurConfiguration = new Configuration(config);
3642 mWaitingForConfig = false;
3643 performLayoutAndPlaceSurfacesLocked();
3644 }
3645 }
3646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003647 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3648 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3649 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003650 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 }
Romain Guy06882f82009-06-10 13:36:04 -07003652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 synchronized(mWindowMap) {
3654 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3655 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003656 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 return;
3658 }
Romain Guy06882f82009-06-10 13:36:04 -07003659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 wtoken.requestedOrientation = requestedOrientation;
3661 }
3662 }
Romain Guy06882f82009-06-10 13:36:04 -07003663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 public int getAppOrientation(IApplicationToken token) {
3665 synchronized(mWindowMap) {
3666 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3667 if (wtoken == null) {
3668 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3669 }
Romain Guy06882f82009-06-10 13:36:04 -07003670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 return wtoken.requestedOrientation;
3672 }
3673 }
Romain Guy06882f82009-06-10 13:36:04 -07003674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3676 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3677 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003678 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 }
3680
3681 synchronized(mWindowMap) {
3682 boolean changed = false;
3683 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003684 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 changed = mFocusedApp != null;
3686 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003687 if (changed) {
3688 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 } else {
3691 AppWindowToken newFocus = findAppWindowToken(token);
3692 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003693 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 return;
3695 }
3696 changed = mFocusedApp != newFocus;
3697 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003698 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003699 if (changed) {
3700 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 }
3703
3704 if (moveFocusNow && changed) {
3705 final long origId = Binder.clearCallingIdentity();
3706 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3707 Binder.restoreCallingIdentity(origId);
3708 }
3709 }
3710 }
3711
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003712 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3714 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003715 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003716 }
Romain Guy06882f82009-06-10 13:36:04 -07003717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003719 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 TAG, "Prepare app transition: transit=" + transit
3721 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003722 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003723 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3724 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003726 } else if (!alwaysKeepCurrent) {
3727 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3728 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3729 // Opening a new task always supersedes a close for the anim.
3730 mNextAppTransition = transit;
3731 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3732 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3733 // Opening a new activity always supersedes a close for the anim.
3734 mNextAppTransition = transit;
3735 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 }
3737 mAppTransitionReady = false;
3738 mAppTransitionTimeout = false;
3739 mStartingIconInTransition = false;
3740 mSkipAppTransitionAnimation = false;
3741 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3742 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3743 5000);
3744 }
3745 }
3746 }
3747
3748 public int getPendingAppTransition() {
3749 return mNextAppTransition;
3750 }
Romain Guy06882f82009-06-10 13:36:04 -07003751
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003752 public void overridePendingAppTransition(String packageName,
3753 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003754 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003755 mNextAppTransitionPackage = packageName;
3756 mNextAppTransitionEnter = enterAnim;
3757 mNextAppTransitionExit = exitAnim;
3758 }
3759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 public void executeAppTransition() {
3762 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3763 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003764 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003765 }
Romain Guy06882f82009-06-10 13:36:04 -07003766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003768 if (DEBUG_APP_TRANSITIONS) {
3769 RuntimeException e = new RuntimeException("here");
3770 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003771 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003772 + mNextAppTransition, e);
3773 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003774 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 mAppTransitionReady = true;
3776 final long origId = Binder.clearCallingIdentity();
3777 performLayoutAndPlaceSurfacesLocked();
3778 Binder.restoreCallingIdentity(origId);
3779 }
3780 }
3781 }
3782
3783 public void setAppStartingWindow(IBinder token, String pkg,
3784 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003785 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3787 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003788 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003789 }
3790
3791 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003792 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3794 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 AppWindowToken wtoken = findAppWindowToken(token);
3797 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003798 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 return;
3800 }
3801
3802 // If the display is frozen, we won't do anything until the
3803 // actual window is displayed so there is no reason to put in
3804 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003805 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 return;
3807 }
Romain Guy06882f82009-06-10 13:36:04 -07003808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 if (wtoken.startingData != null) {
3810 return;
3811 }
Romain Guy06882f82009-06-10 13:36:04 -07003812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 if (transferFrom != null) {
3814 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3815 if (ttoken != null) {
3816 WindowState startingWindow = ttoken.startingWindow;
3817 if (startingWindow != null) {
3818 if (mStartingIconInTransition) {
3819 // In this case, the starting icon has already
3820 // been displayed, so start letting windows get
3821 // shown immediately without any more transitions.
3822 mSkipAppTransitionAnimation = true;
3823 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003824 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 "Moving existing starting from " + ttoken
3826 + " to " + wtoken);
3827 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 // Transfer the starting window over to the new
3830 // token.
3831 wtoken.startingData = ttoken.startingData;
3832 wtoken.startingView = ttoken.startingView;
3833 wtoken.startingWindow = startingWindow;
3834 ttoken.startingData = null;
3835 ttoken.startingView = null;
3836 ttoken.startingWindow = null;
3837 ttoken.startingMoved = true;
3838 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003839 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003841 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003842 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003844 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003845 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3846 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 ttoken.windows.remove(startingWindow);
3848 ttoken.allAppWindows.remove(startingWindow);
3849 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 // Propagate other interesting state between the
3852 // tokens. If the old token is displayed, we should
3853 // immediately force the new one to be displayed. If
3854 // it is animating, we need to move that animation to
3855 // the new one.
3856 if (ttoken.allDrawn) {
3857 wtoken.allDrawn = true;
3858 }
3859 if (ttoken.firstWindowDrawn) {
3860 wtoken.firstWindowDrawn = true;
3861 }
3862 if (!ttoken.hidden) {
3863 wtoken.hidden = false;
3864 wtoken.hiddenRequested = false;
3865 wtoken.willBeHidden = false;
3866 }
3867 if (wtoken.clientHidden != ttoken.clientHidden) {
3868 wtoken.clientHidden = ttoken.clientHidden;
3869 wtoken.sendAppVisibilityToClients();
3870 }
3871 if (ttoken.animation != null) {
3872 wtoken.animation = ttoken.animation;
3873 wtoken.animating = ttoken.animating;
3874 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3875 ttoken.animation = null;
3876 ttoken.animLayerAdjustment = 0;
3877 wtoken.updateLayers();
3878 ttoken.updateLayers();
3879 }
Romain Guy06882f82009-06-10 13:36:04 -07003880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003881 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 mLayoutNeeded = true;
3883 performLayoutAndPlaceSurfacesLocked();
3884 Binder.restoreCallingIdentity(origId);
3885 return;
3886 } else if (ttoken.startingData != null) {
3887 // The previous app was getting ready to show a
3888 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003889 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 "Moving pending starting from " + ttoken
3891 + " to " + wtoken);
3892 wtoken.startingData = ttoken.startingData;
3893 ttoken.startingData = null;
3894 ttoken.startingMoved = true;
3895 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3896 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3897 // want to process the message ASAP, before any other queued
3898 // messages.
3899 mH.sendMessageAtFrontOfQueue(m);
3900 return;
3901 }
3902 }
3903 }
3904
3905 // There is no existing starting window, and the caller doesn't
3906 // want us to create one, so that's it!
3907 if (!createIfNeeded) {
3908 return;
3909 }
Romain Guy06882f82009-06-10 13:36:04 -07003910
Dianne Hackborn284ac932009-08-28 10:34:25 -07003911 // If this is a translucent or wallpaper window, then don't
3912 // show a starting window -- the current effect (a full-screen
3913 // opaque starting window that fades away to the real contents
3914 // when it is ready) does not work for this.
3915 if (theme != 0) {
3916 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3917 com.android.internal.R.styleable.Window);
3918 if (ent.array.getBoolean(
3919 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3920 return;
3921 }
3922 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003923 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3924 return;
3925 }
3926 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003927 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3928 return;
3929 }
3930 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 mStartingIconInTransition = true;
3933 wtoken.startingData = new StartingData(
3934 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003935 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003936 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3937 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3938 // want to process the message ASAP, before any other queued
3939 // messages.
3940 mH.sendMessageAtFrontOfQueue(m);
3941 }
3942 }
3943
3944 public void setAppWillBeHidden(IBinder token) {
3945 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3946 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003947 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 }
3949
3950 AppWindowToken wtoken;
3951
3952 synchronized(mWindowMap) {
3953 wtoken = findAppWindowToken(token);
3954 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003955 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 -08003956 return;
3957 }
3958 wtoken.willBeHidden = true;
3959 }
3960 }
Romain Guy06882f82009-06-10 13:36:04 -07003961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3963 boolean visible, int transit, boolean performLayout) {
3964 boolean delayed = false;
3965
3966 if (wtoken.clientHidden == visible) {
3967 wtoken.clientHidden = !visible;
3968 wtoken.sendAppVisibilityToClients();
3969 }
Romain Guy06882f82009-06-10 13:36:04 -07003970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 wtoken.willBeHidden = false;
3972 if (wtoken.hidden == visible) {
3973 final int N = wtoken.allAppWindows.size();
3974 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003975 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3977 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003979 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003980
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003981 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 if (wtoken.animation == sDummyAnimation) {
3983 wtoken.animation = null;
3984 }
3985 applyAnimationLocked(wtoken, lp, transit, visible);
3986 changed = true;
3987 if (wtoken.animation != null) {
3988 delayed = runningAppAnimation = true;
3989 }
3990 }
Romain Guy06882f82009-06-10 13:36:04 -07003991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 for (int i=0; i<N; i++) {
3993 WindowState win = wtoken.allAppWindows.get(i);
3994 if (win == wtoken.startingWindow) {
3995 continue;
3996 }
3997
3998 if (win.isAnimating()) {
3999 delayed = true;
4000 }
Romain Guy06882f82009-06-10 13:36:04 -07004001
Joe Onorato8a9b2202010-02-26 18:56:32 -08004002 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 //win.dump(" ");
4004 if (visible) {
4005 if (!win.isVisibleNow()) {
4006 if (!runningAppAnimation) {
4007 applyAnimationLocked(win,
4008 WindowManagerPolicy.TRANSIT_ENTER, true);
4009 }
4010 changed = true;
4011 }
4012 } else if (win.isVisibleNow()) {
4013 if (!runningAppAnimation) {
4014 applyAnimationLocked(win,
4015 WindowManagerPolicy.TRANSIT_EXIT, false);
4016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004017 changed = true;
4018 }
4019 }
4020
4021 wtoken.hidden = wtoken.hiddenRequested = !visible;
4022 if (!visible) {
4023 unsetAppFreezingScreenLocked(wtoken, true, true);
4024 } else {
4025 // If we are being set visible, and the starting window is
4026 // not yet displayed, then make sure it doesn't get displayed.
4027 WindowState swin = wtoken.startingWindow;
4028 if (swin != null && (swin.mDrawPending
4029 || swin.mCommitDrawPending)) {
4030 swin.mPolicyVisibility = false;
4031 swin.mPolicyVisibilityAfterAnim = false;
4032 }
4033 }
Romain Guy06882f82009-06-10 13:36:04 -07004034
Joe Onorato8a9b2202010-02-26 18:56:32 -08004035 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004036 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4037 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004038
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004039 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004041 if (performLayout) {
4042 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
4043 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07004044 } else {
4045 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004047 }
4048 }
4049
4050 if (wtoken.animation != null) {
4051 delayed = true;
4052 }
Romain Guy06882f82009-06-10 13:36:04 -07004053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 return delayed;
4055 }
4056
4057 public void setAppVisibility(IBinder token, boolean visible) {
4058 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4059 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004060 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004061 }
4062
4063 AppWindowToken wtoken;
4064
4065 synchronized(mWindowMap) {
4066 wtoken = findAppWindowToken(token);
4067 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004068 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004069 return;
4070 }
4071
4072 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004073 RuntimeException e = null;
4074 if (!HIDE_STACK_CRAWLS) {
4075 e = new RuntimeException();
4076 e.fillInStackTrace();
4077 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004078 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004079 + "): mNextAppTransition=" + mNextAppTransition
4080 + " hidden=" + wtoken.hidden
4081 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4082 }
Romain Guy06882f82009-06-10 13:36:04 -07004083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 // If we are preparing an app transition, then delay changing
4085 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004086 if (!mDisplayFrozen && mPolicy.isScreenOn()
4087 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 // Already in requested state, don't do anything more.
4089 if (wtoken.hiddenRequested != visible) {
4090 return;
4091 }
4092 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004093
Joe Onorato8a9b2202010-02-26 18:56:32 -08004094 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004095 TAG, "Setting dummy animation on: " + wtoken);
4096 wtoken.setDummyAnimation();
4097 mOpeningApps.remove(wtoken);
4098 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004099 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 wtoken.inPendingTransaction = true;
4101 if (visible) {
4102 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004103 wtoken.startingDisplayed = false;
4104 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004105
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004106 // If the token is currently hidden (should be the
4107 // common case), then we need to set up to wait for
4108 // its windows to be ready.
4109 if (wtoken.hidden) {
4110 wtoken.allDrawn = false;
4111 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004112
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004113 if (wtoken.clientHidden) {
4114 // In the case where we are making an app visible
4115 // but holding off for a transition, we still need
4116 // to tell the client to make its windows visible so
4117 // they get drawn. Otherwise, we will wait on
4118 // performing the transition until all windows have
4119 // been drawn, they never will be, and we are sad.
4120 wtoken.clientHidden = false;
4121 wtoken.sendAppVisibilityToClients();
4122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 }
4124 } else {
4125 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004126
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004127 // If the token is currently visible (should be the
4128 // common case), then set up to wait for it to be hidden.
4129 if (!wtoken.hidden) {
4130 wtoken.waitingToHide = true;
4131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 }
4133 return;
4134 }
Romain Guy06882f82009-06-10 13:36:04 -07004135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004137 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004138 wtoken.updateReportedVisibilityLocked();
4139 Binder.restoreCallingIdentity(origId);
4140 }
4141 }
4142
4143 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4144 boolean unfreezeSurfaceNow, boolean force) {
4145 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004146 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147 + " force=" + force);
4148 final int N = wtoken.allAppWindows.size();
4149 boolean unfrozeWindows = false;
4150 for (int i=0; i<N; i++) {
4151 WindowState w = wtoken.allAppWindows.get(i);
4152 if (w.mAppFreezing) {
4153 w.mAppFreezing = false;
4154 if (w.mSurface != null && !w.mOrientationChanging) {
4155 w.mOrientationChanging = true;
4156 }
4157 unfrozeWindows = true;
4158 }
4159 }
4160 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004161 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162 wtoken.freezingScreen = false;
4163 mAppsFreezingScreen--;
4164 }
4165 if (unfreezeSurfaceNow) {
4166 if (unfrozeWindows) {
4167 mLayoutNeeded = true;
4168 performLayoutAndPlaceSurfacesLocked();
4169 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004170 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 }
4172 }
4173 }
Romain Guy06882f82009-06-10 13:36:04 -07004174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4176 int configChanges) {
4177 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004178 RuntimeException e = null;
4179 if (!HIDE_STACK_CRAWLS) {
4180 e = new RuntimeException();
4181 e.fillInStackTrace();
4182 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004183 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 + ": hidden=" + wtoken.hidden + " freezing="
4185 + wtoken.freezingScreen, e);
4186 }
4187 if (!wtoken.hiddenRequested) {
4188 if (!wtoken.freezingScreen) {
4189 wtoken.freezingScreen = true;
4190 mAppsFreezingScreen++;
4191 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004192 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4194 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4195 5000);
4196 }
4197 }
4198 final int N = wtoken.allAppWindows.size();
4199 for (int i=0; i<N; i++) {
4200 WindowState w = wtoken.allAppWindows.get(i);
4201 w.mAppFreezing = true;
4202 }
4203 }
4204 }
Romain Guy06882f82009-06-10 13:36:04 -07004205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004206 public void startAppFreezingScreen(IBinder token, int configChanges) {
4207 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4208 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004209 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 }
4211
4212 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004213 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004214 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 return;
4216 }
Romain Guy06882f82009-06-10 13:36:04 -07004217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 AppWindowToken wtoken = findAppWindowToken(token);
4219 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004220 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 return;
4222 }
4223 final long origId = Binder.clearCallingIdentity();
4224 startAppFreezingScreenLocked(wtoken, configChanges);
4225 Binder.restoreCallingIdentity(origId);
4226 }
4227 }
Romain Guy06882f82009-06-10 13:36:04 -07004228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 public void stopAppFreezingScreen(IBinder token, boolean force) {
4230 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4231 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004232 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004233 }
4234
4235 synchronized(mWindowMap) {
4236 AppWindowToken wtoken = findAppWindowToken(token);
4237 if (wtoken == null || wtoken.appToken == null) {
4238 return;
4239 }
4240 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004241 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004242 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4243 unsetAppFreezingScreenLocked(wtoken, true, force);
4244 Binder.restoreCallingIdentity(origId);
4245 }
4246 }
Romain Guy06882f82009-06-10 13:36:04 -07004247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 public void removeAppToken(IBinder token) {
4249 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4250 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004251 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 }
4253
4254 AppWindowToken wtoken = null;
4255 AppWindowToken startingToken = null;
4256 boolean delayed = false;
4257
4258 final long origId = Binder.clearCallingIdentity();
4259 synchronized(mWindowMap) {
4260 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004262 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004263 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004264 wtoken.inPendingTransaction = false;
4265 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004266 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 if (mClosingApps.contains(wtoken)) {
4268 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004269 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004270 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004271 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 delayed = true;
4273 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004274 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 TAG, "Removing app " + wtoken + " delayed=" + delayed
4276 + " animation=" + wtoken.animation
4277 + " animating=" + wtoken.animating);
4278 if (delayed) {
4279 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004280 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4281 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004283 } else {
4284 // Make sure there is no animation running on this token,
4285 // so any windows associated with it will be removed as
4286 // soon as their animations are complete
4287 wtoken.animation = null;
4288 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004290 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4291 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 mAppTokens.remove(wtoken);
4293 wtoken.removed = true;
4294 if (wtoken.startingData != null) {
4295 startingToken = wtoken;
4296 }
4297 unsetAppFreezingScreenLocked(wtoken, true, true);
4298 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004299 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 mFocusedApp = null;
4301 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004302 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 }
4304 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004305 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 }
Romain Guy06882f82009-06-10 13:36:04 -07004307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 if (!delayed && wtoken != null) {
4309 wtoken.updateReportedVisibilityLocked();
4310 }
4311 }
4312 Binder.restoreCallingIdentity(origId);
4313
4314 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004315 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 + startingToken + ": app token removed");
4317 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4318 mH.sendMessage(m);
4319 }
4320 }
4321
4322 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4323 final int NW = token.windows.size();
4324 for (int i=0; i<NW; i++) {
4325 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004326 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004328 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 int j = win.mChildWindows.size();
4330 while (j > 0) {
4331 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004332 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004333 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004334 "Tmp removing child window " + cwin);
4335 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004336 }
4337 }
4338 return NW > 0;
4339 }
4340
4341 void dumpAppTokensLocked() {
4342 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004343 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 }
4345 }
Romain Guy06882f82009-06-10 13:36:04 -07004346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 void dumpWindowsLocked() {
4348 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004349 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 }
4351 }
Romain Guy06882f82009-06-10 13:36:04 -07004352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004353 private int findWindowOffsetLocked(int tokenPos) {
4354 final int NW = mWindows.size();
4355
4356 if (tokenPos >= mAppTokens.size()) {
4357 int i = NW;
4358 while (i > 0) {
4359 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004360 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 if (win.getAppToken() != null) {
4362 return i+1;
4363 }
4364 }
4365 }
4366
4367 while (tokenPos > 0) {
4368 // Find the first app token below the new position that has
4369 // a window displayed.
4370 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004371 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004372 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004373 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004374 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004375 "Skipping token -- currently sending to bottom");
4376 tokenPos--;
4377 continue;
4378 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379 int i = wtoken.windows.size();
4380 while (i > 0) {
4381 i--;
4382 WindowState win = wtoken.windows.get(i);
4383 int j = win.mChildWindows.size();
4384 while (j > 0) {
4385 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004386 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004387 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004388 for (int pos=NW-1; pos>=0; pos--) {
4389 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004390 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004391 "Found child win @" + (pos+1));
4392 return pos+1;
4393 }
4394 }
4395 }
4396 }
4397 for (int pos=NW-1; pos>=0; pos--) {
4398 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004399 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004400 return pos+1;
4401 }
4402 }
4403 }
4404 tokenPos--;
4405 }
4406
4407 return 0;
4408 }
4409
4410 private final int reAddWindowLocked(int index, WindowState win) {
4411 final int NCW = win.mChildWindows.size();
4412 boolean added = false;
4413 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004414 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004416 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004417 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004418 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004419 mWindows.add(index, win);
4420 index++;
4421 added = true;
4422 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004423 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004424 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004425 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 mWindows.add(index, cwin);
4427 index++;
4428 }
4429 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004430 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004431 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004432 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 mWindows.add(index, win);
4434 index++;
4435 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004436 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 return index;
4438 }
Romain Guy06882f82009-06-10 13:36:04 -07004439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4441 final int NW = token.windows.size();
4442 for (int i=0; i<NW; i++) {
4443 index = reAddWindowLocked(index, token.windows.get(i));
4444 }
4445 return index;
4446 }
4447
4448 public void moveAppToken(int index, IBinder token) {
4449 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4450 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004451 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452 }
4453
4454 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004455 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 if (DEBUG_REORDER) dumpAppTokensLocked();
4457 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004458 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4459 "Start moving token " + wtoken + " initially at "
4460 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004462 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004463 + token + " (" + wtoken + ")");
4464 return;
4465 }
4466 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004467 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004468 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004472 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 if (DEBUG_REORDER) dumpWindowsLocked();
4474 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004475 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 if (DEBUG_REORDER) dumpWindowsLocked();
4477 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004478 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 if (DEBUG_REORDER) dumpWindowsLocked();
4480 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 mLayoutNeeded = true;
4482 performLayoutAndPlaceSurfacesLocked();
4483 }
4484 Binder.restoreCallingIdentity(origId);
4485 }
4486 }
4487
4488 private void removeAppTokensLocked(List<IBinder> tokens) {
4489 // XXX This should be done more efficiently!
4490 // (take advantage of the fact that both lists should be
4491 // ordered in the same way.)
4492 int N = tokens.size();
4493 for (int i=0; i<N; i++) {
4494 IBinder token = tokens.get(i);
4495 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004496 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4497 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004499 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004500 + token + " (" + wtoken + ")");
4501 i--;
4502 N--;
4503 }
4504 }
4505 }
4506
Dianne Hackborna8f60182009-09-01 19:01:50 -07004507 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4508 boolean updateFocusAndLayout) {
4509 // First remove all of the windows from the list.
4510 tmpRemoveAppWindowsLocked(wtoken);
4511
4512 // Where to start adding?
4513 int pos = findWindowOffsetLocked(tokenPos);
4514
4515 // And now add them back at the correct place.
4516 pos = reAddAppWindowsLocked(pos, wtoken);
4517
4518 if (updateFocusAndLayout) {
4519 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4520 assignLayersLocked();
4521 }
4522 mLayoutNeeded = true;
4523 performLayoutAndPlaceSurfacesLocked();
4524 }
4525 }
4526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4528 // First remove all of the windows from the list.
4529 final int N = tokens.size();
4530 int i;
4531 for (i=0; i<N; i++) {
4532 WindowToken token = mTokenMap.get(tokens.get(i));
4533 if (token != null) {
4534 tmpRemoveAppWindowsLocked(token);
4535 }
4536 }
4537
4538 // Where to start adding?
4539 int pos = findWindowOffsetLocked(tokenPos);
4540
4541 // And now add them back at the correct place.
4542 for (i=0; i<N; i++) {
4543 WindowToken token = mTokenMap.get(tokens.get(i));
4544 if (token != null) {
4545 pos = reAddAppWindowsLocked(pos, token);
4546 }
4547 }
4548
Dianne Hackborna8f60182009-09-01 19:01:50 -07004549 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4550 assignLayersLocked();
4551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004552 mLayoutNeeded = true;
4553 performLayoutAndPlaceSurfacesLocked();
4554
4555 //dump();
4556 }
4557
4558 public void moveAppTokensToTop(List<IBinder> tokens) {
4559 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4560 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004561 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004562 }
4563
4564 final long origId = Binder.clearCallingIdentity();
4565 synchronized(mWindowMap) {
4566 removeAppTokensLocked(tokens);
4567 final int N = tokens.size();
4568 for (int i=0; i<N; i++) {
4569 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4570 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004571 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4572 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004574 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004575 mToTopApps.remove(wt);
4576 mToBottomApps.remove(wt);
4577 mToTopApps.add(wt);
4578 wt.sendingToBottom = false;
4579 wt.sendingToTop = true;
4580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 }
4582 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004583
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004584 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004585 moveAppWindowsLocked(tokens, mAppTokens.size());
4586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004587 }
4588 Binder.restoreCallingIdentity(origId);
4589 }
4590
4591 public void moveAppTokensToBottom(List<IBinder> tokens) {
4592 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4593 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004594 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004595 }
4596
4597 final long origId = Binder.clearCallingIdentity();
4598 synchronized(mWindowMap) {
4599 removeAppTokensLocked(tokens);
4600 final int N = tokens.size();
4601 int pos = 0;
4602 for (int i=0; i<N; i++) {
4603 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4604 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004605 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4606 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004607 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004608 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004609 mToTopApps.remove(wt);
4610 mToBottomApps.remove(wt);
4611 mToBottomApps.add(i, wt);
4612 wt.sendingToTop = false;
4613 wt.sendingToBottom = true;
4614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004615 pos++;
4616 }
4617 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004618
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004619 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004620 moveAppWindowsLocked(tokens, 0);
4621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004622 }
4623 Binder.restoreCallingIdentity(origId);
4624 }
4625
4626 // -------------------------------------------------------------
4627 // Misc IWindowSession methods
4628 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004629
Jim Miller284b62e2010-06-08 14:27:42 -07004630 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004631 {
Jim Miller284b62e2010-06-08 14:27:42 -07004632 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4633 // called before DevicePolicyManagerService has started.
4634 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4635 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4636 Context.DEVICE_POLICY_SERVICE);
4637 if (dpm != null) {
4638 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4639 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4640 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4641 }
Jim Millerd6b57052010-06-07 17:52:42 -07004642 }
Jim Miller284b62e2010-06-08 14:27:42 -07004643 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004644 }
4645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004646 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004647 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004648 != PackageManager.PERMISSION_GRANTED) {
4649 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4650 }
Jim Millerd6b57052010-06-07 17:52:42 -07004651
Jim Miller284b62e2010-06-08 14:27:42 -07004652 synchronized (mKeyguardTokenWatcher) {
4653 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004655 }
4656
4657 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004658 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 != PackageManager.PERMISSION_GRANTED) {
4660 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662
Jim Miller284b62e2010-06-08 14:27:42 -07004663 synchronized (mKeyguardTokenWatcher) {
4664 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004665
Jim Miller284b62e2010-06-08 14:27:42 -07004666 if (!mKeyguardTokenWatcher.isAcquired()) {
4667 // If we are the last one to reenable the keyguard wait until
4668 // we have actually finished reenabling until returning.
4669 // It is possible that reenableKeyguard() can be called before
4670 // the previous disableKeyguard() is handled, in which case
4671 // neither mKeyguardTokenWatcher.acquired() or released() would
4672 // be called. In that case mKeyguardDisabled will be false here
4673 // and we have nothing to wait for.
4674 while (mKeyguardDisabled) {
4675 try {
4676 mKeyguardTokenWatcher.wait();
4677 } catch (InterruptedException e) {
4678 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679 }
4680 }
4681 }
4682 }
4683 }
4684
4685 /**
4686 * @see android.app.KeyguardManager#exitKeyguardSecurely
4687 */
4688 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004689 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004690 != PackageManager.PERMISSION_GRANTED) {
4691 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4692 }
4693 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4694 public void onKeyguardExitResult(boolean success) {
4695 try {
4696 callback.onKeyguardExitResult(success);
4697 } catch (RemoteException e) {
4698 // Client has died, we don't care.
4699 }
4700 }
4701 });
4702 }
4703
4704 public boolean inKeyguardRestrictedInputMode() {
4705 return mPolicy.inKeyguardRestrictedKeyInputMode();
4706 }
Romain Guy06882f82009-06-10 13:36:04 -07004707
Dianne Hackbornffa42482009-09-23 22:20:11 -07004708 public void closeSystemDialogs(String reason) {
4709 synchronized(mWindowMap) {
4710 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004711 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004712 if (w.mSurface != null) {
4713 try {
4714 w.mClient.closeSystemDialogs(reason);
4715 } catch (RemoteException e) {
4716 }
4717 }
4718 }
4719 }
4720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 static float fixScale(float scale) {
4723 if (scale < 0) scale = 0;
4724 else if (scale > 20) scale = 20;
4725 return Math.abs(scale);
4726 }
Romain Guy06882f82009-06-10 13:36:04 -07004727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004728 public void setAnimationScale(int which, float scale) {
4729 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4730 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004731 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 }
4733
4734 if (scale < 0) scale = 0;
4735 else if (scale > 20) scale = 20;
4736 scale = Math.abs(scale);
4737 switch (which) {
4738 case 0: mWindowAnimationScale = fixScale(scale); break;
4739 case 1: mTransitionAnimationScale = fixScale(scale); break;
4740 }
Romain Guy06882f82009-06-10 13:36:04 -07004741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004742 // Persist setting
4743 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4744 }
Romain Guy06882f82009-06-10 13:36:04 -07004745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004746 public void setAnimationScales(float[] scales) {
4747 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4748 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004749 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004750 }
4751
4752 if (scales != null) {
4753 if (scales.length >= 1) {
4754 mWindowAnimationScale = fixScale(scales[0]);
4755 }
4756 if (scales.length >= 2) {
4757 mTransitionAnimationScale = fixScale(scales[1]);
4758 }
4759 }
Romain Guy06882f82009-06-10 13:36:04 -07004760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004761 // Persist setting
4762 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4763 }
Romain Guy06882f82009-06-10 13:36:04 -07004764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004765 public float getAnimationScale(int which) {
4766 switch (which) {
4767 case 0: return mWindowAnimationScale;
4768 case 1: return mTransitionAnimationScale;
4769 }
4770 return 0;
4771 }
Romain Guy06882f82009-06-10 13:36:04 -07004772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004773 public float[] getAnimationScales() {
4774 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4775 }
Romain Guy06882f82009-06-10 13:36:04 -07004776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004777 public int getSwitchState(int sw) {
4778 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4779 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004780 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004781 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004782 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 }
Romain Guy06882f82009-06-10 13:36:04 -07004784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004785 public int getSwitchStateForDevice(int devid, int sw) {
4786 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4787 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004788 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004790 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004791 }
Romain Guy06882f82009-06-10 13:36:04 -07004792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004793 public int getScancodeState(int sw) {
4794 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4795 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004796 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004798 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 }
Romain Guy06882f82009-06-10 13:36:04 -07004800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 public int getScancodeStateForDevice(int devid, int sw) {
4802 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4803 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004804 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004806 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 }
Romain Guy06882f82009-06-10 13:36:04 -07004808
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004809 public int getTrackballScancodeState(int sw) {
4810 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4811 "getTrackballScancodeState()")) {
4812 throw new SecurityException("Requires READ_INPUT_STATE permission");
4813 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004814 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004815 }
4816
4817 public int getDPadScancodeState(int sw) {
4818 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4819 "getDPadScancodeState()")) {
4820 throw new SecurityException("Requires READ_INPUT_STATE permission");
4821 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004822 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004823 }
4824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 public int getKeycodeState(int sw) {
4826 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4827 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004828 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004830 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 }
Romain Guy06882f82009-06-10 13:36:04 -07004832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004833 public int getKeycodeStateForDevice(int devid, int sw) {
4834 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4835 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004836 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004838 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 }
Romain Guy06882f82009-06-10 13:36:04 -07004840
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004841 public int getTrackballKeycodeState(int sw) {
4842 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4843 "getTrackballKeycodeState()")) {
4844 throw new SecurityException("Requires READ_INPUT_STATE permission");
4845 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004846 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004847 }
4848
4849 public int getDPadKeycodeState(int sw) {
4850 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4851 "getDPadKeycodeState()")) {
4852 throw new SecurityException("Requires READ_INPUT_STATE permission");
4853 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004854 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004855 }
Jeff Browna41ca772010-08-11 14:46:32 -07004856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004857 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004858 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859 }
Romain Guy06882f82009-06-10 13:36:04 -07004860
Jeff Browna41ca772010-08-11 14:46:32 -07004861 public InputChannel monitorInput(String inputChannelName) {
4862 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4863 "monitorInput()")) {
4864 throw new SecurityException("Requires READ_INPUT_STATE permission");
4865 }
4866 return mInputManager.monitorInput(inputChannelName);
4867 }
4868
Jeff Brown8d608662010-08-30 03:02:23 -07004869 public InputDevice getInputDevice(int deviceId) {
4870 return mInputManager.getInputDevice(deviceId);
4871 }
4872
4873 public int[] getInputDeviceIds() {
4874 return mInputManager.getInputDeviceIds();
4875 }
4876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004877 public void enableScreenAfterBoot() {
4878 synchronized(mWindowMap) {
4879 if (mSystemBooted) {
4880 return;
4881 }
4882 mSystemBooted = true;
4883 }
Romain Guy06882f82009-06-10 13:36:04 -07004884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004885 performEnableScreen();
4886 }
Romain Guy06882f82009-06-10 13:36:04 -07004887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004888 public void enableScreenIfNeededLocked() {
4889 if (mDisplayEnabled) {
4890 return;
4891 }
4892 if (!mSystemBooted) {
4893 return;
4894 }
4895 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4896 }
Romain Guy06882f82009-06-10 13:36:04 -07004897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004898 public void performEnableScreen() {
4899 synchronized(mWindowMap) {
4900 if (mDisplayEnabled) {
4901 return;
4902 }
4903 if (!mSystemBooted) {
4904 return;
4905 }
Romain Guy06882f82009-06-10 13:36:04 -07004906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004907 // Don't enable the screen until all existing windows
4908 // have been drawn.
4909 final int N = mWindows.size();
4910 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004911 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004912 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 return;
4914 }
4915 }
Romain Guy06882f82009-06-10 13:36:04 -07004916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 mDisplayEnabled = true;
4918 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004919 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 StringWriter sw = new StringWriter();
4921 PrintWriter pw = new PrintWriter(sw);
4922 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004923 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004924 }
4925 try {
4926 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4927 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004928 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929 Parcel data = Parcel.obtain();
4930 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4931 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4932 data, null, 0);
4933 data.recycle();
4934 }
4935 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004936 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 }
4938 }
Romain Guy06882f82009-06-10 13:36:04 -07004939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004940 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004943 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4944 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 }
Romain Guy06882f82009-06-10 13:36:04 -07004946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 public void setInTouchMode(boolean mode) {
4948 synchronized(mWindowMap) {
4949 mInTouchMode = mode;
4950 }
4951 }
4952
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004953 // TODO: more accounting of which pid(s) turned it on, keep count,
4954 // only allow disables from pids which have count on, etc.
4955 public void showStrictModeViolation(boolean on) {
4956 int pid = Binder.getCallingPid();
4957 synchronized(mWindowMap) {
4958 // Ignoring requests to enable the red border from clients
4959 // which aren't on screen. (e.g. Broadcast Receivers in
4960 // the background..)
4961 if (on) {
4962 boolean isVisible = false;
4963 for (WindowState ws : mWindows) {
4964 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4965 isVisible = true;
4966 break;
4967 }
4968 }
4969 if (!isVisible) {
4970 return;
4971 }
4972 }
4973
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004974 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004975 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004976 try {
4977 if (mStrictModeFlash == null) {
4978 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4979 }
4980 mStrictModeFlash.setVisibility(on);
4981 } finally {
4982 Surface.closeTransaction();
4983 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004984 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004985 }
4986 }
4987
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004988 public void setStrictModeVisualIndicatorPreference(String value) {
4989 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4990 }
4991
Dianne Hackbornd2835932010-12-13 16:28:46 -08004992 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004993 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4994 "screenshotApplications()")) {
4995 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
4996 }
4997
4998 Bitmap rawss;
4999
Dianne Hackbornd2835932010-12-13 16:28:46 -08005000 int maxLayer = 0;
5001 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005002 final Rect frame = new Rect();
5003
5004 float scale;
5005 int sw, sh, dw, dh;
5006 int rot;
5007
5008 synchronized(mWindowMap) {
5009 long ident = Binder.clearCallingIdentity();
5010
5011 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5012 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5013 + TYPE_LAYER_OFFSET;
5014 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5015
5016 // Figure out the part of the screen that is actually the app.
5017 for (int i=0; i<mWindows.size(); i++) {
5018 WindowState ws = mWindows.get(i);
5019 if (ws.mSurface == null) {
5020 continue;
5021 }
5022 if (ws.mLayer >= aboveAppLayer) {
5023 break;
5024 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005025 if (appToken != null && (ws.mAppToken == null
5026 || ws.mAppToken.token != appToken)) {
5027 continue;
5028 }
5029 if (maxLayer < ws.mAnimLayer) {
5030 maxLayer = ws.mAnimLayer;
5031 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005032 final Rect wf = ws.mFrame;
5033 final Rect cr = ws.mContentInsets;
5034 int left = wf.left + cr.left;
5035 int top = wf.top + cr.top;
5036 int right = wf.right - cr.right;
5037 int bottom = wf.bottom - cr.bottom;
5038 frame.union(left, top, right, bottom);
5039 }
5040 Binder.restoreCallingIdentity(ident);
5041
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005042 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005043 return null;
5044 }
5045
5046 // The screenshot API does not apply the current screen rotation.
5047 rot = mDisplay.getRotation();
5048 int fw = frame.width();
5049 int fh = frame.height();
5050
5051 // First try reducing to fit in x dimension.
5052 scale = maxWidth/(float)fw;
5053 sw = maxWidth;
5054 sh = (int)(fh*scale);
5055 if (sh > maxHeight) {
5056 // y dimension became too long; constrain by that.
5057 scale = maxHeight/(float)fh;
5058 sw = (int)(fw*scale);
5059 sh = maxHeight;
5060 }
5061
5062 // The screen shot will contain the entire screen.
5063 dw = (int)(mDisplay.getWidth()*scale);
5064 dh = (int)(mDisplay.getHeight()*scale);
5065 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5066 int tmp = dw;
5067 dw = dh;
5068 dh = tmp;
5069 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5070 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005071 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005072 }
5073
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005074 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005075 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5076 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005077 return null;
5078 }
5079
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005080 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5081 Matrix matrix = new Matrix();
5082 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5083 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5084 Canvas canvas = new Canvas(bm);
5085 canvas.drawBitmap(rawss, matrix, null);
5086
5087 rawss.recycle();
5088 return bm;
5089 }
5090
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005091 public void freezeRotation() {
5092 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5093 "setRotation()")) {
5094 throw new SecurityException("Requires SET_ORIENTATION permission");
5095 }
5096
5097 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5098 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5099 }
5100
5101 public void thawRotation() {
5102 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5103 "setRotation()")) {
5104 throw new SecurityException("Requires SET_ORIENTATION permission");
5105 }
5106
5107 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5108 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5109 }
5110
Romain Guy06882f82009-06-10 13:36:04 -07005111 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005112 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005113 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005114 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005115 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005116 }
5117
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005118 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005119 }
Romain Guy06882f82009-06-10 13:36:04 -07005120
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005121 public void setRotationUnchecked(int rotation,
5122 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005123 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005126 long origId = Binder.clearCallingIdentity();
5127 boolean changed;
5128 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005129 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005130 }
Romain Guy06882f82009-06-10 13:36:04 -07005131
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005132 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005133 sendNewConfiguration();
5134 }
Romain Guy06882f82009-06-10 13:36:04 -07005135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 Binder.restoreCallingIdentity(origId);
5137 }
Romain Guy06882f82009-06-10 13:36:04 -07005138
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005139 /**
5140 * Apply a new rotation to the screen, respecting the requests of
5141 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5142 * re-evaluate the desired rotation.
5143 *
5144 * Returns null if the rotation has been changed. In this case YOU
5145 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5146 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005147 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005148 if (mDragState != null) {
5149 // Potential rotation during a drag. Don't do the rotation now, but make
5150 // a note to perform the rotation later.
5151 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation during drag");
5152 mDragState.setDeferredRotation(rotation, animFlags);
5153 return false;
5154 }
5155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005156 boolean changed;
5157 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5158 rotation = mRequestedRotation;
5159 } else {
5160 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005161 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005162 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005163 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005164 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005165 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005166 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005167 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005169 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005170 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005171 "Rotation changed to " + rotation
5172 + " from " + mRotation
5173 + " (forceApp=" + mForcedAppOrientation
5174 + ", req=" + mRequestedRotation + ")");
5175 mRotation = rotation;
5176 mWindowsFreezingScreen = true;
5177 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5178 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5179 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005180 mWaitingForConfig = true;
5181 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005182 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005183 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005184 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005185 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005186 if (CUSTOM_SCREEN_ROTATION) {
5187 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005188 if (!inTransaction) {
5189 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5190 ">>> OPEN TRANSACTION setRotationUnchecked");
5191 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005192 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005193 try {
5194 if (mScreenRotationAnimation != null) {
5195 mScreenRotationAnimation.setRotation(rotation);
5196 }
5197 } finally {
5198 if (!inTransaction) {
5199 Surface.closeTransaction();
5200 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5201 "<<< CLOSE TRANSACTION setRotationUnchecked");
5202 }
5203 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005204 Surface.setOrientation(0, rotation, animFlags);
5205 Surface.unfreezeDisplay(0);
5206 } else {
5207 Surface.setOrientation(0, rotation, animFlags);
5208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005209 }
5210 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005211 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005212 if (w.mSurface != null) {
5213 w.mOrientationChanging = true;
5214 }
5215 }
5216 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5217 try {
5218 mRotationWatchers.get(i).onRotationChanged(rotation);
5219 } catch (RemoteException e) {
5220 }
5221 }
5222 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 return changed;
5225 }
Romain Guy06882f82009-06-10 13:36:04 -07005226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005227 public int getRotation() {
5228 return mRotation;
5229 }
5230
5231 public int watchRotation(IRotationWatcher watcher) {
5232 final IBinder watcherBinder = watcher.asBinder();
5233 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5234 public void binderDied() {
5235 synchronized (mWindowMap) {
5236 for (int i=0; i<mRotationWatchers.size(); i++) {
5237 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005238 IRotationWatcher removed = mRotationWatchers.remove(i);
5239 if (removed != null) {
5240 removed.asBinder().unlinkToDeath(this, 0);
5241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005242 i--;
5243 }
5244 }
5245 }
5246 }
5247 };
Romain Guy06882f82009-06-10 13:36:04 -07005248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005249 synchronized (mWindowMap) {
5250 try {
5251 watcher.asBinder().linkToDeath(dr, 0);
5252 mRotationWatchers.add(watcher);
5253 } catch (RemoteException e) {
5254 // Client died, no cleanup needed.
5255 }
Romain Guy06882f82009-06-10 13:36:04 -07005256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005257 return mRotation;
5258 }
5259 }
5260
5261 /**
5262 * Starts the view server on the specified port.
5263 *
5264 * @param port The port to listener to.
5265 *
5266 * @return True if the server was successfully started, false otherwise.
5267 *
5268 * @see com.android.server.ViewServer
5269 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5270 */
5271 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005272 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005273 return false;
5274 }
5275
5276 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5277 return false;
5278 }
5279
5280 if (port < 1024) {
5281 return false;
5282 }
5283
5284 if (mViewServer != null) {
5285 if (!mViewServer.isRunning()) {
5286 try {
5287 return mViewServer.start();
5288 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005289 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005290 }
5291 }
5292 return false;
5293 }
5294
5295 try {
5296 mViewServer = new ViewServer(this, port);
5297 return mViewServer.start();
5298 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005299 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005300 }
5301 return false;
5302 }
5303
Romain Guy06882f82009-06-10 13:36:04 -07005304 private boolean isSystemSecure() {
5305 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5306 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5307 }
5308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005309 /**
5310 * Stops the view server if it exists.
5311 *
5312 * @return True if the server stopped, false if it wasn't started or
5313 * couldn't be stopped.
5314 *
5315 * @see com.android.server.ViewServer
5316 */
5317 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005318 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005319 return false;
5320 }
5321
5322 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5323 return false;
5324 }
5325
5326 if (mViewServer != null) {
5327 return mViewServer.stop();
5328 }
5329 return false;
5330 }
5331
5332 /**
5333 * Indicates whether the view server is running.
5334 *
5335 * @return True if the server is running, false otherwise.
5336 *
5337 * @see com.android.server.ViewServer
5338 */
5339 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005340 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005341 return false;
5342 }
5343
5344 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5345 return false;
5346 }
5347
5348 return mViewServer != null && mViewServer.isRunning();
5349 }
5350
5351 /**
5352 * Lists all availble windows in the system. The listing is written in the
5353 * specified Socket's output stream with the following syntax:
5354 * windowHashCodeInHexadecimal windowName
5355 * Each line of the ouput represents a different window.
5356 *
5357 * @param client The remote client to send the listing to.
5358 * @return False if an error occured, true otherwise.
5359 */
5360 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005361 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362 return false;
5363 }
5364
5365 boolean result = true;
5366
Jeff Browne33348b2010-07-15 23:54:05 -07005367 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005368 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005369 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005370 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005371 }
5372
5373 BufferedWriter out = null;
5374
5375 // Any uncaught exception will crash the system process
5376 try {
5377 OutputStream clientStream = client.getOutputStream();
5378 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5379
5380 final int count = windows.length;
5381 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005382 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005383 out.write(Integer.toHexString(System.identityHashCode(w)));
5384 out.write(' ');
5385 out.append(w.mAttrs.getTitle());
5386 out.write('\n');
5387 }
5388
5389 out.write("DONE.\n");
5390 out.flush();
5391 } catch (Exception e) {
5392 result = false;
5393 } finally {
5394 if (out != null) {
5395 try {
5396 out.close();
5397 } catch (IOException e) {
5398 result = false;
5399 }
5400 }
5401 }
5402
5403 return result;
5404 }
5405
5406 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005407 * Returns the focused window in the following format:
5408 * windowHashCodeInHexadecimal windowName
5409 *
5410 * @param client The remote client to send the listing to.
5411 * @return False if an error occurred, true otherwise.
5412 */
5413 boolean viewServerGetFocusedWindow(Socket client) {
5414 if (isSystemSecure()) {
5415 return false;
5416 }
5417
5418 boolean result = true;
5419
5420 WindowState focusedWindow = getFocusedWindow();
5421
5422 BufferedWriter out = null;
5423
5424 // Any uncaught exception will crash the system process
5425 try {
5426 OutputStream clientStream = client.getOutputStream();
5427 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5428
5429 if(focusedWindow != null) {
5430 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5431 out.write(' ');
5432 out.append(focusedWindow.mAttrs.getTitle());
5433 }
5434 out.write('\n');
5435 out.flush();
5436 } catch (Exception e) {
5437 result = false;
5438 } finally {
5439 if (out != null) {
5440 try {
5441 out.close();
5442 } catch (IOException e) {
5443 result = false;
5444 }
5445 }
5446 }
5447
5448 return result;
5449 }
5450
5451 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005452 * Sends a command to a target window. The result of the command, if any, will be
5453 * written in the output stream of the specified socket.
5454 *
5455 * The parameters must follow this syntax:
5456 * windowHashcode extra
5457 *
5458 * Where XX is the length in characeters of the windowTitle.
5459 *
5460 * The first parameter is the target window. The window with the specified hashcode
5461 * will be the target. If no target can be found, nothing happens. The extra parameters
5462 * will be delivered to the target window and as parameters to the command itself.
5463 *
5464 * @param client The remote client to sent the result, if any, to.
5465 * @param command The command to execute.
5466 * @param parameters The command parameters.
5467 *
5468 * @return True if the command was successfully delivered, false otherwise. This does
5469 * not indicate whether the command itself was successful.
5470 */
5471 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005472 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005473 return false;
5474 }
5475
5476 boolean success = true;
5477 Parcel data = null;
5478 Parcel reply = null;
5479
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005480 BufferedWriter out = null;
5481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005482 // Any uncaught exception will crash the system process
5483 try {
5484 // Find the hashcode of the window
5485 int index = parameters.indexOf(' ');
5486 if (index == -1) {
5487 index = parameters.length();
5488 }
5489 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005490 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005491
5492 // Extract the command's parameter after the window description
5493 if (index < parameters.length()) {
5494 parameters = parameters.substring(index + 1);
5495 } else {
5496 parameters = "";
5497 }
5498
5499 final WindowManagerService.WindowState window = findWindow(hashCode);
5500 if (window == null) {
5501 return false;
5502 }
5503
5504 data = Parcel.obtain();
5505 data.writeInterfaceToken("android.view.IWindow");
5506 data.writeString(command);
5507 data.writeString(parameters);
5508 data.writeInt(1);
5509 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5510
5511 reply = Parcel.obtain();
5512
5513 final IBinder binder = window.mClient.asBinder();
5514 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5515 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5516
5517 reply.readException();
5518
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005519 if (!client.isOutputShutdown()) {
5520 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5521 out.write("DONE\n");
5522 out.flush();
5523 }
5524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005525 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005526 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005527 success = false;
5528 } finally {
5529 if (data != null) {
5530 data.recycle();
5531 }
5532 if (reply != null) {
5533 reply.recycle();
5534 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005535 if (out != null) {
5536 try {
5537 out.close();
5538 } catch (IOException e) {
5539
5540 }
5541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005542 }
5543
5544 return success;
5545 }
5546
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005547 public void addWindowChangeListener(WindowChangeListener listener) {
5548 synchronized(mWindowMap) {
5549 mWindowChangeListeners.add(listener);
5550 }
5551 }
5552
5553 public void removeWindowChangeListener(WindowChangeListener listener) {
5554 synchronized(mWindowMap) {
5555 mWindowChangeListeners.remove(listener);
5556 }
5557 }
5558
5559 private void notifyWindowsChanged() {
5560 WindowChangeListener[] windowChangeListeners;
5561 synchronized(mWindowMap) {
5562 if(mWindowChangeListeners.isEmpty()) {
5563 return;
5564 }
5565 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5566 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5567 }
5568 int N = windowChangeListeners.length;
5569 for(int i = 0; i < N; i++) {
5570 windowChangeListeners[i].windowsChanged();
5571 }
5572 }
5573
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005574 private void notifyFocusChanged() {
5575 WindowChangeListener[] windowChangeListeners;
5576 synchronized(mWindowMap) {
5577 if(mWindowChangeListeners.isEmpty()) {
5578 return;
5579 }
5580 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5581 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5582 }
5583 int N = windowChangeListeners.length;
5584 for(int i = 0; i < N; i++) {
5585 windowChangeListeners[i].focusChanged();
5586 }
5587 }
5588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005589 private WindowState findWindow(int hashCode) {
5590 if (hashCode == -1) {
5591 return getFocusedWindow();
5592 }
5593
5594 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005595 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005596 final int count = windows.size();
5597
5598 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005599 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005600 if (System.identityHashCode(w) == hashCode) {
5601 return w;
5602 }
5603 }
5604 }
5605
5606 return null;
5607 }
5608
5609 /*
5610 * Instruct the Activity Manager to fetch the current configuration and broadcast
5611 * that to config-changed listeners if appropriate.
5612 */
5613 void sendNewConfiguration() {
5614 try {
5615 mActivityManager.updateConfiguration(null);
5616 } catch (RemoteException e) {
5617 }
5618 }
Romain Guy06882f82009-06-10 13:36:04 -07005619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005620 public Configuration computeNewConfiguration() {
5621 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005622 Configuration config = computeNewConfigurationLocked();
5623 if (config == null && mWaitingForConfig) {
5624 // Nothing changed but we are waiting for something... stop that!
5625 mWaitingForConfig = false;
5626 performLayoutAndPlaceSurfacesLocked();
5627 }
5628 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005629 }
5630 }
Romain Guy06882f82009-06-10 13:36:04 -07005631
Dianne Hackbornc485a602009-03-24 22:39:49 -07005632 Configuration computeNewConfigurationLocked() {
5633 Configuration config = new Configuration();
5634 if (!computeNewConfigurationLocked(config)) {
5635 return null;
5636 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005637 return config;
5638 }
Romain Guy06882f82009-06-10 13:36:04 -07005639
Dianne Hackbornc485a602009-03-24 22:39:49 -07005640 boolean computeNewConfigurationLocked(Configuration config) {
5641 if (mDisplay == null) {
5642 return false;
5643 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005644
5645 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005646
5647 // Use the effective "visual" dimensions based on current rotation
5648 final boolean rotated = (mRotation == Surface.ROTATION_90
5649 || mRotation == Surface.ROTATION_270);
5650 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5651 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5652
Dianne Hackbornc485a602009-03-24 22:39:49 -07005653 int orientation = Configuration.ORIENTATION_SQUARE;
5654 if (dw < dh) {
5655 orientation = Configuration.ORIENTATION_PORTRAIT;
5656 } else if (dw > dh) {
5657 orientation = Configuration.ORIENTATION_LANDSCAPE;
5658 }
5659 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005660
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005661 DisplayMetrics dm = new DisplayMetrics();
5662 mDisplay.getMetrics(dm);
5663 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5664
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005665 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005666 // Note we only do this once because at this point we don't
5667 // expect the screen to change in this way at runtime, and want
5668 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005669 int longSize = dw;
5670 int shortSize = dh;
5671 if (longSize < shortSize) {
5672 int tmp = longSize;
5673 longSize = shortSize;
5674 shortSize = tmp;
5675 }
5676 longSize = (int)(longSize/dm.density);
5677 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005678
Dianne Hackborn723738c2009-06-25 19:48:04 -07005679 // These semi-magic numbers define our compatibility modes for
5680 // applications with different screens. Don't change unless you
5681 // make sure to test lots and lots of apps!
5682 if (longSize < 470) {
5683 // This is shorter than an HVGA normal density screen (which
5684 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005685 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5686 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005687 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005688 // What size is this screen screen?
5689 if (longSize >= 800 && shortSize >= 600) {
5690 // SVGA or larger screens at medium density are the point
5691 // at which we consider it to be an extra large screen.
5692 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005693 } else if (longSize >= 530 && shortSize >= 400) {
5694 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005695 // at which we consider it to be a large screen.
5696 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5697 } else {
5698 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005699
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005700 // If this screen is wider than normal HVGA, or taller
5701 // than FWVGA, then for old apps we want to run in size
5702 // compatibility mode.
5703 if (shortSize > 321 || longSize > 570) {
5704 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5705 }
5706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005707
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005708 // Is this a long screen?
5709 if (((longSize*3)/5) >= (shortSize-1)) {
5710 // Anything wider than WVGA (5:3) is considering to be long.
5711 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5712 } else {
5713 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5714 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005715 }
5716 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005717 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005718
Dianne Hackbornc485a602009-03-24 22:39:49 -07005719 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5720 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5721 mPolicy.adjustConfigurationLw(config);
5722 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005723 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005724
5725 // -------------------------------------------------------------
5726 // Drag and drop
5727 // -------------------------------------------------------------
5728
5729 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005730 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005731 if (DEBUG_DRAG) {
5732 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005733 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005734 + " asbinder=" + window.asBinder());
5735 }
5736
5737 final int callerPid = Binder.getCallingPid();
5738 final long origId = Binder.clearCallingIdentity();
5739 IBinder token = null;
5740
5741 try {
5742 synchronized (mWindowMap) {
5743 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005744 if (mDragState == null) {
5745 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5746 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5747 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005748 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005749 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005750 // TODO: preserve flags param in DragState
5751 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005752 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005753 token = mDragState.mToken = new Binder();
5754
5755 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005756 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5757 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005758 mH.sendMessageDelayed(msg, 5000);
5759 } else {
5760 Slog.w(TAG, "Drag already in progress");
5761 }
5762 } catch (Surface.OutOfResourcesException e) {
5763 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5764 if (mDragState != null) {
5765 mDragState.reset();
5766 mDragState = null;
5767 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005768 }
5769 }
5770 } finally {
5771 Binder.restoreCallingIdentity(origId);
5772 }
5773
5774 return token;
5775 }
5776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005777 // -------------------------------------------------------------
5778 // Input Events and Focus Management
5779 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005780
Jeff Brown349703e2010-06-22 01:27:15 -07005781 InputMonitor mInputMonitor = new InputMonitor();
5782
5783 /* Tracks the progress of input dispatch and ensures that input dispatch state
5784 * is kept in sync with changes in window focus, visibility, registration, and
5785 * other relevant Window Manager state transitions. */
5786 final class InputMonitor {
5787 // Current window with input focus for keys and other non-touch events. May be null.
5788 private WindowState mInputFocus;
5789
5790 // When true, prevents input dispatch from proceeding until set to false again.
5791 private boolean mInputDispatchFrozen;
5792
5793 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5794 private boolean mInputDispatchEnabled = true;
5795
5796 // Temporary list of windows information to provide to the input dispatcher.
5797 private InputWindowList mTempInputWindows = new InputWindowList();
5798
5799 // Temporary input application object to provide to the input dispatcher.
5800 private InputApplication mTempInputApplication = new InputApplication();
5801
Jeff Brownb09abc12011-01-13 21:08:27 -08005802 // Set to true when the first input device configuration change notification
5803 // is received to indicate that the input devices are ready.
5804 private final Object mInputDevicesReadyMonitor = new Object();
5805 private boolean mInputDevicesReady;
5806
Jeff Brown349703e2010-06-22 01:27:15 -07005807 /* Notifies the window manager about a broken input channel.
5808 *
5809 * Called by the InputManager.
5810 */
Jeff Brown928e0542011-01-10 11:17:36 -08005811 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5812 if (inputWindowHandle == null) {
5813 return;
5814 }
5815
Jeff Brown349703e2010-06-22 01:27:15 -07005816 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005817 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005818 Slog.i(TAG, "WINDOW DIED " + windowState);
5819 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005820 }
5821 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005822
Jeff Brown519e0242010-09-15 15:18:56 -07005823 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005824 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005825 *
5826 * Called by the InputManager.
5827 */
Jeff Brown928e0542011-01-10 11:17:36 -08005828 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5829 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005830 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005831 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005832 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005833 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005834 if (windowState != null) {
5835 Slog.i(TAG, "Input event dispatching timed out sending to "
5836 + windowState.mAttrs.getTitle());
5837 appWindowToken = windowState.mAppToken;
5838 }
Jeff Brown349703e2010-06-22 01:27:15 -07005839 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005840 }
5841
Jeff Brown928e0542011-01-10 11:17:36 -08005842 if (appWindowToken == null && inputApplicationHandle != null) {
5843 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005844 Slog.i(TAG, "Input event dispatching timed out sending to application "
5845 + appWindowToken.stringName);
5846 }
Jeff Brown349703e2010-06-22 01:27:15 -07005847
Jeff Brown519e0242010-09-15 15:18:56 -07005848 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005849 try {
5850 // Notify the activity manager about the timeout and let it decide whether
5851 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005852 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005853 if (! abort) {
5854 // The activity manager declined to abort dispatching.
5855 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005856 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005857 }
Jeff Brown349703e2010-06-22 01:27:15 -07005858 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005859 }
5860 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005861 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005862 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005863
Chris Tatea32dcf72010-10-14 12:13:50 -07005864 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005865 final InputWindow inputWindow = windowList.add();
5866 inputWindow.inputChannel = mDragState.mServerChannel;
5867 inputWindow.name = "drag";
Jeff Brownfbf09772011-01-16 14:06:57 -08005868 inputWindow.layoutParamsFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Christopher Tatea53146c2010-09-07 11:57:52 -07005869 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5870 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5871 inputWindow.visible = true;
5872 inputWindow.canReceiveKeys = false;
5873 inputWindow.hasFocus = true;
5874 inputWindow.hasWallpaper = false;
5875 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005876 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005877 inputWindow.ownerPid = Process.myPid();
5878 inputWindow.ownerUid = Process.myUid();
5879
5880 // The drag window covers the entire display
5881 inputWindow.frameLeft = 0;
5882 inputWindow.frameTop = 0;
5883 inputWindow.frameRight = mDisplay.getWidth();
5884 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005885
Jeff Brownfbf09772011-01-16 14:06:57 -08005886 // The drag window cannot receive new touches.
5887 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07005888 }
5889
Jeff Brown349703e2010-06-22 01:27:15 -07005890 /* Updates the cached window information provided to the input dispatcher. */
5891 public void updateInputWindowsLw() {
5892 // Populate the input window list with information about all of the windows that
5893 // could potentially receive input.
5894 // As an optimization, we could try to prune the list of windows but this turns
5895 // out to be difficult because only the native code knows for sure which window
5896 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005897 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005898
5899 // If there's a drag in flight, provide a pseudowindow to catch drag input
5900 final boolean inDrag = (mDragState != null);
5901 if (inDrag) {
5902 if (DEBUG_DRAG) {
5903 Log.d(TAG, "Inserting drag window");
5904 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005905 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005906 }
5907
Jeff Brown7fbdc842010-06-17 20:52:56 -07005908 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005909 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005910 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005911 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005912 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005913 continue;
5914 }
5915
Jeff Brown349703e2010-06-22 01:27:15 -07005916 final int flags = child.mAttrs.flags;
5917 final int type = child.mAttrs.type;
5918
5919 final boolean hasFocus = (child == mInputFocus);
5920 final boolean isVisible = child.isVisibleLw();
5921 final boolean hasWallpaper = (child == mWallpaperTarget)
5922 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005923
5924 // If there's a drag in progress and 'child' is a potential drop target,
5925 // make sure it's been told about the drag
5926 if (inDrag && isVisible) {
5927 mDragState.sendDragStartedIfNeededLw(child);
5928 }
5929
Jeff Brown349703e2010-06-22 01:27:15 -07005930 // Add a window to our list of input windows.
5931 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005932 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005933 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005934 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005935 inputWindow.layoutParamsFlags = flags;
5936 inputWindow.layoutParamsType = type;
5937 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5938 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005939 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005940 inputWindow.hasFocus = hasFocus;
5941 inputWindow.hasWallpaper = hasWallpaper;
5942 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005943 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005944 inputWindow.ownerPid = child.mSession.mPid;
5945 inputWindow.ownerUid = child.mSession.mUid;
5946
5947 final Rect frame = child.mFrame;
5948 inputWindow.frameLeft = frame.left;
5949 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005950 inputWindow.frameRight = frame.right;
5951 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08005952
5953 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005954 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005955
Jeff Brown349703e2010-06-22 01:27:15 -07005956 // Send windows to native code.
5957 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005958
Jeff Brown349703e2010-06-22 01:27:15 -07005959 // Clear the list in preparation for the next round.
5960 // Also avoids keeping InputChannel objects referenced unnecessarily.
5961 mTempInputWindows.clear();
5962 }
Jeff Brownb09abc12011-01-13 21:08:27 -08005963
5964 /* Notifies that the input device configuration has changed. */
5965 public void notifyConfigurationChanged() {
5966 sendNewConfiguration();
5967
5968 synchronized (mInputDevicesReadyMonitor) {
5969 if (!mInputDevicesReady) {
5970 mInputDevicesReady = true;
5971 mInputDevicesReadyMonitor.notifyAll();
5972 }
5973 }
5974 }
5975
5976 /* Waits until the built-in input devices have been configured. */
5977 public boolean waitForInputDevicesReady(long timeoutMillis) {
5978 synchronized (mInputDevicesReadyMonitor) {
5979 if (!mInputDevicesReady) {
5980 try {
5981 mInputDevicesReadyMonitor.wait(timeoutMillis);
5982 } catch (InterruptedException ex) {
5983 }
5984 }
5985 return mInputDevicesReady;
5986 }
5987 }
5988
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005989 /* Notifies that the lid switch changed state. */
5990 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5991 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5992 }
5993
Jeff Brown349703e2010-06-22 01:27:15 -07005994 /* Provides an opportunity for the window manager policy to intercept early key
5995 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08005996 public int interceptKeyBeforeQueueing(
5997 KeyEvent event, int policyFlags, boolean isScreenOn) {
5998 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005999 }
6000
6001 /* Provides an opportunity for the window manager policy to process a key before
6002 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006003 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006004 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006005 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006006 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006007 }
6008
Jeff Brown3915bb82010-11-05 15:02:16 -07006009 /* Provides an opportunity for the window manager policy to process a key that
6010 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006011 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006012 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006013 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006014 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006015 }
6016
Jeff Brown349703e2010-06-22 01:27:15 -07006017 /* Called when the current input focus changes.
6018 * Layer assignment is assumed to be complete by the time this is called.
6019 */
6020 public void setInputFocusLw(WindowState newWindow) {
6021 if (DEBUG_INPUT) {
6022 Slog.d(TAG, "Input focus has changed to " + newWindow);
6023 }
6024
6025 if (newWindow != mInputFocus) {
6026 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006027 // Displaying a window implicitly causes dispatching to be unpaused.
6028 // This is to protect against bugs if someone pauses dispatching but
6029 // forgets to resume.
6030 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006031 }
Jeff Brown349703e2010-06-22 01:27:15 -07006032
6033 mInputFocus = newWindow;
6034 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006035 }
6036 }
6037
Jeff Brown349703e2010-06-22 01:27:15 -07006038 public void setFocusedAppLw(AppWindowToken newApp) {
6039 // Focused app has changed.
6040 if (newApp == null) {
6041 mInputManager.setFocusedApplication(null);
6042 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006043 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006044 mTempInputApplication.name = newApp.toString();
6045 mTempInputApplication.dispatchingTimeoutNanos =
6046 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006047
Jeff Brown349703e2010-06-22 01:27:15 -07006048 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006049
6050 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006051 }
6052 }
6053
Jeff Brown349703e2010-06-22 01:27:15 -07006054 public void pauseDispatchingLw(WindowToken window) {
6055 if (! window.paused) {
6056 if (DEBUG_INPUT) {
6057 Slog.v(TAG, "Pausing WindowToken " + window);
6058 }
6059
6060 window.paused = true;
6061 updateInputWindowsLw();
6062 }
6063 }
6064
6065 public void resumeDispatchingLw(WindowToken window) {
6066 if (window.paused) {
6067 if (DEBUG_INPUT) {
6068 Slog.v(TAG, "Resuming WindowToken " + window);
6069 }
6070
6071 window.paused = false;
6072 updateInputWindowsLw();
6073 }
6074 }
6075
6076 public void freezeInputDispatchingLw() {
6077 if (! mInputDispatchFrozen) {
6078 if (DEBUG_INPUT) {
6079 Slog.v(TAG, "Freezing input dispatching");
6080 }
6081
6082 mInputDispatchFrozen = true;
6083 updateInputDispatchModeLw();
6084 }
6085 }
6086
6087 public void thawInputDispatchingLw() {
6088 if (mInputDispatchFrozen) {
6089 if (DEBUG_INPUT) {
6090 Slog.v(TAG, "Thawing input dispatching");
6091 }
6092
6093 mInputDispatchFrozen = false;
6094 updateInputDispatchModeLw();
6095 }
6096 }
6097
6098 public void setEventDispatchingLw(boolean enabled) {
6099 if (mInputDispatchEnabled != enabled) {
6100 if (DEBUG_INPUT) {
6101 Slog.v(TAG, "Setting event dispatching to " + enabled);
6102 }
6103
6104 mInputDispatchEnabled = enabled;
6105 updateInputDispatchModeLw();
6106 }
6107 }
6108
6109 private void updateInputDispatchModeLw() {
6110 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6111 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006114 public void pauseKeyDispatching(IBinder _token) {
6115 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6116 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006117 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 }
6119
6120 synchronized (mWindowMap) {
6121 WindowToken token = mTokenMap.get(_token);
6122 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006123 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006124 }
6125 }
6126 }
6127
6128 public void resumeKeyDispatching(IBinder _token) {
6129 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6130 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006131 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132 }
6133
6134 synchronized (mWindowMap) {
6135 WindowToken token = mTokenMap.get(_token);
6136 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006137 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 }
6139 }
6140 }
6141
6142 public void setEventDispatching(boolean enabled) {
6143 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6144 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006145 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 }
6147
6148 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006149 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 }
6151 }
Romain Guy06882f82009-06-10 13:36:04 -07006152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 /**
6154 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006155 * Even when sync is false, this method may block while waiting for current
6156 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006157 *
6158 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006159 * {@link SystemClock#uptimeMillis()} as the timebase.)
6160 * @param sync If true, wait for the event to be completed before returning to the caller.
6161 * @return Returns true if event was dispatched, false if it was dropped for any reason
6162 */
6163 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6164 long downTime = ev.getDownTime();
6165 long eventTime = ev.getEventTime();
6166
6167 int action = ev.getAction();
6168 int code = ev.getKeyCode();
6169 int repeatCount = ev.getRepeatCount();
6170 int metaState = ev.getMetaState();
6171 int deviceId = ev.getDeviceId();
6172 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006173 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006174 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006175
6176 if (source == InputDevice.SOURCE_UNKNOWN) {
6177 source = InputDevice.SOURCE_KEYBOARD;
6178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006179
6180 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6181 if (downTime == 0) downTime = eventTime;
6182
6183 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006184 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006185
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006186 final int pid = Binder.getCallingPid();
6187 final int uid = Binder.getCallingUid();
6188 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006189
Jeff Brownbbda99d2010-07-28 15:48:59 -07006190 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6191 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6192 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6193 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006194
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006195 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006196 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006197 }
6198
6199 /**
6200 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006201 * Even when sync is false, this method may block while waiting for current
6202 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006203 *
6204 * @param ev A motion event describing the pointer (touch) action. (As noted in
6205 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 * {@link SystemClock#uptimeMillis()} as the timebase.)
6207 * @param sync If true, wait for the event to be completed before returning to the caller.
6208 * @return Returns true if event was dispatched, false if it was dropped for any reason
6209 */
6210 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006211 final int pid = Binder.getCallingPid();
6212 final int uid = Binder.getCallingUid();
6213 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006214
Jeff Brownc5ed5912010-07-14 18:48:53 -07006215 MotionEvent newEvent = MotionEvent.obtain(ev);
6216 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6217 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6218 }
6219
Jeff Brownbbda99d2010-07-28 15:48:59 -07006220 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6221 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6222 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6223 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006224
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006225 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006226 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006227 }
Romain Guy06882f82009-06-10 13:36:04 -07006228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 /**
6230 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006231 * Even when sync is false, this method may block while waiting for current
6232 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006233 *
6234 * @param ev A motion event describing the trackball action. (As noted in
6235 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006236 * {@link SystemClock#uptimeMillis()} as the timebase.)
6237 * @param sync If true, wait for the event to be completed before returning to the caller.
6238 * @return Returns true if event was dispatched, false if it was dropped for any reason
6239 */
6240 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006241 final int pid = Binder.getCallingPid();
6242 final int uid = Binder.getCallingUid();
6243 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006244
Jeff Brownc5ed5912010-07-14 18:48:53 -07006245 MotionEvent newEvent = MotionEvent.obtain(ev);
6246 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6247 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6248 }
6249
Jeff Brownbbda99d2010-07-28 15:48:59 -07006250 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6251 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6252 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6253 INJECTION_TIMEOUT_MILLIS);
6254
6255 Binder.restoreCallingIdentity(ident);
6256 return reportInjectionResult(result);
6257 }
6258
6259 /**
6260 * Inject an input event into the UI without waiting for dispatch to commence.
6261 * This variant is useful for fire-and-forget input event injection. It does not
6262 * block any longer than it takes to enqueue the input event.
6263 *
6264 * @param ev An input event. (Be sure to set the input source correctly.)
6265 * @return Returns true if event was dispatched, false if it was dropped for any reason
6266 */
6267 public boolean injectInputEventNoWait(InputEvent ev) {
6268 final int pid = Binder.getCallingPid();
6269 final int uid = Binder.getCallingUid();
6270 final long ident = Binder.clearCallingIdentity();
6271
6272 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6273 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6274 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006275
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006276 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006277 return reportInjectionResult(result);
6278 }
6279
6280 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006281 switch (result) {
6282 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6283 Slog.w(TAG, "Input event injection permission denied.");
6284 throw new SecurityException(
6285 "Injecting to another application requires INJECT_EVENTS permission");
6286 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006287 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006288 return true;
6289 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6290 Slog.w(TAG, "Input event injection timed out.");
6291 return false;
6292 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6293 default:
6294 Slog.w(TAG, "Input event injection failed.");
6295 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 }
Romain Guy06882f82009-06-10 13:36:04 -07006298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006299 private WindowState getFocusedWindow() {
6300 synchronized (mWindowMap) {
6301 return getFocusedWindowLocked();
6302 }
6303 }
6304
6305 private WindowState getFocusedWindowLocked() {
6306 return mCurrentFocus;
6307 }
Romain Guy06882f82009-06-10 13:36:04 -07006308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006309 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006310 if (!mInputMonitor.waitForInputDevicesReady(
6311 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6312 Slog.w(TAG, "Devices still not ready after waiting "
6313 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6314 + " milliseconds before attempting to detect safe mode.");
6315 }
6316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006317 mSafeMode = mPolicy.detectSafeMode();
6318 return mSafeMode;
6319 }
Romain Guy06882f82009-06-10 13:36:04 -07006320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006321 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006322 synchronized(mWindowMap) {
6323 if (mDisplay != null) {
6324 throw new IllegalStateException("Display already initialized");
6325 }
6326 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6327 mDisplay = wm.getDefaultDisplay();
6328 mInitialDisplayWidth = mDisplay.getWidth();
6329 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006330 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6331 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006332 }
6333
6334 try {
6335 mActivityManager.updateConfiguration(null);
6336 } catch (RemoteException e) {
6337 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006338
6339 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006340 }
6341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 // -------------------------------------------------------------
6343 // Client Session State
6344 // -------------------------------------------------------------
6345
6346 private final class Session extends IWindowSession.Stub
6347 implements IBinder.DeathRecipient {
6348 final IInputMethodClient mClient;
6349 final IInputContext mInputContext;
6350 final int mUid;
6351 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006352 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006353 SurfaceSession mSurfaceSession;
6354 int mNumWindow = 0;
6355 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006357 public Session(IInputMethodClient client, IInputContext inputContext) {
6358 mClient = client;
6359 mInputContext = inputContext;
6360 mUid = Binder.getCallingUid();
6361 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006362 StringBuilder sb = new StringBuilder();
6363 sb.append("Session{");
6364 sb.append(Integer.toHexString(System.identityHashCode(this)));
6365 sb.append(" uid ");
6366 sb.append(mUid);
6367 sb.append("}");
6368 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 synchronized (mWindowMap) {
6371 if (mInputMethodManager == null && mHaveInputMethods) {
6372 IBinder b = ServiceManager.getService(
6373 Context.INPUT_METHOD_SERVICE);
6374 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6375 }
6376 }
6377 long ident = Binder.clearCallingIdentity();
6378 try {
6379 // Note: it is safe to call in to the input method manager
6380 // here because we are not holding our lock.
6381 if (mInputMethodManager != null) {
6382 mInputMethodManager.addClient(client, inputContext,
6383 mUid, mPid);
6384 } else {
6385 client.setUsingInputMethod(false);
6386 }
6387 client.asBinder().linkToDeath(this, 0);
6388 } catch (RemoteException e) {
6389 // The caller has died, so we can just forget about this.
6390 try {
6391 if (mInputMethodManager != null) {
6392 mInputMethodManager.removeClient(client);
6393 }
6394 } catch (RemoteException ee) {
6395 }
6396 } finally {
6397 Binder.restoreCallingIdentity(ident);
6398 }
6399 }
Romain Guy06882f82009-06-10 13:36:04 -07006400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 @Override
6402 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6403 throws RemoteException {
6404 try {
6405 return super.onTransact(code, data, reply, flags);
6406 } catch (RuntimeException e) {
6407 // Log all 'real' exceptions thrown to the caller
6408 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006409 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006410 }
6411 throw e;
6412 }
6413 }
6414
6415 public void binderDied() {
6416 // Note: it is safe to call in to the input method manager
6417 // here because we are not holding our lock.
6418 try {
6419 if (mInputMethodManager != null) {
6420 mInputMethodManager.removeClient(mClient);
6421 }
6422 } catch (RemoteException e) {
6423 }
6424 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006425 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006426 mClientDead = true;
6427 killSessionLocked();
6428 }
6429 }
6430
6431 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006432 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6433 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6434 outInputChannel);
6435 }
6436
6437 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006439 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 }
Romain Guy06882f82009-06-10 13:36:04 -07006441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 public void remove(IWindow window) {
6443 removeWindow(this, window);
6444 }
Romain Guy06882f82009-06-10 13:36:04 -07006445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006446 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6447 int requestedWidth, int requestedHeight, int viewFlags,
6448 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006449 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006450 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6451 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006452 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006453 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006454 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6455 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 }
Romain Guy06882f82009-06-10 13:36:04 -07006457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458 public void setTransparentRegion(IWindow window, Region region) {
6459 setTransparentRegionWindow(this, window, region);
6460 }
Romain Guy06882f82009-06-10 13:36:04 -07006461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006463 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006464 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006465 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 }
Romain Guy06882f82009-06-10 13:36:04 -07006467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006468 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6469 getWindowDisplayFrame(this, window, outDisplayFrame);
6470 }
Romain Guy06882f82009-06-10 13:36:04 -07006471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006473 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 TAG, "IWindow finishDrawing called for " + window);
6475 finishDrawingWindow(this, window);
6476 }
6477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006478 public void setInTouchMode(boolean mode) {
6479 synchronized(mWindowMap) {
6480 mInTouchMode = mode;
6481 }
6482 }
6483
6484 public boolean getInTouchMode() {
6485 synchronized(mWindowMap) {
6486 return mInTouchMode;
6487 }
6488 }
6489
6490 public boolean performHapticFeedback(IWindow window, int effectId,
6491 boolean always) {
6492 synchronized(mWindowMap) {
6493 long ident = Binder.clearCallingIdentity();
6494 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006495 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006496 windowForClientLocked(this, window, true),
6497 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 } finally {
6499 Binder.restoreCallingIdentity(ident);
6500 }
6501 }
6502 }
Romain Guy06882f82009-06-10 13:36:04 -07006503
Christopher Tatea53146c2010-09-07 11:57:52 -07006504 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006505 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006506 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006507 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006508 width, height, outSurface);
6509 }
6510
6511 public boolean performDrag(IWindow window, IBinder dragToken,
6512 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6513 ClipData data) {
6514 if (DEBUG_DRAG) {
6515 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6516 }
6517
6518 synchronized (mWindowMap) {
6519 if (mDragState == null) {
6520 Slog.w(TAG, "No drag prepared");
6521 throw new IllegalStateException("performDrag() without prepareDrag()");
6522 }
6523
6524 if (dragToken != mDragState.mToken) {
6525 Slog.w(TAG, "Performing mismatched drag");
6526 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6527 }
6528
6529 WindowState callingWin = windowForClientLocked(null, window, false);
6530 if (callingWin == null) {
6531 Slog.w(TAG, "Bad requesting window " + window);
6532 return false; // !!! TODO: throw here?
6533 }
6534
6535 // !!! TODO: if input is not still focused on the initiating window, fail
6536 // the drag initiation (e.g. an alarm window popped up just as the application
6537 // called performDrag()
6538
6539 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6540
Christopher Tate2c095f32010-10-04 14:13:40 -07006541 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6542 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006543
Chris Tateb478f462010-10-15 16:02:26 -07006544 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6545 // the actual drag event dispatch stuff in the dragstate
6546
Christopher Tatea53146c2010-09-07 11:57:52 -07006547 mDragState.register();
6548 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006549 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6550 mDragState.mServerChannel)) {
6551 Slog.e(TAG, "Unable to transfer touch focus");
6552 mDragState.unregister();
6553 mDragState = null;
6554 mInputMonitor.updateInputWindowsLw();
6555 return false;
6556 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006557
6558 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006559 mDragState.mCurrentX = touchX;
6560 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006561 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006562
6563 // remember the thumb offsets for later
6564 mDragState.mThumbOffsetX = thumbCenterX;
6565 mDragState.mThumbOffsetY = thumbCenterY;
6566
6567 // Make the surface visible at the proper location
6568 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006569 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006570 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006571 try {
6572 surface.setPosition((int)(touchX - thumbCenterX),
6573 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006574 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006575 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006576 surface.show();
6577 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006578 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006579 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006580 }
6581 }
6582
6583 return true; // success!
6584 }
6585
Chris Tated4533f142010-10-19 15:15:08 -07006586 public void reportDropResult(IWindow window, boolean consumed) {
6587 IBinder token = window.asBinder();
6588 if (DEBUG_DRAG) {
6589 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6590 }
6591
6592 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006593 long ident = Binder.clearCallingIdentity();
6594 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006595 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006596 Slog.w(TAG, "Invalid drop-result claim by " + window);
6597 throw new IllegalStateException("reportDropResult() by non-recipient");
6598 }
6599
6600 // The right window has responded, even if it's no longer around,
6601 // so be sure to halt the timeout even if the later WindowState
6602 // lookup fails.
6603 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6604 WindowState callingWin = windowForClientLocked(null, window, false);
6605 if (callingWin == null) {
6606 Slog.w(TAG, "Bad result-reporting window " + window);
6607 return; // !!! TODO: throw here?
6608 }
6609
6610 mDragState.mDragResult = consumed;
6611 mDragState.endDragLw();
6612 } finally {
6613 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006614 }
Chris Tated4533f142010-10-19 15:15:08 -07006615 }
6616 }
6617
Christopher Tatea53146c2010-09-07 11:57:52 -07006618 public void dragRecipientEntered(IWindow window) {
6619 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006620 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006621 }
6622 }
6623
6624 public void dragRecipientExited(IWindow window) {
6625 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006626 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006627 }
6628 }
6629
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006630 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006631 synchronized(mWindowMap) {
6632 long ident = Binder.clearCallingIdentity();
6633 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006634 setWindowWallpaperPositionLocked(
6635 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006636 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006637 } finally {
6638 Binder.restoreCallingIdentity(ident);
6639 }
6640 }
6641 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006642
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006643 public void wallpaperOffsetsComplete(IBinder window) {
6644 WindowManagerService.this.wallpaperOffsetsComplete(window);
6645 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006646
Dianne Hackborn75804932009-10-20 20:15:20 -07006647 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6648 int z, Bundle extras, boolean sync) {
6649 synchronized(mWindowMap) {
6650 long ident = Binder.clearCallingIdentity();
6651 try {
6652 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006653 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006654 action, x, y, z, extras, sync);
6655 } finally {
6656 Binder.restoreCallingIdentity(ident);
6657 }
6658 }
6659 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006660
Dianne Hackborn75804932009-10-20 20:15:20 -07006661 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6662 WindowManagerService.this.wallpaperCommandComplete(window, result);
6663 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006665 void windowAddedLocked() {
6666 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006667 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006668 TAG, "First window added to " + this + ", creating SurfaceSession");
6669 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006670 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006671 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006672 mSessions.add(this);
6673 }
6674 mNumWindow++;
6675 }
6676
6677 void windowRemovedLocked() {
6678 mNumWindow--;
6679 killSessionLocked();
6680 }
Romain Guy06882f82009-06-10 13:36:04 -07006681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006682 void killSessionLocked() {
6683 if (mNumWindow <= 0 && mClientDead) {
6684 mSessions.remove(this);
6685 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006686 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006687 TAG, "Last window removed from " + this
6688 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006689 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006690 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006691 try {
6692 mSurfaceSession.kill();
6693 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006694 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006695 + mSurfaceSession + " in session " + this
6696 + ": " + e.toString());
6697 }
6698 mSurfaceSession = null;
6699 }
6700 }
6701 }
Romain Guy06882f82009-06-10 13:36:04 -07006702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006704 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6705 pw.print(" mClientDead="); pw.print(mClientDead);
6706 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006707 }
6708
6709 @Override
6710 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006711 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 }
6713 }
6714
6715 // -------------------------------------------------------------
6716 // Client Window State
6717 // -------------------------------------------------------------
6718
6719 private final class WindowState implements WindowManagerPolicy.WindowState {
6720 final Session mSession;
6721 final IWindow mClient;
6722 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006723 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006724 AppWindowToken mAppToken;
6725 AppWindowToken mTargetAppToken;
6726 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6727 final DeathRecipient mDeathRecipient;
6728 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006729 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006730 final int mBaseLayer;
6731 final int mSubLayer;
6732 final boolean mLayoutAttached;
6733 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006734 final boolean mIsWallpaper;
6735 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006736 int mViewVisibility;
6737 boolean mPolicyVisibility = true;
6738 boolean mPolicyVisibilityAfterAnim = true;
6739 boolean mAppFreezing;
6740 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006741 boolean mReportDestroySurface;
6742 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006743 boolean mAttachedHidden; // is our parent window hidden?
6744 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006745 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006746 int mRequestedWidth;
6747 int mRequestedHeight;
6748 int mLastRequestedWidth;
6749 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 int mLayer;
6751 int mAnimLayer;
6752 int mLastLayer;
6753 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006754 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006755 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006756
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006757 int mLayoutSeq = -1;
6758
6759 Configuration mConfiguration = null;
6760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006761 // Actual frame shown on-screen (may be modified by animation)
6762 final Rect mShownFrame = new Rect();
6763 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006766 * Set when we have changed the size of the surface, to know that
6767 * we must tell them application to resize (and thus redraw itself).
6768 */
6769 boolean mSurfaceResized;
6770
6771 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 * Insets that determine the actually visible area
6773 */
6774 final Rect mVisibleInsets = new Rect();
6775 final Rect mLastVisibleInsets = new Rect();
6776 boolean mVisibleInsetsChanged;
6777
6778 /**
6779 * Insets that are covered by system windows
6780 */
6781 final Rect mContentInsets = new Rect();
6782 final Rect mLastContentInsets = new Rect();
6783 boolean mContentInsetsChanged;
6784
6785 /**
6786 * Set to true if we are waiting for this window to receive its
6787 * given internal insets before laying out other windows based on it.
6788 */
6789 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 /**
6792 * These are the content insets that were given during layout for
6793 * this window, to be applied to windows behind it.
6794 */
6795 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 /**
6798 * These are the visible insets that were given during layout for
6799 * this window, to be applied to windows behind it.
6800 */
6801 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006804 * This is the given touchable area relative to the window frame, or null if none.
6805 */
6806 final Region mGivenTouchableRegion = new Region();
6807
6808 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006809 * Flag indicating whether the touchable region should be adjusted by
6810 * the visible insets; if false the area outside the visible insets is
6811 * NOT touchable, so we must use those to adjust the frame during hit
6812 * tests.
6813 */
6814 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006816 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006817 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6819 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6820 float mHScale=1, mVScale=1;
6821 float mLastHScale=1, mLastVScale=1;
6822 final Matrix mTmpMatrix = new Matrix();
6823
6824 // "Real" frame that the application sees.
6825 final Rect mFrame = new Rect();
6826 final Rect mLastFrame = new Rect();
6827
6828 final Rect mContainingFrame = new Rect();
6829 final Rect mDisplayFrame = new Rect();
6830 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006831 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006832 final Rect mVisibleFrame = new Rect();
6833
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006834 boolean mContentChanged;
6835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 float mShownAlpha = 1;
6837 float mAlpha = 1;
6838 float mLastAlpha = 1;
6839
6840 // Set to true if, when the window gets displayed, it should perform
6841 // an enter animation.
6842 boolean mEnterAnimationPending;
6843
6844 // Currently running animation.
6845 boolean mAnimating;
6846 boolean mLocalAnimating;
6847 Animation mAnimation;
6848 boolean mAnimationIsEntrance;
6849 boolean mHasTransformation;
6850 boolean mHasLocalTransformation;
6851 final Transformation mTransformation = new Transformation();
6852
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006853 // If a window showing a wallpaper: the requested offset for the
6854 // wallpaper; if a wallpaper window: the currently applied offset.
6855 float mWallpaperX = -1;
6856 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006857
6858 // If a window showing a wallpaper: what fraction of the offset
6859 // range corresponds to a full virtual screen.
6860 float mWallpaperXStep = -1;
6861 float mWallpaperYStep = -1;
6862
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006863 // Wallpaper windows: pixels offset based on above variables.
6864 int mXOffset;
6865 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 // This is set after IWindowSession.relayout() has been called at
6868 // least once for the window. It allows us to detect the situation
6869 // where we don't yet have a surface, but should have one soon, so
6870 // we can give the window focus before waiting for the relayout.
6871 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006873 // This is set after the Surface has been created but before the
6874 // window has been drawn. During this time the surface is hidden.
6875 boolean mDrawPending;
6876
6877 // This is set after the window has finished drawing for the first
6878 // time but before its surface is shown. The surface will be
6879 // displayed when the next layout is run.
6880 boolean mCommitDrawPending;
6881
6882 // This is set during the time after the window's drawing has been
6883 // committed, and before its surface is actually shown. It is used
6884 // to delay showing the surface until all windows in a token are ready
6885 // to be shown.
6886 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006888 // Set when the window has been shown in the screen the first time.
6889 boolean mHasDrawn;
6890
6891 // Currently running an exit animation?
6892 boolean mExiting;
6893
6894 // Currently on the mDestroySurface list?
6895 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 // Completely remove from window manager after exit animation?
6898 boolean mRemoveOnExit;
6899
6900 // Set when the orientation is changing and this window has not yet
6901 // been updated for the new orientation.
6902 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006904 // Is this window now (or just being) removed?
6905 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006906
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006907 // Temp for keeping track of windows that have been removed when
6908 // rebuilding window list.
6909 boolean mRebuilding;
6910
Dianne Hackborn16064f92010-03-25 00:47:24 -07006911 // For debugging, this is the last information given to the surface flinger.
6912 boolean mSurfaceShown;
6913 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6914 int mSurfaceLayer;
6915 float mSurfaceAlpha;
6916
Jeff Brown928e0542011-01-10 11:17:36 -08006917 // Input channel and input window handle used by the input dispatcher.
6918 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006919 InputChannel mInputChannel;
6920
Mattias Petersson1622eee2010-12-21 10:15:11 +01006921 // Used to improve performance of toString()
6922 String mStringNameCache;
6923 CharSequence mLastTitle;
6924 boolean mWasPaused;
6925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006926 WindowState(Session s, IWindow c, WindowToken token,
6927 WindowState attachedWindow, WindowManager.LayoutParams a,
6928 int viewVisibility) {
6929 mSession = s;
6930 mClient = c;
6931 mToken = token;
6932 mAttrs.copyFrom(a);
6933 mViewVisibility = viewVisibility;
6934 DeathRecipient deathRecipient = new DeathRecipient();
6935 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006936 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006937 TAG, "Window " + this + " client=" + c.asBinder()
6938 + " token=" + token + " (" + mAttrs.token + ")");
6939 try {
6940 c.asBinder().linkToDeath(deathRecipient, 0);
6941 } catch (RemoteException e) {
6942 mDeathRecipient = null;
6943 mAttachedWindow = null;
6944 mLayoutAttached = false;
6945 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006946 mIsWallpaper = false;
6947 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 mBaseLayer = 0;
6949 mSubLayer = 0;
6950 return;
6951 }
6952 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006954 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6955 mAttrs.type <= LAST_SUB_WINDOW)) {
6956 // The multiplier here is to reserve space for multiple
6957 // windows in the same type layer.
6958 mBaseLayer = mPolicy.windowTypeToLayerLw(
6959 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6960 + TYPE_LAYER_OFFSET;
6961 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6962 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006963 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 mAttachedWindow.mChildWindows.add(this);
6965 mLayoutAttached = mAttrs.type !=
6966 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6967 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6968 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006969 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6970 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006971 } else {
6972 // The multiplier here is to reserve space for multiple
6973 // windows in the same type layer.
6974 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6975 * TYPE_LAYER_MULTIPLIER
6976 + TYPE_LAYER_OFFSET;
6977 mSubLayer = 0;
6978 mAttachedWindow = null;
6979 mLayoutAttached = false;
6980 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6981 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006982 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6983 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006984 }
6985
6986 WindowState appWin = this;
6987 while (appWin.mAttachedWindow != null) {
6988 appWin = mAttachedWindow;
6989 }
6990 WindowToken appToken = appWin.mToken;
6991 while (appToken.appWindowToken == null) {
6992 WindowToken parent = mTokenMap.get(appToken.token);
6993 if (parent == null || appToken == parent) {
6994 break;
6995 }
6996 appToken = parent;
6997 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006998 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 mAppToken = appToken.appWindowToken;
7000
7001 mSurface = null;
7002 mRequestedWidth = 0;
7003 mRequestedHeight = 0;
7004 mLastRequestedWidth = 0;
7005 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007006 mXOffset = 0;
7007 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 mLayer = 0;
7009 mAnimLayer = 0;
7010 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007011 mInputWindowHandle = new InputWindowHandle(
7012 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007013 }
7014
7015 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007016 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007017 TAG, "Attaching " + this + " token=" + mToken
7018 + ", list=" + mToken.windows);
7019 mSession.windowAddedLocked();
7020 }
7021
7022 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7023 mHaveFrame = true;
7024
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007025 final Rect container = mContainingFrame;
7026 container.set(pf);
7027
7028 final Rect display = mDisplayFrame;
7029 display.set(df);
7030
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007031 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007032 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007033 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7034 display.intersect(mCompatibleScreenFrame);
7035 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007036 }
7037
7038 final int pw = container.right - container.left;
7039 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007040
7041 int w,h;
7042 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7043 w = mAttrs.width < 0 ? pw : mAttrs.width;
7044 h = mAttrs.height< 0 ? ph : mAttrs.height;
7045 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007046 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7047 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007048 }
Romain Guy06882f82009-06-10 13:36:04 -07007049
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007050 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007051 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7052 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007053 mParentFrame.set(pf);
7054 mContentChanged = true;
7055 }
7056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 final Rect content = mContentFrame;
7058 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007060 final Rect visible = mVisibleFrame;
7061 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007064 final int fw = frame.width();
7065 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7068 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7069
7070 Gravity.apply(mAttrs.gravity, w, h, container,
7071 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7072 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7073
7074 //System.out.println("Out: " + mFrame);
7075
7076 // Now make sure the window fits in the overall display.
7077 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 // Make sure the content and visible frames are inside of the
7080 // final window frame.
7081 if (content.left < frame.left) content.left = frame.left;
7082 if (content.top < frame.top) content.top = frame.top;
7083 if (content.right > frame.right) content.right = frame.right;
7084 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7085 if (visible.left < frame.left) visible.left = frame.left;
7086 if (visible.top < frame.top) visible.top = frame.top;
7087 if (visible.right > frame.right) visible.right = frame.right;
7088 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 final Rect contentInsets = mContentInsets;
7091 contentInsets.left = content.left-frame.left;
7092 contentInsets.top = content.top-frame.top;
7093 contentInsets.right = frame.right-content.right;
7094 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007096 final Rect visibleInsets = mVisibleInsets;
7097 visibleInsets.left = visible.left-frame.left;
7098 visibleInsets.top = visible.top-frame.top;
7099 visibleInsets.right = frame.right-visible.right;
7100 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007101
Dianne Hackborn284ac932009-08-28 10:34:25 -07007102 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7103 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007104 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007107 if (localLOGV) {
7108 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7109 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007110 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007111 + mRequestedWidth + ", mRequestedheight="
7112 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7113 + "): frame=" + mFrame.toShortString()
7114 + " ci=" + contentInsets.toShortString()
7115 + " vi=" + visibleInsets.toShortString());
7116 //}
7117 }
7118 }
Romain Guy06882f82009-06-10 13:36:04 -07007119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007120 public Rect getFrameLw() {
7121 return mFrame;
7122 }
7123
7124 public Rect getShownFrameLw() {
7125 return mShownFrame;
7126 }
7127
7128 public Rect getDisplayFrameLw() {
7129 return mDisplayFrame;
7130 }
7131
7132 public Rect getContentFrameLw() {
7133 return mContentFrame;
7134 }
7135
7136 public Rect getVisibleFrameLw() {
7137 return mVisibleFrame;
7138 }
7139
7140 public boolean getGivenInsetsPendingLw() {
7141 return mGivenInsetsPending;
7142 }
7143
7144 public Rect getGivenContentInsetsLw() {
7145 return mGivenContentInsets;
7146 }
Romain Guy06882f82009-06-10 13:36:04 -07007147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007148 public Rect getGivenVisibleInsetsLw() {
7149 return mGivenVisibleInsets;
7150 }
Romain Guy06882f82009-06-10 13:36:04 -07007151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 public WindowManager.LayoutParams getAttrs() {
7153 return mAttrs;
7154 }
7155
7156 public int getSurfaceLayer() {
7157 return mLayer;
7158 }
Romain Guy06882f82009-06-10 13:36:04 -07007159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007160 public IApplicationToken getAppToken() {
7161 return mAppToken != null ? mAppToken.appToken : null;
7162 }
Jeff Brown349703e2010-06-22 01:27:15 -07007163
7164 public long getInputDispatchingTimeoutNanos() {
7165 return mAppToken != null
7166 ? mAppToken.inputDispatchingTimeoutNanos
7167 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007169
7170 public boolean hasAppShownWindows() {
7171 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7172 }
7173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007174 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007175 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007176 TAG, "Setting animation in " + this + ": " + anim);
7177 mAnimating = false;
7178 mLocalAnimating = false;
7179 mAnimation = anim;
7180 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7181 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7182 }
7183
7184 public void clearAnimation() {
7185 if (mAnimation != null) {
7186 mAnimating = true;
7187 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007188 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007189 mAnimation = null;
7190 }
7191 }
Romain Guy06882f82009-06-10 13:36:04 -07007192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 Surface createSurfaceLocked() {
7194 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007195 mReportDestroySurface = false;
7196 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007197 mDrawPending = true;
7198 mCommitDrawPending = false;
7199 mReadyToShow = false;
7200 if (mAppToken != null) {
7201 mAppToken.allDrawn = false;
7202 }
7203
7204 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205
7206 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7207 flags |= Surface.SECURE;
7208 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007209 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 TAG, "Creating surface in session "
7211 + mSession.mSurfaceSession + " window " + this
7212 + " w=" + mFrame.width()
7213 + " h=" + mFrame.height() + " format="
7214 + mAttrs.format + " flags=" + flags);
7215
7216 int w = mFrame.width();
7217 int h = mFrame.height();
7218 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7219 // for a scaled surface, we always want the requested
7220 // size.
7221 w = mRequestedWidth;
7222 h = mRequestedHeight;
7223 }
7224
Romain Guy9825ec62009-10-01 00:58:09 -07007225 // Something is wrong and SurfaceFlinger will not like this,
7226 // try to revert to sane values
7227 if (w <= 0) w = 1;
7228 if (h <= 0) h = 1;
7229
Dianne Hackborn16064f92010-03-25 00:47:24 -07007230 mSurfaceShown = false;
7231 mSurfaceLayer = 0;
7232 mSurfaceAlpha = 1;
7233 mSurfaceX = 0;
7234 mSurfaceY = 0;
7235 mSurfaceW = w;
7236 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007237 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007238 final boolean isHwAccelerated = (mAttrs.flags &
7239 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7240 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7241 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7242 flags |= Surface.OPAQUE;
7243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007244 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007245 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007246 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007247 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007248 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007249 + mSurface + " IN SESSION "
7250 + mSession.mSurfaceSession
7251 + ": pid=" + mSession.mPid + " format="
7252 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007253 + Integer.toHexString(flags)
7254 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007256 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007257 reclaimSomeSurfaceMemoryLocked(this, "create");
7258 return null;
7259 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007260 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 return null;
7262 }
Romain Guy06882f82009-06-10 13:36:04 -07007263
Joe Onorato8a9b2202010-02-26 18:56:32 -08007264 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007265 TAG, "Got surface: " + mSurface
7266 + ", set left=" + mFrame.left + " top=" + mFrame.top
7267 + ", animLayer=" + mAnimLayer);
7268 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007269 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7270 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007271 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7272 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007273 }
7274 Surface.openTransaction();
7275 try {
7276 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007277 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007278 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007279 mSurface.setPosition(mSurfaceX, mSurfaceY);
7280 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007281 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007282 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 mSurface.hide();
7284 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007285 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007286 mSurface.setFlags(Surface.SURFACE_DITHER,
7287 Surface.SURFACE_DITHER);
7288 }
7289 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007290 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7292 }
7293 mLastHidden = true;
7294 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007296 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007297 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007298 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 TAG, "Created surface " + this);
7300 }
7301 return mSurface;
7302 }
Romain Guy06882f82009-06-10 13:36:04 -07007303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 if (mAppToken != null && this == mAppToken.startingWindow) {
7306 mAppToken.startingDisplayed = false;
7307 }
Romain Guy06882f82009-06-10 13:36:04 -07007308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007309 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007310 mDrawPending = false;
7311 mCommitDrawPending = false;
7312 mReadyToShow = false;
7313
7314 int i = mChildWindows.size();
7315 while (i > 0) {
7316 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007317 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007318 c.mAttachedHidden = true;
7319 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007320
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007321 if (mReportDestroySurface) {
7322 mReportDestroySurface = false;
7323 mSurfacePendingDestroy = true;
7324 try {
7325 mClient.dispatchGetNewSurface();
7326 // We'll really destroy on the next time around.
7327 return;
7328 } catch (RemoteException e) {
7329 }
7330 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007333 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007334 RuntimeException e = null;
7335 if (!HIDE_STACK_CRAWLS) {
7336 e = new RuntimeException();
7337 e.fillInStackTrace();
7338 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007339 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007340 + mSurface + ", session " + mSession, e);
7341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007343 RuntimeException e = null;
7344 if (!HIDE_STACK_CRAWLS) {
7345 e = new RuntimeException();
7346 e.fillInStackTrace();
7347 }
7348 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007349 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007350 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007351 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007352 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353 + " surface " + mSurface + " session " + mSession
7354 + ": " + e.toString());
7355 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007356
Dianne Hackborn16064f92010-03-25 00:47:24 -07007357 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007358 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 }
7360 }
7361
7362 boolean finishDrawingLocked() {
7363 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007364 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 TAG, "finishDrawingLocked: " + mSurface);
7366 mCommitDrawPending = true;
7367 mDrawPending = false;
7368 return true;
7369 }
7370 return false;
7371 }
7372
7373 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007374 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007375 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007377 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 }
7379 mCommitDrawPending = false;
7380 mReadyToShow = true;
7381 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7382 final AppWindowToken atoken = mAppToken;
7383 if (atoken == null || atoken.allDrawn || starting) {
7384 performShowLocked();
7385 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007386 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 }
7388
7389 // This must be called while inside a transaction.
7390 boolean performShowLocked() {
7391 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007392 RuntimeException e = null;
7393 if (!HIDE_STACK_CRAWLS) {
7394 e = new RuntimeException();
7395 e.fillInStackTrace();
7396 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007397 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007398 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7399 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7400 }
7401 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007402 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7403 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007404 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 + " during animation: policyVis=" + mPolicyVisibility
7406 + " attHidden=" + mAttachedHidden
7407 + " tok.hiddenRequested="
7408 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007409 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 + (mAppToken != null ? mAppToken.hidden : false)
7411 + " animating=" + mAnimating
7412 + " tok animating="
7413 + (mAppToken != null ? mAppToken.animating : false));
7414 if (!showSurfaceRobustlyLocked(this)) {
7415 return false;
7416 }
7417 mLastAlpha = -1;
7418 mHasDrawn = true;
7419 mLastHidden = false;
7420 mReadyToShow = false;
7421 enableScreenIfNeededLocked();
7422
7423 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007425 int i = mChildWindows.size();
7426 while (i > 0) {
7427 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007428 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007429 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007431 if (c.mSurface != null) {
7432 c.performShowLocked();
7433 // It hadn't been shown, which means layout not
7434 // performed on it, so now we want to make sure to
7435 // do a layout. If called from within the transaction
7436 // loop, this will cause it to restart with a new
7437 // layout.
7438 mLayoutNeeded = true;
7439 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 }
7441 }
Romain Guy06882f82009-06-10 13:36:04 -07007442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 if (mAttrs.type != TYPE_APPLICATION_STARTING
7444 && mAppToken != null) {
7445 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007446
Dianne Hackborn248b1882009-09-16 16:46:44 -07007447 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007448 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007449 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007451 // If this initial window is animating, stop it -- we
7452 // will do an animation to reveal it from behind the
7453 // starting window, so there is no need for it to also
7454 // be doing its own stuff.
7455 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007456 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007457 mAnimation = null;
7458 // Make sure we clean up the animation.
7459 mAnimating = true;
7460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 mFinishedStarting.add(mAppToken);
7462 mH.sendEmptyMessage(H.FINISHED_STARTING);
7463 }
7464 mAppToken.updateReportedVisibilityLocked();
7465 }
7466 }
7467 return true;
7468 }
Romain Guy06882f82009-06-10 13:36:04 -07007469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 // This must be called while inside a transaction. Returns true if
7471 // there is more animation to run.
7472 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007473 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7477 mHasTransformation = true;
7478 mHasLocalTransformation = true;
7479 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007480 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 TAG, "Starting animation in " + this +
7482 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7483 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7484 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7485 mAnimation.setStartTime(currentTime);
7486 mLocalAnimating = true;
7487 mAnimating = true;
7488 }
7489 mTransformation.clear();
7490 final boolean more = mAnimation.getTransformation(
7491 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007492 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 TAG, "Stepped animation in " + this +
7494 ": more=" + more + ", xform=" + mTransformation);
7495 if (more) {
7496 // we're not done!
7497 return true;
7498 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007499 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 TAG, "Finished animation in " + this +
7501 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007502
7503 if (mAnimation != null) {
7504 mAnimation.cancel();
7505 mAnimation = null;
7506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 //WindowManagerService.this.dump();
7508 }
7509 mHasLocalTransformation = false;
7510 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007511 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 // When our app token is animating, we kind-of pretend like
7513 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7514 // part of this check means that we will only do this if
7515 // our window is not currently exiting, or it is not
7516 // locally animating itself. The idea being that one that
7517 // is exiting and doing a local animation should be removed
7518 // once that animation is done.
7519 mAnimating = true;
7520 mHasTransformation = true;
7521 mTransformation.clear();
7522 return false;
7523 } else if (mHasTransformation) {
7524 // Little trick to get through the path below to act like
7525 // we have finished an animation.
7526 mAnimating = true;
7527 } else if (isAnimating()) {
7528 mAnimating = true;
7529 }
7530 } else if (mAnimation != null) {
7531 // If the display is frozen, and there is a pending animation,
7532 // clear it and make sure we run the cleanup code.
7533 mAnimating = true;
7534 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007535 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007536 mAnimation = null;
7537 }
Romain Guy06882f82009-06-10 13:36:04 -07007538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007539 if (!mAnimating && !mLocalAnimating) {
7540 return false;
7541 }
7542
Joe Onorato8a9b2202010-02-26 18:56:32 -08007543 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007544 TAG, "Animation done in " + this + ": exiting=" + mExiting
7545 + ", reportedVisible="
7546 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007548 mAnimating = false;
7549 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007550 if (mAnimation != null) {
7551 mAnimation.cancel();
7552 mAnimation = null;
7553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007554 mAnimLayer = mLayer;
7555 if (mIsImWindow) {
7556 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007557 } else if (mIsWallpaper) {
7558 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007559 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007560 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007561 + " anim layer: " + mAnimLayer);
7562 mHasTransformation = false;
7563 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007564 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7565 if (DEBUG_VISIBILITY) {
7566 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7567 + mPolicyVisibilityAfterAnim);
7568 }
7569 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7570 if (!mPolicyVisibility) {
7571 if (mCurrentFocus == this) {
7572 mFocusMayChange = true;
7573 }
7574 // Window is no longer visible -- make sure if we were waiting
7575 // for it to be displayed before enabling the display, that
7576 // we allow the display to be enabled now.
7577 enableScreenIfNeededLocked();
7578 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 mTransformation.clear();
7581 if (mHasDrawn
7582 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7583 && mAppToken != null
7584 && mAppToken.firstWindowDrawn
7585 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007586 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 + mToken + ": first real window done animating");
7588 mFinishedStarting.add(mAppToken);
7589 mH.sendEmptyMessage(H.FINISHED_STARTING);
7590 }
Romain Guy06882f82009-06-10 13:36:04 -07007591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 finishExit();
7593
7594 if (mAppToken != null) {
7595 mAppToken.updateReportedVisibilityLocked();
7596 }
7597
7598 return false;
7599 }
7600
7601 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007602 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007603 TAG, "finishExit in " + this
7604 + ": exiting=" + mExiting
7605 + " remove=" + mRemoveOnExit
7606 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007608 final int N = mChildWindows.size();
7609 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007610 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 }
Romain Guy06882f82009-06-10 13:36:04 -07007612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007613 if (!mExiting) {
7614 return;
7615 }
Romain Guy06882f82009-06-10 13:36:04 -07007616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 if (isWindowAnimating()) {
7618 return;
7619 }
7620
Joe Onorato8a9b2202010-02-26 18:56:32 -08007621 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 TAG, "Exit animation finished in " + this
7623 + ": remove=" + mRemoveOnExit);
7624 if (mSurface != null) {
7625 mDestroySurface.add(this);
7626 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007627 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007628 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 try {
7630 mSurface.hide();
7631 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007632 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007633 }
7634 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007635 }
7636 mExiting = false;
7637 if (mRemoveOnExit) {
7638 mPendingRemove.add(this);
7639 mRemoveOnExit = false;
7640 }
7641 }
Romain Guy06882f82009-06-10 13:36:04 -07007642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7644 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7645 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7646 if (dtdx < -.000001f || dtdx > .000001f) return false;
7647 if (dsdy < -.000001f || dsdy > .000001f) return false;
7648 return true;
7649 }
Romain Guy06882f82009-06-10 13:36:04 -07007650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 void computeShownFrameLocked() {
7652 final boolean selfTransformation = mHasLocalTransformation;
7653 Transformation attachedTransformation =
7654 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7655 ? mAttachedWindow.mTransformation : null;
7656 Transformation appTransformation =
7657 (mAppToken != null && mAppToken.hasTransformation)
7658 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007659
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007660 // Wallpapers are animated based on the "real" window they
7661 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007662 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007663 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007664 if (mWallpaperTarget.mHasLocalTransformation &&
7665 mWallpaperTarget.mAnimation != null &&
7666 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007667 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007668 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007669 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007670 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007671 }
7672 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007673 mWallpaperTarget.mAppToken.hasTransformation &&
7674 mWallpaperTarget.mAppToken.animation != null &&
7675 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007676 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007677 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007678 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007679 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007680 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007682
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007683 final boolean screenAnimation = mScreenRotationAnimation != null
7684 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007686 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007687 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007688 final Rect frame = mFrame;
7689 final float tmpFloats[] = mTmpFloats;
7690 final Matrix tmpMatrix = mTmpMatrix;
7691
7692 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007693 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007695 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007697 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007699 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007700 }
7701 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007702 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007703 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007704 if (screenAnimation) {
7705 tmpMatrix.postConcat(
7706 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708
7709 // "convert" it into SurfaceFlinger's format
7710 // (a 2x2 matrix + an offset)
7711 // Here we must not transform the position of the surface
7712 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007713 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007714
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007715 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007716 tmpMatrix.getValues(tmpFloats);
7717 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007718 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7719 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007720 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007721 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7722 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007723 int w = frame.width();
7724 int h = frame.height();
7725 mShownFrame.set(x, y, x+w, y+h);
7726
7727 // Now set the alpha... but because our current hardware
7728 // can't do alpha transformation on a non-opaque surface,
7729 // turn it off if we are running an animation that is also
7730 // transforming since it is more important to have that
7731 // animation be smooth.
7732 mShownAlpha = mAlpha;
7733 if (!mLimitedAlphaCompositing
7734 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7735 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7736 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007737 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007738 if (selfTransformation) {
7739 mShownAlpha *= mTransformation.getAlpha();
7740 }
7741 if (attachedTransformation != null) {
7742 mShownAlpha *= attachedTransformation.getAlpha();
7743 }
7744 if (appTransformation != null) {
7745 mShownAlpha *= appTransformation.getAlpha();
7746 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007747 if (screenAnimation) {
7748 mShownAlpha *=
7749 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7750 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007751 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007752 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 }
Romain Guy06882f82009-06-10 13:36:04 -07007754
Joe Onorato8a9b2202010-02-26 18:56:32 -08007755 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007756 TAG, "Continuing animation in " + this +
7757 ": " + mShownFrame +
7758 ", alpha=" + mTransformation.getAlpha());
7759 return;
7760 }
Romain Guy06882f82009-06-10 13:36:04 -07007761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007762 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007763 if (mXOffset != 0 || mYOffset != 0) {
7764 mShownFrame.offset(mXOffset, mYOffset);
7765 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007766 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007767 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007768 mDsDx = 1;
7769 mDtDx = 0;
7770 mDsDy = 0;
7771 mDtDy = 1;
7772 }
Romain Guy06882f82009-06-10 13:36:04 -07007773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 /**
7775 * Is this window visible? It is not visible if there is no
7776 * surface, or we are in the process of running an exit animation
7777 * that will remove the surface, or its app token has been hidden.
7778 */
7779 public boolean isVisibleLw() {
7780 final AppWindowToken atoken = mAppToken;
7781 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7782 && (atoken == null || !atoken.hiddenRequested)
7783 && !mExiting && !mDestroying;
7784 }
7785
7786 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007787 * Like {@link #isVisibleLw}, but also counts a window that is currently
7788 * "hidden" behind the keyguard as visible. This allows us to apply
7789 * things like window flags that impact the keyguard.
7790 * XXX I am starting to think we need to have ANOTHER visibility flag
7791 * for this "hidden behind keyguard" state rather than overloading
7792 * mPolicyVisibility. Ungh.
7793 */
7794 public boolean isVisibleOrBehindKeyguardLw() {
7795 final AppWindowToken atoken = mAppToken;
7796 return mSurface != null && !mAttachedHidden
7797 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007798 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007799 && !mExiting && !mDestroying;
7800 }
7801
7802 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007803 * Is this window visible, ignoring its app token? It is not visible
7804 * if there is no surface, or we are in the process of running an exit animation
7805 * that will remove the surface.
7806 */
7807 public boolean isWinVisibleLw() {
7808 final AppWindowToken atoken = mAppToken;
7809 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7810 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7811 && !mExiting && !mDestroying;
7812 }
7813
7814 /**
7815 * The same as isVisible(), but follows the current hidden state of
7816 * the associated app token, not the pending requested hidden state.
7817 */
7818 boolean isVisibleNow() {
7819 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007820 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 }
7822
7823 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007824 * Can this window possibly be a drag/drop target? The test here is
7825 * a combination of the above "visible now" with the check that the
7826 * Input Manager uses when discarding windows from input consideration.
7827 */
7828 boolean isPotentialDragTarget() {
7829 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7830 }
7831
7832 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 * Same as isVisible(), but we also count it as visible between the
7834 * call to IWindowSession.add() and the first relayout().
7835 */
7836 boolean isVisibleOrAdding() {
7837 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007838 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007839 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7840 && mPolicyVisibility && !mAttachedHidden
7841 && (atoken == null || !atoken.hiddenRequested)
7842 && !mExiting && !mDestroying;
7843 }
7844
7845 /**
7846 * Is this window currently on-screen? It is on-screen either if it
7847 * is visible or it is currently running an animation before no longer
7848 * being visible.
7849 */
7850 boolean isOnScreen() {
7851 final AppWindowToken atoken = mAppToken;
7852 if (atoken != null) {
7853 return mSurface != null && mPolicyVisibility && !mDestroying
7854 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007855 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007856 } else {
7857 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007858 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007859 }
7860 }
Romain Guy06882f82009-06-10 13:36:04 -07007861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 /**
7863 * Like isOnScreen(), but we don't return true if the window is part
7864 * of a transition that has not yet been started.
7865 */
7866 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007867 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007868 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007869 return false;
7870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007872 final boolean animating = atoken != null
7873 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007874 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007875 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7876 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007877 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007878 }
7879
7880 /** Is the window or its container currently animating? */
7881 boolean isAnimating() {
7882 final WindowState attached = mAttachedWindow;
7883 final AppWindowToken atoken = mAppToken;
7884 return mAnimation != null
7885 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007886 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007887 (atoken.animation != null
7888 || atoken.inPendingTransaction));
7889 }
7890
7891 /** Is this window currently animating? */
7892 boolean isWindowAnimating() {
7893 return mAnimation != null;
7894 }
7895
7896 /**
7897 * Like isOnScreen, but returns false if the surface hasn't yet
7898 * been drawn.
7899 */
7900 public boolean isDisplayedLw() {
7901 final AppWindowToken atoken = mAppToken;
7902 return mSurface != null && mPolicyVisibility && !mDestroying
7903 && !mDrawPending && !mCommitDrawPending
7904 && ((!mAttachedHidden &&
7905 (atoken == null || !atoken.hiddenRequested))
7906 || mAnimating);
7907 }
7908
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007909 /**
7910 * Returns true if the window has a surface that it has drawn a
7911 * complete UI in to.
7912 */
7913 public boolean isDrawnLw() {
7914 final AppWindowToken atoken = mAppToken;
7915 return mSurface != null && !mDestroying
7916 && !mDrawPending && !mCommitDrawPending;
7917 }
7918
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007919 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007920 * Return true if the window is opaque and fully drawn. This indicates
7921 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007922 */
7923 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007924 return (mAttrs.format == PixelFormat.OPAQUE
7925 || mAttrs.type == TYPE_WALLPAPER)
7926 && mSurface != null && mAnimation == null
7927 && (mAppToken == null || mAppToken.animation == null)
7928 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007929 }
7930
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007931 /**
7932 * Return whether this window is wanting to have a translation
7933 * animation applied to it for an in-progress move. (Only makes
7934 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7935 */
7936 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007937 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007938 && (mFrame.top != mLastFrame.top
7939 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007940 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007941 && mPolicy.isScreenOn();
7942 }
7943
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007944 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7945 return
7946 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007947 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7948 // only if it's visible
7949 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007950 // and only if the application fills the compatible screen
7951 mFrame.left <= mCompatibleScreenFrame.left &&
7952 mFrame.top <= mCompatibleScreenFrame.top &&
7953 mFrame.right >= mCompatibleScreenFrame.right &&
7954 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007955 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007956 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007957 }
7958
7959 boolean isFullscreen(int screenWidth, int screenHeight) {
7960 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007961 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007962 }
7963
7964 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007965 disposeInputChannel();
7966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007967 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007968 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007969 mAttachedWindow.mChildWindows.remove(this);
7970 }
7971 destroySurfaceLocked();
7972 mSession.windowRemovedLocked();
7973 try {
7974 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7975 } catch (RuntimeException e) {
7976 // Ignore if it has already been removed (usually because
7977 // we are doing this as part of processing a death note.)
7978 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007979 }
7980
7981 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007982 if (mInputChannel != null) {
7983 mInputManager.unregisterInputChannel(mInputChannel);
7984
7985 mInputChannel.dispose();
7986 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007987 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007988 }
7989
7990 private class DeathRecipient implements IBinder.DeathRecipient {
7991 public void binderDied() {
7992 try {
7993 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007994 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007995 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007996 if (win != null) {
7997 removeWindowLocked(mSession, win);
7998 }
7999 }
8000 } catch (IllegalArgumentException ex) {
8001 // This will happen if the window has already been
8002 // removed.
8003 }
8004 }
8005 }
8006
8007 /** Returns true if this window desires key events. */
8008 public final boolean canReceiveKeys() {
8009 return isVisibleOrAdding()
8010 && (mViewVisibility == View.VISIBLE)
8011 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8012 }
8013
8014 public boolean hasDrawnLw() {
8015 return mHasDrawn;
8016 }
8017
8018 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008019 return showLw(doAnimation, true);
8020 }
8021
8022 boolean showLw(boolean doAnimation, boolean requestAnim) {
8023 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8024 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008026 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008027 if (doAnimation) {
8028 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8029 + mPolicyVisibility + " mAnimation=" + mAnimation);
8030 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8031 doAnimation = false;
8032 } else if (mPolicyVisibility && mAnimation == null) {
8033 // Check for the case where we are currently visible and
8034 // not animating; we do not want to do animation at such a
8035 // point to become visible when we already are.
8036 doAnimation = false;
8037 }
8038 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008039 mPolicyVisibility = true;
8040 mPolicyVisibilityAfterAnim = true;
8041 if (doAnimation) {
8042 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8043 }
8044 if (requestAnim) {
8045 requestAnimationLocked(0);
8046 }
8047 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 }
8049
8050 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008051 return hideLw(doAnimation, true);
8052 }
8053
8054 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008055 if (doAnimation) {
8056 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8057 doAnimation = false;
8058 }
8059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008060 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8061 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008062 if (!current) {
8063 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008064 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008065 if (doAnimation) {
8066 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8067 if (mAnimation == null) {
8068 doAnimation = false;
8069 }
8070 }
8071 if (doAnimation) {
8072 mPolicyVisibilityAfterAnim = false;
8073 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008074 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008075 mPolicyVisibilityAfterAnim = false;
8076 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008077 // Window is no longer visible -- make sure if we were waiting
8078 // for it to be displayed before enabling the display, that
8079 // we allow the display to be enabled now.
8080 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008081 if (mCurrentFocus == this) {
8082 mFocusMayChange = true;
8083 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008084 }
8085 if (requestAnim) {
8086 requestAnimationLocked(0);
8087 }
8088 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 }
8090
Jeff Brownfbf09772011-01-16 14:06:57 -08008091 public void getTouchableRegion(Region outRegion) {
8092 final Rect frame = mFrame;
8093 switch (mTouchableInsets) {
8094 default:
8095 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8096 outRegion.set(frame);
8097 break;
8098 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8099 final Rect inset = mGivenContentInsets;
8100 outRegion.set(
8101 frame.left + inset.left, frame.top + inset.top,
8102 frame.right - inset.right, frame.bottom - inset.bottom);
8103 break;
8104 }
8105 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8106 final Rect inset = mGivenVisibleInsets;
8107 outRegion.set(
8108 frame.left + inset.left, frame.top + inset.top,
8109 frame.right - inset.right, frame.bottom - inset.bottom);
8110 break;
8111 }
8112 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8113 final Region givenTouchableRegion = mGivenTouchableRegion;
8114 outRegion.set(givenTouchableRegion);
8115 outRegion.translate(frame.left, frame.top);
8116 break;
8117 }
8118 }
8119 }
8120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008122 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8123 pw.print(" mClient="); pw.println(mClient.asBinder());
8124 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8125 if (mAttachedWindow != null || mLayoutAttached) {
8126 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8127 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8128 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008129 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8130 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8131 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008132 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8133 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008134 }
8135 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8136 pw.print(" mSubLayer="); pw.print(mSubLayer);
8137 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8138 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8139 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8140 pw.print("="); pw.print(mAnimLayer);
8141 pw.print(" mLastLayer="); pw.println(mLastLayer);
8142 if (mSurface != null) {
8143 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008144 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8145 pw.print(" layer="); pw.print(mSurfaceLayer);
8146 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8147 pw.print(" rect=("); pw.print(mSurfaceX);
8148 pw.print(","); pw.print(mSurfaceY);
8149 pw.print(") "); pw.print(mSurfaceW);
8150 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008151 }
8152 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8153 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8154 if (mAppToken != null) {
8155 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8156 }
8157 if (mTargetAppToken != null) {
8158 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8159 }
8160 pw.print(prefix); pw.print("mViewVisibility=0x");
8161 pw.print(Integer.toHexString(mViewVisibility));
8162 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008163 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8164 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008165 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8166 pw.print(prefix); pw.print("mPolicyVisibility=");
8167 pw.print(mPolicyVisibility);
8168 pw.print(" mPolicyVisibilityAfterAnim=");
8169 pw.print(mPolicyVisibilityAfterAnim);
8170 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8171 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008172 if (!mRelayoutCalled) {
8173 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8174 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008175 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008176 pw.print(" h="); pw.print(mRequestedHeight);
8177 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008178 if (mXOffset != 0 || mYOffset != 0) {
8179 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8180 pw.print(" y="); pw.println(mYOffset);
8181 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008182 pw.print(prefix); pw.print("mGivenContentInsets=");
8183 mGivenContentInsets.printShortString(pw);
8184 pw.print(" mGivenVisibleInsets=");
8185 mGivenVisibleInsets.printShortString(pw);
8186 pw.println();
8187 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8188 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8189 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8190 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008191 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008192 pw.print(prefix); pw.print("mShownFrame=");
8193 mShownFrame.printShortString(pw);
8194 pw.print(" last="); mLastShownFrame.printShortString(pw);
8195 pw.println();
8196 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8197 pw.print(" last="); mLastFrame.printShortString(pw);
8198 pw.println();
8199 pw.print(prefix); pw.print("mContainingFrame=");
8200 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008201 pw.print(" mParentFrame=");
8202 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008203 pw.print(" mDisplayFrame=");
8204 mDisplayFrame.printShortString(pw);
8205 pw.println();
8206 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8207 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8208 pw.println();
8209 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8210 pw.print(" last="); mLastContentInsets.printShortString(pw);
8211 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8212 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8213 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008214 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8215 || mAnimation != null) {
8216 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8217 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8218 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8219 pw.print(" mAnimation="); pw.println(mAnimation);
8220 }
8221 if (mHasTransformation || mHasLocalTransformation) {
8222 pw.print(prefix); pw.print("XForm: has=");
8223 pw.print(mHasTransformation);
8224 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8225 pw.print(" "); mTransformation.printShortString(pw);
8226 pw.println();
8227 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008228 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8229 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8230 pw.print(" mAlpha="); pw.print(mAlpha);
8231 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8232 }
8233 if (mHaveMatrix) {
8234 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8235 pw.print(" mDtDx="); pw.print(mDtDx);
8236 pw.print(" mDsDy="); pw.print(mDsDy);
8237 pw.print(" mDtDy="); pw.println(mDtDy);
8238 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008239 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8240 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8241 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8242 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8243 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8244 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8245 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8246 pw.print(" mDestroying="); pw.print(mDestroying);
8247 pw.print(" mRemoved="); pw.println(mRemoved);
8248 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008249 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008250 pw.print(prefix); pw.print("mOrientationChanging=");
8251 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008252 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8253 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008254 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008255 if (mHScale != 1 || mVScale != 1) {
8256 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8257 pw.print(" mVScale="); pw.println(mVScale);
8258 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008259 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008260 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8261 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8262 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008263 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8264 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8265 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8266 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008267 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008268
8269 String makeInputChannelName() {
8270 return Integer.toHexString(System.identityHashCode(this))
8271 + " " + mAttrs.getTitle();
8272 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008273
8274 @Override
8275 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008276 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8277 || mWasPaused != mToken.paused) {
8278 mLastTitle = mAttrs.getTitle();
8279 mWasPaused = mToken.paused;
8280 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8281 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8282 }
8283 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008284 }
8285 }
Romain Guy06882f82009-06-10 13:36:04 -07008286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008287 // -------------------------------------------------------------
8288 // Window Token State
8289 // -------------------------------------------------------------
8290
8291 class WindowToken {
8292 // The actual token.
8293 final IBinder token;
8294
8295 // The type of window this token is for, as per WindowManager.LayoutParams.
8296 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008298 // Set if this token was explicitly added by a client, so should
8299 // not be removed when all windows are removed.
8300 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008301
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008302 // For printing.
8303 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008305 // If this is an AppWindowToken, this is non-null.
8306 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008308 // All of the windows associated with this token.
8309 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8310
8311 // Is key dispatching paused for this token?
8312 boolean paused = false;
8313
8314 // Should this token's windows be hidden?
8315 boolean hidden;
8316
8317 // Temporary for finding which tokens no longer have visible windows.
8318 boolean hasVisible;
8319
Dianne Hackborna8f60182009-09-01 19:01:50 -07008320 // Set to true when this token is in a pending transaction where it
8321 // will be shown.
8322 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008323
Dianne Hackborna8f60182009-09-01 19:01:50 -07008324 // Set to true when this token is in a pending transaction where it
8325 // will be hidden.
8326 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008327
Dianne Hackborna8f60182009-09-01 19:01:50 -07008328 // Set to true when this token is in a pending transaction where its
8329 // windows will be put to the bottom of the list.
8330 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008331
Dianne Hackborna8f60182009-09-01 19:01:50 -07008332 // Set to true when this token is in a pending transaction where its
8333 // windows will be put to the top of the list.
8334 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336 WindowToken(IBinder _token, int type, boolean _explicit) {
8337 token = _token;
8338 windowType = type;
8339 explicit = _explicit;
8340 }
8341
8342 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008343 pw.print(prefix); pw.print("token="); pw.println(token);
8344 pw.print(prefix); pw.print("windows="); pw.println(windows);
8345 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8346 pw.print(" hidden="); pw.print(hidden);
8347 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008348 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8349 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8350 pw.print(" waitingToHide="); pw.print(waitingToHide);
8351 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8352 pw.print(" sendingToTop="); pw.println(sendingToTop);
8353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354 }
8355
8356 @Override
8357 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008358 if (stringName == null) {
8359 StringBuilder sb = new StringBuilder();
8360 sb.append("WindowToken{");
8361 sb.append(Integer.toHexString(System.identityHashCode(this)));
8362 sb.append(" token="); sb.append(token); sb.append('}');
8363 stringName = sb.toString();
8364 }
8365 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008366 }
8367 };
8368
8369 class AppWindowToken extends WindowToken {
8370 // Non-null only for application tokens.
8371 final IApplicationToken appToken;
8372
8373 // All of the windows and child windows that are included in this
8374 // application token. Note this list is NOT sorted!
8375 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8376
8377 int groupId = -1;
8378 boolean appFullscreen;
8379 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008380
8381 // The input dispatching timeout for this application token in nanoseconds.
8382 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008384 // These are used for determining when all windows associated with
8385 // an activity have been drawn, so they can be made visible together
8386 // at the same time.
8387 int lastTransactionSequence = mTransactionSequence-1;
8388 int numInterestingWindows;
8389 int numDrawnWindows;
8390 boolean inPendingTransaction;
8391 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008393 // Is this token going to be hidden in a little while? If so, it
8394 // won't be taken into account for setting the screen orientation.
8395 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 // Is this window's surface needed? This is almost like hidden, except
8398 // it will sometimes be true a little earlier: when the token has
8399 // been shown, but is still waiting for its app transition to execute
8400 // before making its windows shown.
8401 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008403 // Have we told the window clients to hide themselves?
8404 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008406 // Last visibility state we reported to the app token.
8407 boolean reportedVisible;
8408
8409 // Set to true when the token has been removed from the window mgr.
8410 boolean removed;
8411
8412 // Have we been asked to have this token keep the screen frozen?
8413 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 boolean animating;
8416 Animation animation;
8417 boolean hasTransformation;
8418 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008420 // Offset to the window of all layers in the token, for use by
8421 // AppWindowToken animations.
8422 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008424 // Information about an application starting window if displayed.
8425 StartingData startingData;
8426 WindowState startingWindow;
8427 View startingView;
8428 boolean startingDisplayed;
8429 boolean startingMoved;
8430 boolean firstWindowDrawn;
8431
Jeff Brown928e0542011-01-10 11:17:36 -08008432 // Input application handle used by the input dispatcher.
8433 InputApplicationHandle mInputApplicationHandle;
8434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008435 AppWindowToken(IApplicationToken _token) {
8436 super(_token.asBinder(),
8437 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8438 appWindowToken = this;
8439 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008440 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 }
Romain Guy06882f82009-06-10 13:36:04 -07008442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008443 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008444 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008445 TAG, "Setting animation in " + this + ": " + anim);
8446 animation = anim;
8447 animating = false;
8448 anim.restrictDuration(MAX_ANIMATION_DURATION);
8449 anim.scaleCurrentDuration(mTransitionAnimationScale);
8450 int zorder = anim.getZAdjustment();
8451 int adj = 0;
8452 if (zorder == Animation.ZORDER_TOP) {
8453 adj = TYPE_LAYER_OFFSET;
8454 } else if (zorder == Animation.ZORDER_BOTTOM) {
8455 adj = -TYPE_LAYER_OFFSET;
8456 }
Romain Guy06882f82009-06-10 13:36:04 -07008457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 if (animLayerAdjustment != adj) {
8459 animLayerAdjustment = adj;
8460 updateLayers();
8461 }
8462 }
Romain Guy06882f82009-06-10 13:36:04 -07008463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008464 public void setDummyAnimation() {
8465 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008466 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 TAG, "Setting dummy animation in " + this);
8468 animation = sDummyAnimation;
8469 }
8470 }
8471
8472 public void clearAnimation() {
8473 if (animation != null) {
8474 animation = null;
8475 animating = true;
8476 }
8477 }
Romain Guy06882f82009-06-10 13:36:04 -07008478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 void updateLayers() {
8480 final int N = allAppWindows.size();
8481 final int adj = animLayerAdjustment;
8482 for (int i=0; i<N; i++) {
8483 WindowState w = allAppWindows.get(i);
8484 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008485 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 + w.mAnimLayer);
8487 if (w == mInputMethodTarget) {
8488 setInputMethodAnimLayerAdjustment(adj);
8489 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008490 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008491 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008492 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 }
8494 }
Romain Guy06882f82009-06-10 13:36:04 -07008495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 void sendAppVisibilityToClients() {
8497 final int N = allAppWindows.size();
8498 for (int i=0; i<N; i++) {
8499 WindowState win = allAppWindows.get(i);
8500 if (win == startingWindow && clientHidden) {
8501 // Don't hide the starting window.
8502 continue;
8503 }
8504 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008505 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 "Setting visibility of " + win + ": " + (!clientHidden));
8507 win.mClient.dispatchAppVisibility(!clientHidden);
8508 } catch (RemoteException e) {
8509 }
8510 }
8511 }
Romain Guy06882f82009-06-10 13:36:04 -07008512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 void showAllWindowsLocked() {
8514 final int NW = allAppWindows.size();
8515 for (int i=0; i<NW; i++) {
8516 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008517 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 "performing show on: " + w);
8519 w.performShowLocked();
8520 }
8521 }
Romain Guy06882f82009-06-10 13:36:04 -07008522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 // This must be called while inside a transaction.
8524 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008525 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008528 if (animation == sDummyAnimation) {
8529 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008530 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 // when it is really time to animate, this will be set to
8532 // a real animation and the next call will execute normally.
8533 return false;
8534 }
Romain Guy06882f82009-06-10 13:36:04 -07008535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8537 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008538 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 TAG, "Starting animation in " + this +
8540 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8541 + " scale=" + mTransitionAnimationScale
8542 + " allDrawn=" + allDrawn + " animating=" + animating);
8543 animation.initialize(dw, dh, dw, dh);
8544 animation.setStartTime(currentTime);
8545 animating = true;
8546 }
8547 transformation.clear();
8548 final boolean more = animation.getTransformation(
8549 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008550 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008551 TAG, "Stepped animation in " + this +
8552 ": more=" + more + ", xform=" + transformation);
8553 if (more) {
8554 // we're done!
8555 hasTransformation = true;
8556 return true;
8557 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008558 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 TAG, "Finished animation in " + this +
8560 " @ " + currentTime);
8561 animation = null;
8562 }
8563 } else if (animation != null) {
8564 // If the display is frozen, and there is a pending animation,
8565 // clear it and make sure we run the cleanup code.
8566 animating = true;
8567 animation = null;
8568 }
8569
8570 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008572 if (!animating) {
8573 return false;
8574 }
8575
8576 clearAnimation();
8577 animating = false;
8578 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8579 moveInputMethodWindowsIfNeededLocked(true);
8580 }
Romain Guy06882f82009-06-10 13:36:04 -07008581
Joe Onorato8a9b2202010-02-26 18:56:32 -08008582 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583 TAG, "Animation done in " + this
8584 + ": reportedVisible=" + reportedVisible);
8585
8586 transformation.clear();
8587 if (animLayerAdjustment != 0) {
8588 animLayerAdjustment = 0;
8589 updateLayers();
8590 }
Romain Guy06882f82009-06-10 13:36:04 -07008591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008592 final int N = windows.size();
8593 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008594 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008595 }
8596 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008598 return false;
8599 }
8600
8601 void updateReportedVisibilityLocked() {
8602 if (appToken == null) {
8603 return;
8604 }
Romain Guy06882f82009-06-10 13:36:04 -07008605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 int numInteresting = 0;
8607 int numVisible = 0;
8608 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008609
Joe Onorato8a9b2202010-02-26 18:56:32 -08008610 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 final int N = allAppWindows.size();
8612 for (int i=0; i<N; i++) {
8613 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008614 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008615 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008616 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8617 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 continue;
8619 }
8620 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008621 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008622 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008624 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008625 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 + " pv=" + win.mPolicyVisibility
8627 + " dp=" + win.mDrawPending
8628 + " cdp=" + win.mCommitDrawPending
8629 + " ah=" + win.mAttachedHidden
8630 + " th="
8631 + (win.mAppToken != null
8632 ? win.mAppToken.hiddenRequested : false)
8633 + " a=" + win.mAnimating);
8634 }
8635 }
8636 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008637 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 if (!win.isAnimating()) {
8639 numVisible++;
8640 }
8641 nowGone = false;
8642 } else if (win.isAnimating()) {
8643 nowGone = false;
8644 }
8645 }
Romain Guy06882f82009-06-10 13:36:04 -07008646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008647 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008648 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008649 + numInteresting + " visible=" + numVisible);
8650 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008651 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008652 TAG, "Visibility changed in " + this
8653 + ": vis=" + nowVisible);
8654 reportedVisible = nowVisible;
8655 Message m = mH.obtainMessage(
8656 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8657 nowVisible ? 1 : 0,
8658 nowGone ? 1 : 0,
8659 this);
8660 mH.sendMessage(m);
8661 }
8662 }
Romain Guy06882f82009-06-10 13:36:04 -07008663
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008664 WindowState findMainWindow() {
8665 int j = windows.size();
8666 while (j > 0) {
8667 j--;
8668 WindowState win = windows.get(j);
8669 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8670 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8671 return win;
8672 }
8673 }
8674 return null;
8675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008677 void dump(PrintWriter pw, String prefix) {
8678 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008679 if (appToken != null) {
8680 pw.print(prefix); pw.println("app=true");
8681 }
8682 if (allAppWindows.size() > 0) {
8683 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8684 }
8685 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008686 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008687 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8688 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8689 pw.print(" clientHidden="); pw.print(clientHidden);
8690 pw.print(" willBeHidden="); pw.print(willBeHidden);
8691 pw.print(" reportedVisible="); pw.println(reportedVisible);
8692 if (paused || freezingScreen) {
8693 pw.print(prefix); pw.print("paused="); pw.print(paused);
8694 pw.print(" freezingScreen="); pw.println(freezingScreen);
8695 }
8696 if (numInterestingWindows != 0 || numDrawnWindows != 0
8697 || inPendingTransaction || allDrawn) {
8698 pw.print(prefix); pw.print("numInterestingWindows=");
8699 pw.print(numInterestingWindows);
8700 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8701 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8702 pw.print(" allDrawn="); pw.println(allDrawn);
8703 }
8704 if (animating || animation != null) {
8705 pw.print(prefix); pw.print("animating="); pw.print(animating);
8706 pw.print(" animation="); pw.println(animation);
8707 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008708 if (hasTransformation) {
8709 pw.print(prefix); pw.print("XForm: ");
8710 transformation.printShortString(pw);
8711 pw.println();
8712 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008713 if (animLayerAdjustment != 0) {
8714 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8715 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008716 if (startingData != null || removed || firstWindowDrawn) {
8717 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8718 pw.print(" removed="); pw.print(removed);
8719 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8720 }
8721 if (startingWindow != null || startingView != null
8722 || startingDisplayed || startingMoved) {
8723 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8724 pw.print(" startingView="); pw.print(startingView);
8725 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8726 pw.print(" startingMoved"); pw.println(startingMoved);
8727 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 }
8729
8730 @Override
8731 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008732 if (stringName == null) {
8733 StringBuilder sb = new StringBuilder();
8734 sb.append("AppWindowToken{");
8735 sb.append(Integer.toHexString(System.identityHashCode(this)));
8736 sb.append(" token="); sb.append(token); sb.append('}');
8737 stringName = sb.toString();
8738 }
8739 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 }
8741 }
Romain Guy06882f82009-06-10 13:36:04 -07008742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008743 // -------------------------------------------------------------
8744 // DummyAnimation
8745 // -------------------------------------------------------------
8746
8747 // This is an animation that does nothing: it just immediately finishes
8748 // itself every time it is called. It is used as a stub animation in cases
8749 // where we want to synchronize multiple things that may be animating.
8750 static final class DummyAnimation extends Animation {
8751 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8752 return false;
8753 }
8754 }
8755 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008757 // -------------------------------------------------------------
8758 // Async Handler
8759 // -------------------------------------------------------------
8760
8761 static final class StartingData {
8762 final String pkg;
8763 final int theme;
8764 final CharSequence nonLocalizedLabel;
8765 final int labelRes;
8766 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008767 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008769 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008770 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008771 pkg = _pkg;
8772 theme = _theme;
8773 nonLocalizedLabel = _nonLocalizedLabel;
8774 labelRes = _labelRes;
8775 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008776 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008777 }
8778 }
8779
8780 private final class H extends Handler {
8781 public static final int REPORT_FOCUS_CHANGE = 2;
8782 public static final int REPORT_LOSING_FOCUS = 3;
8783 public static final int ANIMATE = 4;
8784 public static final int ADD_STARTING = 5;
8785 public static final int REMOVE_STARTING = 6;
8786 public static final int FINISHED_STARTING = 7;
8787 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008788 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8789 public static final int HOLD_SCREEN_CHANGED = 12;
8790 public static final int APP_TRANSITION_TIMEOUT = 13;
8791 public static final int PERSIST_ANIMATION_SCALE = 14;
8792 public static final int FORCE_GC = 15;
8793 public static final int ENABLE_SCREEN = 16;
8794 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008795 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008796 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008797 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008798 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008800 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008802 public H() {
8803 }
Romain Guy06882f82009-06-10 13:36:04 -07008804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008805 @Override
8806 public void handleMessage(Message msg) {
8807 switch (msg.what) {
8808 case REPORT_FOCUS_CHANGE: {
8809 WindowState lastFocus;
8810 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008812 synchronized(mWindowMap) {
8813 lastFocus = mLastFocus;
8814 newFocus = mCurrentFocus;
8815 if (lastFocus == newFocus) {
8816 // Focus is not changing, so nothing to do.
8817 return;
8818 }
8819 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008820 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008821 // + " to " + newFocus);
8822 if (newFocus != null && lastFocus != null
8823 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008824 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008825 mLosingFocus.add(lastFocus);
8826 lastFocus = null;
8827 }
8828 }
8829
8830 if (lastFocus != newFocus) {
8831 //System.out.println("Changing focus from " + lastFocus
8832 // + " to " + newFocus);
8833 if (newFocus != null) {
8834 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008835 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008836 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8837 } catch (RemoteException e) {
8838 // Ignore if process has died.
8839 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008840 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008841 }
8842
8843 if (lastFocus != null) {
8844 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008845 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008846 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8847 } catch (RemoteException e) {
8848 // Ignore if process has died.
8849 }
8850 }
8851 }
8852 } break;
8853
8854 case REPORT_LOSING_FOCUS: {
8855 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008857 synchronized(mWindowMap) {
8858 losers = mLosingFocus;
8859 mLosingFocus = new ArrayList<WindowState>();
8860 }
8861
8862 final int N = losers.size();
8863 for (int i=0; i<N; i++) {
8864 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008865 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8867 } catch (RemoteException e) {
8868 // Ignore if process has died.
8869 }
8870 }
8871 } break;
8872
8873 case ANIMATE: {
8874 synchronized(mWindowMap) {
8875 mAnimationPending = false;
8876 performLayoutAndPlaceSurfacesLocked();
8877 }
8878 } break;
8879
8880 case ADD_STARTING: {
8881 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8882 final StartingData sd = wtoken.startingData;
8883
8884 if (sd == null) {
8885 // Animation has been canceled... do nothing.
8886 return;
8887 }
Romain Guy06882f82009-06-10 13:36:04 -07008888
Joe Onorato8a9b2202010-02-26 18:56:32 -08008889 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008892 View view = null;
8893 try {
8894 view = mPolicy.addStartingWindow(
8895 wtoken.token, sd.pkg,
8896 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008897 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008898 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008899 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 }
8901
8902 if (view != null) {
8903 boolean abort = false;
8904
8905 synchronized(mWindowMap) {
8906 if (wtoken.removed || wtoken.startingData == null) {
8907 // If the window was successfully added, then
8908 // we need to remove it.
8909 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008910 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008911 "Aborted starting " + wtoken
8912 + ": removed=" + wtoken.removed
8913 + " startingData=" + wtoken.startingData);
8914 wtoken.startingWindow = null;
8915 wtoken.startingData = null;
8916 abort = true;
8917 }
8918 } else {
8919 wtoken.startingView = view;
8920 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008921 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008922 "Added starting " + wtoken
8923 + ": startingWindow="
8924 + wtoken.startingWindow + " startingView="
8925 + wtoken.startingView);
8926 }
8927
8928 if (abort) {
8929 try {
8930 mPolicy.removeStartingWindow(wtoken.token, view);
8931 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008932 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008933 }
8934 }
8935 }
8936 } break;
8937
8938 case REMOVE_STARTING: {
8939 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8940 IBinder token = null;
8941 View view = null;
8942 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008943 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008944 + wtoken + ": startingWindow="
8945 + wtoken.startingWindow + " startingView="
8946 + wtoken.startingView);
8947 if (wtoken.startingWindow != null) {
8948 view = wtoken.startingView;
8949 token = wtoken.token;
8950 wtoken.startingData = null;
8951 wtoken.startingView = null;
8952 wtoken.startingWindow = null;
8953 }
8954 }
8955 if (view != null) {
8956 try {
8957 mPolicy.removeStartingWindow(token, view);
8958 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008959 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008960 }
8961 }
8962 } break;
8963
8964 case FINISHED_STARTING: {
8965 IBinder token = null;
8966 View view = null;
8967 while (true) {
8968 synchronized (mWindowMap) {
8969 final int N = mFinishedStarting.size();
8970 if (N <= 0) {
8971 break;
8972 }
8973 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8974
Joe Onorato8a9b2202010-02-26 18:56:32 -08008975 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 "Finished starting " + wtoken
8977 + ": startingWindow=" + wtoken.startingWindow
8978 + " startingView=" + wtoken.startingView);
8979
8980 if (wtoken.startingWindow == null) {
8981 continue;
8982 }
8983
8984 view = wtoken.startingView;
8985 token = wtoken.token;
8986 wtoken.startingData = null;
8987 wtoken.startingView = null;
8988 wtoken.startingWindow = null;
8989 }
8990
8991 try {
8992 mPolicy.removeStartingWindow(token, view);
8993 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008994 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008995 }
8996 }
8997 } break;
8998
8999 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9000 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9001
9002 boolean nowVisible = msg.arg1 != 0;
9003 boolean nowGone = msg.arg2 != 0;
9004
9005 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009006 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009007 TAG, "Reporting visible in " + wtoken
9008 + " visible=" + nowVisible
9009 + " gone=" + nowGone);
9010 if (nowVisible) {
9011 wtoken.appToken.windowsVisible();
9012 } else {
9013 wtoken.appToken.windowsGone();
9014 }
9015 } catch (RemoteException ex) {
9016 }
9017 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 case WINDOW_FREEZE_TIMEOUT: {
9020 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009021 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009022 int i = mWindows.size();
9023 while (i > 0) {
9024 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009025 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009026 if (w.mOrientationChanging) {
9027 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009028 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009029 }
9030 }
9031 performLayoutAndPlaceSurfacesLocked();
9032 }
9033 break;
9034 }
Romain Guy06882f82009-06-10 13:36:04 -07009035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009036 case HOLD_SCREEN_CHANGED: {
9037 Session oldHold;
9038 Session newHold;
9039 synchronized (mWindowMap) {
9040 oldHold = mLastReportedHold;
9041 newHold = (Session)msg.obj;
9042 mLastReportedHold = newHold;
9043 }
Romain Guy06882f82009-06-10 13:36:04 -07009044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009045 if (oldHold != newHold) {
9046 try {
9047 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009048 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009049 "window",
9050 BatteryStats.WAKE_TYPE_WINDOW);
9051 }
9052 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009053 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009054 "window",
9055 BatteryStats.WAKE_TYPE_WINDOW);
9056 }
9057 } catch (RemoteException e) {
9058 }
9059 }
9060 break;
9061 }
Romain Guy06882f82009-06-10 13:36:04 -07009062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009063 case APP_TRANSITION_TIMEOUT: {
9064 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009065 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009066 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009067 "*** APP TRANSITION TIMEOUT");
9068 mAppTransitionReady = true;
9069 mAppTransitionTimeout = true;
9070 performLayoutAndPlaceSurfacesLocked();
9071 }
9072 }
9073 break;
9074 }
Romain Guy06882f82009-06-10 13:36:04 -07009075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009076 case PERSIST_ANIMATION_SCALE: {
9077 Settings.System.putFloat(mContext.getContentResolver(),
9078 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9079 Settings.System.putFloat(mContext.getContentResolver(),
9080 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9081 break;
9082 }
Romain Guy06882f82009-06-10 13:36:04 -07009083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 case FORCE_GC: {
9085 synchronized(mWindowMap) {
9086 if (mAnimationPending) {
9087 // If we are animating, don't do the gc now but
9088 // delay a bit so we don't interrupt the animation.
9089 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9090 2000);
9091 return;
9092 }
9093 // If we are currently rotating the display, it will
9094 // schedule a new message when done.
9095 if (mDisplayFrozen) {
9096 return;
9097 }
9098 mFreezeGcPending = 0;
9099 }
9100 Runtime.getRuntime().gc();
9101 break;
9102 }
Romain Guy06882f82009-06-10 13:36:04 -07009103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009104 case ENABLE_SCREEN: {
9105 performEnableScreen();
9106 break;
9107 }
Romain Guy06882f82009-06-10 13:36:04 -07009108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009109 case APP_FREEZE_TIMEOUT: {
9110 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009111 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009112 int i = mAppTokens.size();
9113 while (i > 0) {
9114 i--;
9115 AppWindowToken tok = mAppTokens.get(i);
9116 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009117 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 unsetAppFreezingScreenLocked(tok, true, true);
9119 }
9120 }
9121 }
9122 break;
9123 }
Romain Guy06882f82009-06-10 13:36:04 -07009124
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009125 case SEND_NEW_CONFIGURATION: {
9126 removeMessages(SEND_NEW_CONFIGURATION);
9127 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009128 break;
9129 }
Romain Guy06882f82009-06-10 13:36:04 -07009130
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009131 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009132 if (mWindowsChanged) {
9133 synchronized (mWindowMap) {
9134 mWindowsChanged = false;
9135 }
9136 notifyWindowsChanged();
9137 }
9138 break;
9139 }
9140
Christopher Tatea53146c2010-09-07 11:57:52 -07009141 case DRAG_START_TIMEOUT: {
9142 IBinder win = (IBinder)msg.obj;
9143 if (DEBUG_DRAG) {
9144 Slog.w(TAG, "Timeout starting drag by win " + win);
9145 }
9146 synchronized (mWindowMap) {
9147 // !!! TODO: ANR the app that has failed to start the drag in time
9148 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009149 mDragState.unregister();
9150 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009151 mDragState.reset();
9152 mDragState = null;
9153 }
9154 }
Chris Tated4533f142010-10-19 15:15:08 -07009155 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009156 }
9157
Chris Tated4533f142010-10-19 15:15:08 -07009158 case DRAG_END_TIMEOUT: {
9159 IBinder win = (IBinder)msg.obj;
9160 if (DEBUG_DRAG) {
9161 Slog.w(TAG, "Timeout ending drag to win " + win);
9162 }
9163 synchronized (mWindowMap) {
9164 // !!! TODO: ANR the drag-receiving app
9165 mDragState.mDragResult = false;
9166 mDragState.endDragLw();
9167 }
9168 break;
9169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009170 }
9171 }
9172 }
9173
9174 // -------------------------------------------------------------
9175 // IWindowManager API
9176 // -------------------------------------------------------------
9177
9178 public IWindowSession openSession(IInputMethodClient client,
9179 IInputContext inputContext) {
9180 if (client == null) throw new IllegalArgumentException("null client");
9181 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009182 Session session = new Session(client, inputContext);
9183 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 }
9185
9186 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9187 synchronized (mWindowMap) {
9188 // The focus for the client is the window immediately below
9189 // where we would place the input method window.
9190 int idx = findDesiredInputMethodWindowIndexLocked(false);
9191 WindowState imFocus;
9192 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009193 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009194 if (imFocus != null) {
9195 if (imFocus.mSession.mClient != null &&
9196 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9197 return true;
9198 }
9199 }
9200 }
9201 }
9202 return false;
9203 }
Romain Guy06882f82009-06-10 13:36:04 -07009204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 // -------------------------------------------------------------
9206 // Internals
9207 // -------------------------------------------------------------
9208
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009209 final WindowState windowForClientLocked(Session session, IWindow client,
9210 boolean throwOnError) {
9211 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009212 }
Romain Guy06882f82009-06-10 13:36:04 -07009213
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009214 final WindowState windowForClientLocked(Session session, IBinder client,
9215 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009216 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009217 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 TAG, "Looking up client " + client + ": " + win);
9219 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009220 RuntimeException ex = new IllegalArgumentException(
9221 "Requested window " + client + " does not exist");
9222 if (throwOnError) {
9223 throw ex;
9224 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009225 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 return null;
9227 }
9228 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009229 RuntimeException ex = new IllegalArgumentException(
9230 "Requested window " + client + " is in session " +
9231 win.mSession + ", not " + session);
9232 if (throwOnError) {
9233 throw ex;
9234 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009235 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 return null;
9237 }
9238
9239 return win;
9240 }
9241
Dianne Hackborna8f60182009-09-01 19:01:50 -07009242 final void rebuildAppWindowListLocked() {
9243 int NW = mWindows.size();
9244 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009245 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009246 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009247
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009248 if (mRebuildTmp.length < NW) {
9249 mRebuildTmp = new WindowState[NW+10];
9250 }
9251
Dianne Hackborna8f60182009-09-01 19:01:50 -07009252 // First remove all existing app windows.
9253 i=0;
9254 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009255 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009256 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009257 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009258 win.mRebuilding = true;
9259 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009260 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009261 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009262 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009263 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009264 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009265 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009266 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9267 && lastWallpaper == i-1) {
9268 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009269 }
9270 i++;
9271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009272
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009273 // The wallpaper window(s) typically live at the bottom of the stack,
9274 // so skip them before adding app tokens.
9275 lastWallpaper++;
9276 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009277
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009278 // First add all of the exiting app tokens... these are no longer
9279 // in the main app list, but still have windows shown. We put them
9280 // in the back because now that the animation is over we no longer
9281 // will care about them.
9282 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009283 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009284 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9285 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009286
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009287 // And add in the still active app tokens in Z order.
9288 NT = mAppTokens.size();
9289 for (int j=0; j<NT; j++) {
9290 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009292
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009293 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009294 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009295 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009296 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009297 for (i=0; i<numRemoved; i++) {
9298 WindowState ws = mRebuildTmp[i];
9299 if (ws.mRebuilding) {
9300 StringWriter sw = new StringWriter();
9301 PrintWriter pw = new PrintWriter(sw);
9302 ws.dump(pw, "");
9303 pw.flush();
9304 Slog.w(TAG, "This window was lost: " + ws);
9305 Slog.w(TAG, sw.toString());
9306 }
9307 }
9308 Slog.w(TAG, "Current app token list:");
9309 dumpAppTokensLocked();
9310 Slog.w(TAG, "Final window list:");
9311 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009312 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009313 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009315 private final void assignLayersLocked() {
9316 int N = mWindows.size();
9317 int curBaseLayer = 0;
9318 int curLayer = 0;
9319 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009320
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009321 if (DEBUG_LAYERS) {
9322 RuntimeException here = new RuntimeException("here");
9323 here.fillInStackTrace();
9324 Log.v(TAG, "Assigning layers", here);
9325 }
9326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009328 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009329 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9330 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009331 curLayer += WINDOW_LAYER_MULTIPLIER;
9332 w.mLayer = curLayer;
9333 } else {
9334 curBaseLayer = curLayer = w.mBaseLayer;
9335 w.mLayer = curLayer;
9336 }
9337 if (w.mTargetAppToken != null) {
9338 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9339 } else if (w.mAppToken != null) {
9340 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9341 } else {
9342 w.mAnimLayer = w.mLayer;
9343 }
9344 if (w.mIsImWindow) {
9345 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009346 } else if (w.mIsWallpaper) {
9347 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009348 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009349 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009350 + w.mAnimLayer);
9351 //System.out.println(
9352 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9353 }
9354 }
9355
9356 private boolean mInLayout = false;
9357 private final void performLayoutAndPlaceSurfacesLocked() {
9358 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009359 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009360 throw new RuntimeException("Recursive call!");
9361 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009362 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009363 return;
9364 }
9365
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009366 if (mWaitingForConfig) {
9367 // Our configuration has changed (most likely rotation), but we
9368 // don't yet have the complete configuration to report to
9369 // applications. Don't do any window layout until we have it.
9370 return;
9371 }
9372
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009373 if (mDisplay == null) {
9374 // Not yet initialized, nothing to do.
9375 return;
9376 }
9377
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009378 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009380
9381 try {
9382 if (mForceRemoves != null) {
9383 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009384 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009385 for (int i=0; i<mForceRemoves.size(); i++) {
9386 WindowState ws = mForceRemoves.get(i);
9387 Slog.i(TAG, "Force removing: " + ws);
9388 removeWindowInnerLocked(ws.mSession, ws);
9389 }
9390 mForceRemoves = null;
9391 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9392 Object tmp = new Object();
9393 synchronized (tmp) {
9394 try {
9395 tmp.wait(250);
9396 } catch (InterruptedException e) {
9397 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 }
9399 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009400 } catch (RuntimeException e) {
9401 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009402 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 try {
9405 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009406
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009407 int N = mPendingRemove.size();
9408 if (N > 0) {
9409 if (mPendingRemoveTmp.length < N) {
9410 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009412 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009413 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009414 for (int i=0; i<N; i++) {
9415 WindowState w = mPendingRemoveTmp[i];
9416 removeWindowInnerLocked(w.mSession, w);
9417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009418
9419 mInLayout = false;
9420 assignLayersLocked();
9421 mLayoutNeeded = true;
9422 performLayoutAndPlaceSurfacesLocked();
9423
9424 } else {
9425 mInLayout = false;
9426 if (mLayoutNeeded) {
9427 requestAnimationLocked(0);
9428 }
9429 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009430 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009431 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9432 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434 } catch (RuntimeException e) {
9435 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009436 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009437 }
9438 }
9439
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009440 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009441 if (!mLayoutNeeded) {
9442 return 0;
9443 }
9444
9445 mLayoutNeeded = false;
9446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447 final int dw = mDisplay.getWidth();
9448 final int dh = mDisplay.getHeight();
9449
9450 final int N = mWindows.size();
9451 int i;
9452
Joe Onorato8a9b2202010-02-26 18:56:32 -08009453 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009454 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9455
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009456 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009457
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009458 int seq = mLayoutSeq+1;
9459 if (seq < 0) seq = 0;
9460 mLayoutSeq = seq;
9461
9462 // First perform layout of any root windows (not attached
9463 // to another window).
9464 int topAttached = -1;
9465 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009466 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009467
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009468 // Don't do layout of a window if it is not visible, or
9469 // soon won't be visible, to avoid wasting time and funky
9470 // changes while a window is animating away.
9471 final AppWindowToken atoken = win.mAppToken;
9472 final boolean gone = win.mViewVisibility == View.GONE
9473 || !win.mRelayoutCalled
9474 || win.mRootToken.hidden
9475 || (atoken != null && atoken.hiddenRequested)
9476 || win.mAttachedHidden
9477 || win.mExiting || win.mDestroying;
9478
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009479 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9480 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009481 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9482 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009483 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009484 + win.mViewVisibility + " mRelayoutCalled="
9485 + win.mRelayoutCalled + " hidden="
9486 + win.mRootToken.hidden + " hiddenRequested="
9487 + (atoken != null && atoken.hiddenRequested)
9488 + " mAttachedHidden=" + win.mAttachedHidden);
9489 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009490
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009491 // If this view is GONE, then skip it -- keep the current
9492 // frame, and let the caller know so they can ignore it
9493 // if they want. (We do the normal layout for INVISIBLE
9494 // windows, since that means "perform layout as normal,
9495 // just don't display").
9496 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009497 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009498 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009499 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009500 win.mContentChanged = false;
9501 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009502 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9503 win.mLayoutSeq = seq;
9504 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9505 + win.mFrame + " mContainingFrame="
9506 + win.mContainingFrame + " mDisplayFrame="
9507 + win.mDisplayFrame);
9508 } else {
9509 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009510 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009511 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009512 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009513
9514 // Now perform layout of attached windows, which usually
9515 // depend on the position of the window they are attached to.
9516 // XXX does not deal with windows that are attached to windows
9517 // that are themselves attached.
9518 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009519 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009520
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009521 if (win.mLayoutAttached) {
9522 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9523 + " mHaveFrame=" + win.mHaveFrame
9524 + " mViewVisibility=" + win.mViewVisibility
9525 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009526 // If this view is GONE, then skip it -- keep the current
9527 // frame, and let the caller know so they can ignore it
9528 // if they want. (We do the normal layout for INVISIBLE
9529 // windows, since that means "perform layout as normal,
9530 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009531 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9532 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009533 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009534 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009535 win.mContentChanged = false;
9536 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009537 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9538 win.mLayoutSeq = seq;
9539 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9540 + win.mFrame + " mContainingFrame="
9541 + win.mContainingFrame + " mDisplayFrame="
9542 + win.mDisplayFrame);
9543 }
9544 }
9545 }
Jeff Brown349703e2010-06-22 01:27:15 -07009546
9547 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009548 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009549
9550 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 }
Romain Guy06882f82009-06-10 13:36:04 -07009552
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009553 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009554 private final void performLayoutAndPlaceSurfacesLockedInner(
9555 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009556 if (mDisplay == null) {
9557 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9558 return;
9559 }
9560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009561 final long currentTime = SystemClock.uptimeMillis();
9562 final int dw = mDisplay.getWidth();
9563 final int dh = mDisplay.getHeight();
9564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 int i;
9566
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009567 if (mFocusMayChange) {
9568 mFocusMayChange = false;
9569 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9570 }
9571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 // Initialize state of exiting tokens.
9573 for (i=mExitingTokens.size()-1; i>=0; i--) {
9574 mExitingTokens.get(i).hasVisible = false;
9575 }
9576
9577 // Initialize state of exiting applications.
9578 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9579 mExitingAppTokens.get(i).hasVisible = false;
9580 }
9581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009582 boolean orientationChangeComplete = true;
9583 Session holdScreen = null;
9584 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009585 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 boolean focusDisplayed = false;
9587 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009588 boolean createWatermark = false;
9589
9590 if (mFxSession == null) {
9591 mFxSession = new SurfaceSession();
9592 createWatermark = true;
9593 }
9594
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009595 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009596
9597 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009598
9599 if (createWatermark) {
9600 createWatermark();
9601 }
9602 if (mWatermark != null) {
9603 mWatermark.positionSurface(dw, dh);
9604 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009605 if (mStrictModeFlash != null) {
9606 mStrictModeFlash.positionSurface(dw, dh);
9607 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009609 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009610 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009611 int repeats = 0;
9612 int changes = 0;
9613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009614 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009615 repeats++;
9616 if (repeats > 6) {
9617 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9618 mLayoutNeeded = false;
9619 break;
9620 }
9621
9622 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9623 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9624 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9625 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9626 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9627 assignLayersLocked();
9628 mLayoutNeeded = true;
9629 }
9630 }
9631 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9632 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009633 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009634 mLayoutNeeded = true;
9635 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9636 }
9637 }
9638 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9639 mLayoutNeeded = true;
9640 }
9641 }
9642
9643 // FIRST LOOP: Perform a layout, if needed.
9644 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009645 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009646 if (changes != 0) {
9647 continue;
9648 }
9649 } else {
9650 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9651 changes = 0;
9652 }
9653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009654 final int transactionSequence = ++mTransactionSequence;
9655
9656 // Update animations of all applications, including those
9657 // associated with exiting/removed apps
9658 boolean tokensAnimating = false;
9659 final int NAT = mAppTokens.size();
9660 for (i=0; i<NAT; i++) {
9661 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9662 tokensAnimating = true;
9663 }
9664 }
9665 final int NEAT = mExitingAppTokens.size();
9666 for (i=0; i<NEAT; i++) {
9667 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9668 tokensAnimating = true;
9669 }
9670 }
9671
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009672 // SECOND LOOP: Execute animations and update visibility of windows.
9673
Joe Onorato8a9b2202010-02-26 18:56:32 -08009674 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009675 + transactionSequence + " tokensAnimating="
9676 + tokensAnimating);
9677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009678 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009679
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009680 if (mScreenRotationAnimation != null) {
9681 if (mScreenRotationAnimation.isAnimating()) {
9682 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9683 animating = true;
9684 } else {
9685 mScreenRotationAnimation = null;
9686 }
9687 }
9688 }
9689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009690 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009691 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009692 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009693 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009694
9695 mPolicy.beginAnimationLw(dw, dh);
9696
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009697 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009699 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009700 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009701
9702 final WindowManager.LayoutParams attrs = w.mAttrs;
9703
9704 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009705 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009706 if (w.commitFinishDrawingLocked(currentTime)) {
9707 if ((w.mAttrs.flags
9708 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009709 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009710 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009711 wallpaperMayChange = true;
9712 }
9713 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009714
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009715 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009716
9717 int animDw = dw;
9718 int animDh = dh;
9719
9720 // If the window has moved due to its containing
9721 // content frame changing, then we'd like to animate
9722 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009723 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009724 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009725 // Frame has moved, containing content frame
9726 // has also moved, and we're not currently animating...
9727 // let's do something.
9728 Animation a = AnimationUtils.loadAnimation(mContext,
9729 com.android.internal.R.anim.window_move_from_decor);
9730 w.setAnimation(a);
9731 animDw = w.mLastFrame.left - w.mFrame.left;
9732 animDh = w.mLastFrame.top - w.mFrame.top;
9733 }
9734
9735 // Execute animation.
9736 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9737 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009738
9739 // If this window is animating, make a note that we have
9740 // an animating window and take care of a request to run
9741 // a detached wallpaper animation.
9742 if (nowAnimating) {
9743 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9744 windowDetachedWallpaper = w;
9745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009747 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009748
9749 // If this window's app token is running a detached wallpaper
9750 // animation, make a note so we can ensure the wallpaper is
9751 // displayed behind it.
9752 if (w.mAppToken != null && w.mAppToken.animation != null
9753 && w.mAppToken.animation.getDetachWallpaper()) {
9754 windowDetachedWallpaper = w;
9755 }
9756
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009757 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9758 wallpaperMayChange = true;
9759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009760
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009761 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009762 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009763 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009764 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009765 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009766 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009767 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009768 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9769 forceHiding = true;
9770 }
9771 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9772 boolean changed;
9773 if (forceHiding) {
9774 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009775 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9776 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009777 } else {
9778 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009779 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9780 "Now policy shown: " + w);
9781 if (changed) {
9782 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009783 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009784 // Assume we will need to animate. If
9785 // we don't (because the wallpaper will
9786 // stay with the lock screen), then we will
9787 // clean up later.
9788 Animation a = mPolicy.createForceHideEnterAnimation();
9789 if (a != null) {
9790 w.setAnimation(a);
9791 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009792 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009793 if (mCurrentFocus == null ||
9794 mCurrentFocus.mLayer < w.mLayer) {
9795 // We are showing on to of the current
9796 // focus, so re-evaluate focus to make
9797 // sure it is correct.
9798 mFocusMayChange = true;
9799 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009800 }
9801 }
9802 if (changed && (attrs.flags
9803 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9804 wallpaperMayChange = true;
9805 }
9806 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 mPolicy.animatingWindowLw(w, attrs);
9809 }
9810
9811 final AppWindowToken atoken = w.mAppToken;
9812 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9813 if (atoken.lastTransactionSequence != transactionSequence) {
9814 atoken.lastTransactionSequence = transactionSequence;
9815 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9816 atoken.startingDisplayed = false;
9817 }
9818 if ((w.isOnScreen() || w.mAttrs.type
9819 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9820 && !w.mExiting && !w.mDestroying) {
9821 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009822 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009823 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009824 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009825 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009826 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 + " pv=" + w.mPolicyVisibility
9828 + " dp=" + w.mDrawPending
9829 + " cdp=" + w.mCommitDrawPending
9830 + " ah=" + w.mAttachedHidden
9831 + " th=" + atoken.hiddenRequested
9832 + " a=" + w.mAnimating);
9833 }
9834 }
9835 if (w != atoken.startingWindow) {
9836 if (!atoken.freezingScreen || !w.mAppFreezing) {
9837 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009838 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009840 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009841 "tokenMayBeDrawn: " + atoken
9842 + " freezingScreen=" + atoken.freezingScreen
9843 + " mAppFreezing=" + w.mAppFreezing);
9844 tokenMayBeDrawn = true;
9845 }
9846 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009847 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 atoken.startingDisplayed = true;
9849 }
9850 }
9851 } else if (w.mReadyToShow) {
9852 w.performShowLocked();
9853 }
9854 }
9855
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009856 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009857
9858 if (tokenMayBeDrawn) {
9859 // See if any windows have been drawn, so they (and others
9860 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009861 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009862 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009863 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009864 if (wtoken.freezingScreen) {
9865 int numInteresting = wtoken.numInterestingWindows;
9866 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009867 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 "allDrawn: " + wtoken
9869 + " interesting=" + numInteresting
9870 + " drawn=" + wtoken.numDrawnWindows);
9871 wtoken.showAllWindowsLocked();
9872 unsetAppFreezingScreenLocked(wtoken, false, true);
9873 orientationChangeComplete = true;
9874 }
9875 } else if (!wtoken.allDrawn) {
9876 int numInteresting = wtoken.numInterestingWindows;
9877 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009878 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009879 "allDrawn: " + wtoken
9880 + " interesting=" + numInteresting
9881 + " drawn=" + wtoken.numDrawnWindows);
9882 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009883 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009884
9885 // We can now show all of the drawn windows!
9886 if (!mOpeningApps.contains(wtoken)) {
9887 wtoken.showAllWindowsLocked();
9888 }
9889 }
9890 }
9891 }
9892 }
9893
9894 // If we are ready to perform an app transition, check through
9895 // all of the app tokens to be shown and see if they are ready
9896 // to go.
9897 if (mAppTransitionReady) {
9898 int NN = mOpeningApps.size();
9899 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009900 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009901 "Checking " + NN + " opening apps (frozen="
9902 + mDisplayFrozen + " timeout="
9903 + mAppTransitionTimeout + ")...");
9904 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9905 // If the display isn't frozen, wait to do anything until
9906 // all of the apps are ready. Otherwise just go because
9907 // we'll unfreeze the display when everyone is ready.
9908 for (i=0; i<NN && goodToGo; i++) {
9909 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009910 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009911 "Check opening app" + wtoken + ": allDrawn="
9912 + wtoken.allDrawn + " startingDisplayed="
9913 + wtoken.startingDisplayed);
9914 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9915 && !wtoken.startingMoved) {
9916 goodToGo = false;
9917 }
9918 }
9919 }
9920 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009921 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 int transit = mNextAppTransition;
9923 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009924 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009925 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009926 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009927 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009928 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 mAppTransitionTimeout = false;
9930 mStartingIconInTransition = false;
9931 mSkipAppTransitionAnimation = false;
9932
9933 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9934
Dianne Hackborna8f60182009-09-01 19:01:50 -07009935 // If there are applications waiting to come to the
9936 // top of the stack, now is the time to move their windows.
9937 // (Note that we don't do apps going to the bottom
9938 // here -- we want to keep their windows in the old
9939 // Z-order until the animation completes.)
9940 if (mToTopApps.size() > 0) {
9941 NN = mAppTokens.size();
9942 for (i=0; i<NN; i++) {
9943 AppWindowToken wtoken = mAppTokens.get(i);
9944 if (wtoken.sendingToTop) {
9945 wtoken.sendingToTop = false;
9946 moveAppWindowsLocked(wtoken, NN, false);
9947 }
9948 }
9949 mToTopApps.clear();
9950 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009951
Dianne Hackborn25994b42009-09-04 14:21:19 -07009952 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009953
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009954 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009955 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009956
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009957 // The top-most window will supply the layout params,
9958 // and we will determine it below.
9959 LayoutParams animLp = null;
9960 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08009961 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009962
Joe Onorato8a9b2202010-02-26 18:56:32 -08009963 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009964 "New wallpaper target=" + mWallpaperTarget
9965 + ", lower target=" + mLowerWallpaperTarget
9966 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009967 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009968 // Do a first pass through the tokens for two
9969 // things:
9970 // (1) Determine if both the closing and opening
9971 // app token sets are wallpaper targets, in which
9972 // case special animations are needed
9973 // (since the wallpaper needs to stay static
9974 // behind them).
9975 // (2) Find the layout params of the top-most
9976 // application window in the tokens, which is
9977 // what will control the animation theme.
9978 final int NC = mClosingApps.size();
9979 NN = NC + mOpeningApps.size();
9980 for (i=0; i<NN; i++) {
9981 AppWindowToken wtoken;
9982 int mode;
9983 if (i < NC) {
9984 wtoken = mClosingApps.get(i);
9985 mode = 1;
9986 } else {
9987 wtoken = mOpeningApps.get(i-NC);
9988 mode = 2;
9989 }
9990 if (mLowerWallpaperTarget != null) {
9991 if (mLowerWallpaperTarget.mAppToken == wtoken
9992 || mUpperWallpaperTarget.mAppToken == wtoken) {
9993 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009994 }
9995 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009996 if (wtoken.appFullscreen) {
9997 WindowState ws = wtoken.findMainWindow();
9998 if (ws != null) {
9999 // If this is a compatibility mode
10000 // window, we will always use its anim.
10001 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10002 animLp = ws.mAttrs;
10003 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010004 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010005 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010006 bestAnimLayer = ws.mLayer;
10007 }
10008 fullscreenAnim = true;
10009 }
10010 } else if (!fullscreenAnim) {
10011 WindowState ws = wtoken.findMainWindow();
10012 if (ws != null) {
10013 if (ws.mLayer > bestAnimLayer) {
10014 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010015 bestAnimLayer = ws.mLayer;
10016 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010017 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010018 }
10019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010020
Dianne Hackborn25994b42009-09-04 14:21:19 -070010021 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010022 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010023 "Wallpaper animation!");
10024 switch (transit) {
10025 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10026 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10027 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10028 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10029 break;
10030 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10031 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10032 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10033 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10034 break;
10035 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010036 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010037 "New transit: " + transit);
10038 } else if (oldWallpaper != null) {
10039 // We are transitioning from an activity with
10040 // a wallpaper to one without.
10041 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010042 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010043 "New transit away from wallpaper: " + transit);
10044 } else if (mWallpaperTarget != null) {
10045 // We are transitioning from an activity without
10046 // a wallpaper to now showing the wallpaper
10047 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010048 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010049 "New transit into wallpaper: " + transit);
10050 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010051
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010052 // If all closing windows are obscured, then there is
10053 // no need to do an animation. This is the case, for
10054 // example, when this transition is being done behind
10055 // the lock screen.
10056 if (!mPolicy.allowAppAnimationsLw()) {
10057 animLp = null;
10058 }
10059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010060 NN = mOpeningApps.size();
10061 for (i=0; i<NN; i++) {
10062 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010063 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010064 "Now opening app" + wtoken);
10065 wtoken.reportedVisible = false;
10066 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010067 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010068 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010070 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 wtoken.showAllWindowsLocked();
10072 }
10073 NN = mClosingApps.size();
10074 for (i=0; i<NN; i++) {
10075 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010076 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 "Now closing app" + wtoken);
10078 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010079 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010080 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010082 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010083 // Force the allDrawn flag, because we want to start
10084 // this guy's animations regardless of whether it's
10085 // gotten drawn.
10086 wtoken.allDrawn = true;
10087 }
10088
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010089 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010091 mOpeningApps.clear();
10092 mClosingApps.clear();
10093
10094 // This has changed the visibility of windows, so perform
10095 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010096 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10097 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010098 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010099 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10100 assignLayersLocked();
10101 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010102 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010103 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010104 }
10105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010106
Dianne Hackborn16064f92010-03-25 00:47:24 -070010107 int adjResult = 0;
10108
Dianne Hackborna8f60182009-09-01 19:01:50 -070010109 if (!animating && mAppTransitionRunning) {
10110 // We have finished the animation of an app transition. To do
10111 // this, we have delayed a lot of operations like showing and
10112 // hiding apps, moving apps in Z-order, etc. The app token list
10113 // reflects the correct Z-order, but the window list may now
10114 // be out of sync with it. So here we will just rebuild the
10115 // entire app window list. Fun!
10116 mAppTransitionRunning = false;
10117 // Clear information about apps that were moving.
10118 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010119
Dianne Hackborna8f60182009-09-01 19:01:50 -070010120 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010121 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010122 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010123 moveInputMethodWindowsIfNeededLocked(false);
10124 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010125 // Since the window list has been rebuilt, focus might
10126 // have to be recomputed since the actual order of windows
10127 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010128 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010130
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010131 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010132 // At this point, there was a window with a wallpaper that
10133 // was force hiding other windows behind it, but now it
10134 // is going away. This may be simple -- just animate
10135 // away the wallpaper and its window -- or it may be
10136 // hard -- the wallpaper now needs to be shown behind
10137 // something that was hidden.
10138 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010139 if (mLowerWallpaperTarget != null
10140 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010141 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010142 "wallpaperForceHiding changed with lower="
10143 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010144 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010145 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10146 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10147 if (mLowerWallpaperTarget.mAppToken.hidden) {
10148 // The lower target has become hidden before we
10149 // actually started the animation... let's completely
10150 // re-evaluate everything.
10151 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010152 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010153 }
10154 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010155 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010156 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010157 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010158 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010159 + " NEW: " + mWallpaperTarget
10160 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010161 if (mLowerWallpaperTarget == null) {
10162 // Whoops, we don't need a special wallpaper animation.
10163 // Clear them out.
10164 forceHiding = false;
10165 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010166 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010167 if (w.mSurface != null) {
10168 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010169 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010170 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010171 forceHiding = true;
10172 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10173 if (!w.mAnimating) {
10174 // We set the animation above so it
10175 // is not yet running.
10176 w.clearAnimation();
10177 }
10178 }
10179 }
10180 }
10181 }
10182 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010183
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010184 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10185 if (DEBUG_WALLPAPER) Slog.v(TAG,
10186 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10187 + windowDetachedWallpaper);
10188 mWindowDetachedWallpaper = windowDetachedWallpaper;
10189 wallpaperMayChange = true;
10190 }
10191
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010192 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010193 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010194 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010195 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010196 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010197
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010198 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010199 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010200 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010201 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010202 assignLayersLocked();
10203 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010204 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010205 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010206 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010207 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010208
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010209 if (mFocusMayChange) {
10210 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010211 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010212 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010213 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010214 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010215 }
10216
10217 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010218 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010219 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010220
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010221 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10222 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010223
Jeff Browne33348b2010-07-15 23:54:05 -070010224 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010225 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010226
10227 // THIRD LOOP: Update the surfaces of all windows.
10228
10229 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10230
10231 boolean obscured = false;
10232 boolean blurring = false;
10233 boolean dimming = false;
10234 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010235 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010236 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010237
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010238 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010240 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010241 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010242
10243 boolean displayed = false;
10244 final WindowManager.LayoutParams attrs = w.mAttrs;
10245 final int attrFlags = attrs.flags;
10246
10247 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010248 // XXX NOTE: The logic here could be improved. We have
10249 // the decision about whether to resize a window separated
10250 // from whether to hide the surface. This can cause us to
10251 // resize a surface even if we are going to hide it. You
10252 // can see this by (1) holding device in landscape mode on
10253 // home screen; (2) tapping browser icon (device will rotate
10254 // to landscape; (3) tap home. The wallpaper will be resized
10255 // in step 2 but then immediately hidden, causing us to
10256 // have to resize and then redraw it again in step 3. It
10257 // would be nice to figure out how to avoid this, but it is
10258 // difficult because we do need to resize surfaces in some
10259 // cases while they are hidden such as when first showing a
10260 // window.
10261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010262 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010263 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010264 TAG, "Placing surface #" + i + " " + w.mSurface
10265 + ": new=" + w.mShownFrame + ", old="
10266 + w.mLastShownFrame);
10267
10268 boolean resize;
10269 int width, height;
10270 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10271 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10272 w.mLastRequestedHeight != w.mRequestedHeight;
10273 // for a scaled surface, we just want to use
10274 // the requested size.
10275 width = w.mRequestedWidth;
10276 height = w.mRequestedHeight;
10277 w.mLastRequestedWidth = width;
10278 w.mLastRequestedHeight = height;
10279 w.mLastShownFrame.set(w.mShownFrame);
10280 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010281 if (SHOW_TRANSACTIONS) logSurface(w,
10282 "POS " + w.mShownFrame.left
10283 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010284 w.mSurfaceX = w.mShownFrame.left;
10285 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10287 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010288 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 if (!recoveringMemory) {
10290 reclaimSomeSurfaceMemoryLocked(w, "position");
10291 }
10292 }
10293 } else {
10294 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10295 width = w.mShownFrame.width();
10296 height = w.mShownFrame.height();
10297 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010298 }
10299
10300 if (resize) {
10301 if (width < 1) width = 1;
10302 if (height < 1) height = 1;
10303 if (w.mSurface != null) {
10304 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010305 if (SHOW_TRANSACTIONS) logSurface(w,
10306 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010307 + w.mShownFrame.top + " SIZE "
10308 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010309 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010310 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010311 w.mSurfaceW = width;
10312 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010314 w.mSurfaceX = w.mShownFrame.left;
10315 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010316 w.mSurface.setPosition(w.mShownFrame.left,
10317 w.mShownFrame.top);
10318 } catch (RuntimeException e) {
10319 // If something goes wrong with the surface (such
10320 // as running out of memory), don't take down the
10321 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010322 Slog.e(TAG, "Failure updating surface of " + w
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010323 + " size=(" + width + "x" + height
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 + "), pos=(" + w.mShownFrame.left
10325 + "," + w.mShownFrame.top + ")", e);
10326 if (!recoveringMemory) {
10327 reclaimSomeSurfaceMemoryLocked(w, "size");
10328 }
10329 }
10330 }
10331 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010332 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010333 w.mContentInsetsChanged =
10334 !w.mLastContentInsets.equals(w.mContentInsets);
10335 w.mVisibleInsetsChanged =
10336 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010337 boolean configChanged =
10338 w.mConfiguration != mCurConfiguration
10339 && (w.mConfiguration == null
10340 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010341 if (DEBUG_CONFIGURATION && configChanged) {
10342 Slog.v(TAG, "Win " + w + " config changed: "
10343 + mCurConfiguration);
10344 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010345 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010346 + ": configChanged=" + configChanged
10347 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010348 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010349 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010350 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010351 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010352 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 w.mLastFrame.set(w.mFrame);
10354 w.mLastContentInsets.set(w.mContentInsets);
10355 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010356 // If the screen is currently frozen, then keep
10357 // it frozen until this window draws at its new
10358 // orientation.
10359 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010360 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010361 "Resizing while display frozen: " + w);
10362 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010363 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010364 mWindowsFreezingScreen = true;
10365 // XXX should probably keep timeout from
10366 // when we first froze the display.
10367 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10368 mH.sendMessageDelayed(mH.obtainMessage(
10369 H.WINDOW_FREEZE_TIMEOUT), 2000);
10370 }
10371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010372 // If the orientation is changing, then we need to
10373 // hold off on unfreezing the display until this
10374 // window has been redrawn; to do that, we need
10375 // to go through the process of getting informed
10376 // by the application when it has finished drawing.
10377 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010378 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010379 "Orientation start waiting for draw in "
10380 + w + ", surface " + w.mSurface);
10381 w.mDrawPending = true;
10382 w.mCommitDrawPending = false;
10383 w.mReadyToShow = false;
10384 if (w.mAppToken != null) {
10385 w.mAppToken.allDrawn = false;
10386 }
10387 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010388 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010389 "Resizing window " + w + " to " + w.mFrame);
10390 mResizingWindows.add(w);
10391 } else if (w.mOrientationChanging) {
10392 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010393 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 "Orientation not waiting for draw in "
10395 + w + ", surface " + w.mSurface);
10396 w.mOrientationChanging = false;
10397 }
10398 }
10399 }
10400
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010401 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010402 if (!w.mLastHidden) {
10403 //dump();
10404 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010405 if (SHOW_TRANSACTIONS) logSurface(w,
10406 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010407 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010408 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010409 try {
10410 w.mSurface.hide();
10411 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010412 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 }
10414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010415 }
10416 // If we are waiting for this window to handle an
10417 // orientation change, well, it is hidden, so
10418 // doesn't really matter. Note that this does
10419 // introduce a potential glitch if the window
10420 // becomes unhidden before it has drawn for the
10421 // new orientation.
10422 if (w.mOrientationChanging) {
10423 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010424 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010425 "Orientation change skips hidden " + w);
10426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427 } else if (w.mLastLayer != w.mAnimLayer
10428 || w.mLastAlpha != w.mShownAlpha
10429 || w.mLastDsDx != w.mDsDx
10430 || w.mLastDtDx != w.mDtDx
10431 || w.mLastDsDy != w.mDsDy
10432 || w.mLastDtDy != w.mDtDy
10433 || w.mLastHScale != w.mHScale
10434 || w.mLastVScale != w.mVScale
10435 || w.mLastHidden) {
10436 displayed = true;
10437 w.mLastAlpha = w.mShownAlpha;
10438 w.mLastLayer = w.mAnimLayer;
10439 w.mLastDsDx = w.mDsDx;
10440 w.mLastDtDx = w.mDtDx;
10441 w.mLastDsDy = w.mDsDy;
10442 w.mLastDtDy = w.mDtDy;
10443 w.mLastHScale = w.mHScale;
10444 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010445 if (SHOW_TRANSACTIONS) logSurface(w,
10446 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010447 + " matrix=[" + (w.mDsDx*w.mHScale)
10448 + "," + (w.mDtDx*w.mVScale)
10449 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010450 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010451 if (w.mSurface != null) {
10452 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010453 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010455 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010456 w.mSurface.setLayer(w.mAnimLayer);
10457 w.mSurface.setMatrix(
10458 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10459 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10460 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010461 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010462 if (!recoveringMemory) {
10463 reclaimSomeSurfaceMemoryLocked(w, "update");
10464 }
10465 }
10466 }
10467
10468 if (w.mLastHidden && !w.mDrawPending
10469 && !w.mCommitDrawPending
10470 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010471 if (SHOW_TRANSACTIONS) logSurface(w,
10472 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010473 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010474 + " during relayout");
10475 if (showSurfaceRobustlyLocked(w)) {
10476 w.mHasDrawn = true;
10477 w.mLastHidden = false;
10478 } else {
10479 w.mOrientationChanging = false;
10480 }
10481 }
10482 if (w.mSurface != null) {
10483 w.mToken.hasVisible = true;
10484 }
10485 } else {
10486 displayed = true;
10487 }
10488
10489 if (displayed) {
10490 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010491 if (attrs.width == LayoutParams.MATCH_PARENT
10492 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 covered = true;
10494 }
10495 }
10496 if (w.mOrientationChanging) {
10497 if (w.mDrawPending || w.mCommitDrawPending) {
10498 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010499 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010500 "Orientation continue waiting for draw in " + w);
10501 } else {
10502 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010503 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 "Orientation change complete in " + w);
10505 }
10506 }
10507 w.mToken.hasVisible = true;
10508 }
10509 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010510 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 "Orientation change skips hidden " + w);
10512 w.mOrientationChanging = false;
10513 }
10514
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010515 if (w.mContentChanged) {
10516 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10517 w.mContentChanged = false;
10518 }
10519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010520 final boolean canBeSeen = w.isDisplayedLw();
10521
10522 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10523 focusDisplayed = true;
10524 }
10525
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010526 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010528 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010529 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010530 if (w.mSurface != null) {
10531 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10532 holdScreen = w.mSession;
10533 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010534 if (!syswin && w.mAttrs.screenBrightness >= 0
10535 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536 screenBrightness = w.mAttrs.screenBrightness;
10537 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010538 if (!syswin && w.mAttrs.buttonBrightness >= 0
10539 && buttonBrightness < 0) {
10540 buttonBrightness = w.mAttrs.buttonBrightness;
10541 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010542 if (canBeSeen
10543 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10544 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10545 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010546 syswin = true;
10547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010548 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010549
Dianne Hackborn25994b42009-09-04 14:21:19 -070010550 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10551 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010552 // This window completely covers everything behind it,
10553 // so we want to leave all of them as unblurred (for
10554 // performance reasons).
10555 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010556 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010557 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010558 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010559 obscured = true;
10560 if (mBackgroundFillerSurface == null) {
10561 try {
10562 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010563 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010564 0, dw, dh,
10565 PixelFormat.OPAQUE,
10566 Surface.FX_SURFACE_NORMAL);
10567 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010568 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010569 }
10570 }
10571 try {
10572 mBackgroundFillerSurface.setPosition(0, 0);
10573 mBackgroundFillerSurface.setSize(dw, dh);
10574 // Using the same layer as Dim because they will never be shown at the
10575 // same time.
10576 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10577 mBackgroundFillerSurface.show();
10578 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010579 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010580 }
10581 backgroundFillerShown = true;
10582 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010583 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010584 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010585 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010586 + ": blurring=" + blurring
10587 + " obscured=" + obscured
10588 + " displayed=" + displayed);
10589 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10590 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010591 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010592 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010593 if (mDimAnimator == null) {
10594 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010595 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010596 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010597 mDimAnimator.updateParameters(mContext.getResources(),
10598 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010600 }
10601 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10602 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010603 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010604 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010605 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010606 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010607 + mBlurSurface + ": CREATE");
10608 try {
Romain Guy06882f82009-06-10 13:36:04 -070010609 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010610 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 -1, 16, 16,
10612 PixelFormat.OPAQUE,
10613 Surface.FX_SURFACE_BLUR);
10614 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010615 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010616 }
10617 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010618 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010619 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10620 + mBlurSurface + ": pos=(0,0) (" +
10621 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010622 mBlurSurface.setPosition(0, 0);
10623 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010624 mBlurSurface.setLayer(w.mAnimLayer-2);
10625 if (!mBlurShown) {
10626 try {
10627 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10628 + mBlurSurface + ": SHOW");
10629 mBlurSurface.show();
10630 } catch (RuntimeException e) {
10631 Slog.w(TAG, "Failure showing blur surface", e);
10632 }
10633 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010634 }
10635 }
10636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010637 }
10638 }
10639 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010640
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010641 if (obscuredChanged && mWallpaperTarget == w) {
10642 // This is the wallpaper target and its obscured state
10643 // changed... make sure the current wallaper's visibility
10644 // has been updated accordingly.
10645 updateWallpaperVisibilityLocked();
10646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010648
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010649 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10650 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010651 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010652 try {
10653 mBackgroundFillerSurface.hide();
10654 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010655 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010656 }
10657 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010658
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010659 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010660 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10661 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662 }
Romain Guy06882f82009-06-10 13:36:04 -070010663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010664 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010665 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 + ": HIDE");
10667 try {
10668 mBlurSurface.hide();
10669 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010670 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010671 }
10672 mBlurShown = false;
10673 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010674 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010675 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010676 }
10677
Jeff Browne33348b2010-07-15 23:54:05 -070010678 mInputMonitor.updateInputWindowsLw();
10679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010680 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010681
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010682 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10683
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010684 if (mWatermark != null) {
10685 mWatermark.drawIfNeeded();
10686 }
10687
Joe Onorato8a9b2202010-02-26 18:56:32 -080010688 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010689 "With display frozen, orientationChangeComplete="
10690 + orientationChangeComplete);
10691 if (orientationChangeComplete) {
10692 if (mWindowsFreezingScreen) {
10693 mWindowsFreezingScreen = false;
10694 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10695 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010696 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010697 }
Romain Guy06882f82009-06-10 13:36:04 -070010698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010699 i = mResizingWindows.size();
10700 if (i > 0) {
10701 do {
10702 i--;
10703 WindowState win = mResizingWindows.get(i);
10704 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010705 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10706 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010707 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010708 boolean configChanged =
10709 win.mConfiguration != mCurConfiguration
10710 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010711 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10712 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10713 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010714 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010715 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010716 + " / " + mCurConfiguration + " / 0x"
10717 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010718 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010719 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010720 win.mClient.resized(win.mFrame.width(),
10721 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010722 win.mLastVisibleInsets, win.mDrawPending,
10723 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010724 win.mContentInsetsChanged = false;
10725 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010726 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010727 } catch (RemoteException e) {
10728 win.mOrientationChanging = false;
10729 }
10730 } while (i > 0);
10731 mResizingWindows.clear();
10732 }
Romain Guy06882f82009-06-10 13:36:04 -070010733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010734 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010735 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010736 i = mDestroySurface.size();
10737 if (i > 0) {
10738 do {
10739 i--;
10740 WindowState win = mDestroySurface.get(i);
10741 win.mDestroying = false;
10742 if (mInputMethodWindow == win) {
10743 mInputMethodWindow = null;
10744 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010745 if (win == mWallpaperTarget) {
10746 wallpaperDestroyed = true;
10747 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010748 win.destroySurfaceLocked();
10749 } while (i > 0);
10750 mDestroySurface.clear();
10751 }
10752
10753 // Time to remove any exiting tokens?
10754 for (i=mExitingTokens.size()-1; i>=0; i--) {
10755 WindowToken token = mExitingTokens.get(i);
10756 if (!token.hasVisible) {
10757 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010758 if (token.windowType == TYPE_WALLPAPER) {
10759 mWallpaperTokens.remove(token);
10760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010761 }
10762 }
10763
10764 // Time to remove any exiting applications?
10765 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10766 AppWindowToken token = mExitingAppTokens.get(i);
10767 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010768 // Make sure there is no animation running on this token,
10769 // so any windows associated with it will be removed as
10770 // soon as their animations are complete
10771 token.animation = null;
10772 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010773 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10774 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010775 mAppTokens.remove(token);
10776 mExitingAppTokens.remove(i);
10777 }
10778 }
10779
Dianne Hackborna8f60182009-09-01 19:01:50 -070010780 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010781
Dianne Hackborna8f60182009-09-01 19:01:50 -070010782 if (!animating && mAppTransitionRunning) {
10783 // We have finished the animation of an app transition. To do
10784 // this, we have delayed a lot of operations like showing and
10785 // hiding apps, moving apps in Z-order, etc. The app token list
10786 // reflects the correct Z-order, but the window list may now
10787 // be out of sync with it. So here we will just rebuild the
10788 // entire app window list. Fun!
10789 mAppTransitionRunning = false;
10790 needRelayout = true;
10791 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010792 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010793 // Clear information about apps that were moving.
10794 mToBottomApps.clear();
10795 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 if (focusDisplayed) {
10798 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10799 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010800 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010801 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010802 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010803 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010804 requestAnimationLocked(0);
10805 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010806 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10807 }
Jeff Browneb857f12010-07-16 10:06:33 -070010808
Jeff Browne33348b2010-07-15 23:54:05 -070010809 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010810
Jeff Brown8e03b752010-06-13 19:16:55 -070010811 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010812 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10813 mPowerManager.setScreenBrightnessOverride(-1);
10814 } else {
10815 mPowerManager.setScreenBrightnessOverride((int)
10816 (screenBrightness * Power.BRIGHTNESS_ON));
10817 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010818 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10819 mPowerManager.setButtonBrightnessOverride(-1);
10820 } else {
10821 mPowerManager.setButtonBrightnessOverride((int)
10822 (buttonBrightness * Power.BRIGHTNESS_ON));
10823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010824 if (holdScreen != mHoldingScreenOn) {
10825 mHoldingScreenOn = holdScreen;
10826 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10827 mH.sendMessage(m);
10828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010829
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010830 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010831 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010832 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10833 LocalPowerManager.BUTTON_EVENT, true);
10834 mTurnOnScreen = false;
10835 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010836
10837 // Check to see if we are now in a state where the screen should
10838 // be enabled, because the window obscured flags have changed.
10839 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010840 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010841
10842 /**
10843 * Must be called with the main window manager lock held.
10844 */
10845 void setHoldScreenLocked(boolean holding) {
10846 boolean state = mHoldingScreenWakeLock.isHeld();
10847 if (holding != state) {
10848 if (holding) {
10849 mHoldingScreenWakeLock.acquire();
10850 } else {
10851 mPolicy.screenOnStoppedLw();
10852 mHoldingScreenWakeLock.release();
10853 }
10854 }
10855 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010856
10857 void requestAnimationLocked(long delay) {
10858 if (!mAnimationPending) {
10859 mAnimationPending = true;
10860 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10861 }
10862 }
Romain Guy06882f82009-06-10 13:36:04 -070010863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010864 /**
10865 * Have the surface flinger show a surface, robustly dealing with
10866 * error conditions. In particular, if there is not enough memory
10867 * to show the surface, then we will try to get rid of other surfaces
10868 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010869 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010870 * @return Returns true if the surface was successfully shown.
10871 */
10872 boolean showSurfaceRobustlyLocked(WindowState win) {
10873 try {
10874 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010875 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010876 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010877 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010878 if (DEBUG_VISIBILITY) Slog.v(TAG,
10879 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010880 win.mTurnOnScreen = false;
10881 mTurnOnScreen = true;
10882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010883 }
10884 return true;
10885 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010886 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010887 }
Romain Guy06882f82009-06-10 13:36:04 -070010888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010889 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010891 return false;
10892 }
Romain Guy06882f82009-06-10 13:36:04 -070010893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010894 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10895 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010896
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010897 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010900 if (mForceRemoves == null) {
10901 mForceRemoves = new ArrayList<WindowState>();
10902 }
Romain Guy06882f82009-06-10 13:36:04 -070010903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904 long callingIdentity = Binder.clearCallingIdentity();
10905 try {
10906 // There was some problem... first, do a sanity check of the
10907 // window list to make sure we haven't left any dangling surfaces
10908 // around.
10909 int N = mWindows.size();
10910 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010911 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010912 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010913 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010914 if (ws.mSurface != null) {
10915 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010916 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010917 + ws + " surface=" + ws.mSurface
10918 + " token=" + win.mToken
10919 + " pid=" + ws.mSession.mPid
10920 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010921 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010922 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010923 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 ws.mSurface = null;
10925 mForceRemoves.add(ws);
10926 i--;
10927 N--;
10928 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010929 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010930 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010931 + ws + " surface=" + ws.mSurface
10932 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010933 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010934 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010935 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010936 ws.mSurface = null;
10937 leakedSurface = true;
10938 }
10939 }
10940 }
Romain Guy06882f82009-06-10 13:36:04 -070010941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010942 boolean killedApps = false;
10943 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010944 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010945 SparseIntArray pidCandidates = new SparseIntArray();
10946 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010947 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010948 if (ws.mSurface != null) {
10949 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10950 }
10951 }
10952 if (pidCandidates.size() > 0) {
10953 int[] pids = new int[pidCandidates.size()];
10954 for (int i=0; i<pids.length; i++) {
10955 pids[i] = pidCandidates.keyAt(i);
10956 }
10957 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010958 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010959 killedApps = true;
10960 }
10961 } catch (RemoteException e) {
10962 }
10963 }
10964 }
Romain Guy06882f82009-06-10 13:36:04 -070010965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010966 if (leakedSurface || killedApps) {
10967 // We managed to reclaim some memory, so get rid of the trouble
10968 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010969 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010970 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010971 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010972 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010973 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010974 win.mSurface = null;
10975 }
Romain Guy06882f82009-06-10 13:36:04 -070010976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010977 try {
10978 win.mClient.dispatchGetNewSurface();
10979 } catch (RemoteException e) {
10980 }
10981 }
10982 } finally {
10983 Binder.restoreCallingIdentity(callingIdentity);
10984 }
10985 }
Romain Guy06882f82009-06-10 13:36:04 -070010986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 private boolean updateFocusedWindowLocked(int mode) {
10988 WindowState newFocus = computeFocusedWindowLocked();
10989 if (mCurrentFocus != newFocus) {
10990 // This check makes sure that we don't already have the focus
10991 // change message pending.
10992 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10993 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010994 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010995 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10996 final WindowState oldFocus = mCurrentFocus;
10997 mCurrentFocus = newFocus;
10998 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011000 final WindowState imWindow = mInputMethodWindow;
11001 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011002 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011003 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011004 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11005 mLayoutNeeded = true;
11006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080011008 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011009 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11010 // Client will do the layout, but we need to assign layers
11011 // for handleNewWindowLocked() below.
11012 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011013 }
11014 }
Jeff Brown349703e2010-06-22 01:27:15 -070011015
11016 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11017 // If we defer assigning layers, then the caller is responsible for
11018 // doing this part.
11019 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011021 return true;
11022 }
11023 return false;
11024 }
Jeff Brown349703e2010-06-22 01:27:15 -070011025
11026 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011027 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070011028 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011029
11030 private WindowState computeFocusedWindowLocked() {
11031 WindowState result = null;
11032 WindowState win;
11033
11034 int i = mWindows.size() - 1;
11035 int nextAppIndex = mAppTokens.size()-1;
11036 WindowToken nextApp = nextAppIndex >= 0
11037 ? mAppTokens.get(nextAppIndex) : null;
11038
11039 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011040 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011041
Joe Onorato8a9b2202010-02-26 18:56:32 -080011042 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011043 TAG, "Looking for focus: " + i
11044 + " = " + win
11045 + ", flags=" + win.mAttrs.flags
11046 + ", canReceive=" + win.canReceiveKeys());
11047
11048 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011050 // If this window's application has been removed, just skip it.
11051 if (thisApp != null && thisApp.removed) {
11052 i--;
11053 continue;
11054 }
Romain Guy06882f82009-06-10 13:36:04 -070011055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011056 // If there is a focused app, don't allow focus to go to any
11057 // windows below it. If this is an application window, step
11058 // through the app tokens until we find its app.
11059 if (thisApp != null && nextApp != null && thisApp != nextApp
11060 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11061 int origAppIndex = nextAppIndex;
11062 while (nextAppIndex > 0) {
11063 if (nextApp == mFocusedApp) {
11064 // Whoops, we are below the focused app... no focus
11065 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011066 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011067 TAG, "Reached focused app: " + mFocusedApp);
11068 return null;
11069 }
11070 nextAppIndex--;
11071 nextApp = mAppTokens.get(nextAppIndex);
11072 if (nextApp == thisApp) {
11073 break;
11074 }
11075 }
11076 if (thisApp != nextApp) {
11077 // Uh oh, the app token doesn't exist! This shouldn't
11078 // happen, but if it does we can get totally hosed...
11079 // so restart at the original app.
11080 nextAppIndex = origAppIndex;
11081 nextApp = mAppTokens.get(nextAppIndex);
11082 }
11083 }
11084
11085 // Dispatch to this window if it is wants key events.
11086 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011087 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011088 TAG, "Found focus @ " + i + " = " + win);
11089 result = win;
11090 break;
11091 }
11092
11093 i--;
11094 }
11095
11096 return result;
11097 }
11098
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011099 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011100 if (mDisplayFrozen) {
11101 return;
11102 }
Romain Guy06882f82009-06-10 13:36:04 -070011103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011104 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011106 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011107 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011108 if (mFreezeGcPending != 0) {
11109 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011110 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011111 mH.removeMessages(H.FORCE_GC);
11112 Runtime.getRuntime().gc();
11113 mFreezeGcPending = now;
11114 }
11115 } else {
11116 mFreezeGcPending = now;
11117 }
Romain Guy06882f82009-06-10 13:36:04 -070011118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011119 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011120
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011121 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011122
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011123 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11124 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011125 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011126 mAppTransitionReady = true;
11127 }
Romain Guy06882f82009-06-10 13:36:04 -070011128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011129 if (PROFILE_ORIENTATION) {
11130 File file = new File("/data/system/frozen");
11131 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11132 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011133
11134 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011135 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11136 mScreenRotationAnimation.kill();
11137 mScreenRotationAnimation = null;
11138 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011139 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011140 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011141 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011142 }
11143 } else {
11144 Surface.freezeDisplay(0);
11145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011146 }
Romain Guy06882f82009-06-10 13:36:04 -070011147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011148 private void stopFreezingDisplayLocked() {
11149 if (!mDisplayFrozen) {
11150 return;
11151 }
Romain Guy06882f82009-06-10 13:36:04 -070011152
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011153 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11154 return;
11155 }
11156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011157 mDisplayFrozen = false;
11158 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11159 if (PROFILE_ORIENTATION) {
11160 Debug.stopMethodTracing();
11161 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011162
11163 if (CUSTOM_SCREEN_ROTATION) {
11164 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011165 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11166 mTransitionAnimationScale)) {
11167 requestAnimationLocked(0);
11168 } else {
11169 mScreenRotationAnimation = null;
11170 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011171 }
11172 } else {
11173 Surface.unfreezeDisplay(0);
11174 }
Romain Guy06882f82009-06-10 13:36:04 -070011175
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011176 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011177
Christopher Tateb696aee2010-04-02 19:08:30 -070011178 // While the display is frozen we don't re-compute the orientation
11179 // to avoid inconsistent states. However, something interesting
11180 // could have actually changed during that time so re-evaluate it
11181 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011182 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011183 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11184 }
11185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011186 // A little kludge: a lot could have happened while the
11187 // display was frozen, so now that we are coming back we
11188 // do a gc so that any remote references the system
11189 // processes holds on others can be released if they are
11190 // no longer needed.
11191 mH.removeMessages(H.FORCE_GC);
11192 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11193 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011195 mScreenFrozenLock.release();
11196 }
Romain Guy06882f82009-06-10 13:36:04 -070011197
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011198 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11199 DisplayMetrics dm) {
11200 if (index < tokens.length) {
11201 String str = tokens[index];
11202 if (str != null && str.length() > 0) {
11203 try {
11204 int val = Integer.parseInt(str);
11205 return val;
11206 } catch (Exception e) {
11207 }
11208 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011209 }
11210 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11211 return defDps;
11212 }
11213 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11214 return val;
11215 }
11216
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011217 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011218 final String[] mTokens;
11219 final String mText;
11220 final Paint mTextPaint;
11221 final int mTextWidth;
11222 final int mTextHeight;
11223 final int mTextAscent;
11224 final int mTextDescent;
11225 final int mDeltaX;
11226 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011227
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011228 Surface mSurface;
11229 int mLastDW;
11230 int mLastDH;
11231 boolean mDrawNeeded;
11232
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011233 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011234 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011235 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011236
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011237 if (false) {
11238 Log.i(TAG, "*********************** WATERMARK");
11239 for (int i=0; i<tokens.length; i++) {
11240 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11241 }
11242 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011243
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011244 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011245
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011246 StringBuilder builder = new StringBuilder(32);
11247 int len = mTokens[0].length();
11248 len = len & ~1;
11249 for (int i=0; i<len; i+=2) {
11250 int c1 = mTokens[0].charAt(i);
11251 int c2 = mTokens[0].charAt(i+1);
11252 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11253 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11254 else c1 -= '0';
11255 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11256 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11257 else c2 -= '0';
11258 builder.append((char)(255-((c1*16)+c2)));
11259 }
11260 mText = builder.toString();
11261 if (false) {
11262 Log.i(TAG, "Final text: " + mText);
11263 }
11264
11265 int fontSize = getPropertyInt(tokens, 1,
11266 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11267
11268 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11269 mTextPaint.setTextSize(fontSize);
11270 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11271
11272 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11273 mTextWidth = (int)mTextPaint.measureText(mText);
11274 mTextAscent = fm.ascent;
11275 mTextDescent = fm.descent;
11276 mTextHeight = fm.descent - fm.ascent;
11277
11278 mDeltaX = getPropertyInt(tokens, 2,
11279 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11280 mDeltaY = getPropertyInt(tokens, 3,
11281 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11282 int shadowColor = getPropertyInt(tokens, 4,
11283 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11284 int color = getPropertyInt(tokens, 5,
11285 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11286 int shadowRadius = getPropertyInt(tokens, 6,
11287 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11288 int shadowDx = getPropertyInt(tokens, 8,
11289 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11290 int shadowDy = getPropertyInt(tokens, 9,
11291 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11292
11293 mTextPaint.setColor(color);
11294 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011295
11296 try {
11297 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011298 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011299 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011300 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011301 mSurface.show();
11302 } catch (OutOfResourcesException e) {
11303 }
11304 }
11305
11306 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011307 if (mLastDW != dw || mLastDH != dh) {
11308 mLastDW = dw;
11309 mLastDH = dh;
11310 mSurface.setSize(dw, dh);
11311 mDrawNeeded = true;
11312 }
11313 }
11314
11315 void drawIfNeeded() {
11316 if (mDrawNeeded) {
11317 final int dw = mLastDW;
11318 final int dh = mLastDH;
11319
11320 mDrawNeeded = false;
11321 Rect dirty = new Rect(0, 0, dw, dh);
11322 Canvas c = null;
11323 try {
11324 c = mSurface.lockCanvas(dirty);
11325 } catch (IllegalArgumentException e) {
11326 } catch (OutOfResourcesException e) {
11327 }
11328 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011329 c.drawColor(0, PorterDuff.Mode.CLEAR);
11330
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011331 int deltaX = mDeltaX;
11332 int deltaY = mDeltaY;
11333
11334 // deltaX shouldn't be close to a round fraction of our
11335 // x step, or else things will line up too much.
11336 int div = (dw+mTextWidth)/deltaX;
11337 int rem = (dw+mTextWidth) - (div*deltaX);
11338 int qdelta = deltaX/4;
11339 if (rem < qdelta || rem > (deltaX-qdelta)) {
11340 deltaX += deltaX/3;
11341 }
11342
11343 int y = -mTextHeight;
11344 int x = -mTextWidth;
11345 while (y < (dh+mTextHeight)) {
11346 c.drawText(mText, x, y, mTextPaint);
11347 x += deltaX;
11348 if (x >= dw) {
11349 x -= (dw+mTextWidth);
11350 y += deltaY;
11351 }
11352 }
11353 mSurface.unlockCanvasAndPost(c);
11354 }
11355 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011356 }
11357 }
11358
11359 void createWatermark() {
11360 if (mWatermark != null) {
11361 return;
11362 }
11363
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011364 File file = new File("/system/etc/setup.conf");
11365 FileInputStream in = null;
11366 try {
11367 in = new FileInputStream(file);
11368 DataInputStream ind = new DataInputStream(in);
11369 String line = ind.readLine();
11370 if (line != null) {
11371 String[] toks = line.split("%");
11372 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011373 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011374 }
11375 }
11376 } catch (FileNotFoundException e) {
11377 } catch (IOException e) {
11378 } finally {
11379 if (in != null) {
11380 try {
11381 in.close();
11382 } catch (IOException e) {
11383 }
11384 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011385 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011386 }
11387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011388 @Override
11389 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11390 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11391 != PackageManager.PERMISSION_GRANTED) {
11392 pw.println("Permission Denial: can't dump WindowManager from from pid="
11393 + Binder.getCallingPid()
11394 + ", uid=" + Binder.getCallingUid());
11395 return;
11396 }
Romain Guy06882f82009-06-10 13:36:04 -070011397
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011398 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011399 pw.println(" ");
11400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011401 synchronized(mWindowMap) {
11402 pw.println("Current Window Manager state:");
11403 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011404 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011405 pw.print(" Window #"); pw.print(i); pw.print(' ');
11406 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011407 w.dump(pw, " ");
11408 }
11409 if (mInputMethodDialogs.size() > 0) {
11410 pw.println(" ");
11411 pw.println(" Input method dialogs:");
11412 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11413 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011414 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011415 }
11416 }
11417 if (mPendingRemove.size() > 0) {
11418 pw.println(" ");
11419 pw.println(" Remove pending for:");
11420 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11421 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011422 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11423 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011424 w.dump(pw, " ");
11425 }
11426 }
11427 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11428 pw.println(" ");
11429 pw.println(" Windows force removing:");
11430 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11431 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011432 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11433 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011434 w.dump(pw, " ");
11435 }
11436 }
11437 if (mDestroySurface.size() > 0) {
11438 pw.println(" ");
11439 pw.println(" Windows waiting to destroy their surface:");
11440 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11441 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011442 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11443 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011444 w.dump(pw, " ");
11445 }
11446 }
11447 if (mLosingFocus.size() > 0) {
11448 pw.println(" ");
11449 pw.println(" Windows losing focus:");
11450 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11451 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011452 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11453 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011454 w.dump(pw, " ");
11455 }
11456 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011457 if (mResizingWindows.size() > 0) {
11458 pw.println(" ");
11459 pw.println(" Windows waiting to resize:");
11460 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11461 WindowState w = mResizingWindows.get(i);
11462 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11463 pw.print(w); pw.println(":");
11464 w.dump(pw, " ");
11465 }
11466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011467 if (mSessions.size() > 0) {
11468 pw.println(" ");
11469 pw.println(" All active sessions:");
11470 Iterator<Session> it = mSessions.iterator();
11471 while (it.hasNext()) {
11472 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011473 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011474 s.dump(pw, " ");
11475 }
11476 }
11477 if (mTokenMap.size() > 0) {
11478 pw.println(" ");
11479 pw.println(" All tokens:");
11480 Iterator<WindowToken> it = mTokenMap.values().iterator();
11481 while (it.hasNext()) {
11482 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011483 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011484 token.dump(pw, " ");
11485 }
11486 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011487 if (mWallpaperTokens.size() > 0) {
11488 pw.println(" ");
11489 pw.println(" Wallpaper tokens:");
11490 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11491 WindowToken token = mWallpaperTokens.get(i);
11492 pw.print(" Wallpaper #"); pw.print(i);
11493 pw.print(' '); pw.print(token); pw.println(':');
11494 token.dump(pw, " ");
11495 }
11496 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011497 if (mAppTokens.size() > 0) {
11498 pw.println(" ");
11499 pw.println(" Application tokens in Z order:");
11500 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011501 pw.print(" App #"); pw.print(i); pw.print(": ");
11502 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011503 }
11504 }
11505 if (mFinishedStarting.size() > 0) {
11506 pw.println(" ");
11507 pw.println(" Finishing start of application tokens:");
11508 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11509 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011510 pw.print(" Finished Starting #"); pw.print(i);
11511 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011512 token.dump(pw, " ");
11513 }
11514 }
11515 if (mExitingTokens.size() > 0) {
11516 pw.println(" ");
11517 pw.println(" Exiting tokens:");
11518 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11519 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011520 pw.print(" Exiting #"); pw.print(i);
11521 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011522 token.dump(pw, " ");
11523 }
11524 }
11525 if (mExitingAppTokens.size() > 0) {
11526 pw.println(" ");
11527 pw.println(" Exiting application tokens:");
11528 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11529 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011530 pw.print(" Exiting App #"); pw.print(i);
11531 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011532 token.dump(pw, " ");
11533 }
11534 }
11535 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011536 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11537 pw.print(" mLastFocus="); pw.println(mLastFocus);
11538 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11539 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11540 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011541 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011542 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11543 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11544 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11545 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011546 if (mWindowDetachedWallpaper != null) {
11547 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11548 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011549 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11550 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11551 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011552 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11553 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11554 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11555 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011556 if (mDimAnimator != null) {
11557 mDimAnimator.printTo(pw);
11558 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011559 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011560 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011561 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011562 pw.print(mInputMethodAnimLayerAdjustment);
11563 pw.print(" mWallpaperAnimLayerAdjustment=");
11564 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011565 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11566 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011567 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11568 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011569 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11570 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011571 pw.print(" mRotation="); pw.print(mRotation);
11572 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11573 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11574 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11575 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11576 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11577 pw.print(" mNextAppTransition=0x");
11578 pw.print(Integer.toHexString(mNextAppTransition));
11579 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011580 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011581 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011582 if (mNextAppTransitionPackage != null) {
11583 pw.print(" mNextAppTransitionPackage=");
11584 pw.print(mNextAppTransitionPackage);
11585 pw.print(", mNextAppTransitionEnter=0x");
11586 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11587 pw.print(", mNextAppTransitionExit=0x");
11588 pw.print(Integer.toHexString(mNextAppTransitionExit));
11589 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011590 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11591 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11592 if (mOpeningApps.size() > 0) {
11593 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11594 }
11595 if (mClosingApps.size() > 0) {
11596 pw.print(" mClosingApps="); pw.println(mClosingApps);
11597 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011598 if (mToTopApps.size() > 0) {
11599 pw.print(" mToTopApps="); pw.println(mToTopApps);
11600 }
11601 if (mToBottomApps.size() > 0) {
11602 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11603 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011604 if (mDisplay != null) {
11605 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11606 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11607 } else {
11608 pw.println(" NO DISPLAY");
11609 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011610 pw.println(" Policy:");
11611 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011612 }
11613 }
11614
Jeff Brown349703e2010-06-22 01:27:15 -070011615 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011616 public void monitor() {
11617 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011618 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011620
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011621 /**
11622 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011623 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011624 */
11625 private static class DimAnimator {
11626 Surface mDimSurface;
11627 boolean mDimShown = false;
11628 float mDimCurrentAlpha;
11629 float mDimTargetAlpha;
11630 float mDimDeltaPerMs;
11631 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011632
11633 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011634
11635 DimAnimator (SurfaceSession session) {
11636 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011637 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011638 + mDimSurface + ": CREATE");
11639 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011640 mDimSurface = new Surface(session, 0,
11641 "DimSurface",
11642 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011643 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011644 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011645 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011646 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011647 }
11648 }
11649 }
11650
11651 /**
11652 * Show the dim surface.
11653 */
11654 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011655 if (!mDimShown) {
11656 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11657 dw + "x" + dh + ")");
11658 mDimShown = true;
11659 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011660 mLastDimWidth = dw;
11661 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011662 mDimSurface.setPosition(0, 0);
11663 mDimSurface.setSize(dw, dh);
11664 mDimSurface.show();
11665 } catch (RuntimeException e) {
11666 Slog.w(TAG, "Failure showing dim surface", e);
11667 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011668 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11669 mLastDimWidth = dw;
11670 mLastDimHeight = dh;
11671 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011672 }
11673 }
11674
11675 /**
11676 * Set's the dim surface's layer and update dim parameters that will be used in
11677 * {@link updateSurface} after all windows are examined.
11678 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011679 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011680 mDimSurface.setLayer(w.mAnimLayer-1);
11681
11682 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011683 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011684 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011685 if (mDimTargetAlpha != target) {
11686 // If the desired dim level has changed, then
11687 // start an animation to it.
11688 mLastDimAnimTime = currentTime;
11689 long duration = (w.mAnimating && w.mAnimation != null)
11690 ? w.mAnimation.computeDurationHint()
11691 : DEFAULT_DIM_DURATION;
11692 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011693 TypedValue tv = new TypedValue();
11694 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11695 tv, true);
11696 if (tv.type == TypedValue.TYPE_FRACTION) {
11697 duration = (long)tv.getFraction((float)duration, (float)duration);
11698 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11699 && tv.type <= TypedValue.TYPE_LAST_INT) {
11700 duration = tv.data;
11701 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011702 }
11703 if (duration < 1) {
11704 // Don't divide by zero
11705 duration = 1;
11706 }
11707 mDimTargetAlpha = target;
11708 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11709 }
11710 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011711
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011712 /**
11713 * Updating the surface's alpha. Returns true if the animation continues, or returns
11714 * false when the animation is finished and the dim surface is hidden.
11715 */
11716 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11717 if (!dimming) {
11718 if (mDimTargetAlpha != 0) {
11719 mLastDimAnimTime = currentTime;
11720 mDimTargetAlpha = 0;
11721 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11722 }
11723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011724
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011725 boolean animating = false;
11726 if (mLastDimAnimTime != 0) {
11727 mDimCurrentAlpha += mDimDeltaPerMs
11728 * (currentTime-mLastDimAnimTime);
11729 boolean more = true;
11730 if (displayFrozen) {
11731 // If the display is frozen, there is no reason to animate.
11732 more = false;
11733 } else if (mDimDeltaPerMs > 0) {
11734 if (mDimCurrentAlpha > mDimTargetAlpha) {
11735 more = false;
11736 }
11737 } else if (mDimDeltaPerMs < 0) {
11738 if (mDimCurrentAlpha < mDimTargetAlpha) {
11739 more = false;
11740 }
11741 } else {
11742 more = false;
11743 }
11744
11745 // Do we need to continue animating?
11746 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011747 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011748 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11749 mLastDimAnimTime = currentTime;
11750 mDimSurface.setAlpha(mDimCurrentAlpha);
11751 animating = true;
11752 } else {
11753 mDimCurrentAlpha = mDimTargetAlpha;
11754 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011755 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011756 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11757 mDimSurface.setAlpha(mDimCurrentAlpha);
11758 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011759 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011760 + ": HIDE");
11761 try {
11762 mDimSurface.hide();
11763 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011764 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011765 }
11766 mDimShown = false;
11767 }
11768 }
11769 }
11770 return animating;
11771 }
11772
11773 public void printTo(PrintWriter pw) {
11774 pw.print(" mDimShown="); pw.print(mDimShown);
11775 pw.print(" current="); pw.print(mDimCurrentAlpha);
11776 pw.print(" target="); pw.print(mDimTargetAlpha);
11777 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11778 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11779 }
11780 }
11781
11782 /**
11783 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11784 * This is used for opening/closing transition for apps in compatible mode.
11785 */
11786 private static class FadeInOutAnimation extends Animation {
11787 int mWidth;
11788 boolean mFadeIn;
11789
11790 public FadeInOutAnimation(boolean fadeIn) {
11791 setInterpolator(new AccelerateInterpolator());
11792 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11793 mFadeIn = fadeIn;
11794 }
11795
11796 @Override
11797 protected void applyTransformation(float interpolatedTime, Transformation t) {
11798 float x = interpolatedTime;
11799 if (!mFadeIn) {
11800 x = 1.0f - x; // reverse the interpolation for fade out
11801 }
11802 if (x < 0.5) {
11803 // move the window out of the screen.
11804 t.getMatrix().setTranslate(mWidth, 0);
11805 } else {
11806 t.getMatrix().setTranslate(0, 0);// show
11807 t.setAlpha((x - 0.5f) * 2);
11808 }
11809 }
11810
11811 @Override
11812 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11813 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11814 mWidth = width;
11815 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011816
11817 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011818 public int getZAdjustment() {
11819 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011820 }
11821 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011822}