blob: 88d7cf754bf9c02c33e21eef24770043317df780 [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 Brown349703e2010-06-22 01:27:15 -0700215
216 // Default input dispatching timeout in nanoseconds.
217 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 static final int UPDATE_FOCUS_NORMAL = 0;
220 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
221 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
222 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700225 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226
227 /**
228 * Condition waited on by {@link #reenableKeyguard} to know the call to
229 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 * This is set to true only if mKeyguardTokenWatcher.acquired() has
231 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500233 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234
Jim Miller284b62e2010-06-08 14:27:42 -0700235 private static final int ALLOW_DISABLE_YES = 1;
236 private static final int ALLOW_DISABLE_NO = 0;
237 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
238 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
239
Mike Lockwood983ee092009-11-22 01:42:24 -0500240 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
241 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700243 if (shouldAllowDisableKeyguard()) {
244 mPolicy.enableKeyguard(false);
245 mKeyguardDisabled = true;
246 } else {
247 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 }
250 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700251 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500252 synchronized (mKeyguardTokenWatcher) {
253 mKeyguardDisabled = false;
254 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 }
256 }
257 };
258
Jim Miller284b62e2010-06-08 14:27:42 -0700259 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
260 @Override
261 public void onReceive(Context context, Intent intent) {
262 mPolicy.enableKeyguard(true);
263 synchronized(mKeyguardTokenWatcher) {
264 // lazily evaluate this next time we're asked to disable keyguard
265 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
266 mKeyguardDisabled = false;
267 }
268 }
269 };
270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 final Context mContext;
272
273 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
278
279 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 /**
284 * All currently active sessions with clients.
285 */
286 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 /**
289 * Mapping from an IWindow IBinder to the server's Window object.
290 * This is also used as the lock for all of our state.
291 */
292 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
293
294 /**
295 * Mapping from a token IBinder to a WindowToken object.
296 */
297 final HashMap<IBinder, WindowToken> mTokenMap =
298 new HashMap<IBinder, WindowToken>();
299
300 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 * Window tokens that are in the process of exiting, but still
302 * on screen for animations.
303 */
304 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
305
306 /**
307 * Z-ordered (bottom-most first) list of all application tokens, for
308 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800309 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 */
311 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
312
313 /**
314 * Application tokens that are in the process of exiting, but still
315 * on screen for animations.
316 */
317 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
318
319 /**
320 * List of window tokens that have finished starting their application,
321 * and now need to have the policy remove their windows.
322 */
323 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
324
325 /**
326 * Z-ordered (bottom-most first) list of all Window objects.
327 */
Jeff Browne33348b2010-07-15 23:54:05 -0700328 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329
330 /**
331 * Windows that are being resized. Used so we can tell the client about
332 * the resize after closing the transaction in which we resized the
333 * underlying surface.
334 */
335 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
336
337 /**
338 * Windows whose animations have ended and now must be removed.
339 */
340 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
341
342 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800343 * Used when processing mPendingRemove to avoid working on the original array.
344 */
345 WindowState[] mPendingRemoveTmp = new WindowState[20];
346
347 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 * Windows whose surface should be destroyed.
349 */
350 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
351
352 /**
353 * Windows that have lost input focus and are waiting for the new
354 * focus window to be displayed before they are told about this.
355 */
356 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
357
358 /**
359 * This is set when we have run out of memory, and will either be an empty
360 * list or contain windows that need to be force removed.
361 */
362 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700363
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800364 /**
365 * Used when rebuilding window list to keep track of windows that have
366 * been removed.
367 */
368 WindowState[] mRebuildTmp = new WindowState[20];
369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700373 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 Surface mBlurSurface;
375 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700376 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800377 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800378 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 final float[] mTmpFloats = new float[9];
383
384 boolean mSafeMode;
385 boolean mDisplayEnabled = false;
386 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700387 int mInitialDisplayWidth = 0;
388 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 int mRotation = 0;
390 int mRequestedRotation = 0;
391 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700392 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 ArrayList<IRotationWatcher> mRotationWatchers
394 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 boolean mLayoutNeeded = true;
397 boolean mAnimationPending = false;
398 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800399 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 boolean mWindowsFreezingScreen = false;
401 long mFreezeGcPending = 0;
402 int mAppsFreezingScreen = 0;
403
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800404 int mLayoutSeq = 0;
405
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800406 // State while inside of layoutAndPlaceSurfacesLocked().
407 boolean mFocusMayChange;
408
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800409 Configuration mCurConfiguration = new Configuration();
410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 // This is held as long as we have the screen frozen, to give us time to
412 // perform a rotation animation when turning off shows the lock screen which
413 // changes the orientation.
414 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 // State management of app transitions. When we are preparing for a
417 // transition, mNextAppTransition will be the kind of transition to
418 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
419 // mOpeningApps and mClosingApps are the lists of tokens that will be
420 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700421 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700422 String mNextAppTransitionPackage;
423 int mNextAppTransitionEnter;
424 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700426 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionTimeout = false;
428 boolean mStartingIconInTransition = false;
429 boolean mSkipAppTransitionAnimation = false;
430 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
431 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 H mH = new H();
438
439 WindowState mCurrentFocus = null;
440 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 // This just indicates the window the input method is on top of, not
443 // necessarily the window its input is going to.
444 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 boolean mInputMethodTargetWaitingAnim;
446 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 WindowState mInputMethodWindow = null;
449 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
450
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700451 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800452
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700453 // If non-null, this is the currently visible window that is associated
454 // with the wallpaper.
455 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700456 // If non-null, we are in the middle of animating from one wallpaper target
457 // to another, and this is the lower one in Z-order.
458 WindowState mLowerWallpaperTarget = null;
459 // If non-null, we are in the middle of animating from one wallpaper target
460 // to another, and this is the higher one in Z-order.
461 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800462 // Window currently running an animation that has requested it be detached
463 // from the wallpaper. This means we need to ensure the wallpaper is
464 // visible behind it in case it animates in a way that would allow it to be
465 // seen.
466 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700467 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700468 float mLastWallpaperX = -1;
469 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800470 float mLastWallpaperXStep = -1;
471 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700472 // This is set when we are waiting for a wallpaper to tell us it is done
473 // changing its scroll position.
474 WindowState mWaitingOnWallpaper;
475 // The last time we had a timeout when waiting for a wallpaper.
476 long mLastWallpaperTimeoutTime;
477 // We give a wallpaper up to 150ms to finish scrolling.
478 static final long WALLPAPER_TIMEOUT = 150;
479 // Time we wait after a timeout before trying to wait again.
480 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 AppWindowToken mFocusedApp = null;
483
484 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 float mWindowAnimationScale = 1.0f;
487 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700488
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700489 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490
491 // Who is holding the screen on.
492 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700493 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700494
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700495 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700498 * Drag/drop state
499 */
500 class DragState {
501 IBinder mToken;
502 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800503 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700504 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700505 ClipData mData;
506 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700507 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700508 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 float mThumbOffsetX, mThumbOffsetY;
510 InputChannel mServerChannel, mClientChannel;
511 WindowState mTargetWindow;
512 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700513 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700514
Christopher Tateccd24de2011-01-12 15:02:55 -0800515 boolean mPerformDeferredRotation;
516 int mRotation;
517 int mAnimFlags;
518
Christopher Tatea53146c2010-09-07 11:57:52 -0700519 private final Rect tmpRect = new Rect();
520
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800521 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700522 mToken = token;
523 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800524 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700525 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700526 mNotifiedWindows = new ArrayList<WindowState>();
527 }
528
529 void reset() {
530 if (mSurface != null) {
531 mSurface.destroy();
532 }
533 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800534 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700535 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700536 mToken = null;
537 mData = null;
538 mThumbOffsetX = mThumbOffsetY = 0;
539 mNotifiedWindows = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800540 mPerformDeferredRotation = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700541 }
542
543 void register() {
544 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
545 if (mClientChannel != null) {
546 Slog.e(TAG, "Duplicate register of drag input channel");
547 } else {
548 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
549 mServerChannel = channels[0];
550 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800551 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700552 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
553 mH.getLooper().getQueue());
554 }
555 }
556
557 void unregister() {
558 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
559 if (mClientChannel == null) {
560 Slog.e(TAG, "Unregister of nonexistent drag input channel");
561 } else {
562 mInputManager.unregisterInputChannel(mServerChannel);
563 InputQueue.unregisterInputChannel(mClientChannel);
564 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700565 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700566 mClientChannel = null;
567 mServerChannel = null;
568 }
569 }
570
Chris Tatea32dcf72010-10-14 12:13:50 -0700571 int getDragLayerLw() {
572 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
573 * TYPE_LAYER_MULTIPLIER
574 + TYPE_LAYER_OFFSET;
575 }
576
Christopher Tatea53146c2010-09-07 11:57:52 -0700577 /* call out to each visible window/session informing it about the drag
578 */
Chris Tateb8203e92010-10-12 14:23:21 -0700579 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700580 // Cache a base-class instance of the clip metadata so that parceling
581 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700582 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700584 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700585
586 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700587 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 }
589
Christopher Tate2c095f32010-10-04 14:13:40 -0700590 final int N = mWindows.size();
591 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700592 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700593 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700594 }
595
596 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
597 * designated window is potentially a drop recipient. There are race situations
598 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
599 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700600 *
601 * This method clones the 'event' parameter if it's being delivered to the same
602 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700603 */
Chris Tateb478f462010-10-15 16:02:26 -0700604 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
605 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700606 // Don't actually send the event if the drag is supposed to be pinned
607 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800608 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700609 final IBinder winBinder = newWin.mClient.asBinder();
610 if (winBinder != mLocalWin) {
611 if (DEBUG_DRAG) {
612 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
613 }
614 return;
615 }
616 }
617
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700618 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700619 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
620 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800621 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700622 try {
623 newWin.mClient.dispatchDragEvent(event);
624 // track each window that we've notified that the drag is starting
625 mNotifiedWindows.add(newWin);
626 } catch (RemoteException e) {
627 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700628 } finally {
629 // if the callee was local, the dispatch has already recycled the event
630 if (Process.myPid() != newWin.mSession.mPid) {
631 event.recycle();
632 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700633 }
634 }
635 }
636
637 /* helper - construct and send a DRAG_STARTED event only if the window has not
638 * previously been notified, i.e. it became visible after the drag operation
639 * was begun. This is a rare case.
640 */
641 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700642 if (mDragInProgress) {
643 // If we have sent the drag-started, we needn't do so again
644 for (WindowState ws : mNotifiedWindows) {
645 if (ws == newWin) {
646 return;
647 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700648 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700649 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700650 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700651 }
Chris Tateb478f462010-10-15 16:02:26 -0700652 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700653 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700654 }
655
Chris Tated4533f142010-10-19 15:15:08 -0700656 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700657 if (DEBUG_DRAG) {
658 Slog.d(TAG, "broadcasting DRAG_ENDED");
659 }
Chris Tated4533f142010-10-19 15:15:08 -0700660 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800661 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700662 for (WindowState ws: mNotifiedWindows) {
663 try {
664 ws.mClient.dispatchDragEvent(evt);
665 } catch (RemoteException e) {
666 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700667 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700668 }
Chris Tated4533f142010-10-19 15:15:08 -0700669 mNotifiedWindows.clear();
670 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700671 evt.recycle();
672 }
673
Chris Tated4533f142010-10-19 15:15:08 -0700674 void endDragLw() {
675 mDragState.broadcastDragEndedLw();
676
677 // stop intercepting input
678 mDragState.unregister();
679 mInputMonitor.updateInputWindowsLw();
680
Christopher Tateccd24de2011-01-12 15:02:55 -0800681 // Retain the parameters of any deferred rotation operation so
682 // that we can perform it after the reset / unref of the drag state
683 final boolean performRotation = mPerformDeferredRotation;
684 final int rotation = mRotation;
685 final int animFlags = mAnimFlags;
686
Chris Tated4533f142010-10-19 15:15:08 -0700687 // free our resources and drop all the object references
688 mDragState.reset();
689 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800690
691 // Now that we've officially ended the drag, execute any
692 // deferred rotation
693 if (performRotation) {
694 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800695 boolean changed = setRotationUncheckedLocked(rotation, animFlags, false);
Christopher Tateccd24de2011-01-12 15:02:55 -0800696 if (changed) {
697 sendNewConfiguration();
698 }
699 }
Chris Tated4533f142010-10-19 15:15:08 -0700700 }
701
Christopher Tatea53146c2010-09-07 11:57:52 -0700702 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700703 final int myPid = Process.myPid();
704
705 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800706 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tate2c095f32010-10-04 14:13:40 -0700707 mSurface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800708 try {
709 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
710 } finally {
711 mSurface.closeTransaction();
712 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
713 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700714
715 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700716 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800717 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700718 final IBinder touchedBinder = touchedWin.mClient.asBinder();
719 if (touchedBinder != mLocalWin) {
720 // This drag is pinned only to the originating window, but the drag
721 // point is outside that window. Pretend it's over empty space.
722 touchedWin = null;
723 }
724 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700725 try {
726 // have we dragged over a new window?
727 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
728 if (DEBUG_DRAG) {
729 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
730 }
731 // force DRAG_EXITED_EVENT if appropriate
732 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700733 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800734 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700735 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700736 if (myPid != mTargetWindow.mSession.mPid) {
737 evt.recycle();
738 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700739 }
740 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700741 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700742 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
743 }
744 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700745 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800746 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700747 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700748 if (myPid != touchedWin.mSession.mPid) {
749 evt.recycle();
750 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700751 }
752 } catch (RemoteException e) {
753 Slog.w(TAG, "can't send drag notification to windows");
754 }
755 mTargetWindow = touchedWin;
756 }
757
Chris Tated4533f142010-10-19 15:15:08 -0700758 // Tell the drop target about the data. Returns 'true' if we can immediately
759 // dispatch the global drag-ended message, 'false' if we need to wait for a
760 // result from the recipient.
761 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700762 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700763 if (touchedWin == null) {
764 // "drop" outside a valid window -- no recipient to apply a
765 // timeout to, and we can send the drag-ended message immediately.
766 mDragResult = false;
767 return true;
768 }
769
770 if (DEBUG_DRAG) {
771 Slog.d(TAG, "sending DROP to " + touchedWin);
772 }
773 final int myPid = Process.myPid();
774 final IBinder token = touchedWin.mClient.asBinder();
775 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
776 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800777 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700778 try {
779 touchedWin.mClient.dispatchDragEvent(evt);
780
781 // 5 second timeout for this window to respond to the drop
782 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
783 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
784 mH.sendMessageDelayed(msg, 5000);
785 } catch (RemoteException e) {
786 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
787 return true;
788 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700789 if (myPid != touchedWin.mSession.mPid) {
790 evt.recycle();
791 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700792 }
Chris Tated4533f142010-10-19 15:15:08 -0700793 mToken = token;
794 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700795 }
796
797 // Find the visible, touch-deliverable window under the given point
798 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
799 WindowState touchedWin = null;
800 final int x = (int) xf;
801 final int y = (int) yf;
802 final ArrayList<WindowState> windows = mWindows;
803 final int N = windows.size();
804 for (int i = N - 1; i >= 0; i--) {
805 WindowState child = windows.get(i);
806 final int flags = child.mAttrs.flags;
807 if (!child.isVisibleLw()) {
808 // not visible == don't tell about drags
809 continue;
810 }
811 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
812 // not touchable == don't tell about drags
813 continue;
814 }
815 // account for the window's decor etc
816 tmpRect.set(child.mFrame);
817 if (child.mTouchableInsets == ViewTreeObserver
818 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
819 // The point is inside of the window if it is
820 // inside the frame, AND the content part of that
821 // frame that was given by the application.
822 tmpRect.left += child.mGivenContentInsets.left;
823 tmpRect.top += child.mGivenContentInsets.top;
824 tmpRect.right -= child.mGivenContentInsets.right;
825 tmpRect.bottom -= child.mGivenContentInsets.bottom;
826 } else if (child.mTouchableInsets == ViewTreeObserver
827 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
828 // The point is inside of the window if it is
829 // inside the frame, AND the visible part of that
830 // frame that was given by the application.
831 tmpRect.left += child.mGivenVisibleInsets.left;
832 tmpRect.top += child.mGivenVisibleInsets.top;
833 tmpRect.right -= child.mGivenVisibleInsets.right;
834 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
835 }
836 final int touchFlags = flags &
837 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
838 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
839 if (tmpRect.contains(x, y) || touchFlags == 0) {
840 // Found it
841 touchedWin = child;
842 break;
843 }
844 }
845
846 return touchedWin;
847 }
Christopher Tateccd24de2011-01-12 15:02:55 -0800848
849 void setDeferredRotation(int rotation, int animFlags) {
850 mRotation = rotation;
851 mAnimFlags = animFlags;
852 mPerformDeferredRotation = true;
853 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700854 }
855
856 DragState mDragState = null;
857 private final InputHandler mDragInputHandler = new BaseInputHandler() {
858 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700859 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
860 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700861 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700862 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
863 && mDragState != null) {
864 boolean endDrag = false;
865 final float newX = event.getRawX();
866 final float newY = event.getRawY();
867
Christopher Tatea53146c2010-09-07 11:57:52 -0700868 switch (event.getAction()) {
869 case MotionEvent.ACTION_DOWN: {
870 if (DEBUG_DRAG) {
871 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
872 }
873 } break;
874
875 case MotionEvent.ACTION_MOVE: {
876 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700877 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700878 mDragState.notifyMoveLw(newX, newY);
879 }
880 } break;
881
882 case MotionEvent.ACTION_UP: {
883 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
884 + newX + "," + newY);
885 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700886 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700887 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700888 } break;
889
890 case MotionEvent.ACTION_CANCEL: {
891 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
892 endDrag = true;
893 } break;
894 }
895
896 if (endDrag) {
897 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
898 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700899 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700900 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700901 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700902 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700903
904 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700905 }
906 } catch (Exception e) {
907 Slog.e(TAG, "Exception caught by drag handleMotion", e);
908 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700909 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700910 }
911 }
912 };
913
914 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 * Whether the UI is currently running in touch mode (not showing
916 * navigational focus because the user is directly pressing the screen).
917 */
918 boolean mInTouchMode = false;
919
920 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700921 private ArrayList<WindowChangeListener> mWindowChangeListeners =
922 new ArrayList<WindowChangeListener>();
923 private boolean mWindowsChanged = false;
924
925 public interface WindowChangeListener {
926 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700927 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929
Dianne Hackbornc485a602009-03-24 22:39:49 -0700930 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700931 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700932
933 // The frame use to limit the size of the app running in compatibility mode.
934 Rect mCompatibleScreenFrame = new Rect();
935 // The surface used to fill the outer rim of the app running in compatibility mode.
936 Surface mBackgroundFillerSurface = null;
937 boolean mBackgroundFillerShown = false;
938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 public static WindowManagerService main(Context context,
940 PowerManagerService pm, boolean haveInputMethods) {
941 WMThread thr = new WMThread(context, pm, haveInputMethods);
942 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 synchronized (thr) {
945 while (thr.mService == null) {
946 try {
947 thr.wait();
948 } catch (InterruptedException e) {
949 }
950 }
951 }
Romain Guy06882f82009-06-10 13:36:04 -0700952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 return thr.mService;
954 }
Romain Guy06882f82009-06-10 13:36:04 -0700955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 static class WMThread extends Thread {
957 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 private final Context mContext;
960 private final PowerManagerService mPM;
961 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 public WMThread(Context context, PowerManagerService pm,
964 boolean haveInputMethods) {
965 super("WindowManager");
966 mContext = context;
967 mPM = pm;
968 mHaveInputMethods = haveInputMethods;
969 }
Romain Guy06882f82009-06-10 13:36:04 -0700970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 public void run() {
972 Looper.prepare();
973 WindowManagerService s = new WindowManagerService(mContext, mPM,
974 mHaveInputMethods);
975 android.os.Process.setThreadPriority(
976 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700977 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 synchronized (this) {
980 mService = s;
981 notifyAll();
982 }
Romain Guy06882f82009-06-10 13:36:04 -0700983
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700984 // For debug builds, log event loop stalls to dropbox for analysis.
985 if (StrictMode.conditionallyEnableDebugLogging()) {
986 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
987 }
988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 Looper.loop();
990 }
991 }
992
993 static class PolicyThread extends Thread {
994 private final WindowManagerPolicy mPolicy;
995 private final WindowManagerService mService;
996 private final Context mContext;
997 private final PowerManagerService mPM;
998 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 public PolicyThread(WindowManagerPolicy policy,
1001 WindowManagerService service, Context context,
1002 PowerManagerService pm) {
1003 super("WindowManagerPolicy");
1004 mPolicy = policy;
1005 mService = service;
1006 mContext = context;
1007 mPM = pm;
1008 }
Romain Guy06882f82009-06-10 13:36:04 -07001009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 public void run() {
1011 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -08001012 WindowManagerPolicyThread.set(this, Looper.myLooper());
1013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -08001015 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 android.os.Process.setThreadPriority(
1017 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -07001018 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -07001020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 synchronized (this) {
1022 mRunning = true;
1023 notifyAll();
1024 }
Romain Guy06882f82009-06-10 13:36:04 -07001025
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001026 // For debug builds, log event loop stalls to dropbox for analysis.
1027 if (StrictMode.conditionallyEnableDebugLogging()) {
1028 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1029 }
1030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 Looper.loop();
1032 }
1033 }
1034
1035 private WindowManagerService(Context context, PowerManagerService pm,
1036 boolean haveInputMethods) {
1037 mContext = context;
1038 mHaveInputMethods = haveInputMethods;
1039 mLimitedAlphaCompositing = context.getResources().getBoolean(
1040 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 mPowerManager = pm;
1043 mPowerManager.setPolicy(mPolicy);
1044 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1045 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1046 "SCREEN_FROZEN");
1047 mScreenFrozenLock.setReferenceCounted(false);
1048
1049 mActivityManager = ActivityManagerNative.getDefault();
1050 mBatteryStats = BatteryStatsService.getService();
1051
1052 // Get persisted window scale setting
1053 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1054 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1055 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1056 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001057
Jim Miller284b62e2010-06-08 14:27:42 -07001058 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1059 IntentFilter filter = new IntentFilter();
1060 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1061 mContext.registerReceiver(mBroadcastReceiver, filter);
1062
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001063 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1064 "KEEP_SCREEN_ON_FLAG");
1065 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066
Jeff Browne33348b2010-07-15 23:54:05 -07001067 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1070 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 synchronized (thr) {
1073 while (!thr.mRunning) {
1074 try {
1075 thr.wait();
1076 } catch (InterruptedException e) {
1077 }
1078 }
1079 }
Romain Guy06882f82009-06-10 13:36:04 -07001080
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001081 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 // Add ourself to the Watchdog monitors.
1084 Watchdog.getInstance().addMonitor(this);
1085 }
1086
1087 @Override
1088 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1089 throws RemoteException {
1090 try {
1091 return super.onTransact(code, data, reply, flags);
1092 } catch (RuntimeException e) {
1093 // The window manager only throws security exceptions, so let's
1094 // log all others.
1095 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001096 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 }
1098 throw e;
1099 }
1100 }
1101
Jeff Browne33348b2010-07-15 23:54:05 -07001102 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001104 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 TAG, "Adding window " + window + " at "
1106 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1107 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001108 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 }
1110
Jeff Browne33348b2010-07-15 23:54:05 -07001111 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001113 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 TAG, "Adding window " + window + " at "
1115 + i + " of " + mWindows.size() + " (before " + pos + ")");
1116 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001117 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 }
1119
1120 //This method finds out the index of a window that has the same app token as
1121 //win. used for z ordering the windows in mWindows
1122 private int findIdxBasedOnAppTokens(WindowState win) {
1123 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001124 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 int jmax = localmWindows.size();
1126 if(jmax == 0) {
1127 return -1;
1128 }
1129 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001130 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 if(wentry.mAppToken == win.mAppToken) {
1132 return j;
1133 }
1134 }
1135 return -1;
1136 }
Romain Guy06882f82009-06-10 13:36:04 -07001137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1139 final IWindow client = win.mClient;
1140 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001141 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 final int N = localmWindows.size();
1144 final WindowState attached = win.mAttachedWindow;
1145 int i;
1146 if (attached == null) {
1147 int tokenWindowsPos = token.windows.size();
1148 if (token.appWindowToken != null) {
1149 int index = tokenWindowsPos-1;
1150 if (index >= 0) {
1151 // If this application has existing windows, we
1152 // simply place the new window on top of them... but
1153 // keep the starting window on top.
1154 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1155 // Base windows go behind everything else.
1156 placeWindowBefore(token.windows.get(0), win);
1157 tokenWindowsPos = 0;
1158 } else {
1159 AppWindowToken atoken = win.mAppToken;
1160 if (atoken != null &&
1161 token.windows.get(index) == atoken.startingWindow) {
1162 placeWindowBefore(token.windows.get(index), win);
1163 tokenWindowsPos--;
1164 } else {
1165 int newIdx = findIdxBasedOnAppTokens(win);
1166 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001167 //there is a window above this one associated with the same
1168 //apptoken note that the window could be a floating window
1169 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001171 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1172 Slog.v(TAG, "Adding window " + win + " at "
1173 + (newIdx+1) + " of " + N);
1174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001176 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 }
1179 }
1180 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001181 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 TAG, "Figuring out where to add app window "
1183 + client.asBinder() + " (token=" + token + ")");
1184 // Figure out where the window should go, based on the
1185 // order of applications.
1186 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001187 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 for (i=NA-1; i>=0; i--) {
1189 AppWindowToken t = mAppTokens.get(i);
1190 if (t == token) {
1191 i--;
1192 break;
1193 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001194
Dianne Hackborna8f60182009-09-01 19:01:50 -07001195 // We haven't reached the token yet; if this token
1196 // is not going to the bottom and has windows, we can
1197 // use it as an anchor for when we do reach the token.
1198 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 pos = t.windows.get(0);
1200 }
1201 }
1202 // We now know the index into the apps. If we found
1203 // an app window above, that gives us the position; else
1204 // we need to look some more.
1205 if (pos != null) {
1206 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001207 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 if (atoken != null) {
1209 final int NC = atoken.windows.size();
1210 if (NC > 0) {
1211 WindowState bottom = atoken.windows.get(0);
1212 if (bottom.mSubLayer < 0) {
1213 pos = bottom;
1214 }
1215 }
1216 }
1217 placeWindowBefore(pos, win);
1218 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001219 // Continue looking down until we find the first
1220 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 while (i >= 0) {
1222 AppWindowToken t = mAppTokens.get(i);
1223 final int NW = t.windows.size();
1224 if (NW > 0) {
1225 pos = t.windows.get(NW-1);
1226 break;
1227 }
1228 i--;
1229 }
1230 if (pos != null) {
1231 // Move in front of any windows attached to this
1232 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001233 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 if (atoken != null) {
1235 final int NC = atoken.windows.size();
1236 if (NC > 0) {
1237 WindowState top = atoken.windows.get(NC-1);
1238 if (top.mSubLayer >= 0) {
1239 pos = top;
1240 }
1241 }
1242 }
1243 placeWindowAfter(pos, win);
1244 } else {
1245 // Just search for the start of this layer.
1246 final int myLayer = win.mBaseLayer;
1247 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001248 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 if (w.mBaseLayer > myLayer) {
1250 break;
1251 }
1252 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001253 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1254 Slog.v(TAG, "Adding window " + win + " at "
1255 + i + " of " + N);
1256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001258 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 }
1260 }
1261 }
1262 } else {
1263 // Figure out where window should go, based on layer.
1264 final int myLayer = win.mBaseLayer;
1265 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001266 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 i++;
1268 break;
1269 }
1270 }
1271 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001272 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001273 TAG, "Adding window " + win + " at "
1274 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001276 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 }
1278 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001279 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 token.windows.add(tokenWindowsPos, win);
1281 }
1282
1283 } else {
1284 // Figure out this window's ordering relative to the window
1285 // it is attached to.
1286 final int NA = token.windows.size();
1287 final int sublayer = win.mSubLayer;
1288 int largestSublayer = Integer.MIN_VALUE;
1289 WindowState windowWithLargestSublayer = null;
1290 for (i=0; i<NA; i++) {
1291 WindowState w = token.windows.get(i);
1292 final int wSublayer = w.mSubLayer;
1293 if (wSublayer >= largestSublayer) {
1294 largestSublayer = wSublayer;
1295 windowWithLargestSublayer = w;
1296 }
1297 if (sublayer < 0) {
1298 // For negative sublayers, we go below all windows
1299 // in the same sublayer.
1300 if (wSublayer >= sublayer) {
1301 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001302 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303 token.windows.add(i, win);
1304 }
1305 placeWindowBefore(
1306 wSublayer >= 0 ? attached : w, win);
1307 break;
1308 }
1309 } else {
1310 // For positive sublayers, we go above all windows
1311 // in the same sublayer.
1312 if (wSublayer > sublayer) {
1313 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001314 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 token.windows.add(i, win);
1316 }
1317 placeWindowBefore(w, win);
1318 break;
1319 }
1320 }
1321 }
1322 if (i >= NA) {
1323 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001324 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 token.windows.add(win);
1326 }
1327 if (sublayer < 0) {
1328 placeWindowBefore(attached, win);
1329 } else {
1330 placeWindowAfter(largestSublayer >= 0
1331 ? windowWithLargestSublayer
1332 : attached,
1333 win);
1334 }
1335 }
1336 }
Romain Guy06882f82009-06-10 13:36:04 -07001337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 if (win.mAppToken != null && addToToken) {
1339 win.mAppToken.allAppWindows.add(win);
1340 }
1341 }
Romain Guy06882f82009-06-10 13:36:04 -07001342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 static boolean canBeImeTarget(WindowState w) {
1344 final int fl = w.mAttrs.flags
1345 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1346 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1347 return w.isVisibleOrAdding();
1348 }
1349 return false;
1350 }
Romain Guy06882f82009-06-10 13:36:04 -07001351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001353 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 final int N = localmWindows.size();
1355 WindowState w = null;
1356 int i = N;
1357 while (i > 0) {
1358 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001359 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001360
Joe Onorato8a9b2202010-02-26 18:56:32 -08001361 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 // + Integer.toHexString(w.mAttrs.flags));
1363 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001364 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 // Yet more tricksyness! If this window is a "starting"
1367 // window, we do actually want to be on top of it, but
1368 // it is not -really- where input will go. So if the caller
1369 // is not actually looking to move the IME, look down below
1370 // for a real window to target...
1371 if (!willMove
1372 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1373 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001374 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1376 i--;
1377 w = wb;
1378 }
1379 }
1380 break;
1381 }
1382 }
Romain Guy06882f82009-06-10 13:36:04 -07001383
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001384 // Now, a special case -- if the last target's window is in the
1385 // process of exiting, and is above the new target, keep on the
1386 // last target to avoid flicker. Consider for example a Dialog with
1387 // the IME shown: when the Dialog is dismissed, we want to keep
1388 // the IME above it until it is completely gone so it doesn't drop
1389 // behind the dialog or its full-screen scrim.
1390 if (mInputMethodTarget != null && w != null
1391 && mInputMethodTarget.isDisplayedLw()
1392 && mInputMethodTarget.mExiting) {
1393 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1394 w = mInputMethodTarget;
1395 i = localmWindows.indexOf(w);
1396 }
1397 }
Romain Guy06882f82009-06-10 13:36:04 -07001398
Joe Onorato8a9b2202010-02-26 18:56:32 -08001399 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 if (willMove && w != null) {
1403 final WindowState curTarget = mInputMethodTarget;
1404 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 // Now some fun for dealing with window animations that
1407 // modify the Z order. We need to look at all windows below
1408 // the current target that are in this app, finding the highest
1409 // visible one in layering.
1410 AppWindowToken token = curTarget.mAppToken;
1411 WindowState highestTarget = null;
1412 int highestPos = 0;
1413 if (token.animating || token.animation != null) {
1414 int pos = 0;
1415 pos = localmWindows.indexOf(curTarget);
1416 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001417 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418 if (win.mAppToken != token) {
1419 break;
1420 }
1421 if (!win.mRemoved) {
1422 if (highestTarget == null || win.mAnimLayer >
1423 highestTarget.mAnimLayer) {
1424 highestTarget = win;
1425 highestPos = pos;
1426 }
1427 }
1428 pos--;
1429 }
1430 }
Romain Guy06882f82009-06-10 13:36:04 -07001431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 + mNextAppTransition + " " + highestTarget
1435 + " animating=" + highestTarget.isAnimating()
1436 + " layer=" + highestTarget.mAnimLayer
1437 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001438
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001439 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 // If we are currently setting up for an animation,
1441 // hold everything until we can find out what will happen.
1442 mInputMethodTargetWaitingAnim = true;
1443 mInputMethodTarget = highestTarget;
1444 return highestPos + 1;
1445 } else if (highestTarget.isAnimating() &&
1446 highestTarget.mAnimLayer > w.mAnimLayer) {
1447 // If the window we are currently targeting is involved
1448 // with an animation, and it is on top of the next target
1449 // we will be over, then hold off on moving until
1450 // that is done.
1451 mInputMethodTarget = highestTarget;
1452 return highestPos + 1;
1453 }
1454 }
1455 }
1456 }
Romain Guy06882f82009-06-10 13:36:04 -07001457
Joe Onorato8a9b2202010-02-26 18:56:32 -08001458 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 if (w != null) {
1460 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001461 if (DEBUG_INPUT_METHOD) {
1462 RuntimeException e = null;
1463 if (!HIDE_STACK_CRAWLS) {
1464 e = new RuntimeException();
1465 e.fillInStackTrace();
1466 }
1467 Slog.w(TAG, "Moving IM target from "
1468 + mInputMethodTarget + " to " + w, e);
1469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 mInputMethodTarget = w;
1471 if (w.mAppToken != null) {
1472 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1473 } else {
1474 setInputMethodAnimLayerAdjustment(0);
1475 }
1476 }
1477 return i+1;
1478 }
1479 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001480 if (DEBUG_INPUT_METHOD) {
1481 RuntimeException e = null;
1482 if (!HIDE_STACK_CRAWLS) {
1483 e = new RuntimeException();
1484 e.fillInStackTrace();
1485 }
1486 Slog.w(TAG, "Moving IM target from "
1487 + mInputMethodTarget + " to null", e);
1488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 mInputMethodTarget = null;
1490 setInputMethodAnimLayerAdjustment(0);
1491 }
1492 return -1;
1493 }
Romain Guy06882f82009-06-10 13:36:04 -07001494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 void addInputMethodWindowToListLocked(WindowState win) {
1496 int pos = findDesiredInputMethodWindowIndexLocked(true);
1497 if (pos >= 0) {
1498 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001499 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001500 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001502 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 moveInputMethodDialogsLocked(pos+1);
1504 return;
1505 }
1506 win.mTargetAppToken = null;
1507 addWindowToListInOrderLocked(win, true);
1508 moveInputMethodDialogsLocked(pos);
1509 }
Romain Guy06882f82009-06-10 13:36:04 -07001510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001512 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 mInputMethodAnimLayerAdjustment = adj;
1514 WindowState imw = mInputMethodWindow;
1515 if (imw != null) {
1516 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001517 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 + " anim layer: " + imw.mAnimLayer);
1519 int wi = imw.mChildWindows.size();
1520 while (wi > 0) {
1521 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001522 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001524 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 + " anim layer: " + cw.mAnimLayer);
1526 }
1527 }
1528 int di = mInputMethodDialogs.size();
1529 while (di > 0) {
1530 di --;
1531 imw = mInputMethodDialogs.get(di);
1532 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001533 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 + " anim layer: " + imw.mAnimLayer);
1535 }
1536 }
Romain Guy06882f82009-06-10 13:36:04 -07001537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1539 int wpos = mWindows.indexOf(win);
1540 if (wpos >= 0) {
1541 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001542 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001544 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 int NC = win.mChildWindows.size();
1546 while (NC > 0) {
1547 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001548 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 int cpos = mWindows.indexOf(cw);
1550 if (cpos >= 0) {
1551 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001552 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001553 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001554 mWindows.remove(cpos);
1555 }
1556 }
1557 }
1558 return interestingPos;
1559 }
Romain Guy06882f82009-06-10 13:36:04 -07001560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 private void reAddWindowToListInOrderLocked(WindowState win) {
1562 addWindowToListInOrderLocked(win, false);
1563 // This is a hack to get all of the child windows added as well
1564 // at the right position. Child windows should be rare and
1565 // this case should be rare, so it shouldn't be that big a deal.
1566 int wpos = mWindows.indexOf(win);
1567 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001568 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001569 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001571 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 reAddWindowLocked(wpos, win);
1573 }
1574 }
Romain Guy06882f82009-06-10 13:36:04 -07001575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 void logWindowList(String prefix) {
1577 int N = mWindows.size();
1578 while (N > 0) {
1579 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001580 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 }
1582 }
Romain Guy06882f82009-06-10 13:36:04 -07001583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 void moveInputMethodDialogsLocked(int pos) {
1585 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001588 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 for (int i=0; i<N; i++) {
1590 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1591 }
1592 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001593 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 logWindowList(" ");
1595 }
Romain Guy06882f82009-06-10 13:36:04 -07001596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 if (pos >= 0) {
1598 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1599 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001600 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 if (wp == mInputMethodWindow) {
1602 pos++;
1603 }
1604 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001605 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 for (int i=0; i<N; i++) {
1607 WindowState win = dialogs.get(i);
1608 win.mTargetAppToken = targetAppToken;
1609 pos = reAddWindowLocked(pos, win);
1610 }
1611 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001612 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 logWindowList(" ");
1614 }
1615 return;
1616 }
1617 for (int i=0; i<N; i++) {
1618 WindowState win = dialogs.get(i);
1619 win.mTargetAppToken = null;
1620 reAddWindowToListInOrderLocked(win);
1621 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001622 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 logWindowList(" ");
1624 }
1625 }
1626 }
Romain Guy06882f82009-06-10 13:36:04 -07001627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1629 final WindowState imWin = mInputMethodWindow;
1630 final int DN = mInputMethodDialogs.size();
1631 if (imWin == null && DN == 0) {
1632 return false;
1633 }
Romain Guy06882f82009-06-10 13:36:04 -07001634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1636 if (imPos >= 0) {
1637 // In this case, the input method windows are to be placed
1638 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 // First check to see if the input method windows are already
1641 // located here, and contiguous.
1642 final int N = mWindows.size();
1643 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001644 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 // Figure out the actual input method window that should be
1647 // at the bottom of their stack.
1648 WindowState baseImWin = imWin != null
1649 ? imWin : mInputMethodDialogs.get(0);
1650 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001651 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 if (cw.mSubLayer < 0) baseImWin = cw;
1653 }
Romain Guy06882f82009-06-10 13:36:04 -07001654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 if (firstImWin == baseImWin) {
1656 // The windows haven't moved... but are they still contiguous?
1657 // First find the top IM window.
1658 int pos = imPos+1;
1659 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001660 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 break;
1662 }
1663 pos++;
1664 }
1665 pos++;
1666 // Now there should be no more input method windows above.
1667 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001668 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 break;
1670 }
1671 pos++;
1672 }
1673 if (pos >= N) {
1674 // All is good!
1675 return false;
1676 }
1677 }
Romain Guy06882f82009-06-10 13:36:04 -07001678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 if (imWin != null) {
1680 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001681 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 logWindowList(" ");
1683 }
1684 imPos = tmpRemoveWindowLocked(imPos, imWin);
1685 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001686 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 logWindowList(" ");
1688 }
1689 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1690 reAddWindowLocked(imPos, imWin);
1691 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001692 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 logWindowList(" ");
1694 }
1695 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1696 } else {
1697 moveInputMethodDialogsLocked(imPos);
1698 }
Romain Guy06882f82009-06-10 13:36:04 -07001699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 } else {
1701 // In this case, the input method windows go in a fixed layer,
1702 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001705 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 tmpRemoveWindowLocked(0, imWin);
1707 imWin.mTargetAppToken = null;
1708 reAddWindowToListInOrderLocked(imWin);
1709 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001710 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 logWindowList(" ");
1712 }
1713 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1714 } else {
1715 moveInputMethodDialogsLocked(-1);;
1716 }
Romain Guy06882f82009-06-10 13:36:04 -07001717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 }
Romain Guy06882f82009-06-10 13:36:04 -07001719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 if (needAssignLayers) {
1721 assignLayersLocked();
1722 }
Romain Guy06882f82009-06-10 13:36:04 -07001723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 return true;
1725 }
Romain Guy06882f82009-06-10 13:36:04 -07001726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001727 void adjustInputMethodDialogsLocked() {
1728 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1729 }
Romain Guy06882f82009-06-10 13:36:04 -07001730
Dianne Hackborn25994b42009-09-04 14:21:19 -07001731 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001732 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001733 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1734 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1735 ? wallpaperTarget.mAppToken.animation : null)
1736 + " upper=" + mUpperWallpaperTarget
1737 + " lower=" + mLowerWallpaperTarget);
1738 return (wallpaperTarget != null
1739 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1740 && wallpaperTarget.mAppToken.animation != null)))
1741 || mUpperWallpaperTarget != null
1742 || mLowerWallpaperTarget != null;
1743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001744
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001745 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1746 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001747
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001748 int adjustWallpaperWindowsLocked() {
1749 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001750
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001751 final int dw = mDisplay.getWidth();
1752 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001753
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001754 // First find top-most window that has asked to be on top of the
1755 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001756 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001757 int N = localmWindows.size();
1758 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001759 WindowState foundW = null;
1760 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001761 WindowState topCurW = null;
1762 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001763 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001764 int i = N;
1765 while (i > 0) {
1766 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001767 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001768 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1769 if (topCurW == null) {
1770 topCurW = w;
1771 topCurI = i;
1772 }
1773 continue;
1774 }
1775 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001776 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001777 // If this window's app token is hidden and not animating,
1778 // it is of no interest to us.
1779 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001780 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001781 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001782 continue;
1783 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001784 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001785 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001786 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1787 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001788 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001789 && (mWallpaperTarget == w
1790 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001791 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001792 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001793 foundW = w;
1794 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001795 if (w == mWallpaperTarget && ((w.mAppToken != null
1796 && w.mAppToken.animation != null)
1797 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001798 // The current wallpaper target is animating, so we'll
1799 // look behind it for another possible target and figure
1800 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001801 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001802 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001803 continue;
1804 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001805 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001806 } else if (w == mWindowDetachedWallpaper) {
1807 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001808 }
1809 }
1810
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001811 if (foundW == null && windowDetachedI >= 0) {
1812 if (DEBUG_WALLPAPER) Slog.v(TAG,
1813 "Found animating detached wallpaper activity: #" + i + "=" + w);
1814 foundW = w;
1815 foundI = windowDetachedI;
1816 }
1817
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001818 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001819 // If we are currently waiting for an app transition, and either
1820 // the current target or the next target are involved with it,
1821 // then hold off on doing anything with the wallpaper.
1822 // Note that we are checking here for just whether the target
1823 // is part of an app token... which is potentially overly aggressive
1824 // (the app token may not be involved in the transition), but good
1825 // enough (we'll just wait until whatever transition is pending
1826 // executes).
1827 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001828 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001829 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001830 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001831 }
1832 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001834 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001835 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001836 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001837 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001838
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001839 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001840 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001841 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001842 + " oldTarget: " + mWallpaperTarget);
1843 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001844
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001845 mLowerWallpaperTarget = null;
1846 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001847
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001848 WindowState oldW = mWallpaperTarget;
1849 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001850
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001851 // Now what is happening... if the current and new targets are
1852 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001853 if (foundW != null && oldW != null) {
1854 boolean oldAnim = oldW.mAnimation != null
1855 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1856 boolean foundAnim = foundW.mAnimation != null
1857 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001858 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001859 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001860 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001861 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001862 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001863 int oldI = localmWindows.indexOf(oldW);
1864 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001865 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001866 }
1867 if (oldI >= 0) {
1868 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 + "=" + oldW + "; new#" + foundI
1871 + "=" + foundW);
1872 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001873
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001874 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001875 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001876 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001877 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001878 }
1879 mWallpaperTarget = oldW;
1880 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001881
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001882 // Now set the upper and lower wallpaper targets
1883 // correctly, and make sure that we are positioning
1884 // the wallpaper below the lower.
1885 if (foundI > oldI) {
1886 // The new target is on top of the old one.
1887 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001888 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001889 }
1890 mUpperWallpaperTarget = foundW;
1891 mLowerWallpaperTarget = oldW;
1892 foundW = oldW;
1893 foundI = oldI;
1894 } else {
1895 // The new target is below the old one.
1896 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001897 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001898 }
1899 mUpperWallpaperTarget = oldW;
1900 mLowerWallpaperTarget = foundW;
1901 }
1902 }
1903 }
1904 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001905
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001906 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001907 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001908 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1909 || (mLowerWallpaperTarget.mAppToken != null
1910 && mLowerWallpaperTarget.mAppToken.animation != null);
1911 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1912 || (mUpperWallpaperTarget.mAppToken != null
1913 && mUpperWallpaperTarget.mAppToken.animation != null);
1914 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001915 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001916 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001917 }
1918 mLowerWallpaperTarget = null;
1919 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001920 }
1921 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001922
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001923 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001924 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001925 // The window is visible to the compositor... but is it visible
1926 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001927 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001928 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001929
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001930 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001931 // its layer adjustment. Only do this if we are not transfering
1932 // between two wallpaper targets.
1933 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001934 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001935 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001936
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001937 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1938 * TYPE_LAYER_MULTIPLIER
1939 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001940
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001941 // Now w is the window we are supposed to be behind... but we
1942 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001943 // AND any starting window associated with it, AND below the
1944 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001945 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001946 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001947 if (wb.mBaseLayer < maxLayer &&
1948 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001949 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001950 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001951 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001952 // This window is not related to the previous one in any
1953 // interesting way, so stop here.
1954 break;
1955 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001956 foundW = wb;
1957 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001958 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001959 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001960 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001961 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001962
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001963 if (foundW == null && topCurW != null) {
1964 // There is no wallpaper target, so it goes at the bottom.
1965 // We will assume it is the same place as last time, if known.
1966 foundW = topCurW;
1967 foundI = topCurI+1;
1968 } else {
1969 // Okay i is the position immediately above the wallpaper. Look at
1970 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001971 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001972 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001973
Dianne Hackborn284ac932009-08-28 10:34:25 -07001974 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001975 if (mWallpaperTarget.mWallpaperX >= 0) {
1976 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001977 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001978 }
1979 if (mWallpaperTarget.mWallpaperY >= 0) {
1980 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001981 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001982 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001983 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001984
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001985 // Start stepping backwards from here, ensuring that our wallpaper windows
1986 // are correctly placed.
1987 int curTokenIndex = mWallpaperTokens.size();
1988 while (curTokenIndex > 0) {
1989 curTokenIndex--;
1990 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001991 if (token.hidden == visible) {
1992 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1993 token.hidden = !visible;
1994 // Need to do a layout to ensure the wallpaper now has the
1995 // correct size.
1996 mLayoutNeeded = true;
1997 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001998
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001999 int curWallpaperIndex = token.windows.size();
2000 while (curWallpaperIndex > 0) {
2001 curWallpaperIndex--;
2002 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002003
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002004 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002005 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002006 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002007
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002008 // First, make sure the client has the current visibility
2009 // state.
2010 if (wallpaper.mWallpaperVisible != visible) {
2011 wallpaper.mWallpaperVisible = visible;
2012 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002014 "Setting visibility of wallpaper " + wallpaper
2015 + ": " + visible);
2016 wallpaper.mClient.dispatchAppVisibility(visible);
2017 } catch (RemoteException e) {
2018 }
2019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002020
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002021 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002022 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002023 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002024
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002025 // First, if this window is at the current index, then all
2026 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002027 if (wallpaper == foundW) {
2028 foundI--;
2029 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002030 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002031 continue;
2032 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002033
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002034 // The window didn't match... the current wallpaper window,
2035 // wherever it is, is in the wrong place, so make sure it is
2036 // not in the list.
2037 int oldIndex = localmWindows.indexOf(wallpaper);
2038 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002039 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002040 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002041 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002042 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002043 if (oldIndex < foundI) {
2044 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002045 }
2046 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002047
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002048 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002049 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2050 Slog.v(TAG, "Moving wallpaper " + wallpaper
2051 + " from " + oldIndex + " to " + foundI);
2052 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002053
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002054 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002055 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002056 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002057 }
2058 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002059
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002060 return changed;
2061 }
2062
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002063 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002064 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002065 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002066 mWallpaperAnimLayerAdjustment = adj;
2067 int curTokenIndex = mWallpaperTokens.size();
2068 while (curTokenIndex > 0) {
2069 curTokenIndex--;
2070 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2071 int curWallpaperIndex = token.windows.size();
2072 while (curWallpaperIndex > 0) {
2073 curWallpaperIndex--;
2074 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2075 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002076 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002077 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002078 }
2079 }
2080 }
2081
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002082 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2083 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002084 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002085 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002086 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002087 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2089 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2090 changed = wallpaperWin.mXOffset != offset;
2091 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002092 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002093 + wallpaperWin + " x: " + offset);
2094 wallpaperWin.mXOffset = offset;
2095 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002096 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002097 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002098 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002099 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002101
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002102 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002103 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002104 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2105 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2106 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002107 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002108 + wallpaperWin + " y: " + offset);
2109 changed = true;
2110 wallpaperWin.mYOffset = offset;
2111 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002112 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002113 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002114 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002115 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002116 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002117
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002118 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002119 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002120 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002121 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2122 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002123 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002124 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002125 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002126 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002127 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2128 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002129 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002130 if (mWaitingOnWallpaper != null) {
2131 long start = SystemClock.uptimeMillis();
2132 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2133 < start) {
2134 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002135 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002136 "Waiting for offset complete...");
2137 mWindowMap.wait(WALLPAPER_TIMEOUT);
2138 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002139 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002140 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002141 if ((start+WALLPAPER_TIMEOUT)
2142 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002143 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002144 + wallpaperWin);
2145 mLastWallpaperTimeoutTime = start;
2146 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002147 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002148 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002149 }
2150 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002151 } catch (RemoteException e) {
2152 }
2153 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002154
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002155 return changed;
2156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002157
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002158 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002159 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002160 if (mWaitingOnWallpaper != null &&
2161 mWaitingOnWallpaper.mClient.asBinder() == window) {
2162 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002163 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002164 }
2165 }
2166 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002167
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002168 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002169 final int dw = mDisplay.getWidth();
2170 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002171
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002172 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002173
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002174 WindowState target = mWallpaperTarget;
2175 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002176 if (target.mWallpaperX >= 0) {
2177 mLastWallpaperX = target.mWallpaperX;
2178 } else if (changingTarget.mWallpaperX >= 0) {
2179 mLastWallpaperX = changingTarget.mWallpaperX;
2180 }
2181 if (target.mWallpaperY >= 0) {
2182 mLastWallpaperY = target.mWallpaperY;
2183 } else if (changingTarget.mWallpaperY >= 0) {
2184 mLastWallpaperY = changingTarget.mWallpaperY;
2185 }
2186 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002187
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002188 int curTokenIndex = mWallpaperTokens.size();
2189 while (curTokenIndex > 0) {
2190 curTokenIndex--;
2191 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2192 int curWallpaperIndex = token.windows.size();
2193 while (curWallpaperIndex > 0) {
2194 curWallpaperIndex--;
2195 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2196 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2197 wallpaper.computeShownFrameLocked();
2198 changed = true;
2199 // We only want to be synchronous with one wallpaper.
2200 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002201 }
2202 }
2203 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002204
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002205 return changed;
2206 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002207
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002208 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002209 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002210 final int dw = mDisplay.getWidth();
2211 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002212
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002213 int curTokenIndex = mWallpaperTokens.size();
2214 while (curTokenIndex > 0) {
2215 curTokenIndex--;
2216 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002217 if (token.hidden == visible) {
2218 token.hidden = !visible;
2219 // Need to do a layout to ensure the wallpaper now has the
2220 // correct size.
2221 mLayoutNeeded = true;
2222 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002223
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002224 int curWallpaperIndex = token.windows.size();
2225 while (curWallpaperIndex > 0) {
2226 curWallpaperIndex--;
2227 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2228 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002229 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002230 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002231
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002232 if (wallpaper.mWallpaperVisible != visible) {
2233 wallpaper.mWallpaperVisible = visible;
2234 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002235 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002236 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002237 + ": " + visible);
2238 wallpaper.mClient.dispatchAppVisibility(visible);
2239 } catch (RemoteException e) {
2240 }
2241 }
2242 }
2243 }
2244 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 public int addWindow(Session session, IWindow client,
2247 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002248 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 int res = mPolicy.checkAddPermission(attrs);
2250 if (res != WindowManagerImpl.ADD_OKAY) {
2251 return res;
2252 }
Romain Guy06882f82009-06-10 13:36:04 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 boolean reportNewConfig = false;
2255 WindowState attachedWindow = null;
2256 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002257 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002261 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 }
Romain Guy06882f82009-06-10 13:36:04 -07002263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002265 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2267 }
2268
2269 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002270 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002272 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 + attrs.token + ". Aborting.");
2274 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2275 }
2276 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2277 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002278 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 + attrs.token + ". Aborting.");
2280 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2281 }
2282 }
2283
2284 boolean addToken = false;
2285 WindowToken token = mTokenMap.get(attrs.token);
2286 if (token == null) {
2287 if (attrs.type >= FIRST_APPLICATION_WINDOW
2288 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002289 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 + attrs.token + ". Aborting.");
2291 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2292 }
2293 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002294 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 + attrs.token + ". Aborting.");
2296 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2297 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002298 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002299 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002300 + attrs.token + ". Aborting.");
2301 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2302 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 token = new WindowToken(attrs.token, -1, false);
2304 addToken = true;
2305 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2306 && attrs.type <= LAST_APPLICATION_WINDOW) {
2307 AppWindowToken atoken = token.appWindowToken;
2308 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002309 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 + token + ". Aborting.");
2311 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2312 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002313 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 + token + ". Aborting.");
2315 return WindowManagerImpl.ADD_APP_EXITING;
2316 }
2317 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2318 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002319 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2321 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2322 }
2323 } else if (attrs.type == TYPE_INPUT_METHOD) {
2324 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002325 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 + attrs.token + ". Aborting.");
2327 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2328 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002329 } else if (attrs.type == TYPE_WALLPAPER) {
2330 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002331 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002332 + attrs.token + ". Aborting.");
2333 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 }
2336
2337 win = new WindowState(session, client, token,
2338 attachedWindow, attrs, viewVisibility);
2339 if (win.mDeathRecipient == null) {
2340 // Client has apparently died, so there is no reason to
2341 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002342 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 + " that is dead, aborting.");
2344 return WindowManagerImpl.ADD_APP_EXITING;
2345 }
2346
2347 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 res = mPolicy.prepareAddWindowLw(win, attrs);
2350 if (res != WindowManagerImpl.ADD_OKAY) {
2351 return res;
2352 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002353
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002354 if (outInputChannel != null) {
2355 String name = win.makeInputChannelName();
2356 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2357 win.mInputChannel = inputChannels[0];
2358 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2359
Jeff Brown928e0542011-01-10 11:17:36 -08002360 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362
2363 // From now on, no exceptions or errors allowed!
2364
2365 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002366
Dianne Hackborn5132b372010-07-29 12:51:35 -07002367 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 if (addToken) {
2370 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 }
2372 win.attach();
2373 mWindowMap.put(client.asBinder(), win);
2374
2375 if (attrs.type == TYPE_APPLICATION_STARTING &&
2376 token.appWindowToken != null) {
2377 token.appWindowToken.startingWindow = win;
2378 }
2379
2380 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 if (attrs.type == TYPE_INPUT_METHOD) {
2383 mInputMethodWindow = win;
2384 addInputMethodWindowToListLocked(win);
2385 imMayMove = false;
2386 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2387 mInputMethodDialogs.add(win);
2388 addWindowToListInOrderLocked(win, true);
2389 adjustInputMethodDialogsLocked();
2390 imMayMove = false;
2391 } else {
2392 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002393 if (attrs.type == TYPE_WALLPAPER) {
2394 mLastWallpaperTimeoutTime = 0;
2395 adjustWallpaperWindowsLocked();
2396 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002397 adjustWallpaperWindowsLocked();
2398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 }
Romain Guy06882f82009-06-10 13:36:04 -07002400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 if (mInTouchMode) {
2406 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2407 }
2408 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2409 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2410 }
Romain Guy06882f82009-06-10 13:36:04 -07002411
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002412 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002414 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2415 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 imMayMove = false;
2417 }
2418 }
Romain Guy06882f82009-06-10 13:36:04 -07002419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002421 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 }
Romain Guy06882f82009-06-10 13:36:04 -07002423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 assignLayersLocked();
2425 // Don't do layout here, the window must call
2426 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 //dump();
2429
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002430 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002431 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002432 }
Jeff Brown349703e2010-06-22 01:27:15 -07002433
Joe Onorato8a9b2202010-02-26 18:56:32 -08002434 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 TAG, "New client " + client.asBinder()
2436 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002437
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002438 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002439 reportNewConfig = true;
2440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 }
2442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 if (reportNewConfig) {
2444 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 return res;
2450 }
Romain Guy06882f82009-06-10 13:36:04 -07002451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 public void removeWindow(Session session, IWindow client) {
2453 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002454 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 if (win == null) {
2456 return;
2457 }
2458 removeWindowLocked(session, win);
2459 }
2460 }
Romain Guy06882f82009-06-10 13:36:04 -07002461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 public void removeWindowLocked(Session session, WindowState win) {
2463
Joe Onorato8a9b2202010-02-26 18:56:32 -08002464 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 TAG, "Remove " + win + " client="
2466 + Integer.toHexString(System.identityHashCode(
2467 win.mClient.asBinder()))
2468 + ", surface=" + win.mSurface);
2469
2470 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002471
2472 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002473
Joe Onorato8a9b2202010-02-26 18:56:32 -08002474 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2476 + " mExiting=" + win.mExiting
2477 + " isAnimating=" + win.isAnimating()
2478 + " app-animation="
2479 + (win.mAppToken != null ? win.mAppToken.animation : null)
2480 + " inPendingTransaction="
2481 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2482 + " mDisplayFrozen=" + mDisplayFrozen);
2483 // Visibility of the removed window. Will be used later to update orientation later on.
2484 boolean wasVisible = false;
2485 // First, see if we need to run an animation. If we do, we have
2486 // to hold off on removing the window until the animation is done.
2487 // If the display is frozen, just remove immediately, since the
2488 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002489 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 // If we are not currently running the exit animation, we
2491 // need to see about starting one.
2492 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2495 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2496 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2497 }
2498 // Try starting an animation.
2499 if (applyAnimationLocked(win, transit, false)) {
2500 win.mExiting = true;
2501 }
2502 }
2503 if (win.mExiting || win.isAnimating()) {
2504 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002505 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 win.mExiting = true;
2507 win.mRemoveOnExit = true;
2508 mLayoutNeeded = true;
2509 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2510 performLayoutAndPlaceSurfacesLocked();
2511 if (win.mAppToken != null) {
2512 win.mAppToken.updateReportedVisibilityLocked();
2513 }
2514 //dump();
2515 Binder.restoreCallingIdentity(origId);
2516 return;
2517 }
2518 }
2519
2520 removeWindowInnerLocked(session, win);
2521 // Removing a visible window will effect the computed orientation
2522 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002523 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002524 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002525 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002526 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 }
2528 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2529 Binder.restoreCallingIdentity(origId);
2530 }
Romain Guy06882f82009-06-10 13:36:04 -07002531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002533 if (win.mRemoved) {
2534 // Nothing to do.
2535 return;
2536 }
2537
2538 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2539 WindowState cwin = win.mChildWindows.get(i);
2540 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2541 + win);
2542 removeWindowInnerLocked(cwin.mSession, cwin);
2543 }
2544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 if (mInputMethodTarget == win) {
2548 moveInputMethodWindowsIfNeededLocked(false);
2549 }
Romain Guy06882f82009-06-10 13:36:04 -07002550
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002551 if (false) {
2552 RuntimeException e = new RuntimeException("here");
2553 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002554 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 mPolicy.removeWindowLw(win);
2558 win.removeLocked();
2559
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002560 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 mWindowMap.remove(win.mClient.asBinder());
2562 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002563 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002564 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002565 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566
2567 if (mInputMethodWindow == win) {
2568 mInputMethodWindow = null;
2569 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2570 mInputMethodDialogs.remove(win);
2571 }
Romain Guy06882f82009-06-10 13:36:04 -07002572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 final WindowToken token = win.mToken;
2574 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002575 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 token.windows.remove(win);
2577 if (atoken != null) {
2578 atoken.allAppWindows.remove(win);
2579 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002580 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 TAG, "**** Removing window " + win + ": count="
2582 + token.windows.size());
2583 if (token.windows.size() == 0) {
2584 if (!token.explicit) {
2585 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586 } else if (atoken != null) {
2587 atoken.firstWindowDrawn = false;
2588 }
2589 }
2590
2591 if (atoken != null) {
2592 if (atoken.startingWindow == win) {
2593 atoken.startingWindow = null;
2594 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2595 // If this is the last window and we had requested a starting
2596 // transition window, well there is no point now.
2597 atoken.startingData = null;
2598 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2599 // If this is the last window except for a starting transition
2600 // window, we need to get rid of the starting transition.
2601 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002602 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 + ": no more real windows");
2604 }
2605 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2606 mH.sendMessage(m);
2607 }
2608 }
Romain Guy06882f82009-06-10 13:36:04 -07002609
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002610 if (win.mAttrs.type == TYPE_WALLPAPER) {
2611 mLastWallpaperTimeoutTime = 0;
2612 adjustWallpaperWindowsLocked();
2613 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002614 adjustWallpaperWindowsLocked();
2615 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 if (!mInLayout) {
2618 assignLayersLocked();
2619 mLayoutNeeded = true;
2620 performLayoutAndPlaceSurfacesLocked();
2621 if (win.mAppToken != null) {
2622 win.mAppToken.updateReportedVisibilityLocked();
2623 }
2624 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002625
2626 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 }
2628
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002629 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2630 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2631 + ": " + msg + " / " + w.mAttrs.getTitle();
2632 if (where != null) {
2633 Slog.i(TAG, str, where);
2634 } else {
2635 Slog.i(TAG, str);
2636 }
2637 }
2638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2640 long origId = Binder.clearCallingIdentity();
2641 try {
2642 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002643 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002645 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2646 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 Surface.openTransaction();
2648 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002649 if (SHOW_TRANSACTIONS) logSurface(w,
2650 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 w.mSurface.setTransparentRegionHint(region);
2652 } finally {
2653 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002654 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2655 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002656 }
2657 }
2658 }
2659 } finally {
2660 Binder.restoreCallingIdentity(origId);
2661 }
2662 }
2663
2664 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002665 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 Rect visibleInsets) {
2667 long origId = Binder.clearCallingIdentity();
2668 try {
2669 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002670 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 if (w != null) {
2672 w.mGivenInsetsPending = false;
2673 w.mGivenContentInsets.set(contentInsets);
2674 w.mGivenVisibleInsets.set(visibleInsets);
2675 w.mTouchableInsets = touchableInsets;
2676 mLayoutNeeded = true;
2677 performLayoutAndPlaceSurfacesLocked();
2678 }
2679 }
2680 } finally {
2681 Binder.restoreCallingIdentity(origId);
2682 }
2683 }
Romain Guy06882f82009-06-10 13:36:04 -07002684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 public void getWindowDisplayFrame(Session session, IWindow client,
2686 Rect outDisplayFrame) {
2687 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002688 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 if (win == null) {
2690 outDisplayFrame.setEmpty();
2691 return;
2692 }
2693 outDisplayFrame.set(win.mDisplayFrame);
2694 }
2695 }
2696
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002697 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2698 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002699 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2700 window.mWallpaperX = x;
2701 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002702 window.mWallpaperXStep = xStep;
2703 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002704 if (updateWallpaperOffsetLocked(window, true)) {
2705 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002706 }
2707 }
2708 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002709
Dianne Hackborn75804932009-10-20 20:15:20 -07002710 void wallpaperCommandComplete(IBinder window, Bundle result) {
2711 synchronized (mWindowMap) {
2712 if (mWaitingOnWallpaper != null &&
2713 mWaitingOnWallpaper.mClient.asBinder() == window) {
2714 mWaitingOnWallpaper = null;
2715 mWindowMap.notifyAll();
2716 }
2717 }
2718 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002719
Dianne Hackborn75804932009-10-20 20:15:20 -07002720 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2721 String action, int x, int y, int z, Bundle extras, boolean sync) {
2722 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2723 || window == mUpperWallpaperTarget) {
2724 boolean doWait = sync;
2725 int curTokenIndex = mWallpaperTokens.size();
2726 while (curTokenIndex > 0) {
2727 curTokenIndex--;
2728 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2729 int curWallpaperIndex = token.windows.size();
2730 while (curWallpaperIndex > 0) {
2731 curWallpaperIndex--;
2732 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2733 try {
2734 wallpaper.mClient.dispatchWallpaperCommand(action,
2735 x, y, z, extras, sync);
2736 // We only want to be synchronous with one wallpaper.
2737 sync = false;
2738 } catch (RemoteException e) {
2739 }
2740 }
2741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002742
Dianne Hackborn75804932009-10-20 20:15:20 -07002743 if (doWait) {
2744 // XXX Need to wait for result.
2745 }
2746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002747
Dianne Hackborn75804932009-10-20 20:15:20 -07002748 return null;
2749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 public int relayoutWindow(Session session, IWindow client,
2752 WindowManager.LayoutParams attrs, int requestedWidth,
2753 int requestedHeight, int viewVisibility, boolean insetsPending,
2754 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002755 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756 boolean displayed = false;
2757 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002758 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002759 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002762 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 if (win == null) {
2764 return 0;
2765 }
2766 win.mRequestedWidth = requestedWidth;
2767 win.mRequestedHeight = requestedHeight;
2768
2769 if (attrs != null) {
2770 mPolicy.adjustWindowParamsLw(attrs);
2771 }
Romain Guy06882f82009-06-10 13:36:04 -07002772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 int attrChanges = 0;
2774 int flagChanges = 0;
2775 if (attrs != null) {
2776 flagChanges = win.mAttrs.flags ^= attrs.flags;
2777 attrChanges = win.mAttrs.copyFrom(attrs);
2778 }
2779
Joe Onorato8a9b2202010-02-26 18:56:32 -08002780 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002781
2782 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2783 win.mAlpha = attrs.alpha;
2784 }
2785
2786 final boolean scaledWindow =
2787 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2788
2789 if (scaledWindow) {
2790 // requested{Width|Height} Surface's physical size
2791 // attrs.{width|height} Size on screen
2792 win.mHScale = (attrs.width != requestedWidth) ?
2793 (attrs.width / (float)requestedWidth) : 1.0f;
2794 win.mVScale = (attrs.height != requestedHeight) ?
2795 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002796 } else {
2797 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 }
2799
2800 boolean imMayMove = (flagChanges&(
2801 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2802 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 boolean focusMayChange = win.mViewVisibility != viewVisibility
2805 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2806 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002807
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002808 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2809 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 win.mRelayoutCalled = true;
2812 final int oldVisibility = win.mViewVisibility;
2813 win.mViewVisibility = viewVisibility;
2814 if (viewVisibility == View.VISIBLE &&
2815 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2816 displayed = !win.isVisibleLw();
2817 if (win.mExiting) {
2818 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002819 if (win.mAnimation != null) {
2820 win.mAnimation.cancel();
2821 win.mAnimation = null;
2822 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 }
2824 if (win.mDestroying) {
2825 win.mDestroying = false;
2826 mDestroySurface.remove(win);
2827 }
2828 if (oldVisibility == View.GONE) {
2829 win.mEnterAnimationPending = true;
2830 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002831 if (displayed) {
2832 if (win.mSurface != null && !win.mDrawPending
2833 && !win.mCommitDrawPending && !mDisplayFrozen
2834 && mPolicy.isScreenOn()) {
2835 applyEnterAnimationLocked(win);
2836 }
2837 if ((win.mAttrs.flags
2838 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2839 if (DEBUG_VISIBILITY) Slog.v(TAG,
2840 "Relayout window turning screen on: " + win);
2841 win.mTurnOnScreen = true;
2842 }
2843 int diff = 0;
2844 if (win.mConfiguration != mCurConfiguration
2845 && (win.mConfiguration == null
2846 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2847 win.mConfiguration = mCurConfiguration;
2848 if (DEBUG_CONFIGURATION) {
2849 Slog.i(TAG, "Window " + win + " visible with new config: "
2850 + win.mConfiguration + " / 0x"
2851 + Integer.toHexString(diff));
2852 }
2853 outConfig.setTo(mCurConfiguration);
2854 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002855 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2857 // To change the format, we need to re-build the surface.
2858 win.destroySurfaceLocked();
2859 displayed = true;
2860 }
2861 try {
2862 Surface surface = win.createSurfaceLocked();
2863 if (surface != null) {
2864 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002865 win.mReportDestroySurface = false;
2866 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002867 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002868 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002870 // For some reason there isn't a surface. Clear the
2871 // caller's object so they see the same state.
2872 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 }
2874 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002875 mInputMonitor.updateInputWindowsLw();
2876
Joe Onorato8a9b2202010-02-26 18:56:32 -08002877 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002878 + client + " (" + win.mAttrs.getTitle() + ")",
2879 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 Binder.restoreCallingIdentity(origId);
2881 return 0;
2882 }
2883 if (displayed) {
2884 focusMayChange = true;
2885 }
2886 if (win.mAttrs.type == TYPE_INPUT_METHOD
2887 && mInputMethodWindow == null) {
2888 mInputMethodWindow = win;
2889 imMayMove = true;
2890 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002891 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2892 && win.mAppToken != null
2893 && win.mAppToken.startingWindow != null) {
2894 // Special handling of starting window over the base
2895 // window of the app: propagate lock screen flags to it,
2896 // to provide the correct semantics while starting.
2897 final int mask =
2898 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002899 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2900 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002901 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2902 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 } else {
2905 win.mEnterAnimationPending = false;
2906 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002907 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002908 + ": mExiting=" + win.mExiting
2909 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 // If we are not currently running the exit animation, we
2911 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002912 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 // Try starting an animation; if there isn't one, we
2914 // can destroy the surface right away.
2915 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2916 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2917 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2918 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002919 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002921 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 } else if (win.isAnimating()) {
2924 // Currently in a hide animation... turn this into
2925 // an exit.
2926 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002927 } else if (win == mWallpaperTarget) {
2928 // If the wallpaper is currently behind this
2929 // window, we need to change both of them inside
2930 // of a transaction to avoid artifacts.
2931 win.mExiting = true;
2932 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 } else {
2934 if (mInputMethodWindow == win) {
2935 mInputMethodWindow = null;
2936 }
2937 win.destroySurfaceLocked();
2938 }
2939 }
2940 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002941
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002942 if (win.mSurface == null || (win.getAttrs().flags
2943 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2944 || win.mSurfacePendingDestroy) {
2945 // We are being called from a local process, which
2946 // means outSurface holds its current surface. Ensure the
2947 // surface object is cleared, but we don't want it actually
2948 // destroyed at this point.
2949 win.mSurfacePendingDestroy = false;
2950 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002951 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002952 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002953 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002954 "Keeping surface, will report destroy: " + win);
2955 win.mReportDestroySurface = true;
2956 outSurface.copyFrom(win.mSurface);
2957 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 }
2959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 if (focusMayChange) {
2961 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2962 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 imMayMove = false;
2964 }
2965 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2966 }
Romain Guy06882f82009-06-10 13:36:04 -07002967
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002968 // updateFocusedWindowLocked() already assigned layers so we only need to
2969 // reassign them at this point if the IM window state gets shuffled
2970 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002973 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2974 // Little hack here -- we -should- be able to rely on the
2975 // function to return true if the IME has moved and needs
2976 // its layer recomputed. However, if the IME was hidden
2977 // and isn't actually moved in the list, its layer may be
2978 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 assignLayers = true;
2980 }
2981 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002982 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002983 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002984 assignLayers = true;
2985 }
2986 }
Romain Guy06882f82009-06-10 13:36:04 -07002987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 mLayoutNeeded = true;
2989 win.mGivenInsetsPending = insetsPending;
2990 if (assignLayers) {
2991 assignLayersLocked();
2992 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002993 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002995 if (displayed && win.mIsWallpaper) {
2996 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002997 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002998 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 if (win.mAppToken != null) {
3000 win.mAppToken.updateReportedVisibilityLocked();
3001 }
3002 outFrame.set(win.mFrame);
3003 outContentInsets.set(win.mContentInsets);
3004 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003005 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07003007 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003008 + ", requestedHeight=" + requestedHeight
3009 + ", viewVisibility=" + viewVisibility
3010 + "\nRelayout returning frame=" + outFrame
3011 + ", surface=" + outSurface);
3012
Joe Onorato8a9b2202010-02-26 18:56:32 -08003013 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3015
3016 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003017
3018 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 }
3020
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003021 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 sendNewConfiguration();
3023 }
Romain Guy06882f82009-06-10 13:36:04 -07003024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3028 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3029 }
3030
3031 public void finishDrawingWindow(Session session, IWindow client) {
3032 final long origId = Binder.clearCallingIdentity();
3033 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003034 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003036 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3037 adjustWallpaperWindowsLocked();
3038 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 mLayoutNeeded = true;
3040 performLayoutAndPlaceSurfacesLocked();
3041 }
3042 }
3043 Binder.restoreCallingIdentity(origId);
3044 }
3045
3046 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003047 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 + (lp != null ? lp.packageName : null)
3049 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3050 if (lp != null && lp.windowAnimations != 0) {
3051 // If this is a system resource, don't try to load it from the
3052 // application resources. It is nice to avoid loading application
3053 // resources if we can.
3054 String packageName = lp.packageName != null ? lp.packageName : "android";
3055 int resId = lp.windowAnimations;
3056 if ((resId&0xFF000000) == 0x01000000) {
3057 packageName = "android";
3058 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003059 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 + packageName);
3061 return AttributeCache.instance().get(packageName, resId,
3062 com.android.internal.R.styleable.WindowAnimation);
3063 }
3064 return null;
3065 }
Romain Guy06882f82009-06-10 13:36:04 -07003066
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003067 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003068 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003069 + packageName + " resId=0x" + Integer.toHexString(resId));
3070 if (packageName != null) {
3071 if ((resId&0xFF000000) == 0x01000000) {
3072 packageName = "android";
3073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003074 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003075 + packageName);
3076 return AttributeCache.instance().get(packageName, resId,
3077 com.android.internal.R.styleable.WindowAnimation);
3078 }
3079 return null;
3080 }
3081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 private void applyEnterAnimationLocked(WindowState win) {
3083 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3084 if (win.mEnterAnimationPending) {
3085 win.mEnterAnimationPending = false;
3086 transit = WindowManagerPolicy.TRANSIT_ENTER;
3087 }
3088
3089 applyAnimationLocked(win, transit, true);
3090 }
3091
3092 private boolean applyAnimationLocked(WindowState win,
3093 int transit, boolean isEntrance) {
3094 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3095 // If we are trying to apply an animation, but already running
3096 // an animation of the same type, then just leave that one alone.
3097 return true;
3098 }
Romain Guy06882f82009-06-10 13:36:04 -07003099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003100 // Only apply an animation if the display isn't frozen. If it is
3101 // frozen, there is no reason to animate and it can cause strange
3102 // artifacts when we unfreeze the display if some different animation
3103 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003104 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 int anim = mPolicy.selectAnimationLw(win, transit);
3106 int attr = -1;
3107 Animation a = null;
3108 if (anim != 0) {
3109 a = AnimationUtils.loadAnimation(mContext, anim);
3110 } else {
3111 switch (transit) {
3112 case WindowManagerPolicy.TRANSIT_ENTER:
3113 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3114 break;
3115 case WindowManagerPolicy.TRANSIT_EXIT:
3116 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3117 break;
3118 case WindowManagerPolicy.TRANSIT_SHOW:
3119 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3120 break;
3121 case WindowManagerPolicy.TRANSIT_HIDE:
3122 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3123 break;
3124 }
3125 if (attr >= 0) {
3126 a = loadAnimation(win.mAttrs, attr);
3127 }
3128 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003129 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3131 + " mAnimation=" + win.mAnimation
3132 + " isEntrance=" + isEntrance);
3133 if (a != null) {
3134 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003135 RuntimeException e = null;
3136 if (!HIDE_STACK_CRAWLS) {
3137 e = new RuntimeException();
3138 e.fillInStackTrace();
3139 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003140 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 }
3142 win.setAnimation(a);
3143 win.mAnimationIsEntrance = isEntrance;
3144 }
3145 } else {
3146 win.clearAnimation();
3147 }
3148
3149 return win.mAnimation != null;
3150 }
3151
3152 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3153 int anim = 0;
3154 Context context = mContext;
3155 if (animAttr >= 0) {
3156 AttributeCache.Entry ent = getCachedAnimations(lp);
3157 if (ent != null) {
3158 context = ent.context;
3159 anim = ent.array.getResourceId(animAttr, 0);
3160 }
3161 }
3162 if (anim != 0) {
3163 return AnimationUtils.loadAnimation(context, anim);
3164 }
3165 return null;
3166 }
Romain Guy06882f82009-06-10 13:36:04 -07003167
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003168 private Animation loadAnimation(String packageName, int resId) {
3169 int anim = 0;
3170 Context context = mContext;
3171 if (resId >= 0) {
3172 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3173 if (ent != null) {
3174 context = ent.context;
3175 anim = resId;
3176 }
3177 }
3178 if (anim != 0) {
3179 return AnimationUtils.loadAnimation(context, anim);
3180 }
3181 return null;
3182 }
3183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 private boolean applyAnimationLocked(AppWindowToken wtoken,
3185 WindowManager.LayoutParams lp, int transit, boolean enter) {
3186 // Only apply an animation if the display isn't frozen. If it is
3187 // frozen, there is no reason to animate and it can cause strange
3188 // artifacts when we unfreeze the display if some different animation
3189 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003190 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003191 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003192 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003193 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003194 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003195 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003196 } else if (mNextAppTransitionPackage != null) {
3197 a = loadAnimation(mNextAppTransitionPackage, enter ?
3198 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003199 } else {
3200 int animAttr = 0;
3201 switch (transit) {
3202 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3203 animAttr = enter
3204 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3205 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3206 break;
3207 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3208 animAttr = enter
3209 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3210 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3211 break;
3212 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3213 animAttr = enter
3214 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3215 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3216 break;
3217 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3218 animAttr = enter
3219 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3220 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3221 break;
3222 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3223 animAttr = enter
3224 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3225 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3226 break;
3227 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3228 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003229 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003230 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3231 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003232 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003233 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003234 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3235 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003236 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003237 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003238 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003239 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3240 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3241 break;
3242 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3243 animAttr = enter
3244 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3245 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3246 break;
3247 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3248 animAttr = enter
3249 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3250 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003251 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003252 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003253 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003254 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003255 + " anim=" + a
3256 + " animAttr=0x" + Integer.toHexString(animAttr)
3257 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 if (a != null) {
3260 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003261 RuntimeException e = null;
3262 if (!HIDE_STACK_CRAWLS) {
3263 e = new RuntimeException();
3264 e.fillInStackTrace();
3265 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003266 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 }
3268 wtoken.setAnimation(a);
3269 }
3270 } else {
3271 wtoken.clearAnimation();
3272 }
3273
3274 return wtoken.animation != null;
3275 }
3276
3277 // -------------------------------------------------------------
3278 // Application Window Tokens
3279 // -------------------------------------------------------------
3280
3281 public void validateAppTokens(List tokens) {
3282 int v = tokens.size()-1;
3283 int m = mAppTokens.size()-1;
3284 while (v >= 0 && m >= 0) {
3285 AppWindowToken wtoken = mAppTokens.get(m);
3286 if (wtoken.removed) {
3287 m--;
3288 continue;
3289 }
3290 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003291 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3293 }
3294 v--;
3295 m--;
3296 }
3297 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003298 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 v--;
3300 }
3301 while (m >= 0) {
3302 AppWindowToken wtoken = mAppTokens.get(m);
3303 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003304 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 }
3306 m--;
3307 }
3308 }
3309
3310 boolean checkCallingPermission(String permission, String func) {
3311 // Quick check: if the calling permission is me, it's all okay.
3312 if (Binder.getCallingPid() == Process.myPid()) {
3313 return true;
3314 }
Romain Guy06882f82009-06-10 13:36:04 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 if (mContext.checkCallingPermission(permission)
3317 == PackageManager.PERMISSION_GRANTED) {
3318 return true;
3319 }
3320 String msg = "Permission Denial: " + func + " from pid="
3321 + Binder.getCallingPid()
3322 + ", uid=" + Binder.getCallingUid()
3323 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003324 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 return false;
3326 }
Romain Guy06882f82009-06-10 13:36:04 -07003327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 AppWindowToken findAppWindowToken(IBinder token) {
3329 WindowToken wtoken = mTokenMap.get(token);
3330 if (wtoken == null) {
3331 return null;
3332 }
3333 return wtoken.appWindowToken;
3334 }
Romain Guy06882f82009-06-10 13:36:04 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 public void addWindowToken(IBinder token, int type) {
3337 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3338 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003339 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 }
Romain Guy06882f82009-06-10 13:36:04 -07003341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 synchronized(mWindowMap) {
3343 WindowToken wtoken = mTokenMap.get(token);
3344 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003345 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 return;
3347 }
3348 wtoken = new WindowToken(token, type, true);
3349 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003350 if (type == TYPE_WALLPAPER) {
3351 mWallpaperTokens.add(wtoken);
3352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 }
3354 }
Romain Guy06882f82009-06-10 13:36:04 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 public void removeWindowToken(IBinder token) {
3357 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3358 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003359 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 }
3361
3362 final long origId = Binder.clearCallingIdentity();
3363 synchronized(mWindowMap) {
3364 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 if (wtoken != null) {
3366 boolean delayed = false;
3367 if (!wtoken.hidden) {
3368 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 final int N = wtoken.windows.size();
3371 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 for (int i=0; i<N; i++) {
3374 WindowState win = wtoken.windows.get(i);
3375
3376 if (win.isAnimating()) {
3377 delayed = true;
3378 }
Romain Guy06882f82009-06-10 13:36:04 -07003379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 if (win.isVisibleNow()) {
3381 applyAnimationLocked(win,
3382 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 changed = true;
3384 }
3385 }
3386
3387 if (changed) {
3388 mLayoutNeeded = true;
3389 performLayoutAndPlaceSurfacesLocked();
3390 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3391 }
Romain Guy06882f82009-06-10 13:36:04 -07003392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 if (delayed) {
3394 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003395 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3396 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 }
3398 }
Romain Guy06882f82009-06-10 13:36:04 -07003399
Jeff Brownc5ed5912010-07-14 18:48:53 -07003400 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003401 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003402 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003403 }
3404 }
3405 Binder.restoreCallingIdentity(origId);
3406 }
3407
3408 public void addAppToken(int addPos, IApplicationToken token,
3409 int groupId, int requestedOrientation, boolean fullscreen) {
3410 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3411 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003412 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 }
Jeff Brown349703e2010-06-22 01:27:15 -07003414
3415 // Get the dispatching timeout here while we are not holding any locks so that it
3416 // can be cached by the AppWindowToken. The timeout value is used later by the
3417 // input dispatcher in code that does hold locks. If we did not cache the value
3418 // here we would run the chance of introducing a deadlock between the window manager
3419 // (which holds locks while updating the input dispatcher state) and the activity manager
3420 // (which holds locks while querying the application token).
3421 long inputDispatchingTimeoutNanos;
3422 try {
3423 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3424 } catch (RemoteException ex) {
3425 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3426 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3427 }
Romain Guy06882f82009-06-10 13:36:04 -07003428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 synchronized(mWindowMap) {
3430 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3431 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003432 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433 return;
3434 }
3435 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003436 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 wtoken.groupId = groupId;
3438 wtoken.appFullscreen = fullscreen;
3439 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003440 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003442 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 // Application tokens start out hidden.
3445 wtoken.hidden = true;
3446 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 //dump();
3449 }
3450 }
Romain Guy06882f82009-06-10 13:36:04 -07003451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003452 public void setAppGroupId(IBinder token, int groupId) {
3453 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3454 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003455 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 }
3457
3458 synchronized(mWindowMap) {
3459 AppWindowToken wtoken = findAppWindowToken(token);
3460 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003461 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003462 return;
3463 }
3464 wtoken.groupId = groupId;
3465 }
3466 }
Romain Guy06882f82009-06-10 13:36:04 -07003467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 public int getOrientationFromWindowsLocked() {
3469 int pos = mWindows.size() - 1;
3470 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003471 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 pos--;
3473 if (wtoken.mAppToken != null) {
3474 // We hit an application window. so the orientation will be determined by the
3475 // app window. No point in continuing further.
3476 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3477 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003478 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003479 continue;
3480 }
3481 int req = wtoken.mAttrs.screenOrientation;
3482 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3483 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3484 continue;
3485 } else {
3486 return req;
3487 }
3488 }
3489 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3490 }
Romain Guy06882f82009-06-10 13:36:04 -07003491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003493 int pos = mAppTokens.size() - 1;
3494 int curGroup = 0;
3495 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3496 boolean findingBehind = false;
3497 boolean haveGroup = false;
3498 boolean lastFullscreen = false;
3499 while (pos >= 0) {
3500 AppWindowToken wtoken = mAppTokens.get(pos);
3501 pos--;
3502 // if we're about to tear down this window and not seek for
3503 // the behind activity, don't use it for orientation
3504 if (!findingBehind
3505 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3506 continue;
3507 }
3508
3509 if (!haveGroup) {
3510 // We ignore any hidden applications on the top.
3511 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003512 continue;
3513 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003514 haveGroup = true;
3515 curGroup = wtoken.groupId;
3516 lastOrientation = wtoken.requestedOrientation;
3517 } else if (curGroup != wtoken.groupId) {
3518 // If we have hit a new application group, and the bottom
3519 // of the previous group didn't explicitly say to use
3520 // the orientation behind it, and the last app was
3521 // full screen, then we'll stick with the
3522 // user's orientation.
3523 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3524 && lastFullscreen) {
3525 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003528 int or = wtoken.requestedOrientation;
3529 // If this application is fullscreen, and didn't explicitly say
3530 // to use the orientation behind it, then just take whatever
3531 // orientation it has and ignores whatever is under it.
3532 lastFullscreen = wtoken.appFullscreen;
3533 if (lastFullscreen
3534 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3535 return or;
3536 }
3537 // If this application has requested an explicit orientation,
3538 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003539 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3540 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003541 return or;
3542 }
3543 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3544 }
3545 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 }
Romain Guy06882f82009-06-10 13:36:04 -07003547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003549 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003550 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3551 "updateOrientationFromAppTokens()")) {
3552 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3553 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003554
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003555 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003557
3558 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003559 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003560 if (freezeThisOneIfNeeded != null) {
3561 AppWindowToken wtoken = findAppWindowToken(
3562 freezeThisOneIfNeeded);
3563 if (wtoken != null) {
3564 startAppFreezingScreenLocked(wtoken,
3565 ActivityInfo.CONFIG_ORIENTATION);
3566 }
3567 }
3568 config = computeNewConfigurationLocked();
3569
3570 } else if (currentConfig != null) {
3571 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003572 // state mismatches the activity manager's, update it,
3573 // disregarding font scale, which should remain set to
3574 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003575 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003576 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003577 if (computeNewConfigurationLocked(mTempConfiguration)) {
3578 if (currentConfig.diff(mTempConfiguration) != 0) {
3579 mWaitingForConfig = true;
3580 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003581 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003582 config = new Configuration(mTempConfiguration);
3583 }
3584 }
3585 }
3586 }
3587
Dianne Hackborncfaef692009-06-15 14:24:44 -07003588 Binder.restoreCallingIdentity(ident);
3589 return config;
3590 }
3591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003593 * Determine the new desired orientation of the display, returning
3594 * a non-null new Configuration if it has changed from the current
3595 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3596 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3597 * SCREEN. This will typically be done for you if you call
3598 * sendNewConfiguration().
3599 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 * The orientation is computed from non-application windows first. If none of
3601 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003602 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3604 * android.os.IBinder)
3605 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003606 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3607 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003608 // If the display is frozen, some activities may be in the middle
3609 // of restarting, and thus have removed their old window. If the
3610 // window has the flag to hide the lock screen, then the lock screen
3611 // can re-appear and inflict its own orientation on us. Keep the
3612 // orientation stable until this all settles down.
3613 return false;
3614 }
3615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 long ident = Binder.clearCallingIdentity();
3618 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003619 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 mForcedAppOrientation = req;
3623 //send a message to Policy indicating orientation change to take
3624 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003625 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003626 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003627 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3628 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003629 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 }
3631 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003632
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003633 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 } finally {
3635 Binder.restoreCallingIdentity(ident);
3636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 }
Romain Guy06882f82009-06-10 13:36:04 -07003638
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003639 int computeForcedAppOrientationLocked() {
3640 int req = getOrientationFromWindowsLocked();
3641 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3642 req = getOrientationFromAppTokensLocked();
3643 }
3644 return req;
3645 }
Romain Guy06882f82009-06-10 13:36:04 -07003646
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003647 public void setNewConfiguration(Configuration config) {
3648 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3649 "setNewConfiguration()")) {
3650 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3651 }
3652
3653 synchronized(mWindowMap) {
3654 mCurConfiguration = new Configuration(config);
3655 mWaitingForConfig = false;
3656 performLayoutAndPlaceSurfacesLocked();
3657 }
3658 }
3659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3661 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3662 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003663 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 }
Romain Guy06882f82009-06-10 13:36:04 -07003665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003666 synchronized(mWindowMap) {
3667 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3668 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003669 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 return;
3671 }
Romain Guy06882f82009-06-10 13:36:04 -07003672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 wtoken.requestedOrientation = requestedOrientation;
3674 }
3675 }
Romain Guy06882f82009-06-10 13:36:04 -07003676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 public int getAppOrientation(IApplicationToken token) {
3678 synchronized(mWindowMap) {
3679 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3680 if (wtoken == null) {
3681 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3682 }
Romain Guy06882f82009-06-10 13:36:04 -07003683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 return wtoken.requestedOrientation;
3685 }
3686 }
Romain Guy06882f82009-06-10 13:36:04 -07003687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3689 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3690 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003691 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 }
3693
3694 synchronized(mWindowMap) {
3695 boolean changed = false;
3696 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003697 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 changed = mFocusedApp != null;
3699 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003700 if (changed) {
3701 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 } else {
3704 AppWindowToken newFocus = findAppWindowToken(token);
3705 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003706 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 return;
3708 }
3709 changed = mFocusedApp != newFocus;
3710 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003711 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003712 if (changed) {
3713 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 }
3716
3717 if (moveFocusNow && changed) {
3718 final long origId = Binder.clearCallingIdentity();
3719 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3720 Binder.restoreCallingIdentity(origId);
3721 }
3722 }
3723 }
3724
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003725 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3727 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003728 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 }
Romain Guy06882f82009-06-10 13:36:04 -07003730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003732 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 TAG, "Prepare app transition: transit=" + transit
3734 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003735 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003736 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3737 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003739 } else if (!alwaysKeepCurrent) {
3740 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3741 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3742 // Opening a new task always supersedes a close for the anim.
3743 mNextAppTransition = transit;
3744 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3745 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3746 // Opening a new activity always supersedes a close for the anim.
3747 mNextAppTransition = transit;
3748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 }
3750 mAppTransitionReady = false;
3751 mAppTransitionTimeout = false;
3752 mStartingIconInTransition = false;
3753 mSkipAppTransitionAnimation = false;
3754 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3755 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3756 5000);
3757 }
3758 }
3759 }
3760
3761 public int getPendingAppTransition() {
3762 return mNextAppTransition;
3763 }
Romain Guy06882f82009-06-10 13:36:04 -07003764
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003765 public void overridePendingAppTransition(String packageName,
3766 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003767 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003768 mNextAppTransitionPackage = packageName;
3769 mNextAppTransitionEnter = enterAnim;
3770 mNextAppTransitionExit = exitAnim;
3771 }
3772 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 public void executeAppTransition() {
3775 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3776 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003777 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 }
Romain Guy06882f82009-06-10 13:36:04 -07003779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003781 if (DEBUG_APP_TRANSITIONS) {
3782 RuntimeException e = new RuntimeException("here");
3783 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003784 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003785 + mNextAppTransition, e);
3786 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003787 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 mAppTransitionReady = true;
3789 final long origId = Binder.clearCallingIdentity();
3790 performLayoutAndPlaceSurfacesLocked();
3791 Binder.restoreCallingIdentity(origId);
3792 }
3793 }
3794 }
3795
3796 public void setAppStartingWindow(IBinder token, String pkg,
3797 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003798 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3800 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003801 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 }
3803
3804 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003805 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3807 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 AppWindowToken wtoken = findAppWindowToken(token);
3810 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003811 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 return;
3813 }
3814
3815 // If the display is frozen, we won't do anything until the
3816 // actual window is displayed so there is no reason to put in
3817 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003818 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 return;
3820 }
Romain Guy06882f82009-06-10 13:36:04 -07003821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 if (wtoken.startingData != null) {
3823 return;
3824 }
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 if (transferFrom != null) {
3827 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3828 if (ttoken != null) {
3829 WindowState startingWindow = ttoken.startingWindow;
3830 if (startingWindow != null) {
3831 if (mStartingIconInTransition) {
3832 // In this case, the starting icon has already
3833 // been displayed, so start letting windows get
3834 // shown immediately without any more transitions.
3835 mSkipAppTransitionAnimation = true;
3836 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003837 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 "Moving existing starting from " + ttoken
3839 + " to " + wtoken);
3840 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 // Transfer the starting window over to the new
3843 // token.
3844 wtoken.startingData = ttoken.startingData;
3845 wtoken.startingView = ttoken.startingView;
3846 wtoken.startingWindow = startingWindow;
3847 ttoken.startingData = null;
3848 ttoken.startingView = null;
3849 ttoken.startingWindow = null;
3850 ttoken.startingMoved = true;
3851 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003852 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003854 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003855 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003857 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003858 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3859 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 ttoken.windows.remove(startingWindow);
3861 ttoken.allAppWindows.remove(startingWindow);
3862 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 // Propagate other interesting state between the
3865 // tokens. If the old token is displayed, we should
3866 // immediately force the new one to be displayed. If
3867 // it is animating, we need to move that animation to
3868 // the new one.
3869 if (ttoken.allDrawn) {
3870 wtoken.allDrawn = true;
3871 }
3872 if (ttoken.firstWindowDrawn) {
3873 wtoken.firstWindowDrawn = true;
3874 }
3875 if (!ttoken.hidden) {
3876 wtoken.hidden = false;
3877 wtoken.hiddenRequested = false;
3878 wtoken.willBeHidden = false;
3879 }
3880 if (wtoken.clientHidden != ttoken.clientHidden) {
3881 wtoken.clientHidden = ttoken.clientHidden;
3882 wtoken.sendAppVisibilityToClients();
3883 }
3884 if (ttoken.animation != null) {
3885 wtoken.animation = ttoken.animation;
3886 wtoken.animating = ttoken.animating;
3887 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3888 ttoken.animation = null;
3889 ttoken.animLayerAdjustment = 0;
3890 wtoken.updateLayers();
3891 ttoken.updateLayers();
3892 }
Romain Guy06882f82009-06-10 13:36:04 -07003893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003895 mLayoutNeeded = true;
3896 performLayoutAndPlaceSurfacesLocked();
3897 Binder.restoreCallingIdentity(origId);
3898 return;
3899 } else if (ttoken.startingData != null) {
3900 // The previous app was getting ready to show a
3901 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003902 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903 "Moving pending starting from " + ttoken
3904 + " to " + wtoken);
3905 wtoken.startingData = ttoken.startingData;
3906 ttoken.startingData = null;
3907 ttoken.startingMoved = true;
3908 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3909 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3910 // want to process the message ASAP, before any other queued
3911 // messages.
3912 mH.sendMessageAtFrontOfQueue(m);
3913 return;
3914 }
3915 }
3916 }
3917
3918 // There is no existing starting window, and the caller doesn't
3919 // want us to create one, so that's it!
3920 if (!createIfNeeded) {
3921 return;
3922 }
Romain Guy06882f82009-06-10 13:36:04 -07003923
Dianne Hackborn284ac932009-08-28 10:34:25 -07003924 // If this is a translucent or wallpaper window, then don't
3925 // show a starting window -- the current effect (a full-screen
3926 // opaque starting window that fades away to the real contents
3927 // when it is ready) does not work for this.
3928 if (theme != 0) {
3929 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3930 com.android.internal.R.styleable.Window);
3931 if (ent.array.getBoolean(
3932 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3933 return;
3934 }
3935 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003936 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3937 return;
3938 }
3939 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003940 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3941 return;
3942 }
3943 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003945 mStartingIconInTransition = true;
3946 wtoken.startingData = new StartingData(
3947 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003948 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3950 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3951 // want to process the message ASAP, before any other queued
3952 // messages.
3953 mH.sendMessageAtFrontOfQueue(m);
3954 }
3955 }
3956
3957 public void setAppWillBeHidden(IBinder token) {
3958 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3959 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003960 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003961 }
3962
3963 AppWindowToken wtoken;
3964
3965 synchronized(mWindowMap) {
3966 wtoken = findAppWindowToken(token);
3967 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003968 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 -08003969 return;
3970 }
3971 wtoken.willBeHidden = true;
3972 }
3973 }
Romain Guy06882f82009-06-10 13:36:04 -07003974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3976 boolean visible, int transit, boolean performLayout) {
3977 boolean delayed = false;
3978
3979 if (wtoken.clientHidden == visible) {
3980 wtoken.clientHidden = !visible;
3981 wtoken.sendAppVisibilityToClients();
3982 }
Romain Guy06882f82009-06-10 13:36:04 -07003983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003984 wtoken.willBeHidden = false;
3985 if (wtoken.hidden == visible) {
3986 final int N = wtoken.allAppWindows.size();
3987 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003988 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3990 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003993
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003994 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 if (wtoken.animation == sDummyAnimation) {
3996 wtoken.animation = null;
3997 }
3998 applyAnimationLocked(wtoken, lp, transit, visible);
3999 changed = true;
4000 if (wtoken.animation != null) {
4001 delayed = runningAppAnimation = true;
4002 }
4003 }
Romain Guy06882f82009-06-10 13:36:04 -07004004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 for (int i=0; i<N; i++) {
4006 WindowState win = wtoken.allAppWindows.get(i);
4007 if (win == wtoken.startingWindow) {
4008 continue;
4009 }
4010
4011 if (win.isAnimating()) {
4012 delayed = true;
4013 }
Romain Guy06882f82009-06-10 13:36:04 -07004014
Joe Onorato8a9b2202010-02-26 18:56:32 -08004015 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004016 //win.dump(" ");
4017 if (visible) {
4018 if (!win.isVisibleNow()) {
4019 if (!runningAppAnimation) {
4020 applyAnimationLocked(win,
4021 WindowManagerPolicy.TRANSIT_ENTER, true);
4022 }
4023 changed = true;
4024 }
4025 } else if (win.isVisibleNow()) {
4026 if (!runningAppAnimation) {
4027 applyAnimationLocked(win,
4028 WindowManagerPolicy.TRANSIT_EXIT, false);
4029 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 changed = true;
4031 }
4032 }
4033
4034 wtoken.hidden = wtoken.hiddenRequested = !visible;
4035 if (!visible) {
4036 unsetAppFreezingScreenLocked(wtoken, true, true);
4037 } else {
4038 // If we are being set visible, and the starting window is
4039 // not yet displayed, then make sure it doesn't get displayed.
4040 WindowState swin = wtoken.startingWindow;
4041 if (swin != null && (swin.mDrawPending
4042 || swin.mCommitDrawPending)) {
4043 swin.mPolicyVisibility = false;
4044 swin.mPolicyVisibilityAfterAnim = false;
4045 }
4046 }
Romain Guy06882f82009-06-10 13:36:04 -07004047
Joe Onorato8a9b2202010-02-26 18:56:32 -08004048 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004049 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4050 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004051
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004052 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004053 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004054 if (performLayout) {
4055 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
4056 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07004057 } else {
4058 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004060 }
4061 }
4062
4063 if (wtoken.animation != null) {
4064 delayed = true;
4065 }
Romain Guy06882f82009-06-10 13:36:04 -07004066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 return delayed;
4068 }
4069
4070 public void setAppVisibility(IBinder token, boolean visible) {
4071 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4072 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004073 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004074 }
4075
4076 AppWindowToken wtoken;
4077
4078 synchronized(mWindowMap) {
4079 wtoken = findAppWindowToken(token);
4080 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004081 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 return;
4083 }
4084
4085 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004086 RuntimeException e = null;
4087 if (!HIDE_STACK_CRAWLS) {
4088 e = new RuntimeException();
4089 e.fillInStackTrace();
4090 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004091 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 + "): mNextAppTransition=" + mNextAppTransition
4093 + " hidden=" + wtoken.hidden
4094 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4095 }
Romain Guy06882f82009-06-10 13:36:04 -07004096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097 // If we are preparing an app transition, then delay changing
4098 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004099 if (!mDisplayFrozen && mPolicy.isScreenOn()
4100 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 // Already in requested state, don't do anything more.
4102 if (wtoken.hiddenRequested != visible) {
4103 return;
4104 }
4105 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004106
Joe Onorato8a9b2202010-02-26 18:56:32 -08004107 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 TAG, "Setting dummy animation on: " + wtoken);
4109 wtoken.setDummyAnimation();
4110 mOpeningApps.remove(wtoken);
4111 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004112 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 wtoken.inPendingTransaction = true;
4114 if (visible) {
4115 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 wtoken.startingDisplayed = false;
4117 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004118
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004119 // If the token is currently hidden (should be the
4120 // common case), then we need to set up to wait for
4121 // its windows to be ready.
4122 if (wtoken.hidden) {
4123 wtoken.allDrawn = false;
4124 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004125
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004126 if (wtoken.clientHidden) {
4127 // In the case where we are making an app visible
4128 // but holding off for a transition, we still need
4129 // to tell the client to make its windows visible so
4130 // they get drawn. Otherwise, we will wait on
4131 // performing the transition until all windows have
4132 // been drawn, they never will be, and we are sad.
4133 wtoken.clientHidden = false;
4134 wtoken.sendAppVisibilityToClients();
4135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 }
4137 } else {
4138 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004139
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004140 // If the token is currently visible (should be the
4141 // common case), then set up to wait for it to be hidden.
4142 if (!wtoken.hidden) {
4143 wtoken.waitingToHide = true;
4144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 }
4146 return;
4147 }
Romain Guy06882f82009-06-10 13:36:04 -07004148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004150 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 wtoken.updateReportedVisibilityLocked();
4152 Binder.restoreCallingIdentity(origId);
4153 }
4154 }
4155
4156 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4157 boolean unfreezeSurfaceNow, boolean force) {
4158 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004159 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 + " force=" + force);
4161 final int N = wtoken.allAppWindows.size();
4162 boolean unfrozeWindows = false;
4163 for (int i=0; i<N; i++) {
4164 WindowState w = wtoken.allAppWindows.get(i);
4165 if (w.mAppFreezing) {
4166 w.mAppFreezing = false;
4167 if (w.mSurface != null && !w.mOrientationChanging) {
4168 w.mOrientationChanging = true;
4169 }
4170 unfrozeWindows = true;
4171 }
4172 }
4173 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004174 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 wtoken.freezingScreen = false;
4176 mAppsFreezingScreen--;
4177 }
4178 if (unfreezeSurfaceNow) {
4179 if (unfrozeWindows) {
4180 mLayoutNeeded = true;
4181 performLayoutAndPlaceSurfacesLocked();
4182 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004183 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 }
4185 }
4186 }
Romain Guy06882f82009-06-10 13:36:04 -07004187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4189 int configChanges) {
4190 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004191 RuntimeException e = null;
4192 if (!HIDE_STACK_CRAWLS) {
4193 e = new RuntimeException();
4194 e.fillInStackTrace();
4195 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004196 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 + ": hidden=" + wtoken.hidden + " freezing="
4198 + wtoken.freezingScreen, e);
4199 }
4200 if (!wtoken.hiddenRequested) {
4201 if (!wtoken.freezingScreen) {
4202 wtoken.freezingScreen = true;
4203 mAppsFreezingScreen++;
4204 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004205 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004206 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4207 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4208 5000);
4209 }
4210 }
4211 final int N = wtoken.allAppWindows.size();
4212 for (int i=0; i<N; i++) {
4213 WindowState w = wtoken.allAppWindows.get(i);
4214 w.mAppFreezing = true;
4215 }
4216 }
4217 }
Romain Guy06882f82009-06-10 13:36:04 -07004218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 public void startAppFreezingScreen(IBinder token, int configChanges) {
4220 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4221 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004222 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 }
4224
4225 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004226 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004227 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004228 return;
4229 }
Romain Guy06882f82009-06-10 13:36:04 -07004230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004231 AppWindowToken wtoken = findAppWindowToken(token);
4232 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004233 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004234 return;
4235 }
4236 final long origId = Binder.clearCallingIdentity();
4237 startAppFreezingScreenLocked(wtoken, configChanges);
4238 Binder.restoreCallingIdentity(origId);
4239 }
4240 }
Romain Guy06882f82009-06-10 13:36:04 -07004241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004242 public void stopAppFreezingScreen(IBinder token, boolean force) {
4243 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4244 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004245 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 }
4247
4248 synchronized(mWindowMap) {
4249 AppWindowToken wtoken = findAppWindowToken(token);
4250 if (wtoken == null || wtoken.appToken == null) {
4251 return;
4252 }
4253 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004254 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4256 unsetAppFreezingScreenLocked(wtoken, true, force);
4257 Binder.restoreCallingIdentity(origId);
4258 }
4259 }
Romain Guy06882f82009-06-10 13:36:04 -07004260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 public void removeAppToken(IBinder token) {
4262 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4263 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004264 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 }
4266
4267 AppWindowToken wtoken = null;
4268 AppWindowToken startingToken = null;
4269 boolean delayed = false;
4270
4271 final long origId = Binder.clearCallingIdentity();
4272 synchronized(mWindowMap) {
4273 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004274 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004275 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004276 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004277 wtoken.inPendingTransaction = false;
4278 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004279 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 if (mClosingApps.contains(wtoken)) {
4281 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004282 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004283 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004284 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 delayed = true;
4286 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004287 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 TAG, "Removing app " + wtoken + " delayed=" + delayed
4289 + " animation=" + wtoken.animation
4290 + " animating=" + wtoken.animating);
4291 if (delayed) {
4292 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004293 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4294 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004295 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004296 } else {
4297 // Make sure there is no animation running on this token,
4298 // so any windows associated with it will be removed as
4299 // soon as their animations are complete
4300 wtoken.animation = null;
4301 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004303 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4304 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 mAppTokens.remove(wtoken);
4306 wtoken.removed = true;
4307 if (wtoken.startingData != null) {
4308 startingToken = wtoken;
4309 }
4310 unsetAppFreezingScreenLocked(wtoken, true, true);
4311 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004312 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 mFocusedApp = null;
4314 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004315 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 }
4317 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004318 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 }
Romain Guy06882f82009-06-10 13:36:04 -07004320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 if (!delayed && wtoken != null) {
4322 wtoken.updateReportedVisibilityLocked();
4323 }
4324 }
4325 Binder.restoreCallingIdentity(origId);
4326
4327 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004328 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 + startingToken + ": app token removed");
4330 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4331 mH.sendMessage(m);
4332 }
4333 }
4334
4335 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4336 final int NW = token.windows.size();
4337 for (int i=0; i<NW; i++) {
4338 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004339 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004340 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004341 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004342 int j = win.mChildWindows.size();
4343 while (j > 0) {
4344 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004345 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004346 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004347 "Tmp removing child window " + cwin);
4348 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 }
4350 }
4351 return NW > 0;
4352 }
4353
4354 void dumpAppTokensLocked() {
4355 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004356 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
4358 }
Romain Guy06882f82009-06-10 13:36:04 -07004359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 void dumpWindowsLocked() {
4361 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 }
4364 }
Romain Guy06882f82009-06-10 13:36:04 -07004365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 private int findWindowOffsetLocked(int tokenPos) {
4367 final int NW = mWindows.size();
4368
4369 if (tokenPos >= mAppTokens.size()) {
4370 int i = NW;
4371 while (i > 0) {
4372 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004373 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004374 if (win.getAppToken() != null) {
4375 return i+1;
4376 }
4377 }
4378 }
4379
4380 while (tokenPos > 0) {
4381 // Find the first app token below the new position that has
4382 // a window displayed.
4383 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004384 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004386 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004387 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004388 "Skipping token -- currently sending to bottom");
4389 tokenPos--;
4390 continue;
4391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004392 int i = wtoken.windows.size();
4393 while (i > 0) {
4394 i--;
4395 WindowState win = wtoken.windows.get(i);
4396 int j = win.mChildWindows.size();
4397 while (j > 0) {
4398 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004399 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004400 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 for (int pos=NW-1; pos>=0; pos--) {
4402 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004403 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404 "Found child win @" + (pos+1));
4405 return pos+1;
4406 }
4407 }
4408 }
4409 }
4410 for (int pos=NW-1; pos>=0; pos--) {
4411 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004412 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 return pos+1;
4414 }
4415 }
4416 }
4417 tokenPos--;
4418 }
4419
4420 return 0;
4421 }
4422
4423 private final int reAddWindowLocked(int index, WindowState win) {
4424 final int NCW = win.mChildWindows.size();
4425 boolean added = false;
4426 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004427 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004429 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004430 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004431 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 mWindows.add(index, win);
4433 index++;
4434 added = true;
4435 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004436 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004437 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004438 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 mWindows.add(index, cwin);
4440 index++;
4441 }
4442 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004443 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004444 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004445 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 mWindows.add(index, win);
4447 index++;
4448 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004449 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004450 return index;
4451 }
Romain Guy06882f82009-06-10 13:36:04 -07004452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4454 final int NW = token.windows.size();
4455 for (int i=0; i<NW; i++) {
4456 index = reAddWindowLocked(index, token.windows.get(i));
4457 }
4458 return index;
4459 }
4460
4461 public void moveAppToken(int index, IBinder token) {
4462 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4463 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004464 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004465 }
4466
4467 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004468 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 if (DEBUG_REORDER) dumpAppTokensLocked();
4470 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004471 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4472 "Start moving token " + wtoken + " initially at "
4473 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004475 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 + token + " (" + wtoken + ")");
4477 return;
4478 }
4479 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004480 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004481 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004485 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 if (DEBUG_REORDER) dumpWindowsLocked();
4487 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004488 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 if (DEBUG_REORDER) dumpWindowsLocked();
4490 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004491 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 if (DEBUG_REORDER) dumpWindowsLocked();
4493 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 mLayoutNeeded = true;
4495 performLayoutAndPlaceSurfacesLocked();
4496 }
4497 Binder.restoreCallingIdentity(origId);
4498 }
4499 }
4500
4501 private void removeAppTokensLocked(List<IBinder> tokens) {
4502 // XXX This should be done more efficiently!
4503 // (take advantage of the fact that both lists should be
4504 // ordered in the same way.)
4505 int N = tokens.size();
4506 for (int i=0; i<N; i++) {
4507 IBinder token = tokens.get(i);
4508 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004509 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4510 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004512 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 + token + " (" + wtoken + ")");
4514 i--;
4515 N--;
4516 }
4517 }
4518 }
4519
Dianne Hackborna8f60182009-09-01 19:01:50 -07004520 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4521 boolean updateFocusAndLayout) {
4522 // First remove all of the windows from the list.
4523 tmpRemoveAppWindowsLocked(wtoken);
4524
4525 // Where to start adding?
4526 int pos = findWindowOffsetLocked(tokenPos);
4527
4528 // And now add them back at the correct place.
4529 pos = reAddAppWindowsLocked(pos, wtoken);
4530
4531 if (updateFocusAndLayout) {
4532 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4533 assignLayersLocked();
4534 }
4535 mLayoutNeeded = true;
4536 performLayoutAndPlaceSurfacesLocked();
4537 }
4538 }
4539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4541 // First remove all of the windows from the list.
4542 final int N = tokens.size();
4543 int i;
4544 for (i=0; i<N; i++) {
4545 WindowToken token = mTokenMap.get(tokens.get(i));
4546 if (token != null) {
4547 tmpRemoveAppWindowsLocked(token);
4548 }
4549 }
4550
4551 // Where to start adding?
4552 int pos = findWindowOffsetLocked(tokenPos);
4553
4554 // And now add them back at the correct place.
4555 for (i=0; i<N; i++) {
4556 WindowToken token = mTokenMap.get(tokens.get(i));
4557 if (token != null) {
4558 pos = reAddAppWindowsLocked(pos, token);
4559 }
4560 }
4561
Dianne Hackborna8f60182009-09-01 19:01:50 -07004562 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4563 assignLayersLocked();
4564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 mLayoutNeeded = true;
4566 performLayoutAndPlaceSurfacesLocked();
4567
4568 //dump();
4569 }
4570
4571 public void moveAppTokensToTop(List<IBinder> tokens) {
4572 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4573 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004574 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004575 }
4576
4577 final long origId = Binder.clearCallingIdentity();
4578 synchronized(mWindowMap) {
4579 removeAppTokensLocked(tokens);
4580 final int N = tokens.size();
4581 for (int i=0; i<N; i++) {
4582 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4583 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004584 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4585 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004587 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004588 mToTopApps.remove(wt);
4589 mToBottomApps.remove(wt);
4590 mToTopApps.add(wt);
4591 wt.sendingToBottom = false;
4592 wt.sendingToTop = true;
4593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004594 }
4595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004596
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004597 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004598 moveAppWindowsLocked(tokens, mAppTokens.size());
4599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600 }
4601 Binder.restoreCallingIdentity(origId);
4602 }
4603
4604 public void moveAppTokensToBottom(List<IBinder> tokens) {
4605 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4606 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004607 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004608 }
4609
4610 final long origId = Binder.clearCallingIdentity();
4611 synchronized(mWindowMap) {
4612 removeAppTokensLocked(tokens);
4613 final int N = tokens.size();
4614 int pos = 0;
4615 for (int i=0; i<N; i++) {
4616 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4617 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004618 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4619 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004620 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004621 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004622 mToTopApps.remove(wt);
4623 mToBottomApps.remove(wt);
4624 mToBottomApps.add(i, wt);
4625 wt.sendingToTop = false;
4626 wt.sendingToBottom = true;
4627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004628 pos++;
4629 }
4630 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004631
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004632 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004633 moveAppWindowsLocked(tokens, 0);
4634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 }
4636 Binder.restoreCallingIdentity(origId);
4637 }
4638
4639 // -------------------------------------------------------------
4640 // Misc IWindowSession methods
4641 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004642
Jim Miller284b62e2010-06-08 14:27:42 -07004643 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004644 {
Jim Miller284b62e2010-06-08 14:27:42 -07004645 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4646 // called before DevicePolicyManagerService has started.
4647 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4648 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4649 Context.DEVICE_POLICY_SERVICE);
4650 if (dpm != null) {
4651 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4652 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4653 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4654 }
Jim Millerd6b57052010-06-07 17:52:42 -07004655 }
Jim Miller284b62e2010-06-08 14:27:42 -07004656 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004657 }
4658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004660 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 != PackageManager.PERMISSION_GRANTED) {
4662 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4663 }
Jim Millerd6b57052010-06-07 17:52:42 -07004664
Jim Miller284b62e2010-06-08 14:27:42 -07004665 synchronized (mKeyguardTokenWatcher) {
4666 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004668 }
4669
4670 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004671 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 != PackageManager.PERMISSION_GRANTED) {
4673 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004675
Jim Miller284b62e2010-06-08 14:27:42 -07004676 synchronized (mKeyguardTokenWatcher) {
4677 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004678
Jim Miller284b62e2010-06-08 14:27:42 -07004679 if (!mKeyguardTokenWatcher.isAcquired()) {
4680 // If we are the last one to reenable the keyguard wait until
4681 // we have actually finished reenabling until returning.
4682 // It is possible that reenableKeyguard() can be called before
4683 // the previous disableKeyguard() is handled, in which case
4684 // neither mKeyguardTokenWatcher.acquired() or released() would
4685 // be called. In that case mKeyguardDisabled will be false here
4686 // and we have nothing to wait for.
4687 while (mKeyguardDisabled) {
4688 try {
4689 mKeyguardTokenWatcher.wait();
4690 } catch (InterruptedException e) {
4691 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004692 }
4693 }
4694 }
4695 }
4696 }
4697
4698 /**
4699 * @see android.app.KeyguardManager#exitKeyguardSecurely
4700 */
4701 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004702 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004703 != PackageManager.PERMISSION_GRANTED) {
4704 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4705 }
4706 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4707 public void onKeyguardExitResult(boolean success) {
4708 try {
4709 callback.onKeyguardExitResult(success);
4710 } catch (RemoteException e) {
4711 // Client has died, we don't care.
4712 }
4713 }
4714 });
4715 }
4716
4717 public boolean inKeyguardRestrictedInputMode() {
4718 return mPolicy.inKeyguardRestrictedKeyInputMode();
4719 }
Romain Guy06882f82009-06-10 13:36:04 -07004720
Dianne Hackbornffa42482009-09-23 22:20:11 -07004721 public void closeSystemDialogs(String reason) {
4722 synchronized(mWindowMap) {
4723 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004724 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004725 if (w.mSurface != null) {
4726 try {
4727 w.mClient.closeSystemDialogs(reason);
4728 } catch (RemoteException e) {
4729 }
4730 }
4731 }
4732 }
4733 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004735 static float fixScale(float scale) {
4736 if (scale < 0) scale = 0;
4737 else if (scale > 20) scale = 20;
4738 return Math.abs(scale);
4739 }
Romain Guy06882f82009-06-10 13:36:04 -07004740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004741 public void setAnimationScale(int which, float scale) {
4742 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4743 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004744 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004745 }
4746
4747 if (scale < 0) scale = 0;
4748 else if (scale > 20) scale = 20;
4749 scale = Math.abs(scale);
4750 switch (which) {
4751 case 0: mWindowAnimationScale = fixScale(scale); break;
4752 case 1: mTransitionAnimationScale = fixScale(scale); break;
4753 }
Romain Guy06882f82009-06-10 13:36:04 -07004754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004755 // Persist setting
4756 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4757 }
Romain Guy06882f82009-06-10 13:36:04 -07004758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004759 public void setAnimationScales(float[] scales) {
4760 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4761 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004762 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004763 }
4764
4765 if (scales != null) {
4766 if (scales.length >= 1) {
4767 mWindowAnimationScale = fixScale(scales[0]);
4768 }
4769 if (scales.length >= 2) {
4770 mTransitionAnimationScale = fixScale(scales[1]);
4771 }
4772 }
Romain Guy06882f82009-06-10 13:36:04 -07004773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004774 // Persist setting
4775 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4776 }
Romain Guy06882f82009-06-10 13:36:04 -07004777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 public float getAnimationScale(int which) {
4779 switch (which) {
4780 case 0: return mWindowAnimationScale;
4781 case 1: return mTransitionAnimationScale;
4782 }
4783 return 0;
4784 }
Romain Guy06882f82009-06-10 13:36:04 -07004785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004786 public float[] getAnimationScales() {
4787 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4788 }
Romain Guy06882f82009-06-10 13:36:04 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 public int getSwitchState(int sw) {
4791 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4792 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004793 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004795 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 }
Romain Guy06882f82009-06-10 13:36:04 -07004797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 public int getSwitchStateForDevice(int devid, int sw) {
4799 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4800 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004801 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004802 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004803 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 }
Romain Guy06882f82009-06-10 13:36:04 -07004805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004806 public int getScancodeState(int sw) {
4807 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4808 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004809 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004811 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 }
Romain Guy06882f82009-06-10 13:36:04 -07004813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004814 public int getScancodeStateForDevice(int devid, int sw) {
4815 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4816 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004817 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004819 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004820 }
Romain Guy06882f82009-06-10 13:36:04 -07004821
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004822 public int getTrackballScancodeState(int sw) {
4823 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4824 "getTrackballScancodeState()")) {
4825 throw new SecurityException("Requires READ_INPUT_STATE permission");
4826 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004827 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004828 }
4829
4830 public int getDPadScancodeState(int sw) {
4831 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4832 "getDPadScancodeState()")) {
4833 throw new SecurityException("Requires READ_INPUT_STATE permission");
4834 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004835 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004836 }
4837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004838 public int getKeycodeState(int sw) {
4839 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4840 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004841 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004843 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004844 }
Romain Guy06882f82009-06-10 13:36:04 -07004845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004846 public int getKeycodeStateForDevice(int devid, int sw) {
4847 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4848 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004849 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004851 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 }
Romain Guy06882f82009-06-10 13:36:04 -07004853
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004854 public int getTrackballKeycodeState(int sw) {
4855 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4856 "getTrackballKeycodeState()")) {
4857 throw new SecurityException("Requires READ_INPUT_STATE permission");
4858 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004859 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004860 }
4861
4862 public int getDPadKeycodeState(int sw) {
4863 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4864 "getDPadKeycodeState()")) {
4865 throw new SecurityException("Requires READ_INPUT_STATE permission");
4866 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004867 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004868 }
Jeff Browna41ca772010-08-11 14:46:32 -07004869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004871 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004872 }
Romain Guy06882f82009-06-10 13:36:04 -07004873
Jeff Browna41ca772010-08-11 14:46:32 -07004874 public InputChannel monitorInput(String inputChannelName) {
4875 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4876 "monitorInput()")) {
4877 throw new SecurityException("Requires READ_INPUT_STATE permission");
4878 }
4879 return mInputManager.monitorInput(inputChannelName);
4880 }
4881
Jeff Brown8d608662010-08-30 03:02:23 -07004882 public InputDevice getInputDevice(int deviceId) {
4883 return mInputManager.getInputDevice(deviceId);
4884 }
4885
4886 public int[] getInputDeviceIds() {
4887 return mInputManager.getInputDeviceIds();
4888 }
4889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004890 public void enableScreenAfterBoot() {
4891 synchronized(mWindowMap) {
4892 if (mSystemBooted) {
4893 return;
4894 }
4895 mSystemBooted = true;
4896 }
Romain Guy06882f82009-06-10 13:36:04 -07004897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004898 performEnableScreen();
4899 }
Romain Guy06882f82009-06-10 13:36:04 -07004900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004901 public void enableScreenIfNeededLocked() {
4902 if (mDisplayEnabled) {
4903 return;
4904 }
4905 if (!mSystemBooted) {
4906 return;
4907 }
4908 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4909 }
Romain Guy06882f82009-06-10 13:36:04 -07004910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 public void performEnableScreen() {
4912 synchronized(mWindowMap) {
4913 if (mDisplayEnabled) {
4914 return;
4915 }
4916 if (!mSystemBooted) {
4917 return;
4918 }
Romain Guy06882f82009-06-10 13:36:04 -07004919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 // Don't enable the screen until all existing windows
4921 // have been drawn.
4922 final int N = mWindows.size();
4923 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004924 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004925 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 return;
4927 }
4928 }
Romain Guy06882f82009-06-10 13:36:04 -07004929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 mDisplayEnabled = true;
4931 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004932 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004933 StringWriter sw = new StringWriter();
4934 PrintWriter pw = new PrintWriter(sw);
4935 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004936 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 }
4938 try {
4939 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4940 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004941 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 Parcel data = Parcel.obtain();
4943 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4944 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4945 data, null, 0);
4946 data.recycle();
4947 }
4948 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004949 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 }
4951 }
Romain Guy06882f82009-06-10 13:36:04 -07004952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004956 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4957 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004958 }
Romain Guy06882f82009-06-10 13:36:04 -07004959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004960 public void setInTouchMode(boolean mode) {
4961 synchronized(mWindowMap) {
4962 mInTouchMode = mode;
4963 }
4964 }
4965
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004966 // TODO: more accounting of which pid(s) turned it on, keep count,
4967 // only allow disables from pids which have count on, etc.
4968 public void showStrictModeViolation(boolean on) {
4969 int pid = Binder.getCallingPid();
4970 synchronized(mWindowMap) {
4971 // Ignoring requests to enable the red border from clients
4972 // which aren't on screen. (e.g. Broadcast Receivers in
4973 // the background..)
4974 if (on) {
4975 boolean isVisible = false;
4976 for (WindowState ws : mWindows) {
4977 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4978 isVisible = true;
4979 break;
4980 }
4981 }
4982 if (!isVisible) {
4983 return;
4984 }
4985 }
4986
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004987 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004988 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004989 try {
4990 if (mStrictModeFlash == null) {
4991 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4992 }
4993 mStrictModeFlash.setVisibility(on);
4994 } finally {
4995 Surface.closeTransaction();
4996 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004997 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004998 }
4999 }
5000
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08005001 public void setStrictModeVisualIndicatorPreference(String value) {
5002 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
5003 }
5004
Dianne Hackbornd2835932010-12-13 16:28:46 -08005005 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005006 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5007 "screenshotApplications()")) {
5008 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5009 }
5010
5011 Bitmap rawss;
5012
Dianne Hackbornd2835932010-12-13 16:28:46 -08005013 int maxLayer = 0;
5014 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005015 final Rect frame = new Rect();
5016
5017 float scale;
5018 int sw, sh, dw, dh;
5019 int rot;
5020
5021 synchronized(mWindowMap) {
5022 long ident = Binder.clearCallingIdentity();
5023
5024 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5025 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5026 + TYPE_LAYER_OFFSET;
5027 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5028
5029 // Figure out the part of the screen that is actually the app.
5030 for (int i=0; i<mWindows.size(); i++) {
5031 WindowState ws = mWindows.get(i);
5032 if (ws.mSurface == null) {
5033 continue;
5034 }
5035 if (ws.mLayer >= aboveAppLayer) {
5036 break;
5037 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005038 if (appToken != null && (ws.mAppToken == null
5039 || ws.mAppToken.token != appToken)) {
5040 continue;
5041 }
5042 if (maxLayer < ws.mAnimLayer) {
5043 maxLayer = ws.mAnimLayer;
5044 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005045 final Rect wf = ws.mFrame;
5046 final Rect cr = ws.mContentInsets;
5047 int left = wf.left + cr.left;
5048 int top = wf.top + cr.top;
5049 int right = wf.right - cr.right;
5050 int bottom = wf.bottom - cr.bottom;
5051 frame.union(left, top, right, bottom);
5052 }
5053 Binder.restoreCallingIdentity(ident);
5054
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005055 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005056 return null;
5057 }
5058
5059 // The screenshot API does not apply the current screen rotation.
5060 rot = mDisplay.getRotation();
5061 int fw = frame.width();
5062 int fh = frame.height();
5063
5064 // First try reducing to fit in x dimension.
5065 scale = maxWidth/(float)fw;
5066 sw = maxWidth;
5067 sh = (int)(fh*scale);
5068 if (sh > maxHeight) {
5069 // y dimension became too long; constrain by that.
5070 scale = maxHeight/(float)fh;
5071 sw = (int)(fw*scale);
5072 sh = maxHeight;
5073 }
5074
5075 // The screen shot will contain the entire screen.
5076 dw = (int)(mDisplay.getWidth()*scale);
5077 dh = (int)(mDisplay.getHeight()*scale);
5078 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5079 int tmp = dw;
5080 dw = dh;
5081 dh = tmp;
5082 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5083 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005084 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005085 }
5086
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005087 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005088 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5089 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005090 return null;
5091 }
5092
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005093 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5094 Matrix matrix = new Matrix();
5095 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5096 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5097 Canvas canvas = new Canvas(bm);
5098 canvas.drawBitmap(rawss, matrix, null);
5099
5100 rawss.recycle();
5101 return bm;
5102 }
5103
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005104 public void freezeRotation() {
5105 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5106 "setRotation()")) {
5107 throw new SecurityException("Requires SET_ORIENTATION permission");
5108 }
5109
5110 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5111 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5112 }
5113
5114 public void thawRotation() {
5115 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5116 "setRotation()")) {
5117 throw new SecurityException("Requires SET_ORIENTATION permission");
5118 }
5119
5120 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5121 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5122 }
5123
Romain Guy06882f82009-06-10 13:36:04 -07005124 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005125 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005126 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005127 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005128 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005129 }
5130
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005131 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005132 }
Romain Guy06882f82009-06-10 13:36:04 -07005133
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005134 public void setRotationUnchecked(int rotation,
5135 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005136 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005137 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005139 long origId = Binder.clearCallingIdentity();
5140 boolean changed;
5141 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005142 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005143 }
Romain Guy06882f82009-06-10 13:36:04 -07005144
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005145 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005146 sendNewConfiguration();
5147 }
Romain Guy06882f82009-06-10 13:36:04 -07005148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005149 Binder.restoreCallingIdentity(origId);
5150 }
Romain Guy06882f82009-06-10 13:36:04 -07005151
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005152 /**
5153 * Apply a new rotation to the screen, respecting the requests of
5154 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5155 * re-evaluate the desired rotation.
5156 *
5157 * Returns null if the rotation has been changed. In this case YOU
5158 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5159 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005160 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005161 if (mDragState != null) {
5162 // Potential rotation during a drag. Don't do the rotation now, but make
5163 // a note to perform the rotation later.
5164 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation during drag");
5165 mDragState.setDeferredRotation(rotation, animFlags);
5166 return false;
5167 }
5168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005169 boolean changed;
5170 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5171 rotation = mRequestedRotation;
5172 } else {
5173 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005174 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005175 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005176 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005177 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005179 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005180 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005182 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005183 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 "Rotation changed to " + rotation
5185 + " from " + mRotation
5186 + " (forceApp=" + mForcedAppOrientation
5187 + ", req=" + mRequestedRotation + ")");
5188 mRotation = rotation;
5189 mWindowsFreezingScreen = true;
5190 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5191 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5192 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005193 mWaitingForConfig = true;
5194 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005195 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005196 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005197 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005198 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005199 if (CUSTOM_SCREEN_ROTATION) {
5200 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005201 if (!inTransaction) {
5202 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5203 ">>> OPEN TRANSACTION setRotationUnchecked");
5204 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005205 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005206 try {
5207 if (mScreenRotationAnimation != null) {
5208 mScreenRotationAnimation.setRotation(rotation);
5209 }
5210 } finally {
5211 if (!inTransaction) {
5212 Surface.closeTransaction();
5213 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5214 "<<< CLOSE TRANSACTION setRotationUnchecked");
5215 }
5216 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005217 Surface.setOrientation(0, rotation, animFlags);
5218 Surface.unfreezeDisplay(0);
5219 } else {
5220 Surface.setOrientation(0, rotation, animFlags);
5221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005222 }
5223 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005224 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005225 if (w.mSurface != null) {
5226 w.mOrientationChanging = true;
5227 }
5228 }
5229 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5230 try {
5231 mRotationWatchers.get(i).onRotationChanged(rotation);
5232 } catch (RemoteException e) {
5233 }
5234 }
5235 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005237 return changed;
5238 }
Romain Guy06882f82009-06-10 13:36:04 -07005239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005240 public int getRotation() {
5241 return mRotation;
5242 }
5243
5244 public int watchRotation(IRotationWatcher watcher) {
5245 final IBinder watcherBinder = watcher.asBinder();
5246 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5247 public void binderDied() {
5248 synchronized (mWindowMap) {
5249 for (int i=0; i<mRotationWatchers.size(); i++) {
5250 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005251 IRotationWatcher removed = mRotationWatchers.remove(i);
5252 if (removed != null) {
5253 removed.asBinder().unlinkToDeath(this, 0);
5254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005255 i--;
5256 }
5257 }
5258 }
5259 }
5260 };
Romain Guy06882f82009-06-10 13:36:04 -07005261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 synchronized (mWindowMap) {
5263 try {
5264 watcher.asBinder().linkToDeath(dr, 0);
5265 mRotationWatchers.add(watcher);
5266 } catch (RemoteException e) {
5267 // Client died, no cleanup needed.
5268 }
Romain Guy06882f82009-06-10 13:36:04 -07005269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005270 return mRotation;
5271 }
5272 }
5273
5274 /**
5275 * Starts the view server on the specified port.
5276 *
5277 * @param port The port to listener to.
5278 *
5279 * @return True if the server was successfully started, false otherwise.
5280 *
5281 * @see com.android.server.ViewServer
5282 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5283 */
5284 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005285 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005286 return false;
5287 }
5288
5289 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5290 return false;
5291 }
5292
5293 if (port < 1024) {
5294 return false;
5295 }
5296
5297 if (mViewServer != null) {
5298 if (!mViewServer.isRunning()) {
5299 try {
5300 return mViewServer.start();
5301 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005302 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005303 }
5304 }
5305 return false;
5306 }
5307
5308 try {
5309 mViewServer = new ViewServer(this, port);
5310 return mViewServer.start();
5311 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005312 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 }
5314 return false;
5315 }
5316
Romain Guy06882f82009-06-10 13:36:04 -07005317 private boolean isSystemSecure() {
5318 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5319 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5320 }
5321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005322 /**
5323 * Stops the view server if it exists.
5324 *
5325 * @return True if the server stopped, false if it wasn't started or
5326 * couldn't be stopped.
5327 *
5328 * @see com.android.server.ViewServer
5329 */
5330 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005331 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005332 return false;
5333 }
5334
5335 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5336 return false;
5337 }
5338
5339 if (mViewServer != null) {
5340 return mViewServer.stop();
5341 }
5342 return false;
5343 }
5344
5345 /**
5346 * Indicates whether the view server is running.
5347 *
5348 * @return True if the server is running, false otherwise.
5349 *
5350 * @see com.android.server.ViewServer
5351 */
5352 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005353 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005354 return false;
5355 }
5356
5357 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5358 return false;
5359 }
5360
5361 return mViewServer != null && mViewServer.isRunning();
5362 }
5363
5364 /**
5365 * Lists all availble windows in the system. The listing is written in the
5366 * specified Socket's output stream with the following syntax:
5367 * windowHashCodeInHexadecimal windowName
5368 * Each line of the ouput represents a different window.
5369 *
5370 * @param client The remote client to send the listing to.
5371 * @return False if an error occured, true otherwise.
5372 */
5373 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005374 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005375 return false;
5376 }
5377
5378 boolean result = true;
5379
Jeff Browne33348b2010-07-15 23:54:05 -07005380 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005381 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005383 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005384 }
5385
5386 BufferedWriter out = null;
5387
5388 // Any uncaught exception will crash the system process
5389 try {
5390 OutputStream clientStream = client.getOutputStream();
5391 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5392
5393 final int count = windows.length;
5394 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005395 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005396 out.write(Integer.toHexString(System.identityHashCode(w)));
5397 out.write(' ');
5398 out.append(w.mAttrs.getTitle());
5399 out.write('\n');
5400 }
5401
5402 out.write("DONE.\n");
5403 out.flush();
5404 } catch (Exception e) {
5405 result = false;
5406 } finally {
5407 if (out != null) {
5408 try {
5409 out.close();
5410 } catch (IOException e) {
5411 result = false;
5412 }
5413 }
5414 }
5415
5416 return result;
5417 }
5418
5419 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005420 * Returns the focused window in the following format:
5421 * windowHashCodeInHexadecimal windowName
5422 *
5423 * @param client The remote client to send the listing to.
5424 * @return False if an error occurred, true otherwise.
5425 */
5426 boolean viewServerGetFocusedWindow(Socket client) {
5427 if (isSystemSecure()) {
5428 return false;
5429 }
5430
5431 boolean result = true;
5432
5433 WindowState focusedWindow = getFocusedWindow();
5434
5435 BufferedWriter out = null;
5436
5437 // Any uncaught exception will crash the system process
5438 try {
5439 OutputStream clientStream = client.getOutputStream();
5440 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5441
5442 if(focusedWindow != null) {
5443 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5444 out.write(' ');
5445 out.append(focusedWindow.mAttrs.getTitle());
5446 }
5447 out.write('\n');
5448 out.flush();
5449 } catch (Exception e) {
5450 result = false;
5451 } finally {
5452 if (out != null) {
5453 try {
5454 out.close();
5455 } catch (IOException e) {
5456 result = false;
5457 }
5458 }
5459 }
5460
5461 return result;
5462 }
5463
5464 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005465 * Sends a command to a target window. The result of the command, if any, will be
5466 * written in the output stream of the specified socket.
5467 *
5468 * The parameters must follow this syntax:
5469 * windowHashcode extra
5470 *
5471 * Where XX is the length in characeters of the windowTitle.
5472 *
5473 * The first parameter is the target window. The window with the specified hashcode
5474 * will be the target. If no target can be found, nothing happens. The extra parameters
5475 * will be delivered to the target window and as parameters to the command itself.
5476 *
5477 * @param client The remote client to sent the result, if any, to.
5478 * @param command The command to execute.
5479 * @param parameters The command parameters.
5480 *
5481 * @return True if the command was successfully delivered, false otherwise. This does
5482 * not indicate whether the command itself was successful.
5483 */
5484 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005485 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005486 return false;
5487 }
5488
5489 boolean success = true;
5490 Parcel data = null;
5491 Parcel reply = null;
5492
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005493 BufferedWriter out = null;
5494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005495 // Any uncaught exception will crash the system process
5496 try {
5497 // Find the hashcode of the window
5498 int index = parameters.indexOf(' ');
5499 if (index == -1) {
5500 index = parameters.length();
5501 }
5502 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005503 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005504
5505 // Extract the command's parameter after the window description
5506 if (index < parameters.length()) {
5507 parameters = parameters.substring(index + 1);
5508 } else {
5509 parameters = "";
5510 }
5511
5512 final WindowManagerService.WindowState window = findWindow(hashCode);
5513 if (window == null) {
5514 return false;
5515 }
5516
5517 data = Parcel.obtain();
5518 data.writeInterfaceToken("android.view.IWindow");
5519 data.writeString(command);
5520 data.writeString(parameters);
5521 data.writeInt(1);
5522 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5523
5524 reply = Parcel.obtain();
5525
5526 final IBinder binder = window.mClient.asBinder();
5527 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5528 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5529
5530 reply.readException();
5531
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005532 if (!client.isOutputShutdown()) {
5533 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5534 out.write("DONE\n");
5535 out.flush();
5536 }
5537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005538 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005539 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005540 success = false;
5541 } finally {
5542 if (data != null) {
5543 data.recycle();
5544 }
5545 if (reply != null) {
5546 reply.recycle();
5547 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005548 if (out != null) {
5549 try {
5550 out.close();
5551 } catch (IOException e) {
5552
5553 }
5554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005555 }
5556
5557 return success;
5558 }
5559
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005560 public void addWindowChangeListener(WindowChangeListener listener) {
5561 synchronized(mWindowMap) {
5562 mWindowChangeListeners.add(listener);
5563 }
5564 }
5565
5566 public void removeWindowChangeListener(WindowChangeListener listener) {
5567 synchronized(mWindowMap) {
5568 mWindowChangeListeners.remove(listener);
5569 }
5570 }
5571
5572 private void notifyWindowsChanged() {
5573 WindowChangeListener[] windowChangeListeners;
5574 synchronized(mWindowMap) {
5575 if(mWindowChangeListeners.isEmpty()) {
5576 return;
5577 }
5578 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5579 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5580 }
5581 int N = windowChangeListeners.length;
5582 for(int i = 0; i < N; i++) {
5583 windowChangeListeners[i].windowsChanged();
5584 }
5585 }
5586
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005587 private void notifyFocusChanged() {
5588 WindowChangeListener[] windowChangeListeners;
5589 synchronized(mWindowMap) {
5590 if(mWindowChangeListeners.isEmpty()) {
5591 return;
5592 }
5593 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5594 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5595 }
5596 int N = windowChangeListeners.length;
5597 for(int i = 0; i < N; i++) {
5598 windowChangeListeners[i].focusChanged();
5599 }
5600 }
5601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005602 private WindowState findWindow(int hashCode) {
5603 if (hashCode == -1) {
5604 return getFocusedWindow();
5605 }
5606
5607 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005608 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005609 final int count = windows.size();
5610
5611 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005612 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005613 if (System.identityHashCode(w) == hashCode) {
5614 return w;
5615 }
5616 }
5617 }
5618
5619 return null;
5620 }
5621
5622 /*
5623 * Instruct the Activity Manager to fetch the current configuration and broadcast
5624 * that to config-changed listeners if appropriate.
5625 */
5626 void sendNewConfiguration() {
5627 try {
5628 mActivityManager.updateConfiguration(null);
5629 } catch (RemoteException e) {
5630 }
5631 }
Romain Guy06882f82009-06-10 13:36:04 -07005632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005633 public Configuration computeNewConfiguration() {
5634 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005635 Configuration config = computeNewConfigurationLocked();
5636 if (config == null && mWaitingForConfig) {
5637 // Nothing changed but we are waiting for something... stop that!
5638 mWaitingForConfig = false;
5639 performLayoutAndPlaceSurfacesLocked();
5640 }
5641 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005642 }
5643 }
Romain Guy06882f82009-06-10 13:36:04 -07005644
Dianne Hackbornc485a602009-03-24 22:39:49 -07005645 Configuration computeNewConfigurationLocked() {
5646 Configuration config = new Configuration();
5647 if (!computeNewConfigurationLocked(config)) {
5648 return null;
5649 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005650 return config;
5651 }
Romain Guy06882f82009-06-10 13:36:04 -07005652
Dianne Hackbornc485a602009-03-24 22:39:49 -07005653 boolean computeNewConfigurationLocked(Configuration config) {
5654 if (mDisplay == null) {
5655 return false;
5656 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005657
5658 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005659
5660 // Use the effective "visual" dimensions based on current rotation
5661 final boolean rotated = (mRotation == Surface.ROTATION_90
5662 || mRotation == Surface.ROTATION_270);
5663 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5664 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5665
Dianne Hackbornc485a602009-03-24 22:39:49 -07005666 int orientation = Configuration.ORIENTATION_SQUARE;
5667 if (dw < dh) {
5668 orientation = Configuration.ORIENTATION_PORTRAIT;
5669 } else if (dw > dh) {
5670 orientation = Configuration.ORIENTATION_LANDSCAPE;
5671 }
5672 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005673
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005674 DisplayMetrics dm = new DisplayMetrics();
5675 mDisplay.getMetrics(dm);
5676 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5677
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005678 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005679 // Note we only do this once because at this point we don't
5680 // expect the screen to change in this way at runtime, and want
5681 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005682 int longSize = dw;
5683 int shortSize = dh;
5684 if (longSize < shortSize) {
5685 int tmp = longSize;
5686 longSize = shortSize;
5687 shortSize = tmp;
5688 }
5689 longSize = (int)(longSize/dm.density);
5690 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005691
Dianne Hackborn723738c2009-06-25 19:48:04 -07005692 // These semi-magic numbers define our compatibility modes for
5693 // applications with different screens. Don't change unless you
5694 // make sure to test lots and lots of apps!
5695 if (longSize < 470) {
5696 // This is shorter than an HVGA normal density screen (which
5697 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005698 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5699 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005700 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005701 // What size is this screen screen?
5702 if (longSize >= 800 && shortSize >= 600) {
5703 // SVGA or larger screens at medium density are the point
5704 // at which we consider it to be an extra large screen.
5705 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005706 } else if (longSize >= 530 && shortSize >= 400) {
5707 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005708 // at which we consider it to be a large screen.
5709 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5710 } else {
5711 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005712
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005713 // If this screen is wider than normal HVGA, or taller
5714 // than FWVGA, then for old apps we want to run in size
5715 // compatibility mode.
5716 if (shortSize > 321 || longSize > 570) {
5717 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5718 }
5719 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005720
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005721 // Is this a long screen?
5722 if (((longSize*3)/5) >= (shortSize-1)) {
5723 // Anything wider than WVGA (5:3) is considering to be long.
5724 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5725 } else {
5726 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5727 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005728 }
5729 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005730 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005731
Dianne Hackbornc485a602009-03-24 22:39:49 -07005732 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5733 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5734 mPolicy.adjustConfigurationLw(config);
5735 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005736 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005737
5738 // -------------------------------------------------------------
5739 // Drag and drop
5740 // -------------------------------------------------------------
5741
5742 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005743 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005744 if (DEBUG_DRAG) {
5745 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005746 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005747 + " asbinder=" + window.asBinder());
5748 }
5749
5750 final int callerPid = Binder.getCallingPid();
5751 final long origId = Binder.clearCallingIdentity();
5752 IBinder token = null;
5753
5754 try {
5755 synchronized (mWindowMap) {
5756 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005757 if (mDragState == null) {
5758 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5759 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5760 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005761 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005762 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005763 // TODO: preserve flags param in DragState
5764 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005765 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005766 token = mDragState.mToken = new Binder();
5767
5768 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005769 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5770 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005771 mH.sendMessageDelayed(msg, 5000);
5772 } else {
5773 Slog.w(TAG, "Drag already in progress");
5774 }
5775 } catch (Surface.OutOfResourcesException e) {
5776 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5777 if (mDragState != null) {
5778 mDragState.reset();
5779 mDragState = null;
5780 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005781 }
5782 }
5783 } finally {
5784 Binder.restoreCallingIdentity(origId);
5785 }
5786
5787 return token;
5788 }
5789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005790 // -------------------------------------------------------------
5791 // Input Events and Focus Management
5792 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005793
Jeff Brown349703e2010-06-22 01:27:15 -07005794 InputMonitor mInputMonitor = new InputMonitor();
5795
5796 /* Tracks the progress of input dispatch and ensures that input dispatch state
5797 * is kept in sync with changes in window focus, visibility, registration, and
5798 * other relevant Window Manager state transitions. */
5799 final class InputMonitor {
5800 // Current window with input focus for keys and other non-touch events. May be null.
5801 private WindowState mInputFocus;
5802
5803 // When true, prevents input dispatch from proceeding until set to false again.
5804 private boolean mInputDispatchFrozen;
5805
5806 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5807 private boolean mInputDispatchEnabled = true;
5808
5809 // Temporary list of windows information to provide to the input dispatcher.
5810 private InputWindowList mTempInputWindows = new InputWindowList();
5811
5812 // Temporary input application object to provide to the input dispatcher.
5813 private InputApplication mTempInputApplication = new InputApplication();
5814
5815 /* Notifies the window manager about a broken input channel.
5816 *
5817 * Called by the InputManager.
5818 */
Jeff Brown928e0542011-01-10 11:17:36 -08005819 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5820 if (inputWindowHandle == null) {
5821 return;
5822 }
5823
Jeff Brown349703e2010-06-22 01:27:15 -07005824 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005825 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005826 Slog.i(TAG, "WINDOW DIED " + windowState);
5827 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005828 }
5829 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005830
Jeff Brown519e0242010-09-15 15:18:56 -07005831 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005832 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005833 *
5834 * Called by the InputManager.
5835 */
Jeff Brown928e0542011-01-10 11:17:36 -08005836 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5837 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005838 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005839 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005840 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005841 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005842 if (windowState != null) {
5843 Slog.i(TAG, "Input event dispatching timed out sending to "
5844 + windowState.mAttrs.getTitle());
5845 appWindowToken = windowState.mAppToken;
5846 }
Jeff Brown349703e2010-06-22 01:27:15 -07005847 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005848 }
5849
Jeff Brown928e0542011-01-10 11:17:36 -08005850 if (appWindowToken == null && inputApplicationHandle != null) {
5851 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005852 Slog.i(TAG, "Input event dispatching timed out sending to application "
5853 + appWindowToken.stringName);
5854 }
Jeff Brown349703e2010-06-22 01:27:15 -07005855
Jeff Brown519e0242010-09-15 15:18:56 -07005856 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005857 try {
5858 // Notify the activity manager about the timeout and let it decide whether
5859 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005860 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005861 if (! abort) {
5862 // The activity manager declined to abort dispatching.
5863 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005864 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005865 }
Jeff Brown349703e2010-06-22 01:27:15 -07005866 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005867 }
5868 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005869 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005870 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005871
Chris Tatea32dcf72010-10-14 12:13:50 -07005872 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005873 final InputWindow inputWindow = windowList.add();
5874 inputWindow.inputChannel = mDragState.mServerChannel;
5875 inputWindow.name = "drag";
5876 inputWindow.layoutParamsFlags = 0;
5877 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5878 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5879 inputWindow.visible = true;
5880 inputWindow.canReceiveKeys = false;
5881 inputWindow.hasFocus = true;
5882 inputWindow.hasWallpaper = false;
5883 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005884 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005885 inputWindow.ownerPid = Process.myPid();
5886 inputWindow.ownerUid = Process.myUid();
5887
5888 // The drag window covers the entire display
5889 inputWindow.frameLeft = 0;
5890 inputWindow.frameTop = 0;
5891 inputWindow.frameRight = mDisplay.getWidth();
5892 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005893
Christopher Tatea53146c2010-09-07 11:57:52 -07005894 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5895 inputWindow.visibleFrameTop = inputWindow.frameTop;
5896 inputWindow.visibleFrameRight = inputWindow.frameRight;
5897 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5898
5899 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5900 inputWindow.touchableAreaTop = inputWindow.frameTop;
5901 inputWindow.touchableAreaRight = inputWindow.frameRight;
5902 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5903 }
5904
Jeff Brown349703e2010-06-22 01:27:15 -07005905 /* Updates the cached window information provided to the input dispatcher. */
5906 public void updateInputWindowsLw() {
5907 // Populate the input window list with information about all of the windows that
5908 // could potentially receive input.
5909 // As an optimization, we could try to prune the list of windows but this turns
5910 // out to be difficult because only the native code knows for sure which window
5911 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005912 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005913
5914 // If there's a drag in flight, provide a pseudowindow to catch drag input
5915 final boolean inDrag = (mDragState != null);
5916 if (inDrag) {
5917 if (DEBUG_DRAG) {
5918 Log.d(TAG, "Inserting drag window");
5919 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005920 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005921 }
5922
Jeff Brown7fbdc842010-06-17 20:52:56 -07005923 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005924 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005925 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005926 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005927 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005928 continue;
5929 }
5930
Jeff Brown349703e2010-06-22 01:27:15 -07005931 final int flags = child.mAttrs.flags;
5932 final int type = child.mAttrs.type;
5933
5934 final boolean hasFocus = (child == mInputFocus);
5935 final boolean isVisible = child.isVisibleLw();
5936 final boolean hasWallpaper = (child == mWallpaperTarget)
5937 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005938
5939 // If there's a drag in progress and 'child' is a potential drop target,
5940 // make sure it's been told about the drag
5941 if (inDrag && isVisible) {
5942 mDragState.sendDragStartedIfNeededLw(child);
5943 }
5944
Jeff Brown349703e2010-06-22 01:27:15 -07005945 // Add a window to our list of input windows.
5946 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005947 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005948 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005949 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005950 inputWindow.layoutParamsFlags = flags;
5951 inputWindow.layoutParamsType = type;
5952 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5953 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005954 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005955 inputWindow.hasFocus = hasFocus;
5956 inputWindow.hasWallpaper = hasWallpaper;
5957 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005958 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005959 inputWindow.ownerPid = child.mSession.mPid;
5960 inputWindow.ownerUid = child.mSession.mUid;
5961
5962 final Rect frame = child.mFrame;
5963 inputWindow.frameLeft = frame.left;
5964 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005965 inputWindow.frameRight = frame.right;
5966 inputWindow.frameBottom = frame.bottom;
5967
5968 final Rect visibleFrame = child.mVisibleFrame;
5969 inputWindow.visibleFrameLeft = visibleFrame.left;
5970 inputWindow.visibleFrameTop = visibleFrame.top;
5971 inputWindow.visibleFrameRight = visibleFrame.right;
5972 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005973
5974 switch (child.mTouchableInsets) {
5975 default:
5976 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5977 inputWindow.touchableAreaLeft = frame.left;
5978 inputWindow.touchableAreaTop = frame.top;
5979 inputWindow.touchableAreaRight = frame.right;
5980 inputWindow.touchableAreaBottom = frame.bottom;
5981 break;
5982
5983 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5984 Rect inset = child.mGivenContentInsets;
5985 inputWindow.touchableAreaLeft = frame.left + inset.left;
5986 inputWindow.touchableAreaTop = frame.top + inset.top;
5987 inputWindow.touchableAreaRight = frame.right - inset.right;
5988 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5989 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005990 }
Jeff Brown349703e2010-06-22 01:27:15 -07005991
5992 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5993 Rect inset = child.mGivenVisibleInsets;
5994 inputWindow.touchableAreaLeft = frame.left + inset.left;
5995 inputWindow.touchableAreaTop = frame.top + inset.top;
5996 inputWindow.touchableAreaRight = frame.right - inset.right;
5997 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005998 break;
5999 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006000 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006001 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006002
Jeff Brown349703e2010-06-22 01:27:15 -07006003 // Send windows to native code.
6004 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006005
Jeff Brown349703e2010-06-22 01:27:15 -07006006 // Clear the list in preparation for the next round.
6007 // Also avoids keeping InputChannel objects referenced unnecessarily.
6008 mTempInputWindows.clear();
6009 }
6010
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006011 /* Notifies that the lid switch changed state. */
6012 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6013 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6014 }
6015
Jeff Brown349703e2010-06-22 01:27:15 -07006016 /* Provides an opportunity for the window manager policy to intercept early key
6017 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006018 public int interceptKeyBeforeQueueing(
6019 KeyEvent event, int policyFlags, boolean isScreenOn) {
6020 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006021 }
6022
6023 /* Provides an opportunity for the window manager policy to process a key before
6024 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006025 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006026 InputWindowHandle focus, KeyEvent event, int policyFlags) {
6027 WindowState windowState = (WindowState) focus.windowState;
Jeff Brown1f245102010-11-18 20:53:46 -08006028 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006029 }
6030
Jeff Brown3915bb82010-11-05 15:02:16 -07006031 /* Provides an opportunity for the window manager policy to process a key that
6032 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006033 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006034 InputWindowHandle focus, KeyEvent event, int policyFlags) {
6035 WindowState windowState = (WindowState) focus.windowState;
Jeff Brown1f245102010-11-18 20:53:46 -08006036 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006037 }
6038
Jeff Brown349703e2010-06-22 01:27:15 -07006039 /* Called when the current input focus changes.
6040 * Layer assignment is assumed to be complete by the time this is called.
6041 */
6042 public void setInputFocusLw(WindowState newWindow) {
6043 if (DEBUG_INPUT) {
6044 Slog.d(TAG, "Input focus has changed to " + newWindow);
6045 }
6046
6047 if (newWindow != mInputFocus) {
6048 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006049 // Displaying a window implicitly causes dispatching to be unpaused.
6050 // This is to protect against bugs if someone pauses dispatching but
6051 // forgets to resume.
6052 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006053 }
Jeff Brown349703e2010-06-22 01:27:15 -07006054
6055 mInputFocus = newWindow;
6056 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006057 }
6058 }
6059
Jeff Brown349703e2010-06-22 01:27:15 -07006060 public void setFocusedAppLw(AppWindowToken newApp) {
6061 // Focused app has changed.
6062 if (newApp == null) {
6063 mInputManager.setFocusedApplication(null);
6064 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006065 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006066 mTempInputApplication.name = newApp.toString();
6067 mTempInputApplication.dispatchingTimeoutNanos =
6068 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006069
Jeff Brown349703e2010-06-22 01:27:15 -07006070 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006071
6072 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006073 }
6074 }
6075
Jeff Brown349703e2010-06-22 01:27:15 -07006076 public void pauseDispatchingLw(WindowToken window) {
6077 if (! window.paused) {
6078 if (DEBUG_INPUT) {
6079 Slog.v(TAG, "Pausing WindowToken " + window);
6080 }
6081
6082 window.paused = true;
6083 updateInputWindowsLw();
6084 }
6085 }
6086
6087 public void resumeDispatchingLw(WindowToken window) {
6088 if (window.paused) {
6089 if (DEBUG_INPUT) {
6090 Slog.v(TAG, "Resuming WindowToken " + window);
6091 }
6092
6093 window.paused = false;
6094 updateInputWindowsLw();
6095 }
6096 }
6097
6098 public void freezeInputDispatchingLw() {
6099 if (! mInputDispatchFrozen) {
6100 if (DEBUG_INPUT) {
6101 Slog.v(TAG, "Freezing input dispatching");
6102 }
6103
6104 mInputDispatchFrozen = true;
6105 updateInputDispatchModeLw();
6106 }
6107 }
6108
6109 public void thawInputDispatchingLw() {
6110 if (mInputDispatchFrozen) {
6111 if (DEBUG_INPUT) {
6112 Slog.v(TAG, "Thawing input dispatching");
6113 }
6114
6115 mInputDispatchFrozen = false;
6116 updateInputDispatchModeLw();
6117 }
6118 }
6119
6120 public void setEventDispatchingLw(boolean enabled) {
6121 if (mInputDispatchEnabled != enabled) {
6122 if (DEBUG_INPUT) {
6123 Slog.v(TAG, "Setting event dispatching to " + enabled);
6124 }
6125
6126 mInputDispatchEnabled = enabled;
6127 updateInputDispatchModeLw();
6128 }
6129 }
6130
6131 private void updateInputDispatchModeLw() {
6132 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6133 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006136 public void pauseKeyDispatching(IBinder _token) {
6137 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6138 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006139 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006140 }
6141
6142 synchronized (mWindowMap) {
6143 WindowToken token = mTokenMap.get(_token);
6144 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006145 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 }
6147 }
6148 }
6149
6150 public void resumeKeyDispatching(IBinder _token) {
6151 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6152 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006153 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 }
6155
6156 synchronized (mWindowMap) {
6157 WindowToken token = mTokenMap.get(_token);
6158 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006159 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006160 }
6161 }
6162 }
6163
6164 public void setEventDispatching(boolean enabled) {
6165 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6166 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006167 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 }
6169
6170 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006171 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 }
6173 }
Romain Guy06882f82009-06-10 13:36:04 -07006174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006175 /**
6176 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006177 * Even when sync is false, this method may block while waiting for current
6178 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006179 *
6180 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006181 * {@link SystemClock#uptimeMillis()} as the timebase.)
6182 * @param sync If true, wait for the event to be completed before returning to the caller.
6183 * @return Returns true if event was dispatched, false if it was dropped for any reason
6184 */
6185 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6186 long downTime = ev.getDownTime();
6187 long eventTime = ev.getEventTime();
6188
6189 int action = ev.getAction();
6190 int code = ev.getKeyCode();
6191 int repeatCount = ev.getRepeatCount();
6192 int metaState = ev.getMetaState();
6193 int deviceId = ev.getDeviceId();
6194 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006195 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006196 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006197
6198 if (source == InputDevice.SOURCE_UNKNOWN) {
6199 source = InputDevice.SOURCE_KEYBOARD;
6200 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006201
6202 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6203 if (downTime == 0) downTime = eventTime;
6204
6205 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006206 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006207
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006208 final int pid = Binder.getCallingPid();
6209 final int uid = Binder.getCallingUid();
6210 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006211
Jeff Brownbbda99d2010-07-28 15:48:59 -07006212 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6213 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6214 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6215 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006216
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006217 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006218 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006219 }
6220
6221 /**
6222 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006223 * Even when sync is false, this method may block while waiting for current
6224 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006225 *
6226 * @param ev A motion event describing the pointer (touch) action. (As noted in
6227 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 * {@link SystemClock#uptimeMillis()} as the timebase.)
6229 * @param sync If true, wait for the event to be completed before returning to the caller.
6230 * @return Returns true if event was dispatched, false if it was dropped for any reason
6231 */
6232 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006233 final int pid = Binder.getCallingPid();
6234 final int uid = Binder.getCallingUid();
6235 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006236
Jeff Brownc5ed5912010-07-14 18:48:53 -07006237 MotionEvent newEvent = MotionEvent.obtain(ev);
6238 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6239 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6240 }
6241
Jeff Brownbbda99d2010-07-28 15:48:59 -07006242 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6243 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6244 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6245 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006246
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006247 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006248 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006249 }
Romain Guy06882f82009-06-10 13:36:04 -07006250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006251 /**
6252 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006253 * Even when sync is false, this method may block while waiting for current
6254 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006255 *
6256 * @param ev A motion event describing the trackball action. (As noted in
6257 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258 * {@link SystemClock#uptimeMillis()} as the timebase.)
6259 * @param sync If true, wait for the event to be completed before returning to the caller.
6260 * @return Returns true if event was dispatched, false if it was dropped for any reason
6261 */
6262 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006263 final int pid = Binder.getCallingPid();
6264 final int uid = Binder.getCallingUid();
6265 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006266
Jeff Brownc5ed5912010-07-14 18:48:53 -07006267 MotionEvent newEvent = MotionEvent.obtain(ev);
6268 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6269 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6270 }
6271
Jeff Brownbbda99d2010-07-28 15:48:59 -07006272 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6273 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6274 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6275 INJECTION_TIMEOUT_MILLIS);
6276
6277 Binder.restoreCallingIdentity(ident);
6278 return reportInjectionResult(result);
6279 }
6280
6281 /**
6282 * Inject an input event into the UI without waiting for dispatch to commence.
6283 * This variant is useful for fire-and-forget input event injection. It does not
6284 * block any longer than it takes to enqueue the input event.
6285 *
6286 * @param ev An input event. (Be sure to set the input source correctly.)
6287 * @return Returns true if event was dispatched, false if it was dropped for any reason
6288 */
6289 public boolean injectInputEventNoWait(InputEvent ev) {
6290 final int pid = Binder.getCallingPid();
6291 final int uid = Binder.getCallingUid();
6292 final long ident = Binder.clearCallingIdentity();
6293
6294 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6295 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6296 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006297
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006298 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006299 return reportInjectionResult(result);
6300 }
6301
6302 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006303 switch (result) {
6304 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6305 Slog.w(TAG, "Input event injection permission denied.");
6306 throw new SecurityException(
6307 "Injecting to another application requires INJECT_EVENTS permission");
6308 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006309 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006310 return true;
6311 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6312 Slog.w(TAG, "Input event injection timed out.");
6313 return false;
6314 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6315 default:
6316 Slog.w(TAG, "Input event injection failed.");
6317 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006319 }
Romain Guy06882f82009-06-10 13:36:04 -07006320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006321 private WindowState getFocusedWindow() {
6322 synchronized (mWindowMap) {
6323 return getFocusedWindowLocked();
6324 }
6325 }
6326
6327 private WindowState getFocusedWindowLocked() {
6328 return mCurrentFocus;
6329 }
Romain Guy06882f82009-06-10 13:36:04 -07006330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 public boolean detectSafeMode() {
6332 mSafeMode = mPolicy.detectSafeMode();
6333 return mSafeMode;
6334 }
Romain Guy06882f82009-06-10 13:36:04 -07006335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006337 synchronized(mWindowMap) {
6338 if (mDisplay != null) {
6339 throw new IllegalStateException("Display already initialized");
6340 }
6341 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6342 mDisplay = wm.getDefaultDisplay();
6343 mInitialDisplayWidth = mDisplay.getWidth();
6344 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006345 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6346 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006347 }
6348
6349 try {
6350 mActivityManager.updateConfiguration(null);
6351 } catch (RemoteException e) {
6352 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006353
6354 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006355 }
6356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006357 // -------------------------------------------------------------
6358 // Client Session State
6359 // -------------------------------------------------------------
6360
6361 private final class Session extends IWindowSession.Stub
6362 implements IBinder.DeathRecipient {
6363 final IInputMethodClient mClient;
6364 final IInputContext mInputContext;
6365 final int mUid;
6366 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006367 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 SurfaceSession mSurfaceSession;
6369 int mNumWindow = 0;
6370 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 public Session(IInputMethodClient client, IInputContext inputContext) {
6373 mClient = client;
6374 mInputContext = inputContext;
6375 mUid = Binder.getCallingUid();
6376 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006377 StringBuilder sb = new StringBuilder();
6378 sb.append("Session{");
6379 sb.append(Integer.toHexString(System.identityHashCode(this)));
6380 sb.append(" uid ");
6381 sb.append(mUid);
6382 sb.append("}");
6383 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385 synchronized (mWindowMap) {
6386 if (mInputMethodManager == null && mHaveInputMethods) {
6387 IBinder b = ServiceManager.getService(
6388 Context.INPUT_METHOD_SERVICE);
6389 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6390 }
6391 }
6392 long ident = Binder.clearCallingIdentity();
6393 try {
6394 // Note: it is safe to call in to the input method manager
6395 // here because we are not holding our lock.
6396 if (mInputMethodManager != null) {
6397 mInputMethodManager.addClient(client, inputContext,
6398 mUid, mPid);
6399 } else {
6400 client.setUsingInputMethod(false);
6401 }
6402 client.asBinder().linkToDeath(this, 0);
6403 } catch (RemoteException e) {
6404 // The caller has died, so we can just forget about this.
6405 try {
6406 if (mInputMethodManager != null) {
6407 mInputMethodManager.removeClient(client);
6408 }
6409 } catch (RemoteException ee) {
6410 }
6411 } finally {
6412 Binder.restoreCallingIdentity(ident);
6413 }
6414 }
Romain Guy06882f82009-06-10 13:36:04 -07006415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006416 @Override
6417 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6418 throws RemoteException {
6419 try {
6420 return super.onTransact(code, data, reply, flags);
6421 } catch (RuntimeException e) {
6422 // Log all 'real' exceptions thrown to the caller
6423 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006424 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006425 }
6426 throw e;
6427 }
6428 }
6429
6430 public void binderDied() {
6431 // Note: it is safe to call in to the input method manager
6432 // here because we are not holding our lock.
6433 try {
6434 if (mInputMethodManager != null) {
6435 mInputMethodManager.removeClient(mClient);
6436 }
6437 } catch (RemoteException e) {
6438 }
6439 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006440 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 mClientDead = true;
6442 killSessionLocked();
6443 }
6444 }
6445
6446 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006447 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6448 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6449 outInputChannel);
6450 }
6451
6452 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006454 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006455 }
Romain Guy06882f82009-06-10 13:36:04 -07006456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006457 public void remove(IWindow window) {
6458 removeWindow(this, window);
6459 }
Romain Guy06882f82009-06-10 13:36:04 -07006460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006461 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6462 int requestedWidth, int requestedHeight, int viewFlags,
6463 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006464 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006465 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6466 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006468 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006469 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6470 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006471 }
Romain Guy06882f82009-06-10 13:36:04 -07006472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006473 public void setTransparentRegion(IWindow window, Region region) {
6474 setTransparentRegionWindow(this, window, region);
6475 }
Romain Guy06882f82009-06-10 13:36:04 -07006476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006477 public void setInsets(IWindow window, int touchableInsets,
6478 Rect contentInsets, Rect visibleInsets) {
6479 setInsetsWindow(this, window, touchableInsets, contentInsets,
6480 visibleInsets);
6481 }
Romain Guy06882f82009-06-10 13:36:04 -07006482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6484 getWindowDisplayFrame(this, window, outDisplayFrame);
6485 }
Romain Guy06882f82009-06-10 13:36:04 -07006486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006488 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006489 TAG, "IWindow finishDrawing called for " + window);
6490 finishDrawingWindow(this, window);
6491 }
6492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 public void setInTouchMode(boolean mode) {
6494 synchronized(mWindowMap) {
6495 mInTouchMode = mode;
6496 }
6497 }
6498
6499 public boolean getInTouchMode() {
6500 synchronized(mWindowMap) {
6501 return mInTouchMode;
6502 }
6503 }
6504
6505 public boolean performHapticFeedback(IWindow window, int effectId,
6506 boolean always) {
6507 synchronized(mWindowMap) {
6508 long ident = Binder.clearCallingIdentity();
6509 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006510 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006511 windowForClientLocked(this, window, true),
6512 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 } finally {
6514 Binder.restoreCallingIdentity(ident);
6515 }
6516 }
6517 }
Romain Guy06882f82009-06-10 13:36:04 -07006518
Christopher Tatea53146c2010-09-07 11:57:52 -07006519 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006520 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006521 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006522 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006523 width, height, outSurface);
6524 }
6525
6526 public boolean performDrag(IWindow window, IBinder dragToken,
6527 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6528 ClipData data) {
6529 if (DEBUG_DRAG) {
6530 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6531 }
6532
6533 synchronized (mWindowMap) {
6534 if (mDragState == null) {
6535 Slog.w(TAG, "No drag prepared");
6536 throw new IllegalStateException("performDrag() without prepareDrag()");
6537 }
6538
6539 if (dragToken != mDragState.mToken) {
6540 Slog.w(TAG, "Performing mismatched drag");
6541 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6542 }
6543
6544 WindowState callingWin = windowForClientLocked(null, window, false);
6545 if (callingWin == null) {
6546 Slog.w(TAG, "Bad requesting window " + window);
6547 return false; // !!! TODO: throw here?
6548 }
6549
6550 // !!! TODO: if input is not still focused on the initiating window, fail
6551 // the drag initiation (e.g. an alarm window popped up just as the application
6552 // called performDrag()
6553
6554 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6555
Christopher Tate2c095f32010-10-04 14:13:40 -07006556 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6557 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006558
Chris Tateb478f462010-10-15 16:02:26 -07006559 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6560 // the actual drag event dispatch stuff in the dragstate
6561
Christopher Tatea53146c2010-09-07 11:57:52 -07006562 mDragState.register();
6563 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006564 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6565 mDragState.mServerChannel)) {
6566 Slog.e(TAG, "Unable to transfer touch focus");
6567 mDragState.unregister();
6568 mDragState = null;
6569 mInputMonitor.updateInputWindowsLw();
6570 return false;
6571 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006572
6573 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006574 mDragState.mCurrentX = touchX;
6575 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006576 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006577
6578 // remember the thumb offsets for later
6579 mDragState.mThumbOffsetX = thumbCenterX;
6580 mDragState.mThumbOffsetY = thumbCenterY;
6581
6582 // Make the surface visible at the proper location
6583 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006584 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006585 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006586 try {
6587 surface.setPosition((int)(touchX - thumbCenterX),
6588 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006589 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006590 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006591 surface.show();
6592 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006593 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006594 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006595 }
6596 }
6597
6598 return true; // success!
6599 }
6600
Chris Tated4533f142010-10-19 15:15:08 -07006601 public void reportDropResult(IWindow window, boolean consumed) {
6602 IBinder token = window.asBinder();
6603 if (DEBUG_DRAG) {
6604 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6605 }
6606
6607 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006608 long ident = Binder.clearCallingIdentity();
6609 try {
6610 if (mDragState.mToken != token) {
6611 Slog.w(TAG, "Invalid drop-result claim by " + window);
6612 throw new IllegalStateException("reportDropResult() by non-recipient");
6613 }
6614
6615 // The right window has responded, even if it's no longer around,
6616 // so be sure to halt the timeout even if the later WindowState
6617 // lookup fails.
6618 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6619 WindowState callingWin = windowForClientLocked(null, window, false);
6620 if (callingWin == null) {
6621 Slog.w(TAG, "Bad result-reporting window " + window);
6622 return; // !!! TODO: throw here?
6623 }
6624
6625 mDragState.mDragResult = consumed;
6626 mDragState.endDragLw();
6627 } finally {
6628 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006629 }
Chris Tated4533f142010-10-19 15:15:08 -07006630 }
6631 }
6632
Christopher Tatea53146c2010-09-07 11:57:52 -07006633 public void dragRecipientEntered(IWindow window) {
6634 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006635 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006636 }
6637 }
6638
6639 public void dragRecipientExited(IWindow window) {
6640 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006641 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006642 }
6643 }
6644
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006645 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006646 synchronized(mWindowMap) {
6647 long ident = Binder.clearCallingIdentity();
6648 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006649 setWindowWallpaperPositionLocked(
6650 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006651 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006652 } finally {
6653 Binder.restoreCallingIdentity(ident);
6654 }
6655 }
6656 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006657
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006658 public void wallpaperOffsetsComplete(IBinder window) {
6659 WindowManagerService.this.wallpaperOffsetsComplete(window);
6660 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006661
Dianne Hackborn75804932009-10-20 20:15:20 -07006662 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6663 int z, Bundle extras, boolean sync) {
6664 synchronized(mWindowMap) {
6665 long ident = Binder.clearCallingIdentity();
6666 try {
6667 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006668 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006669 action, x, y, z, extras, sync);
6670 } finally {
6671 Binder.restoreCallingIdentity(ident);
6672 }
6673 }
6674 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006675
Dianne Hackborn75804932009-10-20 20:15:20 -07006676 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6677 WindowManagerService.this.wallpaperCommandComplete(window, result);
6678 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006680 void windowAddedLocked() {
6681 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006682 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 TAG, "First window added to " + this + ", creating SurfaceSession");
6684 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006685 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006686 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006687 mSessions.add(this);
6688 }
6689 mNumWindow++;
6690 }
6691
6692 void windowRemovedLocked() {
6693 mNumWindow--;
6694 killSessionLocked();
6695 }
Romain Guy06882f82009-06-10 13:36:04 -07006696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006697 void killSessionLocked() {
6698 if (mNumWindow <= 0 && mClientDead) {
6699 mSessions.remove(this);
6700 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006701 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 TAG, "Last window removed from " + this
6703 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006704 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006705 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 try {
6707 mSurfaceSession.kill();
6708 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006709 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006710 + mSurfaceSession + " in session " + this
6711 + ": " + e.toString());
6712 }
6713 mSurfaceSession = null;
6714 }
6715 }
6716 }
Romain Guy06882f82009-06-10 13:36:04 -07006717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006718 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006719 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6720 pw.print(" mClientDead="); pw.print(mClientDead);
6721 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 }
6723
6724 @Override
6725 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006726 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006727 }
6728 }
6729
6730 // -------------------------------------------------------------
6731 // Client Window State
6732 // -------------------------------------------------------------
6733
6734 private final class WindowState implements WindowManagerPolicy.WindowState {
6735 final Session mSession;
6736 final IWindow mClient;
6737 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006738 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006739 AppWindowToken mAppToken;
6740 AppWindowToken mTargetAppToken;
6741 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6742 final DeathRecipient mDeathRecipient;
6743 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006744 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 final int mBaseLayer;
6746 final int mSubLayer;
6747 final boolean mLayoutAttached;
6748 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006749 final boolean mIsWallpaper;
6750 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006751 int mViewVisibility;
6752 boolean mPolicyVisibility = true;
6753 boolean mPolicyVisibilityAfterAnim = true;
6754 boolean mAppFreezing;
6755 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006756 boolean mReportDestroySurface;
6757 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006758 boolean mAttachedHidden; // is our parent window hidden?
6759 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006760 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006761 int mRequestedWidth;
6762 int mRequestedHeight;
6763 int mLastRequestedWidth;
6764 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 int mLayer;
6766 int mAnimLayer;
6767 int mLastLayer;
6768 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006769 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006770 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006772 int mLayoutSeq = -1;
6773
6774 Configuration mConfiguration = null;
6775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 // Actual frame shown on-screen (may be modified by animation)
6777 final Rect mShownFrame = new Rect();
6778 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006781 * Set when we have changed the size of the surface, to know that
6782 * we must tell them application to resize (and thus redraw itself).
6783 */
6784 boolean mSurfaceResized;
6785
6786 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006787 * Insets that determine the actually visible area
6788 */
6789 final Rect mVisibleInsets = new Rect();
6790 final Rect mLastVisibleInsets = new Rect();
6791 boolean mVisibleInsetsChanged;
6792
6793 /**
6794 * Insets that are covered by system windows
6795 */
6796 final Rect mContentInsets = new Rect();
6797 final Rect mLastContentInsets = new Rect();
6798 boolean mContentInsetsChanged;
6799
6800 /**
6801 * Set to true if we are waiting for this window to receive its
6802 * given internal insets before laying out other windows based on it.
6803 */
6804 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 /**
6807 * These are the content insets that were given during layout for
6808 * this window, to be applied to windows behind it.
6809 */
6810 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 /**
6813 * These are the visible insets that were given during layout for
6814 * this window, to be applied to windows behind it.
6815 */
6816 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 /**
6819 * Flag indicating whether the touchable region should be adjusted by
6820 * the visible insets; if false the area outside the visible insets is
6821 * NOT touchable, so we must use those to adjust the frame during hit
6822 * tests.
6823 */
6824 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006826 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006827 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006828 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6829 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6830 float mHScale=1, mVScale=1;
6831 float mLastHScale=1, mLastVScale=1;
6832 final Matrix mTmpMatrix = new Matrix();
6833
6834 // "Real" frame that the application sees.
6835 final Rect mFrame = new Rect();
6836 final Rect mLastFrame = new Rect();
6837
6838 final Rect mContainingFrame = new Rect();
6839 final Rect mDisplayFrame = new Rect();
6840 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006841 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006842 final Rect mVisibleFrame = new Rect();
6843
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006844 boolean mContentChanged;
6845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 float mShownAlpha = 1;
6847 float mAlpha = 1;
6848 float mLastAlpha = 1;
6849
6850 // Set to true if, when the window gets displayed, it should perform
6851 // an enter animation.
6852 boolean mEnterAnimationPending;
6853
6854 // Currently running animation.
6855 boolean mAnimating;
6856 boolean mLocalAnimating;
6857 Animation mAnimation;
6858 boolean mAnimationIsEntrance;
6859 boolean mHasTransformation;
6860 boolean mHasLocalTransformation;
6861 final Transformation mTransformation = new Transformation();
6862
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006863 // If a window showing a wallpaper: the requested offset for the
6864 // wallpaper; if a wallpaper window: the currently applied offset.
6865 float mWallpaperX = -1;
6866 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006867
6868 // If a window showing a wallpaper: what fraction of the offset
6869 // range corresponds to a full virtual screen.
6870 float mWallpaperXStep = -1;
6871 float mWallpaperYStep = -1;
6872
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006873 // Wallpaper windows: pixels offset based on above variables.
6874 int mXOffset;
6875 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 // This is set after IWindowSession.relayout() has been called at
6878 // least once for the window. It allows us to detect the situation
6879 // where we don't yet have a surface, but should have one soon, so
6880 // we can give the window focus before waiting for the relayout.
6881 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 // This is set after the Surface has been created but before the
6884 // window has been drawn. During this time the surface is hidden.
6885 boolean mDrawPending;
6886
6887 // This is set after the window has finished drawing for the first
6888 // time but before its surface is shown. The surface will be
6889 // displayed when the next layout is run.
6890 boolean mCommitDrawPending;
6891
6892 // This is set during the time after the window's drawing has been
6893 // committed, and before its surface is actually shown. It is used
6894 // to delay showing the surface until all windows in a token are ready
6895 // to be shown.
6896 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006898 // Set when the window has been shown in the screen the first time.
6899 boolean mHasDrawn;
6900
6901 // Currently running an exit animation?
6902 boolean mExiting;
6903
6904 // Currently on the mDestroySurface list?
6905 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006907 // Completely remove from window manager after exit animation?
6908 boolean mRemoveOnExit;
6909
6910 // Set when the orientation is changing and this window has not yet
6911 // been updated for the new orientation.
6912 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 // Is this window now (or just being) removed?
6915 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006916
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006917 // Temp for keeping track of windows that have been removed when
6918 // rebuilding window list.
6919 boolean mRebuilding;
6920
Dianne Hackborn16064f92010-03-25 00:47:24 -07006921 // For debugging, this is the last information given to the surface flinger.
6922 boolean mSurfaceShown;
6923 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6924 int mSurfaceLayer;
6925 float mSurfaceAlpha;
6926
Jeff Brown928e0542011-01-10 11:17:36 -08006927 // Input channel and input window handle used by the input dispatcher.
6928 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006929 InputChannel mInputChannel;
6930
Mattias Petersson1622eee2010-12-21 10:15:11 +01006931 // Used to improve performance of toString()
6932 String mStringNameCache;
6933 CharSequence mLastTitle;
6934 boolean mWasPaused;
6935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006936 WindowState(Session s, IWindow c, WindowToken token,
6937 WindowState attachedWindow, WindowManager.LayoutParams a,
6938 int viewVisibility) {
6939 mSession = s;
6940 mClient = c;
6941 mToken = token;
6942 mAttrs.copyFrom(a);
6943 mViewVisibility = viewVisibility;
6944 DeathRecipient deathRecipient = new DeathRecipient();
6945 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006946 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 TAG, "Window " + this + " client=" + c.asBinder()
6948 + " token=" + token + " (" + mAttrs.token + ")");
6949 try {
6950 c.asBinder().linkToDeath(deathRecipient, 0);
6951 } catch (RemoteException e) {
6952 mDeathRecipient = null;
6953 mAttachedWindow = null;
6954 mLayoutAttached = false;
6955 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006956 mIsWallpaper = false;
6957 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958 mBaseLayer = 0;
6959 mSubLayer = 0;
6960 return;
6961 }
6962 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6965 mAttrs.type <= LAST_SUB_WINDOW)) {
6966 // The multiplier here is to reserve space for multiple
6967 // windows in the same type layer.
6968 mBaseLayer = mPolicy.windowTypeToLayerLw(
6969 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6970 + TYPE_LAYER_OFFSET;
6971 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6972 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006973 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 mAttachedWindow.mChildWindows.add(this);
6975 mLayoutAttached = mAttrs.type !=
6976 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6977 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6978 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006979 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6980 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 } else {
6982 // The multiplier here is to reserve space for multiple
6983 // windows in the same type layer.
6984 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6985 * TYPE_LAYER_MULTIPLIER
6986 + TYPE_LAYER_OFFSET;
6987 mSubLayer = 0;
6988 mAttachedWindow = null;
6989 mLayoutAttached = false;
6990 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6991 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006992 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6993 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006994 }
6995
6996 WindowState appWin = this;
6997 while (appWin.mAttachedWindow != null) {
6998 appWin = mAttachedWindow;
6999 }
7000 WindowToken appToken = appWin.mToken;
7001 while (appToken.appWindowToken == null) {
7002 WindowToken parent = mTokenMap.get(appToken.token);
7003 if (parent == null || appToken == parent) {
7004 break;
7005 }
7006 appToken = parent;
7007 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007008 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 mAppToken = appToken.appWindowToken;
7010
7011 mSurface = null;
7012 mRequestedWidth = 0;
7013 mRequestedHeight = 0;
7014 mLastRequestedWidth = 0;
7015 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007016 mXOffset = 0;
7017 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 mLayer = 0;
7019 mAnimLayer = 0;
7020 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007021 mInputWindowHandle = new InputWindowHandle(
7022 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007023 }
7024
7025 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007026 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007027 TAG, "Attaching " + this + " token=" + mToken
7028 + ", list=" + mToken.windows);
7029 mSession.windowAddedLocked();
7030 }
7031
7032 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7033 mHaveFrame = true;
7034
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007035 final Rect container = mContainingFrame;
7036 container.set(pf);
7037
7038 final Rect display = mDisplayFrame;
7039 display.set(df);
7040
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007041 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007042 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007043 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7044 display.intersect(mCompatibleScreenFrame);
7045 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007046 }
7047
7048 final int pw = container.right - container.left;
7049 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007050
7051 int w,h;
7052 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7053 w = mAttrs.width < 0 ? pw : mAttrs.width;
7054 h = mAttrs.height< 0 ? ph : mAttrs.height;
7055 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007056 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7057 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007058 }
Romain Guy06882f82009-06-10 13:36:04 -07007059
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007060 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007061 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7062 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007063 mParentFrame.set(pf);
7064 mContentChanged = true;
7065 }
7066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 final Rect content = mContentFrame;
7068 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 final Rect visible = mVisibleFrame;
7071 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007073 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007074 final int fw = frame.width();
7075 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007077 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7078 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7079
7080 Gravity.apply(mAttrs.gravity, w, h, container,
7081 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7082 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7083
7084 //System.out.println("Out: " + mFrame);
7085
7086 // Now make sure the window fits in the overall display.
7087 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007089 // Make sure the content and visible frames are inside of the
7090 // final window frame.
7091 if (content.left < frame.left) content.left = frame.left;
7092 if (content.top < frame.top) content.top = frame.top;
7093 if (content.right > frame.right) content.right = frame.right;
7094 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7095 if (visible.left < frame.left) visible.left = frame.left;
7096 if (visible.top < frame.top) visible.top = frame.top;
7097 if (visible.right > frame.right) visible.right = frame.right;
7098 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007100 final Rect contentInsets = mContentInsets;
7101 contentInsets.left = content.left-frame.left;
7102 contentInsets.top = content.top-frame.top;
7103 contentInsets.right = frame.right-content.right;
7104 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 final Rect visibleInsets = mVisibleInsets;
7107 visibleInsets.left = visible.left-frame.left;
7108 visibleInsets.top = visible.top-frame.top;
7109 visibleInsets.right = frame.right-visible.right;
7110 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007111
Dianne Hackborn284ac932009-08-28 10:34:25 -07007112 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7113 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007114 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007115 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007117 if (localLOGV) {
7118 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7119 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007120 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007121 + mRequestedWidth + ", mRequestedheight="
7122 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7123 + "): frame=" + mFrame.toShortString()
7124 + " ci=" + contentInsets.toShortString()
7125 + " vi=" + visibleInsets.toShortString());
7126 //}
7127 }
7128 }
Romain Guy06882f82009-06-10 13:36:04 -07007129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 public Rect getFrameLw() {
7131 return mFrame;
7132 }
7133
7134 public Rect getShownFrameLw() {
7135 return mShownFrame;
7136 }
7137
7138 public Rect getDisplayFrameLw() {
7139 return mDisplayFrame;
7140 }
7141
7142 public Rect getContentFrameLw() {
7143 return mContentFrame;
7144 }
7145
7146 public Rect getVisibleFrameLw() {
7147 return mVisibleFrame;
7148 }
7149
7150 public boolean getGivenInsetsPendingLw() {
7151 return mGivenInsetsPending;
7152 }
7153
7154 public Rect getGivenContentInsetsLw() {
7155 return mGivenContentInsets;
7156 }
Romain Guy06882f82009-06-10 13:36:04 -07007157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007158 public Rect getGivenVisibleInsetsLw() {
7159 return mGivenVisibleInsets;
7160 }
Romain Guy06882f82009-06-10 13:36:04 -07007161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 public WindowManager.LayoutParams getAttrs() {
7163 return mAttrs;
7164 }
7165
7166 public int getSurfaceLayer() {
7167 return mLayer;
7168 }
Romain Guy06882f82009-06-10 13:36:04 -07007169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007170 public IApplicationToken getAppToken() {
7171 return mAppToken != null ? mAppToken.appToken : null;
7172 }
Jeff Brown349703e2010-06-22 01:27:15 -07007173
7174 public long getInputDispatchingTimeoutNanos() {
7175 return mAppToken != null
7176 ? mAppToken.inputDispatchingTimeoutNanos
7177 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007179
7180 public boolean hasAppShownWindows() {
7181 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7182 }
7183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007184 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007185 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007186 TAG, "Setting animation in " + this + ": " + anim);
7187 mAnimating = false;
7188 mLocalAnimating = false;
7189 mAnimation = anim;
7190 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7191 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7192 }
7193
7194 public void clearAnimation() {
7195 if (mAnimation != null) {
7196 mAnimating = true;
7197 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007198 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 mAnimation = null;
7200 }
7201 }
Romain Guy06882f82009-06-10 13:36:04 -07007202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 Surface createSurfaceLocked() {
7204 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007205 mReportDestroySurface = false;
7206 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007207 mDrawPending = true;
7208 mCommitDrawPending = false;
7209 mReadyToShow = false;
7210 if (mAppToken != null) {
7211 mAppToken.allDrawn = false;
7212 }
7213
7214 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215
7216 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7217 flags |= Surface.SECURE;
7218 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007219 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007220 TAG, "Creating surface in session "
7221 + mSession.mSurfaceSession + " window " + this
7222 + " w=" + mFrame.width()
7223 + " h=" + mFrame.height() + " format="
7224 + mAttrs.format + " flags=" + flags);
7225
7226 int w = mFrame.width();
7227 int h = mFrame.height();
7228 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7229 // for a scaled surface, we always want the requested
7230 // size.
7231 w = mRequestedWidth;
7232 h = mRequestedHeight;
7233 }
7234
Romain Guy9825ec62009-10-01 00:58:09 -07007235 // Something is wrong and SurfaceFlinger will not like this,
7236 // try to revert to sane values
7237 if (w <= 0) w = 1;
7238 if (h <= 0) h = 1;
7239
Dianne Hackborn16064f92010-03-25 00:47:24 -07007240 mSurfaceShown = false;
7241 mSurfaceLayer = 0;
7242 mSurfaceAlpha = 1;
7243 mSurfaceX = 0;
7244 mSurfaceY = 0;
7245 mSurfaceW = w;
7246 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007247 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007248 final boolean isHwAccelerated = (mAttrs.flags &
7249 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7250 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7251 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7252 flags |= Surface.OPAQUE;
7253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007254 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007255 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007256 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007257 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007258 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007259 + mSurface + " IN SESSION "
7260 + mSession.mSurfaceSession
7261 + ": pid=" + mSession.mPid + " format="
7262 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007263 + Integer.toHexString(flags)
7264 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007265 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007266 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007267 reclaimSomeSurfaceMemoryLocked(this, "create");
7268 return null;
7269 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007270 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 return null;
7272 }
Romain Guy06882f82009-06-10 13:36:04 -07007273
Joe Onorato8a9b2202010-02-26 18:56:32 -08007274 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007275 TAG, "Got surface: " + mSurface
7276 + ", set left=" + mFrame.left + " top=" + mFrame.top
7277 + ", animLayer=" + mAnimLayer);
7278 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007279 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7280 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007281 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7282 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 }
7284 Surface.openTransaction();
7285 try {
7286 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007287 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007288 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007289 mSurface.setPosition(mSurfaceX, mSurfaceY);
7290 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007292 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 mSurface.hide();
7294 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007295 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007296 mSurface.setFlags(Surface.SURFACE_DITHER,
7297 Surface.SURFACE_DITHER);
7298 }
7299 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007300 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7302 }
7303 mLastHidden = true;
7304 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007306 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007307 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007308 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007309 TAG, "Created surface " + this);
7310 }
7311 return mSurface;
7312 }
Romain Guy06882f82009-06-10 13:36:04 -07007313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007314 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007315 if (mAppToken != null && this == mAppToken.startingWindow) {
7316 mAppToken.startingDisplayed = false;
7317 }
Romain Guy06882f82009-06-10 13:36:04 -07007318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007319 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007320 mDrawPending = false;
7321 mCommitDrawPending = false;
7322 mReadyToShow = false;
7323
7324 int i = mChildWindows.size();
7325 while (i > 0) {
7326 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007327 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007328 c.mAttachedHidden = true;
7329 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007330
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007331 if (mReportDestroySurface) {
7332 mReportDestroySurface = false;
7333 mSurfacePendingDestroy = true;
7334 try {
7335 mClient.dispatchGetNewSurface();
7336 // We'll really destroy on the next time around.
7337 return;
7338 } catch (RemoteException e) {
7339 }
7340 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007343 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007344 RuntimeException e = null;
7345 if (!HIDE_STACK_CRAWLS) {
7346 e = new RuntimeException();
7347 e.fillInStackTrace();
7348 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007349 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007350 + mSurface + ", session " + mSession, e);
7351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007353 RuntimeException e = null;
7354 if (!HIDE_STACK_CRAWLS) {
7355 e = new RuntimeException();
7356 e.fillInStackTrace();
7357 }
7358 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007360 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007361 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007362 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007363 + " surface " + mSurface + " session " + mSession
7364 + ": " + e.toString());
7365 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007366
Dianne Hackborn16064f92010-03-25 00:47:24 -07007367 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 }
7370 }
7371
7372 boolean finishDrawingLocked() {
7373 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007374 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007375 TAG, "finishDrawingLocked: " + mSurface);
7376 mCommitDrawPending = true;
7377 mDrawPending = false;
7378 return true;
7379 }
7380 return false;
7381 }
7382
7383 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007384 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007385 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007387 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007388 }
7389 mCommitDrawPending = false;
7390 mReadyToShow = true;
7391 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7392 final AppWindowToken atoken = mAppToken;
7393 if (atoken == null || atoken.allDrawn || starting) {
7394 performShowLocked();
7395 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007396 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007397 }
7398
7399 // This must be called while inside a transaction.
7400 boolean performShowLocked() {
7401 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007402 RuntimeException e = null;
7403 if (!HIDE_STACK_CRAWLS) {
7404 e = new RuntimeException();
7405 e.fillInStackTrace();
7406 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007407 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7409 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7410 }
7411 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007412 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7413 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007414 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 + " during animation: policyVis=" + mPolicyVisibility
7416 + " attHidden=" + mAttachedHidden
7417 + " tok.hiddenRequested="
7418 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007419 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007420 + (mAppToken != null ? mAppToken.hidden : false)
7421 + " animating=" + mAnimating
7422 + " tok animating="
7423 + (mAppToken != null ? mAppToken.animating : false));
7424 if (!showSurfaceRobustlyLocked(this)) {
7425 return false;
7426 }
7427 mLastAlpha = -1;
7428 mHasDrawn = true;
7429 mLastHidden = false;
7430 mReadyToShow = false;
7431 enableScreenIfNeededLocked();
7432
7433 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 int i = mChildWindows.size();
7436 while (i > 0) {
7437 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007438 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007439 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007441 if (c.mSurface != null) {
7442 c.performShowLocked();
7443 // It hadn't been shown, which means layout not
7444 // performed on it, so now we want to make sure to
7445 // do a layout. If called from within the transaction
7446 // loop, this will cause it to restart with a new
7447 // layout.
7448 mLayoutNeeded = true;
7449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 }
7451 }
Romain Guy06882f82009-06-10 13:36:04 -07007452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 if (mAttrs.type != TYPE_APPLICATION_STARTING
7454 && mAppToken != null) {
7455 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007456
Dianne Hackborn248b1882009-09-16 16:46:44 -07007457 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007458 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007459 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007461 // If this initial window is animating, stop it -- we
7462 // will do an animation to reveal it from behind the
7463 // starting window, so there is no need for it to also
7464 // be doing its own stuff.
7465 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007466 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007467 mAnimation = null;
7468 // Make sure we clean up the animation.
7469 mAnimating = true;
7470 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007471 mFinishedStarting.add(mAppToken);
7472 mH.sendEmptyMessage(H.FINISHED_STARTING);
7473 }
7474 mAppToken.updateReportedVisibilityLocked();
7475 }
7476 }
7477 return true;
7478 }
Romain Guy06882f82009-06-10 13:36:04 -07007479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 // This must be called while inside a transaction. Returns true if
7481 // there is more animation to run.
7482 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007483 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007484 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7487 mHasTransformation = true;
7488 mHasLocalTransformation = true;
7489 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007490 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 TAG, "Starting animation in " + this +
7492 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7493 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7494 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7495 mAnimation.setStartTime(currentTime);
7496 mLocalAnimating = true;
7497 mAnimating = true;
7498 }
7499 mTransformation.clear();
7500 final boolean more = mAnimation.getTransformation(
7501 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007502 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 TAG, "Stepped animation in " + this +
7504 ": more=" + more + ", xform=" + mTransformation);
7505 if (more) {
7506 // we're not done!
7507 return true;
7508 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007509 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 TAG, "Finished animation in " + this +
7511 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007512
7513 if (mAnimation != null) {
7514 mAnimation.cancel();
7515 mAnimation = null;
7516 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 //WindowManagerService.this.dump();
7518 }
7519 mHasLocalTransformation = false;
7520 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007521 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 // When our app token is animating, we kind-of pretend like
7523 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7524 // part of this check means that we will only do this if
7525 // our window is not currently exiting, or it is not
7526 // locally animating itself. The idea being that one that
7527 // is exiting and doing a local animation should be removed
7528 // once that animation is done.
7529 mAnimating = true;
7530 mHasTransformation = true;
7531 mTransformation.clear();
7532 return false;
7533 } else if (mHasTransformation) {
7534 // Little trick to get through the path below to act like
7535 // we have finished an animation.
7536 mAnimating = true;
7537 } else if (isAnimating()) {
7538 mAnimating = true;
7539 }
7540 } else if (mAnimation != null) {
7541 // If the display is frozen, and there is a pending animation,
7542 // clear it and make sure we run the cleanup code.
7543 mAnimating = true;
7544 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007545 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 mAnimation = null;
7547 }
Romain Guy06882f82009-06-10 13:36:04 -07007548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007549 if (!mAnimating && !mLocalAnimating) {
7550 return false;
7551 }
7552
Joe Onorato8a9b2202010-02-26 18:56:32 -08007553 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007554 TAG, "Animation done in " + this + ": exiting=" + mExiting
7555 + ", reportedVisible="
7556 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 mAnimating = false;
7559 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007560 if (mAnimation != null) {
7561 mAnimation.cancel();
7562 mAnimation = null;
7563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007564 mAnimLayer = mLayer;
7565 if (mIsImWindow) {
7566 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007567 } else if (mIsWallpaper) {
7568 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007570 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007571 + " anim layer: " + mAnimLayer);
7572 mHasTransformation = false;
7573 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007574 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7575 if (DEBUG_VISIBILITY) {
7576 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7577 + mPolicyVisibilityAfterAnim);
7578 }
7579 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7580 if (!mPolicyVisibility) {
7581 if (mCurrentFocus == this) {
7582 mFocusMayChange = true;
7583 }
7584 // Window is no longer visible -- make sure if we were waiting
7585 // for it to be displayed before enabling the display, that
7586 // we allow the display to be enabled now.
7587 enableScreenIfNeededLocked();
7588 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007589 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007590 mTransformation.clear();
7591 if (mHasDrawn
7592 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7593 && mAppToken != null
7594 && mAppToken.firstWindowDrawn
7595 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007596 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 + mToken + ": first real window done animating");
7598 mFinishedStarting.add(mAppToken);
7599 mH.sendEmptyMessage(H.FINISHED_STARTING);
7600 }
Romain Guy06882f82009-06-10 13:36:04 -07007601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 finishExit();
7603
7604 if (mAppToken != null) {
7605 mAppToken.updateReportedVisibilityLocked();
7606 }
7607
7608 return false;
7609 }
7610
7611 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007612 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007613 TAG, "finishExit in " + this
7614 + ": exiting=" + mExiting
7615 + " remove=" + mRemoveOnExit
7616 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 final int N = mChildWindows.size();
7619 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007620 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 }
Romain Guy06882f82009-06-10 13:36:04 -07007622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 if (!mExiting) {
7624 return;
7625 }
Romain Guy06882f82009-06-10 13:36:04 -07007626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 if (isWindowAnimating()) {
7628 return;
7629 }
7630
Joe Onorato8a9b2202010-02-26 18:56:32 -08007631 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 TAG, "Exit animation finished in " + this
7633 + ": remove=" + mRemoveOnExit);
7634 if (mSurface != null) {
7635 mDestroySurface.add(this);
7636 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007637 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007638 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 try {
7640 mSurface.hide();
7641 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007642 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 }
7644 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007645 }
7646 mExiting = false;
7647 if (mRemoveOnExit) {
7648 mPendingRemove.add(this);
7649 mRemoveOnExit = false;
7650 }
7651 }
Romain Guy06882f82009-06-10 13:36:04 -07007652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007653 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7654 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7655 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7656 if (dtdx < -.000001f || dtdx > .000001f) return false;
7657 if (dsdy < -.000001f || dsdy > .000001f) return false;
7658 return true;
7659 }
Romain Guy06882f82009-06-10 13:36:04 -07007660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007661 void computeShownFrameLocked() {
7662 final boolean selfTransformation = mHasLocalTransformation;
7663 Transformation attachedTransformation =
7664 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7665 ? mAttachedWindow.mTransformation : null;
7666 Transformation appTransformation =
7667 (mAppToken != null && mAppToken.hasTransformation)
7668 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007669
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007670 // Wallpapers are animated based on the "real" window they
7671 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007672 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007673 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007674 if (mWallpaperTarget.mHasLocalTransformation &&
7675 mWallpaperTarget.mAnimation != null &&
7676 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007677 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007678 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007679 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007680 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007681 }
7682 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007683 mWallpaperTarget.mAppToken.hasTransformation &&
7684 mWallpaperTarget.mAppToken.animation != null &&
7685 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007686 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007687 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007688 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007689 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007690 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007692
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007693 final boolean screenAnimation = mScreenRotationAnimation != null
7694 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007695 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007696 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007697 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 final Rect frame = mFrame;
7699 final float tmpFloats[] = mTmpFloats;
7700 final Matrix tmpMatrix = mTmpMatrix;
7701
7702 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007703 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007705 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007707 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007709 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007710 }
7711 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007712 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007713 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007714 if (screenAnimation) {
7715 tmpMatrix.postConcat(
7716 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7717 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007718
7719 // "convert" it into SurfaceFlinger's format
7720 // (a 2x2 matrix + an offset)
7721 // Here we must not transform the position of the surface
7722 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007723 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007724
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007725 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007726 tmpMatrix.getValues(tmpFloats);
7727 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007728 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7729 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007730 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007731 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7732 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007733 int w = frame.width();
7734 int h = frame.height();
7735 mShownFrame.set(x, y, x+w, y+h);
7736
7737 // Now set the alpha... but because our current hardware
7738 // can't do alpha transformation on a non-opaque surface,
7739 // turn it off if we are running an animation that is also
7740 // transforming since it is more important to have that
7741 // animation be smooth.
7742 mShownAlpha = mAlpha;
7743 if (!mLimitedAlphaCompositing
7744 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7745 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7746 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007747 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007748 if (selfTransformation) {
7749 mShownAlpha *= mTransformation.getAlpha();
7750 }
7751 if (attachedTransformation != null) {
7752 mShownAlpha *= attachedTransformation.getAlpha();
7753 }
7754 if (appTransformation != null) {
7755 mShownAlpha *= appTransformation.getAlpha();
7756 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007757 if (screenAnimation) {
7758 mShownAlpha *=
7759 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007762 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007763 }
Romain Guy06882f82009-06-10 13:36:04 -07007764
Joe Onorato8a9b2202010-02-26 18:56:32 -08007765 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007766 TAG, "Continuing animation in " + this +
7767 ": " + mShownFrame +
7768 ", alpha=" + mTransformation.getAlpha());
7769 return;
7770 }
Romain Guy06882f82009-06-10 13:36:04 -07007771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007772 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007773 if (mXOffset != 0 || mYOffset != 0) {
7774 mShownFrame.offset(mXOffset, mYOffset);
7775 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007777 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007778 mDsDx = 1;
7779 mDtDx = 0;
7780 mDsDy = 0;
7781 mDtDy = 1;
7782 }
Romain Guy06882f82009-06-10 13:36:04 -07007783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007784 /**
7785 * Is this window visible? It is not visible if there is no
7786 * surface, or we are in the process of running an exit animation
7787 * that will remove the surface, or its app token has been hidden.
7788 */
7789 public boolean isVisibleLw() {
7790 final AppWindowToken atoken = mAppToken;
7791 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7792 && (atoken == null || !atoken.hiddenRequested)
7793 && !mExiting && !mDestroying;
7794 }
7795
7796 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007797 * Like {@link #isVisibleLw}, but also counts a window that is currently
7798 * "hidden" behind the keyguard as visible. This allows us to apply
7799 * things like window flags that impact the keyguard.
7800 * XXX I am starting to think we need to have ANOTHER visibility flag
7801 * for this "hidden behind keyguard" state rather than overloading
7802 * mPolicyVisibility. Ungh.
7803 */
7804 public boolean isVisibleOrBehindKeyguardLw() {
7805 final AppWindowToken atoken = mAppToken;
7806 return mSurface != null && !mAttachedHidden
7807 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007808 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007809 && !mExiting && !mDestroying;
7810 }
7811
7812 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007813 * Is this window visible, ignoring its app token? It is not visible
7814 * if there is no surface, or we are in the process of running an exit animation
7815 * that will remove the surface.
7816 */
7817 public boolean isWinVisibleLw() {
7818 final AppWindowToken atoken = mAppToken;
7819 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7820 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7821 && !mExiting && !mDestroying;
7822 }
7823
7824 /**
7825 * The same as isVisible(), but follows the current hidden state of
7826 * the associated app token, not the pending requested hidden state.
7827 */
7828 boolean isVisibleNow() {
7829 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007830 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007831 }
7832
7833 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007834 * Can this window possibly be a drag/drop target? The test here is
7835 * a combination of the above "visible now" with the check that the
7836 * Input Manager uses when discarding windows from input consideration.
7837 */
7838 boolean isPotentialDragTarget() {
7839 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7840 }
7841
7842 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007843 * Same as isVisible(), but we also count it as visible between the
7844 * call to IWindowSession.add() and the first relayout().
7845 */
7846 boolean isVisibleOrAdding() {
7847 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007848 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007849 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7850 && mPolicyVisibility && !mAttachedHidden
7851 && (atoken == null || !atoken.hiddenRequested)
7852 && !mExiting && !mDestroying;
7853 }
7854
7855 /**
7856 * Is this window currently on-screen? It is on-screen either if it
7857 * is visible or it is currently running an animation before no longer
7858 * being visible.
7859 */
7860 boolean isOnScreen() {
7861 final AppWindowToken atoken = mAppToken;
7862 if (atoken != null) {
7863 return mSurface != null && mPolicyVisibility && !mDestroying
7864 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007865 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 } else {
7867 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007868 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007869 }
7870 }
Romain Guy06882f82009-06-10 13:36:04 -07007871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007872 /**
7873 * Like isOnScreen(), but we don't return true if the window is part
7874 * of a transition that has not yet been started.
7875 */
7876 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007877 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007878 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007879 return false;
7880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007881 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007882 final boolean animating = atoken != null
7883 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007884 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007885 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7886 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007887 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007888 }
7889
7890 /** Is the window or its container currently animating? */
7891 boolean isAnimating() {
7892 final WindowState attached = mAttachedWindow;
7893 final AppWindowToken atoken = mAppToken;
7894 return mAnimation != null
7895 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007896 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007897 (atoken.animation != null
7898 || atoken.inPendingTransaction));
7899 }
7900
7901 /** Is this window currently animating? */
7902 boolean isWindowAnimating() {
7903 return mAnimation != null;
7904 }
7905
7906 /**
7907 * Like isOnScreen, but returns false if the surface hasn't yet
7908 * been drawn.
7909 */
7910 public boolean isDisplayedLw() {
7911 final AppWindowToken atoken = mAppToken;
7912 return mSurface != null && mPolicyVisibility && !mDestroying
7913 && !mDrawPending && !mCommitDrawPending
7914 && ((!mAttachedHidden &&
7915 (atoken == null || !atoken.hiddenRequested))
7916 || mAnimating);
7917 }
7918
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007919 /**
7920 * Returns true if the window has a surface that it has drawn a
7921 * complete UI in to.
7922 */
7923 public boolean isDrawnLw() {
7924 final AppWindowToken atoken = mAppToken;
7925 return mSurface != null && !mDestroying
7926 && !mDrawPending && !mCommitDrawPending;
7927 }
7928
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007929 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007930 * Return true if the window is opaque and fully drawn. This indicates
7931 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007932 */
7933 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007934 return (mAttrs.format == PixelFormat.OPAQUE
7935 || mAttrs.type == TYPE_WALLPAPER)
7936 && mSurface != null && mAnimation == null
7937 && (mAppToken == null || mAppToken.animation == null)
7938 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007939 }
7940
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007941 /**
7942 * Return whether this window is wanting to have a translation
7943 * animation applied to it for an in-progress move. (Only makes
7944 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7945 */
7946 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007947 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007948 && (mFrame.top != mLastFrame.top
7949 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007950 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007951 && mPolicy.isScreenOn();
7952 }
7953
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007954 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7955 return
7956 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007957 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7958 // only if it's visible
7959 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007960 // and only if the application fills the compatible screen
7961 mFrame.left <= mCompatibleScreenFrame.left &&
7962 mFrame.top <= mCompatibleScreenFrame.top &&
7963 mFrame.right >= mCompatibleScreenFrame.right &&
7964 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007965 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007966 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007967 }
7968
7969 boolean isFullscreen(int screenWidth, int screenHeight) {
7970 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007971 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007972 }
7973
7974 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007975 disposeInputChannel();
7976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007978 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 mAttachedWindow.mChildWindows.remove(this);
7980 }
7981 destroySurfaceLocked();
7982 mSession.windowRemovedLocked();
7983 try {
7984 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7985 } catch (RuntimeException e) {
7986 // Ignore if it has already been removed (usually because
7987 // we are doing this as part of processing a death note.)
7988 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007989 }
7990
7991 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007992 if (mInputChannel != null) {
7993 mInputManager.unregisterInputChannel(mInputChannel);
7994
7995 mInputChannel.dispose();
7996 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007997 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007998 }
7999
8000 private class DeathRecipient implements IBinder.DeathRecipient {
8001 public void binderDied() {
8002 try {
8003 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008004 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008005 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008006 if (win != null) {
8007 removeWindowLocked(mSession, win);
8008 }
8009 }
8010 } catch (IllegalArgumentException ex) {
8011 // This will happen if the window has already been
8012 // removed.
8013 }
8014 }
8015 }
8016
8017 /** Returns true if this window desires key events. */
8018 public final boolean canReceiveKeys() {
8019 return isVisibleOrAdding()
8020 && (mViewVisibility == View.VISIBLE)
8021 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8022 }
8023
8024 public boolean hasDrawnLw() {
8025 return mHasDrawn;
8026 }
8027
8028 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008029 return showLw(doAnimation, true);
8030 }
8031
8032 boolean showLw(boolean doAnimation, boolean requestAnim) {
8033 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8034 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008036 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008037 if (doAnimation) {
8038 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8039 + mPolicyVisibility + " mAnimation=" + mAnimation);
8040 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8041 doAnimation = false;
8042 } else if (mPolicyVisibility && mAnimation == null) {
8043 // Check for the case where we are currently visible and
8044 // not animating; we do not want to do animation at such a
8045 // point to become visible when we already are.
8046 doAnimation = false;
8047 }
8048 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008049 mPolicyVisibility = true;
8050 mPolicyVisibilityAfterAnim = true;
8051 if (doAnimation) {
8052 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8053 }
8054 if (requestAnim) {
8055 requestAnimationLocked(0);
8056 }
8057 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008058 }
8059
8060 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008061 return hideLw(doAnimation, true);
8062 }
8063
8064 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008065 if (doAnimation) {
8066 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8067 doAnimation = false;
8068 }
8069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008070 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8071 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008072 if (!current) {
8073 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008074 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008075 if (doAnimation) {
8076 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8077 if (mAnimation == null) {
8078 doAnimation = false;
8079 }
8080 }
8081 if (doAnimation) {
8082 mPolicyVisibilityAfterAnim = false;
8083 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008084 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008085 mPolicyVisibilityAfterAnim = false;
8086 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008087 // Window is no longer visible -- make sure if we were waiting
8088 // for it to be displayed before enabling the display, that
8089 // we allow the display to be enabled now.
8090 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008091 if (mCurrentFocus == this) {
8092 mFocusMayChange = true;
8093 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008094 }
8095 if (requestAnim) {
8096 requestAnimationLocked(0);
8097 }
8098 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 }
8100
8101 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008102 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8103 pw.print(" mClient="); pw.println(mClient.asBinder());
8104 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8105 if (mAttachedWindow != null || mLayoutAttached) {
8106 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8107 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8108 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008109 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8110 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8111 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008112 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8113 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008114 }
8115 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8116 pw.print(" mSubLayer="); pw.print(mSubLayer);
8117 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8118 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8119 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8120 pw.print("="); pw.print(mAnimLayer);
8121 pw.print(" mLastLayer="); pw.println(mLastLayer);
8122 if (mSurface != null) {
8123 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008124 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8125 pw.print(" layer="); pw.print(mSurfaceLayer);
8126 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8127 pw.print(" rect=("); pw.print(mSurfaceX);
8128 pw.print(","); pw.print(mSurfaceY);
8129 pw.print(") "); pw.print(mSurfaceW);
8130 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008131 }
8132 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8133 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8134 if (mAppToken != null) {
8135 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8136 }
8137 if (mTargetAppToken != null) {
8138 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8139 }
8140 pw.print(prefix); pw.print("mViewVisibility=0x");
8141 pw.print(Integer.toHexString(mViewVisibility));
8142 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008143 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8144 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008145 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8146 pw.print(prefix); pw.print("mPolicyVisibility=");
8147 pw.print(mPolicyVisibility);
8148 pw.print(" mPolicyVisibilityAfterAnim=");
8149 pw.print(mPolicyVisibilityAfterAnim);
8150 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8151 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008152 if (!mRelayoutCalled) {
8153 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8154 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008155 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008156 pw.print(" h="); pw.print(mRequestedHeight);
8157 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008158 if (mXOffset != 0 || mYOffset != 0) {
8159 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8160 pw.print(" y="); pw.println(mYOffset);
8161 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008162 pw.print(prefix); pw.print("mGivenContentInsets=");
8163 mGivenContentInsets.printShortString(pw);
8164 pw.print(" mGivenVisibleInsets=");
8165 mGivenVisibleInsets.printShortString(pw);
8166 pw.println();
8167 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8168 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8169 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8170 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008171 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008172 pw.print(prefix); pw.print("mShownFrame=");
8173 mShownFrame.printShortString(pw);
8174 pw.print(" last="); mLastShownFrame.printShortString(pw);
8175 pw.println();
8176 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8177 pw.print(" last="); mLastFrame.printShortString(pw);
8178 pw.println();
8179 pw.print(prefix); pw.print("mContainingFrame=");
8180 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008181 pw.print(" mParentFrame=");
8182 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008183 pw.print(" mDisplayFrame=");
8184 mDisplayFrame.printShortString(pw);
8185 pw.println();
8186 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8187 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8188 pw.println();
8189 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8190 pw.print(" last="); mLastContentInsets.printShortString(pw);
8191 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8192 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8193 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008194 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8195 || mAnimation != null) {
8196 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8197 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8198 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8199 pw.print(" mAnimation="); pw.println(mAnimation);
8200 }
8201 if (mHasTransformation || mHasLocalTransformation) {
8202 pw.print(prefix); pw.print("XForm: has=");
8203 pw.print(mHasTransformation);
8204 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8205 pw.print(" "); mTransformation.printShortString(pw);
8206 pw.println();
8207 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008208 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8209 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8210 pw.print(" mAlpha="); pw.print(mAlpha);
8211 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8212 }
8213 if (mHaveMatrix) {
8214 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8215 pw.print(" mDtDx="); pw.print(mDtDx);
8216 pw.print(" mDsDy="); pw.print(mDsDy);
8217 pw.print(" mDtDy="); pw.println(mDtDy);
8218 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008219 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8220 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8221 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8222 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8223 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8224 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8225 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8226 pw.print(" mDestroying="); pw.print(mDestroying);
8227 pw.print(" mRemoved="); pw.println(mRemoved);
8228 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008229 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008230 pw.print(prefix); pw.print("mOrientationChanging=");
8231 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008232 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8233 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008234 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008235 if (mHScale != 1 || mVScale != 1) {
8236 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8237 pw.print(" mVScale="); pw.println(mVScale);
8238 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008239 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008240 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8241 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8242 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008243 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8244 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8245 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008247 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008248
8249 String makeInputChannelName() {
8250 return Integer.toHexString(System.identityHashCode(this))
8251 + " " + mAttrs.getTitle();
8252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008253
8254 @Override
8255 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008256 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8257 || mWasPaused != mToken.paused) {
8258 mLastTitle = mAttrs.getTitle();
8259 mWasPaused = mToken.paused;
8260 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8261 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8262 }
8263 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008264 }
8265 }
Romain Guy06882f82009-06-10 13:36:04 -07008266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008267 // -------------------------------------------------------------
8268 // Window Token State
8269 // -------------------------------------------------------------
8270
8271 class WindowToken {
8272 // The actual token.
8273 final IBinder token;
8274
8275 // The type of window this token is for, as per WindowManager.LayoutParams.
8276 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008278 // Set if this token was explicitly added by a client, so should
8279 // not be removed when all windows are removed.
8280 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008281
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008282 // For printing.
8283 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008285 // If this is an AppWindowToken, this is non-null.
8286 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008288 // All of the windows associated with this token.
8289 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8290
8291 // Is key dispatching paused for this token?
8292 boolean paused = false;
8293
8294 // Should this token's windows be hidden?
8295 boolean hidden;
8296
8297 // Temporary for finding which tokens no longer have visible windows.
8298 boolean hasVisible;
8299
Dianne Hackborna8f60182009-09-01 19:01:50 -07008300 // Set to true when this token is in a pending transaction where it
8301 // will be shown.
8302 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008303
Dianne Hackborna8f60182009-09-01 19:01:50 -07008304 // Set to true when this token is in a pending transaction where it
8305 // will be hidden.
8306 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008307
Dianne Hackborna8f60182009-09-01 19:01:50 -07008308 // Set to true when this token is in a pending transaction where its
8309 // windows will be put to the bottom of the list.
8310 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008311
Dianne Hackborna8f60182009-09-01 19:01:50 -07008312 // Set to true when this token is in a pending transaction where its
8313 // windows will be put to the top of the list.
8314 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316 WindowToken(IBinder _token, int type, boolean _explicit) {
8317 token = _token;
8318 windowType = type;
8319 explicit = _explicit;
8320 }
8321
8322 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008323 pw.print(prefix); pw.print("token="); pw.println(token);
8324 pw.print(prefix); pw.print("windows="); pw.println(windows);
8325 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8326 pw.print(" hidden="); pw.print(hidden);
8327 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008328 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8329 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8330 pw.print(" waitingToHide="); pw.print(waitingToHide);
8331 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8332 pw.print(" sendingToTop="); pw.println(sendingToTop);
8333 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008334 }
8335
8336 @Override
8337 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008338 if (stringName == null) {
8339 StringBuilder sb = new StringBuilder();
8340 sb.append("WindowToken{");
8341 sb.append(Integer.toHexString(System.identityHashCode(this)));
8342 sb.append(" token="); sb.append(token); sb.append('}');
8343 stringName = sb.toString();
8344 }
8345 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008346 }
8347 };
8348
8349 class AppWindowToken extends WindowToken {
8350 // Non-null only for application tokens.
8351 final IApplicationToken appToken;
8352
8353 // All of the windows and child windows that are included in this
8354 // application token. Note this list is NOT sorted!
8355 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8356
8357 int groupId = -1;
8358 boolean appFullscreen;
8359 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008360
8361 // The input dispatching timeout for this application token in nanoseconds.
8362 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008364 // These are used for determining when all windows associated with
8365 // an activity have been drawn, so they can be made visible together
8366 // at the same time.
8367 int lastTransactionSequence = mTransactionSequence-1;
8368 int numInterestingWindows;
8369 int numDrawnWindows;
8370 boolean inPendingTransaction;
8371 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008373 // Is this token going to be hidden in a little while? If so, it
8374 // won't be taken into account for setting the screen orientation.
8375 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 // Is this window's surface needed? This is almost like hidden, except
8378 // it will sometimes be true a little earlier: when the token has
8379 // been shown, but is still waiting for its app transition to execute
8380 // before making its windows shown.
8381 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008383 // Have we told the window clients to hide themselves?
8384 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008386 // Last visibility state we reported to the app token.
8387 boolean reportedVisible;
8388
8389 // Set to true when the token has been removed from the window mgr.
8390 boolean removed;
8391
8392 // Have we been asked to have this token keep the screen frozen?
8393 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008395 boolean animating;
8396 Animation animation;
8397 boolean hasTransformation;
8398 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008400 // Offset to the window of all layers in the token, for use by
8401 // AppWindowToken animations.
8402 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008404 // Information about an application starting window if displayed.
8405 StartingData startingData;
8406 WindowState startingWindow;
8407 View startingView;
8408 boolean startingDisplayed;
8409 boolean startingMoved;
8410 boolean firstWindowDrawn;
8411
Jeff Brown928e0542011-01-10 11:17:36 -08008412 // Input application handle used by the input dispatcher.
8413 InputApplicationHandle mInputApplicationHandle;
8414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 AppWindowToken(IApplicationToken _token) {
8416 super(_token.asBinder(),
8417 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8418 appWindowToken = this;
8419 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008420 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008421 }
Romain Guy06882f82009-06-10 13:36:04 -07008422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008423 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008424 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008425 TAG, "Setting animation in " + this + ": " + anim);
8426 animation = anim;
8427 animating = false;
8428 anim.restrictDuration(MAX_ANIMATION_DURATION);
8429 anim.scaleCurrentDuration(mTransitionAnimationScale);
8430 int zorder = anim.getZAdjustment();
8431 int adj = 0;
8432 if (zorder == Animation.ZORDER_TOP) {
8433 adj = TYPE_LAYER_OFFSET;
8434 } else if (zorder == Animation.ZORDER_BOTTOM) {
8435 adj = -TYPE_LAYER_OFFSET;
8436 }
Romain Guy06882f82009-06-10 13:36:04 -07008437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008438 if (animLayerAdjustment != adj) {
8439 animLayerAdjustment = adj;
8440 updateLayers();
8441 }
8442 }
Romain Guy06882f82009-06-10 13:36:04 -07008443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008444 public void setDummyAnimation() {
8445 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008446 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 TAG, "Setting dummy animation in " + this);
8448 animation = sDummyAnimation;
8449 }
8450 }
8451
8452 public void clearAnimation() {
8453 if (animation != null) {
8454 animation = null;
8455 animating = true;
8456 }
8457 }
Romain Guy06882f82009-06-10 13:36:04 -07008458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008459 void updateLayers() {
8460 final int N = allAppWindows.size();
8461 final int adj = animLayerAdjustment;
8462 for (int i=0; i<N; i++) {
8463 WindowState w = allAppWindows.get(i);
8464 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008465 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 + w.mAnimLayer);
8467 if (w == mInputMethodTarget) {
8468 setInputMethodAnimLayerAdjustment(adj);
8469 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008470 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008471 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008472 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008473 }
8474 }
Romain Guy06882f82009-06-10 13:36:04 -07008475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008476 void sendAppVisibilityToClients() {
8477 final int N = allAppWindows.size();
8478 for (int i=0; i<N; i++) {
8479 WindowState win = allAppWindows.get(i);
8480 if (win == startingWindow && clientHidden) {
8481 // Don't hide the starting window.
8482 continue;
8483 }
8484 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008485 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 "Setting visibility of " + win + ": " + (!clientHidden));
8487 win.mClient.dispatchAppVisibility(!clientHidden);
8488 } catch (RemoteException e) {
8489 }
8490 }
8491 }
Romain Guy06882f82009-06-10 13:36:04 -07008492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 void showAllWindowsLocked() {
8494 final int NW = allAppWindows.size();
8495 for (int i=0; i<NW; i++) {
8496 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008497 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 "performing show on: " + w);
8499 w.performShowLocked();
8500 }
8501 }
Romain Guy06882f82009-06-10 13:36:04 -07008502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 // This must be called while inside a transaction.
8504 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008505 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008508 if (animation == sDummyAnimation) {
8509 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008510 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008511 // when it is really time to animate, this will be set to
8512 // a real animation and the next call will execute normally.
8513 return false;
8514 }
Romain Guy06882f82009-06-10 13:36:04 -07008515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8517 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008518 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008519 TAG, "Starting animation in " + this +
8520 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8521 + " scale=" + mTransitionAnimationScale
8522 + " allDrawn=" + allDrawn + " animating=" + animating);
8523 animation.initialize(dw, dh, dw, dh);
8524 animation.setStartTime(currentTime);
8525 animating = true;
8526 }
8527 transformation.clear();
8528 final boolean more = animation.getTransformation(
8529 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008530 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 TAG, "Stepped animation in " + this +
8532 ": more=" + more + ", xform=" + transformation);
8533 if (more) {
8534 // we're done!
8535 hasTransformation = true;
8536 return true;
8537 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008538 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 TAG, "Finished animation in " + this +
8540 " @ " + currentTime);
8541 animation = null;
8542 }
8543 } else if (animation != null) {
8544 // If the display is frozen, and there is a pending animation,
8545 // clear it and make sure we run the cleanup code.
8546 animating = true;
8547 animation = null;
8548 }
8549
8550 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 if (!animating) {
8553 return false;
8554 }
8555
8556 clearAnimation();
8557 animating = false;
8558 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8559 moveInputMethodWindowsIfNeededLocked(true);
8560 }
Romain Guy06882f82009-06-10 13:36:04 -07008561
Joe Onorato8a9b2202010-02-26 18:56:32 -08008562 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008563 TAG, "Animation done in " + this
8564 + ": reportedVisible=" + reportedVisible);
8565
8566 transformation.clear();
8567 if (animLayerAdjustment != 0) {
8568 animLayerAdjustment = 0;
8569 updateLayers();
8570 }
Romain Guy06882f82009-06-10 13:36:04 -07008571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008572 final int N = windows.size();
8573 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008574 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008575 }
8576 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008578 return false;
8579 }
8580
8581 void updateReportedVisibilityLocked() {
8582 if (appToken == null) {
8583 return;
8584 }
Romain Guy06882f82009-06-10 13:36:04 -07008585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 int numInteresting = 0;
8587 int numVisible = 0;
8588 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008589
Joe Onorato8a9b2202010-02-26 18:56:32 -08008590 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008591 final int N = allAppWindows.size();
8592 for (int i=0; i<N; i++) {
8593 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008594 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008595 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008596 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8597 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008598 continue;
8599 }
8600 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008601 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008602 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008603 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008604 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008605 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 + " pv=" + win.mPolicyVisibility
8607 + " dp=" + win.mDrawPending
8608 + " cdp=" + win.mCommitDrawPending
8609 + " ah=" + win.mAttachedHidden
8610 + " th="
8611 + (win.mAppToken != null
8612 ? win.mAppToken.hiddenRequested : false)
8613 + " a=" + win.mAnimating);
8614 }
8615 }
8616 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008617 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 if (!win.isAnimating()) {
8619 numVisible++;
8620 }
8621 nowGone = false;
8622 } else if (win.isAnimating()) {
8623 nowGone = false;
8624 }
8625 }
Romain Guy06882f82009-06-10 13:36:04 -07008626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008628 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 + numInteresting + " visible=" + numVisible);
8630 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008631 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008632 TAG, "Visibility changed in " + this
8633 + ": vis=" + nowVisible);
8634 reportedVisible = nowVisible;
8635 Message m = mH.obtainMessage(
8636 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8637 nowVisible ? 1 : 0,
8638 nowGone ? 1 : 0,
8639 this);
8640 mH.sendMessage(m);
8641 }
8642 }
Romain Guy06882f82009-06-10 13:36:04 -07008643
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008644 WindowState findMainWindow() {
8645 int j = windows.size();
8646 while (j > 0) {
8647 j--;
8648 WindowState win = windows.get(j);
8649 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8650 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8651 return win;
8652 }
8653 }
8654 return null;
8655 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008657 void dump(PrintWriter pw, String prefix) {
8658 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008659 if (appToken != null) {
8660 pw.print(prefix); pw.println("app=true");
8661 }
8662 if (allAppWindows.size() > 0) {
8663 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8664 }
8665 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008666 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008667 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8668 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8669 pw.print(" clientHidden="); pw.print(clientHidden);
8670 pw.print(" willBeHidden="); pw.print(willBeHidden);
8671 pw.print(" reportedVisible="); pw.println(reportedVisible);
8672 if (paused || freezingScreen) {
8673 pw.print(prefix); pw.print("paused="); pw.print(paused);
8674 pw.print(" freezingScreen="); pw.println(freezingScreen);
8675 }
8676 if (numInterestingWindows != 0 || numDrawnWindows != 0
8677 || inPendingTransaction || allDrawn) {
8678 pw.print(prefix); pw.print("numInterestingWindows=");
8679 pw.print(numInterestingWindows);
8680 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8681 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8682 pw.print(" allDrawn="); pw.println(allDrawn);
8683 }
8684 if (animating || animation != null) {
8685 pw.print(prefix); pw.print("animating="); pw.print(animating);
8686 pw.print(" animation="); pw.println(animation);
8687 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008688 if (hasTransformation) {
8689 pw.print(prefix); pw.print("XForm: ");
8690 transformation.printShortString(pw);
8691 pw.println();
8692 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008693 if (animLayerAdjustment != 0) {
8694 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8695 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008696 if (startingData != null || removed || firstWindowDrawn) {
8697 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8698 pw.print(" removed="); pw.print(removed);
8699 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8700 }
8701 if (startingWindow != null || startingView != null
8702 || startingDisplayed || startingMoved) {
8703 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8704 pw.print(" startingView="); pw.print(startingView);
8705 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8706 pw.print(" startingMoved"); pw.println(startingMoved);
8707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008708 }
8709
8710 @Override
8711 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008712 if (stringName == null) {
8713 StringBuilder sb = new StringBuilder();
8714 sb.append("AppWindowToken{");
8715 sb.append(Integer.toHexString(System.identityHashCode(this)));
8716 sb.append(" token="); sb.append(token); sb.append('}');
8717 stringName = sb.toString();
8718 }
8719 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008720 }
8721 }
Romain Guy06882f82009-06-10 13:36:04 -07008722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008723 // -------------------------------------------------------------
8724 // DummyAnimation
8725 // -------------------------------------------------------------
8726
8727 // This is an animation that does nothing: it just immediately finishes
8728 // itself every time it is called. It is used as a stub animation in cases
8729 // where we want to synchronize multiple things that may be animating.
8730 static final class DummyAnimation extends Animation {
8731 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8732 return false;
8733 }
8734 }
8735 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 // -------------------------------------------------------------
8738 // Async Handler
8739 // -------------------------------------------------------------
8740
8741 static final class StartingData {
8742 final String pkg;
8743 final int theme;
8744 final CharSequence nonLocalizedLabel;
8745 final int labelRes;
8746 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008747 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008749 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008750 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008751 pkg = _pkg;
8752 theme = _theme;
8753 nonLocalizedLabel = _nonLocalizedLabel;
8754 labelRes = _labelRes;
8755 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008756 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008757 }
8758 }
8759
8760 private final class H extends Handler {
8761 public static final int REPORT_FOCUS_CHANGE = 2;
8762 public static final int REPORT_LOSING_FOCUS = 3;
8763 public static final int ANIMATE = 4;
8764 public static final int ADD_STARTING = 5;
8765 public static final int REMOVE_STARTING = 6;
8766 public static final int FINISHED_STARTING = 7;
8767 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8769 public static final int HOLD_SCREEN_CHANGED = 12;
8770 public static final int APP_TRANSITION_TIMEOUT = 13;
8771 public static final int PERSIST_ANIMATION_SCALE = 14;
8772 public static final int FORCE_GC = 15;
8773 public static final int ENABLE_SCREEN = 16;
8774 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008775 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008776 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008777 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008778 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008780 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008782 public H() {
8783 }
Romain Guy06882f82009-06-10 13:36:04 -07008784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008785 @Override
8786 public void handleMessage(Message msg) {
8787 switch (msg.what) {
8788 case REPORT_FOCUS_CHANGE: {
8789 WindowState lastFocus;
8790 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 synchronized(mWindowMap) {
8793 lastFocus = mLastFocus;
8794 newFocus = mCurrentFocus;
8795 if (lastFocus == newFocus) {
8796 // Focus is not changing, so nothing to do.
8797 return;
8798 }
8799 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008800 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008801 // + " to " + newFocus);
8802 if (newFocus != null && lastFocus != null
8803 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008804 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008805 mLosingFocus.add(lastFocus);
8806 lastFocus = null;
8807 }
8808 }
8809
8810 if (lastFocus != newFocus) {
8811 //System.out.println("Changing focus from " + lastFocus
8812 // + " to " + newFocus);
8813 if (newFocus != null) {
8814 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008815 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008816 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8817 } catch (RemoteException e) {
8818 // Ignore if process has died.
8819 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008820 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008821 }
8822
8823 if (lastFocus != null) {
8824 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008825 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008826 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8827 } catch (RemoteException e) {
8828 // Ignore if process has died.
8829 }
8830 }
8831 }
8832 } break;
8833
8834 case REPORT_LOSING_FOCUS: {
8835 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008837 synchronized(mWindowMap) {
8838 losers = mLosingFocus;
8839 mLosingFocus = new ArrayList<WindowState>();
8840 }
8841
8842 final int N = losers.size();
8843 for (int i=0; i<N; i++) {
8844 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008845 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008846 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8847 } catch (RemoteException e) {
8848 // Ignore if process has died.
8849 }
8850 }
8851 } break;
8852
8853 case ANIMATE: {
8854 synchronized(mWindowMap) {
8855 mAnimationPending = false;
8856 performLayoutAndPlaceSurfacesLocked();
8857 }
8858 } break;
8859
8860 case ADD_STARTING: {
8861 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8862 final StartingData sd = wtoken.startingData;
8863
8864 if (sd == null) {
8865 // Animation has been canceled... do nothing.
8866 return;
8867 }
Romain Guy06882f82009-06-10 13:36:04 -07008868
Joe Onorato8a9b2202010-02-26 18:56:32 -08008869 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008870 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008872 View view = null;
8873 try {
8874 view = mPolicy.addStartingWindow(
8875 wtoken.token, sd.pkg,
8876 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008877 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008878 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008879 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008880 }
8881
8882 if (view != null) {
8883 boolean abort = false;
8884
8885 synchronized(mWindowMap) {
8886 if (wtoken.removed || wtoken.startingData == null) {
8887 // If the window was successfully added, then
8888 // we need to remove it.
8889 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008890 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 "Aborted starting " + wtoken
8892 + ": removed=" + wtoken.removed
8893 + " startingData=" + wtoken.startingData);
8894 wtoken.startingWindow = null;
8895 wtoken.startingData = null;
8896 abort = true;
8897 }
8898 } else {
8899 wtoken.startingView = view;
8900 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008901 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008902 "Added starting " + wtoken
8903 + ": startingWindow="
8904 + wtoken.startingWindow + " startingView="
8905 + wtoken.startingView);
8906 }
8907
8908 if (abort) {
8909 try {
8910 mPolicy.removeStartingWindow(wtoken.token, view);
8911 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008912 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008913 }
8914 }
8915 }
8916 } break;
8917
8918 case REMOVE_STARTING: {
8919 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8920 IBinder token = null;
8921 View view = null;
8922 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008923 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008924 + wtoken + ": startingWindow="
8925 + wtoken.startingWindow + " startingView="
8926 + wtoken.startingView);
8927 if (wtoken.startingWindow != null) {
8928 view = wtoken.startingView;
8929 token = wtoken.token;
8930 wtoken.startingData = null;
8931 wtoken.startingView = null;
8932 wtoken.startingWindow = null;
8933 }
8934 }
8935 if (view != null) {
8936 try {
8937 mPolicy.removeStartingWindow(token, view);
8938 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008939 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008940 }
8941 }
8942 } break;
8943
8944 case FINISHED_STARTING: {
8945 IBinder token = null;
8946 View view = null;
8947 while (true) {
8948 synchronized (mWindowMap) {
8949 final int N = mFinishedStarting.size();
8950 if (N <= 0) {
8951 break;
8952 }
8953 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8954
Joe Onorato8a9b2202010-02-26 18:56:32 -08008955 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008956 "Finished starting " + wtoken
8957 + ": startingWindow=" + wtoken.startingWindow
8958 + " startingView=" + wtoken.startingView);
8959
8960 if (wtoken.startingWindow == null) {
8961 continue;
8962 }
8963
8964 view = wtoken.startingView;
8965 token = wtoken.token;
8966 wtoken.startingData = null;
8967 wtoken.startingView = null;
8968 wtoken.startingWindow = null;
8969 }
8970
8971 try {
8972 mPolicy.removeStartingWindow(token, view);
8973 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008974 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008975 }
8976 }
8977 } break;
8978
8979 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8980 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8981
8982 boolean nowVisible = msg.arg1 != 0;
8983 boolean nowGone = msg.arg2 != 0;
8984
8985 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008986 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 TAG, "Reporting visible in " + wtoken
8988 + " visible=" + nowVisible
8989 + " gone=" + nowGone);
8990 if (nowVisible) {
8991 wtoken.appToken.windowsVisible();
8992 } else {
8993 wtoken.appToken.windowsGone();
8994 }
8995 } catch (RemoteException ex) {
8996 }
8997 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008999 case WINDOW_FREEZE_TIMEOUT: {
9000 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009001 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009002 int i = mWindows.size();
9003 while (i > 0) {
9004 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009005 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009006 if (w.mOrientationChanging) {
9007 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009008 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009009 }
9010 }
9011 performLayoutAndPlaceSurfacesLocked();
9012 }
9013 break;
9014 }
Romain Guy06882f82009-06-10 13:36:04 -07009015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009016 case HOLD_SCREEN_CHANGED: {
9017 Session oldHold;
9018 Session newHold;
9019 synchronized (mWindowMap) {
9020 oldHold = mLastReportedHold;
9021 newHold = (Session)msg.obj;
9022 mLastReportedHold = newHold;
9023 }
Romain Guy06882f82009-06-10 13:36:04 -07009024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009025 if (oldHold != newHold) {
9026 try {
9027 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009028 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009029 "window",
9030 BatteryStats.WAKE_TYPE_WINDOW);
9031 }
9032 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009033 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009034 "window",
9035 BatteryStats.WAKE_TYPE_WINDOW);
9036 }
9037 } catch (RemoteException e) {
9038 }
9039 }
9040 break;
9041 }
Romain Guy06882f82009-06-10 13:36:04 -07009042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 case APP_TRANSITION_TIMEOUT: {
9044 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009045 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009046 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009047 "*** APP TRANSITION TIMEOUT");
9048 mAppTransitionReady = true;
9049 mAppTransitionTimeout = true;
9050 performLayoutAndPlaceSurfacesLocked();
9051 }
9052 }
9053 break;
9054 }
Romain Guy06882f82009-06-10 13:36:04 -07009055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009056 case PERSIST_ANIMATION_SCALE: {
9057 Settings.System.putFloat(mContext.getContentResolver(),
9058 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9059 Settings.System.putFloat(mContext.getContentResolver(),
9060 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9061 break;
9062 }
Romain Guy06882f82009-06-10 13:36:04 -07009063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009064 case FORCE_GC: {
9065 synchronized(mWindowMap) {
9066 if (mAnimationPending) {
9067 // If we are animating, don't do the gc now but
9068 // delay a bit so we don't interrupt the animation.
9069 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9070 2000);
9071 return;
9072 }
9073 // If we are currently rotating the display, it will
9074 // schedule a new message when done.
9075 if (mDisplayFrozen) {
9076 return;
9077 }
9078 mFreezeGcPending = 0;
9079 }
9080 Runtime.getRuntime().gc();
9081 break;
9082 }
Romain Guy06882f82009-06-10 13:36:04 -07009083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 case ENABLE_SCREEN: {
9085 performEnableScreen();
9086 break;
9087 }
Romain Guy06882f82009-06-10 13:36:04 -07009088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009089 case APP_FREEZE_TIMEOUT: {
9090 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009091 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009092 int i = mAppTokens.size();
9093 while (i > 0) {
9094 i--;
9095 AppWindowToken tok = mAppTokens.get(i);
9096 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009097 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009098 unsetAppFreezingScreenLocked(tok, true, true);
9099 }
9100 }
9101 }
9102 break;
9103 }
Romain Guy06882f82009-06-10 13:36:04 -07009104
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009105 case SEND_NEW_CONFIGURATION: {
9106 removeMessages(SEND_NEW_CONFIGURATION);
9107 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009108 break;
9109 }
Romain Guy06882f82009-06-10 13:36:04 -07009110
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009111 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009112 if (mWindowsChanged) {
9113 synchronized (mWindowMap) {
9114 mWindowsChanged = false;
9115 }
9116 notifyWindowsChanged();
9117 }
9118 break;
9119 }
9120
Christopher Tatea53146c2010-09-07 11:57:52 -07009121 case DRAG_START_TIMEOUT: {
9122 IBinder win = (IBinder)msg.obj;
9123 if (DEBUG_DRAG) {
9124 Slog.w(TAG, "Timeout starting drag by win " + win);
9125 }
9126 synchronized (mWindowMap) {
9127 // !!! TODO: ANR the app that has failed to start the drag in time
9128 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009129 mDragState.unregister();
9130 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009131 mDragState.reset();
9132 mDragState = null;
9133 }
9134 }
Chris Tated4533f142010-10-19 15:15:08 -07009135 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009136 }
9137
Chris Tated4533f142010-10-19 15:15:08 -07009138 case DRAG_END_TIMEOUT: {
9139 IBinder win = (IBinder)msg.obj;
9140 if (DEBUG_DRAG) {
9141 Slog.w(TAG, "Timeout ending drag to win " + win);
9142 }
9143 synchronized (mWindowMap) {
9144 // !!! TODO: ANR the drag-receiving app
9145 mDragState.mDragResult = false;
9146 mDragState.endDragLw();
9147 }
9148 break;
9149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009150 }
9151 }
9152 }
9153
9154 // -------------------------------------------------------------
9155 // IWindowManager API
9156 // -------------------------------------------------------------
9157
9158 public IWindowSession openSession(IInputMethodClient client,
9159 IInputContext inputContext) {
9160 if (client == null) throw new IllegalArgumentException("null client");
9161 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009162 Session session = new Session(client, inputContext);
9163 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009164 }
9165
9166 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9167 synchronized (mWindowMap) {
9168 // The focus for the client is the window immediately below
9169 // where we would place the input method window.
9170 int idx = findDesiredInputMethodWindowIndexLocked(false);
9171 WindowState imFocus;
9172 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009173 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 if (imFocus != null) {
9175 if (imFocus.mSession.mClient != null &&
9176 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9177 return true;
9178 }
9179 }
9180 }
9181 }
9182 return false;
9183 }
Romain Guy06882f82009-06-10 13:36:04 -07009184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009185 // -------------------------------------------------------------
9186 // Internals
9187 // -------------------------------------------------------------
9188
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009189 final WindowState windowForClientLocked(Session session, IWindow client,
9190 boolean throwOnError) {
9191 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009192 }
Romain Guy06882f82009-06-10 13:36:04 -07009193
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009194 final WindowState windowForClientLocked(Session session, IBinder client,
9195 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009196 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009197 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009198 TAG, "Looking up client " + client + ": " + win);
9199 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009200 RuntimeException ex = new IllegalArgumentException(
9201 "Requested window " + client + " does not exist");
9202 if (throwOnError) {
9203 throw ex;
9204 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009205 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009206 return null;
9207 }
9208 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009209 RuntimeException ex = new IllegalArgumentException(
9210 "Requested window " + client + " is in session " +
9211 win.mSession + ", not " + session);
9212 if (throwOnError) {
9213 throw ex;
9214 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009215 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009216 return null;
9217 }
9218
9219 return win;
9220 }
9221
Dianne Hackborna8f60182009-09-01 19:01:50 -07009222 final void rebuildAppWindowListLocked() {
9223 int NW = mWindows.size();
9224 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009225 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009226 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009227
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009228 if (mRebuildTmp.length < NW) {
9229 mRebuildTmp = new WindowState[NW+10];
9230 }
9231
Dianne Hackborna8f60182009-09-01 19:01:50 -07009232 // First remove all existing app windows.
9233 i=0;
9234 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009235 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009236 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009237 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009238 win.mRebuilding = true;
9239 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009240 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009241 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009242 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009243 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009244 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009245 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009246 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9247 && lastWallpaper == i-1) {
9248 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009249 }
9250 i++;
9251 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009252
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009253 // The wallpaper window(s) typically live at the bottom of the stack,
9254 // so skip them before adding app tokens.
9255 lastWallpaper++;
9256 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009257
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009258 // First add all of the exiting app tokens... these are no longer
9259 // in the main app list, but still have windows shown. We put them
9260 // in the back because now that the animation is over we no longer
9261 // will care about them.
9262 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009263 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009264 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009266
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009267 // And add in the still active app tokens in Z order.
9268 NT = mAppTokens.size();
9269 for (int j=0; j<NT; j++) {
9270 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009272
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009273 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009274 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009275 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009276 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009277 for (i=0; i<numRemoved; i++) {
9278 WindowState ws = mRebuildTmp[i];
9279 if (ws.mRebuilding) {
9280 StringWriter sw = new StringWriter();
9281 PrintWriter pw = new PrintWriter(sw);
9282 ws.dump(pw, "");
9283 pw.flush();
9284 Slog.w(TAG, "This window was lost: " + ws);
9285 Slog.w(TAG, sw.toString());
9286 }
9287 }
9288 Slog.w(TAG, "Current app token list:");
9289 dumpAppTokensLocked();
9290 Slog.w(TAG, "Final window list:");
9291 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009292 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009293 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 private final void assignLayersLocked() {
9296 int N = mWindows.size();
9297 int curBaseLayer = 0;
9298 int curLayer = 0;
9299 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009300
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009301 if (DEBUG_LAYERS) {
9302 RuntimeException here = new RuntimeException("here");
9303 here.fillInStackTrace();
9304 Log.v(TAG, "Assigning layers", here);
9305 }
9306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009307 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009308 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009309 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9310 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 curLayer += WINDOW_LAYER_MULTIPLIER;
9312 w.mLayer = curLayer;
9313 } else {
9314 curBaseLayer = curLayer = w.mBaseLayer;
9315 w.mLayer = curLayer;
9316 }
9317 if (w.mTargetAppToken != null) {
9318 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9319 } else if (w.mAppToken != null) {
9320 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9321 } else {
9322 w.mAnimLayer = w.mLayer;
9323 }
9324 if (w.mIsImWindow) {
9325 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009326 } else if (w.mIsWallpaper) {
9327 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009328 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009329 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009330 + w.mAnimLayer);
9331 //System.out.println(
9332 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9333 }
9334 }
9335
9336 private boolean mInLayout = false;
9337 private final void performLayoutAndPlaceSurfacesLocked() {
9338 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009339 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009340 throw new RuntimeException("Recursive call!");
9341 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009342 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009343 return;
9344 }
9345
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009346 if (mWaitingForConfig) {
9347 // Our configuration has changed (most likely rotation), but we
9348 // don't yet have the complete configuration to report to
9349 // applications. Don't do any window layout until we have it.
9350 return;
9351 }
9352
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009353 if (mDisplay == null) {
9354 // Not yet initialized, nothing to do.
9355 return;
9356 }
9357
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009358 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009359 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009360
9361 try {
9362 if (mForceRemoves != null) {
9363 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009364 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009365 for (int i=0; i<mForceRemoves.size(); i++) {
9366 WindowState ws = mForceRemoves.get(i);
9367 Slog.i(TAG, "Force removing: " + ws);
9368 removeWindowInnerLocked(ws.mSession, ws);
9369 }
9370 mForceRemoves = null;
9371 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9372 Object tmp = new Object();
9373 synchronized (tmp) {
9374 try {
9375 tmp.wait(250);
9376 } catch (InterruptedException e) {
9377 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009378 }
9379 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009380 } catch (RuntimeException e) {
9381 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009382 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 try {
9385 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009386
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009387 int N = mPendingRemove.size();
9388 if (N > 0) {
9389 if (mPendingRemoveTmp.length < N) {
9390 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009391 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009392 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009394 for (int i=0; i<N; i++) {
9395 WindowState w = mPendingRemoveTmp[i];
9396 removeWindowInnerLocked(w.mSession, w);
9397 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398
9399 mInLayout = false;
9400 assignLayersLocked();
9401 mLayoutNeeded = true;
9402 performLayoutAndPlaceSurfacesLocked();
9403
9404 } else {
9405 mInLayout = false;
9406 if (mLayoutNeeded) {
9407 requestAnimationLocked(0);
9408 }
9409 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009410 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009411 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9412 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009414 } catch (RuntimeException e) {
9415 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009416 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 }
9418 }
9419
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009420 private final int performLayoutLockedInner(boolean initial) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009421 if (!mLayoutNeeded) {
9422 return 0;
9423 }
9424
9425 mLayoutNeeded = false;
9426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 final int dw = mDisplay.getWidth();
9428 final int dh = mDisplay.getHeight();
9429
9430 final int N = mWindows.size();
9431 int i;
9432
Joe Onorato8a9b2202010-02-26 18:56:32 -08009433 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009434 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9435
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009436 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009437
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009438 int seq = mLayoutSeq+1;
9439 if (seq < 0) seq = 0;
9440 mLayoutSeq = seq;
9441
9442 // First perform layout of any root windows (not attached
9443 // to another window).
9444 int topAttached = -1;
9445 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009446 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009448 // Don't do layout of a window if it is not visible, or
9449 // soon won't be visible, to avoid wasting time and funky
9450 // changes while a window is animating away.
9451 final AppWindowToken atoken = win.mAppToken;
9452 final boolean gone = win.mViewVisibility == View.GONE
9453 || !win.mRelayoutCalled
9454 || win.mRootToken.hidden
9455 || (atoken != null && atoken.hiddenRequested)
9456 || win.mAttachedHidden
9457 || win.mExiting || win.mDestroying;
9458
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009459 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9460 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009461 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9462 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009463 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009464 + win.mViewVisibility + " mRelayoutCalled="
9465 + win.mRelayoutCalled + " hidden="
9466 + win.mRootToken.hidden + " hiddenRequested="
9467 + (atoken != null && atoken.hiddenRequested)
9468 + " mAttachedHidden=" + win.mAttachedHidden);
9469 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009470
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009471 // If this view is GONE, then skip it -- keep the current
9472 // frame, and let the caller know so they can ignore it
9473 // if they want. (We do the normal layout for INVISIBLE
9474 // windows, since that means "perform layout as normal,
9475 // just don't display").
9476 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009477 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009478 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009479 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009480 win.mContentChanged = false;
9481 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009482 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9483 win.mLayoutSeq = seq;
9484 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9485 + win.mFrame + " mContainingFrame="
9486 + win.mContainingFrame + " mDisplayFrame="
9487 + win.mDisplayFrame);
9488 } else {
9489 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009490 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009491 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009492 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009493
9494 // Now perform layout of attached windows, which usually
9495 // depend on the position of the window they are attached to.
9496 // XXX does not deal with windows that are attached to windows
9497 // that are themselves attached.
9498 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009499 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009500
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009501 if (win.mLayoutAttached) {
9502 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9503 + " mHaveFrame=" + win.mHaveFrame
9504 + " mViewVisibility=" + win.mViewVisibility
9505 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009506 // If this view is GONE, then skip it -- keep the current
9507 // frame, and let the caller know so they can ignore it
9508 // if they want. (We do the normal layout for INVISIBLE
9509 // windows, since that means "perform layout as normal,
9510 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009511 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9512 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009513 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009514 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009515 win.mContentChanged = false;
9516 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009517 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9518 win.mLayoutSeq = seq;
9519 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9520 + win.mFrame + " mContainingFrame="
9521 + win.mContainingFrame + " mDisplayFrame="
9522 + win.mDisplayFrame);
9523 }
9524 }
9525 }
Jeff Brown349703e2010-06-22 01:27:15 -07009526
9527 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009528 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009529
9530 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009531 }
Romain Guy06882f82009-06-10 13:36:04 -07009532
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009533 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534 private final void performLayoutAndPlaceSurfacesLockedInner(
9535 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009536 if (mDisplay == null) {
9537 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9538 return;
9539 }
9540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009541 final long currentTime = SystemClock.uptimeMillis();
9542 final int dw = mDisplay.getWidth();
9543 final int dh = mDisplay.getHeight();
9544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 int i;
9546
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009547 if (mFocusMayChange) {
9548 mFocusMayChange = false;
9549 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9550 }
9551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 // Initialize state of exiting tokens.
9553 for (i=mExitingTokens.size()-1; i>=0; i--) {
9554 mExitingTokens.get(i).hasVisible = false;
9555 }
9556
9557 // Initialize state of exiting applications.
9558 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9559 mExitingAppTokens.get(i).hasVisible = false;
9560 }
9561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009562 boolean orientationChangeComplete = true;
9563 Session holdScreen = null;
9564 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009565 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009566 boolean focusDisplayed = false;
9567 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009568 boolean createWatermark = false;
9569
9570 if (mFxSession == null) {
9571 mFxSession = new SurfaceSession();
9572 createWatermark = true;
9573 }
9574
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009575 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009576
9577 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009578
9579 if (createWatermark) {
9580 createWatermark();
9581 }
9582 if (mWatermark != null) {
9583 mWatermark.positionSurface(dw, dh);
9584 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009585 if (mStrictModeFlash != null) {
9586 mStrictModeFlash.positionSurface(dw, dh);
9587 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009590 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009591 int repeats = 0;
9592 int changes = 0;
9593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009594 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009595 repeats++;
9596 if (repeats > 6) {
9597 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9598 mLayoutNeeded = false;
9599 break;
9600 }
9601
9602 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9603 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9604 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9605 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9606 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9607 assignLayersLocked();
9608 mLayoutNeeded = true;
9609 }
9610 }
9611 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9612 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009613 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009614 mLayoutNeeded = true;
9615 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9616 }
9617 }
9618 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9619 mLayoutNeeded = true;
9620 }
9621 }
9622
9623 // FIRST LOOP: Perform a layout, if needed.
9624 if (repeats < 4) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009625 changes = performLayoutLockedInner(repeats == 0);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009626 if (changes != 0) {
9627 continue;
9628 }
9629 } else {
9630 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9631 changes = 0;
9632 }
9633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009634 final int transactionSequence = ++mTransactionSequence;
9635
9636 // Update animations of all applications, including those
9637 // associated with exiting/removed apps
9638 boolean tokensAnimating = false;
9639 final int NAT = mAppTokens.size();
9640 for (i=0; i<NAT; i++) {
9641 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9642 tokensAnimating = true;
9643 }
9644 }
9645 final int NEAT = mExitingAppTokens.size();
9646 for (i=0; i<NEAT; i++) {
9647 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9648 tokensAnimating = true;
9649 }
9650 }
9651
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009652 // SECOND LOOP: Execute animations and update visibility of windows.
9653
Joe Onorato8a9b2202010-02-26 18:56:32 -08009654 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009655 + transactionSequence + " tokensAnimating="
9656 + tokensAnimating);
9657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009658 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009659
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009660 if (mScreenRotationAnimation != null) {
9661 if (mScreenRotationAnimation.isAnimating()) {
9662 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9663 animating = true;
9664 } else {
9665 mScreenRotationAnimation = null;
9666 }
9667 }
9668 }
9669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009670 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009671 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009672 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009673 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009674
9675 mPolicy.beginAnimationLw(dw, dh);
9676
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009677 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009679 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009680 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009681
9682 final WindowManager.LayoutParams attrs = w.mAttrs;
9683
9684 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009685 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009686 if (w.commitFinishDrawingLocked(currentTime)) {
9687 if ((w.mAttrs.flags
9688 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009689 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009690 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009691 wallpaperMayChange = true;
9692 }
9693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009694
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009695 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009696
9697 int animDw = dw;
9698 int animDh = dh;
9699
9700 // If the window has moved due to its containing
9701 // content frame changing, then we'd like to animate
9702 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009703 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009704 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009705 // Frame has moved, containing content frame
9706 // has also moved, and we're not currently animating...
9707 // let's do something.
9708 Animation a = AnimationUtils.loadAnimation(mContext,
9709 com.android.internal.R.anim.window_move_from_decor);
9710 w.setAnimation(a);
9711 animDw = w.mLastFrame.left - w.mFrame.left;
9712 animDh = w.mLastFrame.top - w.mFrame.top;
9713 }
9714
9715 // Execute animation.
9716 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9717 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009718
9719 // If this window is animating, make a note that we have
9720 // an animating window and take care of a request to run
9721 // a detached wallpaper animation.
9722 if (nowAnimating) {
9723 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9724 windowDetachedWallpaper = w;
9725 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009726 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009727 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009728
9729 // If this window's app token is running a detached wallpaper
9730 // animation, make a note so we can ensure the wallpaper is
9731 // displayed behind it.
9732 if (w.mAppToken != null && w.mAppToken.animation != null
9733 && w.mAppToken.animation.getDetachWallpaper()) {
9734 windowDetachedWallpaper = w;
9735 }
9736
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009737 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9738 wallpaperMayChange = true;
9739 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009740
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009741 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009742 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009743 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009744 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009745 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009746 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009747 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009748 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9749 forceHiding = true;
9750 }
9751 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9752 boolean changed;
9753 if (forceHiding) {
9754 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009755 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9756 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009757 } else {
9758 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009759 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9760 "Now policy shown: " + w);
9761 if (changed) {
9762 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009763 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009764 // Assume we will need to animate. If
9765 // we don't (because the wallpaper will
9766 // stay with the lock screen), then we will
9767 // clean up later.
9768 Animation a = mPolicy.createForceHideEnterAnimation();
9769 if (a != null) {
9770 w.setAnimation(a);
9771 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009772 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009773 if (mCurrentFocus == null ||
9774 mCurrentFocus.mLayer < w.mLayer) {
9775 // We are showing on to of the current
9776 // focus, so re-evaluate focus to make
9777 // sure it is correct.
9778 mFocusMayChange = true;
9779 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009780 }
9781 }
9782 if (changed && (attrs.flags
9783 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9784 wallpaperMayChange = true;
9785 }
9786 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 mPolicy.animatingWindowLw(w, attrs);
9789 }
9790
9791 final AppWindowToken atoken = w.mAppToken;
9792 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9793 if (atoken.lastTransactionSequence != transactionSequence) {
9794 atoken.lastTransactionSequence = transactionSequence;
9795 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9796 atoken.startingDisplayed = false;
9797 }
9798 if ((w.isOnScreen() || w.mAttrs.type
9799 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9800 && !w.mExiting && !w.mDestroying) {
9801 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009802 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009803 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009804 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009805 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009806 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009807 + " pv=" + w.mPolicyVisibility
9808 + " dp=" + w.mDrawPending
9809 + " cdp=" + w.mCommitDrawPending
9810 + " ah=" + w.mAttachedHidden
9811 + " th=" + atoken.hiddenRequested
9812 + " a=" + w.mAnimating);
9813 }
9814 }
9815 if (w != atoken.startingWindow) {
9816 if (!atoken.freezingScreen || !w.mAppFreezing) {
9817 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009818 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009819 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009820 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009821 "tokenMayBeDrawn: " + atoken
9822 + " freezingScreen=" + atoken.freezingScreen
9823 + " mAppFreezing=" + w.mAppFreezing);
9824 tokenMayBeDrawn = true;
9825 }
9826 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009827 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009828 atoken.startingDisplayed = true;
9829 }
9830 }
9831 } else if (w.mReadyToShow) {
9832 w.performShowLocked();
9833 }
9834 }
9835
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009836 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009837
9838 if (tokenMayBeDrawn) {
9839 // See if any windows have been drawn, so they (and others
9840 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009841 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009842 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009843 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009844 if (wtoken.freezingScreen) {
9845 int numInteresting = wtoken.numInterestingWindows;
9846 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009847 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 "allDrawn: " + wtoken
9849 + " interesting=" + numInteresting
9850 + " drawn=" + wtoken.numDrawnWindows);
9851 wtoken.showAllWindowsLocked();
9852 unsetAppFreezingScreenLocked(wtoken, false, true);
9853 orientationChangeComplete = true;
9854 }
9855 } else if (!wtoken.allDrawn) {
9856 int numInteresting = wtoken.numInterestingWindows;
9857 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009858 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859 "allDrawn: " + wtoken
9860 + " interesting=" + numInteresting
9861 + " drawn=" + wtoken.numDrawnWindows);
9862 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009863 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009864
9865 // We can now show all of the drawn windows!
9866 if (!mOpeningApps.contains(wtoken)) {
9867 wtoken.showAllWindowsLocked();
9868 }
9869 }
9870 }
9871 }
9872 }
9873
9874 // If we are ready to perform an app transition, check through
9875 // all of the app tokens to be shown and see if they are ready
9876 // to go.
9877 if (mAppTransitionReady) {
9878 int NN = mOpeningApps.size();
9879 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009880 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009881 "Checking " + NN + " opening apps (frozen="
9882 + mDisplayFrozen + " timeout="
9883 + mAppTransitionTimeout + ")...");
9884 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9885 // If the display isn't frozen, wait to do anything until
9886 // all of the apps are ready. Otherwise just go because
9887 // we'll unfreeze the display when everyone is ready.
9888 for (i=0; i<NN && goodToGo; i++) {
9889 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009890 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009891 "Check opening app" + wtoken + ": allDrawn="
9892 + wtoken.allDrawn + " startingDisplayed="
9893 + wtoken.startingDisplayed);
9894 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9895 && !wtoken.startingMoved) {
9896 goodToGo = false;
9897 }
9898 }
9899 }
9900 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009901 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 int transit = mNextAppTransition;
9903 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009904 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009906 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009907 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009908 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 mAppTransitionTimeout = false;
9910 mStartingIconInTransition = false;
9911 mSkipAppTransitionAnimation = false;
9912
9913 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9914
Dianne Hackborna8f60182009-09-01 19:01:50 -07009915 // If there are applications waiting to come to the
9916 // top of the stack, now is the time to move their windows.
9917 // (Note that we don't do apps going to the bottom
9918 // here -- we want to keep their windows in the old
9919 // Z-order until the animation completes.)
9920 if (mToTopApps.size() > 0) {
9921 NN = mAppTokens.size();
9922 for (i=0; i<NN; i++) {
9923 AppWindowToken wtoken = mAppTokens.get(i);
9924 if (wtoken.sendingToTop) {
9925 wtoken.sendingToTop = false;
9926 moveAppWindowsLocked(wtoken, NN, false);
9927 }
9928 }
9929 mToTopApps.clear();
9930 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009931
Dianne Hackborn25994b42009-09-04 14:21:19 -07009932 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009933
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009934 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009935 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009936
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009937 // The top-most window will supply the layout params,
9938 // and we will determine it below.
9939 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009940 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009941 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009942
Joe Onorato8a9b2202010-02-26 18:56:32 -08009943 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009944 "New wallpaper target=" + mWallpaperTarget
9945 + ", lower target=" + mLowerWallpaperTarget
9946 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009947 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009948 // Do a first pass through the tokens for two
9949 // things:
9950 // (1) Determine if both the closing and opening
9951 // app token sets are wallpaper targets, in which
9952 // case special animations are needed
9953 // (since the wallpaper needs to stay static
9954 // behind them).
9955 // (2) Find the layout params of the top-most
9956 // application window in the tokens, which is
9957 // what will control the animation theme.
9958 final int NC = mClosingApps.size();
9959 NN = NC + mOpeningApps.size();
9960 for (i=0; i<NN; i++) {
9961 AppWindowToken wtoken;
9962 int mode;
9963 if (i < NC) {
9964 wtoken = mClosingApps.get(i);
9965 mode = 1;
9966 } else {
9967 wtoken = mOpeningApps.get(i-NC);
9968 mode = 2;
9969 }
9970 if (mLowerWallpaperTarget != null) {
9971 if (mLowerWallpaperTarget.mAppToken == wtoken
9972 || mUpperWallpaperTarget.mAppToken == wtoken) {
9973 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009974 }
9975 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009976 if (wtoken.appFullscreen) {
9977 WindowState ws = wtoken.findMainWindow();
9978 if (ws != null) {
9979 // If this is a compatibility mode
9980 // window, we will always use its anim.
9981 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9982 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009983 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009984 bestAnimLayer = Integer.MAX_VALUE;
9985 } else if (ws.mLayer > bestAnimLayer) {
9986 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009987 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009988 bestAnimLayer = ws.mLayer;
9989 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009990 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009991 }
9992 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009993
Dianne Hackborn25994b42009-09-04 14:21:19 -07009994 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009995 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009996 "Wallpaper animation!");
9997 switch (transit) {
9998 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9999 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10000 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10001 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10002 break;
10003 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10004 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10005 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10006 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10007 break;
10008 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010009 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010010 "New transit: " + transit);
10011 } else if (oldWallpaper != null) {
10012 // We are transitioning from an activity with
10013 // a wallpaper to one without.
10014 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010015 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010016 "New transit away from wallpaper: " + transit);
10017 } else if (mWallpaperTarget != null) {
10018 // We are transitioning from an activity without
10019 // a wallpaper to now showing the wallpaper
10020 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010021 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010022 "New transit into wallpaper: " + transit);
10023 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010024
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010025 // If all closing windows are obscured, then there is
10026 // no need to do an animation. This is the case, for
10027 // example, when this transition is being done behind
10028 // the lock screen.
10029 if (!mPolicy.allowAppAnimationsLw()) {
10030 animLp = null;
10031 }
10032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 NN = mOpeningApps.size();
10034 for (i=0; i<NN; i++) {
10035 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010036 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010037 "Now opening app" + wtoken);
10038 wtoken.reportedVisible = false;
10039 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010040 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010041 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010042 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010043 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010044 wtoken.showAllWindowsLocked();
10045 }
10046 NN = mClosingApps.size();
10047 for (i=0; i<NN; i++) {
10048 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010049 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 "Now closing app" + wtoken);
10051 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010052 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010053 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010055 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010056 // Force the allDrawn flag, because we want to start
10057 // this guy's animations regardless of whether it's
10058 // gotten drawn.
10059 wtoken.allDrawn = true;
10060 }
10061
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010062 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010064 mOpeningApps.clear();
10065 mClosingApps.clear();
10066
10067 // This has changed the visibility of windows, so perform
10068 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010069 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10070 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010072 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10073 assignLayersLocked();
10074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010076 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 }
10078 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010079
Dianne Hackborn16064f92010-03-25 00:47:24 -070010080 int adjResult = 0;
10081
Dianne Hackborna8f60182009-09-01 19:01:50 -070010082 if (!animating && mAppTransitionRunning) {
10083 // We have finished the animation of an app transition. To do
10084 // this, we have delayed a lot of operations like showing and
10085 // hiding apps, moving apps in Z-order, etc. The app token list
10086 // reflects the correct Z-order, but the window list may now
10087 // be out of sync with it. So here we will just rebuild the
10088 // entire app window list. Fun!
10089 mAppTransitionRunning = false;
10090 // Clear information about apps that were moving.
10091 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010092
Dianne Hackborna8f60182009-09-01 19:01:50 -070010093 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010094 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010095 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010096 moveInputMethodWindowsIfNeededLocked(false);
10097 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010098 // Since the window list has been rebuilt, focus might
10099 // have to be recomputed since the actual order of windows
10100 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010101 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010103
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010104 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010105 // At this point, there was a window with a wallpaper that
10106 // was force hiding other windows behind it, but now it
10107 // is going away. This may be simple -- just animate
10108 // away the wallpaper and its window -- or it may be
10109 // hard -- the wallpaper now needs to be shown behind
10110 // something that was hidden.
10111 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010112 if (mLowerWallpaperTarget != null
10113 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010114 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010115 "wallpaperForceHiding changed with lower="
10116 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010117 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010118 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10119 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10120 if (mLowerWallpaperTarget.mAppToken.hidden) {
10121 // The lower target has become hidden before we
10122 // actually started the animation... let's completely
10123 // re-evaluate everything.
10124 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010125 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010126 }
10127 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010128 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010129 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010130 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010131 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010132 + " NEW: " + mWallpaperTarget
10133 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010134 if (mLowerWallpaperTarget == null) {
10135 // Whoops, we don't need a special wallpaper animation.
10136 // Clear them out.
10137 forceHiding = false;
10138 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010139 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010140 if (w.mSurface != null) {
10141 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010142 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010143 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010144 forceHiding = true;
10145 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10146 if (!w.mAnimating) {
10147 // We set the animation above so it
10148 // is not yet running.
10149 w.clearAnimation();
10150 }
10151 }
10152 }
10153 }
10154 }
10155 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010156
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010157 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10158 if (DEBUG_WALLPAPER) Slog.v(TAG,
10159 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10160 + windowDetachedWallpaper);
10161 mWindowDetachedWallpaper = windowDetachedWallpaper;
10162 wallpaperMayChange = true;
10163 }
10164
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010165 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010166 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010167 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010168 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010169 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010170
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010171 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010172 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010173 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010174 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010175 assignLayersLocked();
10176 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010177 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010178 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010179 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010180 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010181
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010182 if (mFocusMayChange) {
10183 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010184 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010185 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010186 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010187 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010188 }
10189
10190 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010191 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010192 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010193
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010194 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10195 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010196
Jeff Browne33348b2010-07-15 23:54:05 -070010197 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010198 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010199
10200 // THIRD LOOP: Update the surfaces of all windows.
10201
10202 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10203
10204 boolean obscured = false;
10205 boolean blurring = false;
10206 boolean dimming = false;
10207 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010208 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010209 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010210
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010211 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010213 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010214 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010215
10216 boolean displayed = false;
10217 final WindowManager.LayoutParams attrs = w.mAttrs;
10218 final int attrFlags = attrs.flags;
10219
10220 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010221 // XXX NOTE: The logic here could be improved. We have
10222 // the decision about whether to resize a window separated
10223 // from whether to hide the surface. This can cause us to
10224 // resize a surface even if we are going to hide it. You
10225 // can see this by (1) holding device in landscape mode on
10226 // home screen; (2) tapping browser icon (device will rotate
10227 // to landscape; (3) tap home. The wallpaper will be resized
10228 // in step 2 but then immediately hidden, causing us to
10229 // have to resize and then redraw it again in step 3. It
10230 // would be nice to figure out how to avoid this, but it is
10231 // difficult because we do need to resize surfaces in some
10232 // cases while they are hidden such as when first showing a
10233 // window.
10234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010236 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010237 TAG, "Placing surface #" + i + " " + w.mSurface
10238 + ": new=" + w.mShownFrame + ", old="
10239 + w.mLastShownFrame);
10240
10241 boolean resize;
10242 int width, height;
10243 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10244 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10245 w.mLastRequestedHeight != w.mRequestedHeight;
10246 // for a scaled surface, we just want to use
10247 // the requested size.
10248 width = w.mRequestedWidth;
10249 height = w.mRequestedHeight;
10250 w.mLastRequestedWidth = width;
10251 w.mLastRequestedHeight = height;
10252 w.mLastShownFrame.set(w.mShownFrame);
10253 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010254 if (SHOW_TRANSACTIONS) logSurface(w,
10255 "POS " + w.mShownFrame.left
10256 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010257 w.mSurfaceX = w.mShownFrame.left;
10258 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010259 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10260 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010261 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010262 if (!recoveringMemory) {
10263 reclaimSomeSurfaceMemoryLocked(w, "position");
10264 }
10265 }
10266 } else {
10267 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10268 width = w.mShownFrame.width();
10269 height = w.mShownFrame.height();
10270 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010271 }
10272
10273 if (resize) {
10274 if (width < 1) width = 1;
10275 if (height < 1) height = 1;
10276 if (w.mSurface != null) {
10277 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010278 if (SHOW_TRANSACTIONS) logSurface(w,
10279 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010280 + w.mShownFrame.top + " SIZE "
10281 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010282 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010283 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010284 w.mSurfaceW = width;
10285 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010287 w.mSurfaceX = w.mShownFrame.left;
10288 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 w.mSurface.setPosition(w.mShownFrame.left,
10290 w.mShownFrame.top);
10291 } catch (RuntimeException e) {
10292 // If something goes wrong with the surface (such
10293 // as running out of memory), don't take down the
10294 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010295 Slog.e(TAG, "Failure updating surface of " + w
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010296 + " size=(" + width + "x" + height
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 + "), pos=(" + w.mShownFrame.left
10298 + "," + w.mShownFrame.top + ")", e);
10299 if (!recoveringMemory) {
10300 reclaimSomeSurfaceMemoryLocked(w, "size");
10301 }
10302 }
10303 }
10304 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010305 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010306 w.mContentInsetsChanged =
10307 !w.mLastContentInsets.equals(w.mContentInsets);
10308 w.mVisibleInsetsChanged =
10309 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010310 boolean configChanged =
10311 w.mConfiguration != mCurConfiguration
10312 && (w.mConfiguration == null
10313 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010314 if (DEBUG_CONFIGURATION && configChanged) {
10315 Slog.v(TAG, "Win " + w + " config changed: "
10316 + mCurConfiguration);
10317 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010318 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010319 + ": configChanged=" + configChanged
10320 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010321 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010322 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010323 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010324 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010325 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010326 w.mLastFrame.set(w.mFrame);
10327 w.mLastContentInsets.set(w.mContentInsets);
10328 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010329 // If the screen is currently frozen, then keep
10330 // it frozen until this window draws at its new
10331 // orientation.
10332 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010333 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010334 "Resizing while display frozen: " + w);
10335 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010336 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010337 mWindowsFreezingScreen = true;
10338 // XXX should probably keep timeout from
10339 // when we first froze the display.
10340 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10341 mH.sendMessageDelayed(mH.obtainMessage(
10342 H.WINDOW_FREEZE_TIMEOUT), 2000);
10343 }
10344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010345 // If the orientation is changing, then we need to
10346 // hold off on unfreezing the display until this
10347 // window has been redrawn; to do that, we need
10348 // to go through the process of getting informed
10349 // by the application when it has finished drawing.
10350 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010351 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010352 "Orientation start waiting for draw in "
10353 + w + ", surface " + w.mSurface);
10354 w.mDrawPending = true;
10355 w.mCommitDrawPending = false;
10356 w.mReadyToShow = false;
10357 if (w.mAppToken != null) {
10358 w.mAppToken.allDrawn = false;
10359 }
10360 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010361 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010362 "Resizing window " + w + " to " + w.mFrame);
10363 mResizingWindows.add(w);
10364 } else if (w.mOrientationChanging) {
10365 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010366 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 "Orientation not waiting for draw in "
10368 + w + ", surface " + w.mSurface);
10369 w.mOrientationChanging = false;
10370 }
10371 }
10372 }
10373
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010374 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010375 if (!w.mLastHidden) {
10376 //dump();
10377 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010378 if (SHOW_TRANSACTIONS) logSurface(w,
10379 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010380 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010381 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010382 try {
10383 w.mSurface.hide();
10384 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010385 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010386 }
10387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010388 }
10389 // If we are waiting for this window to handle an
10390 // orientation change, well, it is hidden, so
10391 // doesn't really matter. Note that this does
10392 // introduce a potential glitch if the window
10393 // becomes unhidden before it has drawn for the
10394 // new orientation.
10395 if (w.mOrientationChanging) {
10396 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010397 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 "Orientation change skips hidden " + w);
10399 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010400 } else if (w.mLastLayer != w.mAnimLayer
10401 || w.mLastAlpha != w.mShownAlpha
10402 || w.mLastDsDx != w.mDsDx
10403 || w.mLastDtDx != w.mDtDx
10404 || w.mLastDsDy != w.mDsDy
10405 || w.mLastDtDy != w.mDtDy
10406 || w.mLastHScale != w.mHScale
10407 || w.mLastVScale != w.mVScale
10408 || w.mLastHidden) {
10409 displayed = true;
10410 w.mLastAlpha = w.mShownAlpha;
10411 w.mLastLayer = w.mAnimLayer;
10412 w.mLastDsDx = w.mDsDx;
10413 w.mLastDtDx = w.mDtDx;
10414 w.mLastDsDy = w.mDsDy;
10415 w.mLastDtDy = w.mDtDy;
10416 w.mLastHScale = w.mHScale;
10417 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010418 if (SHOW_TRANSACTIONS) logSurface(w,
10419 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010420 + " matrix=[" + (w.mDsDx*w.mHScale)
10421 + "," + (w.mDtDx*w.mVScale)
10422 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010423 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010424 if (w.mSurface != null) {
10425 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010426 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010428 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429 w.mSurface.setLayer(w.mAnimLayer);
10430 w.mSurface.setMatrix(
10431 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10432 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10433 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010434 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 if (!recoveringMemory) {
10436 reclaimSomeSurfaceMemoryLocked(w, "update");
10437 }
10438 }
10439 }
10440
10441 if (w.mLastHidden && !w.mDrawPending
10442 && !w.mCommitDrawPending
10443 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010444 if (SHOW_TRANSACTIONS) logSurface(w,
10445 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010446 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010447 + " during relayout");
10448 if (showSurfaceRobustlyLocked(w)) {
10449 w.mHasDrawn = true;
10450 w.mLastHidden = false;
10451 } else {
10452 w.mOrientationChanging = false;
10453 }
10454 }
10455 if (w.mSurface != null) {
10456 w.mToken.hasVisible = true;
10457 }
10458 } else {
10459 displayed = true;
10460 }
10461
10462 if (displayed) {
10463 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010464 if (attrs.width == LayoutParams.MATCH_PARENT
10465 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 covered = true;
10467 }
10468 }
10469 if (w.mOrientationChanging) {
10470 if (w.mDrawPending || w.mCommitDrawPending) {
10471 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010472 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 "Orientation continue waiting for draw in " + w);
10474 } else {
10475 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010476 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 "Orientation change complete in " + w);
10478 }
10479 }
10480 w.mToken.hasVisible = true;
10481 }
10482 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010483 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010484 "Orientation change skips hidden " + w);
10485 w.mOrientationChanging = false;
10486 }
10487
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010488 if (w.mContentChanged) {
10489 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10490 w.mContentChanged = false;
10491 }
10492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 final boolean canBeSeen = w.isDisplayedLw();
10494
10495 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10496 focusDisplayed = true;
10497 }
10498
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010499 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010502 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010503 if (w.mSurface != null) {
10504 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10505 holdScreen = w.mSession;
10506 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010507 if (!syswin && w.mAttrs.screenBrightness >= 0
10508 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509 screenBrightness = w.mAttrs.screenBrightness;
10510 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010511 if (!syswin && w.mAttrs.buttonBrightness >= 0
10512 && buttonBrightness < 0) {
10513 buttonBrightness = w.mAttrs.buttonBrightness;
10514 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010515 if (canBeSeen
10516 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10517 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10518 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010519 syswin = true;
10520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010521 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010522
Dianne Hackborn25994b42009-09-04 14:21:19 -070010523 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10524 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 // This window completely covers everything behind it,
10526 // so we want to leave all of them as unblurred (for
10527 // performance reasons).
10528 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010529 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010530 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010531 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010532 obscured = true;
10533 if (mBackgroundFillerSurface == null) {
10534 try {
10535 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010536 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010537 0, dw, dh,
10538 PixelFormat.OPAQUE,
10539 Surface.FX_SURFACE_NORMAL);
10540 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010541 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010542 }
10543 }
10544 try {
10545 mBackgroundFillerSurface.setPosition(0, 0);
10546 mBackgroundFillerSurface.setSize(dw, dh);
10547 // Using the same layer as Dim because they will never be shown at the
10548 // same time.
10549 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10550 mBackgroundFillerSurface.show();
10551 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010552 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010553 }
10554 backgroundFillerShown = true;
10555 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010556 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010557 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010558 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010559 + ": blurring=" + blurring
10560 + " obscured=" + obscured
10561 + " displayed=" + displayed);
10562 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10563 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010564 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010565 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010566 if (mDimAnimator == null) {
10567 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010568 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010569 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010570 mDimAnimator.updateParameters(mContext.getResources(),
10571 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 }
10574 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10575 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010576 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010577 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010578 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010579 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010580 + mBlurSurface + ": CREATE");
10581 try {
Romain Guy06882f82009-06-10 13:36:04 -070010582 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010583 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010584 -1, 16, 16,
10585 PixelFormat.OPAQUE,
10586 Surface.FX_SURFACE_BLUR);
10587 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010588 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010589 }
10590 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010591 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010592 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10593 + mBlurSurface + ": pos=(0,0) (" +
10594 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010595 mBlurSurface.setPosition(0, 0);
10596 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010597 mBlurSurface.setLayer(w.mAnimLayer-2);
10598 if (!mBlurShown) {
10599 try {
10600 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10601 + mBlurSurface + ": SHOW");
10602 mBlurSurface.show();
10603 } catch (RuntimeException e) {
10604 Slog.w(TAG, "Failure showing blur surface", e);
10605 }
10606 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010607 }
10608 }
10609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010610 }
10611 }
10612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010613
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010614 if (obscuredChanged && mWallpaperTarget == w) {
10615 // This is the wallpaper target and its obscured state
10616 // changed... make sure the current wallaper's visibility
10617 // has been updated accordingly.
10618 updateWallpaperVisibilityLocked();
10619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010621
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010622 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10623 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010624 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010625 try {
10626 mBackgroundFillerSurface.hide();
10627 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010628 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010629 }
10630 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010631
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010632 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010633 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10634 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010635 }
Romain Guy06882f82009-06-10 13:36:04 -070010636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010637 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010638 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010639 + ": HIDE");
10640 try {
10641 mBlurSurface.hide();
10642 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010643 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010644 }
10645 mBlurShown = false;
10646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010648 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010649 }
10650
Jeff Browne33348b2010-07-15 23:54:05 -070010651 mInputMonitor.updateInputWindowsLw();
10652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010653 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010654
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010655 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10656
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010657 if (mWatermark != null) {
10658 mWatermark.drawIfNeeded();
10659 }
10660
Joe Onorato8a9b2202010-02-26 18:56:32 -080010661 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662 "With display frozen, orientationChangeComplete="
10663 + orientationChangeComplete);
10664 if (orientationChangeComplete) {
10665 if (mWindowsFreezingScreen) {
10666 mWindowsFreezingScreen = false;
10667 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10668 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010669 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010670 }
Romain Guy06882f82009-06-10 13:36:04 -070010671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010672 i = mResizingWindows.size();
10673 if (i > 0) {
10674 do {
10675 i--;
10676 WindowState win = mResizingWindows.get(i);
10677 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010678 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10679 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010680 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010681 boolean configChanged =
10682 win.mConfiguration != mCurConfiguration
10683 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010684 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10685 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10686 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010687 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010688 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010689 + " / " + mCurConfiguration + " / 0x"
10690 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010691 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010692 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010693 win.mClient.resized(win.mFrame.width(),
10694 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010695 win.mLastVisibleInsets, win.mDrawPending,
10696 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010697 win.mContentInsetsChanged = false;
10698 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010699 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010700 } catch (RemoteException e) {
10701 win.mOrientationChanging = false;
10702 }
10703 } while (i > 0);
10704 mResizingWindows.clear();
10705 }
Romain Guy06882f82009-06-10 13:36:04 -070010706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010707 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010708 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010709 i = mDestroySurface.size();
10710 if (i > 0) {
10711 do {
10712 i--;
10713 WindowState win = mDestroySurface.get(i);
10714 win.mDestroying = false;
10715 if (mInputMethodWindow == win) {
10716 mInputMethodWindow = null;
10717 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010718 if (win == mWallpaperTarget) {
10719 wallpaperDestroyed = true;
10720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010721 win.destroySurfaceLocked();
10722 } while (i > 0);
10723 mDestroySurface.clear();
10724 }
10725
10726 // Time to remove any exiting tokens?
10727 for (i=mExitingTokens.size()-1; i>=0; i--) {
10728 WindowToken token = mExitingTokens.get(i);
10729 if (!token.hasVisible) {
10730 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010731 if (token.windowType == TYPE_WALLPAPER) {
10732 mWallpaperTokens.remove(token);
10733 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010734 }
10735 }
10736
10737 // Time to remove any exiting applications?
10738 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10739 AppWindowToken token = mExitingAppTokens.get(i);
10740 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010741 // Make sure there is no animation running on this token,
10742 // so any windows associated with it will be removed as
10743 // soon as their animations are complete
10744 token.animation = null;
10745 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010746 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10747 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010748 mAppTokens.remove(token);
10749 mExitingAppTokens.remove(i);
10750 }
10751 }
10752
Dianne Hackborna8f60182009-09-01 19:01:50 -070010753 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010754
Dianne Hackborna8f60182009-09-01 19:01:50 -070010755 if (!animating && mAppTransitionRunning) {
10756 // We have finished the animation of an app transition. To do
10757 // this, we have delayed a lot of operations like showing and
10758 // hiding apps, moving apps in Z-order, etc. The app token list
10759 // reflects the correct Z-order, but the window list may now
10760 // be out of sync with it. So here we will just rebuild the
10761 // entire app window list. Fun!
10762 mAppTransitionRunning = false;
10763 needRelayout = true;
10764 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010765 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010766 // Clear information about apps that were moving.
10767 mToBottomApps.clear();
10768 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770 if (focusDisplayed) {
10771 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10772 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010773 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010774 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010775 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010776 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010777 requestAnimationLocked(0);
10778 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10780 }
Jeff Browneb857f12010-07-16 10:06:33 -070010781
Jeff Browne33348b2010-07-15 23:54:05 -070010782 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010783
Jeff Brown8e03b752010-06-13 19:16:55 -070010784 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10786 mPowerManager.setScreenBrightnessOverride(-1);
10787 } else {
10788 mPowerManager.setScreenBrightnessOverride((int)
10789 (screenBrightness * Power.BRIGHTNESS_ON));
10790 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010791 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10792 mPowerManager.setButtonBrightnessOverride(-1);
10793 } else {
10794 mPowerManager.setButtonBrightnessOverride((int)
10795 (buttonBrightness * Power.BRIGHTNESS_ON));
10796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 if (holdScreen != mHoldingScreenOn) {
10798 mHoldingScreenOn = holdScreen;
10799 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10800 mH.sendMessage(m);
10801 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010802
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010803 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010804 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010805 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10806 LocalPowerManager.BUTTON_EVENT, true);
10807 mTurnOnScreen = false;
10808 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010809
10810 // Check to see if we are now in a state where the screen should
10811 // be enabled, because the window obscured flags have changed.
10812 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010813 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010814
10815 /**
10816 * Must be called with the main window manager lock held.
10817 */
10818 void setHoldScreenLocked(boolean holding) {
10819 boolean state = mHoldingScreenWakeLock.isHeld();
10820 if (holding != state) {
10821 if (holding) {
10822 mHoldingScreenWakeLock.acquire();
10823 } else {
10824 mPolicy.screenOnStoppedLw();
10825 mHoldingScreenWakeLock.release();
10826 }
10827 }
10828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010829
10830 void requestAnimationLocked(long delay) {
10831 if (!mAnimationPending) {
10832 mAnimationPending = true;
10833 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10834 }
10835 }
Romain Guy06882f82009-06-10 13:36:04 -070010836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010837 /**
10838 * Have the surface flinger show a surface, robustly dealing with
10839 * error conditions. In particular, if there is not enough memory
10840 * to show the surface, then we will try to get rid of other surfaces
10841 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010842 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010843 * @return Returns true if the surface was successfully shown.
10844 */
10845 boolean showSurfaceRobustlyLocked(WindowState win) {
10846 try {
10847 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010848 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010849 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010850 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010851 if (DEBUG_VISIBILITY) Slog.v(TAG,
10852 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010853 win.mTurnOnScreen = false;
10854 mTurnOnScreen = true;
10855 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010856 }
10857 return true;
10858 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010859 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010860 }
Romain Guy06882f82009-06-10 13:36:04 -070010861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010862 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010864 return false;
10865 }
Romain Guy06882f82009-06-10 13:36:04 -070010866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010867 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10868 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010869
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010870 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010871 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010873 if (mForceRemoves == null) {
10874 mForceRemoves = new ArrayList<WindowState>();
10875 }
Romain Guy06882f82009-06-10 13:36:04 -070010876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010877 long callingIdentity = Binder.clearCallingIdentity();
10878 try {
10879 // There was some problem... first, do a sanity check of the
10880 // window list to make sure we haven't left any dangling surfaces
10881 // around.
10882 int N = mWindows.size();
10883 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010884 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010885 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010886 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010887 if (ws.mSurface != null) {
10888 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010889 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010890 + ws + " surface=" + ws.mSurface
10891 + " token=" + win.mToken
10892 + " pid=" + ws.mSession.mPid
10893 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010894 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010895 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010896 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010897 ws.mSurface = null;
10898 mForceRemoves.add(ws);
10899 i--;
10900 N--;
10901 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010902 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010903 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904 + ws + " surface=" + ws.mSurface
10905 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010906 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010907 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010908 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010909 ws.mSurface = null;
10910 leakedSurface = true;
10911 }
10912 }
10913 }
Romain Guy06882f82009-06-10 13:36:04 -070010914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010915 boolean killedApps = false;
10916 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010917 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010918 SparseIntArray pidCandidates = new SparseIntArray();
10919 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010920 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010921 if (ws.mSurface != null) {
10922 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10923 }
10924 }
10925 if (pidCandidates.size() > 0) {
10926 int[] pids = new int[pidCandidates.size()];
10927 for (int i=0; i<pids.length; i++) {
10928 pids[i] = pidCandidates.keyAt(i);
10929 }
10930 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010931 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010932 killedApps = true;
10933 }
10934 } catch (RemoteException e) {
10935 }
10936 }
10937 }
Romain Guy06882f82009-06-10 13:36:04 -070010938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 if (leakedSurface || killedApps) {
10940 // We managed to reclaim some memory, so get rid of the trouble
10941 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010942 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010943 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010944 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010945 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010946 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010947 win.mSurface = null;
10948 }
Romain Guy06882f82009-06-10 13:36:04 -070010949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010950 try {
10951 win.mClient.dispatchGetNewSurface();
10952 } catch (RemoteException e) {
10953 }
10954 }
10955 } finally {
10956 Binder.restoreCallingIdentity(callingIdentity);
10957 }
10958 }
Romain Guy06882f82009-06-10 13:36:04 -070010959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010960 private boolean updateFocusedWindowLocked(int mode) {
10961 WindowState newFocus = computeFocusedWindowLocked();
10962 if (mCurrentFocus != newFocus) {
10963 // This check makes sure that we don't already have the focus
10964 // change message pending.
10965 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10966 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010967 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010968 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10969 final WindowState oldFocus = mCurrentFocus;
10970 mCurrentFocus = newFocus;
10971 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010973 final WindowState imWindow = mInputMethodWindow;
10974 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010975 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010976 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010977 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10978 mLayoutNeeded = true;
10979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -080010981 performLayoutLockedInner(true);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010982 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10983 // Client will do the layout, but we need to assign layers
10984 // for handleNewWindowLocked() below.
10985 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010986 }
10987 }
Jeff Brown349703e2010-06-22 01:27:15 -070010988
10989 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10990 // If we defer assigning layers, then the caller is responsible for
10991 // doing this part.
10992 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010993 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010994 return true;
10995 }
10996 return false;
10997 }
Jeff Brown349703e2010-06-22 01:27:15 -070010998
10999 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011000 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070011001 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011002
11003 private WindowState computeFocusedWindowLocked() {
11004 WindowState result = null;
11005 WindowState win;
11006
11007 int i = mWindows.size() - 1;
11008 int nextAppIndex = mAppTokens.size()-1;
11009 WindowToken nextApp = nextAppIndex >= 0
11010 ? mAppTokens.get(nextAppIndex) : null;
11011
11012 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011013 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011014
Joe Onorato8a9b2202010-02-26 18:56:32 -080011015 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011016 TAG, "Looking for focus: " + i
11017 + " = " + win
11018 + ", flags=" + win.mAttrs.flags
11019 + ", canReceive=" + win.canReceiveKeys());
11020
11021 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011023 // If this window's application has been removed, just skip it.
11024 if (thisApp != null && thisApp.removed) {
11025 i--;
11026 continue;
11027 }
Romain Guy06882f82009-06-10 13:36:04 -070011028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011029 // If there is a focused app, don't allow focus to go to any
11030 // windows below it. If this is an application window, step
11031 // through the app tokens until we find its app.
11032 if (thisApp != null && nextApp != null && thisApp != nextApp
11033 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11034 int origAppIndex = nextAppIndex;
11035 while (nextAppIndex > 0) {
11036 if (nextApp == mFocusedApp) {
11037 // Whoops, we are below the focused app... no focus
11038 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011039 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011040 TAG, "Reached focused app: " + mFocusedApp);
11041 return null;
11042 }
11043 nextAppIndex--;
11044 nextApp = mAppTokens.get(nextAppIndex);
11045 if (nextApp == thisApp) {
11046 break;
11047 }
11048 }
11049 if (thisApp != nextApp) {
11050 // Uh oh, the app token doesn't exist! This shouldn't
11051 // happen, but if it does we can get totally hosed...
11052 // so restart at the original app.
11053 nextAppIndex = origAppIndex;
11054 nextApp = mAppTokens.get(nextAppIndex);
11055 }
11056 }
11057
11058 // Dispatch to this window if it is wants key events.
11059 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011060 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011061 TAG, "Found focus @ " + i + " = " + win);
11062 result = win;
11063 break;
11064 }
11065
11066 i--;
11067 }
11068
11069 return result;
11070 }
11071
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011072 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011073 if (mDisplayFrozen) {
11074 return;
11075 }
Romain Guy06882f82009-06-10 13:36:04 -070011076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011077 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011079 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011080 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011081 if (mFreezeGcPending != 0) {
11082 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011083 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011084 mH.removeMessages(H.FORCE_GC);
11085 Runtime.getRuntime().gc();
11086 mFreezeGcPending = now;
11087 }
11088 } else {
11089 mFreezeGcPending = now;
11090 }
Romain Guy06882f82009-06-10 13:36:04 -070011091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011092 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011093
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011094 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011095
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011096 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11097 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011098 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011099 mAppTransitionReady = true;
11100 }
Romain Guy06882f82009-06-10 13:36:04 -070011101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011102 if (PROFILE_ORIENTATION) {
11103 File file = new File("/data/system/frozen");
11104 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11105 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011106
11107 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011108 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11109 mScreenRotationAnimation.kill();
11110 mScreenRotationAnimation = null;
11111 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011112 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011113 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011114 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011115 }
11116 } else {
11117 Surface.freezeDisplay(0);
11118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011119 }
Romain Guy06882f82009-06-10 13:36:04 -070011120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011121 private void stopFreezingDisplayLocked() {
11122 if (!mDisplayFrozen) {
11123 return;
11124 }
Romain Guy06882f82009-06-10 13:36:04 -070011125
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011126 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11127 return;
11128 }
11129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011130 mDisplayFrozen = false;
11131 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11132 if (PROFILE_ORIENTATION) {
11133 Debug.stopMethodTracing();
11134 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011135
11136 if (CUSTOM_SCREEN_ROTATION) {
11137 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011138 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11139 mTransitionAnimationScale)) {
11140 requestAnimationLocked(0);
11141 } else {
11142 mScreenRotationAnimation = null;
11143 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011144 }
11145 } else {
11146 Surface.unfreezeDisplay(0);
11147 }
Romain Guy06882f82009-06-10 13:36:04 -070011148
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011149 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011150
Christopher Tateb696aee2010-04-02 19:08:30 -070011151 // While the display is frozen we don't re-compute the orientation
11152 // to avoid inconsistent states. However, something interesting
11153 // could have actually changed during that time so re-evaluate it
11154 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011155 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011156 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11157 }
11158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011159 // A little kludge: a lot could have happened while the
11160 // display was frozen, so now that we are coming back we
11161 // do a gc so that any remote references the system
11162 // processes holds on others can be released if they are
11163 // no longer needed.
11164 mH.removeMessages(H.FORCE_GC);
11165 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11166 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011168 mScreenFrozenLock.release();
11169 }
Romain Guy06882f82009-06-10 13:36:04 -070011170
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011171 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11172 DisplayMetrics dm) {
11173 if (index < tokens.length) {
11174 String str = tokens[index];
11175 if (str != null && str.length() > 0) {
11176 try {
11177 int val = Integer.parseInt(str);
11178 return val;
11179 } catch (Exception e) {
11180 }
11181 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011182 }
11183 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11184 return defDps;
11185 }
11186 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11187 return val;
11188 }
11189
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011190 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011191 final String[] mTokens;
11192 final String mText;
11193 final Paint mTextPaint;
11194 final int mTextWidth;
11195 final int mTextHeight;
11196 final int mTextAscent;
11197 final int mTextDescent;
11198 final int mDeltaX;
11199 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011200
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011201 Surface mSurface;
11202 int mLastDW;
11203 int mLastDH;
11204 boolean mDrawNeeded;
11205
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011206 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011207 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011208 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011209
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011210 if (false) {
11211 Log.i(TAG, "*********************** WATERMARK");
11212 for (int i=0; i<tokens.length; i++) {
11213 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11214 }
11215 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011216
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011217 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011218
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011219 StringBuilder builder = new StringBuilder(32);
11220 int len = mTokens[0].length();
11221 len = len & ~1;
11222 for (int i=0; i<len; i+=2) {
11223 int c1 = mTokens[0].charAt(i);
11224 int c2 = mTokens[0].charAt(i+1);
11225 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11226 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11227 else c1 -= '0';
11228 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11229 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11230 else c2 -= '0';
11231 builder.append((char)(255-((c1*16)+c2)));
11232 }
11233 mText = builder.toString();
11234 if (false) {
11235 Log.i(TAG, "Final text: " + mText);
11236 }
11237
11238 int fontSize = getPropertyInt(tokens, 1,
11239 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11240
11241 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11242 mTextPaint.setTextSize(fontSize);
11243 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11244
11245 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11246 mTextWidth = (int)mTextPaint.measureText(mText);
11247 mTextAscent = fm.ascent;
11248 mTextDescent = fm.descent;
11249 mTextHeight = fm.descent - fm.ascent;
11250
11251 mDeltaX = getPropertyInt(tokens, 2,
11252 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11253 mDeltaY = getPropertyInt(tokens, 3,
11254 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11255 int shadowColor = getPropertyInt(tokens, 4,
11256 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11257 int color = getPropertyInt(tokens, 5,
11258 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11259 int shadowRadius = getPropertyInt(tokens, 6,
11260 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11261 int shadowDx = getPropertyInt(tokens, 8,
11262 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11263 int shadowDy = getPropertyInt(tokens, 9,
11264 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11265
11266 mTextPaint.setColor(color);
11267 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011268
11269 try {
11270 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011271 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011272 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011273 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011274 mSurface.show();
11275 } catch (OutOfResourcesException e) {
11276 }
11277 }
11278
11279 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011280 if (mLastDW != dw || mLastDH != dh) {
11281 mLastDW = dw;
11282 mLastDH = dh;
11283 mSurface.setSize(dw, dh);
11284 mDrawNeeded = true;
11285 }
11286 }
11287
11288 void drawIfNeeded() {
11289 if (mDrawNeeded) {
11290 final int dw = mLastDW;
11291 final int dh = mLastDH;
11292
11293 mDrawNeeded = false;
11294 Rect dirty = new Rect(0, 0, dw, dh);
11295 Canvas c = null;
11296 try {
11297 c = mSurface.lockCanvas(dirty);
11298 } catch (IllegalArgumentException e) {
11299 } catch (OutOfResourcesException e) {
11300 }
11301 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011302 c.drawColor(0, PorterDuff.Mode.CLEAR);
11303
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011304 int deltaX = mDeltaX;
11305 int deltaY = mDeltaY;
11306
11307 // deltaX shouldn't be close to a round fraction of our
11308 // x step, or else things will line up too much.
11309 int div = (dw+mTextWidth)/deltaX;
11310 int rem = (dw+mTextWidth) - (div*deltaX);
11311 int qdelta = deltaX/4;
11312 if (rem < qdelta || rem > (deltaX-qdelta)) {
11313 deltaX += deltaX/3;
11314 }
11315
11316 int y = -mTextHeight;
11317 int x = -mTextWidth;
11318 while (y < (dh+mTextHeight)) {
11319 c.drawText(mText, x, y, mTextPaint);
11320 x += deltaX;
11321 if (x >= dw) {
11322 x -= (dw+mTextWidth);
11323 y += deltaY;
11324 }
11325 }
11326 mSurface.unlockCanvasAndPost(c);
11327 }
11328 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011329 }
11330 }
11331
11332 void createWatermark() {
11333 if (mWatermark != null) {
11334 return;
11335 }
11336
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011337 File file = new File("/system/etc/setup.conf");
11338 FileInputStream in = null;
11339 try {
11340 in = new FileInputStream(file);
11341 DataInputStream ind = new DataInputStream(in);
11342 String line = ind.readLine();
11343 if (line != null) {
11344 String[] toks = line.split("%");
11345 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011346 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011347 }
11348 }
11349 } catch (FileNotFoundException e) {
11350 } catch (IOException e) {
11351 } finally {
11352 if (in != null) {
11353 try {
11354 in.close();
11355 } catch (IOException e) {
11356 }
11357 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011358 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011359 }
11360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011361 @Override
11362 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11363 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11364 != PackageManager.PERMISSION_GRANTED) {
11365 pw.println("Permission Denial: can't dump WindowManager from from pid="
11366 + Binder.getCallingPid()
11367 + ", uid=" + Binder.getCallingUid());
11368 return;
11369 }
Romain Guy06882f82009-06-10 13:36:04 -070011370
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011371 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011372 pw.println(" ");
11373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011374 synchronized(mWindowMap) {
11375 pw.println("Current Window Manager state:");
11376 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011377 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011378 pw.print(" Window #"); pw.print(i); pw.print(' ');
11379 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011380 w.dump(pw, " ");
11381 }
11382 if (mInputMethodDialogs.size() > 0) {
11383 pw.println(" ");
11384 pw.println(" Input method dialogs:");
11385 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11386 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011387 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011388 }
11389 }
11390 if (mPendingRemove.size() > 0) {
11391 pw.println(" ");
11392 pw.println(" Remove pending for:");
11393 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11394 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011395 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11396 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011397 w.dump(pw, " ");
11398 }
11399 }
11400 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11401 pw.println(" ");
11402 pw.println(" Windows force removing:");
11403 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11404 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011405 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11406 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011407 w.dump(pw, " ");
11408 }
11409 }
11410 if (mDestroySurface.size() > 0) {
11411 pw.println(" ");
11412 pw.println(" Windows waiting to destroy their surface:");
11413 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11414 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011415 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11416 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011417 w.dump(pw, " ");
11418 }
11419 }
11420 if (mLosingFocus.size() > 0) {
11421 pw.println(" ");
11422 pw.println(" Windows losing focus:");
11423 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11424 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011425 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11426 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011427 w.dump(pw, " ");
11428 }
11429 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011430 if (mResizingWindows.size() > 0) {
11431 pw.println(" ");
11432 pw.println(" Windows waiting to resize:");
11433 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11434 WindowState w = mResizingWindows.get(i);
11435 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11436 pw.print(w); pw.println(":");
11437 w.dump(pw, " ");
11438 }
11439 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011440 if (mSessions.size() > 0) {
11441 pw.println(" ");
11442 pw.println(" All active sessions:");
11443 Iterator<Session> it = mSessions.iterator();
11444 while (it.hasNext()) {
11445 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011446 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011447 s.dump(pw, " ");
11448 }
11449 }
11450 if (mTokenMap.size() > 0) {
11451 pw.println(" ");
11452 pw.println(" All tokens:");
11453 Iterator<WindowToken> it = mTokenMap.values().iterator();
11454 while (it.hasNext()) {
11455 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011456 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011457 token.dump(pw, " ");
11458 }
11459 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011460 if (mWallpaperTokens.size() > 0) {
11461 pw.println(" ");
11462 pw.println(" Wallpaper tokens:");
11463 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11464 WindowToken token = mWallpaperTokens.get(i);
11465 pw.print(" Wallpaper #"); pw.print(i);
11466 pw.print(' '); pw.print(token); pw.println(':');
11467 token.dump(pw, " ");
11468 }
11469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011470 if (mAppTokens.size() > 0) {
11471 pw.println(" ");
11472 pw.println(" Application tokens in Z order:");
11473 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011474 pw.print(" App #"); pw.print(i); pw.print(": ");
11475 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011476 }
11477 }
11478 if (mFinishedStarting.size() > 0) {
11479 pw.println(" ");
11480 pw.println(" Finishing start of application tokens:");
11481 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11482 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011483 pw.print(" Finished Starting #"); pw.print(i);
11484 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011485 token.dump(pw, " ");
11486 }
11487 }
11488 if (mExitingTokens.size() > 0) {
11489 pw.println(" ");
11490 pw.println(" Exiting tokens:");
11491 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11492 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011493 pw.print(" Exiting #"); pw.print(i);
11494 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011495 token.dump(pw, " ");
11496 }
11497 }
11498 if (mExitingAppTokens.size() > 0) {
11499 pw.println(" ");
11500 pw.println(" Exiting application tokens:");
11501 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11502 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011503 pw.print(" Exiting App #"); pw.print(i);
11504 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011505 token.dump(pw, " ");
11506 }
11507 }
11508 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011509 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11510 pw.print(" mLastFocus="); pw.println(mLastFocus);
11511 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11512 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11513 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011514 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011515 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11516 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11517 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11518 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011519 if (mWindowDetachedWallpaper != null) {
11520 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11521 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011522 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11523 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11524 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011525 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11526 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11527 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11528 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011529 if (mDimAnimator != null) {
11530 mDimAnimator.printTo(pw);
11531 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011532 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011533 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011534 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011535 pw.print(mInputMethodAnimLayerAdjustment);
11536 pw.print(" mWallpaperAnimLayerAdjustment=");
11537 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011538 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11539 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011540 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11541 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011542 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11543 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011544 pw.print(" mRotation="); pw.print(mRotation);
11545 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11546 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11547 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11548 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11549 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11550 pw.print(" mNextAppTransition=0x");
11551 pw.print(Integer.toHexString(mNextAppTransition));
11552 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011553 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011554 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011555 if (mNextAppTransitionPackage != null) {
11556 pw.print(" mNextAppTransitionPackage=");
11557 pw.print(mNextAppTransitionPackage);
11558 pw.print(", mNextAppTransitionEnter=0x");
11559 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11560 pw.print(", mNextAppTransitionExit=0x");
11561 pw.print(Integer.toHexString(mNextAppTransitionExit));
11562 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011563 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11564 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11565 if (mOpeningApps.size() > 0) {
11566 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11567 }
11568 if (mClosingApps.size() > 0) {
11569 pw.print(" mClosingApps="); pw.println(mClosingApps);
11570 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011571 if (mToTopApps.size() > 0) {
11572 pw.print(" mToTopApps="); pw.println(mToTopApps);
11573 }
11574 if (mToBottomApps.size() > 0) {
11575 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11576 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011577 if (mDisplay != null) {
11578 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11579 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11580 } else {
11581 pw.println(" NO DISPLAY");
11582 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011583 pw.println(" Policy:");
11584 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011585 }
11586 }
11587
Jeff Brown349703e2010-06-22 01:27:15 -070011588 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011589 public void monitor() {
11590 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011591 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011593
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011594 /**
11595 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011596 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011597 */
11598 private static class DimAnimator {
11599 Surface mDimSurface;
11600 boolean mDimShown = false;
11601 float mDimCurrentAlpha;
11602 float mDimTargetAlpha;
11603 float mDimDeltaPerMs;
11604 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011605
11606 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011607
11608 DimAnimator (SurfaceSession session) {
11609 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011610 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011611 + mDimSurface + ": CREATE");
11612 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011613 mDimSurface = new Surface(session, 0,
11614 "DimSurface",
11615 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011616 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011617 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011618 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011619 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011620 }
11621 }
11622 }
11623
11624 /**
11625 * Show the dim surface.
11626 */
11627 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011628 if (!mDimShown) {
11629 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11630 dw + "x" + dh + ")");
11631 mDimShown = true;
11632 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011633 mLastDimWidth = dw;
11634 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011635 mDimSurface.setPosition(0, 0);
11636 mDimSurface.setSize(dw, dh);
11637 mDimSurface.show();
11638 } catch (RuntimeException e) {
11639 Slog.w(TAG, "Failure showing dim surface", e);
11640 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011641 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11642 mLastDimWidth = dw;
11643 mLastDimHeight = dh;
11644 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011645 }
11646 }
11647
11648 /**
11649 * Set's the dim surface's layer and update dim parameters that will be used in
11650 * {@link updateSurface} after all windows are examined.
11651 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011652 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011653 mDimSurface.setLayer(w.mAnimLayer-1);
11654
11655 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011656 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011657 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011658 if (mDimTargetAlpha != target) {
11659 // If the desired dim level has changed, then
11660 // start an animation to it.
11661 mLastDimAnimTime = currentTime;
11662 long duration = (w.mAnimating && w.mAnimation != null)
11663 ? w.mAnimation.computeDurationHint()
11664 : DEFAULT_DIM_DURATION;
11665 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011666 TypedValue tv = new TypedValue();
11667 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11668 tv, true);
11669 if (tv.type == TypedValue.TYPE_FRACTION) {
11670 duration = (long)tv.getFraction((float)duration, (float)duration);
11671 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11672 && tv.type <= TypedValue.TYPE_LAST_INT) {
11673 duration = tv.data;
11674 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011675 }
11676 if (duration < 1) {
11677 // Don't divide by zero
11678 duration = 1;
11679 }
11680 mDimTargetAlpha = target;
11681 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11682 }
11683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011684
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011685 /**
11686 * Updating the surface's alpha. Returns true if the animation continues, or returns
11687 * false when the animation is finished and the dim surface is hidden.
11688 */
11689 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11690 if (!dimming) {
11691 if (mDimTargetAlpha != 0) {
11692 mLastDimAnimTime = currentTime;
11693 mDimTargetAlpha = 0;
11694 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11695 }
11696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011697
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011698 boolean animating = false;
11699 if (mLastDimAnimTime != 0) {
11700 mDimCurrentAlpha += mDimDeltaPerMs
11701 * (currentTime-mLastDimAnimTime);
11702 boolean more = true;
11703 if (displayFrozen) {
11704 // If the display is frozen, there is no reason to animate.
11705 more = false;
11706 } else if (mDimDeltaPerMs > 0) {
11707 if (mDimCurrentAlpha > mDimTargetAlpha) {
11708 more = false;
11709 }
11710 } else if (mDimDeltaPerMs < 0) {
11711 if (mDimCurrentAlpha < mDimTargetAlpha) {
11712 more = false;
11713 }
11714 } else {
11715 more = false;
11716 }
11717
11718 // Do we need to continue animating?
11719 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011720 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011721 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11722 mLastDimAnimTime = currentTime;
11723 mDimSurface.setAlpha(mDimCurrentAlpha);
11724 animating = true;
11725 } else {
11726 mDimCurrentAlpha = mDimTargetAlpha;
11727 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011728 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011729 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11730 mDimSurface.setAlpha(mDimCurrentAlpha);
11731 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011732 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011733 + ": HIDE");
11734 try {
11735 mDimSurface.hide();
11736 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011737 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011738 }
11739 mDimShown = false;
11740 }
11741 }
11742 }
11743 return animating;
11744 }
11745
11746 public void printTo(PrintWriter pw) {
11747 pw.print(" mDimShown="); pw.print(mDimShown);
11748 pw.print(" current="); pw.print(mDimCurrentAlpha);
11749 pw.print(" target="); pw.print(mDimTargetAlpha);
11750 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11751 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11752 }
11753 }
11754
11755 /**
11756 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11757 * This is used for opening/closing transition for apps in compatible mode.
11758 */
11759 private static class FadeInOutAnimation extends Animation {
11760 int mWidth;
11761 boolean mFadeIn;
11762
11763 public FadeInOutAnimation(boolean fadeIn) {
11764 setInterpolator(new AccelerateInterpolator());
11765 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11766 mFadeIn = fadeIn;
11767 }
11768
11769 @Override
11770 protected void applyTransformation(float interpolatedTime, Transformation t) {
11771 float x = interpolatedTime;
11772 if (!mFadeIn) {
11773 x = 1.0f - x; // reverse the interpolation for fade out
11774 }
11775 if (x < 0.5) {
11776 // move the window out of the screen.
11777 t.getMatrix().setTranslate(mWidth, 0);
11778 } else {
11779 t.getMatrix().setTranslate(0, 0);// show
11780 t.setAlpha((x - 0.5f) * 2);
11781 }
11782 }
11783
11784 @Override
11785 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11786 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11787 mWidth = width;
11788 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011789
11790 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011791 public int getZAdjustment() {
11792 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011793 }
11794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011795}