blob: 30a94327719bfbc4a419cc4652f13405c3312cdf [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>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800399 int mDeferredRotation;
400 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mLayoutNeeded = true;
403 boolean mAnimationPending = false;
404 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800405 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 boolean mWindowsFreezingScreen = false;
407 long mFreezeGcPending = 0;
408 int mAppsFreezingScreen = 0;
409
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800410 int mLayoutSeq = 0;
411
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800412 // State while inside of layoutAndPlaceSurfacesLocked().
413 boolean mFocusMayChange;
414
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800415 Configuration mCurConfiguration = new Configuration();
416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 // This is held as long as we have the screen frozen, to give us time to
418 // perform a rotation animation when turning off shows the lock screen which
419 // changes the orientation.
420 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // State management of app transitions. When we are preparing for a
423 // transition, mNextAppTransition will be the kind of transition to
424 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
425 // mOpeningApps and mClosingApps are the lists of tokens that will be
426 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700427 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700428 String mNextAppTransitionPackage;
429 int mNextAppTransitionEnter;
430 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 boolean mAppTransitionTimeout = false;
434 boolean mStartingIconInTransition = false;
435 boolean mSkipAppTransitionAnimation = false;
436 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700438 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
439 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 H mH = new H();
444
445 WindowState mCurrentFocus = null;
446 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 // This just indicates the window the input method is on top of, not
449 // necessarily the window its input is going to.
450 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 boolean mInputMethodTargetWaitingAnim;
452 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 WindowState mInputMethodWindow = null;
455 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
456
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700457 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800458
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700459 // If non-null, this is the currently visible window that is associated
460 // with the wallpaper.
461 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the lower one in Z-order.
464 WindowState mLowerWallpaperTarget = null;
465 // If non-null, we are in the middle of animating from one wallpaper target
466 // to another, and this is the higher one in Z-order.
467 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800468 // Window currently running an animation that has requested it be detached
469 // from the wallpaper. This means we need to ensure the wallpaper is
470 // visible behind it in case it animates in a way that would allow it to be
471 // seen.
472 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700473 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700474 float mLastWallpaperX = -1;
475 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800476 float mLastWallpaperXStep = -1;
477 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700478 // This is set when we are waiting for a wallpaper to tell us it is done
479 // changing its scroll position.
480 WindowState mWaitingOnWallpaper;
481 // The last time we had a timeout when waiting for a wallpaper.
482 long mLastWallpaperTimeoutTime;
483 // We give a wallpaper up to 150ms to finish scrolling.
484 static final long WALLPAPER_TIMEOUT = 150;
485 // Time we wait after a timeout before trying to wait again.
486 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 AppWindowToken mFocusedApp = null;
489
490 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 float mWindowAnimationScale = 1.0f;
493 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700494
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700495 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496
497 // Who is holding the screen on.
498 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700499 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700500
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700501 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700504 * Drag/drop state
505 */
506 class DragState {
507 IBinder mToken;
508 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800509 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700510 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700511 ClipData mData;
512 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700513 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700514 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 float mThumbOffsetX, mThumbOffsetY;
516 InputChannel mServerChannel, mClientChannel;
517 WindowState mTargetWindow;
518 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700519 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700520
Jeff Brownfbf09772011-01-16 14:06:57 -0800521 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700522
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800523 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700524 mToken = token;
525 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800526 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700527 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700528 mNotifiedWindows = new ArrayList<WindowState>();
529 }
530
531 void reset() {
532 if (mSurface != null) {
533 mSurface.destroy();
534 }
535 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800536 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700537 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700538 mToken = null;
539 mData = null;
540 mThumbOffsetX = mThumbOffsetY = 0;
541 mNotifiedWindows = null;
542 }
543
544 void register() {
545 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
546 if (mClientChannel != null) {
547 Slog.e(TAG, "Duplicate register of drag input channel");
548 } else {
549 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
550 mServerChannel = channels[0];
551 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800552 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700553 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
554 mH.getLooper().getQueue());
555 }
556 }
557
558 void unregister() {
559 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
560 if (mClientChannel == null) {
561 Slog.e(TAG, "Unregister of nonexistent drag input channel");
562 } else {
563 mInputManager.unregisterInputChannel(mServerChannel);
564 InputQueue.unregisterInputChannel(mClientChannel);
565 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700566 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 mClientChannel = null;
568 mServerChannel = null;
569 }
570 }
571
Chris Tatea32dcf72010-10-14 12:13:50 -0700572 int getDragLayerLw() {
573 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
574 * TYPE_LAYER_MULTIPLIER
575 + TYPE_LAYER_OFFSET;
576 }
577
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 /* call out to each visible window/session informing it about the drag
579 */
Chris Tateb8203e92010-10-12 14:23:21 -0700580 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 // Cache a base-class instance of the clip metadata so that parceling
582 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800583 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700585 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700586
587 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700588 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
590
Christopher Tate2c095f32010-10-04 14:13:40 -0700591 final int N = mWindows.size();
592 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700593 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700594 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700595 }
596
597 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
598 * designated window is potentially a drop recipient. There are race situations
599 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
600 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700601 *
602 * This method clones the 'event' parameter if it's being delivered to the same
603 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700604 */
Chris Tateb478f462010-10-15 16:02:26 -0700605 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
606 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700607 // Don't actually send the event if the drag is supposed to be pinned
608 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800609 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700610 final IBinder winBinder = newWin.mClient.asBinder();
611 if (winBinder != mLocalWin) {
612 if (DEBUG_DRAG) {
613 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
614 }
615 return;
616 }
617 }
618
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700619 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700620 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
621 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800622 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700623 try {
624 newWin.mClient.dispatchDragEvent(event);
625 // track each window that we've notified that the drag is starting
626 mNotifiedWindows.add(newWin);
627 } catch (RemoteException e) {
628 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700629 } finally {
630 // if the callee was local, the dispatch has already recycled the event
631 if (Process.myPid() != newWin.mSession.mPid) {
632 event.recycle();
633 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700634 }
635 }
636 }
637
638 /* helper - construct and send a DRAG_STARTED event only if the window has not
639 * previously been notified, i.e. it became visible after the drag operation
640 * was begun. This is a rare case.
641 */
642 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700643 if (mDragInProgress) {
644 // If we have sent the drag-started, we needn't do so again
645 for (WindowState ws : mNotifiedWindows) {
646 if (ws == newWin) {
647 return;
648 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700650 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700651 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700652 }
Chris Tateb478f462010-10-15 16:02:26 -0700653 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700654 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700655 }
656
Chris Tated4533f142010-10-19 15:15:08 -0700657 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700658 if (DEBUG_DRAG) {
659 Slog.d(TAG, "broadcasting DRAG_ENDED");
660 }
Chris Tated4533f142010-10-19 15:15:08 -0700661 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800662 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700663 for (WindowState ws: mNotifiedWindows) {
664 try {
665 ws.mClient.dispatchDragEvent(evt);
666 } catch (RemoteException e) {
667 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700668 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700669 }
Chris Tated4533f142010-10-19 15:15:08 -0700670 mNotifiedWindows.clear();
671 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 evt.recycle();
673 }
674
Chris Tated4533f142010-10-19 15:15:08 -0700675 void endDragLw() {
676 mDragState.broadcastDragEndedLw();
677
678 // stop intercepting input
679 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -0800680 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tated4533f142010-10-19 15:15:08 -0700681
682 // free our resources and drop all the object references
683 mDragState.reset();
684 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800685
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800686 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
687 boolean changed = setRotationUncheckedLocked(
688 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
689 if (changed) {
690 sendNewConfiguration();
Christopher Tateccd24de2011-01-12 15:02:55 -0800691 }
Chris Tated4533f142010-10-19 15:15:08 -0700692 }
693
Christopher Tatea53146c2010-09-07 11:57:52 -0700694 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700695 final int myPid = Process.myPid();
696
697 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800698 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800699 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800700 try {
701 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
702 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800703 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800704 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
705 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700706
707 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700708 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800709 if (touchedWin == null) {
710 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
711 return;
712 }
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800713 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700714 final IBinder touchedBinder = touchedWin.mClient.asBinder();
715 if (touchedBinder != mLocalWin) {
716 // This drag is pinned only to the originating window, but the drag
717 // point is outside that window. Pretend it's over empty space.
718 touchedWin = null;
719 }
720 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700721 try {
722 // have we dragged over a new window?
723 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
724 if (DEBUG_DRAG) {
725 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
726 }
727 // force DRAG_EXITED_EVENT if appropriate
728 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700729 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800730 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700731 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700732 if (myPid != mTargetWindow.mSession.mPid) {
733 evt.recycle();
734 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700735 }
736 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700737 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700738 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
739 }
740 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700741 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800742 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700744 if (myPid != touchedWin.mSession.mPid) {
745 evt.recycle();
746 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700747 }
748 } catch (RemoteException e) {
749 Slog.w(TAG, "can't send drag notification to windows");
750 }
751 mTargetWindow = touchedWin;
752 }
753
Chris Tated4533f142010-10-19 15:15:08 -0700754 // Tell the drop target about the data. Returns 'true' if we can immediately
755 // dispatch the global drag-ended message, 'false' if we need to wait for a
756 // result from the recipient.
757 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700758 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700759 if (touchedWin == null) {
760 // "drop" outside a valid window -- no recipient to apply a
761 // timeout to, and we can send the drag-ended message immediately.
762 mDragResult = false;
763 return true;
764 }
765
766 if (DEBUG_DRAG) {
767 Slog.d(TAG, "sending DROP to " + touchedWin);
768 }
769 final int myPid = Process.myPid();
770 final IBinder token = touchedWin.mClient.asBinder();
771 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
772 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800773 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700774 try {
775 touchedWin.mClient.dispatchDragEvent(evt);
776
777 // 5 second timeout for this window to respond to the drop
778 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
779 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
780 mH.sendMessageDelayed(msg, 5000);
781 } catch (RemoteException e) {
782 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
783 return true;
784 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700785 if (myPid != touchedWin.mSession.mPid) {
786 evt.recycle();
787 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700788 }
Chris Tated4533f142010-10-19 15:15:08 -0700789 mToken = token;
790 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700791 }
792
793 // Find the visible, touch-deliverable window under the given point
794 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
795 WindowState touchedWin = null;
796 final int x = (int) xf;
797 final int y = (int) yf;
798 final ArrayList<WindowState> windows = mWindows;
799 final int N = windows.size();
800 for (int i = N - 1; i >= 0; i--) {
801 WindowState child = windows.get(i);
802 final int flags = child.mAttrs.flags;
803 if (!child.isVisibleLw()) {
804 // not visible == don't tell about drags
805 continue;
806 }
807 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
808 // not touchable == don't tell about drags
809 continue;
810 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800811
812 child.getTouchableRegion(mTmpRegion);
813
Christopher Tatea53146c2010-09-07 11:57:52 -0700814 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800815 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
816 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
817 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700818 // Found it
819 touchedWin = child;
820 break;
821 }
822 }
823
824 return touchedWin;
825 }
826 }
827
828 DragState mDragState = null;
829 private final InputHandler mDragInputHandler = new BaseInputHandler() {
830 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700831 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
832 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700833 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700834 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
835 && mDragState != null) {
836 boolean endDrag = false;
837 final float newX = event.getRawX();
838 final float newY = event.getRawY();
839
Christopher Tatea53146c2010-09-07 11:57:52 -0700840 switch (event.getAction()) {
841 case MotionEvent.ACTION_DOWN: {
842 if (DEBUG_DRAG) {
843 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
844 }
845 } break;
846
847 case MotionEvent.ACTION_MOVE: {
848 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700849 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700850 mDragState.notifyMoveLw(newX, newY);
851 }
852 } break;
853
854 case MotionEvent.ACTION_UP: {
855 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
856 + newX + "," + newY);
857 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700858 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700859 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700860 } break;
861
862 case MotionEvent.ACTION_CANCEL: {
863 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
864 endDrag = true;
865 } break;
866 }
867
868 if (endDrag) {
869 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
870 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700871 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700872 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700873 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700874 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700875
876 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700877 }
878 } catch (Exception e) {
879 Slog.e(TAG, "Exception caught by drag handleMotion", e);
880 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700881 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700882 }
883 }
884 };
885
886 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 * Whether the UI is currently running in touch mode (not showing
888 * navigational focus because the user is directly pressing the screen).
889 */
890 boolean mInTouchMode = false;
891
892 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700893 private ArrayList<WindowChangeListener> mWindowChangeListeners =
894 new ArrayList<WindowChangeListener>();
895 private boolean mWindowsChanged = false;
896
897 public interface WindowChangeListener {
898 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700899 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901
Dianne Hackbornc485a602009-03-24 22:39:49 -0700902 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700903 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700904
905 // The frame use to limit the size of the app running in compatibility mode.
906 Rect mCompatibleScreenFrame = new Rect();
907 // The surface used to fill the outer rim of the app running in compatibility mode.
908 Surface mBackgroundFillerSurface = null;
909 boolean mBackgroundFillerShown = false;
910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 public static WindowManagerService main(Context context,
912 PowerManagerService pm, boolean haveInputMethods) {
913 WMThread thr = new WMThread(context, pm, haveInputMethods);
914 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 synchronized (thr) {
917 while (thr.mService == null) {
918 try {
919 thr.wait();
920 } catch (InterruptedException e) {
921 }
922 }
923 }
Romain Guy06882f82009-06-10 13:36:04 -0700924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 return thr.mService;
926 }
Romain Guy06882f82009-06-10 13:36:04 -0700927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 static class WMThread extends Thread {
929 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 private final Context mContext;
932 private final PowerManagerService mPM;
933 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 public WMThread(Context context, PowerManagerService pm,
936 boolean haveInputMethods) {
937 super("WindowManager");
938 mContext = context;
939 mPM = pm;
940 mHaveInputMethods = haveInputMethods;
941 }
Romain Guy06882f82009-06-10 13:36:04 -0700942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 public void run() {
944 Looper.prepare();
945 WindowManagerService s = new WindowManagerService(mContext, mPM,
946 mHaveInputMethods);
947 android.os.Process.setThreadPriority(
948 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700949 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 synchronized (this) {
952 mService = s;
953 notifyAll();
954 }
Romain Guy06882f82009-06-10 13:36:04 -0700955
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700956 // For debug builds, log event loop stalls to dropbox for analysis.
957 if (StrictMode.conditionallyEnableDebugLogging()) {
958 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
959 }
960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 Looper.loop();
962 }
963 }
964
965 static class PolicyThread extends Thread {
966 private final WindowManagerPolicy mPolicy;
967 private final WindowManagerService mService;
968 private final Context mContext;
969 private final PowerManagerService mPM;
970 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 public PolicyThread(WindowManagerPolicy policy,
973 WindowManagerService service, Context context,
974 PowerManagerService pm) {
975 super("WindowManagerPolicy");
976 mPolicy = policy;
977 mService = service;
978 mContext = context;
979 mPM = pm;
980 }
Romain Guy06882f82009-06-10 13:36:04 -0700981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 public void run() {
983 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800984 WindowManagerPolicyThread.set(this, Looper.myLooper());
985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800987 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 android.os.Process.setThreadPriority(
989 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700990 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 synchronized (this) {
994 mRunning = true;
995 notifyAll();
996 }
Romain Guy06882f82009-06-10 13:36:04 -0700997
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700998 // For debug builds, log event loop stalls to dropbox for analysis.
999 if (StrictMode.conditionallyEnableDebugLogging()) {
1000 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1001 }
1002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 Looper.loop();
1004 }
1005 }
1006
1007 private WindowManagerService(Context context, PowerManagerService pm,
1008 boolean haveInputMethods) {
1009 mContext = context;
1010 mHaveInputMethods = haveInputMethods;
1011 mLimitedAlphaCompositing = context.getResources().getBoolean(
1012 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 mPowerManager = pm;
1015 mPowerManager.setPolicy(mPolicy);
1016 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1017 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1018 "SCREEN_FROZEN");
1019 mScreenFrozenLock.setReferenceCounted(false);
1020
1021 mActivityManager = ActivityManagerNative.getDefault();
1022 mBatteryStats = BatteryStatsService.getService();
1023
1024 // Get persisted window scale setting
1025 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1026 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1027 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1028 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001029
Jim Miller284b62e2010-06-08 14:27:42 -07001030 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1031 IntentFilter filter = new IntentFilter();
1032 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1033 mContext.registerReceiver(mBroadcastReceiver, filter);
1034
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001035 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1036 "KEEP_SCREEN_ON_FLAG");
1037 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038
Jeff Browne33348b2010-07-15 23:54:05 -07001039 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1042 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 synchronized (thr) {
1045 while (!thr.mRunning) {
1046 try {
1047 thr.wait();
1048 } catch (InterruptedException e) {
1049 }
1050 }
1051 }
Romain Guy06882f82009-06-10 13:36:04 -07001052
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001053 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 // Add ourself to the Watchdog monitors.
1056 Watchdog.getInstance().addMonitor(this);
1057 }
1058
1059 @Override
1060 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1061 throws RemoteException {
1062 try {
1063 return super.onTransact(code, data, reply, flags);
1064 } catch (RuntimeException e) {
1065 // The window manager only throws security exceptions, so let's
1066 // log all others.
1067 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 }
1070 throw e;
1071 }
1072 }
1073
Jeff Browne33348b2010-07-15 23:54:05 -07001074 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001076 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 TAG, "Adding window " + window + " at "
1078 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1079 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001080 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 }
1082
Jeff Browne33348b2010-07-15 23:54:05 -07001083 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001085 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 TAG, "Adding window " + window + " at "
1087 + i + " of " + mWindows.size() + " (before " + pos + ")");
1088 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001089 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 }
1091
1092 //This method finds out the index of a window that has the same app token as
1093 //win. used for z ordering the windows in mWindows
1094 private int findIdxBasedOnAppTokens(WindowState win) {
1095 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001096 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 int jmax = localmWindows.size();
1098 if(jmax == 0) {
1099 return -1;
1100 }
1101 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001102 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 if(wentry.mAppToken == win.mAppToken) {
1104 return j;
1105 }
1106 }
1107 return -1;
1108 }
Romain Guy06882f82009-06-10 13:36:04 -07001109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1111 final IWindow client = win.mClient;
1112 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001113 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 final int N = localmWindows.size();
1116 final WindowState attached = win.mAttachedWindow;
1117 int i;
1118 if (attached == null) {
1119 int tokenWindowsPos = token.windows.size();
1120 if (token.appWindowToken != null) {
1121 int index = tokenWindowsPos-1;
1122 if (index >= 0) {
1123 // If this application has existing windows, we
1124 // simply place the new window on top of them... but
1125 // keep the starting window on top.
1126 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1127 // Base windows go behind everything else.
1128 placeWindowBefore(token.windows.get(0), win);
1129 tokenWindowsPos = 0;
1130 } else {
1131 AppWindowToken atoken = win.mAppToken;
1132 if (atoken != null &&
1133 token.windows.get(index) == atoken.startingWindow) {
1134 placeWindowBefore(token.windows.get(index), win);
1135 tokenWindowsPos--;
1136 } else {
1137 int newIdx = findIdxBasedOnAppTokens(win);
1138 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001139 //there is a window above this one associated with the same
1140 //apptoken note that the window could be a floating window
1141 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001143 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1144 Slog.v(TAG, "Adding window " + win + " at "
1145 + (newIdx+1) + " of " + N);
1146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001148 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 }
1151 }
1152 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001153 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 TAG, "Figuring out where to add app window "
1155 + client.asBinder() + " (token=" + token + ")");
1156 // Figure out where the window should go, based on the
1157 // order of applications.
1158 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001159 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 for (i=NA-1; i>=0; i--) {
1161 AppWindowToken t = mAppTokens.get(i);
1162 if (t == token) {
1163 i--;
1164 break;
1165 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001166
Dianne Hackborna8f60182009-09-01 19:01:50 -07001167 // We haven't reached the token yet; if this token
1168 // is not going to the bottom and has windows, we can
1169 // use it as an anchor for when we do reach the token.
1170 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 pos = t.windows.get(0);
1172 }
1173 }
1174 // We now know the index into the apps. If we found
1175 // an app window above, that gives us the position; else
1176 // we need to look some more.
1177 if (pos != null) {
1178 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001179 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 if (atoken != null) {
1181 final int NC = atoken.windows.size();
1182 if (NC > 0) {
1183 WindowState bottom = atoken.windows.get(0);
1184 if (bottom.mSubLayer < 0) {
1185 pos = bottom;
1186 }
1187 }
1188 }
1189 placeWindowBefore(pos, win);
1190 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001191 // Continue looking down until we find the first
1192 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 while (i >= 0) {
1194 AppWindowToken t = mAppTokens.get(i);
1195 final int NW = t.windows.size();
1196 if (NW > 0) {
1197 pos = t.windows.get(NW-1);
1198 break;
1199 }
1200 i--;
1201 }
1202 if (pos != null) {
1203 // Move in front of any windows attached to this
1204 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001205 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 if (atoken != null) {
1207 final int NC = atoken.windows.size();
1208 if (NC > 0) {
1209 WindowState top = atoken.windows.get(NC-1);
1210 if (top.mSubLayer >= 0) {
1211 pos = top;
1212 }
1213 }
1214 }
1215 placeWindowAfter(pos, win);
1216 } else {
1217 // Just search for the start of this layer.
1218 final int myLayer = win.mBaseLayer;
1219 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001220 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 if (w.mBaseLayer > myLayer) {
1222 break;
1223 }
1224 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001225 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1226 Slog.v(TAG, "Adding window " + win + " at "
1227 + i + " of " + N);
1228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001230 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 }
1232 }
1233 }
1234 } else {
1235 // Figure out where window should go, based on layer.
1236 final int myLayer = win.mBaseLayer;
1237 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001238 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 i++;
1240 break;
1241 }
1242 }
1243 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001244 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001245 TAG, "Adding window " + win + " at "
1246 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001248 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 }
1250 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001251 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 token.windows.add(tokenWindowsPos, win);
1253 }
1254
1255 } else {
1256 // Figure out this window's ordering relative to the window
1257 // it is attached to.
1258 final int NA = token.windows.size();
1259 final int sublayer = win.mSubLayer;
1260 int largestSublayer = Integer.MIN_VALUE;
1261 WindowState windowWithLargestSublayer = null;
1262 for (i=0; i<NA; i++) {
1263 WindowState w = token.windows.get(i);
1264 final int wSublayer = w.mSubLayer;
1265 if (wSublayer >= largestSublayer) {
1266 largestSublayer = wSublayer;
1267 windowWithLargestSublayer = w;
1268 }
1269 if (sublayer < 0) {
1270 // For negative sublayers, we go below all windows
1271 // in the same sublayer.
1272 if (wSublayer >= sublayer) {
1273 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001274 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 token.windows.add(i, win);
1276 }
1277 placeWindowBefore(
1278 wSublayer >= 0 ? attached : w, win);
1279 break;
1280 }
1281 } else {
1282 // For positive sublayers, we go above all windows
1283 // in the same sublayer.
1284 if (wSublayer > sublayer) {
1285 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001286 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 token.windows.add(i, win);
1288 }
1289 placeWindowBefore(w, win);
1290 break;
1291 }
1292 }
1293 }
1294 if (i >= NA) {
1295 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001296 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 token.windows.add(win);
1298 }
1299 if (sublayer < 0) {
1300 placeWindowBefore(attached, win);
1301 } else {
1302 placeWindowAfter(largestSublayer >= 0
1303 ? windowWithLargestSublayer
1304 : attached,
1305 win);
1306 }
1307 }
1308 }
Romain Guy06882f82009-06-10 13:36:04 -07001309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 if (win.mAppToken != null && addToToken) {
1311 win.mAppToken.allAppWindows.add(win);
1312 }
1313 }
Romain Guy06882f82009-06-10 13:36:04 -07001314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 static boolean canBeImeTarget(WindowState w) {
1316 final int fl = w.mAttrs.flags
1317 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1318 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1319 return w.isVisibleOrAdding();
1320 }
1321 return false;
1322 }
Romain Guy06882f82009-06-10 13:36:04 -07001323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001325 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 final int N = localmWindows.size();
1327 WindowState w = null;
1328 int i = N;
1329 while (i > 0) {
1330 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001331 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001332
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 // + Integer.toHexString(w.mAttrs.flags));
1335 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001336 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 // Yet more tricksyness! If this window is a "starting"
1339 // window, we do actually want to be on top of it, but
1340 // it is not -really- where input will go. So if the caller
1341 // is not actually looking to move the IME, look down below
1342 // for a real window to target...
1343 if (!willMove
1344 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1345 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001346 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1348 i--;
1349 w = wb;
1350 }
1351 }
1352 break;
1353 }
1354 }
Romain Guy06882f82009-06-10 13:36:04 -07001355
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001356 // Now, a special case -- if the last target's window is in the
1357 // process of exiting, and is above the new target, keep on the
1358 // last target to avoid flicker. Consider for example a Dialog with
1359 // the IME shown: when the Dialog is dismissed, we want to keep
1360 // the IME above it until it is completely gone so it doesn't drop
1361 // behind the dialog or its full-screen scrim.
1362 if (mInputMethodTarget != null && w != null
1363 && mInputMethodTarget.isDisplayedLw()
1364 && mInputMethodTarget.mExiting) {
1365 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1366 w = mInputMethodTarget;
1367 i = localmWindows.indexOf(w);
1368 }
1369 }
Romain Guy06882f82009-06-10 13:36:04 -07001370
Joe Onorato8a9b2202010-02-26 18:56:32 -08001371 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 if (willMove && w != null) {
1375 final WindowState curTarget = mInputMethodTarget;
1376 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 // Now some fun for dealing with window animations that
1379 // modify the Z order. We need to look at all windows below
1380 // the current target that are in this app, finding the highest
1381 // visible one in layering.
1382 AppWindowToken token = curTarget.mAppToken;
1383 WindowState highestTarget = null;
1384 int highestPos = 0;
1385 if (token.animating || token.animation != null) {
1386 int pos = 0;
1387 pos = localmWindows.indexOf(curTarget);
1388 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001389 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 if (win.mAppToken != token) {
1391 break;
1392 }
1393 if (!win.mRemoved) {
1394 if (highestTarget == null || win.mAnimLayer >
1395 highestTarget.mAnimLayer) {
1396 highestTarget = win;
1397 highestPos = pos;
1398 }
1399 }
1400 pos--;
1401 }
1402 }
Romain Guy06882f82009-06-10 13:36:04 -07001403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 + mNextAppTransition + " " + highestTarget
1407 + " animating=" + highestTarget.isAnimating()
1408 + " layer=" + highestTarget.mAnimLayer
1409 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001410
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001411 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 // If we are currently setting up for an animation,
1413 // hold everything until we can find out what will happen.
1414 mInputMethodTargetWaitingAnim = true;
1415 mInputMethodTarget = highestTarget;
1416 return highestPos + 1;
1417 } else if (highestTarget.isAnimating() &&
1418 highestTarget.mAnimLayer > w.mAnimLayer) {
1419 // If the window we are currently targeting is involved
1420 // with an animation, and it is on top of the next target
1421 // we will be over, then hold off on moving until
1422 // that is done.
1423 mInputMethodTarget = highestTarget;
1424 return highestPos + 1;
1425 }
1426 }
1427 }
1428 }
Romain Guy06882f82009-06-10 13:36:04 -07001429
Joe Onorato8a9b2202010-02-26 18:56:32 -08001430 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 if (w != null) {
1432 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001433 if (DEBUG_INPUT_METHOD) {
1434 RuntimeException e = null;
1435 if (!HIDE_STACK_CRAWLS) {
1436 e = new RuntimeException();
1437 e.fillInStackTrace();
1438 }
1439 Slog.w(TAG, "Moving IM target from "
1440 + mInputMethodTarget + " to " + w, e);
1441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 mInputMethodTarget = w;
1443 if (w.mAppToken != null) {
1444 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1445 } else {
1446 setInputMethodAnimLayerAdjustment(0);
1447 }
1448 }
1449 return i+1;
1450 }
1451 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001452 if (DEBUG_INPUT_METHOD) {
1453 RuntimeException e = null;
1454 if (!HIDE_STACK_CRAWLS) {
1455 e = new RuntimeException();
1456 e.fillInStackTrace();
1457 }
1458 Slog.w(TAG, "Moving IM target from "
1459 + mInputMethodTarget + " to null", e);
1460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 mInputMethodTarget = null;
1462 setInputMethodAnimLayerAdjustment(0);
1463 }
1464 return -1;
1465 }
Romain Guy06882f82009-06-10 13:36:04 -07001466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 void addInputMethodWindowToListLocked(WindowState win) {
1468 int pos = findDesiredInputMethodWindowIndexLocked(true);
1469 if (pos >= 0) {
1470 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001471 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001472 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001474 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 moveInputMethodDialogsLocked(pos+1);
1476 return;
1477 }
1478 win.mTargetAppToken = null;
1479 addWindowToListInOrderLocked(win, true);
1480 moveInputMethodDialogsLocked(pos);
1481 }
Romain Guy06882f82009-06-10 13:36:04 -07001482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001484 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 mInputMethodAnimLayerAdjustment = adj;
1486 WindowState imw = mInputMethodWindow;
1487 if (imw != null) {
1488 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001489 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 + " anim layer: " + imw.mAnimLayer);
1491 int wi = imw.mChildWindows.size();
1492 while (wi > 0) {
1493 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001494 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001496 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 + " anim layer: " + cw.mAnimLayer);
1498 }
1499 }
1500 int di = mInputMethodDialogs.size();
1501 while (di > 0) {
1502 di --;
1503 imw = mInputMethodDialogs.get(di);
1504 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001505 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 + " anim layer: " + imw.mAnimLayer);
1507 }
1508 }
Romain Guy06882f82009-06-10 13:36:04 -07001509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1511 int wpos = mWindows.indexOf(win);
1512 if (wpos >= 0) {
1513 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001514 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001516 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 int NC = win.mChildWindows.size();
1518 while (NC > 0) {
1519 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001520 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 int cpos = mWindows.indexOf(cw);
1522 if (cpos >= 0) {
1523 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001524 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001525 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 mWindows.remove(cpos);
1527 }
1528 }
1529 }
1530 return interestingPos;
1531 }
Romain Guy06882f82009-06-10 13:36:04 -07001532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 private void reAddWindowToListInOrderLocked(WindowState win) {
1534 addWindowToListInOrderLocked(win, false);
1535 // This is a hack to get all of the child windows added as well
1536 // at the right position. Child windows should be rare and
1537 // this case should be rare, so it shouldn't be that big a deal.
1538 int wpos = mWindows.indexOf(win);
1539 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001540 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001541 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001543 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 reAddWindowLocked(wpos, win);
1545 }
1546 }
Romain Guy06882f82009-06-10 13:36:04 -07001547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 void logWindowList(String prefix) {
1549 int N = mWindows.size();
1550 while (N > 0) {
1551 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001552 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 }
1554 }
Romain Guy06882f82009-06-10 13:36:04 -07001555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 void moveInputMethodDialogsLocked(int pos) {
1557 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 for (int i=0; i<N; i++) {
1562 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1563 }
1564 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001565 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 logWindowList(" ");
1567 }
Romain Guy06882f82009-06-10 13:36:04 -07001568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 if (pos >= 0) {
1570 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1571 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001572 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 if (wp == mInputMethodWindow) {
1574 pos++;
1575 }
1576 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001577 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 for (int i=0; i<N; i++) {
1579 WindowState win = dialogs.get(i);
1580 win.mTargetAppToken = targetAppToken;
1581 pos = reAddWindowLocked(pos, win);
1582 }
1583 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001584 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 logWindowList(" ");
1586 }
1587 return;
1588 }
1589 for (int i=0; i<N; i++) {
1590 WindowState win = dialogs.get(i);
1591 win.mTargetAppToken = null;
1592 reAddWindowToListInOrderLocked(win);
1593 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001594 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 logWindowList(" ");
1596 }
1597 }
1598 }
Romain Guy06882f82009-06-10 13:36:04 -07001599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1601 final WindowState imWin = mInputMethodWindow;
1602 final int DN = mInputMethodDialogs.size();
1603 if (imWin == null && DN == 0) {
1604 return false;
1605 }
Romain Guy06882f82009-06-10 13:36:04 -07001606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1608 if (imPos >= 0) {
1609 // In this case, the input method windows are to be placed
1610 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 // First check to see if the input method windows are already
1613 // located here, and contiguous.
1614 final int N = mWindows.size();
1615 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001616 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 // Figure out the actual input method window that should be
1619 // at the bottom of their stack.
1620 WindowState baseImWin = imWin != null
1621 ? imWin : mInputMethodDialogs.get(0);
1622 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001623 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 if (cw.mSubLayer < 0) baseImWin = cw;
1625 }
Romain Guy06882f82009-06-10 13:36:04 -07001626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 if (firstImWin == baseImWin) {
1628 // The windows haven't moved... but are they still contiguous?
1629 // First find the top IM window.
1630 int pos = imPos+1;
1631 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001632 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 break;
1634 }
1635 pos++;
1636 }
1637 pos++;
1638 // Now there should be no more input method windows above.
1639 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001640 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 break;
1642 }
1643 pos++;
1644 }
1645 if (pos >= N) {
1646 // All is good!
1647 return false;
1648 }
1649 }
Romain Guy06882f82009-06-10 13:36:04 -07001650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 if (imWin != null) {
1652 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001653 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 logWindowList(" ");
1655 }
1656 imPos = tmpRemoveWindowLocked(imPos, imWin);
1657 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001658 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 logWindowList(" ");
1660 }
1661 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1662 reAddWindowLocked(imPos, imWin);
1663 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001664 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 logWindowList(" ");
1666 }
1667 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1668 } else {
1669 moveInputMethodDialogsLocked(imPos);
1670 }
Romain Guy06882f82009-06-10 13:36:04 -07001671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 } else {
1673 // In this case, the input method windows go in a fixed layer,
1674 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 tmpRemoveWindowLocked(0, imWin);
1679 imWin.mTargetAppToken = null;
1680 reAddWindowToListInOrderLocked(imWin);
1681 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001682 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 logWindowList(" ");
1684 }
1685 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1686 } else {
1687 moveInputMethodDialogsLocked(-1);;
1688 }
Romain Guy06882f82009-06-10 13:36:04 -07001689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 }
Romain Guy06882f82009-06-10 13:36:04 -07001691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 if (needAssignLayers) {
1693 assignLayersLocked();
1694 }
Romain Guy06882f82009-06-10 13:36:04 -07001695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001696 return true;
1697 }
Romain Guy06882f82009-06-10 13:36:04 -07001698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 void adjustInputMethodDialogsLocked() {
1700 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1701 }
Romain Guy06882f82009-06-10 13:36:04 -07001702
Dianne Hackborn25994b42009-09-04 14:21:19 -07001703 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001704 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001705 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1706 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1707 ? wallpaperTarget.mAppToken.animation : null)
1708 + " upper=" + mUpperWallpaperTarget
1709 + " lower=" + mLowerWallpaperTarget);
1710 return (wallpaperTarget != null
1711 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1712 && wallpaperTarget.mAppToken.animation != null)))
1713 || mUpperWallpaperTarget != null
1714 || mLowerWallpaperTarget != null;
1715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001716
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001717 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1718 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001719
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001720 int adjustWallpaperWindowsLocked() {
1721 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001723 final int dw = mDisplay.getWidth();
1724 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001725
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001726 // First find top-most window that has asked to be on top of the
1727 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001728 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001729 int N = localmWindows.size();
1730 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001731 WindowState foundW = null;
1732 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001733 WindowState topCurW = null;
1734 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001735 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001736 int i = N;
1737 while (i > 0) {
1738 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001739 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001740 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1741 if (topCurW == null) {
1742 topCurW = w;
1743 topCurI = i;
1744 }
1745 continue;
1746 }
1747 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001748 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001749 // If this window's app token is hidden and not animating,
1750 // it is of no interest to us.
1751 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001752 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001753 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001754 continue;
1755 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001756 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001757 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001758 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1759 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001760 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001761 && (mWallpaperTarget == w
1762 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001763 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001764 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001765 foundW = w;
1766 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001767 if (w == mWallpaperTarget && ((w.mAppToken != null
1768 && w.mAppToken.animation != null)
1769 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 // The current wallpaper target is animating, so we'll
1771 // look behind it for another possible target and figure
1772 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001773 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001774 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001775 continue;
1776 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001777 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001778 } else if (w == mWindowDetachedWallpaper) {
1779 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001780 }
1781 }
1782
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001783 if (foundW == null && windowDetachedI >= 0) {
1784 if (DEBUG_WALLPAPER) Slog.v(TAG,
1785 "Found animating detached wallpaper activity: #" + i + "=" + w);
1786 foundW = w;
1787 foundI = windowDetachedI;
1788 }
1789
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001790 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001791 // If we are currently waiting for an app transition, and either
1792 // the current target or the next target are involved with it,
1793 // then hold off on doing anything with the wallpaper.
1794 // Note that we are checking here for just whether the target
1795 // is part of an app token... which is potentially overly aggressive
1796 // (the app token may not be involved in the transition), but good
1797 // enough (we'll just wait until whatever transition is pending
1798 // executes).
1799 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001800 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001802 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001803 }
1804 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001805 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001807 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001808 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001809 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001810
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001811 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001812 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 + " oldTarget: " + mWallpaperTarget);
1815 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001816
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001817 mLowerWallpaperTarget = null;
1818 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001819
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001820 WindowState oldW = mWallpaperTarget;
1821 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001822
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001823 // Now what is happening... if the current and new targets are
1824 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001825 if (foundW != null && oldW != null) {
1826 boolean oldAnim = oldW.mAnimation != null
1827 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1828 boolean foundAnim = foundW.mAnimation != null
1829 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001830 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001831 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001832 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001833 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001834 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001835 int oldI = localmWindows.indexOf(oldW);
1836 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001837 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001838 }
1839 if (oldI >= 0) {
1840 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001841 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001842 + "=" + oldW + "; new#" + foundI
1843 + "=" + foundW);
1844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001845
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001846 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001847 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001848 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001849 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001850 }
1851 mWallpaperTarget = oldW;
1852 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001853
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001854 // Now set the upper and lower wallpaper targets
1855 // correctly, and make sure that we are positioning
1856 // the wallpaper below the lower.
1857 if (foundI > oldI) {
1858 // The new target is on top of the old one.
1859 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001861 }
1862 mUpperWallpaperTarget = foundW;
1863 mLowerWallpaperTarget = oldW;
1864 foundW = oldW;
1865 foundI = oldI;
1866 } else {
1867 // The new target is below the old one.
1868 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 }
1871 mUpperWallpaperTarget = oldW;
1872 mLowerWallpaperTarget = foundW;
1873 }
1874 }
1875 }
1876 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001877
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001878 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001879 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001880 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1881 || (mLowerWallpaperTarget.mAppToken != null
1882 && mLowerWallpaperTarget.mAppToken.animation != null);
1883 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1884 || (mUpperWallpaperTarget.mAppToken != null
1885 && mUpperWallpaperTarget.mAppToken.animation != null);
1886 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001887 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001888 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001889 }
1890 mLowerWallpaperTarget = null;
1891 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001892 }
1893 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001894
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001895 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001896 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001897 // The window is visible to the compositor... but is it visible
1898 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001899 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001900 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001901
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001902 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001903 // its layer adjustment. Only do this if we are not transfering
1904 // between two wallpaper targets.
1905 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001906 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001907 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001908
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001909 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1910 * TYPE_LAYER_MULTIPLIER
1911 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001912
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001913 // Now w is the window we are supposed to be behind... but we
1914 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001915 // AND any starting window associated with it, AND below the
1916 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001917 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001918 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001919 if (wb.mBaseLayer < maxLayer &&
1920 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001921 (foundW.mAttachedWindow == null ||
1922 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001923 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001924 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001925 // This window is not related to the previous one in any
1926 // interesting way, so stop here.
1927 break;
1928 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001929 foundW = wb;
1930 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001931 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001932 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001933 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001934 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001935
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001936 if (foundW == null && topCurW != null) {
1937 // There is no wallpaper target, so it goes at the bottom.
1938 // We will assume it is the same place as last time, if known.
1939 foundW = topCurW;
1940 foundI = topCurI+1;
1941 } else {
1942 // Okay i is the position immediately above the wallpaper. Look at
1943 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001944 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001945 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001946
Dianne Hackborn284ac932009-08-28 10:34:25 -07001947 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001948 if (mWallpaperTarget.mWallpaperX >= 0) {
1949 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001950 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001951 }
1952 if (mWallpaperTarget.mWallpaperY >= 0) {
1953 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001954 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001955 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001957
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001958 // Start stepping backwards from here, ensuring that our wallpaper windows
1959 // are correctly placed.
1960 int curTokenIndex = mWallpaperTokens.size();
1961 while (curTokenIndex > 0) {
1962 curTokenIndex--;
1963 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001964 if (token.hidden == visible) {
1965 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1966 token.hidden = !visible;
1967 // Need to do a layout to ensure the wallpaper now has the
1968 // correct size.
1969 mLayoutNeeded = true;
1970 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001971
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001972 int curWallpaperIndex = token.windows.size();
1973 while (curWallpaperIndex > 0) {
1974 curWallpaperIndex--;
1975 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001976
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001977 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001978 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001979 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001980
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001981 // First, make sure the client has the current visibility
1982 // state.
1983 if (wallpaper.mWallpaperVisible != visible) {
1984 wallpaper.mWallpaperVisible = visible;
1985 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001986 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001987 "Setting visibility of wallpaper " + wallpaper
1988 + ": " + visible);
1989 wallpaper.mClient.dispatchAppVisibility(visible);
1990 } catch (RemoteException e) {
1991 }
1992 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001993
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001994 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001995 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001996 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001997
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001998 // First, if this window is at the current index, then all
1999 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002000 if (wallpaper == foundW) {
2001 foundI--;
2002 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002003 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002004 continue;
2005 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002006
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002007 // The window didn't match... the current wallpaper window,
2008 // wherever it is, is in the wrong place, so make sure it is
2009 // not in the list.
2010 int oldIndex = localmWindows.indexOf(wallpaper);
2011 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002012 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002013 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002014 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002015 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002016 if (oldIndex < foundI) {
2017 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002018 }
2019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002020
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002021 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002022 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2023 Slog.v(TAG, "Moving wallpaper " + wallpaper
2024 + " from " + oldIndex + " to " + foundI);
2025 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002026
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002027 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002028 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002029 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002030 }
2031 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002032
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002033 return changed;
2034 }
2035
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002036 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002037 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002038 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002039 mWallpaperAnimLayerAdjustment = adj;
2040 int curTokenIndex = mWallpaperTokens.size();
2041 while (curTokenIndex > 0) {
2042 curTokenIndex--;
2043 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2044 int curWallpaperIndex = token.windows.size();
2045 while (curWallpaperIndex > 0) {
2046 curWallpaperIndex--;
2047 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2048 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002049 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002050 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002051 }
2052 }
2053 }
2054
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002055 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2056 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002057 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002058 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002059 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002060 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002061 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2062 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2063 changed = wallpaperWin.mXOffset != offset;
2064 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002065 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002066 + wallpaperWin + " x: " + offset);
2067 wallpaperWin.mXOffset = offset;
2068 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002069 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002070 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002071 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002072 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002073 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002074
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002075 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002076 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002077 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2078 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2079 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002080 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002081 + wallpaperWin + " y: " + offset);
2082 changed = true;
2083 wallpaperWin.mYOffset = offset;
2084 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002085 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002086 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002087 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002089 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002090
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002091 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002092 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002093 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002094 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2095 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002096 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002097 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002098 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002099 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002100 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2101 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002102 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002103 if (mWaitingOnWallpaper != null) {
2104 long start = SystemClock.uptimeMillis();
2105 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2106 < start) {
2107 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002108 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002109 "Waiting for offset complete...");
2110 mWindowMap.wait(WALLPAPER_TIMEOUT);
2111 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002112 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002113 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002114 if ((start+WALLPAPER_TIMEOUT)
2115 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002116 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002117 + wallpaperWin);
2118 mLastWallpaperTimeoutTime = start;
2119 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002120 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002121 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002122 }
2123 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002124 } catch (RemoteException e) {
2125 }
2126 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002127
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002128 return changed;
2129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002130
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002131 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002132 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002133 if (mWaitingOnWallpaper != null &&
2134 mWaitingOnWallpaper.mClient.asBinder() == window) {
2135 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002136 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002137 }
2138 }
2139 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002140
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002141 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002142 final int dw = mDisplay.getWidth();
2143 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002144
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002145 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002146
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002147 WindowState target = mWallpaperTarget;
2148 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002149 if (target.mWallpaperX >= 0) {
2150 mLastWallpaperX = target.mWallpaperX;
2151 } else if (changingTarget.mWallpaperX >= 0) {
2152 mLastWallpaperX = changingTarget.mWallpaperX;
2153 }
2154 if (target.mWallpaperY >= 0) {
2155 mLastWallpaperY = target.mWallpaperY;
2156 } else if (changingTarget.mWallpaperY >= 0) {
2157 mLastWallpaperY = changingTarget.mWallpaperY;
2158 }
2159 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002160
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002161 int curTokenIndex = mWallpaperTokens.size();
2162 while (curTokenIndex > 0) {
2163 curTokenIndex--;
2164 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2165 int curWallpaperIndex = token.windows.size();
2166 while (curWallpaperIndex > 0) {
2167 curWallpaperIndex--;
2168 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2169 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2170 wallpaper.computeShownFrameLocked();
2171 changed = true;
2172 // We only want to be synchronous with one wallpaper.
2173 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002174 }
2175 }
2176 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002177
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002178 return changed;
2179 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002180
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002181 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002182 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002183 final int dw = mDisplay.getWidth();
2184 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002185
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002186 int curTokenIndex = mWallpaperTokens.size();
2187 while (curTokenIndex > 0) {
2188 curTokenIndex--;
2189 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002190 if (token.hidden == visible) {
2191 token.hidden = !visible;
2192 // Need to do a layout to ensure the wallpaper now has the
2193 // correct size.
2194 mLayoutNeeded = true;
2195 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002196
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002197 int curWallpaperIndex = token.windows.size();
2198 while (curWallpaperIndex > 0) {
2199 curWallpaperIndex--;
2200 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2201 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002202 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002203 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002204
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002205 if (wallpaper.mWallpaperVisible != visible) {
2206 wallpaper.mWallpaperVisible = visible;
2207 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002208 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002209 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002210 + ": " + visible);
2211 wallpaper.mClient.dispatchAppVisibility(visible);
2212 } catch (RemoteException e) {
2213 }
2214 }
2215 }
2216 }
2217 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 public int addWindow(Session session, IWindow client,
2220 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002221 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 int res = mPolicy.checkAddPermission(attrs);
2223 if (res != WindowManagerImpl.ADD_OKAY) {
2224 return res;
2225 }
Romain Guy06882f82009-06-10 13:36:04 -07002226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 boolean reportNewConfig = false;
2228 WindowState attachedWindow = null;
2229 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002230 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002234 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 }
Romain Guy06882f82009-06-10 13:36:04 -07002236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002238 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2240 }
2241
2242 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002243 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002245 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 + attrs.token + ". Aborting.");
2247 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2248 }
2249 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2250 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002251 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 + attrs.token + ". Aborting.");
2253 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2254 }
2255 }
2256
2257 boolean addToken = false;
2258 WindowToken token = mTokenMap.get(attrs.token);
2259 if (token == null) {
2260 if (attrs.type >= FIRST_APPLICATION_WINDOW
2261 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002262 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 + attrs.token + ". Aborting.");
2264 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2265 }
2266 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002267 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 + attrs.token + ". Aborting.");
2269 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2270 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002271 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002272 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002273 + attrs.token + ". Aborting.");
2274 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 token = new WindowToken(attrs.token, -1, false);
2277 addToken = true;
2278 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2279 && attrs.type <= LAST_APPLICATION_WINDOW) {
2280 AppWindowToken atoken = token.appWindowToken;
2281 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002282 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 + token + ". Aborting.");
2284 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2285 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002286 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 + token + ". Aborting.");
2288 return WindowManagerImpl.ADD_APP_EXITING;
2289 }
2290 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2291 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002292 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2294 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2295 }
2296 } else if (attrs.type == TYPE_INPUT_METHOD) {
2297 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002298 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 + attrs.token + ". Aborting.");
2300 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2301 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002302 } else if (attrs.type == TYPE_WALLPAPER) {
2303 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002304 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002305 + attrs.token + ". Aborting.");
2306 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 }
2309
2310 win = new WindowState(session, client, token,
2311 attachedWindow, attrs, viewVisibility);
2312 if (win.mDeathRecipient == null) {
2313 // Client has apparently died, so there is no reason to
2314 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002315 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 + " that is dead, aborting.");
2317 return WindowManagerImpl.ADD_APP_EXITING;
2318 }
2319
2320 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 res = mPolicy.prepareAddWindowLw(win, attrs);
2323 if (res != WindowManagerImpl.ADD_OKAY) {
2324 return res;
2325 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002326
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002327 if (outInputChannel != null) {
2328 String name = win.makeInputChannelName();
2329 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2330 win.mInputChannel = inputChannels[0];
2331 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2332
Jeff Brown928e0542011-01-10 11:17:36 -08002333 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335
2336 // From now on, no exceptions or errors allowed!
2337
2338 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002339
Dianne Hackborn5132b372010-07-29 12:51:35 -07002340 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 if (addToken) {
2343 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 }
2345 win.attach();
2346 mWindowMap.put(client.asBinder(), win);
2347
2348 if (attrs.type == TYPE_APPLICATION_STARTING &&
2349 token.appWindowToken != null) {
2350 token.appWindowToken.startingWindow = win;
2351 }
2352
2353 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 if (attrs.type == TYPE_INPUT_METHOD) {
2356 mInputMethodWindow = win;
2357 addInputMethodWindowToListLocked(win);
2358 imMayMove = false;
2359 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2360 mInputMethodDialogs.add(win);
2361 addWindowToListInOrderLocked(win, true);
2362 adjustInputMethodDialogsLocked();
2363 imMayMove = false;
2364 } else {
2365 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002366 if (attrs.type == TYPE_WALLPAPER) {
2367 mLastWallpaperTimeoutTime = 0;
2368 adjustWallpaperWindowsLocked();
2369 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002370 adjustWallpaperWindowsLocked();
2371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 }
Romain Guy06882f82009-06-10 13:36:04 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 if (mInTouchMode) {
2379 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2380 }
2381 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2382 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2383 }
Romain Guy06882f82009-06-10 13:36:04 -07002384
Jeff Brown2e44b072011-01-24 15:21:56 -08002385 mInputMonitor.setUpdateInputWindowsNeededLw();
2386
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002387 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002389 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2390 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002391 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 imMayMove = false;
2393 }
2394 }
Romain Guy06882f82009-06-10 13:36:04 -07002395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002397 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 }
Romain Guy06882f82009-06-10 13:36:04 -07002399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 assignLayersLocked();
2401 // Don't do layout here, the window must call
2402 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 //dump();
2405
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002406 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002407 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002408 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002409 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002410
Joe Onorato8a9b2202010-02-26 18:56:32 -08002411 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 TAG, "New client " + client.asBinder()
2413 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002414
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002415 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002416 reportNewConfig = true;
2417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 }
2419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 if (reportNewConfig) {
2421 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 return res;
2427 }
Romain Guy06882f82009-06-10 13:36:04 -07002428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 public void removeWindow(Session session, IWindow client) {
2430 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002431 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 if (win == null) {
2433 return;
2434 }
2435 removeWindowLocked(session, win);
2436 }
2437 }
Romain Guy06882f82009-06-10 13:36:04 -07002438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 public void removeWindowLocked(Session session, WindowState win) {
2440
Joe Onorato8a9b2202010-02-26 18:56:32 -08002441 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 TAG, "Remove " + win + " client="
2443 + Integer.toHexString(System.identityHashCode(
2444 win.mClient.asBinder()))
2445 + ", surface=" + win.mSurface);
2446
2447 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002448
2449 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002450
Joe Onorato8a9b2202010-02-26 18:56:32 -08002451 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2453 + " mExiting=" + win.mExiting
2454 + " isAnimating=" + win.isAnimating()
2455 + " app-animation="
2456 + (win.mAppToken != null ? win.mAppToken.animation : null)
2457 + " inPendingTransaction="
2458 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2459 + " mDisplayFrozen=" + mDisplayFrozen);
2460 // Visibility of the removed window. Will be used later to update orientation later on.
2461 boolean wasVisible = false;
2462 // First, see if we need to run an animation. If we do, we have
2463 // to hold off on removing the window until the animation is done.
2464 // If the display is frozen, just remove immediately, since the
2465 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002466 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 // If we are not currently running the exit animation, we
2468 // need to see about starting one.
2469 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2472 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2473 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2474 }
2475 // Try starting an animation.
2476 if (applyAnimationLocked(win, transit, false)) {
2477 win.mExiting = true;
2478 }
2479 }
2480 if (win.mExiting || win.isAnimating()) {
2481 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002482 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 win.mExiting = true;
2484 win.mRemoveOnExit = true;
2485 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002486 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2487 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002489 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 if (win.mAppToken != null) {
2491 win.mAppToken.updateReportedVisibilityLocked();
2492 }
2493 //dump();
2494 Binder.restoreCallingIdentity(origId);
2495 return;
2496 }
2497 }
2498
2499 removeWindowInnerLocked(session, win);
2500 // Removing a visible window will effect the computed orientation
2501 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002502 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002503 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002504 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002505 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002507 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 Binder.restoreCallingIdentity(origId);
2509 }
Romain Guy06882f82009-06-10 13:36:04 -07002510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002512 if (win.mRemoved) {
2513 // Nothing to do.
2514 return;
2515 }
2516
2517 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2518 WindowState cwin = win.mChildWindows.get(i);
2519 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2520 + win);
2521 removeWindowInnerLocked(cwin.mSession, cwin);
2522 }
2523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 if (mInputMethodTarget == win) {
2527 moveInputMethodWindowsIfNeededLocked(false);
2528 }
Romain Guy06882f82009-06-10 13:36:04 -07002529
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002530 if (false) {
2531 RuntimeException e = new RuntimeException("here");
2532 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002533 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002534 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 mPolicy.removeWindowLw(win);
2537 win.removeLocked();
2538
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002539 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 mWindowMap.remove(win.mClient.asBinder());
2541 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002542 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002543 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002544 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545
2546 if (mInputMethodWindow == win) {
2547 mInputMethodWindow = null;
2548 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2549 mInputMethodDialogs.remove(win);
2550 }
Romain Guy06882f82009-06-10 13:36:04 -07002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 final WindowToken token = win.mToken;
2553 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002554 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 token.windows.remove(win);
2556 if (atoken != null) {
2557 atoken.allAppWindows.remove(win);
2558 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002559 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 TAG, "**** Removing window " + win + ": count="
2561 + token.windows.size());
2562 if (token.windows.size() == 0) {
2563 if (!token.explicit) {
2564 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 } else if (atoken != null) {
2566 atoken.firstWindowDrawn = false;
2567 }
2568 }
2569
2570 if (atoken != null) {
2571 if (atoken.startingWindow == win) {
2572 atoken.startingWindow = null;
2573 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2574 // If this is the last window and we had requested a starting
2575 // transition window, well there is no point now.
2576 atoken.startingData = null;
2577 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2578 // If this is the last window except for a starting transition
2579 // window, we need to get rid of the starting transition.
2580 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002581 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 + ": no more real windows");
2583 }
2584 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2585 mH.sendMessage(m);
2586 }
2587 }
Romain Guy06882f82009-06-10 13:36:04 -07002588
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002589 if (win.mAttrs.type == TYPE_WALLPAPER) {
2590 mLastWallpaperTimeoutTime = 0;
2591 adjustWallpaperWindowsLocked();
2592 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002593 adjustWallpaperWindowsLocked();
2594 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002596 if (!mInLayout) {
2597 assignLayersLocked();
2598 mLayoutNeeded = true;
2599 performLayoutAndPlaceSurfacesLocked();
2600 if (win.mAppToken != null) {
2601 win.mAppToken.updateReportedVisibilityLocked();
2602 }
2603 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002604
Jeff Brown2e44b072011-01-24 15:21:56 -08002605 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 }
2607
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002608 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2609 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2610 + ": " + msg + " / " + w.mAttrs.getTitle();
2611 if (where != null) {
2612 Slog.i(TAG, str, where);
2613 } else {
2614 Slog.i(TAG, str);
2615 }
2616 }
2617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2619 long origId = Binder.clearCallingIdentity();
2620 try {
2621 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002622 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002624 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2625 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002626 Surface.openTransaction();
2627 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002628 if (SHOW_TRANSACTIONS) logSurface(w,
2629 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002630 w.mSurface.setTransparentRegionHint(region);
2631 } finally {
2632 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002633 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2634 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 }
2636 }
2637 }
2638 } finally {
2639 Binder.restoreCallingIdentity(origId);
2640 }
2641 }
2642
2643 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002644 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002645 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 long origId = Binder.clearCallingIdentity();
2647 try {
2648 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002649 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002650 if (w != null) {
2651 w.mGivenInsetsPending = false;
2652 w.mGivenContentInsets.set(contentInsets);
2653 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002654 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 w.mTouchableInsets = touchableInsets;
2656 mLayoutNeeded = true;
2657 performLayoutAndPlaceSurfacesLocked();
2658 }
2659 }
2660 } finally {
2661 Binder.restoreCallingIdentity(origId);
2662 }
2663 }
Romain Guy06882f82009-06-10 13:36:04 -07002664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002665 public void getWindowDisplayFrame(Session session, IWindow client,
2666 Rect outDisplayFrame) {
2667 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002668 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 if (win == null) {
2670 outDisplayFrame.setEmpty();
2671 return;
2672 }
2673 outDisplayFrame.set(win.mDisplayFrame);
2674 }
2675 }
2676
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002677 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2678 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002679 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2680 window.mWallpaperX = x;
2681 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002682 window.mWallpaperXStep = xStep;
2683 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002684 if (updateWallpaperOffsetLocked(window, true)) {
2685 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002686 }
2687 }
2688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002689
Dianne Hackborn75804932009-10-20 20:15:20 -07002690 void wallpaperCommandComplete(IBinder window, Bundle result) {
2691 synchronized (mWindowMap) {
2692 if (mWaitingOnWallpaper != null &&
2693 mWaitingOnWallpaper.mClient.asBinder() == window) {
2694 mWaitingOnWallpaper = null;
2695 mWindowMap.notifyAll();
2696 }
2697 }
2698 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002699
Dianne Hackborn75804932009-10-20 20:15:20 -07002700 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2701 String action, int x, int y, int z, Bundle extras, boolean sync) {
2702 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2703 || window == mUpperWallpaperTarget) {
2704 boolean doWait = sync;
2705 int curTokenIndex = mWallpaperTokens.size();
2706 while (curTokenIndex > 0) {
2707 curTokenIndex--;
2708 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2709 int curWallpaperIndex = token.windows.size();
2710 while (curWallpaperIndex > 0) {
2711 curWallpaperIndex--;
2712 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2713 try {
2714 wallpaper.mClient.dispatchWallpaperCommand(action,
2715 x, y, z, extras, sync);
2716 // We only want to be synchronous with one wallpaper.
2717 sync = false;
2718 } catch (RemoteException e) {
2719 }
2720 }
2721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002722
Dianne Hackborn75804932009-10-20 20:15:20 -07002723 if (doWait) {
2724 // XXX Need to wait for result.
2725 }
2726 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002727
Dianne Hackborn75804932009-10-20 20:15:20 -07002728 return null;
2729 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 public int relayoutWindow(Session session, IWindow client,
2732 WindowManager.LayoutParams attrs, int requestedWidth,
2733 int requestedHeight, int viewVisibility, boolean insetsPending,
2734 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002735 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002736 boolean displayed = false;
2737 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002738 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002739 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002742 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 if (win == null) {
2744 return 0;
2745 }
2746 win.mRequestedWidth = requestedWidth;
2747 win.mRequestedHeight = requestedHeight;
2748
2749 if (attrs != null) {
2750 mPolicy.adjustWindowParamsLw(attrs);
2751 }
Romain Guy06882f82009-06-10 13:36:04 -07002752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 int attrChanges = 0;
2754 int flagChanges = 0;
2755 if (attrs != null) {
2756 flagChanges = win.mAttrs.flags ^= attrs.flags;
2757 attrChanges = win.mAttrs.copyFrom(attrs);
2758 }
2759
Joe Onorato8a9b2202010-02-26 18:56:32 -08002760 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761
2762 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2763 win.mAlpha = attrs.alpha;
2764 }
2765
2766 final boolean scaledWindow =
2767 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2768
2769 if (scaledWindow) {
2770 // requested{Width|Height} Surface's physical size
2771 // attrs.{width|height} Size on screen
2772 win.mHScale = (attrs.width != requestedWidth) ?
2773 (attrs.width / (float)requestedWidth) : 1.0f;
2774 win.mVScale = (attrs.height != requestedHeight) ?
2775 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002776 } else {
2777 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002778 }
2779
2780 boolean imMayMove = (flagChanges&(
2781 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2782 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 boolean focusMayChange = win.mViewVisibility != viewVisibility
2785 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2786 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002787
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002788 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2789 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 win.mRelayoutCalled = true;
2792 final int oldVisibility = win.mViewVisibility;
2793 win.mViewVisibility = viewVisibility;
2794 if (viewVisibility == View.VISIBLE &&
2795 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2796 displayed = !win.isVisibleLw();
2797 if (win.mExiting) {
2798 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002799 if (win.mAnimation != null) {
2800 win.mAnimation.cancel();
2801 win.mAnimation = null;
2802 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 }
2804 if (win.mDestroying) {
2805 win.mDestroying = false;
2806 mDestroySurface.remove(win);
2807 }
2808 if (oldVisibility == View.GONE) {
2809 win.mEnterAnimationPending = true;
2810 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002811 if (displayed) {
2812 if (win.mSurface != null && !win.mDrawPending
2813 && !win.mCommitDrawPending && !mDisplayFrozen
2814 && mPolicy.isScreenOn()) {
2815 applyEnterAnimationLocked(win);
2816 }
2817 if ((win.mAttrs.flags
2818 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2819 if (DEBUG_VISIBILITY) Slog.v(TAG,
2820 "Relayout window turning screen on: " + win);
2821 win.mTurnOnScreen = true;
2822 }
2823 int diff = 0;
2824 if (win.mConfiguration != mCurConfiguration
2825 && (win.mConfiguration == null
2826 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2827 win.mConfiguration = mCurConfiguration;
2828 if (DEBUG_CONFIGURATION) {
2829 Slog.i(TAG, "Window " + win + " visible with new config: "
2830 + win.mConfiguration + " / 0x"
2831 + Integer.toHexString(diff));
2832 }
2833 outConfig.setTo(mCurConfiguration);
2834 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2837 // To change the format, we need to re-build the surface.
2838 win.destroySurfaceLocked();
2839 displayed = true;
2840 }
2841 try {
2842 Surface surface = win.createSurfaceLocked();
2843 if (surface != null) {
2844 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002845 win.mReportDestroySurface = false;
2846 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002847 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002848 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002850 // For some reason there isn't a surface. Clear the
2851 // caller's object so they see the same state.
2852 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 }
2854 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002855 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002856
Joe Onorato8a9b2202010-02-26 18:56:32 -08002857 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002858 + client + " (" + win.mAttrs.getTitle() + ")",
2859 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 Binder.restoreCallingIdentity(origId);
2861 return 0;
2862 }
2863 if (displayed) {
2864 focusMayChange = true;
2865 }
2866 if (win.mAttrs.type == TYPE_INPUT_METHOD
2867 && mInputMethodWindow == null) {
2868 mInputMethodWindow = win;
2869 imMayMove = true;
2870 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002871 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2872 && win.mAppToken != null
2873 && win.mAppToken.startingWindow != null) {
2874 // Special handling of starting window over the base
2875 // window of the app: propagate lock screen flags to it,
2876 // to provide the correct semantics while starting.
2877 final int mask =
2878 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002879 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2880 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002881 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2882 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 } else {
2885 win.mEnterAnimationPending = false;
2886 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002887 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002888 + ": mExiting=" + win.mExiting
2889 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 // If we are not currently running the exit animation, we
2891 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002892 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 // Try starting an animation; if there isn't one, we
2894 // can destroy the surface right away.
2895 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2896 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2897 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2898 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002899 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002901 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 } else if (win.isAnimating()) {
2904 // Currently in a hide animation... turn this into
2905 // an exit.
2906 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002907 } else if (win == mWallpaperTarget) {
2908 // If the wallpaper is currently behind this
2909 // window, we need to change both of them inside
2910 // of a transaction to avoid artifacts.
2911 win.mExiting = true;
2912 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 } else {
2914 if (mInputMethodWindow == win) {
2915 mInputMethodWindow = null;
2916 }
2917 win.destroySurfaceLocked();
2918 }
2919 }
2920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002921
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002922 if (win.mSurface == null || (win.getAttrs().flags
2923 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2924 || win.mSurfacePendingDestroy) {
2925 // We are being called from a local process, which
2926 // means outSurface holds its current surface. Ensure the
2927 // surface object is cleared, but we don't want it actually
2928 // destroyed at this point.
2929 win.mSurfacePendingDestroy = false;
2930 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002931 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002932 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002933 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002934 "Keeping surface, will report destroy: " + win);
2935 win.mReportDestroySurface = true;
2936 outSurface.copyFrom(win.mSurface);
2937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 }
2939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 if (focusMayChange) {
2941 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002942 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2943 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002944 imMayMove = false;
2945 }
2946 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2947 }
Romain Guy06882f82009-06-10 13:36:04 -07002948
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002949 // updateFocusedWindowLocked() already assigned layers so we only need to
2950 // reassign them at this point if the IM window state gets shuffled
2951 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002954 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2955 // Little hack here -- we -should- be able to rely on the
2956 // function to return true if the IME has moved and needs
2957 // its layer recomputed. However, if the IME was hidden
2958 // and isn't actually moved in the list, its layer may be
2959 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 assignLayers = true;
2961 }
2962 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002963 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002964 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002965 assignLayers = true;
2966 }
2967 }
Romain Guy06882f82009-06-10 13:36:04 -07002968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 mLayoutNeeded = true;
2970 win.mGivenInsetsPending = insetsPending;
2971 if (assignLayers) {
2972 assignLayersLocked();
2973 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002974 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002976 if (displayed && win.mIsWallpaper) {
2977 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002978 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 if (win.mAppToken != null) {
2981 win.mAppToken.updateReportedVisibilityLocked();
2982 }
2983 outFrame.set(win.mFrame);
2984 outContentInsets.set(win.mContentInsets);
2985 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002986 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002988 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 + ", requestedHeight=" + requestedHeight
2990 + ", viewVisibility=" + viewVisibility
2991 + "\nRelayout returning frame=" + outFrame
2992 + ", surface=" + outSurface);
2993
Joe Onorato8a9b2202010-02-26 18:56:32 -08002994 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2996
2997 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002998
Jeff Brown2e44b072011-01-24 15:21:56 -08002999 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003000 }
3001
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003002 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003 sendNewConfiguration();
3004 }
Romain Guy06882f82009-06-10 13:36:04 -07003005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003008 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3009 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3010 }
3011
3012 public void finishDrawingWindow(Session session, IWindow client) {
3013 final long origId = Binder.clearCallingIdentity();
3014 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003015 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003017 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3018 adjustWallpaperWindowsLocked();
3019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003020 mLayoutNeeded = true;
3021 performLayoutAndPlaceSurfacesLocked();
3022 }
3023 }
3024 Binder.restoreCallingIdentity(origId);
3025 }
3026
3027 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003028 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003029 + (lp != null ? lp.packageName : null)
3030 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3031 if (lp != null && lp.windowAnimations != 0) {
3032 // If this is a system resource, don't try to load it from the
3033 // application resources. It is nice to avoid loading application
3034 // resources if we can.
3035 String packageName = lp.packageName != null ? lp.packageName : "android";
3036 int resId = lp.windowAnimations;
3037 if ((resId&0xFF000000) == 0x01000000) {
3038 packageName = "android";
3039 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003040 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041 + packageName);
3042 return AttributeCache.instance().get(packageName, resId,
3043 com.android.internal.R.styleable.WindowAnimation);
3044 }
3045 return null;
3046 }
Romain Guy06882f82009-06-10 13:36:04 -07003047
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003048 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003049 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003050 + packageName + " resId=0x" + Integer.toHexString(resId));
3051 if (packageName != null) {
3052 if ((resId&0xFF000000) == 0x01000000) {
3053 packageName = "android";
3054 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003055 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003056 + packageName);
3057 return AttributeCache.instance().get(packageName, resId,
3058 com.android.internal.R.styleable.WindowAnimation);
3059 }
3060 return null;
3061 }
3062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 private void applyEnterAnimationLocked(WindowState win) {
3064 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3065 if (win.mEnterAnimationPending) {
3066 win.mEnterAnimationPending = false;
3067 transit = WindowManagerPolicy.TRANSIT_ENTER;
3068 }
3069
3070 applyAnimationLocked(win, transit, true);
3071 }
3072
3073 private boolean applyAnimationLocked(WindowState win,
3074 int transit, boolean isEntrance) {
3075 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3076 // If we are trying to apply an animation, but already running
3077 // an animation of the same type, then just leave that one alone.
3078 return true;
3079 }
Romain Guy06882f82009-06-10 13:36:04 -07003080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 // Only apply an animation if the display isn't frozen. If it is
3082 // frozen, there is no reason to animate and it can cause strange
3083 // artifacts when we unfreeze the display if some different animation
3084 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003085 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003086 int anim = mPolicy.selectAnimationLw(win, transit);
3087 int attr = -1;
3088 Animation a = null;
3089 if (anim != 0) {
3090 a = AnimationUtils.loadAnimation(mContext, anim);
3091 } else {
3092 switch (transit) {
3093 case WindowManagerPolicy.TRANSIT_ENTER:
3094 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3095 break;
3096 case WindowManagerPolicy.TRANSIT_EXIT:
3097 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3098 break;
3099 case WindowManagerPolicy.TRANSIT_SHOW:
3100 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3101 break;
3102 case WindowManagerPolicy.TRANSIT_HIDE:
3103 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3104 break;
3105 }
3106 if (attr >= 0) {
3107 a = loadAnimation(win.mAttrs, attr);
3108 }
3109 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003110 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003111 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3112 + " mAnimation=" + win.mAnimation
3113 + " isEntrance=" + isEntrance);
3114 if (a != null) {
3115 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003116 RuntimeException e = null;
3117 if (!HIDE_STACK_CRAWLS) {
3118 e = new RuntimeException();
3119 e.fillInStackTrace();
3120 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003121 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 }
3123 win.setAnimation(a);
3124 win.mAnimationIsEntrance = isEntrance;
3125 }
3126 } else {
3127 win.clearAnimation();
3128 }
3129
3130 return win.mAnimation != null;
3131 }
3132
3133 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3134 int anim = 0;
3135 Context context = mContext;
3136 if (animAttr >= 0) {
3137 AttributeCache.Entry ent = getCachedAnimations(lp);
3138 if (ent != null) {
3139 context = ent.context;
3140 anim = ent.array.getResourceId(animAttr, 0);
3141 }
3142 }
3143 if (anim != 0) {
3144 return AnimationUtils.loadAnimation(context, anim);
3145 }
3146 return null;
3147 }
Romain Guy06882f82009-06-10 13:36:04 -07003148
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003149 private Animation loadAnimation(String packageName, int resId) {
3150 int anim = 0;
3151 Context context = mContext;
3152 if (resId >= 0) {
3153 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3154 if (ent != null) {
3155 context = ent.context;
3156 anim = resId;
3157 }
3158 }
3159 if (anim != 0) {
3160 return AnimationUtils.loadAnimation(context, anim);
3161 }
3162 return null;
3163 }
3164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003165 private boolean applyAnimationLocked(AppWindowToken wtoken,
3166 WindowManager.LayoutParams lp, int transit, boolean enter) {
3167 // Only apply an animation if the display isn't frozen. If it is
3168 // frozen, there is no reason to animate and it can cause strange
3169 // artifacts when we unfreeze the display if some different animation
3170 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003171 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003172 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003173 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003174 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003175 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003176 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003177 } else if (mNextAppTransitionPackage != null) {
3178 a = loadAnimation(mNextAppTransitionPackage, enter ?
3179 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003180 } else {
3181 int animAttr = 0;
3182 switch (transit) {
3183 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3184 animAttr = enter
3185 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3186 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3187 break;
3188 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3189 animAttr = enter
3190 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3191 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3192 break;
3193 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3194 animAttr = enter
3195 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3196 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3197 break;
3198 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3199 animAttr = enter
3200 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3201 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3202 break;
3203 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3204 animAttr = enter
3205 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3206 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3207 break;
3208 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3209 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003210 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003211 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3212 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003213 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003214 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003215 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3216 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003217 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003218 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003219 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003220 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3221 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3222 break;
3223 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3224 animAttr = enter
3225 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3226 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3227 break;
3228 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3229 animAttr = enter
3230 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3231 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003232 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003233 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003234 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003235 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003236 + " anim=" + a
3237 + " animAttr=0x" + Integer.toHexString(animAttr)
3238 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003240 if (a != null) {
3241 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003242 RuntimeException e = null;
3243 if (!HIDE_STACK_CRAWLS) {
3244 e = new RuntimeException();
3245 e.fillInStackTrace();
3246 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003247 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 }
3249 wtoken.setAnimation(a);
3250 }
3251 } else {
3252 wtoken.clearAnimation();
3253 }
3254
3255 return wtoken.animation != null;
3256 }
3257
3258 // -------------------------------------------------------------
3259 // Application Window Tokens
3260 // -------------------------------------------------------------
3261
3262 public void validateAppTokens(List tokens) {
3263 int v = tokens.size()-1;
3264 int m = mAppTokens.size()-1;
3265 while (v >= 0 && m >= 0) {
3266 AppWindowToken wtoken = mAppTokens.get(m);
3267 if (wtoken.removed) {
3268 m--;
3269 continue;
3270 }
3271 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003272 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003273 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3274 }
3275 v--;
3276 m--;
3277 }
3278 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003279 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 v--;
3281 }
3282 while (m >= 0) {
3283 AppWindowToken wtoken = mAppTokens.get(m);
3284 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003285 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 }
3287 m--;
3288 }
3289 }
3290
3291 boolean checkCallingPermission(String permission, String func) {
3292 // Quick check: if the calling permission is me, it's all okay.
3293 if (Binder.getCallingPid() == Process.myPid()) {
3294 return true;
3295 }
Romain Guy06882f82009-06-10 13:36:04 -07003296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 if (mContext.checkCallingPermission(permission)
3298 == PackageManager.PERMISSION_GRANTED) {
3299 return true;
3300 }
3301 String msg = "Permission Denial: " + func + " from pid="
3302 + Binder.getCallingPid()
3303 + ", uid=" + Binder.getCallingUid()
3304 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003305 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 return false;
3307 }
Romain Guy06882f82009-06-10 13:36:04 -07003308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 AppWindowToken findAppWindowToken(IBinder token) {
3310 WindowToken wtoken = mTokenMap.get(token);
3311 if (wtoken == null) {
3312 return null;
3313 }
3314 return wtoken.appWindowToken;
3315 }
Romain Guy06882f82009-06-10 13:36:04 -07003316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 public void addWindowToken(IBinder token, int type) {
3318 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3319 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003320 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 }
Romain Guy06882f82009-06-10 13:36:04 -07003322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 synchronized(mWindowMap) {
3324 WindowToken wtoken = mTokenMap.get(token);
3325 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003326 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 return;
3328 }
3329 wtoken = new WindowToken(token, type, true);
3330 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003331 if (type == TYPE_WALLPAPER) {
3332 mWallpaperTokens.add(wtoken);
3333 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 }
3335 }
Romain Guy06882f82009-06-10 13:36:04 -07003336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 public void removeWindowToken(IBinder token) {
3338 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3339 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003340 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 }
3342
3343 final long origId = Binder.clearCallingIdentity();
3344 synchronized(mWindowMap) {
3345 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 if (wtoken != null) {
3347 boolean delayed = false;
3348 if (!wtoken.hidden) {
3349 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003351 final int N = wtoken.windows.size();
3352 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 for (int i=0; i<N; i++) {
3355 WindowState win = wtoken.windows.get(i);
3356
3357 if (win.isAnimating()) {
3358 delayed = true;
3359 }
Romain Guy06882f82009-06-10 13:36:04 -07003360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003361 if (win.isVisibleNow()) {
3362 applyAnimationLocked(win,
3363 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 changed = true;
3365 }
3366 }
3367
3368 if (changed) {
3369 mLayoutNeeded = true;
3370 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003371 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3372 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 }
Romain Guy06882f82009-06-10 13:36:04 -07003374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 if (delayed) {
3376 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003377 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3378 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 }
3380 }
Romain Guy06882f82009-06-10 13:36:04 -07003381
Jeff Brown2e44b072011-01-24 15:21:56 -08003382 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003384 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 }
3386 }
3387 Binder.restoreCallingIdentity(origId);
3388 }
3389
3390 public void addAppToken(int addPos, IApplicationToken token,
3391 int groupId, int requestedOrientation, boolean fullscreen) {
3392 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3393 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003394 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 }
Jeff Brown349703e2010-06-22 01:27:15 -07003396
3397 // Get the dispatching timeout here while we are not holding any locks so that it
3398 // can be cached by the AppWindowToken. The timeout value is used later by the
3399 // input dispatcher in code that does hold locks. If we did not cache the value
3400 // here we would run the chance of introducing a deadlock between the window manager
3401 // (which holds locks while updating the input dispatcher state) and the activity manager
3402 // (which holds locks while querying the application token).
3403 long inputDispatchingTimeoutNanos;
3404 try {
3405 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3406 } catch (RemoteException ex) {
3407 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3408 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3409 }
Romain Guy06882f82009-06-10 13:36:04 -07003410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 synchronized(mWindowMap) {
3412 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3413 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003414 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 return;
3416 }
3417 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003418 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 wtoken.groupId = groupId;
3420 wtoken.appFullscreen = fullscreen;
3421 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003422 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003423 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 // Application tokens start out hidden.
3427 wtoken.hidden = true;
3428 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 //dump();
3431 }
3432 }
Romain Guy06882f82009-06-10 13:36:04 -07003433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 public void setAppGroupId(IBinder token, int groupId) {
3435 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3436 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003437 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003438 }
3439
3440 synchronized(mWindowMap) {
3441 AppWindowToken wtoken = findAppWindowToken(token);
3442 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003443 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 return;
3445 }
3446 wtoken.groupId = groupId;
3447 }
3448 }
Romain Guy06882f82009-06-10 13:36:04 -07003449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 public int getOrientationFromWindowsLocked() {
3451 int pos = mWindows.size() - 1;
3452 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003453 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 pos--;
3455 if (wtoken.mAppToken != null) {
3456 // We hit an application window. so the orientation will be determined by the
3457 // app window. No point in continuing further.
3458 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3459 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003460 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003461 continue;
3462 }
3463 int req = wtoken.mAttrs.screenOrientation;
3464 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3465 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3466 continue;
3467 } else {
3468 return req;
3469 }
3470 }
3471 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3472 }
Romain Guy06882f82009-06-10 13:36:04 -07003473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003475 int pos = mAppTokens.size() - 1;
3476 int curGroup = 0;
3477 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3478 boolean findingBehind = false;
3479 boolean haveGroup = false;
3480 boolean lastFullscreen = false;
3481 while (pos >= 0) {
3482 AppWindowToken wtoken = mAppTokens.get(pos);
3483 pos--;
3484 // if we're about to tear down this window and not seek for
3485 // the behind activity, don't use it for orientation
3486 if (!findingBehind
3487 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3488 continue;
3489 }
3490
3491 if (!haveGroup) {
3492 // We ignore any hidden applications on the top.
3493 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003494 continue;
3495 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003496 haveGroup = true;
3497 curGroup = wtoken.groupId;
3498 lastOrientation = wtoken.requestedOrientation;
3499 } else if (curGroup != wtoken.groupId) {
3500 // If we have hit a new application group, and the bottom
3501 // of the previous group didn't explicitly say to use
3502 // the orientation behind it, and the last app was
3503 // full screen, then we'll stick with the
3504 // user's orientation.
3505 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3506 && lastFullscreen) {
3507 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003510 int or = wtoken.requestedOrientation;
3511 // If this application is fullscreen, and didn't explicitly say
3512 // to use the orientation behind it, then just take whatever
3513 // orientation it has and ignores whatever is under it.
3514 lastFullscreen = wtoken.appFullscreen;
3515 if (lastFullscreen
3516 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3517 return or;
3518 }
3519 // If this application has requested an explicit orientation,
3520 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003521 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3522 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003523 return or;
3524 }
3525 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3526 }
3527 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 }
Romain Guy06882f82009-06-10 13:36:04 -07003529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003531 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003532 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3533 "updateOrientationFromAppTokens()")) {
3534 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3535 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003536
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003537 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003539
3540 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003541 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003542 if (freezeThisOneIfNeeded != null) {
3543 AppWindowToken wtoken = findAppWindowToken(
3544 freezeThisOneIfNeeded);
3545 if (wtoken != null) {
3546 startAppFreezingScreenLocked(wtoken,
3547 ActivityInfo.CONFIG_ORIENTATION);
3548 }
3549 }
3550 config = computeNewConfigurationLocked();
3551
3552 } else if (currentConfig != null) {
3553 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003554 // state mismatches the activity manager's, update it,
3555 // disregarding font scale, which should remain set to
3556 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003557 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003558 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003559 if (computeNewConfigurationLocked(mTempConfiguration)) {
3560 if (currentConfig.diff(mTempConfiguration) != 0) {
3561 mWaitingForConfig = true;
3562 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003563 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003564 config = new Configuration(mTempConfiguration);
3565 }
3566 }
3567 }
3568 }
3569
Dianne Hackborncfaef692009-06-15 14:24:44 -07003570 Binder.restoreCallingIdentity(ident);
3571 return config;
3572 }
3573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003575 * Determine the new desired orientation of the display, returning
3576 * a non-null new Configuration if it has changed from the current
3577 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3578 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3579 * SCREEN. This will typically be done for you if you call
3580 * sendNewConfiguration().
3581 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 * The orientation is computed from non-application windows first. If none of
3583 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003584 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3586 * android.os.IBinder)
3587 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003588 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3589 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003590 // If the display is frozen, some activities may be in the middle
3591 // of restarting, and thus have removed their old window. If the
3592 // window has the flag to hide the lock screen, then the lock screen
3593 // can re-appear and inflict its own orientation on us. Keep the
3594 // orientation stable until this all settles down.
3595 return false;
3596 }
3597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 long ident = Binder.clearCallingIdentity();
3600 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003601 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 mForcedAppOrientation = req;
3605 //send a message to Policy indicating orientation change to take
3606 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003607 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003608 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003609 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3610 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003611 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 }
3613 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003614
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003615 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 } finally {
3617 Binder.restoreCallingIdentity(ident);
3618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 }
Romain Guy06882f82009-06-10 13:36:04 -07003620
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003621 int computeForcedAppOrientationLocked() {
3622 int req = getOrientationFromWindowsLocked();
3623 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3624 req = getOrientationFromAppTokensLocked();
3625 }
3626 return req;
3627 }
Romain Guy06882f82009-06-10 13:36:04 -07003628
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003629 public void setNewConfiguration(Configuration config) {
3630 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3631 "setNewConfiguration()")) {
3632 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3633 }
3634
3635 synchronized(mWindowMap) {
3636 mCurConfiguration = new Configuration(config);
3637 mWaitingForConfig = false;
3638 performLayoutAndPlaceSurfacesLocked();
3639 }
3640 }
3641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3643 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3644 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003645 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003646 }
Romain Guy06882f82009-06-10 13:36:04 -07003647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 synchronized(mWindowMap) {
3649 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3650 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003651 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003652 return;
3653 }
Romain Guy06882f82009-06-10 13:36:04 -07003654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 wtoken.requestedOrientation = requestedOrientation;
3656 }
3657 }
Romain Guy06882f82009-06-10 13:36:04 -07003658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659 public int getAppOrientation(IApplicationToken token) {
3660 synchronized(mWindowMap) {
3661 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3662 if (wtoken == null) {
3663 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3664 }
Romain Guy06882f82009-06-10 13:36:04 -07003665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003666 return wtoken.requestedOrientation;
3667 }
3668 }
Romain Guy06882f82009-06-10 13:36:04 -07003669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3671 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3672 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003673 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 }
3675
3676 synchronized(mWindowMap) {
3677 boolean changed = false;
3678 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003679 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 changed = mFocusedApp != null;
3681 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003682 if (changed) {
3683 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003684 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 } else {
3686 AppWindowToken newFocus = findAppWindowToken(token);
3687 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003688 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003689 return;
3690 }
3691 changed = mFocusedApp != newFocus;
3692 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003693 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003694 if (changed) {
3695 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003696 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003697 }
3698
3699 if (moveFocusNow && changed) {
3700 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003701 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 Binder.restoreCallingIdentity(origId);
3703 }
3704 }
3705 }
3706
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003707 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3709 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003710 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 }
Romain Guy06882f82009-06-10 13:36:04 -07003712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003714 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 TAG, "Prepare app transition: transit=" + transit
3716 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003717 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003718 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3719 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003721 } else if (!alwaysKeepCurrent) {
3722 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3723 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3724 // Opening a new task always supersedes a close for the anim.
3725 mNextAppTransition = transit;
3726 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3727 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3728 // Opening a new activity always supersedes a close for the anim.
3729 mNextAppTransition = transit;
3730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 }
3732 mAppTransitionReady = false;
3733 mAppTransitionTimeout = false;
3734 mStartingIconInTransition = false;
3735 mSkipAppTransitionAnimation = false;
3736 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3737 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3738 5000);
3739 }
3740 }
3741 }
3742
3743 public int getPendingAppTransition() {
3744 return mNextAppTransition;
3745 }
Romain Guy06882f82009-06-10 13:36:04 -07003746
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003747 public void overridePendingAppTransition(String packageName,
3748 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003749 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003750 mNextAppTransitionPackage = packageName;
3751 mNextAppTransitionEnter = enterAnim;
3752 mNextAppTransitionExit = exitAnim;
3753 }
3754 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 public void executeAppTransition() {
3757 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3758 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003759 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 }
Romain Guy06882f82009-06-10 13:36:04 -07003761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003763 if (DEBUG_APP_TRANSITIONS) {
3764 RuntimeException e = new RuntimeException("here");
3765 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003766 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003767 + mNextAppTransition, e);
3768 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003769 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 mAppTransitionReady = true;
3771 final long origId = Binder.clearCallingIdentity();
3772 performLayoutAndPlaceSurfacesLocked();
3773 Binder.restoreCallingIdentity(origId);
3774 }
3775 }
3776 }
3777
3778 public void setAppStartingWindow(IBinder token, String pkg,
3779 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003780 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3782 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003783 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 }
3785
3786 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003787 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3789 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 AppWindowToken wtoken = findAppWindowToken(token);
3792 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003793 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 return;
3795 }
3796
3797 // If the display is frozen, we won't do anything until the
3798 // actual window is displayed so there is no reason to put in
3799 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003800 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 return;
3802 }
Romain Guy06882f82009-06-10 13:36:04 -07003803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 if (wtoken.startingData != null) {
3805 return;
3806 }
Romain Guy06882f82009-06-10 13:36:04 -07003807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003808 if (transferFrom != null) {
3809 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3810 if (ttoken != null) {
3811 WindowState startingWindow = ttoken.startingWindow;
3812 if (startingWindow != null) {
3813 if (mStartingIconInTransition) {
3814 // In this case, the starting icon has already
3815 // been displayed, so start letting windows get
3816 // shown immediately without any more transitions.
3817 mSkipAppTransitionAnimation = true;
3818 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003819 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 "Moving existing starting from " + ttoken
3821 + " to " + wtoken);
3822 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 // Transfer the starting window over to the new
3825 // token.
3826 wtoken.startingData = ttoken.startingData;
3827 wtoken.startingView = ttoken.startingView;
3828 wtoken.startingWindow = startingWindow;
3829 ttoken.startingData = null;
3830 ttoken.startingView = null;
3831 ttoken.startingWindow = null;
3832 ttoken.startingMoved = true;
3833 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003834 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003836 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003837 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003839 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003840 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3841 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 ttoken.windows.remove(startingWindow);
3843 ttoken.allAppWindows.remove(startingWindow);
3844 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 // Propagate other interesting state between the
3847 // tokens. If the old token is displayed, we should
3848 // immediately force the new one to be displayed. If
3849 // it is animating, we need to move that animation to
3850 // the new one.
3851 if (ttoken.allDrawn) {
3852 wtoken.allDrawn = true;
3853 }
3854 if (ttoken.firstWindowDrawn) {
3855 wtoken.firstWindowDrawn = true;
3856 }
3857 if (!ttoken.hidden) {
3858 wtoken.hidden = false;
3859 wtoken.hiddenRequested = false;
3860 wtoken.willBeHidden = false;
3861 }
3862 if (wtoken.clientHidden != ttoken.clientHidden) {
3863 wtoken.clientHidden = ttoken.clientHidden;
3864 wtoken.sendAppVisibilityToClients();
3865 }
3866 if (ttoken.animation != null) {
3867 wtoken.animation = ttoken.animation;
3868 wtoken.animating = ttoken.animating;
3869 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3870 ttoken.animation = null;
3871 ttoken.animLayerAdjustment = 0;
3872 wtoken.updateLayers();
3873 ttoken.updateLayers();
3874 }
Romain Guy06882f82009-06-10 13:36:04 -07003875
Jeff Brown3a22cd92011-01-21 13:59:04 -08003876 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3877 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 mLayoutNeeded = true;
3879 performLayoutAndPlaceSurfacesLocked();
3880 Binder.restoreCallingIdentity(origId);
3881 return;
3882 } else if (ttoken.startingData != null) {
3883 // The previous app was getting ready to show a
3884 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003885 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 "Moving pending starting from " + ttoken
3887 + " to " + wtoken);
3888 wtoken.startingData = ttoken.startingData;
3889 ttoken.startingData = null;
3890 ttoken.startingMoved = true;
3891 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3892 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3893 // want to process the message ASAP, before any other queued
3894 // messages.
3895 mH.sendMessageAtFrontOfQueue(m);
3896 return;
3897 }
3898 }
3899 }
3900
3901 // There is no existing starting window, and the caller doesn't
3902 // want us to create one, so that's it!
3903 if (!createIfNeeded) {
3904 return;
3905 }
Romain Guy06882f82009-06-10 13:36:04 -07003906
Dianne Hackborn284ac932009-08-28 10:34:25 -07003907 // If this is a translucent or wallpaper window, then don't
3908 // show a starting window -- the current effect (a full-screen
3909 // opaque starting window that fades away to the real contents
3910 // when it is ready) does not work for this.
3911 if (theme != 0) {
3912 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3913 com.android.internal.R.styleable.Window);
3914 if (ent.array.getBoolean(
3915 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3916 return;
3917 }
3918 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003919 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3920 return;
3921 }
3922 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003923 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3924 return;
3925 }
3926 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003928 mStartingIconInTransition = true;
3929 wtoken.startingData = new StartingData(
3930 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003931 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3933 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3934 // want to process the message ASAP, before any other queued
3935 // messages.
3936 mH.sendMessageAtFrontOfQueue(m);
3937 }
3938 }
3939
3940 public void setAppWillBeHidden(IBinder token) {
3941 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3942 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003943 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944 }
3945
3946 AppWindowToken wtoken;
3947
3948 synchronized(mWindowMap) {
3949 wtoken = findAppWindowToken(token);
3950 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003951 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 -08003952 return;
3953 }
3954 wtoken.willBeHidden = true;
3955 }
3956 }
Romain Guy06882f82009-06-10 13:36:04 -07003957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3959 boolean visible, int transit, boolean performLayout) {
3960 boolean delayed = false;
3961
3962 if (wtoken.clientHidden == visible) {
3963 wtoken.clientHidden = !visible;
3964 wtoken.sendAppVisibilityToClients();
3965 }
Romain Guy06882f82009-06-10 13:36:04 -07003966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 wtoken.willBeHidden = false;
3968 if (wtoken.hidden == visible) {
3969 final int N = wtoken.allAppWindows.size();
3970 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003971 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3973 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003976
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003977 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978 if (wtoken.animation == sDummyAnimation) {
3979 wtoken.animation = null;
3980 }
3981 applyAnimationLocked(wtoken, lp, transit, visible);
3982 changed = true;
3983 if (wtoken.animation != null) {
3984 delayed = runningAppAnimation = true;
3985 }
3986 }
Romain Guy06882f82009-06-10 13:36:04 -07003987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 for (int i=0; i<N; i++) {
3989 WindowState win = wtoken.allAppWindows.get(i);
3990 if (win == wtoken.startingWindow) {
3991 continue;
3992 }
3993
3994 if (win.isAnimating()) {
3995 delayed = true;
3996 }
Romain Guy06882f82009-06-10 13:36:04 -07003997
Joe Onorato8a9b2202010-02-26 18:56:32 -08003998 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 //win.dump(" ");
4000 if (visible) {
4001 if (!win.isVisibleNow()) {
4002 if (!runningAppAnimation) {
4003 applyAnimationLocked(win,
4004 WindowManagerPolicy.TRANSIT_ENTER, true);
4005 }
4006 changed = true;
4007 }
4008 } else if (win.isVisibleNow()) {
4009 if (!runningAppAnimation) {
4010 applyAnimationLocked(win,
4011 WindowManagerPolicy.TRANSIT_EXIT, false);
4012 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 changed = true;
4014 }
4015 }
4016
4017 wtoken.hidden = wtoken.hiddenRequested = !visible;
4018 if (!visible) {
4019 unsetAppFreezingScreenLocked(wtoken, true, true);
4020 } else {
4021 // If we are being set visible, and the starting window is
4022 // not yet displayed, then make sure it doesn't get displayed.
4023 WindowState swin = wtoken.startingWindow;
4024 if (swin != null && (swin.mDrawPending
4025 || swin.mCommitDrawPending)) {
4026 swin.mPolicyVisibility = false;
4027 swin.mPolicyVisibilityAfterAnim = false;
4028 }
4029 }
Romain Guy06882f82009-06-10 13:36:04 -07004030
Joe Onorato8a9b2202010-02-26 18:56:32 -08004031 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004032 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4033 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004034
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004035 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004036 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004037 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004038 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004039 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4040 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004041 performLayoutAndPlaceSurfacesLocked();
4042 }
Jeff Brown2e44b072011-01-24 15:21:56 -08004043 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004044 }
4045 }
4046
4047 if (wtoken.animation != null) {
4048 delayed = true;
4049 }
Romain Guy06882f82009-06-10 13:36:04 -07004050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004051 return delayed;
4052 }
4053
4054 public void setAppVisibility(IBinder token, boolean visible) {
4055 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4056 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004057 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004058 }
4059
4060 AppWindowToken wtoken;
4061
4062 synchronized(mWindowMap) {
4063 wtoken = findAppWindowToken(token);
4064 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004065 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004066 return;
4067 }
4068
4069 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004070 RuntimeException e = null;
4071 if (!HIDE_STACK_CRAWLS) {
4072 e = new RuntimeException();
4073 e.fillInStackTrace();
4074 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004075 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 + "): mNextAppTransition=" + mNextAppTransition
4077 + " hidden=" + wtoken.hidden
4078 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4079 }
Romain Guy06882f82009-06-10 13:36:04 -07004080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 // If we are preparing an app transition, then delay changing
4082 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004083 if (!mDisplayFrozen && mPolicy.isScreenOn()
4084 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004085 // Already in requested state, don't do anything more.
4086 if (wtoken.hiddenRequested != visible) {
4087 return;
4088 }
4089 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004090
Joe Onorato8a9b2202010-02-26 18:56:32 -08004091 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 TAG, "Setting dummy animation on: " + wtoken);
4093 wtoken.setDummyAnimation();
4094 mOpeningApps.remove(wtoken);
4095 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004096 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097 wtoken.inPendingTransaction = true;
4098 if (visible) {
4099 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 wtoken.startingDisplayed = false;
4101 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004102
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004103 // If the token is currently hidden (should be the
4104 // common case), then we need to set up to wait for
4105 // its windows to be ready.
4106 if (wtoken.hidden) {
4107 wtoken.allDrawn = false;
4108 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004109
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004110 if (wtoken.clientHidden) {
4111 // In the case where we are making an app visible
4112 // but holding off for a transition, we still need
4113 // to tell the client to make its windows visible so
4114 // they get drawn. Otherwise, we will wait on
4115 // performing the transition until all windows have
4116 // been drawn, they never will be, and we are sad.
4117 wtoken.clientHidden = false;
4118 wtoken.sendAppVisibilityToClients();
4119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004120 }
4121 } else {
4122 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004123
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004124 // If the token is currently visible (should be the
4125 // common case), then set up to wait for it to be hidden.
4126 if (!wtoken.hidden) {
4127 wtoken.waitingToHide = true;
4128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 }
4130 return;
4131 }
Romain Guy06882f82009-06-10 13:36:04 -07004132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004134 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 wtoken.updateReportedVisibilityLocked();
4136 Binder.restoreCallingIdentity(origId);
4137 }
4138 }
4139
4140 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4141 boolean unfreezeSurfaceNow, boolean force) {
4142 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004143 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004144 + " force=" + force);
4145 final int N = wtoken.allAppWindows.size();
4146 boolean unfrozeWindows = false;
4147 for (int i=0; i<N; i++) {
4148 WindowState w = wtoken.allAppWindows.get(i);
4149 if (w.mAppFreezing) {
4150 w.mAppFreezing = false;
4151 if (w.mSurface != null && !w.mOrientationChanging) {
4152 w.mOrientationChanging = true;
4153 }
4154 unfrozeWindows = true;
4155 }
4156 }
4157 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004158 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004159 wtoken.freezingScreen = false;
4160 mAppsFreezingScreen--;
4161 }
4162 if (unfreezeSurfaceNow) {
4163 if (unfrozeWindows) {
4164 mLayoutNeeded = true;
4165 performLayoutAndPlaceSurfacesLocked();
4166 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004167 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 }
4169 }
4170 }
Romain Guy06882f82009-06-10 13:36:04 -07004171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4173 int configChanges) {
4174 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004175 RuntimeException e = null;
4176 if (!HIDE_STACK_CRAWLS) {
4177 e = new RuntimeException();
4178 e.fillInStackTrace();
4179 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004180 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 + ": hidden=" + wtoken.hidden + " freezing="
4182 + wtoken.freezingScreen, e);
4183 }
4184 if (!wtoken.hiddenRequested) {
4185 if (!wtoken.freezingScreen) {
4186 wtoken.freezingScreen = true;
4187 mAppsFreezingScreen++;
4188 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004189 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4191 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4192 5000);
4193 }
4194 }
4195 final int N = wtoken.allAppWindows.size();
4196 for (int i=0; i<N; i++) {
4197 WindowState w = wtoken.allAppWindows.get(i);
4198 w.mAppFreezing = true;
4199 }
4200 }
4201 }
Romain Guy06882f82009-06-10 13:36:04 -07004202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004203 public void startAppFreezingScreen(IBinder token, int configChanges) {
4204 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4205 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004206 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 }
4208
4209 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004210 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004211 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004212 return;
4213 }
Romain Guy06882f82009-06-10 13:36:04 -07004214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 AppWindowToken wtoken = findAppWindowToken(token);
4216 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004217 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 return;
4219 }
4220 final long origId = Binder.clearCallingIdentity();
4221 startAppFreezingScreenLocked(wtoken, configChanges);
4222 Binder.restoreCallingIdentity(origId);
4223 }
4224 }
Romain Guy06882f82009-06-10 13:36:04 -07004225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 public void stopAppFreezingScreen(IBinder token, boolean force) {
4227 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4228 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004229 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004230 }
4231
4232 synchronized(mWindowMap) {
4233 AppWindowToken wtoken = findAppWindowToken(token);
4234 if (wtoken == null || wtoken.appToken == null) {
4235 return;
4236 }
4237 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004238 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4240 unsetAppFreezingScreenLocked(wtoken, true, force);
4241 Binder.restoreCallingIdentity(origId);
4242 }
4243 }
Romain Guy06882f82009-06-10 13:36:04 -07004244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 public void removeAppToken(IBinder token) {
4246 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4247 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004248 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 }
4250
4251 AppWindowToken wtoken = null;
4252 AppWindowToken startingToken = null;
4253 boolean delayed = false;
4254
4255 final long origId = Binder.clearCallingIdentity();
4256 synchronized(mWindowMap) {
4257 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004259 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004260 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 wtoken.inPendingTransaction = false;
4262 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004263 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004264 if (mClosingApps.contains(wtoken)) {
4265 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004266 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004268 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 delayed = true;
4270 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004271 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 TAG, "Removing app " + wtoken + " delayed=" + delayed
4273 + " animation=" + wtoken.animation
4274 + " animating=" + wtoken.animating);
4275 if (delayed) {
4276 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004277 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4278 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004280 } else {
4281 // Make sure there is no animation running on this token,
4282 // so any windows associated with it will be removed as
4283 // soon as their animations are complete
4284 wtoken.animation = null;
4285 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004287 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4288 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 mAppTokens.remove(wtoken);
4290 wtoken.removed = true;
4291 if (wtoken.startingData != null) {
4292 startingToken = wtoken;
4293 }
4294 unsetAppFreezingScreenLocked(wtoken, true, true);
4295 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004296 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004298 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004299 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 }
4301 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004302 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 }
Romain Guy06882f82009-06-10 13:36:04 -07004304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 if (!delayed && wtoken != null) {
4306 wtoken.updateReportedVisibilityLocked();
4307 }
4308 }
4309 Binder.restoreCallingIdentity(origId);
4310
4311 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004312 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 + startingToken + ": app token removed");
4314 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4315 mH.sendMessage(m);
4316 }
4317 }
4318
4319 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4320 final int NW = token.windows.size();
4321 for (int i=0; i<NW; i++) {
4322 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004323 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004325 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 int j = win.mChildWindows.size();
4327 while (j > 0) {
4328 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004329 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004330 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004331 "Tmp removing child window " + cwin);
4332 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 }
4334 }
4335 return NW > 0;
4336 }
4337
4338 void dumpAppTokensLocked() {
4339 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004340 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004341 }
4342 }
Romain Guy06882f82009-06-10 13:36:04 -07004343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 void dumpWindowsLocked() {
4345 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004346 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 }
4348 }
Romain Guy06882f82009-06-10 13:36:04 -07004349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 private int findWindowOffsetLocked(int tokenPos) {
4351 final int NW = mWindows.size();
4352
4353 if (tokenPos >= mAppTokens.size()) {
4354 int i = NW;
4355 while (i > 0) {
4356 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004357 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 if (win.getAppToken() != null) {
4359 return i+1;
4360 }
4361 }
4362 }
4363
4364 while (tokenPos > 0) {
4365 // Find the first app token below the new position that has
4366 // a window displayed.
4367 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004368 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004370 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004371 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004372 "Skipping token -- currently sending to bottom");
4373 tokenPos--;
4374 continue;
4375 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 int i = wtoken.windows.size();
4377 while (i > 0) {
4378 i--;
4379 WindowState win = wtoken.windows.get(i);
4380 int j = win.mChildWindows.size();
4381 while (j > 0) {
4382 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004383 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004384 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 for (int pos=NW-1; pos>=0; pos--) {
4386 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004387 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004388 "Found child win @" + (pos+1));
4389 return pos+1;
4390 }
4391 }
4392 }
4393 }
4394 for (int pos=NW-1; pos>=0; pos--) {
4395 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004396 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004397 return pos+1;
4398 }
4399 }
4400 }
4401 tokenPos--;
4402 }
4403
4404 return 0;
4405 }
4406
4407 private final int reAddWindowLocked(int index, WindowState win) {
4408 final int NCW = win.mChildWindows.size();
4409 boolean added = false;
4410 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004411 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004412 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004413 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004414 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004415 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 mWindows.add(index, win);
4417 index++;
4418 added = true;
4419 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004420 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004421 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004422 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 mWindows.add(index, cwin);
4424 index++;
4425 }
4426 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004427 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004428 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004429 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004430 mWindows.add(index, win);
4431 index++;
4432 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004433 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004434 return index;
4435 }
Romain Guy06882f82009-06-10 13:36:04 -07004436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4438 final int NW = token.windows.size();
4439 for (int i=0; i<NW; i++) {
4440 index = reAddWindowLocked(index, token.windows.get(i));
4441 }
4442 return index;
4443 }
4444
4445 public void moveAppToken(int index, IBinder token) {
4446 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4447 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004448 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 }
4450
4451 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004452 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 if (DEBUG_REORDER) dumpAppTokensLocked();
4454 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004455 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4456 "Start moving token " + wtoken + " initially at "
4457 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004459 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004460 + token + " (" + wtoken + ")");
4461 return;
4462 }
4463 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004464 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004465 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004468 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004469 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 if (DEBUG_REORDER) dumpWindowsLocked();
4471 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004472 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 if (DEBUG_REORDER) dumpWindowsLocked();
4474 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004475 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004477 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4478 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004480 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004482 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 }
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) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004519 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004520 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4521 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004522 assignLayersLocked();
4523 }
4524 mLayoutNeeded = true;
4525 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004526 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004527 }
4528 }
4529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4531 // First remove all of the windows from the list.
4532 final int N = tokens.size();
4533 int i;
4534 for (i=0; i<N; i++) {
4535 WindowToken token = mTokenMap.get(tokens.get(i));
4536 if (token != null) {
4537 tmpRemoveAppWindowsLocked(token);
4538 }
4539 }
4540
4541 // Where to start adding?
4542 int pos = findWindowOffsetLocked(tokenPos);
4543
4544 // And now add them back at the correct place.
4545 for (i=0; i<N; i++) {
4546 WindowToken token = mTokenMap.get(tokens.get(i));
4547 if (token != null) {
4548 pos = reAddAppWindowsLocked(pos, token);
4549 }
4550 }
4551
Jeff Brown2e44b072011-01-24 15:21:56 -08004552 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004553 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4554 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004555 assignLayersLocked();
4556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004557 mLayoutNeeded = true;
4558 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004559 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004560
4561 //dump();
4562 }
4563
4564 public void moveAppTokensToTop(List<IBinder> tokens) {
4565 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4566 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004567 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004568 }
4569
4570 final long origId = Binder.clearCallingIdentity();
4571 synchronized(mWindowMap) {
4572 removeAppTokensLocked(tokens);
4573 final int N = tokens.size();
4574 for (int i=0; i<N; i++) {
4575 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4576 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004577 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4578 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004580 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004581 mToTopApps.remove(wt);
4582 mToBottomApps.remove(wt);
4583 mToTopApps.add(wt);
4584 wt.sendingToBottom = false;
4585 wt.sendingToTop = true;
4586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004587 }
4588 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004589
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004590 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004591 moveAppWindowsLocked(tokens, mAppTokens.size());
4592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 }
4594 Binder.restoreCallingIdentity(origId);
4595 }
4596
4597 public void moveAppTokensToBottom(List<IBinder> tokens) {
4598 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4599 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004600 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004601 }
4602
4603 final long origId = Binder.clearCallingIdentity();
4604 synchronized(mWindowMap) {
4605 removeAppTokensLocked(tokens);
4606 final int N = tokens.size();
4607 int pos = 0;
4608 for (int i=0; i<N; i++) {
4609 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4610 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004611 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4612 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004614 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004615 mToTopApps.remove(wt);
4616 mToBottomApps.remove(wt);
4617 mToBottomApps.add(i, wt);
4618 wt.sendingToTop = false;
4619 wt.sendingToBottom = true;
4620 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 pos++;
4622 }
4623 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004624
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004625 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004626 moveAppWindowsLocked(tokens, 0);
4627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004628 }
4629 Binder.restoreCallingIdentity(origId);
4630 }
4631
4632 // -------------------------------------------------------------
4633 // Misc IWindowSession methods
4634 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004635
Jim Miller284b62e2010-06-08 14:27:42 -07004636 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004637 {
Jim Miller284b62e2010-06-08 14:27:42 -07004638 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4639 // called before DevicePolicyManagerService has started.
4640 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4641 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4642 Context.DEVICE_POLICY_SERVICE);
4643 if (dpm != null) {
4644 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4645 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4646 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4647 }
Jim Millerd6b57052010-06-07 17:52:42 -07004648 }
Jim Miller284b62e2010-06-08 14:27:42 -07004649 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004650 }
4651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004652 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004653 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004654 != PackageManager.PERMISSION_GRANTED) {
4655 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4656 }
Jim Millerd6b57052010-06-07 17:52:42 -07004657
Jim Miller284b62e2010-06-08 14:27:42 -07004658 synchronized (mKeyguardTokenWatcher) {
4659 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 }
4662
4663 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004664 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 != PackageManager.PERMISSION_GRANTED) {
4666 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004668
Jim Miller284b62e2010-06-08 14:27:42 -07004669 synchronized (mKeyguardTokenWatcher) {
4670 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004671
Jim Miller284b62e2010-06-08 14:27:42 -07004672 if (!mKeyguardTokenWatcher.isAcquired()) {
4673 // If we are the last one to reenable the keyguard wait until
4674 // we have actually finished reenabling until returning.
4675 // It is possible that reenableKeyguard() can be called before
4676 // the previous disableKeyguard() is handled, in which case
4677 // neither mKeyguardTokenWatcher.acquired() or released() would
4678 // be called. In that case mKeyguardDisabled will be false here
4679 // and we have nothing to wait for.
4680 while (mKeyguardDisabled) {
4681 try {
4682 mKeyguardTokenWatcher.wait();
4683 } catch (InterruptedException e) {
4684 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 }
4686 }
4687 }
4688 }
4689 }
4690
4691 /**
4692 * @see android.app.KeyguardManager#exitKeyguardSecurely
4693 */
4694 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004695 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 != PackageManager.PERMISSION_GRANTED) {
4697 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4698 }
4699 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4700 public void onKeyguardExitResult(boolean success) {
4701 try {
4702 callback.onKeyguardExitResult(success);
4703 } catch (RemoteException e) {
4704 // Client has died, we don't care.
4705 }
4706 }
4707 });
4708 }
4709
4710 public boolean inKeyguardRestrictedInputMode() {
4711 return mPolicy.inKeyguardRestrictedKeyInputMode();
4712 }
Romain Guy06882f82009-06-10 13:36:04 -07004713
Dianne Hackbornffa42482009-09-23 22:20:11 -07004714 public void closeSystemDialogs(String reason) {
4715 synchronized(mWindowMap) {
4716 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004717 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004718 if (w.mSurface != null) {
4719 try {
4720 w.mClient.closeSystemDialogs(reason);
4721 } catch (RemoteException e) {
4722 }
4723 }
4724 }
4725 }
4726 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004728 static float fixScale(float scale) {
4729 if (scale < 0) scale = 0;
4730 else if (scale > 20) scale = 20;
4731 return Math.abs(scale);
4732 }
Romain Guy06882f82009-06-10 13:36:04 -07004733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004734 public void setAnimationScale(int which, float scale) {
4735 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4736 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004737 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 }
4739
4740 if (scale < 0) scale = 0;
4741 else if (scale > 20) scale = 20;
4742 scale = Math.abs(scale);
4743 switch (which) {
4744 case 0: mWindowAnimationScale = fixScale(scale); break;
4745 case 1: mTransitionAnimationScale = fixScale(scale); break;
4746 }
Romain Guy06882f82009-06-10 13:36:04 -07004747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004748 // Persist setting
4749 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4750 }
Romain Guy06882f82009-06-10 13:36:04 -07004751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004752 public void setAnimationScales(float[] scales) {
4753 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4754 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004755 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004756 }
4757
4758 if (scales != null) {
4759 if (scales.length >= 1) {
4760 mWindowAnimationScale = fixScale(scales[0]);
4761 }
4762 if (scales.length >= 2) {
4763 mTransitionAnimationScale = fixScale(scales[1]);
4764 }
4765 }
Romain Guy06882f82009-06-10 13:36:04 -07004766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 // Persist setting
4768 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4769 }
Romain Guy06882f82009-06-10 13:36:04 -07004770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004771 public float getAnimationScale(int which) {
4772 switch (which) {
4773 case 0: return mWindowAnimationScale;
4774 case 1: return mTransitionAnimationScale;
4775 }
4776 return 0;
4777 }
Romain Guy06882f82009-06-10 13:36:04 -07004778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004779 public float[] getAnimationScales() {
4780 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4781 }
Romain Guy06882f82009-06-10 13:36:04 -07004782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 public int getSwitchState(int sw) {
4784 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4785 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004786 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004787 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004788 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 }
Romain Guy06882f82009-06-10 13:36:04 -07004790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004791 public int getSwitchStateForDevice(int devid, int sw) {
4792 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4793 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004794 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004796 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 }
Romain Guy06882f82009-06-10 13:36:04 -07004798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 public int getScancodeState(int sw) {
4800 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4801 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004802 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004803 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004804 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 }
Romain Guy06882f82009-06-10 13:36:04 -07004806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 public int getScancodeStateForDevice(int devid, int sw) {
4808 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4809 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004810 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004812 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 }
Romain Guy06882f82009-06-10 13:36:04 -07004814
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004815 public int getTrackballScancodeState(int sw) {
4816 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4817 "getTrackballScancodeState()")) {
4818 throw new SecurityException("Requires READ_INPUT_STATE permission");
4819 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004820 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004821 }
4822
4823 public int getDPadScancodeState(int sw) {
4824 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4825 "getDPadScancodeState()")) {
4826 throw new SecurityException("Requires READ_INPUT_STATE permission");
4827 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004828 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004829 }
4830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 public int getKeycodeState(int sw) {
4832 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4833 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004834 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004836 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 }
Romain Guy06882f82009-06-10 13:36:04 -07004838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 public int getKeycodeStateForDevice(int devid, int sw) {
4840 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4841 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004842 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004844 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004845 }
Romain Guy06882f82009-06-10 13:36:04 -07004846
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004847 public int getTrackballKeycodeState(int sw) {
4848 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4849 "getTrackballKeycodeState()")) {
4850 throw new SecurityException("Requires READ_INPUT_STATE permission");
4851 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004852 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004853 }
4854
4855 public int getDPadKeycodeState(int sw) {
4856 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4857 "getDPadKeycodeState()")) {
4858 throw new SecurityException("Requires READ_INPUT_STATE permission");
4859 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004860 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004861 }
Jeff Browna41ca772010-08-11 14:46:32 -07004862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004864 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004865 }
Romain Guy06882f82009-06-10 13:36:04 -07004866
Jeff Browna41ca772010-08-11 14:46:32 -07004867 public InputChannel monitorInput(String inputChannelName) {
4868 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4869 "monitorInput()")) {
4870 throw new SecurityException("Requires READ_INPUT_STATE permission");
4871 }
4872 return mInputManager.monitorInput(inputChannelName);
4873 }
4874
Jeff Brown8d608662010-08-30 03:02:23 -07004875 public InputDevice getInputDevice(int deviceId) {
4876 return mInputManager.getInputDevice(deviceId);
4877 }
4878
4879 public int[] getInputDeviceIds() {
4880 return mInputManager.getInputDeviceIds();
4881 }
4882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 public void enableScreenAfterBoot() {
4884 synchronized(mWindowMap) {
4885 if (mSystemBooted) {
4886 return;
4887 }
4888 mSystemBooted = true;
4889 }
Romain Guy06882f82009-06-10 13:36:04 -07004890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004891 performEnableScreen();
4892 }
Romain Guy06882f82009-06-10 13:36:04 -07004893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004894 public void enableScreenIfNeededLocked() {
4895 if (mDisplayEnabled) {
4896 return;
4897 }
4898 if (!mSystemBooted) {
4899 return;
4900 }
4901 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4902 }
Romain Guy06882f82009-06-10 13:36:04 -07004903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004904 public void performEnableScreen() {
4905 synchronized(mWindowMap) {
4906 if (mDisplayEnabled) {
4907 return;
4908 }
4909 if (!mSystemBooted) {
4910 return;
4911 }
Romain Guy06882f82009-06-10 13:36:04 -07004912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 // Don't enable the screen until all existing windows
4914 // have been drawn.
4915 final int N = mWindows.size();
4916 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004917 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004918 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 return;
4920 }
4921 }
Romain Guy06882f82009-06-10 13:36:04 -07004922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004923 mDisplayEnabled = true;
4924 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004925 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 StringWriter sw = new StringWriter();
4927 PrintWriter pw = new PrintWriter(sw);
4928 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004929 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 }
4931 try {
4932 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4933 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004934 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 Parcel data = Parcel.obtain();
4936 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4937 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4938 data, null, 0);
4939 data.recycle();
4940 }
4941 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004942 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004943 }
4944 }
Romain Guy06882f82009-06-10 13:36:04 -07004945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004946 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004948 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004949 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4950 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004951 }
Romain Guy06882f82009-06-10 13:36:04 -07004952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953 public void setInTouchMode(boolean mode) {
4954 synchronized(mWindowMap) {
4955 mInTouchMode = mode;
4956 }
4957 }
4958
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004959 // TODO: more accounting of which pid(s) turned it on, keep count,
4960 // only allow disables from pids which have count on, etc.
4961 public void showStrictModeViolation(boolean on) {
4962 int pid = Binder.getCallingPid();
4963 synchronized(mWindowMap) {
4964 // Ignoring requests to enable the red border from clients
4965 // which aren't on screen. (e.g. Broadcast Receivers in
4966 // the background..)
4967 if (on) {
4968 boolean isVisible = false;
4969 for (WindowState ws : mWindows) {
4970 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4971 isVisible = true;
4972 break;
4973 }
4974 }
4975 if (!isVisible) {
4976 return;
4977 }
4978 }
4979
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004980 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004981 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004982 try {
4983 if (mStrictModeFlash == null) {
4984 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4985 }
4986 mStrictModeFlash.setVisibility(on);
4987 } finally {
4988 Surface.closeTransaction();
4989 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004990 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004991 }
4992 }
4993
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004994 public void setStrictModeVisualIndicatorPreference(String value) {
4995 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4996 }
4997
Dianne Hackbornd2835932010-12-13 16:28:46 -08004998 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004999 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5000 "screenshotApplications()")) {
5001 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5002 }
5003
5004 Bitmap rawss;
5005
Dianne Hackbornd2835932010-12-13 16:28:46 -08005006 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005007 final Rect frame = new Rect();
5008
5009 float scale;
5010 int sw, sh, dw, dh;
5011 int rot;
5012
5013 synchronized(mWindowMap) {
5014 long ident = Binder.clearCallingIdentity();
5015
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005016 dw = mDisplay.getWidth();
5017 dh = mDisplay.getHeight();
5018
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005019 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5020 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5021 + TYPE_LAYER_OFFSET;
5022 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5023
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005024 boolean isImeTarget = mInputMethodTarget != null
5025 && mInputMethodTarget.mAppToken != null
5026 && mInputMethodTarget.mAppToken.appToken != null
5027 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
5028
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005029 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005030 boolean including = false;
5031 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005032 WindowState ws = mWindows.get(i);
5033 if (ws.mSurface == null) {
5034 continue;
5035 }
5036 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08005037 continue;
5038 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005039 // When we will skip windows: when we are not including
5040 // ones behind a window we didn't skip, and we are actually
5041 // taking a screenshot of a specific app.
5042 if (!including && appToken != null) {
5043 // Also, we can possibly skip this window if it is not
5044 // an IME target or the application for the screenshot
5045 // is not the current IME target.
5046 if (!ws.mIsImWindow || !isImeTarget) {
5047 // And finally, this window is of no interest if it
5048 // is not associated with the screenshot app.
5049 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
5050 continue;
5051 }
5052 }
5053 }
5054
5055 // We keep on including windows until we go past a full-screen
5056 // window.
5057 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
5058
Dianne Hackbornd2835932010-12-13 16:28:46 -08005059 if (maxLayer < ws.mAnimLayer) {
5060 maxLayer = ws.mAnimLayer;
5061 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005062 final Rect wf = ws.mFrame;
5063 final Rect cr = ws.mContentInsets;
5064 int left = wf.left + cr.left;
5065 int top = wf.top + cr.top;
5066 int right = wf.right - cr.right;
5067 int bottom = wf.bottom - cr.bottom;
5068 frame.union(left, top, right, bottom);
5069 }
5070 Binder.restoreCallingIdentity(ident);
5071
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005072 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005073 return null;
5074 }
5075
5076 // The screenshot API does not apply the current screen rotation.
5077 rot = mDisplay.getRotation();
5078 int fw = frame.width();
5079 int fh = frame.height();
5080
5081 // First try reducing to fit in x dimension.
5082 scale = maxWidth/(float)fw;
5083 sw = maxWidth;
5084 sh = (int)(fh*scale);
5085 if (sh > maxHeight) {
5086 // y dimension became too long; constrain by that.
5087 scale = maxHeight/(float)fh;
5088 sw = (int)(fw*scale);
5089 sh = maxHeight;
5090 }
5091
5092 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005093 dw = (int)(dw*scale);
5094 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005095 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5096 int tmp = dw;
5097 dw = dh;
5098 dh = tmp;
5099 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5100 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005101 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005102 }
5103
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005104 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005105 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5106 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005107 return null;
5108 }
5109
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005110 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5111 Matrix matrix = new Matrix();
5112 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5113 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5114 Canvas canvas = new Canvas(bm);
5115 canvas.drawBitmap(rawss, matrix, null);
5116
5117 rawss.recycle();
5118 return bm;
5119 }
5120
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005121 public void freezeRotation() {
5122 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5123 "setRotation()")) {
5124 throw new SecurityException("Requires SET_ORIENTATION permission");
5125 }
5126
5127 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5128 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5129 }
5130
5131 public void thawRotation() {
5132 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5133 "setRotation()")) {
5134 throw new SecurityException("Requires SET_ORIENTATION permission");
5135 }
5136
5137 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5138 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5139 }
5140
Romain Guy06882f82009-06-10 13:36:04 -07005141 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005142 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005143 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005144 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005145 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005146 }
5147
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005148 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005149 }
Romain Guy06882f82009-06-10 13:36:04 -07005150
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005151 public void setRotationUnchecked(int rotation,
5152 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005153 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005154 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005156 long origId = Binder.clearCallingIdentity();
5157 boolean changed;
5158 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005159 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005160 }
Romain Guy06882f82009-06-10 13:36:04 -07005161
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005162 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005163 sendNewConfiguration();
5164 }
Romain Guy06882f82009-06-10 13:36:04 -07005165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005166 Binder.restoreCallingIdentity(origId);
5167 }
Romain Guy06882f82009-06-10 13:36:04 -07005168
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005169 /**
5170 * Apply a new rotation to the screen, respecting the requests of
5171 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5172 * re-evaluate the desired rotation.
5173 *
5174 * Returns null if the rotation has been changed. In this case YOU
5175 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5176 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005177 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005178 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005179 // Potential rotation during a drag. Don't do the rotation now, but make
5180 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005181 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5182 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5183 mDeferredRotation = rotation;
5184 mDeferredRotationAnimFlags = animFlags;
5185 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005186 return false;
5187 }
5188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189 boolean changed;
5190 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005191 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5192 rotation = mDeferredRotation;
5193 mRequestedRotation = rotation;
5194 mLastRotationFlags = mDeferredRotationAnimFlags;
5195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 rotation = mRequestedRotation;
5197 } else {
5198 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005199 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005200 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005201 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005202 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005203 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005204 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005205 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005206 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005208 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005209 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 "Rotation changed to " + rotation
5211 + " from " + mRotation
5212 + " (forceApp=" + mForcedAppOrientation
5213 + ", req=" + mRequestedRotation + ")");
5214 mRotation = rotation;
5215 mWindowsFreezingScreen = true;
5216 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5217 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5218 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005219 mWaitingForConfig = true;
5220 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005221 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005222 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005223 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005225 if (CUSTOM_SCREEN_ROTATION) {
5226 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005227 if (!inTransaction) {
5228 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5229 ">>> OPEN TRANSACTION setRotationUnchecked");
5230 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005231 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005232 try {
5233 if (mScreenRotationAnimation != null) {
5234 mScreenRotationAnimation.setRotation(rotation);
5235 }
5236 } finally {
5237 if (!inTransaction) {
5238 Surface.closeTransaction();
5239 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5240 "<<< CLOSE TRANSACTION setRotationUnchecked");
5241 }
5242 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005243 Surface.setOrientation(0, rotation, animFlags);
5244 Surface.unfreezeDisplay(0);
5245 } else {
5246 Surface.setOrientation(0, rotation, animFlags);
5247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005248 }
5249 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005250 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 if (w.mSurface != null) {
5252 w.mOrientationChanging = true;
5253 }
5254 }
5255 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5256 try {
5257 mRotationWatchers.get(i).onRotationChanged(rotation);
5258 } catch (RemoteException e) {
5259 }
5260 }
5261 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005263 return changed;
5264 }
Romain Guy06882f82009-06-10 13:36:04 -07005265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005266 public int getRotation() {
5267 return mRotation;
5268 }
5269
5270 public int watchRotation(IRotationWatcher watcher) {
5271 final IBinder watcherBinder = watcher.asBinder();
5272 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5273 public void binderDied() {
5274 synchronized (mWindowMap) {
5275 for (int i=0; i<mRotationWatchers.size(); i++) {
5276 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005277 IRotationWatcher removed = mRotationWatchers.remove(i);
5278 if (removed != null) {
5279 removed.asBinder().unlinkToDeath(this, 0);
5280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005281 i--;
5282 }
5283 }
5284 }
5285 }
5286 };
Romain Guy06882f82009-06-10 13:36:04 -07005287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005288 synchronized (mWindowMap) {
5289 try {
5290 watcher.asBinder().linkToDeath(dr, 0);
5291 mRotationWatchers.add(watcher);
5292 } catch (RemoteException e) {
5293 // Client died, no cleanup needed.
5294 }
Romain Guy06882f82009-06-10 13:36:04 -07005295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005296 return mRotation;
5297 }
5298 }
5299
5300 /**
5301 * Starts the view server on the specified port.
5302 *
5303 * @param port The port to listener to.
5304 *
5305 * @return True if the server was successfully started, false otherwise.
5306 *
5307 * @see com.android.server.ViewServer
5308 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5309 */
5310 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005311 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005312 return false;
5313 }
5314
5315 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5316 return false;
5317 }
5318
5319 if (port < 1024) {
5320 return false;
5321 }
5322
5323 if (mViewServer != null) {
5324 if (!mViewServer.isRunning()) {
5325 try {
5326 return mViewServer.start();
5327 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005328 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005329 }
5330 }
5331 return false;
5332 }
5333
5334 try {
5335 mViewServer = new ViewServer(this, port);
5336 return mViewServer.start();
5337 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005338 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005339 }
5340 return false;
5341 }
5342
Romain Guy06882f82009-06-10 13:36:04 -07005343 private boolean isSystemSecure() {
5344 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5345 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5346 }
5347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005348 /**
5349 * Stops the view server if it exists.
5350 *
5351 * @return True if the server stopped, false if it wasn't started or
5352 * couldn't be stopped.
5353 *
5354 * @see com.android.server.ViewServer
5355 */
5356 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005357 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005358 return false;
5359 }
5360
5361 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5362 return false;
5363 }
5364
5365 if (mViewServer != null) {
5366 return mViewServer.stop();
5367 }
5368 return false;
5369 }
5370
5371 /**
5372 * Indicates whether the view server is running.
5373 *
5374 * @return True if the server is running, false otherwise.
5375 *
5376 * @see com.android.server.ViewServer
5377 */
5378 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005379 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 return false;
5381 }
5382
5383 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5384 return false;
5385 }
5386
5387 return mViewServer != null && mViewServer.isRunning();
5388 }
5389
5390 /**
5391 * Lists all availble windows in the system. The listing is written in the
5392 * specified Socket's output stream with the following syntax:
5393 * windowHashCodeInHexadecimal windowName
5394 * Each line of the ouput represents a different window.
5395 *
5396 * @param client The remote client to send the listing to.
5397 * @return False if an error occured, true otherwise.
5398 */
5399 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005400 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005401 return false;
5402 }
5403
5404 boolean result = true;
5405
Jeff Browne33348b2010-07-15 23:54:05 -07005406 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005407 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005408 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005409 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005410 }
5411
5412 BufferedWriter out = null;
5413
5414 // Any uncaught exception will crash the system process
5415 try {
5416 OutputStream clientStream = client.getOutputStream();
5417 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5418
5419 final int count = windows.length;
5420 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005421 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005422 out.write(Integer.toHexString(System.identityHashCode(w)));
5423 out.write(' ');
5424 out.append(w.mAttrs.getTitle());
5425 out.write('\n');
5426 }
5427
5428 out.write("DONE.\n");
5429 out.flush();
5430 } catch (Exception e) {
5431 result = false;
5432 } finally {
5433 if (out != null) {
5434 try {
5435 out.close();
5436 } catch (IOException e) {
5437 result = false;
5438 }
5439 }
5440 }
5441
5442 return result;
5443 }
5444
5445 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005446 * Returns the focused window in the following format:
5447 * windowHashCodeInHexadecimal windowName
5448 *
5449 * @param client The remote client to send the listing to.
5450 * @return False if an error occurred, true otherwise.
5451 */
5452 boolean viewServerGetFocusedWindow(Socket client) {
5453 if (isSystemSecure()) {
5454 return false;
5455 }
5456
5457 boolean result = true;
5458
5459 WindowState focusedWindow = getFocusedWindow();
5460
5461 BufferedWriter out = null;
5462
5463 // Any uncaught exception will crash the system process
5464 try {
5465 OutputStream clientStream = client.getOutputStream();
5466 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5467
5468 if(focusedWindow != null) {
5469 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5470 out.write(' ');
5471 out.append(focusedWindow.mAttrs.getTitle());
5472 }
5473 out.write('\n');
5474 out.flush();
5475 } catch (Exception e) {
5476 result = false;
5477 } finally {
5478 if (out != null) {
5479 try {
5480 out.close();
5481 } catch (IOException e) {
5482 result = false;
5483 }
5484 }
5485 }
5486
5487 return result;
5488 }
5489
5490 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005491 * Sends a command to a target window. The result of the command, if any, will be
5492 * written in the output stream of the specified socket.
5493 *
5494 * The parameters must follow this syntax:
5495 * windowHashcode extra
5496 *
5497 * Where XX is the length in characeters of the windowTitle.
5498 *
5499 * The first parameter is the target window. The window with the specified hashcode
5500 * will be the target. If no target can be found, nothing happens. The extra parameters
5501 * will be delivered to the target window and as parameters to the command itself.
5502 *
5503 * @param client The remote client to sent the result, if any, to.
5504 * @param command The command to execute.
5505 * @param parameters The command parameters.
5506 *
5507 * @return True if the command was successfully delivered, false otherwise. This does
5508 * not indicate whether the command itself was successful.
5509 */
5510 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005511 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005512 return false;
5513 }
5514
5515 boolean success = true;
5516 Parcel data = null;
5517 Parcel reply = null;
5518
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005519 BufferedWriter out = null;
5520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005521 // Any uncaught exception will crash the system process
5522 try {
5523 // Find the hashcode of the window
5524 int index = parameters.indexOf(' ');
5525 if (index == -1) {
5526 index = parameters.length();
5527 }
5528 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005529 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005530
5531 // Extract the command's parameter after the window description
5532 if (index < parameters.length()) {
5533 parameters = parameters.substring(index + 1);
5534 } else {
5535 parameters = "";
5536 }
5537
5538 final WindowManagerService.WindowState window = findWindow(hashCode);
5539 if (window == null) {
5540 return false;
5541 }
5542
5543 data = Parcel.obtain();
5544 data.writeInterfaceToken("android.view.IWindow");
5545 data.writeString(command);
5546 data.writeString(parameters);
5547 data.writeInt(1);
5548 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5549
5550 reply = Parcel.obtain();
5551
5552 final IBinder binder = window.mClient.asBinder();
5553 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5554 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5555
5556 reply.readException();
5557
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005558 if (!client.isOutputShutdown()) {
5559 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5560 out.write("DONE\n");
5561 out.flush();
5562 }
5563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005564 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005565 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005566 success = false;
5567 } finally {
5568 if (data != null) {
5569 data.recycle();
5570 }
5571 if (reply != null) {
5572 reply.recycle();
5573 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005574 if (out != null) {
5575 try {
5576 out.close();
5577 } catch (IOException e) {
5578
5579 }
5580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005581 }
5582
5583 return success;
5584 }
5585
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005586 public void addWindowChangeListener(WindowChangeListener listener) {
5587 synchronized(mWindowMap) {
5588 mWindowChangeListeners.add(listener);
5589 }
5590 }
5591
5592 public void removeWindowChangeListener(WindowChangeListener listener) {
5593 synchronized(mWindowMap) {
5594 mWindowChangeListeners.remove(listener);
5595 }
5596 }
5597
5598 private void notifyWindowsChanged() {
5599 WindowChangeListener[] windowChangeListeners;
5600 synchronized(mWindowMap) {
5601 if(mWindowChangeListeners.isEmpty()) {
5602 return;
5603 }
5604 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5605 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5606 }
5607 int N = windowChangeListeners.length;
5608 for(int i = 0; i < N; i++) {
5609 windowChangeListeners[i].windowsChanged();
5610 }
5611 }
5612
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005613 private void notifyFocusChanged() {
5614 WindowChangeListener[] windowChangeListeners;
5615 synchronized(mWindowMap) {
5616 if(mWindowChangeListeners.isEmpty()) {
5617 return;
5618 }
5619 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5620 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5621 }
5622 int N = windowChangeListeners.length;
5623 for(int i = 0; i < N; i++) {
5624 windowChangeListeners[i].focusChanged();
5625 }
5626 }
5627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005628 private WindowState findWindow(int hashCode) {
5629 if (hashCode == -1) {
5630 return getFocusedWindow();
5631 }
5632
5633 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005634 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005635 final int count = windows.size();
5636
5637 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005638 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005639 if (System.identityHashCode(w) == hashCode) {
5640 return w;
5641 }
5642 }
5643 }
5644
5645 return null;
5646 }
5647
5648 /*
5649 * Instruct the Activity Manager to fetch the current configuration and broadcast
5650 * that to config-changed listeners if appropriate.
5651 */
5652 void sendNewConfiguration() {
5653 try {
5654 mActivityManager.updateConfiguration(null);
5655 } catch (RemoteException e) {
5656 }
5657 }
Romain Guy06882f82009-06-10 13:36:04 -07005658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005659 public Configuration computeNewConfiguration() {
5660 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005661 Configuration config = computeNewConfigurationLocked();
5662 if (config == null && mWaitingForConfig) {
5663 // Nothing changed but we are waiting for something... stop that!
5664 mWaitingForConfig = false;
5665 performLayoutAndPlaceSurfacesLocked();
5666 }
5667 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005668 }
5669 }
Romain Guy06882f82009-06-10 13:36:04 -07005670
Dianne Hackbornc485a602009-03-24 22:39:49 -07005671 Configuration computeNewConfigurationLocked() {
5672 Configuration config = new Configuration();
5673 if (!computeNewConfigurationLocked(config)) {
5674 return null;
5675 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005676 return config;
5677 }
Romain Guy06882f82009-06-10 13:36:04 -07005678
Dianne Hackbornc485a602009-03-24 22:39:49 -07005679 boolean computeNewConfigurationLocked(Configuration config) {
5680 if (mDisplay == null) {
5681 return false;
5682 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005683
5684 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005685
5686 // Use the effective "visual" dimensions based on current rotation
5687 final boolean rotated = (mRotation == Surface.ROTATION_90
5688 || mRotation == Surface.ROTATION_270);
5689 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5690 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5691
Dianne Hackbornc485a602009-03-24 22:39:49 -07005692 int orientation = Configuration.ORIENTATION_SQUARE;
5693 if (dw < dh) {
5694 orientation = Configuration.ORIENTATION_PORTRAIT;
5695 } else if (dw > dh) {
5696 orientation = Configuration.ORIENTATION_LANDSCAPE;
5697 }
5698 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005699
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005700 DisplayMetrics dm = new DisplayMetrics();
5701 mDisplay.getMetrics(dm);
5702 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5703
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005704 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005705 // Note we only do this once because at this point we don't
5706 // expect the screen to change in this way at runtime, and want
5707 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005708 int longSize = dw;
5709 int shortSize = dh;
5710 if (longSize < shortSize) {
5711 int tmp = longSize;
5712 longSize = shortSize;
5713 shortSize = tmp;
5714 }
5715 longSize = (int)(longSize/dm.density);
5716 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005717
Dianne Hackborn723738c2009-06-25 19:48:04 -07005718 // These semi-magic numbers define our compatibility modes for
5719 // applications with different screens. Don't change unless you
5720 // make sure to test lots and lots of apps!
5721 if (longSize < 470) {
5722 // This is shorter than an HVGA normal density screen (which
5723 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005724 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5725 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005726 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005727 // What size is this screen screen?
5728 if (longSize >= 800 && shortSize >= 600) {
5729 // SVGA or larger screens at medium density are the point
5730 // at which we consider it to be an extra large screen.
5731 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005732 } else if (longSize >= 530 && shortSize >= 400) {
5733 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005734 // at which we consider it to be a large screen.
5735 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5736 } else {
5737 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005738
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005739 // If this screen is wider than normal HVGA, or taller
5740 // than FWVGA, then for old apps we want to run in size
5741 // compatibility mode.
5742 if (shortSize > 321 || longSize > 570) {
5743 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5744 }
5745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005746
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005747 // Is this a long screen?
5748 if (((longSize*3)/5) >= (shortSize-1)) {
5749 // Anything wider than WVGA (5:3) is considering to be long.
5750 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5751 } else {
5752 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5753 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005754 }
5755 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005756 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005757
Dianne Hackbornc485a602009-03-24 22:39:49 -07005758 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5759 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5760 mPolicy.adjustConfigurationLw(config);
5761 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005762 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005763
5764 // -------------------------------------------------------------
5765 // Drag and drop
5766 // -------------------------------------------------------------
5767
5768 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005769 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005770 if (DEBUG_DRAG) {
5771 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005772 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005773 + " asbinder=" + window.asBinder());
5774 }
5775
5776 final int callerPid = Binder.getCallingPid();
5777 final long origId = Binder.clearCallingIdentity();
5778 IBinder token = null;
5779
5780 try {
5781 synchronized (mWindowMap) {
5782 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005783 if (mDragState == null) {
5784 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5785 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5786 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005787 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005788 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005789 // TODO: preserve flags param in DragState
5790 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005791 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005792 token = mDragState.mToken = new Binder();
5793
5794 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005795 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5796 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005797 mH.sendMessageDelayed(msg, 5000);
5798 } else {
5799 Slog.w(TAG, "Drag already in progress");
5800 }
5801 } catch (Surface.OutOfResourcesException e) {
5802 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5803 if (mDragState != null) {
5804 mDragState.reset();
5805 mDragState = null;
5806 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005807 }
5808 }
5809 } finally {
5810 Binder.restoreCallingIdentity(origId);
5811 }
5812
5813 return token;
5814 }
5815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005816 // -------------------------------------------------------------
5817 // Input Events and Focus Management
5818 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005819
Jeff Brown349703e2010-06-22 01:27:15 -07005820 InputMonitor mInputMonitor = new InputMonitor();
5821
5822 /* Tracks the progress of input dispatch and ensures that input dispatch state
5823 * is kept in sync with changes in window focus, visibility, registration, and
5824 * other relevant Window Manager state transitions. */
5825 final class InputMonitor {
5826 // Current window with input focus for keys and other non-touch events. May be null.
5827 private WindowState mInputFocus;
5828
5829 // When true, prevents input dispatch from proceeding until set to false again.
5830 private boolean mInputDispatchFrozen;
5831
5832 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5833 private boolean mInputDispatchEnabled = true;
5834
Jeff Brown3a22cd92011-01-21 13:59:04 -08005835 // When true, need to call updateInputWindowsLw().
5836 private boolean mUpdateInputWindowsNeeded = true;
5837
Jeff Brown349703e2010-06-22 01:27:15 -07005838 // Temporary list of windows information to provide to the input dispatcher.
5839 private InputWindowList mTempInputWindows = new InputWindowList();
5840
5841 // Temporary input application object to provide to the input dispatcher.
5842 private InputApplication mTempInputApplication = new InputApplication();
5843
Jeff Brownb09abc12011-01-13 21:08:27 -08005844 // Set to true when the first input device configuration change notification
5845 // is received to indicate that the input devices are ready.
5846 private final Object mInputDevicesReadyMonitor = new Object();
5847 private boolean mInputDevicesReady;
5848
Jeff Brown349703e2010-06-22 01:27:15 -07005849 /* Notifies the window manager about a broken input channel.
5850 *
5851 * Called by the InputManager.
5852 */
Jeff Brown928e0542011-01-10 11:17:36 -08005853 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5854 if (inputWindowHandle == null) {
5855 return;
5856 }
5857
Jeff Brown349703e2010-06-22 01:27:15 -07005858 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005859 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005860 Slog.i(TAG, "WINDOW DIED " + windowState);
5861 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005862 }
5863 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005864
Jeff Brown519e0242010-09-15 15:18:56 -07005865 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005866 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005867 *
5868 * Called by the InputManager.
5869 */
Jeff Brown928e0542011-01-10 11:17:36 -08005870 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5871 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005872 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005873 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005874 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005875 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005876 if (windowState != null) {
5877 Slog.i(TAG, "Input event dispatching timed out sending to "
5878 + windowState.mAttrs.getTitle());
5879 appWindowToken = windowState.mAppToken;
5880 }
Jeff Brown349703e2010-06-22 01:27:15 -07005881 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005882 }
5883
Jeff Brown928e0542011-01-10 11:17:36 -08005884 if (appWindowToken == null && inputApplicationHandle != null) {
5885 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005886 Slog.i(TAG, "Input event dispatching timed out sending to application "
5887 + appWindowToken.stringName);
5888 }
Jeff Brown349703e2010-06-22 01:27:15 -07005889
Jeff Brown519e0242010-09-15 15:18:56 -07005890 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005891 try {
5892 // Notify the activity manager about the timeout and let it decide whether
5893 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005894 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005895 if (! abort) {
5896 // The activity manager declined to abort dispatching.
5897 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005898 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005899 }
Jeff Brown349703e2010-06-22 01:27:15 -07005900 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005901 }
5902 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005903 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005904 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005905
Chris Tatea32dcf72010-10-14 12:13:50 -07005906 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005907 final InputWindow inputWindow = windowList.add();
5908 inputWindow.inputChannel = mDragState.mServerChannel;
5909 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08005910 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07005911 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5912 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5913 inputWindow.visible = true;
5914 inputWindow.canReceiveKeys = false;
5915 inputWindow.hasFocus = true;
5916 inputWindow.hasWallpaper = false;
5917 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005918 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005919 inputWindow.ownerPid = Process.myPid();
5920 inputWindow.ownerUid = Process.myUid();
5921
5922 // The drag window covers the entire display
5923 inputWindow.frameLeft = 0;
5924 inputWindow.frameTop = 0;
5925 inputWindow.frameRight = mDisplay.getWidth();
5926 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005927
Jeff Brownfbf09772011-01-16 14:06:57 -08005928 // The drag window cannot receive new touches.
5929 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07005930 }
5931
Jeff Brown3a22cd92011-01-21 13:59:04 -08005932 public void setUpdateInputWindowsNeededLw() {
5933 mUpdateInputWindowsNeeded = true;
5934 }
5935
Jeff Brown349703e2010-06-22 01:27:15 -07005936 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08005937 public void updateInputWindowsLw(boolean force) {
5938 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08005939 return;
5940 }
5941 mUpdateInputWindowsNeeded = false;
5942
Jeff Brown349703e2010-06-22 01:27:15 -07005943 // Populate the input window list with information about all of the windows that
5944 // could potentially receive input.
5945 // As an optimization, we could try to prune the list of windows but this turns
5946 // out to be difficult because only the native code knows for sure which window
5947 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005948 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005949
5950 // If there's a drag in flight, provide a pseudowindow to catch drag input
5951 final boolean inDrag = (mDragState != null);
5952 if (inDrag) {
5953 if (DEBUG_DRAG) {
5954 Log.d(TAG, "Inserting drag window");
5955 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005956 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005957 }
5958
Jeff Brown7fbdc842010-06-17 20:52:56 -07005959 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005960 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005961 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005962 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005963 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005964 continue;
5965 }
5966
Jeff Brown349703e2010-06-22 01:27:15 -07005967 final int flags = child.mAttrs.flags;
5968 final int type = child.mAttrs.type;
5969
5970 final boolean hasFocus = (child == mInputFocus);
5971 final boolean isVisible = child.isVisibleLw();
5972 final boolean hasWallpaper = (child == mWallpaperTarget)
5973 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005974
5975 // If there's a drag in progress and 'child' is a potential drop target,
5976 // make sure it's been told about the drag
5977 if (inDrag && isVisible) {
5978 mDragState.sendDragStartedIfNeededLw(child);
5979 }
5980
Jeff Brown349703e2010-06-22 01:27:15 -07005981 // Add a window to our list of input windows.
5982 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005983 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005984 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005985 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005986 inputWindow.layoutParamsFlags = flags;
5987 inputWindow.layoutParamsType = type;
5988 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5989 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005990 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005991 inputWindow.hasFocus = hasFocus;
5992 inputWindow.hasWallpaper = hasWallpaper;
5993 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005994 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005995 inputWindow.ownerPid = child.mSession.mPid;
5996 inputWindow.ownerUid = child.mSession.mUid;
5997
5998 final Rect frame = child.mFrame;
5999 inputWindow.frameLeft = frame.left;
6000 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006001 inputWindow.frameRight = frame.right;
6002 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006003
6004 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006005 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006006
Jeff Brown349703e2010-06-22 01:27:15 -07006007 // Send windows to native code.
6008 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006009
Jeff Brown349703e2010-06-22 01:27:15 -07006010 // Clear the list in preparation for the next round.
6011 // Also avoids keeping InputChannel objects referenced unnecessarily.
6012 mTempInputWindows.clear();
6013 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006014
6015 /* Notifies that the input device configuration has changed. */
6016 public void notifyConfigurationChanged() {
6017 sendNewConfiguration();
6018
6019 synchronized (mInputDevicesReadyMonitor) {
6020 if (!mInputDevicesReady) {
6021 mInputDevicesReady = true;
6022 mInputDevicesReadyMonitor.notifyAll();
6023 }
6024 }
6025 }
6026
6027 /* Waits until the built-in input devices have been configured. */
6028 public boolean waitForInputDevicesReady(long timeoutMillis) {
6029 synchronized (mInputDevicesReadyMonitor) {
6030 if (!mInputDevicesReady) {
6031 try {
6032 mInputDevicesReadyMonitor.wait(timeoutMillis);
6033 } catch (InterruptedException ex) {
6034 }
6035 }
6036 return mInputDevicesReady;
6037 }
6038 }
6039
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006040 /* Notifies that the lid switch changed state. */
6041 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6042 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6043 }
6044
Jeff Brown349703e2010-06-22 01:27:15 -07006045 /* Provides an opportunity for the window manager policy to intercept early key
6046 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006047 public int interceptKeyBeforeQueueing(
6048 KeyEvent event, int policyFlags, boolean isScreenOn) {
6049 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006050 }
6051
6052 /* Provides an opportunity for the window manager policy to process a key before
6053 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006054 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006055 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006056 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006057 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006058 }
6059
Jeff Brown3915bb82010-11-05 15:02:16 -07006060 /* Provides an opportunity for the window manager policy to process a key that
6061 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006062 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006063 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006064 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006065 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006066 }
6067
Jeff Brown349703e2010-06-22 01:27:15 -07006068 /* Called when the current input focus changes.
6069 * Layer assignment is assumed to be complete by the time this is called.
6070 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006071 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006072 if (DEBUG_INPUT) {
6073 Slog.d(TAG, "Input focus has changed to " + newWindow);
6074 }
6075
6076 if (newWindow != mInputFocus) {
6077 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006078 // Displaying a window implicitly causes dispatching to be unpaused.
6079 // This is to protect against bugs if someone pauses dispatching but
6080 // forgets to resume.
6081 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006082 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006083
Jeff Brown349703e2010-06-22 01:27:15 -07006084 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006085 setUpdateInputWindowsNeededLw();
6086
6087 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006088 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006089 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006090 }
6091 }
6092
Jeff Brown349703e2010-06-22 01:27:15 -07006093 public void setFocusedAppLw(AppWindowToken newApp) {
6094 // Focused app has changed.
6095 if (newApp == null) {
6096 mInputManager.setFocusedApplication(null);
6097 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006098 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006099 mTempInputApplication.name = newApp.toString();
6100 mTempInputApplication.dispatchingTimeoutNanos =
6101 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006102
Jeff Brown349703e2010-06-22 01:27:15 -07006103 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006104
6105 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006106 }
6107 }
6108
Jeff Brown349703e2010-06-22 01:27:15 -07006109 public void pauseDispatchingLw(WindowToken window) {
6110 if (! window.paused) {
6111 if (DEBUG_INPUT) {
6112 Slog.v(TAG, "Pausing WindowToken " + window);
6113 }
6114
6115 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006116 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006117 }
6118 }
6119
6120 public void resumeDispatchingLw(WindowToken window) {
6121 if (window.paused) {
6122 if (DEBUG_INPUT) {
6123 Slog.v(TAG, "Resuming WindowToken " + window);
6124 }
6125
6126 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006127 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006128 }
6129 }
6130
6131 public void freezeInputDispatchingLw() {
6132 if (! mInputDispatchFrozen) {
6133 if (DEBUG_INPUT) {
6134 Slog.v(TAG, "Freezing input dispatching");
6135 }
6136
6137 mInputDispatchFrozen = true;
6138 updateInputDispatchModeLw();
6139 }
6140 }
6141
6142 public void thawInputDispatchingLw() {
6143 if (mInputDispatchFrozen) {
6144 if (DEBUG_INPUT) {
6145 Slog.v(TAG, "Thawing input dispatching");
6146 }
6147
6148 mInputDispatchFrozen = false;
6149 updateInputDispatchModeLw();
6150 }
6151 }
6152
6153 public void setEventDispatchingLw(boolean enabled) {
6154 if (mInputDispatchEnabled != enabled) {
6155 if (DEBUG_INPUT) {
6156 Slog.v(TAG, "Setting event dispatching to " + enabled);
6157 }
6158
6159 mInputDispatchEnabled = enabled;
6160 updateInputDispatchModeLw();
6161 }
6162 }
6163
6164 private void updateInputDispatchModeLw() {
6165 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6166 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006169 public void pauseKeyDispatching(IBinder _token) {
6170 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6171 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006172 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006173 }
6174
6175 synchronized (mWindowMap) {
6176 WindowToken token = mTokenMap.get(_token);
6177 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006178 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006179 }
6180 }
6181 }
6182
6183 public void resumeKeyDispatching(IBinder _token) {
6184 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6185 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006186 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 }
6188
6189 synchronized (mWindowMap) {
6190 WindowToken token = mTokenMap.get(_token);
6191 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006192 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193 }
6194 }
6195 }
6196
6197 public void setEventDispatching(boolean enabled) {
6198 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6199 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006200 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006201 }
6202
6203 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006204 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006205 }
6206 }
Romain Guy06882f82009-06-10 13:36:04 -07006207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006208 /**
6209 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006210 * Even when sync is false, this method may block while waiting for current
6211 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006212 *
6213 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006214 * {@link SystemClock#uptimeMillis()} as the timebase.)
6215 * @param sync If true, wait for the event to be completed before returning to the caller.
6216 * @return Returns true if event was dispatched, false if it was dropped for any reason
6217 */
6218 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6219 long downTime = ev.getDownTime();
6220 long eventTime = ev.getEventTime();
6221
6222 int action = ev.getAction();
6223 int code = ev.getKeyCode();
6224 int repeatCount = ev.getRepeatCount();
6225 int metaState = ev.getMetaState();
6226 int deviceId = ev.getDeviceId();
6227 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006228 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006229 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006230
6231 if (source == InputDevice.SOURCE_UNKNOWN) {
6232 source = InputDevice.SOURCE_KEYBOARD;
6233 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006234
6235 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6236 if (downTime == 0) downTime = eventTime;
6237
6238 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006239 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006240
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 Brownbbda99d2010-07-28 15:48:59 -07006245 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6246 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6247 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6248 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006249
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006250 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006251 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006252 }
6253
6254 /**
6255 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006256 * Even when sync is false, this method may block while waiting for current
6257 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006258 *
6259 * @param ev A motion event describing the pointer (touch) action. (As noted in
6260 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006261 * {@link SystemClock#uptimeMillis()} as the timebase.)
6262 * @param sync If true, wait for the event to be completed before returning to the caller.
6263 * @return Returns true if event was dispatched, false if it was dropped for any reason
6264 */
6265 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006266 final int pid = Binder.getCallingPid();
6267 final int uid = Binder.getCallingUid();
6268 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006269
Jeff Brownc5ed5912010-07-14 18:48:53 -07006270 MotionEvent newEvent = MotionEvent.obtain(ev);
6271 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6272 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6273 }
6274
Jeff Brownbbda99d2010-07-28 15:48:59 -07006275 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6276 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6277 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6278 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006279
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006280 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006281 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006282 }
Romain Guy06882f82009-06-10 13:36:04 -07006283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006284 /**
6285 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006286 * Even when sync is false, this method may block while waiting for current
6287 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006288 *
6289 * @param ev A motion event describing the trackball action. (As noted in
6290 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006291 * {@link SystemClock#uptimeMillis()} as the timebase.)
6292 * @param sync If true, wait for the event to be completed before returning to the caller.
6293 * @return Returns true if event was dispatched, false if it was dropped for any reason
6294 */
6295 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006296 final int pid = Binder.getCallingPid();
6297 final int uid = Binder.getCallingUid();
6298 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006299
Jeff Brownc5ed5912010-07-14 18:48:53 -07006300 MotionEvent newEvent = MotionEvent.obtain(ev);
6301 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6302 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6303 }
6304
Jeff Brownbbda99d2010-07-28 15:48:59 -07006305 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6306 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6307 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6308 INJECTION_TIMEOUT_MILLIS);
6309
6310 Binder.restoreCallingIdentity(ident);
6311 return reportInjectionResult(result);
6312 }
6313
6314 /**
6315 * Inject an input event into the UI without waiting for dispatch to commence.
6316 * This variant is useful for fire-and-forget input event injection. It does not
6317 * block any longer than it takes to enqueue the input event.
6318 *
6319 * @param ev An input event. (Be sure to set the input source correctly.)
6320 * @return Returns true if event was dispatched, false if it was dropped for any reason
6321 */
6322 public boolean injectInputEventNoWait(InputEvent ev) {
6323 final int pid = Binder.getCallingPid();
6324 final int uid = Binder.getCallingUid();
6325 final long ident = Binder.clearCallingIdentity();
6326
6327 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6328 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6329 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006330
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006331 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006332 return reportInjectionResult(result);
6333 }
6334
6335 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006336 switch (result) {
6337 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6338 Slog.w(TAG, "Input event injection permission denied.");
6339 throw new SecurityException(
6340 "Injecting to another application requires INJECT_EVENTS permission");
6341 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006342 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006343 return true;
6344 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6345 Slog.w(TAG, "Input event injection timed out.");
6346 return false;
6347 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6348 default:
6349 Slog.w(TAG, "Input event injection failed.");
6350 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 }
Romain Guy06882f82009-06-10 13:36:04 -07006353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 private WindowState getFocusedWindow() {
6355 synchronized (mWindowMap) {
6356 return getFocusedWindowLocked();
6357 }
6358 }
6359
6360 private WindowState getFocusedWindowLocked() {
6361 return mCurrentFocus;
6362 }
Romain Guy06882f82009-06-10 13:36:04 -07006363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006364 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006365 if (!mInputMonitor.waitForInputDevicesReady(
6366 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6367 Slog.w(TAG, "Devices still not ready after waiting "
6368 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6369 + " milliseconds before attempting to detect safe mode.");
6370 }
6371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 mSafeMode = mPolicy.detectSafeMode();
6373 return mSafeMode;
6374 }
Romain Guy06882f82009-06-10 13:36:04 -07006375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006377 synchronized(mWindowMap) {
6378 if (mDisplay != null) {
6379 throw new IllegalStateException("Display already initialized");
6380 }
6381 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6382 mDisplay = wm.getDefaultDisplay();
6383 mInitialDisplayWidth = mDisplay.getWidth();
6384 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006385 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6386 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006387 }
6388
6389 try {
6390 mActivityManager.updateConfiguration(null);
6391 } catch (RemoteException e) {
6392 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006393
6394 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006395 }
6396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 // -------------------------------------------------------------
6398 // Client Session State
6399 // -------------------------------------------------------------
6400
6401 private final class Session extends IWindowSession.Stub
6402 implements IBinder.DeathRecipient {
6403 final IInputMethodClient mClient;
6404 final IInputContext mInputContext;
6405 final int mUid;
6406 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006407 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 SurfaceSession mSurfaceSession;
6409 int mNumWindow = 0;
6410 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006412 public Session(IInputMethodClient client, IInputContext inputContext) {
6413 mClient = client;
6414 mInputContext = inputContext;
6415 mUid = Binder.getCallingUid();
6416 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006417 StringBuilder sb = new StringBuilder();
6418 sb.append("Session{");
6419 sb.append(Integer.toHexString(System.identityHashCode(this)));
6420 sb.append(" uid ");
6421 sb.append(mUid);
6422 sb.append("}");
6423 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006425 synchronized (mWindowMap) {
6426 if (mInputMethodManager == null && mHaveInputMethods) {
6427 IBinder b = ServiceManager.getService(
6428 Context.INPUT_METHOD_SERVICE);
6429 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6430 }
6431 }
6432 long ident = Binder.clearCallingIdentity();
6433 try {
6434 // Note: it is safe to call in to the input method manager
6435 // here because we are not holding our lock.
6436 if (mInputMethodManager != null) {
6437 mInputMethodManager.addClient(client, inputContext,
6438 mUid, mPid);
6439 } else {
6440 client.setUsingInputMethod(false);
6441 }
6442 client.asBinder().linkToDeath(this, 0);
6443 } catch (RemoteException e) {
6444 // The caller has died, so we can just forget about this.
6445 try {
6446 if (mInputMethodManager != null) {
6447 mInputMethodManager.removeClient(client);
6448 }
6449 } catch (RemoteException ee) {
6450 }
6451 } finally {
6452 Binder.restoreCallingIdentity(ident);
6453 }
6454 }
Romain Guy06882f82009-06-10 13:36:04 -07006455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 @Override
6457 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6458 throws RemoteException {
6459 try {
6460 return super.onTransact(code, data, reply, flags);
6461 } catch (RuntimeException e) {
6462 // Log all 'real' exceptions thrown to the caller
6463 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006464 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 }
6466 throw e;
6467 }
6468 }
6469
6470 public void binderDied() {
6471 // Note: it is safe to call in to the input method manager
6472 // here because we are not holding our lock.
6473 try {
6474 if (mInputMethodManager != null) {
6475 mInputMethodManager.removeClient(mClient);
6476 }
6477 } catch (RemoteException e) {
6478 }
6479 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006480 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 mClientDead = true;
6482 killSessionLocked();
6483 }
6484 }
6485
6486 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006487 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6488 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6489 outInputChannel);
6490 }
6491
6492 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006494 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006495 }
Romain Guy06882f82009-06-10 13:36:04 -07006496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006497 public void remove(IWindow window) {
6498 removeWindow(this, window);
6499 }
Romain Guy06882f82009-06-10 13:36:04 -07006500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006501 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6502 int requestedWidth, int requestedHeight, int viewFlags,
6503 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006504 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006505 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6506 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006507 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006508 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006509 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6510 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 }
Romain Guy06882f82009-06-10 13:36:04 -07006512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 public void setTransparentRegion(IWindow window, Region region) {
6514 setTransparentRegionWindow(this, window, region);
6515 }
Romain Guy06882f82009-06-10 13:36:04 -07006516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006517 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006518 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006520 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006521 }
Romain Guy06882f82009-06-10 13:36:04 -07006522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006523 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6524 getWindowDisplayFrame(this, window, outDisplayFrame);
6525 }
Romain Guy06882f82009-06-10 13:36:04 -07006526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006527 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006528 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006529 TAG, "IWindow finishDrawing called for " + window);
6530 finishDrawingWindow(this, window);
6531 }
6532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 public void setInTouchMode(boolean mode) {
6534 synchronized(mWindowMap) {
6535 mInTouchMode = mode;
6536 }
6537 }
6538
6539 public boolean getInTouchMode() {
6540 synchronized(mWindowMap) {
6541 return mInTouchMode;
6542 }
6543 }
6544
6545 public boolean performHapticFeedback(IWindow window, int effectId,
6546 boolean always) {
6547 synchronized(mWindowMap) {
6548 long ident = Binder.clearCallingIdentity();
6549 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006550 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006551 windowForClientLocked(this, window, true),
6552 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 } finally {
6554 Binder.restoreCallingIdentity(ident);
6555 }
6556 }
6557 }
Romain Guy06882f82009-06-10 13:36:04 -07006558
Christopher Tatea53146c2010-09-07 11:57:52 -07006559 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006560 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006561 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006562 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006563 width, height, outSurface);
6564 }
6565
6566 public boolean performDrag(IWindow window, IBinder dragToken,
6567 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6568 ClipData data) {
6569 if (DEBUG_DRAG) {
6570 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6571 }
6572
6573 synchronized (mWindowMap) {
6574 if (mDragState == null) {
6575 Slog.w(TAG, "No drag prepared");
6576 throw new IllegalStateException("performDrag() without prepareDrag()");
6577 }
6578
6579 if (dragToken != mDragState.mToken) {
6580 Slog.w(TAG, "Performing mismatched drag");
6581 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6582 }
6583
6584 WindowState callingWin = windowForClientLocked(null, window, false);
6585 if (callingWin == null) {
6586 Slog.w(TAG, "Bad requesting window " + window);
6587 return false; // !!! TODO: throw here?
6588 }
6589
6590 // !!! TODO: if input is not still focused on the initiating window, fail
6591 // the drag initiation (e.g. an alarm window popped up just as the application
6592 // called performDrag()
6593
6594 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6595
Christopher Tate2c095f32010-10-04 14:13:40 -07006596 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6597 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006598
Chris Tateb478f462010-10-15 16:02:26 -07006599 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6600 // the actual drag event dispatch stuff in the dragstate
6601
Christopher Tatea53146c2010-09-07 11:57:52 -07006602 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006603 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006604 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6605 mDragState.mServerChannel)) {
6606 Slog.e(TAG, "Unable to transfer touch focus");
6607 mDragState.unregister();
6608 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006609 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006610 return false;
6611 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006612
6613 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006614 mDragState.mCurrentX = touchX;
6615 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006616 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006617
6618 // remember the thumb offsets for later
6619 mDragState.mThumbOffsetX = thumbCenterX;
6620 mDragState.mThumbOffsetY = thumbCenterY;
6621
6622 // Make the surface visible at the proper location
6623 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006624 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006625 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006626 try {
6627 surface.setPosition((int)(touchX - thumbCenterX),
6628 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006629 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006630 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006631 surface.show();
6632 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006633 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006634 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006635 }
6636 }
6637
6638 return true; // success!
6639 }
6640
Chris Tated4533f142010-10-19 15:15:08 -07006641 public void reportDropResult(IWindow window, boolean consumed) {
6642 IBinder token = window.asBinder();
6643 if (DEBUG_DRAG) {
6644 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6645 }
6646
6647 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006648 long ident = Binder.clearCallingIdentity();
6649 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006650 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006651 Slog.w(TAG, "Invalid drop-result claim by " + window);
6652 throw new IllegalStateException("reportDropResult() by non-recipient");
6653 }
6654
6655 // The right window has responded, even if it's no longer around,
6656 // so be sure to halt the timeout even if the later WindowState
6657 // lookup fails.
6658 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6659 WindowState callingWin = windowForClientLocked(null, window, false);
6660 if (callingWin == null) {
6661 Slog.w(TAG, "Bad result-reporting window " + window);
6662 return; // !!! TODO: throw here?
6663 }
6664
6665 mDragState.mDragResult = consumed;
6666 mDragState.endDragLw();
6667 } finally {
6668 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006669 }
Chris Tated4533f142010-10-19 15:15:08 -07006670 }
6671 }
6672
Christopher Tatea53146c2010-09-07 11:57:52 -07006673 public void dragRecipientEntered(IWindow window) {
6674 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006675 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006676 }
6677 }
6678
6679 public void dragRecipientExited(IWindow window) {
6680 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006681 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006682 }
6683 }
6684
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006685 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006686 synchronized(mWindowMap) {
6687 long ident = Binder.clearCallingIdentity();
6688 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006689 setWindowWallpaperPositionLocked(
6690 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006691 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006692 } finally {
6693 Binder.restoreCallingIdentity(ident);
6694 }
6695 }
6696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006697
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006698 public void wallpaperOffsetsComplete(IBinder window) {
6699 WindowManagerService.this.wallpaperOffsetsComplete(window);
6700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006701
Dianne Hackborn75804932009-10-20 20:15:20 -07006702 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6703 int z, Bundle extras, boolean sync) {
6704 synchronized(mWindowMap) {
6705 long ident = Binder.clearCallingIdentity();
6706 try {
6707 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006708 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006709 action, x, y, z, extras, sync);
6710 } finally {
6711 Binder.restoreCallingIdentity(ident);
6712 }
6713 }
6714 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006715
Dianne Hackborn75804932009-10-20 20:15:20 -07006716 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6717 WindowManagerService.this.wallpaperCommandComplete(window, result);
6718 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006720 void windowAddedLocked() {
6721 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006722 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006723 TAG, "First window added to " + this + ", creating SurfaceSession");
6724 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006725 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006726 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006727 mSessions.add(this);
6728 }
6729 mNumWindow++;
6730 }
6731
6732 void windowRemovedLocked() {
6733 mNumWindow--;
6734 killSessionLocked();
6735 }
Romain Guy06882f82009-06-10 13:36:04 -07006736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 void killSessionLocked() {
6738 if (mNumWindow <= 0 && mClientDead) {
6739 mSessions.remove(this);
6740 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006741 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 TAG, "Last window removed from " + this
6743 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006744 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006745 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006746 try {
6747 mSurfaceSession.kill();
6748 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006749 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 + mSurfaceSession + " in session " + this
6751 + ": " + e.toString());
6752 }
6753 mSurfaceSession = null;
6754 }
6755 }
6756 }
Romain Guy06882f82009-06-10 13:36:04 -07006757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006758 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006759 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6760 pw.print(" mClientDead="); pw.print(mClientDead);
6761 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 }
6763
6764 @Override
6765 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006766 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 }
6768 }
6769
6770 // -------------------------------------------------------------
6771 // Client Window State
6772 // -------------------------------------------------------------
6773
6774 private final class WindowState implements WindowManagerPolicy.WindowState {
6775 final Session mSession;
6776 final IWindow mClient;
6777 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006778 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006779 AppWindowToken mAppToken;
6780 AppWindowToken mTargetAppToken;
6781 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6782 final DeathRecipient mDeathRecipient;
6783 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006784 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006785 final int mBaseLayer;
6786 final int mSubLayer;
6787 final boolean mLayoutAttached;
6788 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006789 final boolean mIsWallpaper;
6790 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 int mViewVisibility;
6792 boolean mPolicyVisibility = true;
6793 boolean mPolicyVisibilityAfterAnim = true;
6794 boolean mAppFreezing;
6795 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006796 boolean mReportDestroySurface;
6797 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 boolean mAttachedHidden; // is our parent window hidden?
6799 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006800 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006801 int mRequestedWidth;
6802 int mRequestedHeight;
6803 int mLastRequestedWidth;
6804 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006805 int mLayer;
6806 int mAnimLayer;
6807 int mLastLayer;
6808 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006809 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006810 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006811
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006812 int mLayoutSeq = -1;
6813
6814 Configuration mConfiguration = null;
6815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006816 // Actual frame shown on-screen (may be modified by animation)
6817 final Rect mShownFrame = new Rect();
6818 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006820 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006821 * Set when we have changed the size of the surface, to know that
6822 * we must tell them application to resize (and thus redraw itself).
6823 */
6824 boolean mSurfaceResized;
6825
6826 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 * Insets that determine the actually visible area
6828 */
6829 final Rect mVisibleInsets = new Rect();
6830 final Rect mLastVisibleInsets = new Rect();
6831 boolean mVisibleInsetsChanged;
6832
6833 /**
6834 * Insets that are covered by system windows
6835 */
6836 final Rect mContentInsets = new Rect();
6837 final Rect mLastContentInsets = new Rect();
6838 boolean mContentInsetsChanged;
6839
6840 /**
6841 * Set to true if we are waiting for this window to receive its
6842 * given internal insets before laying out other windows based on it.
6843 */
6844 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 /**
6847 * These are the content insets that were given during layout for
6848 * this window, to be applied to windows behind it.
6849 */
6850 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 /**
6853 * These are the visible insets that were given during layout for
6854 * this window, to be applied to windows behind it.
6855 */
6856 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006859 * This is the given touchable area relative to the window frame, or null if none.
6860 */
6861 final Region mGivenTouchableRegion = new Region();
6862
6863 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 * Flag indicating whether the touchable region should be adjusted by
6865 * the visible insets; if false the area outside the visible insets is
6866 * NOT touchable, so we must use those to adjust the frame during hit
6867 * tests.
6868 */
6869 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006872 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006873 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6874 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6875 float mHScale=1, mVScale=1;
6876 float mLastHScale=1, mLastVScale=1;
6877 final Matrix mTmpMatrix = new Matrix();
6878
6879 // "Real" frame that the application sees.
6880 final Rect mFrame = new Rect();
6881 final Rect mLastFrame = new Rect();
6882
6883 final Rect mContainingFrame = new Rect();
6884 final Rect mDisplayFrame = new Rect();
6885 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006886 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 final Rect mVisibleFrame = new Rect();
6888
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006889 boolean mContentChanged;
6890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 float mShownAlpha = 1;
6892 float mAlpha = 1;
6893 float mLastAlpha = 1;
6894
6895 // Set to true if, when the window gets displayed, it should perform
6896 // an enter animation.
6897 boolean mEnterAnimationPending;
6898
6899 // Currently running animation.
6900 boolean mAnimating;
6901 boolean mLocalAnimating;
6902 Animation mAnimation;
6903 boolean mAnimationIsEntrance;
6904 boolean mHasTransformation;
6905 boolean mHasLocalTransformation;
6906 final Transformation mTransformation = new Transformation();
6907
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006908 // If a window showing a wallpaper: the requested offset for the
6909 // wallpaper; if a wallpaper window: the currently applied offset.
6910 float mWallpaperX = -1;
6911 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006912
6913 // If a window showing a wallpaper: what fraction of the offset
6914 // range corresponds to a full virtual screen.
6915 float mWallpaperXStep = -1;
6916 float mWallpaperYStep = -1;
6917
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006918 // Wallpaper windows: pixels offset based on above variables.
6919 int mXOffset;
6920 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 // This is set after IWindowSession.relayout() has been called at
6923 // least once for the window. It allows us to detect the situation
6924 // where we don't yet have a surface, but should have one soon, so
6925 // we can give the window focus before waiting for the relayout.
6926 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006928 // This is set after the Surface has been created but before the
6929 // window has been drawn. During this time the surface is hidden.
6930 boolean mDrawPending;
6931
6932 // This is set after the window has finished drawing for the first
6933 // time but before its surface is shown. The surface will be
6934 // displayed when the next layout is run.
6935 boolean mCommitDrawPending;
6936
6937 // This is set during the time after the window's drawing has been
6938 // committed, and before its surface is actually shown. It is used
6939 // to delay showing the surface until all windows in a token are ready
6940 // to be shown.
6941 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006943 // Set when the window has been shown in the screen the first time.
6944 boolean mHasDrawn;
6945
6946 // Currently running an exit animation?
6947 boolean mExiting;
6948
6949 // Currently on the mDestroySurface list?
6950 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 // Completely remove from window manager after exit animation?
6953 boolean mRemoveOnExit;
6954
6955 // Set when the orientation is changing and this window has not yet
6956 // been updated for the new orientation.
6957 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 // Is this window now (or just being) removed?
6960 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006961
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006962 // Temp for keeping track of windows that have been removed when
6963 // rebuilding window list.
6964 boolean mRebuilding;
6965
Dianne Hackborn16064f92010-03-25 00:47:24 -07006966 // For debugging, this is the last information given to the surface flinger.
6967 boolean mSurfaceShown;
6968 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6969 int mSurfaceLayer;
6970 float mSurfaceAlpha;
6971
Jeff Brown928e0542011-01-10 11:17:36 -08006972 // Input channel and input window handle used by the input dispatcher.
6973 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006974 InputChannel mInputChannel;
6975
Mattias Petersson1622eee2010-12-21 10:15:11 +01006976 // Used to improve performance of toString()
6977 String mStringNameCache;
6978 CharSequence mLastTitle;
6979 boolean mWasPaused;
6980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 WindowState(Session s, IWindow c, WindowToken token,
6982 WindowState attachedWindow, WindowManager.LayoutParams a,
6983 int viewVisibility) {
6984 mSession = s;
6985 mClient = c;
6986 mToken = token;
6987 mAttrs.copyFrom(a);
6988 mViewVisibility = viewVisibility;
6989 DeathRecipient deathRecipient = new DeathRecipient();
6990 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006991 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006992 TAG, "Window " + this + " client=" + c.asBinder()
6993 + " token=" + token + " (" + mAttrs.token + ")");
6994 try {
6995 c.asBinder().linkToDeath(deathRecipient, 0);
6996 } catch (RemoteException e) {
6997 mDeathRecipient = null;
6998 mAttachedWindow = null;
6999 mLayoutAttached = false;
7000 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007001 mIsWallpaper = false;
7002 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 mBaseLayer = 0;
7004 mSubLayer = 0;
7005 return;
7006 }
7007 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7010 mAttrs.type <= LAST_SUB_WINDOW)) {
7011 // The multiplier here is to reserve space for multiple
7012 // windows in the same type layer.
7013 mBaseLayer = mPolicy.windowTypeToLayerLw(
7014 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7015 + TYPE_LAYER_OFFSET;
7016 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7017 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007018 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007019 mAttachedWindow.mChildWindows.add(this);
7020 mLayoutAttached = mAttrs.type !=
7021 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7022 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7023 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007024 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7025 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007026 } else {
7027 // The multiplier here is to reserve space for multiple
7028 // windows in the same type layer.
7029 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7030 * TYPE_LAYER_MULTIPLIER
7031 + TYPE_LAYER_OFFSET;
7032 mSubLayer = 0;
7033 mAttachedWindow = null;
7034 mLayoutAttached = false;
7035 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7036 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007037 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7038 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007039 }
7040
7041 WindowState appWin = this;
7042 while (appWin.mAttachedWindow != null) {
7043 appWin = mAttachedWindow;
7044 }
7045 WindowToken appToken = appWin.mToken;
7046 while (appToken.appWindowToken == null) {
7047 WindowToken parent = mTokenMap.get(appToken.token);
7048 if (parent == null || appToken == parent) {
7049 break;
7050 }
7051 appToken = parent;
7052 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007053 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 mAppToken = appToken.appWindowToken;
7055
7056 mSurface = null;
7057 mRequestedWidth = 0;
7058 mRequestedHeight = 0;
7059 mLastRequestedWidth = 0;
7060 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007061 mXOffset = 0;
7062 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 mLayer = 0;
7064 mAnimLayer = 0;
7065 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007066 mInputWindowHandle = new InputWindowHandle(
7067 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007068 }
7069
7070 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007071 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 TAG, "Attaching " + this + " token=" + mToken
7073 + ", list=" + mToken.windows);
7074 mSession.windowAddedLocked();
7075 }
7076
7077 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7078 mHaveFrame = true;
7079
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007080 final Rect container = mContainingFrame;
7081 container.set(pf);
7082
7083 final Rect display = mDisplayFrame;
7084 display.set(df);
7085
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007086 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007087 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007088 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7089 display.intersect(mCompatibleScreenFrame);
7090 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007091 }
7092
7093 final int pw = container.right - container.left;
7094 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095
7096 int w,h;
7097 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7098 w = mAttrs.width < 0 ? pw : mAttrs.width;
7099 h = mAttrs.height< 0 ? ph : mAttrs.height;
7100 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007101 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7102 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 }
Romain Guy06882f82009-06-10 13:36:04 -07007104
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007105 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007106 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7107 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007108 mParentFrame.set(pf);
7109 mContentChanged = true;
7110 }
7111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007112 final Rect content = mContentFrame;
7113 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 final Rect visible = mVisibleFrame;
7116 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007118 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007119 final int fw = frame.width();
7120 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007122 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7123 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7124
7125 Gravity.apply(mAttrs.gravity, w, h, container,
7126 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7127 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7128
7129 //System.out.println("Out: " + mFrame);
7130
7131 // Now make sure the window fits in the overall display.
7132 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007134 // Make sure the content and visible frames are inside of the
7135 // final window frame.
7136 if (content.left < frame.left) content.left = frame.left;
7137 if (content.top < frame.top) content.top = frame.top;
7138 if (content.right > frame.right) content.right = frame.right;
7139 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7140 if (visible.left < frame.left) visible.left = frame.left;
7141 if (visible.top < frame.top) visible.top = frame.top;
7142 if (visible.right > frame.right) visible.right = frame.right;
7143 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007145 final Rect contentInsets = mContentInsets;
7146 contentInsets.left = content.left-frame.left;
7147 contentInsets.top = content.top-frame.top;
7148 contentInsets.right = frame.right-content.right;
7149 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007151 final Rect visibleInsets = mVisibleInsets;
7152 visibleInsets.left = visible.left-frame.left;
7153 visibleInsets.top = visible.top-frame.top;
7154 visibleInsets.right = frame.right-visible.right;
7155 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007156
Dianne Hackborn284ac932009-08-28 10:34:25 -07007157 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7158 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007159 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007160 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 if (localLOGV) {
7163 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7164 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007165 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007166 + mRequestedWidth + ", mRequestedheight="
7167 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7168 + "): frame=" + mFrame.toShortString()
7169 + " ci=" + contentInsets.toShortString()
7170 + " vi=" + visibleInsets.toShortString());
7171 //}
7172 }
7173 }
Romain Guy06882f82009-06-10 13:36:04 -07007174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007175 public Rect getFrameLw() {
7176 return mFrame;
7177 }
7178
7179 public Rect getShownFrameLw() {
7180 return mShownFrame;
7181 }
7182
7183 public Rect getDisplayFrameLw() {
7184 return mDisplayFrame;
7185 }
7186
7187 public Rect getContentFrameLw() {
7188 return mContentFrame;
7189 }
7190
7191 public Rect getVisibleFrameLw() {
7192 return mVisibleFrame;
7193 }
7194
7195 public boolean getGivenInsetsPendingLw() {
7196 return mGivenInsetsPending;
7197 }
7198
7199 public Rect getGivenContentInsetsLw() {
7200 return mGivenContentInsets;
7201 }
Romain Guy06882f82009-06-10 13:36:04 -07007202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 public Rect getGivenVisibleInsetsLw() {
7204 return mGivenVisibleInsets;
7205 }
Romain Guy06882f82009-06-10 13:36:04 -07007206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007207 public WindowManager.LayoutParams getAttrs() {
7208 return mAttrs;
7209 }
7210
7211 public int getSurfaceLayer() {
7212 return mLayer;
7213 }
Romain Guy06882f82009-06-10 13:36:04 -07007214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215 public IApplicationToken getAppToken() {
7216 return mAppToken != null ? mAppToken.appToken : null;
7217 }
Jeff Brown349703e2010-06-22 01:27:15 -07007218
7219 public long getInputDispatchingTimeoutNanos() {
7220 return mAppToken != null
7221 ? mAppToken.inputDispatchingTimeoutNanos
7222 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007224
7225 public boolean hasAppShownWindows() {
7226 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7227 }
7228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007229 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007230 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007231 TAG, "Setting animation in " + this + ": " + anim);
7232 mAnimating = false;
7233 mLocalAnimating = false;
7234 mAnimation = anim;
7235 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7236 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7237 }
7238
7239 public void clearAnimation() {
7240 if (mAnimation != null) {
7241 mAnimating = true;
7242 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007243 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007244 mAnimation = null;
7245 }
7246 }
Romain Guy06882f82009-06-10 13:36:04 -07007247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 Surface createSurfaceLocked() {
7249 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007250 mReportDestroySurface = false;
7251 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 mDrawPending = true;
7253 mCommitDrawPending = false;
7254 mReadyToShow = false;
7255 if (mAppToken != null) {
7256 mAppToken.allDrawn = false;
7257 }
7258
7259 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007260
7261 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7262 flags |= Surface.SECURE;
7263 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007264 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007265 TAG, "Creating surface in session "
7266 + mSession.mSurfaceSession + " window " + this
7267 + " w=" + mFrame.width()
7268 + " h=" + mFrame.height() + " format="
7269 + mAttrs.format + " flags=" + flags);
7270
7271 int w = mFrame.width();
7272 int h = mFrame.height();
7273 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7274 // for a scaled surface, we always want the requested
7275 // size.
7276 w = mRequestedWidth;
7277 h = mRequestedHeight;
7278 }
7279
Romain Guy9825ec62009-10-01 00:58:09 -07007280 // Something is wrong and SurfaceFlinger will not like this,
7281 // try to revert to sane values
7282 if (w <= 0) w = 1;
7283 if (h <= 0) h = 1;
7284
Dianne Hackborn16064f92010-03-25 00:47:24 -07007285 mSurfaceShown = false;
7286 mSurfaceLayer = 0;
7287 mSurfaceAlpha = 1;
7288 mSurfaceX = 0;
7289 mSurfaceY = 0;
7290 mSurfaceW = w;
7291 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007292 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007293 final boolean isHwAccelerated = (mAttrs.flags &
7294 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7295 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7296 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7297 flags |= Surface.OPAQUE;
7298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007300 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007301 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007302 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007303 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007304 + mSurface + " IN SESSION "
7305 + mSession.mSurfaceSession
7306 + ": pid=" + mSession.mPid + " format="
7307 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007308 + Integer.toHexString(flags)
7309 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007311 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007312 reclaimSomeSurfaceMemoryLocked(this, "create");
7313 return null;
7314 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007315 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 return null;
7317 }
Romain Guy06882f82009-06-10 13:36:04 -07007318
Joe Onorato8a9b2202010-02-26 18:56:32 -08007319 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007320 TAG, "Got surface: " + mSurface
7321 + ", set left=" + mFrame.left + " top=" + mFrame.top
7322 + ", animLayer=" + mAnimLayer);
7323 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007324 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7325 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007326 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7327 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007328 }
7329 Surface.openTransaction();
7330 try {
7331 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007332 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007333 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007334 mSurface.setPosition(mSurfaceX, mSurfaceY);
7335 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007337 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 mSurface.hide();
7339 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007340 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007341 mSurface.setFlags(Surface.SURFACE_DITHER,
7342 Surface.SURFACE_DITHER);
7343 }
7344 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007345 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7347 }
7348 mLastHidden = true;
7349 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007351 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007353 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 TAG, "Created surface " + this);
7355 }
7356 return mSurface;
7357 }
Romain Guy06882f82009-06-10 13:36:04 -07007358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007360 if (mAppToken != null && this == mAppToken.startingWindow) {
7361 mAppToken.startingDisplayed = false;
7362 }
Romain Guy06882f82009-06-10 13:36:04 -07007363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007364 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007365 mDrawPending = false;
7366 mCommitDrawPending = false;
7367 mReadyToShow = false;
7368
7369 int i = mChildWindows.size();
7370 while (i > 0) {
7371 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007372 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007373 c.mAttachedHidden = true;
7374 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007375
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007376 if (mReportDestroySurface) {
7377 mReportDestroySurface = false;
7378 mSurfacePendingDestroy = true;
7379 try {
7380 mClient.dispatchGetNewSurface();
7381 // We'll really destroy on the next time around.
7382 return;
7383 } catch (RemoteException e) {
7384 }
7385 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007388 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007389 RuntimeException e = null;
7390 if (!HIDE_STACK_CRAWLS) {
7391 e = new RuntimeException();
7392 e.fillInStackTrace();
7393 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007394 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007395 + mSurface + ", session " + mSession, e);
7396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007397 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007398 RuntimeException e = null;
7399 if (!HIDE_STACK_CRAWLS) {
7400 e = new RuntimeException();
7401 e.fillInStackTrace();
7402 }
7403 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007405 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007407 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 + " surface " + mSurface + " session " + mSession
7409 + ": " + e.toString());
7410 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007411
Dianne Hackborn16064f92010-03-25 00:47:24 -07007412 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007414 }
7415 }
7416
7417 boolean finishDrawingLocked() {
7418 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007419 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007420 TAG, "finishDrawingLocked: " + mSurface);
7421 mCommitDrawPending = true;
7422 mDrawPending = false;
7423 return true;
7424 }
7425 return false;
7426 }
7427
7428 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007429 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007430 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007431 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007432 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 }
7434 mCommitDrawPending = false;
7435 mReadyToShow = true;
7436 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7437 final AppWindowToken atoken = mAppToken;
7438 if (atoken == null || atoken.allDrawn || starting) {
7439 performShowLocked();
7440 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007441 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 }
7443
7444 // This must be called while inside a transaction.
7445 boolean performShowLocked() {
7446 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007447 RuntimeException e = null;
7448 if (!HIDE_STACK_CRAWLS) {
7449 e = new RuntimeException();
7450 e.fillInStackTrace();
7451 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007452 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7454 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7455 }
7456 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007457 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7458 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007459 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 + " during animation: policyVis=" + mPolicyVisibility
7461 + " attHidden=" + mAttachedHidden
7462 + " tok.hiddenRequested="
7463 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007464 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007465 + (mAppToken != null ? mAppToken.hidden : false)
7466 + " animating=" + mAnimating
7467 + " tok animating="
7468 + (mAppToken != null ? mAppToken.animating : false));
7469 if (!showSurfaceRobustlyLocked(this)) {
7470 return false;
7471 }
7472 mLastAlpha = -1;
7473 mHasDrawn = true;
7474 mLastHidden = false;
7475 mReadyToShow = false;
7476 enableScreenIfNeededLocked();
7477
7478 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 int i = mChildWindows.size();
7481 while (i > 0) {
7482 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007483 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007484 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007485 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007486 if (c.mSurface != null) {
7487 c.performShowLocked();
7488 // It hadn't been shown, which means layout not
7489 // performed on it, so now we want to make sure to
7490 // do a layout. If called from within the transaction
7491 // loop, this will cause it to restart with a new
7492 // layout.
7493 mLayoutNeeded = true;
7494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 }
7496 }
Romain Guy06882f82009-06-10 13:36:04 -07007497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 if (mAttrs.type != TYPE_APPLICATION_STARTING
7499 && mAppToken != null) {
7500 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007501
Dianne Hackborn248b1882009-09-16 16:46:44 -07007502 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007503 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007504 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007506 // If this initial window is animating, stop it -- we
7507 // will do an animation to reveal it from behind the
7508 // starting window, so there is no need for it to also
7509 // be doing its own stuff.
7510 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007511 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007512 mAnimation = null;
7513 // Make sure we clean up the animation.
7514 mAnimating = true;
7515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 mFinishedStarting.add(mAppToken);
7517 mH.sendEmptyMessage(H.FINISHED_STARTING);
7518 }
7519 mAppToken.updateReportedVisibilityLocked();
7520 }
7521 }
7522 return true;
7523 }
Romain Guy06882f82009-06-10 13:36:04 -07007524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 // This must be called while inside a transaction. Returns true if
7526 // there is more animation to run.
7527 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007528 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007529 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7532 mHasTransformation = true;
7533 mHasLocalTransformation = true;
7534 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007535 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007536 TAG, "Starting animation in " + this +
7537 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7538 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7539 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7540 mAnimation.setStartTime(currentTime);
7541 mLocalAnimating = true;
7542 mAnimating = true;
7543 }
7544 mTransformation.clear();
7545 final boolean more = mAnimation.getTransformation(
7546 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007547 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007548 TAG, "Stepped animation in " + this +
7549 ": more=" + more + ", xform=" + mTransformation);
7550 if (more) {
7551 // we're not done!
7552 return true;
7553 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007554 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007555 TAG, "Finished animation in " + this +
7556 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007557
7558 if (mAnimation != null) {
7559 mAnimation.cancel();
7560 mAnimation = null;
7561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 //WindowManagerService.this.dump();
7563 }
7564 mHasLocalTransformation = false;
7565 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007566 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007567 // When our app token is animating, we kind-of pretend like
7568 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7569 // part of this check means that we will only do this if
7570 // our window is not currently exiting, or it is not
7571 // locally animating itself. The idea being that one that
7572 // is exiting and doing a local animation should be removed
7573 // once that animation is done.
7574 mAnimating = true;
7575 mHasTransformation = true;
7576 mTransformation.clear();
7577 return false;
7578 } else if (mHasTransformation) {
7579 // Little trick to get through the path below to act like
7580 // we have finished an animation.
7581 mAnimating = true;
7582 } else if (isAnimating()) {
7583 mAnimating = true;
7584 }
7585 } else if (mAnimation != null) {
7586 // If the display is frozen, and there is a pending animation,
7587 // clear it and make sure we run the cleanup code.
7588 mAnimating = true;
7589 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007590 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 mAnimation = null;
7592 }
Romain Guy06882f82009-06-10 13:36:04 -07007593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 if (!mAnimating && !mLocalAnimating) {
7595 return false;
7596 }
7597
Joe Onorato8a9b2202010-02-26 18:56:32 -08007598 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 TAG, "Animation done in " + this + ": exiting=" + mExiting
7600 + ", reportedVisible="
7601 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007603 mAnimating = false;
7604 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007605 if (mAnimation != null) {
7606 mAnimation.cancel();
7607 mAnimation = null;
7608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 mAnimLayer = mLayer;
7610 if (mIsImWindow) {
7611 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007612 } else if (mIsWallpaper) {
7613 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007615 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007616 + " anim layer: " + mAnimLayer);
7617 mHasTransformation = false;
7618 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007619 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7620 if (DEBUG_VISIBILITY) {
7621 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7622 + mPolicyVisibilityAfterAnim);
7623 }
7624 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7625 if (!mPolicyVisibility) {
7626 if (mCurrentFocus == this) {
7627 mFocusMayChange = true;
7628 }
7629 // Window is no longer visible -- make sure if we were waiting
7630 // for it to be displayed before enabling the display, that
7631 // we allow the display to be enabled now.
7632 enableScreenIfNeededLocked();
7633 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007635 mTransformation.clear();
7636 if (mHasDrawn
7637 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7638 && mAppToken != null
7639 && mAppToken.firstWindowDrawn
7640 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007641 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007642 + mToken + ": first real window done animating");
7643 mFinishedStarting.add(mAppToken);
7644 mH.sendEmptyMessage(H.FINISHED_STARTING);
7645 }
Romain Guy06882f82009-06-10 13:36:04 -07007646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007647 finishExit();
7648
7649 if (mAppToken != null) {
7650 mAppToken.updateReportedVisibilityLocked();
7651 }
7652
7653 return false;
7654 }
7655
7656 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007657 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007658 TAG, "finishExit in " + this
7659 + ": exiting=" + mExiting
7660 + " remove=" + mRemoveOnExit
7661 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 final int N = mChildWindows.size();
7664 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007665 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007666 }
Romain Guy06882f82009-06-10 13:36:04 -07007667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007668 if (!mExiting) {
7669 return;
7670 }
Romain Guy06882f82009-06-10 13:36:04 -07007671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007672 if (isWindowAnimating()) {
7673 return;
7674 }
7675
Joe Onorato8a9b2202010-02-26 18:56:32 -08007676 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007677 TAG, "Exit animation finished in " + this
7678 + ": remove=" + mRemoveOnExit);
7679 if (mSurface != null) {
7680 mDestroySurface.add(this);
7681 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007682 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007683 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007684 try {
7685 mSurface.hide();
7686 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007687 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007688 }
7689 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 }
7691 mExiting = false;
7692 if (mRemoveOnExit) {
7693 mPendingRemove.add(this);
7694 mRemoveOnExit = false;
7695 }
7696 }
Romain Guy06882f82009-06-10 13:36:04 -07007697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7699 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7700 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7701 if (dtdx < -.000001f || dtdx > .000001f) return false;
7702 if (dsdy < -.000001f || dsdy > .000001f) return false;
7703 return true;
7704 }
Romain Guy06882f82009-06-10 13:36:04 -07007705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 void computeShownFrameLocked() {
7707 final boolean selfTransformation = mHasLocalTransformation;
7708 Transformation attachedTransformation =
7709 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7710 ? mAttachedWindow.mTransformation : null;
7711 Transformation appTransformation =
7712 (mAppToken != null && mAppToken.hasTransformation)
7713 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007714
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007715 // Wallpapers are animated based on the "real" window they
7716 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007717 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007718 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007719 if (mWallpaperTarget.mHasLocalTransformation &&
7720 mWallpaperTarget.mAnimation != null &&
7721 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007722 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007723 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007724 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007725 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007726 }
7727 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007728 mWallpaperTarget.mAppToken.hasTransformation &&
7729 mWallpaperTarget.mAppToken.animation != null &&
7730 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007731 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007732 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007733 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007734 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007735 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007736 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007737
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007738 final boolean screenAnimation = mScreenRotationAnimation != null
7739 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007740 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007741 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007742 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007743 final Rect frame = mFrame;
7744 final float tmpFloats[] = mTmpFloats;
7745 final Matrix tmpMatrix = mTmpMatrix;
7746
7747 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007748 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007749 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007750 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007751 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007752 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007754 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007755 }
7756 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007757 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007759 if (screenAnimation) {
7760 tmpMatrix.postConcat(
7761 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7762 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007763
7764 // "convert" it into SurfaceFlinger's format
7765 // (a 2x2 matrix + an offset)
7766 // Here we must not transform the position of the surface
7767 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007768 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007769
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007770 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007771 tmpMatrix.getValues(tmpFloats);
7772 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007773 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7774 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007776 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7777 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007778 int w = frame.width();
7779 int h = frame.height();
7780 mShownFrame.set(x, y, x+w, y+h);
7781
7782 // Now set the alpha... but because our current hardware
7783 // can't do alpha transformation on a non-opaque surface,
7784 // turn it off if we are running an animation that is also
7785 // transforming since it is more important to have that
7786 // animation be smooth.
7787 mShownAlpha = mAlpha;
7788 if (!mLimitedAlphaCompositing
7789 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7790 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7791 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007792 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007793 if (selfTransformation) {
7794 mShownAlpha *= mTransformation.getAlpha();
7795 }
7796 if (attachedTransformation != null) {
7797 mShownAlpha *= attachedTransformation.getAlpha();
7798 }
7799 if (appTransformation != null) {
7800 mShownAlpha *= appTransformation.getAlpha();
7801 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007802 if (screenAnimation) {
7803 mShownAlpha *=
7804 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7805 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007806 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007807 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007808 }
Romain Guy06882f82009-06-10 13:36:04 -07007809
Joe Onorato8a9b2202010-02-26 18:56:32 -08007810 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007811 TAG, "Continuing animation in " + this +
7812 ": " + mShownFrame +
7813 ", alpha=" + mTransformation.getAlpha());
7814 return;
7815 }
Romain Guy06882f82009-06-10 13:36:04 -07007816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007817 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007818 if (mXOffset != 0 || mYOffset != 0) {
7819 mShownFrame.offset(mXOffset, mYOffset);
7820 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007822 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007823 mDsDx = 1;
7824 mDtDx = 0;
7825 mDsDy = 0;
7826 mDtDy = 1;
7827 }
Romain Guy06882f82009-06-10 13:36:04 -07007828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007829 /**
7830 * Is this window visible? It is not visible if there is no
7831 * surface, or we are in the process of running an exit animation
7832 * that will remove the surface, or its app token has been hidden.
7833 */
7834 public boolean isVisibleLw() {
7835 final AppWindowToken atoken = mAppToken;
7836 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7837 && (atoken == null || !atoken.hiddenRequested)
7838 && !mExiting && !mDestroying;
7839 }
7840
7841 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007842 * Like {@link #isVisibleLw}, but also counts a window that is currently
7843 * "hidden" behind the keyguard as visible. This allows us to apply
7844 * things like window flags that impact the keyguard.
7845 * XXX I am starting to think we need to have ANOTHER visibility flag
7846 * for this "hidden behind keyguard" state rather than overloading
7847 * mPolicyVisibility. Ungh.
7848 */
7849 public boolean isVisibleOrBehindKeyguardLw() {
7850 final AppWindowToken atoken = mAppToken;
7851 return mSurface != null && !mAttachedHidden
7852 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007853 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007854 && !mExiting && !mDestroying;
7855 }
7856
7857 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007858 * Is this window visible, ignoring its app token? It is not visible
7859 * if there is no surface, or we are in the process of running an exit animation
7860 * that will remove the surface.
7861 */
7862 public boolean isWinVisibleLw() {
7863 final AppWindowToken atoken = mAppToken;
7864 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7865 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7866 && !mExiting && !mDestroying;
7867 }
7868
7869 /**
7870 * The same as isVisible(), but follows the current hidden state of
7871 * the associated app token, not the pending requested hidden state.
7872 */
7873 boolean isVisibleNow() {
7874 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007875 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876 }
7877
7878 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007879 * Can this window possibly be a drag/drop target? The test here is
7880 * a combination of the above "visible now" with the check that the
7881 * Input Manager uses when discarding windows from input consideration.
7882 */
7883 boolean isPotentialDragTarget() {
7884 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7885 }
7886
7887 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007888 * Same as isVisible(), but we also count it as visible between the
7889 * call to IWindowSession.add() and the first relayout().
7890 */
7891 boolean isVisibleOrAdding() {
7892 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007893 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7895 && mPolicyVisibility && !mAttachedHidden
7896 && (atoken == null || !atoken.hiddenRequested)
7897 && !mExiting && !mDestroying;
7898 }
7899
7900 /**
7901 * Is this window currently on-screen? It is on-screen either if it
7902 * is visible or it is currently running an animation before no longer
7903 * being visible.
7904 */
7905 boolean isOnScreen() {
7906 final AppWindowToken atoken = mAppToken;
7907 if (atoken != null) {
7908 return mSurface != null && mPolicyVisibility && !mDestroying
7909 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007910 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007911 } else {
7912 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007913 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007914 }
7915 }
Romain Guy06882f82009-06-10 13:36:04 -07007916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007917 /**
7918 * Like isOnScreen(), but we don't return true if the window is part
7919 * of a transition that has not yet been started.
7920 */
7921 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007922 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007923 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007924 return false;
7925 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007926 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007927 final boolean animating = atoken != null
7928 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007930 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7931 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007932 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007933 }
7934
7935 /** Is the window or its container currently animating? */
7936 boolean isAnimating() {
7937 final WindowState attached = mAttachedWindow;
7938 final AppWindowToken atoken = mAppToken;
7939 return mAnimation != null
7940 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007941 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007942 (atoken.animation != null
7943 || atoken.inPendingTransaction));
7944 }
7945
7946 /** Is this window currently animating? */
7947 boolean isWindowAnimating() {
7948 return mAnimation != null;
7949 }
7950
7951 /**
7952 * Like isOnScreen, but returns false if the surface hasn't yet
7953 * been drawn.
7954 */
7955 public boolean isDisplayedLw() {
7956 final AppWindowToken atoken = mAppToken;
7957 return mSurface != null && mPolicyVisibility && !mDestroying
7958 && !mDrawPending && !mCommitDrawPending
7959 && ((!mAttachedHidden &&
7960 (atoken == null || !atoken.hiddenRequested))
7961 || mAnimating);
7962 }
7963
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007964 /**
7965 * Returns true if the window has a surface that it has drawn a
7966 * complete UI in to.
7967 */
7968 public boolean isDrawnLw() {
7969 final AppWindowToken atoken = mAppToken;
7970 return mSurface != null && !mDestroying
7971 && !mDrawPending && !mCommitDrawPending;
7972 }
7973
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007974 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007975 * Return true if the window is opaque and fully drawn. This indicates
7976 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007977 */
7978 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007979 return (mAttrs.format == PixelFormat.OPAQUE
7980 || mAttrs.type == TYPE_WALLPAPER)
7981 && mSurface != null && mAnimation == null
7982 && (mAppToken == null || mAppToken.animation == null)
7983 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007984 }
7985
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007986 /**
7987 * Return whether this window is wanting to have a translation
7988 * animation applied to it for an in-progress move. (Only makes
7989 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7990 */
7991 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007992 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007993 && (mFrame.top != mLastFrame.top
7994 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007995 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007996 && mPolicy.isScreenOn();
7997 }
7998
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007999 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8000 return
8001 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008002 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8003 // only if it's visible
8004 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008005 // and only if the application fills the compatible screen
8006 mFrame.left <= mCompatibleScreenFrame.left &&
8007 mFrame.top <= mCompatibleScreenFrame.top &&
8008 mFrame.right >= mCompatibleScreenFrame.right &&
8009 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008010 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008011 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008012 }
8013
8014 boolean isFullscreen(int screenWidth, int screenHeight) {
8015 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008016 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008017 }
8018
8019 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008020 disposeInputChannel();
8021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008023 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008024 mAttachedWindow.mChildWindows.remove(this);
8025 }
8026 destroySurfaceLocked();
8027 mSession.windowRemovedLocked();
8028 try {
8029 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8030 } catch (RuntimeException e) {
8031 // Ignore if it has already been removed (usually because
8032 // we are doing this as part of processing a death note.)
8033 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008034 }
8035
8036 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008037 if (mInputChannel != null) {
8038 mInputManager.unregisterInputChannel(mInputChannel);
8039
8040 mInputChannel.dispose();
8041 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008042 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 }
8044
8045 private class DeathRecipient implements IBinder.DeathRecipient {
8046 public void binderDied() {
8047 try {
8048 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008049 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008050 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008051 if (win != null) {
8052 removeWindowLocked(mSession, win);
8053 }
8054 }
8055 } catch (IllegalArgumentException ex) {
8056 // This will happen if the window has already been
8057 // removed.
8058 }
8059 }
8060 }
8061
8062 /** Returns true if this window desires key events. */
8063 public final boolean canReceiveKeys() {
8064 return isVisibleOrAdding()
8065 && (mViewVisibility == View.VISIBLE)
8066 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8067 }
8068
8069 public boolean hasDrawnLw() {
8070 return mHasDrawn;
8071 }
8072
8073 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008074 return showLw(doAnimation, true);
8075 }
8076
8077 boolean showLw(boolean doAnimation, boolean requestAnim) {
8078 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8079 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008080 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008081 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008082 if (doAnimation) {
8083 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8084 + mPolicyVisibility + " mAnimation=" + mAnimation);
8085 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8086 doAnimation = false;
8087 } else if (mPolicyVisibility && mAnimation == null) {
8088 // Check for the case where we are currently visible and
8089 // not animating; we do not want to do animation at such a
8090 // point to become visible when we already are.
8091 doAnimation = false;
8092 }
8093 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008094 mPolicyVisibility = true;
8095 mPolicyVisibilityAfterAnim = true;
8096 if (doAnimation) {
8097 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8098 }
8099 if (requestAnim) {
8100 requestAnimationLocked(0);
8101 }
8102 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 }
8104
8105 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008106 return hideLw(doAnimation, true);
8107 }
8108
8109 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008110 if (doAnimation) {
8111 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8112 doAnimation = false;
8113 }
8114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008115 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8116 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008117 if (!current) {
8118 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008119 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008120 if (doAnimation) {
8121 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8122 if (mAnimation == null) {
8123 doAnimation = false;
8124 }
8125 }
8126 if (doAnimation) {
8127 mPolicyVisibilityAfterAnim = false;
8128 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008129 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008130 mPolicyVisibilityAfterAnim = false;
8131 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008132 // Window is no longer visible -- make sure if we were waiting
8133 // for it to be displayed before enabling the display, that
8134 // we allow the display to be enabled now.
8135 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008136 if (mCurrentFocus == this) {
8137 mFocusMayChange = true;
8138 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008139 }
8140 if (requestAnim) {
8141 requestAnimationLocked(0);
8142 }
8143 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008144 }
8145
Jeff Brownfbf09772011-01-16 14:06:57 -08008146 public void getTouchableRegion(Region outRegion) {
8147 final Rect frame = mFrame;
8148 switch (mTouchableInsets) {
8149 default:
8150 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8151 outRegion.set(frame);
8152 break;
8153 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8154 final Rect inset = mGivenContentInsets;
8155 outRegion.set(
8156 frame.left + inset.left, frame.top + inset.top,
8157 frame.right - inset.right, frame.bottom - inset.bottom);
8158 break;
8159 }
8160 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8161 final Rect inset = mGivenVisibleInsets;
8162 outRegion.set(
8163 frame.left + inset.left, frame.top + inset.top,
8164 frame.right - inset.right, frame.bottom - inset.bottom);
8165 break;
8166 }
8167 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8168 final Region givenTouchableRegion = mGivenTouchableRegion;
8169 outRegion.set(givenTouchableRegion);
8170 outRegion.translate(frame.left, frame.top);
8171 break;
8172 }
8173 }
8174 }
8175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008176 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008177 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8178 pw.print(" mClient="); pw.println(mClient.asBinder());
8179 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8180 if (mAttachedWindow != null || mLayoutAttached) {
8181 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8182 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8183 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008184 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8185 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8186 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008187 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8188 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008189 }
8190 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8191 pw.print(" mSubLayer="); pw.print(mSubLayer);
8192 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8193 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8194 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8195 pw.print("="); pw.print(mAnimLayer);
8196 pw.print(" mLastLayer="); pw.println(mLastLayer);
8197 if (mSurface != null) {
8198 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008199 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8200 pw.print(" layer="); pw.print(mSurfaceLayer);
8201 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8202 pw.print(" rect=("); pw.print(mSurfaceX);
8203 pw.print(","); pw.print(mSurfaceY);
8204 pw.print(") "); pw.print(mSurfaceW);
8205 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008206 }
8207 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8208 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8209 if (mAppToken != null) {
8210 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8211 }
8212 if (mTargetAppToken != null) {
8213 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8214 }
8215 pw.print(prefix); pw.print("mViewVisibility=0x");
8216 pw.print(Integer.toHexString(mViewVisibility));
8217 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008218 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8219 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008220 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8221 pw.print(prefix); pw.print("mPolicyVisibility=");
8222 pw.print(mPolicyVisibility);
8223 pw.print(" mPolicyVisibilityAfterAnim=");
8224 pw.print(mPolicyVisibilityAfterAnim);
8225 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8226 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008227 if (!mRelayoutCalled) {
8228 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8229 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008230 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008231 pw.print(" h="); pw.print(mRequestedHeight);
8232 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008233 if (mXOffset != 0 || mYOffset != 0) {
8234 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8235 pw.print(" y="); pw.println(mYOffset);
8236 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008237 pw.print(prefix); pw.print("mGivenContentInsets=");
8238 mGivenContentInsets.printShortString(pw);
8239 pw.print(" mGivenVisibleInsets=");
8240 mGivenVisibleInsets.printShortString(pw);
8241 pw.println();
8242 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8243 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8244 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8245 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008246 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008247 pw.print(prefix); pw.print("mShownFrame=");
8248 mShownFrame.printShortString(pw);
8249 pw.print(" last="); mLastShownFrame.printShortString(pw);
8250 pw.println();
8251 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8252 pw.print(" last="); mLastFrame.printShortString(pw);
8253 pw.println();
8254 pw.print(prefix); pw.print("mContainingFrame=");
8255 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008256 pw.print(" mParentFrame=");
8257 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008258 pw.print(" mDisplayFrame=");
8259 mDisplayFrame.printShortString(pw);
8260 pw.println();
8261 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8262 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8263 pw.println();
8264 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8265 pw.print(" last="); mLastContentInsets.printShortString(pw);
8266 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8267 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8268 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008269 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8270 || mAnimation != null) {
8271 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8272 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8273 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8274 pw.print(" mAnimation="); pw.println(mAnimation);
8275 }
8276 if (mHasTransformation || mHasLocalTransformation) {
8277 pw.print(prefix); pw.print("XForm: has=");
8278 pw.print(mHasTransformation);
8279 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8280 pw.print(" "); mTransformation.printShortString(pw);
8281 pw.println();
8282 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008283 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8284 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8285 pw.print(" mAlpha="); pw.print(mAlpha);
8286 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8287 }
8288 if (mHaveMatrix) {
8289 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8290 pw.print(" mDtDx="); pw.print(mDtDx);
8291 pw.print(" mDsDy="); pw.print(mDsDy);
8292 pw.print(" mDtDy="); pw.println(mDtDy);
8293 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008294 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8295 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8296 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8297 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8298 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8299 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8300 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8301 pw.print(" mDestroying="); pw.print(mDestroying);
8302 pw.print(" mRemoved="); pw.println(mRemoved);
8303 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008304 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008305 pw.print(prefix); pw.print("mOrientationChanging=");
8306 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008307 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8308 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008309 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008310 if (mHScale != 1 || mVScale != 1) {
8311 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8312 pw.print(" mVScale="); pw.println(mVScale);
8313 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008314 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008315 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8316 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8317 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008318 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8319 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8320 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8321 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008322 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008323
8324 String makeInputChannelName() {
8325 return Integer.toHexString(System.identityHashCode(this))
8326 + " " + mAttrs.getTitle();
8327 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328
8329 @Override
8330 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008331 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8332 || mWasPaused != mToken.paused) {
8333 mLastTitle = mAttrs.getTitle();
8334 mWasPaused = mToken.paused;
8335 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8336 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8337 }
8338 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008339 }
8340 }
Romain Guy06882f82009-06-10 13:36:04 -07008341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008342 // -------------------------------------------------------------
8343 // Window Token State
8344 // -------------------------------------------------------------
8345
8346 class WindowToken {
8347 // The actual token.
8348 final IBinder token;
8349
8350 // The type of window this token is for, as per WindowManager.LayoutParams.
8351 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 // Set if this token was explicitly added by a client, so should
8354 // not be removed when all windows are removed.
8355 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008356
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008357 // For printing.
8358 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 // If this is an AppWindowToken, this is non-null.
8361 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008363 // All of the windows associated with this token.
8364 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8365
8366 // Is key dispatching paused for this token?
8367 boolean paused = false;
8368
8369 // Should this token's windows be hidden?
8370 boolean hidden;
8371
8372 // Temporary for finding which tokens no longer have visible windows.
8373 boolean hasVisible;
8374
Dianne Hackborna8f60182009-09-01 19:01:50 -07008375 // Set to true when this token is in a pending transaction where it
8376 // will be shown.
8377 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008378
Dianne Hackborna8f60182009-09-01 19:01:50 -07008379 // Set to true when this token is in a pending transaction where it
8380 // will be hidden.
8381 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008382
Dianne Hackborna8f60182009-09-01 19:01:50 -07008383 // Set to true when this token is in a pending transaction where its
8384 // windows will be put to the bottom of the list.
8385 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008386
Dianne Hackborna8f60182009-09-01 19:01:50 -07008387 // Set to true when this token is in a pending transaction where its
8388 // windows will be put to the top of the list.
8389 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008391 WindowToken(IBinder _token, int type, boolean _explicit) {
8392 token = _token;
8393 windowType = type;
8394 explicit = _explicit;
8395 }
8396
8397 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008398 pw.print(prefix); pw.print("token="); pw.println(token);
8399 pw.print(prefix); pw.print("windows="); pw.println(windows);
8400 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8401 pw.print(" hidden="); pw.print(hidden);
8402 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008403 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8404 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8405 pw.print(" waitingToHide="); pw.print(waitingToHide);
8406 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8407 pw.print(" sendingToTop="); pw.println(sendingToTop);
8408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 }
8410
8411 @Override
8412 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008413 if (stringName == null) {
8414 StringBuilder sb = new StringBuilder();
8415 sb.append("WindowToken{");
8416 sb.append(Integer.toHexString(System.identityHashCode(this)));
8417 sb.append(" token="); sb.append(token); sb.append('}');
8418 stringName = sb.toString();
8419 }
8420 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008421 }
8422 };
8423
8424 class AppWindowToken extends WindowToken {
8425 // Non-null only for application tokens.
8426 final IApplicationToken appToken;
8427
8428 // All of the windows and child windows that are included in this
8429 // application token. Note this list is NOT sorted!
8430 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8431
8432 int groupId = -1;
8433 boolean appFullscreen;
8434 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008435
8436 // The input dispatching timeout for this application token in nanoseconds.
8437 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008439 // These are used for determining when all windows associated with
8440 // an activity have been drawn, so they can be made visible together
8441 // at the same time.
8442 int lastTransactionSequence = mTransactionSequence-1;
8443 int numInterestingWindows;
8444 int numDrawnWindows;
8445 boolean inPendingTransaction;
8446 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008448 // Is this token going to be hidden in a little while? If so, it
8449 // won't be taken into account for setting the screen orientation.
8450 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 // Is this window's surface needed? This is almost like hidden, except
8453 // it will sometimes be true a little earlier: when the token has
8454 // been shown, but is still waiting for its app transition to execute
8455 // before making its windows shown.
8456 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 // Have we told the window clients to hide themselves?
8459 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008461 // Last visibility state we reported to the app token.
8462 boolean reportedVisible;
8463
8464 // Set to true when the token has been removed from the window mgr.
8465 boolean removed;
8466
8467 // Have we been asked to have this token keep the screen frozen?
8468 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008470 boolean animating;
8471 Animation animation;
8472 boolean hasTransformation;
8473 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008475 // Offset to the window of all layers in the token, for use by
8476 // AppWindowToken animations.
8477 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 // Information about an application starting window if displayed.
8480 StartingData startingData;
8481 WindowState startingWindow;
8482 View startingView;
8483 boolean startingDisplayed;
8484 boolean startingMoved;
8485 boolean firstWindowDrawn;
8486
Jeff Brown928e0542011-01-10 11:17:36 -08008487 // Input application handle used by the input dispatcher.
8488 InputApplicationHandle mInputApplicationHandle;
8489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008490 AppWindowToken(IApplicationToken _token) {
8491 super(_token.asBinder(),
8492 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8493 appWindowToken = this;
8494 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008495 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 }
Romain Guy06882f82009-06-10 13:36:04 -07008497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008499 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008500 TAG, "Setting animation in " + this + ": " + anim);
8501 animation = anim;
8502 animating = false;
8503 anim.restrictDuration(MAX_ANIMATION_DURATION);
8504 anim.scaleCurrentDuration(mTransitionAnimationScale);
8505 int zorder = anim.getZAdjustment();
8506 int adj = 0;
8507 if (zorder == Animation.ZORDER_TOP) {
8508 adj = TYPE_LAYER_OFFSET;
8509 } else if (zorder == Animation.ZORDER_BOTTOM) {
8510 adj = -TYPE_LAYER_OFFSET;
8511 }
Romain Guy06882f82009-06-10 13:36:04 -07008512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 if (animLayerAdjustment != adj) {
8514 animLayerAdjustment = adj;
8515 updateLayers();
8516 }
8517 }
Romain Guy06882f82009-06-10 13:36:04 -07008518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008519 public void setDummyAnimation() {
8520 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008521 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008522 TAG, "Setting dummy animation in " + this);
8523 animation = sDummyAnimation;
8524 }
8525 }
8526
8527 public void clearAnimation() {
8528 if (animation != null) {
8529 animation = null;
8530 animating = true;
8531 }
8532 }
Romain Guy06882f82009-06-10 13:36:04 -07008533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 void updateLayers() {
8535 final int N = allAppWindows.size();
8536 final int adj = animLayerAdjustment;
8537 for (int i=0; i<N; i++) {
8538 WindowState w = allAppWindows.get(i);
8539 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008540 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541 + w.mAnimLayer);
8542 if (w == mInputMethodTarget) {
8543 setInputMethodAnimLayerAdjustment(adj);
8544 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008545 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008546 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 }
8549 }
Romain Guy06882f82009-06-10 13:36:04 -07008550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008551 void sendAppVisibilityToClients() {
8552 final int N = allAppWindows.size();
8553 for (int i=0; i<N; i++) {
8554 WindowState win = allAppWindows.get(i);
8555 if (win == startingWindow && clientHidden) {
8556 // Don't hide the starting window.
8557 continue;
8558 }
8559 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008560 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 "Setting visibility of " + win + ": " + (!clientHidden));
8562 win.mClient.dispatchAppVisibility(!clientHidden);
8563 } catch (RemoteException e) {
8564 }
8565 }
8566 }
Romain Guy06882f82009-06-10 13:36:04 -07008567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 void showAllWindowsLocked() {
8569 final int NW = allAppWindows.size();
8570 for (int i=0; i<NW; i++) {
8571 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008572 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573 "performing show on: " + w);
8574 w.performShowLocked();
8575 }
8576 }
Romain Guy06882f82009-06-10 13:36:04 -07008577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008578 // This must be called while inside a transaction.
8579 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008580 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008581 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583 if (animation == sDummyAnimation) {
8584 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008585 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 // when it is really time to animate, this will be set to
8587 // a real animation and the next call will execute normally.
8588 return false;
8589 }
Romain Guy06882f82009-06-10 13:36:04 -07008590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008591 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8592 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008593 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008594 TAG, "Starting animation in " + this +
8595 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8596 + " scale=" + mTransitionAnimationScale
8597 + " allDrawn=" + allDrawn + " animating=" + animating);
8598 animation.initialize(dw, dh, dw, dh);
8599 animation.setStartTime(currentTime);
8600 animating = true;
8601 }
8602 transformation.clear();
8603 final boolean more = animation.getTransformation(
8604 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008605 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 TAG, "Stepped animation in " + this +
8607 ": more=" + more + ", xform=" + transformation);
8608 if (more) {
8609 // we're done!
8610 hasTransformation = true;
8611 return true;
8612 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008613 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008614 TAG, "Finished animation in " + this +
8615 " @ " + currentTime);
8616 animation = null;
8617 }
8618 } else if (animation != null) {
8619 // If the display is frozen, and there is a pending animation,
8620 // clear it and make sure we run the cleanup code.
8621 animating = true;
8622 animation = null;
8623 }
8624
8625 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 if (!animating) {
8628 return false;
8629 }
8630
8631 clearAnimation();
8632 animating = false;
8633 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8634 moveInputMethodWindowsIfNeededLocked(true);
8635 }
Romain Guy06882f82009-06-10 13:36:04 -07008636
Joe Onorato8a9b2202010-02-26 18:56:32 -08008637 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 TAG, "Animation done in " + this
8639 + ": reportedVisible=" + reportedVisible);
8640
8641 transformation.clear();
8642 if (animLayerAdjustment != 0) {
8643 animLayerAdjustment = 0;
8644 updateLayers();
8645 }
Romain Guy06882f82009-06-10 13:36:04 -07008646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008647 final int N = windows.size();
8648 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008649 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008650 }
8651 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 return false;
8654 }
8655
8656 void updateReportedVisibilityLocked() {
8657 if (appToken == null) {
8658 return;
8659 }
Romain Guy06882f82009-06-10 13:36:04 -07008660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008661 int numInteresting = 0;
8662 int numVisible = 0;
8663 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008664
Joe Onorato8a9b2202010-02-26 18:56:32 -08008665 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008666 final int N = allAppWindows.size();
8667 for (int i=0; i<N; i++) {
8668 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008669 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008670 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008671 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8672 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 continue;
8674 }
8675 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008676 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008677 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008678 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008679 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008680 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 + " pv=" + win.mPolicyVisibility
8682 + " dp=" + win.mDrawPending
8683 + " cdp=" + win.mCommitDrawPending
8684 + " ah=" + win.mAttachedHidden
8685 + " th="
8686 + (win.mAppToken != null
8687 ? win.mAppToken.hiddenRequested : false)
8688 + " a=" + win.mAnimating);
8689 }
8690 }
8691 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008692 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 if (!win.isAnimating()) {
8694 numVisible++;
8695 }
8696 nowGone = false;
8697 } else if (win.isAnimating()) {
8698 nowGone = false;
8699 }
8700 }
Romain Guy06882f82009-06-10 13:36:04 -07008701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008702 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008703 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 + numInteresting + " visible=" + numVisible);
8705 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008706 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008707 TAG, "Visibility changed in " + this
8708 + ": vis=" + nowVisible);
8709 reportedVisible = nowVisible;
8710 Message m = mH.obtainMessage(
8711 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8712 nowVisible ? 1 : 0,
8713 nowGone ? 1 : 0,
8714 this);
8715 mH.sendMessage(m);
8716 }
8717 }
Romain Guy06882f82009-06-10 13:36:04 -07008718
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008719 WindowState findMainWindow() {
8720 int j = windows.size();
8721 while (j > 0) {
8722 j--;
8723 WindowState win = windows.get(j);
8724 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8725 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8726 return win;
8727 }
8728 }
8729 return null;
8730 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008732 void dump(PrintWriter pw, String prefix) {
8733 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008734 if (appToken != null) {
8735 pw.print(prefix); pw.println("app=true");
8736 }
8737 if (allAppWindows.size() > 0) {
8738 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8739 }
8740 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008741 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008742 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8743 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8744 pw.print(" clientHidden="); pw.print(clientHidden);
8745 pw.print(" willBeHidden="); pw.print(willBeHidden);
8746 pw.print(" reportedVisible="); pw.println(reportedVisible);
8747 if (paused || freezingScreen) {
8748 pw.print(prefix); pw.print("paused="); pw.print(paused);
8749 pw.print(" freezingScreen="); pw.println(freezingScreen);
8750 }
8751 if (numInterestingWindows != 0 || numDrawnWindows != 0
8752 || inPendingTransaction || allDrawn) {
8753 pw.print(prefix); pw.print("numInterestingWindows=");
8754 pw.print(numInterestingWindows);
8755 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8756 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8757 pw.print(" allDrawn="); pw.println(allDrawn);
8758 }
8759 if (animating || animation != null) {
8760 pw.print(prefix); pw.print("animating="); pw.print(animating);
8761 pw.print(" animation="); pw.println(animation);
8762 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008763 if (hasTransformation) {
8764 pw.print(prefix); pw.print("XForm: ");
8765 transformation.printShortString(pw);
8766 pw.println();
8767 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008768 if (animLayerAdjustment != 0) {
8769 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8770 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008771 if (startingData != null || removed || firstWindowDrawn) {
8772 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8773 pw.print(" removed="); pw.print(removed);
8774 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8775 }
8776 if (startingWindow != null || startingView != null
8777 || startingDisplayed || startingMoved) {
8778 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8779 pw.print(" startingView="); pw.print(startingView);
8780 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8781 pw.print(" startingMoved"); pw.println(startingMoved);
8782 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783 }
8784
8785 @Override
8786 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008787 if (stringName == null) {
8788 StringBuilder sb = new StringBuilder();
8789 sb.append("AppWindowToken{");
8790 sb.append(Integer.toHexString(System.identityHashCode(this)));
8791 sb.append(" token="); sb.append(token); sb.append('}');
8792 stringName = sb.toString();
8793 }
8794 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008795 }
8796 }
Romain Guy06882f82009-06-10 13:36:04 -07008797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008798 // -------------------------------------------------------------
8799 // DummyAnimation
8800 // -------------------------------------------------------------
8801
8802 // This is an animation that does nothing: it just immediately finishes
8803 // itself every time it is called. It is used as a stub animation in cases
8804 // where we want to synchronize multiple things that may be animating.
8805 static final class DummyAnimation extends Animation {
8806 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8807 return false;
8808 }
8809 }
8810 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008812 // -------------------------------------------------------------
8813 // Async Handler
8814 // -------------------------------------------------------------
8815
8816 static final class StartingData {
8817 final String pkg;
8818 final int theme;
8819 final CharSequence nonLocalizedLabel;
8820 final int labelRes;
8821 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008822 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008824 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008825 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008826 pkg = _pkg;
8827 theme = _theme;
8828 nonLocalizedLabel = _nonLocalizedLabel;
8829 labelRes = _labelRes;
8830 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008831 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008832 }
8833 }
8834
8835 private final class H extends Handler {
8836 public static final int REPORT_FOCUS_CHANGE = 2;
8837 public static final int REPORT_LOSING_FOCUS = 3;
8838 public static final int ANIMATE = 4;
8839 public static final int ADD_STARTING = 5;
8840 public static final int REMOVE_STARTING = 6;
8841 public static final int FINISHED_STARTING = 7;
8842 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008843 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8844 public static final int HOLD_SCREEN_CHANGED = 12;
8845 public static final int APP_TRANSITION_TIMEOUT = 13;
8846 public static final int PERSIST_ANIMATION_SCALE = 14;
8847 public static final int FORCE_GC = 15;
8848 public static final int ENABLE_SCREEN = 16;
8849 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008850 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008851 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008852 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008853 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008855 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008857 public H() {
8858 }
Romain Guy06882f82009-06-10 13:36:04 -07008859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008860 @Override
8861 public void handleMessage(Message msg) {
8862 switch (msg.what) {
8863 case REPORT_FOCUS_CHANGE: {
8864 WindowState lastFocus;
8865 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008867 synchronized(mWindowMap) {
8868 lastFocus = mLastFocus;
8869 newFocus = mCurrentFocus;
8870 if (lastFocus == newFocus) {
8871 // Focus is not changing, so nothing to do.
8872 return;
8873 }
8874 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008875 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008876 // + " to " + newFocus);
8877 if (newFocus != null && lastFocus != null
8878 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008879 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008880 mLosingFocus.add(lastFocus);
8881 lastFocus = null;
8882 }
8883 }
8884
8885 if (lastFocus != newFocus) {
8886 //System.out.println("Changing focus from " + lastFocus
8887 // + " to " + newFocus);
8888 if (newFocus != null) {
8889 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008890 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8892 } catch (RemoteException e) {
8893 // Ignore if process has died.
8894 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008895 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008896 }
8897
8898 if (lastFocus != null) {
8899 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008900 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8902 } catch (RemoteException e) {
8903 // Ignore if process has died.
8904 }
8905 }
Joe Onorato664644d2011-01-23 17:53:23 -08008906
8907 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008908 }
8909 } break;
8910
8911 case REPORT_LOSING_FOCUS: {
8912 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008914 synchronized(mWindowMap) {
8915 losers = mLosingFocus;
8916 mLosingFocus = new ArrayList<WindowState>();
8917 }
8918
8919 final int N = losers.size();
8920 for (int i=0; i<N; i++) {
8921 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008922 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008923 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8924 } catch (RemoteException e) {
8925 // Ignore if process has died.
8926 }
8927 }
8928 } break;
8929
8930 case ANIMATE: {
8931 synchronized(mWindowMap) {
8932 mAnimationPending = false;
8933 performLayoutAndPlaceSurfacesLocked();
8934 }
8935 } break;
8936
8937 case ADD_STARTING: {
8938 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8939 final StartingData sd = wtoken.startingData;
8940
8941 if (sd == null) {
8942 // Animation has been canceled... do nothing.
8943 return;
8944 }
Romain Guy06882f82009-06-10 13:36:04 -07008945
Joe Onorato8a9b2202010-02-26 18:56:32 -08008946 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008947 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008949 View view = null;
8950 try {
8951 view = mPolicy.addStartingWindow(
8952 wtoken.token, sd.pkg,
8953 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008954 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008955 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008956 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008957 }
8958
8959 if (view != null) {
8960 boolean abort = false;
8961
8962 synchronized(mWindowMap) {
8963 if (wtoken.removed || wtoken.startingData == null) {
8964 // If the window was successfully added, then
8965 // we need to remove it.
8966 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008967 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008968 "Aborted starting " + wtoken
8969 + ": removed=" + wtoken.removed
8970 + " startingData=" + wtoken.startingData);
8971 wtoken.startingWindow = null;
8972 wtoken.startingData = null;
8973 abort = true;
8974 }
8975 } else {
8976 wtoken.startingView = view;
8977 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008978 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008979 "Added starting " + wtoken
8980 + ": startingWindow="
8981 + wtoken.startingWindow + " startingView="
8982 + wtoken.startingView);
8983 }
8984
8985 if (abort) {
8986 try {
8987 mPolicy.removeStartingWindow(wtoken.token, view);
8988 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008989 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008990 }
8991 }
8992 }
8993 } break;
8994
8995 case REMOVE_STARTING: {
8996 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8997 IBinder token = null;
8998 View view = null;
8999 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009000 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 + wtoken + ": startingWindow="
9002 + wtoken.startingWindow + " startingView="
9003 + wtoken.startingView);
9004 if (wtoken.startingWindow != null) {
9005 view = wtoken.startingView;
9006 token = wtoken.token;
9007 wtoken.startingData = null;
9008 wtoken.startingView = null;
9009 wtoken.startingWindow = null;
9010 }
9011 }
9012 if (view != null) {
9013 try {
9014 mPolicy.removeStartingWindow(token, view);
9015 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009016 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009017 }
9018 }
9019 } break;
9020
9021 case FINISHED_STARTING: {
9022 IBinder token = null;
9023 View view = null;
9024 while (true) {
9025 synchronized (mWindowMap) {
9026 final int N = mFinishedStarting.size();
9027 if (N <= 0) {
9028 break;
9029 }
9030 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9031
Joe Onorato8a9b2202010-02-26 18:56:32 -08009032 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009033 "Finished starting " + wtoken
9034 + ": startingWindow=" + wtoken.startingWindow
9035 + " startingView=" + wtoken.startingView);
9036
9037 if (wtoken.startingWindow == null) {
9038 continue;
9039 }
9040
9041 view = wtoken.startingView;
9042 token = wtoken.token;
9043 wtoken.startingData = null;
9044 wtoken.startingView = null;
9045 wtoken.startingWindow = null;
9046 }
9047
9048 try {
9049 mPolicy.removeStartingWindow(token, view);
9050 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009051 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009052 }
9053 }
9054 } break;
9055
9056 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9057 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9058
9059 boolean nowVisible = msg.arg1 != 0;
9060 boolean nowGone = msg.arg2 != 0;
9061
9062 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009063 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009064 TAG, "Reporting visible in " + wtoken
9065 + " visible=" + nowVisible
9066 + " gone=" + nowGone);
9067 if (nowVisible) {
9068 wtoken.appToken.windowsVisible();
9069 } else {
9070 wtoken.appToken.windowsGone();
9071 }
9072 } catch (RemoteException ex) {
9073 }
9074 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009076 case WINDOW_FREEZE_TIMEOUT: {
9077 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009078 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009079 int i = mWindows.size();
9080 while (i > 0) {
9081 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009082 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009083 if (w.mOrientationChanging) {
9084 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009085 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009086 }
9087 }
9088 performLayoutAndPlaceSurfacesLocked();
9089 }
9090 break;
9091 }
Romain Guy06882f82009-06-10 13:36:04 -07009092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009093 case HOLD_SCREEN_CHANGED: {
9094 Session oldHold;
9095 Session newHold;
9096 synchronized (mWindowMap) {
9097 oldHold = mLastReportedHold;
9098 newHold = (Session)msg.obj;
9099 mLastReportedHold = newHold;
9100 }
Romain Guy06882f82009-06-10 13:36:04 -07009101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009102 if (oldHold != newHold) {
9103 try {
9104 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009105 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009106 "window",
9107 BatteryStats.WAKE_TYPE_WINDOW);
9108 }
9109 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009110 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009111 "window",
9112 BatteryStats.WAKE_TYPE_WINDOW);
9113 }
9114 } catch (RemoteException e) {
9115 }
9116 }
9117 break;
9118 }
Romain Guy06882f82009-06-10 13:36:04 -07009119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009120 case APP_TRANSITION_TIMEOUT: {
9121 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009122 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009123 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009124 "*** APP TRANSITION TIMEOUT");
9125 mAppTransitionReady = true;
9126 mAppTransitionTimeout = true;
9127 performLayoutAndPlaceSurfacesLocked();
9128 }
9129 }
9130 break;
9131 }
Romain Guy06882f82009-06-10 13:36:04 -07009132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009133 case PERSIST_ANIMATION_SCALE: {
9134 Settings.System.putFloat(mContext.getContentResolver(),
9135 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9136 Settings.System.putFloat(mContext.getContentResolver(),
9137 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9138 break;
9139 }
Romain Guy06882f82009-06-10 13:36:04 -07009140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141 case FORCE_GC: {
9142 synchronized(mWindowMap) {
9143 if (mAnimationPending) {
9144 // If we are animating, don't do the gc now but
9145 // delay a bit so we don't interrupt the animation.
9146 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9147 2000);
9148 return;
9149 }
9150 // If we are currently rotating the display, it will
9151 // schedule a new message when done.
9152 if (mDisplayFrozen) {
9153 return;
9154 }
9155 mFreezeGcPending = 0;
9156 }
9157 Runtime.getRuntime().gc();
9158 break;
9159 }
Romain Guy06882f82009-06-10 13:36:04 -07009160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009161 case ENABLE_SCREEN: {
9162 performEnableScreen();
9163 break;
9164 }
Romain Guy06882f82009-06-10 13:36:04 -07009165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009166 case APP_FREEZE_TIMEOUT: {
9167 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009168 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009169 int i = mAppTokens.size();
9170 while (i > 0) {
9171 i--;
9172 AppWindowToken tok = mAppTokens.get(i);
9173 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009174 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009175 unsetAppFreezingScreenLocked(tok, true, true);
9176 }
9177 }
9178 }
9179 break;
9180 }
Romain Guy06882f82009-06-10 13:36:04 -07009181
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009182 case SEND_NEW_CONFIGURATION: {
9183 removeMessages(SEND_NEW_CONFIGURATION);
9184 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009185 break;
9186 }
Romain Guy06882f82009-06-10 13:36:04 -07009187
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009188 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009189 if (mWindowsChanged) {
9190 synchronized (mWindowMap) {
9191 mWindowsChanged = false;
9192 }
9193 notifyWindowsChanged();
9194 }
9195 break;
9196 }
9197
Christopher Tatea53146c2010-09-07 11:57:52 -07009198 case DRAG_START_TIMEOUT: {
9199 IBinder win = (IBinder)msg.obj;
9200 if (DEBUG_DRAG) {
9201 Slog.w(TAG, "Timeout starting drag by win " + win);
9202 }
9203 synchronized (mWindowMap) {
9204 // !!! TODO: ANR the app that has failed to start the drag in time
9205 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009206 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009207 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009208 mDragState.reset();
9209 mDragState = null;
9210 }
9211 }
Chris Tated4533f142010-10-19 15:15:08 -07009212 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009213 }
9214
Chris Tated4533f142010-10-19 15:15:08 -07009215 case DRAG_END_TIMEOUT: {
9216 IBinder win = (IBinder)msg.obj;
9217 if (DEBUG_DRAG) {
9218 Slog.w(TAG, "Timeout ending drag to win " + win);
9219 }
9220 synchronized (mWindowMap) {
9221 // !!! TODO: ANR the drag-receiving app
9222 mDragState.mDragResult = false;
9223 mDragState.endDragLw();
9224 }
9225 break;
9226 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009227 }
9228 }
9229 }
9230
9231 // -------------------------------------------------------------
9232 // IWindowManager API
9233 // -------------------------------------------------------------
9234
9235 public IWindowSession openSession(IInputMethodClient client,
9236 IInputContext inputContext) {
9237 if (client == null) throw new IllegalArgumentException("null client");
9238 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009239 Session session = new Session(client, inputContext);
9240 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009241 }
9242
9243 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9244 synchronized (mWindowMap) {
9245 // The focus for the client is the window immediately below
9246 // where we would place the input method window.
9247 int idx = findDesiredInputMethodWindowIndexLocked(false);
9248 WindowState imFocus;
9249 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009250 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009251 if (imFocus != null) {
9252 if (imFocus.mSession.mClient != null &&
9253 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9254 return true;
9255 }
9256 }
9257 }
9258 }
9259 return false;
9260 }
Romain Guy06882f82009-06-10 13:36:04 -07009261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 // -------------------------------------------------------------
9263 // Internals
9264 // -------------------------------------------------------------
9265
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009266 final WindowState windowForClientLocked(Session session, IWindow client,
9267 boolean throwOnError) {
9268 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009269 }
Romain Guy06882f82009-06-10 13:36:04 -07009270
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009271 final WindowState windowForClientLocked(Session session, IBinder client,
9272 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009273 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009274 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009275 TAG, "Looking up client " + client + ": " + win);
9276 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009277 RuntimeException ex = new IllegalArgumentException(
9278 "Requested window " + client + " does not exist");
9279 if (throwOnError) {
9280 throw ex;
9281 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009282 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 return null;
9284 }
9285 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009286 RuntimeException ex = new IllegalArgumentException(
9287 "Requested window " + client + " is in session " +
9288 win.mSession + ", not " + session);
9289 if (throwOnError) {
9290 throw ex;
9291 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009292 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009293 return null;
9294 }
9295
9296 return win;
9297 }
9298
Dianne Hackborna8f60182009-09-01 19:01:50 -07009299 final void rebuildAppWindowListLocked() {
9300 int NW = mWindows.size();
9301 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009302 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009303 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009304
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009305 if (mRebuildTmp.length < NW) {
9306 mRebuildTmp = new WindowState[NW+10];
9307 }
9308
Dianne Hackborna8f60182009-09-01 19:01:50 -07009309 // First remove all existing app windows.
9310 i=0;
9311 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009312 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009313 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009314 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009315 win.mRebuilding = true;
9316 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009317 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009318 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009319 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009320 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009321 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009322 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009323 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9324 && lastWallpaper == i-1) {
9325 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009326 }
9327 i++;
9328 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009329
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009330 // The wallpaper window(s) typically live at the bottom of the stack,
9331 // so skip them before adding app tokens.
9332 lastWallpaper++;
9333 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009334
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009335 // First add all of the exiting app tokens... these are no longer
9336 // in the main app list, but still have windows shown. We put them
9337 // in the back because now that the animation is over we no longer
9338 // will care about them.
9339 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009340 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009341 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9342 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009343
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009344 // And add in the still active app tokens in Z order.
9345 NT = mAppTokens.size();
9346 for (int j=0; j<NT; j++) {
9347 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009348 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009349
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009350 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009351 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009352 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009353 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009354 for (i=0; i<numRemoved; i++) {
9355 WindowState ws = mRebuildTmp[i];
9356 if (ws.mRebuilding) {
9357 StringWriter sw = new StringWriter();
9358 PrintWriter pw = new PrintWriter(sw);
9359 ws.dump(pw, "");
9360 pw.flush();
9361 Slog.w(TAG, "This window was lost: " + ws);
9362 Slog.w(TAG, sw.toString());
9363 }
9364 }
9365 Slog.w(TAG, "Current app token list:");
9366 dumpAppTokensLocked();
9367 Slog.w(TAG, "Final window list:");
9368 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009369 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009370 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009372 private final void assignLayersLocked() {
9373 int N = mWindows.size();
9374 int curBaseLayer = 0;
9375 int curLayer = 0;
9376 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009377
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009378 if (DEBUG_LAYERS) {
9379 RuntimeException here = new RuntimeException("here");
9380 here.fillInStackTrace();
9381 Log.v(TAG, "Assigning layers", here);
9382 }
9383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009385 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009386 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9387 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009388 curLayer += WINDOW_LAYER_MULTIPLIER;
9389 w.mLayer = curLayer;
9390 } else {
9391 curBaseLayer = curLayer = w.mBaseLayer;
9392 w.mLayer = curLayer;
9393 }
9394 if (w.mTargetAppToken != null) {
9395 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9396 } else if (w.mAppToken != null) {
9397 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9398 } else {
9399 w.mAnimLayer = w.mLayer;
9400 }
9401 if (w.mIsImWindow) {
9402 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009403 } else if (w.mIsWallpaper) {
9404 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009405 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009406 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 + w.mAnimLayer);
9408 //System.out.println(
9409 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9410 }
9411 }
9412
9413 private boolean mInLayout = false;
9414 private final void performLayoutAndPlaceSurfacesLocked() {
9415 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009416 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 throw new RuntimeException("Recursive call!");
9418 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009419 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009420 return;
9421 }
9422
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009423 if (mWaitingForConfig) {
9424 // Our configuration has changed (most likely rotation), but we
9425 // don't yet have the complete configuration to report to
9426 // applications. Don't do any window layout until we have it.
9427 return;
9428 }
9429
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009430 if (mDisplay == null) {
9431 // Not yet initialized, nothing to do.
9432 return;
9433 }
9434
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009435 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009436 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009437
9438 try {
9439 if (mForceRemoves != null) {
9440 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009441 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009442 for (int i=0; i<mForceRemoves.size(); i++) {
9443 WindowState ws = mForceRemoves.get(i);
9444 Slog.i(TAG, "Force removing: " + ws);
9445 removeWindowInnerLocked(ws.mSession, ws);
9446 }
9447 mForceRemoves = null;
9448 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9449 Object tmp = new Object();
9450 synchronized (tmp) {
9451 try {
9452 tmp.wait(250);
9453 } catch (InterruptedException e) {
9454 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009455 }
9456 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009457 } catch (RuntimeException e) {
9458 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009459 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009461 try {
9462 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009463
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009464 int N = mPendingRemove.size();
9465 if (N > 0) {
9466 if (mPendingRemoveTmp.length < N) {
9467 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009468 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009469 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009470 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009471 for (int i=0; i<N; i++) {
9472 WindowState w = mPendingRemoveTmp[i];
9473 removeWindowInnerLocked(w.mSession, w);
9474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009475
9476 mInLayout = false;
9477 assignLayersLocked();
9478 mLayoutNeeded = true;
9479 performLayoutAndPlaceSurfacesLocked();
9480
9481 } else {
9482 mInLayout = false;
9483 if (mLayoutNeeded) {
9484 requestAnimationLocked(0);
9485 }
9486 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009487 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009488 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9489 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 } catch (RuntimeException e) {
9492 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009493 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494 }
9495 }
9496
Jeff Brown3a22cd92011-01-21 13:59:04 -08009497 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009498 if (!mLayoutNeeded) {
9499 return 0;
9500 }
9501
9502 mLayoutNeeded = false;
9503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009504 final int dw = mDisplay.getWidth();
9505 final int dh = mDisplay.getHeight();
9506
9507 final int N = mWindows.size();
9508 int i;
9509
Joe Onorato8a9b2202010-02-26 18:56:32 -08009510 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009511 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9512
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009513 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009514
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009515 int seq = mLayoutSeq+1;
9516 if (seq < 0) seq = 0;
9517 mLayoutSeq = seq;
9518
9519 // First perform layout of any root windows (not attached
9520 // to another window).
9521 int topAttached = -1;
9522 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009523 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009524
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009525 // Don't do layout of a window if it is not visible, or
9526 // soon won't be visible, to avoid wasting time and funky
9527 // changes while a window is animating away.
9528 final AppWindowToken atoken = win.mAppToken;
9529 final boolean gone = win.mViewVisibility == View.GONE
9530 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009531 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009532 || (atoken != null && atoken.hiddenRequested)
9533 || win.mAttachedHidden
9534 || win.mExiting || win.mDestroying;
9535
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009536 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9537 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009538 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9539 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009540 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009541 + win.mViewVisibility + " mRelayoutCalled="
9542 + win.mRelayoutCalled + " hidden="
9543 + win.mRootToken.hidden + " hiddenRequested="
9544 + (atoken != null && atoken.hiddenRequested)
9545 + " mAttachedHidden=" + win.mAttachedHidden);
9546 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009547
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009548 // If this view is GONE, then skip it -- keep the current
9549 // frame, and let the caller know so they can ignore it
9550 // if they want. (We do the normal layout for INVISIBLE
9551 // windows, since that means "perform layout as normal,
9552 // just don't display").
9553 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009554 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009555 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009556 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009557 win.mContentChanged = false;
9558 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009559 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9560 win.mLayoutSeq = seq;
9561 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9562 + win.mFrame + " mContainingFrame="
9563 + win.mContainingFrame + " mDisplayFrame="
9564 + win.mDisplayFrame);
9565 } else {
9566 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009567 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009569 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009570
9571 // Now perform layout of attached windows, which usually
9572 // depend on the position of the window they are attached to.
9573 // XXX does not deal with windows that are attached to windows
9574 // that are themselves attached.
9575 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009576 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009577
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009578 if (win.mLayoutAttached) {
9579 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9580 + " mHaveFrame=" + win.mHaveFrame
9581 + " mViewVisibility=" + win.mViewVisibility
9582 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009583 // If this view is GONE, then skip it -- keep the current
9584 // frame, and let the caller know so they can ignore it
9585 // if they want. (We do the normal layout for INVISIBLE
9586 // windows, since that means "perform layout as normal,
9587 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009588 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9589 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009590 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009591 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009592 win.mContentChanged = false;
9593 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009594 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9595 win.mLayoutSeq = seq;
9596 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9597 + win.mFrame + " mContainingFrame="
9598 + win.mContainingFrame + " mDisplayFrame="
9599 + win.mDisplayFrame);
9600 }
9601 }
9602 }
Jeff Brown349703e2010-06-22 01:27:15 -07009603
9604 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009605 mInputMonitor.setUpdateInputWindowsNeededLw();
9606 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009607 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009608 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009609
9610 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009611 }
Romain Guy06882f82009-06-10 13:36:04 -07009612
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009613 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009614 private final void performLayoutAndPlaceSurfacesLockedInner(
9615 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009616 if (mDisplay == null) {
9617 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9618 return;
9619 }
9620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009621 final long currentTime = SystemClock.uptimeMillis();
9622 final int dw = mDisplay.getWidth();
9623 final int dh = mDisplay.getHeight();
9624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009625 int i;
9626
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009627 if (mFocusMayChange) {
9628 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009629 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9630 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009631 }
9632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633 // Initialize state of exiting tokens.
9634 for (i=mExitingTokens.size()-1; i>=0; i--) {
9635 mExitingTokens.get(i).hasVisible = false;
9636 }
9637
9638 // Initialize state of exiting applications.
9639 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9640 mExitingAppTokens.get(i).hasVisible = false;
9641 }
9642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009643 boolean orientationChangeComplete = true;
9644 Session holdScreen = null;
9645 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009646 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009647 boolean focusDisplayed = false;
9648 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009649 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009650 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009651
9652 if (mFxSession == null) {
9653 mFxSession = new SurfaceSession();
9654 createWatermark = true;
9655 }
9656
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009657 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009658
9659 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009660
9661 if (createWatermark) {
9662 createWatermark();
9663 }
9664 if (mWatermark != null) {
9665 mWatermark.positionSurface(dw, dh);
9666 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009667 if (mStrictModeFlash != null) {
9668 mStrictModeFlash.positionSurface(dw, dh);
9669 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009671 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009672 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009673 int repeats = 0;
9674 int changes = 0;
9675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009676 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009677 repeats++;
9678 if (repeats > 6) {
9679 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9680 mLayoutNeeded = false;
9681 break;
9682 }
9683
9684 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9685 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9686 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9687 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9688 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9689 assignLayersLocked();
9690 mLayoutNeeded = true;
9691 }
9692 }
9693 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9694 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009695 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009696 mLayoutNeeded = true;
9697 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9698 }
9699 }
9700 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9701 mLayoutNeeded = true;
9702 }
9703 }
9704
9705 // FIRST LOOP: Perform a layout, if needed.
9706 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009707 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009708 if (changes != 0) {
9709 continue;
9710 }
9711 } else {
9712 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9713 changes = 0;
9714 }
9715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009716 final int transactionSequence = ++mTransactionSequence;
9717
9718 // Update animations of all applications, including those
9719 // associated with exiting/removed apps
9720 boolean tokensAnimating = false;
9721 final int NAT = mAppTokens.size();
9722 for (i=0; i<NAT; i++) {
9723 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9724 tokensAnimating = true;
9725 }
9726 }
9727 final int NEAT = mExitingAppTokens.size();
9728 for (i=0; i<NEAT; i++) {
9729 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9730 tokensAnimating = true;
9731 }
9732 }
9733
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009734 // SECOND LOOP: Execute animations and update visibility of windows.
9735
Joe Onorato8a9b2202010-02-26 18:56:32 -08009736 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009737 + transactionSequence + " tokensAnimating="
9738 + tokensAnimating);
9739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009740 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009742 if (mScreenRotationAnimation != null) {
9743 if (mScreenRotationAnimation.isAnimating()) {
9744 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9745 animating = true;
9746 } else {
9747 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009748 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009749 }
9750 }
9751 }
9752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009754 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009755 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009756 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009757
9758 mPolicy.beginAnimationLw(dw, dh);
9759
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009760 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009762 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009763 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764
9765 final WindowManager.LayoutParams attrs = w.mAttrs;
9766
9767 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009768 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009769 if (w.commitFinishDrawingLocked(currentTime)) {
9770 if ((w.mAttrs.flags
9771 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009772 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009773 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009774 wallpaperMayChange = true;
9775 }
9776 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009777
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009778 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009779
9780 int animDw = dw;
9781 int animDh = dh;
9782
9783 // If the window has moved due to its containing
9784 // content frame changing, then we'd like to animate
9785 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009786 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009787 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009788 // Frame has moved, containing content frame
9789 // has also moved, and we're not currently animating...
9790 // let's do something.
9791 Animation a = AnimationUtils.loadAnimation(mContext,
9792 com.android.internal.R.anim.window_move_from_decor);
9793 w.setAnimation(a);
9794 animDw = w.mLastFrame.left - w.mFrame.left;
9795 animDh = w.mLastFrame.top - w.mFrame.top;
9796 }
9797
9798 // Execute animation.
9799 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9800 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009801
9802 // If this window is animating, make a note that we have
9803 // an animating window and take care of a request to run
9804 // a detached wallpaper animation.
9805 if (nowAnimating) {
9806 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9807 windowDetachedWallpaper = w;
9808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009809 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009810 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009811
9812 // If this window's app token is running a detached wallpaper
9813 // animation, make a note so we can ensure the wallpaper is
9814 // displayed behind it.
9815 if (w.mAppToken != null && w.mAppToken.animation != null
9816 && w.mAppToken.animation.getDetachWallpaper()) {
9817 windowDetachedWallpaper = w;
9818 }
9819
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009820 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9821 wallpaperMayChange = true;
9822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009823
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009824 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009825 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009826 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009827 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009828 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009829 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009830 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009831 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9832 forceHiding = true;
9833 }
9834 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9835 boolean changed;
9836 if (forceHiding) {
9837 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009838 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9839 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009840 } else {
9841 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009842 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9843 "Now policy shown: " + w);
9844 if (changed) {
9845 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009846 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009847 // Assume we will need to animate. If
9848 // we don't (because the wallpaper will
9849 // stay with the lock screen), then we will
9850 // clean up later.
9851 Animation a = mPolicy.createForceHideEnterAnimation();
9852 if (a != null) {
9853 w.setAnimation(a);
9854 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009855 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009856 if (mCurrentFocus == null ||
9857 mCurrentFocus.mLayer < w.mLayer) {
9858 // We are showing on to of the current
9859 // focus, so re-evaluate focus to make
9860 // sure it is correct.
9861 mFocusMayChange = true;
9862 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009863 }
9864 }
9865 if (changed && (attrs.flags
9866 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9867 wallpaperMayChange = true;
9868 }
9869 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009871 mPolicy.animatingWindowLw(w, attrs);
9872 }
9873
9874 final AppWindowToken atoken = w.mAppToken;
9875 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9876 if (atoken.lastTransactionSequence != transactionSequence) {
9877 atoken.lastTransactionSequence = transactionSequence;
9878 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9879 atoken.startingDisplayed = false;
9880 }
9881 if ((w.isOnScreen() || w.mAttrs.type
9882 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9883 && !w.mExiting && !w.mDestroying) {
9884 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009885 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009886 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009888 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009889 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009890 + " pv=" + w.mPolicyVisibility
9891 + " dp=" + w.mDrawPending
9892 + " cdp=" + w.mCommitDrawPending
9893 + " ah=" + w.mAttachedHidden
9894 + " th=" + atoken.hiddenRequested
9895 + " a=" + w.mAnimating);
9896 }
9897 }
9898 if (w != atoken.startingWindow) {
9899 if (!atoken.freezingScreen || !w.mAppFreezing) {
9900 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009901 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009903 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009904 "tokenMayBeDrawn: " + atoken
9905 + " freezingScreen=" + atoken.freezingScreen
9906 + " mAppFreezing=" + w.mAppFreezing);
9907 tokenMayBeDrawn = true;
9908 }
9909 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009910 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009911 atoken.startingDisplayed = true;
9912 }
9913 }
9914 } else if (w.mReadyToShow) {
9915 w.performShowLocked();
9916 }
9917 }
9918
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009919 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009920
9921 if (tokenMayBeDrawn) {
9922 // See if any windows have been drawn, so they (and others
9923 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009924 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009925 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009926 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009927 if (wtoken.freezingScreen) {
9928 int numInteresting = wtoken.numInterestingWindows;
9929 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009930 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009931 "allDrawn: " + wtoken
9932 + " interesting=" + numInteresting
9933 + " drawn=" + wtoken.numDrawnWindows);
9934 wtoken.showAllWindowsLocked();
9935 unsetAppFreezingScreenLocked(wtoken, false, true);
9936 orientationChangeComplete = true;
9937 }
9938 } else if (!wtoken.allDrawn) {
9939 int numInteresting = wtoken.numInterestingWindows;
9940 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009941 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009942 "allDrawn: " + wtoken
9943 + " interesting=" + numInteresting
9944 + " drawn=" + wtoken.numDrawnWindows);
9945 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009946 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009947
9948 // We can now show all of the drawn windows!
9949 if (!mOpeningApps.contains(wtoken)) {
9950 wtoken.showAllWindowsLocked();
9951 }
9952 }
9953 }
9954 }
9955 }
9956
9957 // If we are ready to perform an app transition, check through
9958 // all of the app tokens to be shown and see if they are ready
9959 // to go.
9960 if (mAppTransitionReady) {
9961 int NN = mOpeningApps.size();
9962 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009963 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009964 "Checking " + NN + " opening apps (frozen="
9965 + mDisplayFrozen + " timeout="
9966 + mAppTransitionTimeout + ")...");
9967 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9968 // If the display isn't frozen, wait to do anything until
9969 // all of the apps are ready. Otherwise just go because
9970 // we'll unfreeze the display when everyone is ready.
9971 for (i=0; i<NN && goodToGo; i++) {
9972 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009973 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009974 "Check opening app" + wtoken + ": allDrawn="
9975 + wtoken.allDrawn + " startingDisplayed="
9976 + wtoken.startingDisplayed);
9977 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9978 && !wtoken.startingMoved) {
9979 goodToGo = false;
9980 }
9981 }
9982 }
9983 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009984 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009985 int transit = mNextAppTransition;
9986 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009987 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009988 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009989 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009990 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009991 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 mAppTransitionTimeout = false;
9993 mStartingIconInTransition = false;
9994 mSkipAppTransitionAnimation = false;
9995
9996 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9997
Dianne Hackborna8f60182009-09-01 19:01:50 -07009998 // If there are applications waiting to come to the
9999 // top of the stack, now is the time to move their windows.
10000 // (Note that we don't do apps going to the bottom
10001 // here -- we want to keep their windows in the old
10002 // Z-order until the animation completes.)
10003 if (mToTopApps.size() > 0) {
10004 NN = mAppTokens.size();
10005 for (i=0; i<NN; i++) {
10006 AppWindowToken wtoken = mAppTokens.get(i);
10007 if (wtoken.sendingToTop) {
10008 wtoken.sendingToTop = false;
10009 moveAppWindowsLocked(wtoken, NN, false);
10010 }
10011 }
10012 mToTopApps.clear();
10013 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010014
Dianne Hackborn25994b42009-09-04 14:21:19 -070010015 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010016
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010017 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010018 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010019
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010020 // The top-most window will supply the layout params,
10021 // and we will determine it below.
10022 LayoutParams animLp = null;
10023 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010024 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010025
Joe Onorato8a9b2202010-02-26 18:56:32 -080010026 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010027 "New wallpaper target=" + mWallpaperTarget
10028 + ", lower target=" + mLowerWallpaperTarget
10029 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010030 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010031 // Do a first pass through the tokens for two
10032 // things:
10033 // (1) Determine if both the closing and opening
10034 // app token sets are wallpaper targets, in which
10035 // case special animations are needed
10036 // (since the wallpaper needs to stay static
10037 // behind them).
10038 // (2) Find the layout params of the top-most
10039 // application window in the tokens, which is
10040 // what will control the animation theme.
10041 final int NC = mClosingApps.size();
10042 NN = NC + mOpeningApps.size();
10043 for (i=0; i<NN; i++) {
10044 AppWindowToken wtoken;
10045 int mode;
10046 if (i < NC) {
10047 wtoken = mClosingApps.get(i);
10048 mode = 1;
10049 } else {
10050 wtoken = mOpeningApps.get(i-NC);
10051 mode = 2;
10052 }
10053 if (mLowerWallpaperTarget != null) {
10054 if (mLowerWallpaperTarget.mAppToken == wtoken
10055 || mUpperWallpaperTarget.mAppToken == wtoken) {
10056 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010057 }
10058 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010059 if (wtoken.appFullscreen) {
10060 WindowState ws = wtoken.findMainWindow();
10061 if (ws != null) {
10062 // If this is a compatibility mode
10063 // window, we will always use its anim.
10064 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10065 animLp = ws.mAttrs;
10066 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010067 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010068 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010069 bestAnimLayer = ws.mLayer;
10070 }
10071 fullscreenAnim = true;
10072 }
10073 } else if (!fullscreenAnim) {
10074 WindowState ws = wtoken.findMainWindow();
10075 if (ws != null) {
10076 if (ws.mLayer > bestAnimLayer) {
10077 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010078 bestAnimLayer = ws.mLayer;
10079 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010080 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010081 }
10082 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010083
Dianne Hackborn25994b42009-09-04 14:21:19 -070010084 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010085 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010086 "Wallpaper animation!");
10087 switch (transit) {
10088 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10089 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10090 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10091 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10092 break;
10093 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10094 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10095 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10096 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10097 break;
10098 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010099 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010100 "New transit: " + transit);
10101 } else if (oldWallpaper != null) {
10102 // We are transitioning from an activity with
10103 // a wallpaper to one without.
10104 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010105 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010106 "New transit away from wallpaper: " + transit);
10107 } else if (mWallpaperTarget != null) {
10108 // We are transitioning from an activity without
10109 // a wallpaper to now showing the wallpaper
10110 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010111 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010112 "New transit into wallpaper: " + transit);
10113 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010114
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010115 // If all closing windows are obscured, then there is
10116 // no need to do an animation. This is the case, for
10117 // example, when this transition is being done behind
10118 // the lock screen.
10119 if (!mPolicy.allowAppAnimationsLw()) {
10120 animLp = null;
10121 }
10122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 NN = mOpeningApps.size();
10124 for (i=0; i<NN; i++) {
10125 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010126 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010127 "Now opening app" + wtoken);
10128 wtoken.reportedVisible = false;
10129 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010130 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010131 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010132 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010133 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010134 wtoken.showAllWindowsLocked();
10135 }
10136 NN = mClosingApps.size();
10137 for (i=0; i<NN; i++) {
10138 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010139 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010140 "Now closing app" + wtoken);
10141 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010142 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010143 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010145 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010146 // Force the allDrawn flag, because we want to start
10147 // this guy's animations regardless of whether it's
10148 // gotten drawn.
10149 wtoken.allDrawn = true;
10150 }
10151
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010152 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010154 mOpeningApps.clear();
10155 mClosingApps.clear();
10156
10157 // This has changed the visibility of windows, so perform
10158 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010159 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10160 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010161 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010162 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10163 assignLayersLocked();
10164 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010165 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10166 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010167 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010168 }
10169 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010170
Dianne Hackborn16064f92010-03-25 00:47:24 -070010171 int adjResult = 0;
10172
Dianne Hackborna8f60182009-09-01 19:01:50 -070010173 if (!animating && mAppTransitionRunning) {
10174 // We have finished the animation of an app transition. To do
10175 // this, we have delayed a lot of operations like showing and
10176 // hiding apps, moving apps in Z-order, etc. The app token list
10177 // reflects the correct Z-order, but the window list may now
10178 // be out of sync with it. So here we will just rebuild the
10179 // entire app window list. Fun!
10180 mAppTransitionRunning = false;
10181 // Clear information about apps that were moving.
10182 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010183
Dianne Hackborna8f60182009-09-01 19:01:50 -070010184 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010185 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010186 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010187 moveInputMethodWindowsIfNeededLocked(false);
10188 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010189 // Since the window list has been rebuilt, focus might
10190 // have to be recomputed since the actual order of windows
10191 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010192 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010193 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010194
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010195 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010196 // At this point, there was a window with a wallpaper that
10197 // was force hiding other windows behind it, but now it
10198 // is going away. This may be simple -- just animate
10199 // away the wallpaper and its window -- or it may be
10200 // hard -- the wallpaper now needs to be shown behind
10201 // something that was hidden.
10202 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010203 if (mLowerWallpaperTarget != null
10204 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010205 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010206 "wallpaperForceHiding changed with lower="
10207 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010208 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010209 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10210 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10211 if (mLowerWallpaperTarget.mAppToken.hidden) {
10212 // The lower target has become hidden before we
10213 // actually started the animation... let's completely
10214 // re-evaluate everything.
10215 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010216 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010217 }
10218 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010219 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010220 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010221 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010222 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010223 + " NEW: " + mWallpaperTarget
10224 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010225 if (mLowerWallpaperTarget == null) {
10226 // Whoops, we don't need a special wallpaper animation.
10227 // Clear them out.
10228 forceHiding = false;
10229 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010230 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010231 if (w.mSurface != null) {
10232 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010233 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010234 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010235 forceHiding = true;
10236 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10237 if (!w.mAnimating) {
10238 // We set the animation above so it
10239 // is not yet running.
10240 w.clearAnimation();
10241 }
10242 }
10243 }
10244 }
10245 }
10246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010247
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010248 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10249 if (DEBUG_WALLPAPER) Slog.v(TAG,
10250 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10251 + windowDetachedWallpaper);
10252 mWindowDetachedWallpaper = windowDetachedWallpaper;
10253 wallpaperMayChange = true;
10254 }
10255
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010256 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010257 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010258 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010259 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010260 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010261
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010262 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010263 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010264 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010265 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010266 assignLayersLocked();
10267 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010268 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010269 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010270 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010272
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010273 if (mFocusMayChange) {
10274 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010275 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10276 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010277 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010278 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010279 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010280 }
10281
10282 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010283 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010284 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010285
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010286 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10287 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010288 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289
10290 // THIRD LOOP: Update the surfaces of all windows.
10291
10292 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10293
10294 boolean obscured = false;
10295 boolean blurring = false;
10296 boolean dimming = false;
10297 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010298 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010299 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010300
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010301 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010303 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010304 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010305
10306 boolean displayed = false;
10307 final WindowManager.LayoutParams attrs = w.mAttrs;
10308 final int attrFlags = attrs.flags;
10309
10310 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010311 // XXX NOTE: The logic here could be improved. We have
10312 // the decision about whether to resize a window separated
10313 // from whether to hide the surface. This can cause us to
10314 // resize a surface even if we are going to hide it. You
10315 // can see this by (1) holding device in landscape mode on
10316 // home screen; (2) tapping browser icon (device will rotate
10317 // to landscape; (3) tap home. The wallpaper will be resized
10318 // in step 2 but then immediately hidden, causing us to
10319 // have to resize and then redraw it again in step 3. It
10320 // would be nice to figure out how to avoid this, but it is
10321 // difficult because we do need to resize surfaces in some
10322 // cases while they are hidden such as when first showing a
10323 // window.
10324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010325 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010326 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 TAG, "Placing surface #" + i + " " + w.mSurface
10328 + ": new=" + w.mShownFrame + ", old="
10329 + w.mLastShownFrame);
10330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010331 int width, height;
10332 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010333 // for a scaled surface, we just want to use
10334 // the requested size.
10335 width = w.mRequestedWidth;
10336 height = w.mRequestedHeight;
10337 w.mLastRequestedWidth = width;
10338 w.mLastRequestedHeight = height;
10339 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010340 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010341 width = w.mShownFrame.width();
10342 height = w.mShownFrame.height();
10343 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010344 }
10345
Jeff Brownfbae7222011-01-23 13:07:25 -080010346 if (w.mSurface != null) {
10347 if (w.mSurfaceX != w.mShownFrame.left
10348 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010349 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010350 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010351 "POS " + w.mShownFrame.left
10352 + ", " + w.mShownFrame.top, null);
10353 w.mSurfaceX = w.mShownFrame.left;
10354 w.mSurfaceY = w.mShownFrame.top;
10355 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10356 } catch (RuntimeException e) {
10357 Slog.w(TAG, "Error positioning surface of " + w
10358 + " pos=(" + w.mShownFrame.left
10359 + "," + w.mShownFrame.top + ")", e);
10360 if (!recoveringMemory) {
10361 reclaimSomeSurfaceMemoryLocked(w, "position");
10362 }
10363 }
10364 }
10365
10366 if (width < 1) {
10367 width = 1;
10368 }
10369 if (height < 1) {
10370 height = 1;
10371 }
10372
10373 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10374 try {
10375 if (SHOW_TRANSACTIONS) logSurface(w,
10376 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010377 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010378 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010379 w.mSurfaceW = width;
10380 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010381 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010382 } catch (RuntimeException e) {
10383 // If something goes wrong with the surface (such
10384 // as running out of memory), don't take down the
10385 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010386 Slog.e(TAG, "Error resizing surface of " + w
10387 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010388 if (!recoveringMemory) {
10389 reclaimSomeSurfaceMemoryLocked(w, "size");
10390 }
10391 }
10392 }
10393 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010394
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010395 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010396 w.mContentInsetsChanged =
10397 !w.mLastContentInsets.equals(w.mContentInsets);
10398 w.mVisibleInsetsChanged =
10399 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010400 boolean configChanged =
10401 w.mConfiguration != mCurConfiguration
10402 && (w.mConfiguration == null
10403 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010404 if (DEBUG_CONFIGURATION && configChanged) {
10405 Slog.v(TAG, "Win " + w + " config changed: "
10406 + mCurConfiguration);
10407 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010408 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010409 + ": configChanged=" + configChanged
10410 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010411 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10412 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010414 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010415 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010416 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010417 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10418 Slog.v(TAG, "Resize reasons: "
10419 + "frameChanged=" + frameChanged
10420 + " contentInsetsChanged=" + w.mContentInsetsChanged
10421 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10422 + " surfaceResized=" + w.mSurfaceResized
10423 + " configChanged=" + configChanged);
10424 }
10425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010426 w.mLastFrame.set(w.mFrame);
10427 w.mLastContentInsets.set(w.mContentInsets);
10428 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010429 // If the screen is currently frozen, then keep
10430 // it frozen until this window draws at its new
10431 // orientation.
10432 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010433 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010434 "Resizing while display frozen: " + w);
10435 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010436 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010437 mWindowsFreezingScreen = true;
10438 // XXX should probably keep timeout from
10439 // when we first froze the display.
10440 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10441 mH.sendMessageDelayed(mH.obtainMessage(
10442 H.WINDOW_FREEZE_TIMEOUT), 2000);
10443 }
10444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010445 // If the orientation is changing, then we need to
10446 // hold off on unfreezing the display until this
10447 // window has been redrawn; to do that, we need
10448 // to go through the process of getting informed
10449 // by the application when it has finished drawing.
10450 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010451 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 "Orientation start waiting for draw in "
10453 + w + ", surface " + w.mSurface);
10454 w.mDrawPending = true;
10455 w.mCommitDrawPending = false;
10456 w.mReadyToShow = false;
10457 if (w.mAppToken != null) {
10458 w.mAppToken.allDrawn = false;
10459 }
10460 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010461 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010462 "Resizing window " + w + " to " + w.mFrame);
10463 mResizingWindows.add(w);
10464 } else if (w.mOrientationChanging) {
10465 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010466 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010467 "Orientation not waiting for draw in "
10468 + w + ", surface " + w.mSurface);
10469 w.mOrientationChanging = false;
10470 }
10471 }
10472 }
10473
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010474 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 if (!w.mLastHidden) {
10476 //dump();
10477 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010478 if (SHOW_TRANSACTIONS) logSurface(w,
10479 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010480 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010481 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010482 try {
10483 w.mSurface.hide();
10484 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010485 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010486 }
10487 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010488 }
10489 // If we are waiting for this window to handle an
10490 // orientation change, well, it is hidden, so
10491 // doesn't really matter. Note that this does
10492 // introduce a potential glitch if the window
10493 // becomes unhidden before it has drawn for the
10494 // new orientation.
10495 if (w.mOrientationChanging) {
10496 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010497 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010498 "Orientation change skips hidden " + w);
10499 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010500 } else if (w.mLastLayer != w.mAnimLayer
10501 || w.mLastAlpha != w.mShownAlpha
10502 || w.mLastDsDx != w.mDsDx
10503 || w.mLastDtDx != w.mDtDx
10504 || w.mLastDsDy != w.mDsDy
10505 || w.mLastDtDy != w.mDtDy
10506 || w.mLastHScale != w.mHScale
10507 || w.mLastVScale != w.mVScale
10508 || w.mLastHidden) {
10509 displayed = true;
10510 w.mLastAlpha = w.mShownAlpha;
10511 w.mLastLayer = w.mAnimLayer;
10512 w.mLastDsDx = w.mDsDx;
10513 w.mLastDtDx = w.mDtDx;
10514 w.mLastDsDy = w.mDsDy;
10515 w.mLastDtDy = w.mDtDy;
10516 w.mLastHScale = w.mHScale;
10517 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010518 if (SHOW_TRANSACTIONS) logSurface(w,
10519 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010520 + " matrix=[" + (w.mDsDx*w.mHScale)
10521 + "," + (w.mDtDx*w.mVScale)
10522 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010523 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524 if (w.mSurface != null) {
10525 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010526 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010527 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010528 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010529 w.mSurface.setLayer(w.mAnimLayer);
10530 w.mSurface.setMatrix(
10531 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10532 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10533 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010534 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010535 if (!recoveringMemory) {
10536 reclaimSomeSurfaceMemoryLocked(w, "update");
10537 }
10538 }
10539 }
10540
10541 if (w.mLastHidden && !w.mDrawPending
10542 && !w.mCommitDrawPending
10543 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010544 if (SHOW_TRANSACTIONS) logSurface(w,
10545 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010546 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010547 + " during relayout");
10548 if (showSurfaceRobustlyLocked(w)) {
10549 w.mHasDrawn = true;
10550 w.mLastHidden = false;
10551 } else {
10552 w.mOrientationChanging = false;
10553 }
10554 }
10555 if (w.mSurface != null) {
10556 w.mToken.hasVisible = true;
10557 }
10558 } else {
10559 displayed = true;
10560 }
10561
10562 if (displayed) {
10563 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010564 if (attrs.width == LayoutParams.MATCH_PARENT
10565 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010566 covered = true;
10567 }
10568 }
10569 if (w.mOrientationChanging) {
10570 if (w.mDrawPending || w.mCommitDrawPending) {
10571 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010572 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 "Orientation continue waiting for draw in " + w);
10574 } else {
10575 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010576 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010577 "Orientation change complete in " + w);
10578 }
10579 }
10580 w.mToken.hasVisible = true;
10581 }
10582 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010583 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010584 "Orientation change skips hidden " + w);
10585 w.mOrientationChanging = false;
10586 }
10587
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010588 if (w.mContentChanged) {
10589 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10590 w.mContentChanged = false;
10591 }
10592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010593 final boolean canBeSeen = w.isDisplayedLw();
10594
10595 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10596 focusDisplayed = true;
10597 }
10598
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010599 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010602 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010603 if (w.mSurface != null) {
10604 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10605 holdScreen = w.mSession;
10606 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010607 if (!syswin && w.mAttrs.screenBrightness >= 0
10608 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010609 screenBrightness = w.mAttrs.screenBrightness;
10610 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010611 if (!syswin && w.mAttrs.buttonBrightness >= 0
10612 && buttonBrightness < 0) {
10613 buttonBrightness = w.mAttrs.buttonBrightness;
10614 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010615 if (canBeSeen
10616 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10617 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10618 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010619 syswin = true;
10620 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010621 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010622
Dianne Hackborn25994b42009-09-04 14:21:19 -070010623 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10624 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010625 // This window completely covers everything behind it,
10626 // so we want to leave all of them as unblurred (for
10627 // performance reasons).
10628 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010629 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010630 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010631 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010632 obscured = true;
10633 if (mBackgroundFillerSurface == null) {
10634 try {
10635 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010636 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010637 0, dw, dh,
10638 PixelFormat.OPAQUE,
10639 Surface.FX_SURFACE_NORMAL);
10640 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010641 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010642 }
10643 }
10644 try {
10645 mBackgroundFillerSurface.setPosition(0, 0);
10646 mBackgroundFillerSurface.setSize(dw, dh);
10647 // Using the same layer as Dim because they will never be shown at the
10648 // same time.
10649 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10650 mBackgroundFillerSurface.show();
10651 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010652 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010653 }
10654 backgroundFillerShown = true;
10655 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010656 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010657 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010658 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659 + ": blurring=" + blurring
10660 + " obscured=" + obscured
10661 + " displayed=" + displayed);
10662 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10663 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010664 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010665 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010666 if (mDimAnimator == null) {
10667 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010668 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010669 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010670 mDimAnimator.updateParameters(mContext.getResources(),
10671 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010672 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010673 }
10674 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10675 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010676 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010677 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010678 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010679 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010680 + mBlurSurface + ": CREATE");
10681 try {
Romain Guy06882f82009-06-10 13:36:04 -070010682 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010683 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010684 -1, 16, 16,
10685 PixelFormat.OPAQUE,
10686 Surface.FX_SURFACE_BLUR);
10687 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010688 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010689 }
10690 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010691 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010692 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10693 + mBlurSurface + ": pos=(0,0) (" +
10694 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010695 mBlurSurface.setPosition(0, 0);
10696 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010697 mBlurSurface.setLayer(w.mAnimLayer-2);
10698 if (!mBlurShown) {
10699 try {
10700 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10701 + mBlurSurface + ": SHOW");
10702 mBlurSurface.show();
10703 } catch (RuntimeException e) {
10704 Slog.w(TAG, "Failure showing blur surface", e);
10705 }
10706 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010707 }
10708 }
10709 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010710 }
10711 }
10712 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010713
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010714 if (obscuredChanged && mWallpaperTarget == w) {
10715 // This is the wallpaper target and its obscured state
10716 // changed... make sure the current wallaper's visibility
10717 // has been updated accordingly.
10718 updateWallpaperVisibilityLocked();
10719 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010721
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010722 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10723 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010724 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010725 try {
10726 mBackgroundFillerSurface.hide();
10727 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010728 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010729 }
10730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010731
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010732 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010733 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10734 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010735 }
Romain Guy06882f82009-06-10 13:36:04 -070010736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010737 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010738 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010739 + ": HIDE");
10740 try {
10741 mBlurSurface.hide();
10742 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010743 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010744 }
10745 mBlurShown = false;
10746 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010747 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010748 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 }
10750
10751 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010752
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010753 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10754
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010755 if (mWatermark != null) {
10756 mWatermark.drawIfNeeded();
10757 }
10758
Joe Onorato8a9b2202010-02-26 18:56:32 -080010759 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010760 "With display frozen, orientationChangeComplete="
10761 + orientationChangeComplete);
10762 if (orientationChangeComplete) {
10763 if (mWindowsFreezingScreen) {
10764 mWindowsFreezingScreen = false;
10765 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10766 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010767 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010768 }
Romain Guy06882f82009-06-10 13:36:04 -070010769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770 i = mResizingWindows.size();
10771 if (i > 0) {
10772 do {
10773 i--;
10774 WindowState win = mResizingWindows.get(i);
10775 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010776 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10777 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010778 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010779 boolean configChanged =
10780 win.mConfiguration != mCurConfiguration
10781 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010782 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10783 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10784 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010785 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010786 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010787 + " / " + mCurConfiguration + " / 0x"
10788 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010789 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010790 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010791 win.mClient.resized(win.mFrame.width(),
10792 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010793 win.mLastVisibleInsets, win.mDrawPending,
10794 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010795 win.mContentInsetsChanged = false;
10796 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010797 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010798 } catch (RemoteException e) {
10799 win.mOrientationChanging = false;
10800 }
10801 } while (i > 0);
10802 mResizingWindows.clear();
10803 }
Romain Guy06882f82009-06-10 13:36:04 -070010804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010805 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010806 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010807 i = mDestroySurface.size();
10808 if (i > 0) {
10809 do {
10810 i--;
10811 WindowState win = mDestroySurface.get(i);
10812 win.mDestroying = false;
10813 if (mInputMethodWindow == win) {
10814 mInputMethodWindow = null;
10815 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010816 if (win == mWallpaperTarget) {
10817 wallpaperDestroyed = true;
10818 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010819 win.destroySurfaceLocked();
10820 } while (i > 0);
10821 mDestroySurface.clear();
10822 }
10823
10824 // Time to remove any exiting tokens?
10825 for (i=mExitingTokens.size()-1; i>=0; i--) {
10826 WindowToken token = mExitingTokens.get(i);
10827 if (!token.hasVisible) {
10828 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010829 if (token.windowType == TYPE_WALLPAPER) {
10830 mWallpaperTokens.remove(token);
10831 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010832 }
10833 }
10834
10835 // Time to remove any exiting applications?
10836 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10837 AppWindowToken token = mExitingAppTokens.get(i);
10838 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010839 // Make sure there is no animation running on this token,
10840 // so any windows associated with it will be removed as
10841 // soon as their animations are complete
10842 token.animation = null;
10843 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010844 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10845 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010846 mAppTokens.remove(token);
10847 mExitingAppTokens.remove(i);
10848 }
10849 }
10850
Dianne Hackborna8f60182009-09-01 19:01:50 -070010851 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010852
Dianne Hackborna8f60182009-09-01 19:01:50 -070010853 if (!animating && mAppTransitionRunning) {
10854 // We have finished the animation of an app transition. To do
10855 // this, we have delayed a lot of operations like showing and
10856 // hiding apps, moving apps in Z-order, etc. The app token list
10857 // reflects the correct Z-order, but the window list may now
10858 // be out of sync with it. So here we will just rebuild the
10859 // entire app window list. Fun!
10860 mAppTransitionRunning = false;
10861 needRelayout = true;
10862 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010863 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010864 // Clear information about apps that were moving.
10865 mToBottomApps.clear();
10866 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010868 if (focusDisplayed) {
10869 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10870 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010871 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010872 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010873 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010874 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010875 requestAnimationLocked(0);
10876 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010877 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10878 }
Jeff Browneb857f12010-07-16 10:06:33 -070010879
Jeff Brown3a22cd92011-01-21 13:59:04 -080010880 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080010881 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070010882
Jeff Brown8e03b752010-06-13 19:16:55 -070010883 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080010884 if (!mDisplayFrozen) {
10885 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10886 mPowerManager.setScreenBrightnessOverride(-1);
10887 } else {
10888 mPowerManager.setScreenBrightnessOverride((int)
10889 (screenBrightness * Power.BRIGHTNESS_ON));
10890 }
10891 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10892 mPowerManager.setButtonBrightnessOverride(-1);
10893 } else {
10894 mPowerManager.setButtonBrightnessOverride((int)
10895 (buttonBrightness * Power.BRIGHTNESS_ON));
10896 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 if (holdScreen != mHoldingScreenOn) {
10899 mHoldingScreenOn = holdScreen;
10900 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10901 mH.sendMessage(m);
10902 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010903
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010904 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010905 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010906 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10907 LocalPowerManager.BUTTON_EVENT, true);
10908 mTurnOnScreen = false;
10909 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010910
Dianne Hackborn89ba6752011-01-23 16:51:16 -080010911 if (updateRotation) {
10912 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
10913 boolean changed = setRotationUncheckedLocked(
10914 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
10915 if (changed) {
10916 sendNewConfiguration();
10917 }
10918 }
10919
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010920 // Check to see if we are now in a state where the screen should
10921 // be enabled, because the window obscured flags have changed.
10922 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010923 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010924
10925 /**
10926 * Must be called with the main window manager lock held.
10927 */
10928 void setHoldScreenLocked(boolean holding) {
10929 boolean state = mHoldingScreenWakeLock.isHeld();
10930 if (holding != state) {
10931 if (holding) {
10932 mHoldingScreenWakeLock.acquire();
10933 } else {
10934 mPolicy.screenOnStoppedLw();
10935 mHoldingScreenWakeLock.release();
10936 }
10937 }
10938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939
10940 void requestAnimationLocked(long delay) {
10941 if (!mAnimationPending) {
10942 mAnimationPending = true;
10943 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10944 }
10945 }
Romain Guy06882f82009-06-10 13:36:04 -070010946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010947 /**
10948 * Have the surface flinger show a surface, robustly dealing with
10949 * error conditions. In particular, if there is not enough memory
10950 * to show the surface, then we will try to get rid of other surfaces
10951 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010952 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010953 * @return Returns true if the surface was successfully shown.
10954 */
10955 boolean showSurfaceRobustlyLocked(WindowState win) {
10956 try {
10957 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010958 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010959 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010960 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010961 if (DEBUG_VISIBILITY) Slog.v(TAG,
10962 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010963 win.mTurnOnScreen = false;
10964 mTurnOnScreen = true;
10965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010966 }
10967 return true;
10968 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010969 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010970 }
Romain Guy06882f82009-06-10 13:36:04 -070010971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010972 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010974 return false;
10975 }
Romain Guy06882f82009-06-10 13:36:04 -070010976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010977 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10978 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010979
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010980 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010981 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010983 if (mForceRemoves == null) {
10984 mForceRemoves = new ArrayList<WindowState>();
10985 }
Romain Guy06882f82009-06-10 13:36:04 -070010986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 long callingIdentity = Binder.clearCallingIdentity();
10988 try {
10989 // There was some problem... first, do a sanity check of the
10990 // window list to make sure we haven't left any dangling surfaces
10991 // around.
10992 int N = mWindows.size();
10993 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010994 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010995 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010996 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010997 if (ws.mSurface != null) {
10998 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010999 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011000 + ws + " surface=" + ws.mSurface
11001 + " token=" + win.mToken
11002 + " pid=" + ws.mSession.mPid
11003 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011004 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011005 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011006 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 ws.mSurface = null;
11008 mForceRemoves.add(ws);
11009 i--;
11010 N--;
11011 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011012 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011013 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011014 + ws + " surface=" + ws.mSurface
11015 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011016 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011017 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011018 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011019 ws.mSurface = null;
11020 leakedSurface = true;
11021 }
11022 }
11023 }
Romain Guy06882f82009-06-10 13:36:04 -070011024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011025 boolean killedApps = false;
11026 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011027 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011028 SparseIntArray pidCandidates = new SparseIntArray();
11029 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011030 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011031 if (ws.mSurface != null) {
11032 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11033 }
11034 }
11035 if (pidCandidates.size() > 0) {
11036 int[] pids = new int[pidCandidates.size()];
11037 for (int i=0; i<pids.length; i++) {
11038 pids[i] = pidCandidates.keyAt(i);
11039 }
11040 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011041 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011042 killedApps = true;
11043 }
11044 } catch (RemoteException e) {
11045 }
11046 }
11047 }
Romain Guy06882f82009-06-10 13:36:04 -070011048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011049 if (leakedSurface || killedApps) {
11050 // We managed to reclaim some memory, so get rid of the trouble
11051 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011052 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011053 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011054 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011055 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011056 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011057 win.mSurface = null;
11058 }
Romain Guy06882f82009-06-10 13:36:04 -070011059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011060 try {
11061 win.mClient.dispatchGetNewSurface();
11062 } catch (RemoteException e) {
11063 }
11064 }
11065 } finally {
11066 Binder.restoreCallingIdentity(callingIdentity);
11067 }
11068 }
Romain Guy06882f82009-06-10 13:36:04 -070011069
Jeff Brown3a22cd92011-01-21 13:59:04 -080011070 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011071 WindowState newFocus = computeFocusedWindowLocked();
11072 if (mCurrentFocus != newFocus) {
11073 // This check makes sure that we don't already have the focus
11074 // change message pending.
11075 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11076 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011077 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011078 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11079 final WindowState oldFocus = mCurrentFocus;
11080 mCurrentFocus = newFocus;
11081 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011083 final WindowState imWindow = mInputMethodWindow;
11084 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011085 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011086 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011087 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11088 mLayoutNeeded = true;
11089 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011090 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011091 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011092 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11093 // Client will do the layout, but we need to assign layers
11094 // for handleNewWindowLocked() below.
11095 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011096 }
11097 }
Jeff Brown349703e2010-06-22 01:27:15 -070011098
11099 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11100 // If we defer assigning layers, then the caller is responsible for
11101 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011102 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011103 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011104 return true;
11105 }
11106 return false;
11107 }
Jeff Brown349703e2010-06-22 01:27:15 -070011108
Jeff Brown3a22cd92011-01-21 13:59:04 -080011109 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11110 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011112
11113 private WindowState computeFocusedWindowLocked() {
11114 WindowState result = null;
11115 WindowState win;
11116
11117 int i = mWindows.size() - 1;
11118 int nextAppIndex = mAppTokens.size()-1;
11119 WindowToken nextApp = nextAppIndex >= 0
11120 ? mAppTokens.get(nextAppIndex) : null;
11121
11122 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011123 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011124
Joe Onorato8a9b2202010-02-26 18:56:32 -080011125 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011126 TAG, "Looking for focus: " + i
11127 + " = " + win
11128 + ", flags=" + win.mAttrs.flags
11129 + ", canReceive=" + win.canReceiveKeys());
11130
11131 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011133 // If this window's application has been removed, just skip it.
11134 if (thisApp != null && thisApp.removed) {
11135 i--;
11136 continue;
11137 }
Romain Guy06882f82009-06-10 13:36:04 -070011138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011139 // If there is a focused app, don't allow focus to go to any
11140 // windows below it. If this is an application window, step
11141 // through the app tokens until we find its app.
11142 if (thisApp != null && nextApp != null && thisApp != nextApp
11143 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11144 int origAppIndex = nextAppIndex;
11145 while (nextAppIndex > 0) {
11146 if (nextApp == mFocusedApp) {
11147 // Whoops, we are below the focused app... no focus
11148 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011149 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011150 TAG, "Reached focused app: " + mFocusedApp);
11151 return null;
11152 }
11153 nextAppIndex--;
11154 nextApp = mAppTokens.get(nextAppIndex);
11155 if (nextApp == thisApp) {
11156 break;
11157 }
11158 }
11159 if (thisApp != nextApp) {
11160 // Uh oh, the app token doesn't exist! This shouldn't
11161 // happen, but if it does we can get totally hosed...
11162 // so restart at the original app.
11163 nextAppIndex = origAppIndex;
11164 nextApp = mAppTokens.get(nextAppIndex);
11165 }
11166 }
11167
11168 // Dispatch to this window if it is wants key events.
11169 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011170 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011171 TAG, "Found focus @ " + i + " = " + win);
11172 result = win;
11173 break;
11174 }
11175
11176 i--;
11177 }
11178
11179 return result;
11180 }
11181
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011182 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011183 if (mDisplayFrozen) {
11184 return;
11185 }
Romain Guy06882f82009-06-10 13:36:04 -070011186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011187 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011189 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011190 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011191 if (mFreezeGcPending != 0) {
11192 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011193 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011194 mH.removeMessages(H.FORCE_GC);
11195 Runtime.getRuntime().gc();
11196 mFreezeGcPending = now;
11197 }
11198 } else {
11199 mFreezeGcPending = now;
11200 }
Romain Guy06882f82009-06-10 13:36:04 -070011201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011202 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011203
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011204 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011205
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011206 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11207 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011208 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011209 mAppTransitionReady = true;
11210 }
Romain Guy06882f82009-06-10 13:36:04 -070011211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011212 if (PROFILE_ORIENTATION) {
11213 File file = new File("/data/system/frozen");
11214 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11215 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011216
11217 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011218 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11219 mScreenRotationAnimation.kill();
11220 mScreenRotationAnimation = null;
11221 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011222 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011223 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011224 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011225 }
11226 } else {
11227 Surface.freezeDisplay(0);
11228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011229 }
Romain Guy06882f82009-06-10 13:36:04 -070011230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011231 private void stopFreezingDisplayLocked() {
11232 if (!mDisplayFrozen) {
11233 return;
11234 }
Romain Guy06882f82009-06-10 13:36:04 -070011235
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011236 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11237 return;
11238 }
11239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011240 mDisplayFrozen = false;
11241 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11242 if (PROFILE_ORIENTATION) {
11243 Debug.stopMethodTracing();
11244 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011245
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011246 boolean updateRotation = false;
11247
Dianne Hackborna1111872010-11-23 20:55:11 -080011248 if (CUSTOM_SCREEN_ROTATION) {
11249 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011250 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11251 mTransitionAnimationScale)) {
11252 requestAnimationLocked(0);
11253 } else {
11254 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011255 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011256 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011257 }
11258 } else {
11259 Surface.unfreezeDisplay(0);
11260 }
Romain Guy06882f82009-06-10 13:36:04 -070011261
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011262 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011263
Christopher Tateb696aee2010-04-02 19:08:30 -070011264 // While the display is frozen we don't re-compute the orientation
11265 // to avoid inconsistent states. However, something interesting
11266 // could have actually changed during that time so re-evaluate it
11267 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011268 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011269 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11270 }
11271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011272 // A little kludge: a lot could have happened while the
11273 // display was frozen, so now that we are coming back we
11274 // do a gc so that any remote references the system
11275 // processes holds on others can be released if they are
11276 // no longer needed.
11277 mH.removeMessages(H.FORCE_GC);
11278 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11279 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011281 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011282
11283 if (updateRotation) {
11284 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11285 boolean changed = setRotationUncheckedLocked(
11286 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11287 if (changed) {
11288 sendNewConfiguration();
11289 }
11290 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011291 }
Romain Guy06882f82009-06-10 13:36:04 -070011292
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011293 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11294 DisplayMetrics dm) {
11295 if (index < tokens.length) {
11296 String str = tokens[index];
11297 if (str != null && str.length() > 0) {
11298 try {
11299 int val = Integer.parseInt(str);
11300 return val;
11301 } catch (Exception e) {
11302 }
11303 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011304 }
11305 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11306 return defDps;
11307 }
11308 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11309 return val;
11310 }
11311
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011312 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011313 final String[] mTokens;
11314 final String mText;
11315 final Paint mTextPaint;
11316 final int mTextWidth;
11317 final int mTextHeight;
11318 final int mTextAscent;
11319 final int mTextDescent;
11320 final int mDeltaX;
11321 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011322
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011323 Surface mSurface;
11324 int mLastDW;
11325 int mLastDH;
11326 boolean mDrawNeeded;
11327
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011328 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011329 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011330 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011331
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011332 if (false) {
11333 Log.i(TAG, "*********************** WATERMARK");
11334 for (int i=0; i<tokens.length; i++) {
11335 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11336 }
11337 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011338
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011339 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011340
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011341 StringBuilder builder = new StringBuilder(32);
11342 int len = mTokens[0].length();
11343 len = len & ~1;
11344 for (int i=0; i<len; i+=2) {
11345 int c1 = mTokens[0].charAt(i);
11346 int c2 = mTokens[0].charAt(i+1);
11347 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11348 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11349 else c1 -= '0';
11350 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11351 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11352 else c2 -= '0';
11353 builder.append((char)(255-((c1*16)+c2)));
11354 }
11355 mText = builder.toString();
11356 if (false) {
11357 Log.i(TAG, "Final text: " + mText);
11358 }
11359
11360 int fontSize = getPropertyInt(tokens, 1,
11361 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11362
11363 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11364 mTextPaint.setTextSize(fontSize);
11365 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11366
11367 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11368 mTextWidth = (int)mTextPaint.measureText(mText);
11369 mTextAscent = fm.ascent;
11370 mTextDescent = fm.descent;
11371 mTextHeight = fm.descent - fm.ascent;
11372
11373 mDeltaX = getPropertyInt(tokens, 2,
11374 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11375 mDeltaY = getPropertyInt(tokens, 3,
11376 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11377 int shadowColor = getPropertyInt(tokens, 4,
11378 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11379 int color = getPropertyInt(tokens, 5,
11380 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11381 int shadowRadius = getPropertyInt(tokens, 6,
11382 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11383 int shadowDx = getPropertyInt(tokens, 8,
11384 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11385 int shadowDy = getPropertyInt(tokens, 9,
11386 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11387
11388 mTextPaint.setColor(color);
11389 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011390
11391 try {
11392 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011393 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011394 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011395 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011396 mSurface.show();
11397 } catch (OutOfResourcesException e) {
11398 }
11399 }
11400
11401 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011402 if (mLastDW != dw || mLastDH != dh) {
11403 mLastDW = dw;
11404 mLastDH = dh;
11405 mSurface.setSize(dw, dh);
11406 mDrawNeeded = true;
11407 }
11408 }
11409
11410 void drawIfNeeded() {
11411 if (mDrawNeeded) {
11412 final int dw = mLastDW;
11413 final int dh = mLastDH;
11414
11415 mDrawNeeded = false;
11416 Rect dirty = new Rect(0, 0, dw, dh);
11417 Canvas c = null;
11418 try {
11419 c = mSurface.lockCanvas(dirty);
11420 } catch (IllegalArgumentException e) {
11421 } catch (OutOfResourcesException e) {
11422 }
11423 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011424 c.drawColor(0, PorterDuff.Mode.CLEAR);
11425
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011426 int deltaX = mDeltaX;
11427 int deltaY = mDeltaY;
11428
11429 // deltaX shouldn't be close to a round fraction of our
11430 // x step, or else things will line up too much.
11431 int div = (dw+mTextWidth)/deltaX;
11432 int rem = (dw+mTextWidth) - (div*deltaX);
11433 int qdelta = deltaX/4;
11434 if (rem < qdelta || rem > (deltaX-qdelta)) {
11435 deltaX += deltaX/3;
11436 }
11437
11438 int y = -mTextHeight;
11439 int x = -mTextWidth;
11440 while (y < (dh+mTextHeight)) {
11441 c.drawText(mText, x, y, mTextPaint);
11442 x += deltaX;
11443 if (x >= dw) {
11444 x -= (dw+mTextWidth);
11445 y += deltaY;
11446 }
11447 }
11448 mSurface.unlockCanvasAndPost(c);
11449 }
11450 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011451 }
11452 }
11453
11454 void createWatermark() {
11455 if (mWatermark != null) {
11456 return;
11457 }
11458
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011459 File file = new File("/system/etc/setup.conf");
11460 FileInputStream in = null;
11461 try {
11462 in = new FileInputStream(file);
11463 DataInputStream ind = new DataInputStream(in);
11464 String line = ind.readLine();
11465 if (line != null) {
11466 String[] toks = line.split("%");
11467 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011468 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011469 }
11470 }
11471 } catch (FileNotFoundException e) {
11472 } catch (IOException e) {
11473 } finally {
11474 if (in != null) {
11475 try {
11476 in.close();
11477 } catch (IOException e) {
11478 }
11479 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011480 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011481 }
11482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011483 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011484 public void statusBarVisibilityChanged(int visibility) {
11485 synchronized (mWindowMap) {
11486 final int N = mWindows.size();
11487 for (int i = 0; i < N; i++) {
11488 WindowState ws = mWindows.get(i);
11489 try {
11490 if (ws.getAttrs().hasSystemUiListeners) {
11491 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11492 }
11493 } catch (RemoteException e) {
11494 // so sorry
11495 }
11496 }
11497 }
11498 }
11499
11500 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011501 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11502 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11503 != PackageManager.PERMISSION_GRANTED) {
11504 pw.println("Permission Denial: can't dump WindowManager from from pid="
11505 + Binder.getCallingPid()
11506 + ", uid=" + Binder.getCallingUid());
11507 return;
11508 }
Romain Guy06882f82009-06-10 13:36:04 -070011509
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011510 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011511 pw.println(" ");
11512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011513 synchronized(mWindowMap) {
11514 pw.println("Current Window Manager state:");
11515 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011516 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011517 pw.print(" Window #"); pw.print(i); pw.print(' ');
11518 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011519 w.dump(pw, " ");
11520 }
11521 if (mInputMethodDialogs.size() > 0) {
11522 pw.println(" ");
11523 pw.println(" Input method dialogs:");
11524 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11525 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011526 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011527 }
11528 }
11529 if (mPendingRemove.size() > 0) {
11530 pw.println(" ");
11531 pw.println(" Remove pending for:");
11532 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11533 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011534 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11535 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011536 w.dump(pw, " ");
11537 }
11538 }
11539 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11540 pw.println(" ");
11541 pw.println(" Windows force removing:");
11542 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11543 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011544 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11545 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011546 w.dump(pw, " ");
11547 }
11548 }
11549 if (mDestroySurface.size() > 0) {
11550 pw.println(" ");
11551 pw.println(" Windows waiting to destroy their surface:");
11552 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11553 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011554 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11555 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011556 w.dump(pw, " ");
11557 }
11558 }
11559 if (mLosingFocus.size() > 0) {
11560 pw.println(" ");
11561 pw.println(" Windows losing focus:");
11562 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11563 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011564 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11565 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011566 w.dump(pw, " ");
11567 }
11568 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011569 if (mResizingWindows.size() > 0) {
11570 pw.println(" ");
11571 pw.println(" Windows waiting to resize:");
11572 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11573 WindowState w = mResizingWindows.get(i);
11574 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11575 pw.print(w); pw.println(":");
11576 w.dump(pw, " ");
11577 }
11578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011579 if (mSessions.size() > 0) {
11580 pw.println(" ");
11581 pw.println(" All active sessions:");
11582 Iterator<Session> it = mSessions.iterator();
11583 while (it.hasNext()) {
11584 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011585 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011586 s.dump(pw, " ");
11587 }
11588 }
11589 if (mTokenMap.size() > 0) {
11590 pw.println(" ");
11591 pw.println(" All tokens:");
11592 Iterator<WindowToken> it = mTokenMap.values().iterator();
11593 while (it.hasNext()) {
11594 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011595 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011596 token.dump(pw, " ");
11597 }
11598 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011599 if (mWallpaperTokens.size() > 0) {
11600 pw.println(" ");
11601 pw.println(" Wallpaper tokens:");
11602 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11603 WindowToken token = mWallpaperTokens.get(i);
11604 pw.print(" Wallpaper #"); pw.print(i);
11605 pw.print(' '); pw.print(token); pw.println(':');
11606 token.dump(pw, " ");
11607 }
11608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011609 if (mAppTokens.size() > 0) {
11610 pw.println(" ");
11611 pw.println(" Application tokens in Z order:");
11612 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011613 pw.print(" App #"); pw.print(i); pw.print(": ");
11614 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011615 }
11616 }
11617 if (mFinishedStarting.size() > 0) {
11618 pw.println(" ");
11619 pw.println(" Finishing start of application tokens:");
11620 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11621 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011622 pw.print(" Finished Starting #"); pw.print(i);
11623 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011624 token.dump(pw, " ");
11625 }
11626 }
11627 if (mExitingTokens.size() > 0) {
11628 pw.println(" ");
11629 pw.println(" Exiting tokens:");
11630 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11631 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011632 pw.print(" Exiting #"); pw.print(i);
11633 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011634 token.dump(pw, " ");
11635 }
11636 }
11637 if (mExitingAppTokens.size() > 0) {
11638 pw.println(" ");
11639 pw.println(" Exiting application tokens:");
11640 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11641 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011642 pw.print(" Exiting App #"); pw.print(i);
11643 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011644 token.dump(pw, " ");
11645 }
11646 }
11647 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011648 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11649 pw.print(" mLastFocus="); pw.println(mLastFocus);
11650 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11651 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11652 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011653 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011654 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11655 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11656 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11657 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011658 if (mWindowDetachedWallpaper != null) {
11659 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11660 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011661 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11662 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11663 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011664 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11665 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11666 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11667 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011668 if (mDimAnimator != null) {
11669 mDimAnimator.printTo(pw);
11670 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011671 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011672 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011673 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011674 pw.print(mInputMethodAnimLayerAdjustment);
11675 pw.print(" mWallpaperAnimLayerAdjustment=");
11676 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011677 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11678 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011679 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11680 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011681 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11682 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011683 pw.print(" mRotation="); pw.print(mRotation);
11684 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11685 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011686 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11687 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011688 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11689 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11690 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11691 pw.print(" mNextAppTransition=0x");
11692 pw.print(Integer.toHexString(mNextAppTransition));
11693 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011694 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011695 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011696 if (mNextAppTransitionPackage != null) {
11697 pw.print(" mNextAppTransitionPackage=");
11698 pw.print(mNextAppTransitionPackage);
11699 pw.print(", mNextAppTransitionEnter=0x");
11700 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11701 pw.print(", mNextAppTransitionExit=0x");
11702 pw.print(Integer.toHexString(mNextAppTransitionExit));
11703 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011704 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11705 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11706 if (mOpeningApps.size() > 0) {
11707 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11708 }
11709 if (mClosingApps.size() > 0) {
11710 pw.print(" mClosingApps="); pw.println(mClosingApps);
11711 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011712 if (mToTopApps.size() > 0) {
11713 pw.print(" mToTopApps="); pw.println(mToTopApps);
11714 }
11715 if (mToBottomApps.size() > 0) {
11716 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11717 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011718 if (mDisplay != null) {
11719 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11720 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11721 } else {
11722 pw.println(" NO DISPLAY");
11723 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011724 pw.println(" Policy:");
11725 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011726 }
11727 }
11728
Jeff Brown349703e2010-06-22 01:27:15 -070011729 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011730 public void monitor() {
11731 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011732 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011733 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011734
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011735 /**
11736 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011737 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011738 */
11739 private static class DimAnimator {
11740 Surface mDimSurface;
11741 boolean mDimShown = false;
11742 float mDimCurrentAlpha;
11743 float mDimTargetAlpha;
11744 float mDimDeltaPerMs;
11745 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011746
11747 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011748
11749 DimAnimator (SurfaceSession session) {
11750 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011751 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011752 + mDimSurface + ": CREATE");
11753 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011754 mDimSurface = new Surface(session, 0,
11755 "DimSurface",
11756 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011757 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011758 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011759 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011760 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011761 }
11762 }
11763 }
11764
11765 /**
11766 * Show the dim surface.
11767 */
11768 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011769 if (!mDimShown) {
11770 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11771 dw + "x" + dh + ")");
11772 mDimShown = true;
11773 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011774 mLastDimWidth = dw;
11775 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011776 mDimSurface.setPosition(0, 0);
11777 mDimSurface.setSize(dw, dh);
11778 mDimSurface.show();
11779 } catch (RuntimeException e) {
11780 Slog.w(TAG, "Failure showing dim surface", e);
11781 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011782 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11783 mLastDimWidth = dw;
11784 mLastDimHeight = dh;
11785 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011786 }
11787 }
11788
11789 /**
11790 * Set's the dim surface's layer and update dim parameters that will be used in
11791 * {@link updateSurface} after all windows are examined.
11792 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011793 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011794 mDimSurface.setLayer(w.mAnimLayer-1);
11795
11796 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011797 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011798 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011799 if (mDimTargetAlpha != target) {
11800 // If the desired dim level has changed, then
11801 // start an animation to it.
11802 mLastDimAnimTime = currentTime;
11803 long duration = (w.mAnimating && w.mAnimation != null)
11804 ? w.mAnimation.computeDurationHint()
11805 : DEFAULT_DIM_DURATION;
11806 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011807 TypedValue tv = new TypedValue();
11808 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11809 tv, true);
11810 if (tv.type == TypedValue.TYPE_FRACTION) {
11811 duration = (long)tv.getFraction((float)duration, (float)duration);
11812 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11813 && tv.type <= TypedValue.TYPE_LAST_INT) {
11814 duration = tv.data;
11815 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011816 }
11817 if (duration < 1) {
11818 // Don't divide by zero
11819 duration = 1;
11820 }
11821 mDimTargetAlpha = target;
11822 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11823 }
11824 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011825
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011826 /**
11827 * Updating the surface's alpha. Returns true if the animation continues, or returns
11828 * false when the animation is finished and the dim surface is hidden.
11829 */
11830 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11831 if (!dimming) {
11832 if (mDimTargetAlpha != 0) {
11833 mLastDimAnimTime = currentTime;
11834 mDimTargetAlpha = 0;
11835 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11836 }
11837 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011838
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011839 boolean animating = false;
11840 if (mLastDimAnimTime != 0) {
11841 mDimCurrentAlpha += mDimDeltaPerMs
11842 * (currentTime-mLastDimAnimTime);
11843 boolean more = true;
11844 if (displayFrozen) {
11845 // If the display is frozen, there is no reason to animate.
11846 more = false;
11847 } else if (mDimDeltaPerMs > 0) {
11848 if (mDimCurrentAlpha > mDimTargetAlpha) {
11849 more = false;
11850 }
11851 } else if (mDimDeltaPerMs < 0) {
11852 if (mDimCurrentAlpha < mDimTargetAlpha) {
11853 more = false;
11854 }
11855 } else {
11856 more = false;
11857 }
11858
11859 // Do we need to continue animating?
11860 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011861 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011862 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11863 mLastDimAnimTime = currentTime;
11864 mDimSurface.setAlpha(mDimCurrentAlpha);
11865 animating = true;
11866 } else {
11867 mDimCurrentAlpha = mDimTargetAlpha;
11868 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011869 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011870 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11871 mDimSurface.setAlpha(mDimCurrentAlpha);
11872 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011873 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011874 + ": HIDE");
11875 try {
11876 mDimSurface.hide();
11877 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011878 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011879 }
11880 mDimShown = false;
11881 }
11882 }
11883 }
11884 return animating;
11885 }
11886
11887 public void printTo(PrintWriter pw) {
11888 pw.print(" mDimShown="); pw.print(mDimShown);
11889 pw.print(" current="); pw.print(mDimCurrentAlpha);
11890 pw.print(" target="); pw.print(mDimTargetAlpha);
11891 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11892 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11893 }
11894 }
11895
11896 /**
11897 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11898 * This is used for opening/closing transition for apps in compatible mode.
11899 */
11900 private static class FadeInOutAnimation extends Animation {
11901 int mWidth;
11902 boolean mFadeIn;
11903
11904 public FadeInOutAnimation(boolean fadeIn) {
11905 setInterpolator(new AccelerateInterpolator());
11906 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11907 mFadeIn = fadeIn;
11908 }
11909
11910 @Override
11911 protected void applyTransformation(float interpolatedTime, Transformation t) {
11912 float x = interpolatedTime;
11913 if (!mFadeIn) {
11914 x = 1.0f - x; // reverse the interpolation for fade out
11915 }
11916 if (x < 0.5) {
11917 // move the window out of the screen.
11918 t.getMatrix().setTranslate(mWidth, 0);
11919 } else {
11920 t.getMatrix().setTranslate(0, 0);// show
11921 t.setAlpha((x - 0.5f) * 2);
11922 }
11923 }
11924
11925 @Override
11926 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11927 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11928 mWidth = width;
11929 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011930
11931 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011932 public int getZAdjustment() {
11933 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011934 }
11935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011936}