blob: 779e0ad03e65e507d86849671c1025246832dfd3 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
32import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070035import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37import com.android.internal.app.IBatteryStats;
38import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080039import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070040import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import com.android.internal.view.IInputContext;
42import com.android.internal.view.IInputMethodClient;
43import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080044import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import com.android.server.am.BatteryStatsService;
46
47import android.Manifest;
48import android.app.ActivityManagerNative;
49import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070050import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070051import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070052import android.content.ClipData;
53import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.Intent;
56import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080061import android.content.res.Resources;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080062import android.graphics.Bitmap;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070065import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070067import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070088import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.os.SystemClock;
90import android.os.SystemProperties;
91import android.os.TokenWatcher;
92import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070093import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070095import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080096import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070098import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700100import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101import android.view.Gravity;
102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
129import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.File;
132import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.FileInputStream;
134import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135import java.io.IOException;
136import java.io.OutputStream;
137import java.io.OutputStreamWriter;
138import java.io.PrintWriter;
139import java.io.StringWriter;
140import java.net.Socket;
141import java.util.ArrayList;
142import java.util.HashMap;
143import java.util.HashSet;
144import java.util.Iterator;
145import java.util.List;
146
147/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700148public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700149 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800152 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800162 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700164 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean DEBUG_APP_TRANSITIONS = false;
166 static final boolean DEBUG_STARTING_WINDOW = false;
167 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700168 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800169 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700171 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 static final boolean PROFILE_ORIENTATION = false;
174 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700175 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to multiply the policy's type layer, to reserve room
178 * for multiple windows of the same type and Z-ordering adjustment
179 * with TYPE_LAYER_OFFSET. */
180 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
183 * or below others in the same layer. */
184 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /** How much to increment the layer for each window, to reserve room
187 * for effect surfaces between them.
188 */
189 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /** The maximum length we will accept for a loaded animation duration:
192 * this is 10 seconds.
193 */
194 static final int MAX_ANIMATION_DURATION = 10*1000;
195
196 /** Amount of time (in milliseconds) to animate the dim surface from one
197 * value to another, when no window animation is driving it.
198 */
199 static final int DEFAULT_DIM_DURATION = 200;
200
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700201 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
202 * compatible windows.
203 */
204 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
205
Dianne Hackborna1111872010-11-23 20:55:11 -0800206 /**
207 * If true, the window manager will do its own custom freezing and general
208 * management of the screen during rotation.
209 */
210 static final boolean CUSTOM_SCREEN_ROTATION = true;
211
Jeff Brown7fbdc842010-06-17 20:52:56 -0700212 // Maximum number of milliseconds to wait for input event injection.
213 // FIXME is this value reasonable?
214 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800215
216 // Maximum number of milliseconds to wait for input devices to be enumerated before
217 // proceding with safe mode detection.
218 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700219
220 // Default input dispatching timeout in nanoseconds.
221 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 static final int UPDATE_FOCUS_NORMAL = 0;
224 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
225 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
226 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700229 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
231 /**
232 * Condition waited on by {@link #reenableKeyguard} to know the call to
233 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500234 * This is set to true only if mKeyguardTokenWatcher.acquired() has
235 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
Jim Miller284b62e2010-06-08 14:27:42 -0700239 private static final int ALLOW_DISABLE_YES = 1;
240 private static final int ALLOW_DISABLE_NO = 0;
241 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
242 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
243
Mike Lockwood983ee092009-11-22 01:42:24 -0500244 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
245 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700247 if (shouldAllowDisableKeyguard()) {
248 mPolicy.enableKeyguard(false);
249 mKeyguardDisabled = true;
250 } else {
251 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700255 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500256 synchronized (mKeyguardTokenWatcher) {
257 mKeyguardDisabled = false;
258 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260 }
261 };
262
Jim Miller284b62e2010-06-08 14:27:42 -0700263 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
264 @Override
265 public void onReceive(Context context, Intent intent) {
266 mPolicy.enableKeyguard(true);
267 synchronized(mKeyguardTokenWatcher) {
268 // lazily evaluate this next time we're asked to disable keyguard
269 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
270 mKeyguardDisabled = false;
271 }
272 }
273 };
274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final Context mContext;
276
277 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
282
283 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 /**
288 * All currently active sessions with clients.
289 */
290 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 /**
293 * Mapping from an IWindow IBinder to the server's Window object.
294 * This is also used as the lock for all of our state.
295 */
296 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
297
298 /**
299 * Mapping from a token IBinder to a WindowToken object.
300 */
301 final HashMap<IBinder, WindowToken> mTokenMap =
302 new HashMap<IBinder, WindowToken>();
303
304 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 * Window tokens that are in the process of exiting, but still
306 * on screen for animations.
307 */
308 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
309
310 /**
311 * Z-ordered (bottom-most first) list of all application tokens, for
312 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800313 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 */
315 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
316
317 /**
318 * Application tokens that are in the process of exiting, but still
319 * on screen for animations.
320 */
321 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
322
323 /**
324 * List of window tokens that have finished starting their application,
325 * and now need to have the policy remove their windows.
326 */
327 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
328
329 /**
330 * Z-ordered (bottom-most first) list of all Window objects.
331 */
Jeff Browne33348b2010-07-15 23:54:05 -0700332 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
334 /**
335 * Windows that are being resized. Used so we can tell the client about
336 * the resize after closing the transaction in which we resized the
337 * underlying surface.
338 */
339 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
340
341 /**
342 * Windows whose animations have ended and now must be removed.
343 */
344 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
345
346 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800347 * Used when processing mPendingRemove to avoid working on the original array.
348 */
349 WindowState[] mPendingRemoveTmp = new WindowState[20];
350
351 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 * Windows whose surface should be destroyed.
353 */
354 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
355
356 /**
357 * Windows that have lost input focus and are waiting for the new
358 * focus window to be displayed before they are told about this.
359 */
360 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
361
362 /**
363 * This is set when we have run out of memory, and will either be an empty
364 * list or contain windows that need to be force removed.
365 */
366 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700367
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800368 /**
369 * Used when rebuilding window list to keep track of windows that have
370 * been removed.
371 */
372 WindowState[] mRebuildTmp = new WindowState[20];
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800381 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800382 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 final float[] mTmpFloats = new float[9];
387
388 boolean mSafeMode;
389 boolean mDisplayEnabled = false;
390 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700391 int mInitialDisplayWidth = 0;
392 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 int mRotation = 0;
394 int mRequestedRotation = 0;
395 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700396 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 ArrayList<IRotationWatcher> mRotationWatchers
398 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800399 int mDeferredRotation;
400 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mLayoutNeeded = true;
403 boolean mAnimationPending = false;
404 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800405 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 boolean mWindowsFreezingScreen = false;
407 long mFreezeGcPending = 0;
408 int mAppsFreezingScreen = 0;
409
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800410 int mLayoutSeq = 0;
411
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800412 // State while inside of layoutAndPlaceSurfacesLocked().
413 boolean mFocusMayChange;
414
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800415 Configuration mCurConfiguration = new Configuration();
416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 // This is held as long as we have the screen frozen, to give us time to
418 // perform a rotation animation when turning off shows the lock screen which
419 // changes the orientation.
420 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // State management of app transitions. When we are preparing for a
423 // transition, mNextAppTransition will be the kind of transition to
424 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
425 // mOpeningApps and mClosingApps are the lists of tokens that will be
426 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700427 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700428 String mNextAppTransitionPackage;
429 int mNextAppTransitionEnter;
430 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 boolean mAppTransitionTimeout = false;
434 boolean mStartingIconInTransition = false;
435 boolean mSkipAppTransitionAnimation = false;
436 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700438 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
439 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 H mH = new H();
444
445 WindowState mCurrentFocus = null;
446 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 // This just indicates the window the input method is on top of, not
449 // necessarily the window its input is going to.
450 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 boolean mInputMethodTargetWaitingAnim;
452 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 WindowState mInputMethodWindow = null;
455 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
456
Jeff Brown2992ea72011-01-28 22:04:14 -0800457 boolean mHardKeyboardAvailable;
458 boolean mHardKeyboardEnabled;
459 OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
460
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700461 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800462
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700463 // If non-null, this is the currently visible window that is associated
464 // with the wallpaper.
465 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700466 // If non-null, we are in the middle of animating from one wallpaper target
467 // to another, and this is the lower one in Z-order.
468 WindowState mLowerWallpaperTarget = null;
469 // If non-null, we are in the middle of animating from one wallpaper target
470 // to another, and this is the higher one in Z-order.
471 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800472 // Window currently running an animation that has requested it be detached
473 // from the wallpaper. This means we need to ensure the wallpaper is
474 // visible behind it in case it animates in a way that would allow it to be
475 // seen.
476 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700477 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700478 float mLastWallpaperX = -1;
479 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800480 float mLastWallpaperXStep = -1;
481 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700482 // This is set when we are waiting for a wallpaper to tell us it is done
483 // changing its scroll position.
484 WindowState mWaitingOnWallpaper;
485 // The last time we had a timeout when waiting for a wallpaper.
486 long mLastWallpaperTimeoutTime;
487 // We give a wallpaper up to 150ms to finish scrolling.
488 static final long WALLPAPER_TIMEOUT = 150;
489 // Time we wait after a timeout before trying to wait again.
490 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 AppWindowToken mFocusedApp = null;
493
494 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 float mWindowAnimationScale = 1.0f;
497 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700498
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700499 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500
501 // Who is holding the screen on.
502 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700503 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700504
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700505 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700508 * Drag/drop state
509 */
510 class DragState {
511 IBinder mToken;
512 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800513 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700514 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 ClipData mData;
516 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700517 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700518 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700519 float mThumbOffsetX, mThumbOffsetY;
520 InputChannel mServerChannel, mClientChannel;
521 WindowState mTargetWindow;
522 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700523 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700524
Jeff Brownfbf09772011-01-16 14:06:57 -0800525 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700526
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800527 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700528 mToken = token;
529 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800530 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700531 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700532 mNotifiedWindows = new ArrayList<WindowState>();
533 }
534
535 void reset() {
536 if (mSurface != null) {
537 mSurface.destroy();
538 }
539 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800540 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700541 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700542 mToken = null;
543 mData = null;
544 mThumbOffsetX = mThumbOffsetY = 0;
545 mNotifiedWindows = null;
546 }
547
548 void register() {
549 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
550 if (mClientChannel != null) {
551 Slog.e(TAG, "Duplicate register of drag input channel");
552 } else {
553 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
554 mServerChannel = channels[0];
555 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800556 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700557 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
558 mH.getLooper().getQueue());
559 }
560 }
561
562 void unregister() {
563 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
564 if (mClientChannel == null) {
565 Slog.e(TAG, "Unregister of nonexistent drag input channel");
566 } else {
567 mInputManager.unregisterInputChannel(mServerChannel);
568 InputQueue.unregisterInputChannel(mClientChannel);
569 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700570 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700571 mClientChannel = null;
572 mServerChannel = null;
573 }
574 }
575
Chris Tatea32dcf72010-10-14 12:13:50 -0700576 int getDragLayerLw() {
577 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
578 * TYPE_LAYER_MULTIPLIER
579 + TYPE_LAYER_OFFSET;
580 }
581
Christopher Tatea53146c2010-09-07 11:57:52 -0700582 /* call out to each visible window/session informing it about the drag
583 */
Chris Tateb8203e92010-10-12 14:23:21 -0700584 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700585 // Cache a base-class instance of the clip metadata so that parceling
586 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800587 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700589 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700590
591 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700592 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700593 }
594
Christopher Tate2c095f32010-10-04 14:13:40 -0700595 final int N = mWindows.size();
596 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700597 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700599 }
600
601 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
602 * designated window is potentially a drop recipient. There are race situations
603 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
604 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700605 *
606 * This method clones the 'event' parameter if it's being delivered to the same
607 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700608 */
Chris Tateb478f462010-10-15 16:02:26 -0700609 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
610 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700611 // Don't actually send the event if the drag is supposed to be pinned
612 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800613 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700614 final IBinder winBinder = newWin.mClient.asBinder();
615 if (winBinder != mLocalWin) {
616 if (DEBUG_DRAG) {
617 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
618 }
619 return;
620 }
621 }
622
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700623 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700624 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
625 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800626 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700627 try {
628 newWin.mClient.dispatchDragEvent(event);
629 // track each window that we've notified that the drag is starting
630 mNotifiedWindows.add(newWin);
631 } catch (RemoteException e) {
632 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700633 } finally {
634 // if the callee was local, the dispatch has already recycled the event
635 if (Process.myPid() != newWin.mSession.mPid) {
636 event.recycle();
637 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700638 }
639 }
640 }
641
642 /* helper - construct and send a DRAG_STARTED event only if the window has not
643 * previously been notified, i.e. it became visible after the drag operation
644 * was begun. This is a rare case.
645 */
646 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700647 if (mDragInProgress) {
648 // If we have sent the drag-started, we needn't do so again
649 for (WindowState ws : mNotifiedWindows) {
650 if (ws == newWin) {
651 return;
652 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700653 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700654 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700655 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700656 }
Chris Tateb478f462010-10-15 16:02:26 -0700657 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700658 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700659 }
660
Chris Tated4533f142010-10-19 15:15:08 -0700661 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700662 if (DEBUG_DRAG) {
663 Slog.d(TAG, "broadcasting DRAG_ENDED");
664 }
Chris Tated4533f142010-10-19 15:15:08 -0700665 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800666 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700667 for (WindowState ws: mNotifiedWindows) {
668 try {
669 ws.mClient.dispatchDragEvent(evt);
670 } catch (RemoteException e) {
671 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700673 }
Chris Tated4533f142010-10-19 15:15:08 -0700674 mNotifiedWindows.clear();
675 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700676 evt.recycle();
677 }
678
Chris Tated4533f142010-10-19 15:15:08 -0700679 void endDragLw() {
680 mDragState.broadcastDragEndedLw();
681
682 // stop intercepting input
683 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -0800684 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tated4533f142010-10-19 15:15:08 -0700685
686 // free our resources and drop all the object references
687 mDragState.reset();
688 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800689
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800690 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
691 boolean changed = setRotationUncheckedLocked(
692 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
693 if (changed) {
694 sendNewConfiguration();
Christopher Tateccd24de2011-01-12 15:02:55 -0800695 }
Chris Tated4533f142010-10-19 15:15:08 -0700696 }
697
Christopher Tatea53146c2010-09-07 11:57:52 -0700698 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700699 final int myPid = Process.myPid();
700
701 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800702 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800703 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800704 try {
705 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
706 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800707 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800708 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
709 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700710
711 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700712 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800713 if (touchedWin == null) {
714 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
715 return;
716 }
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 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800815
816 child.getTouchableRegion(mTmpRegion);
817
Christopher Tatea53146c2010-09-07 11:57:52 -0700818 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800819 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
820 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
821 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700822 // Found it
823 touchedWin = child;
824 break;
825 }
826 }
827
828 return touchedWin;
829 }
830 }
831
832 DragState mDragState = null;
833 private final InputHandler mDragInputHandler = new BaseInputHandler() {
834 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700835 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
836 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700837 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700838 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
839 && mDragState != null) {
840 boolean endDrag = false;
841 final float newX = event.getRawX();
842 final float newY = event.getRawY();
843
Christopher Tatea53146c2010-09-07 11:57:52 -0700844 switch (event.getAction()) {
845 case MotionEvent.ACTION_DOWN: {
846 if (DEBUG_DRAG) {
847 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
848 }
849 } break;
850
851 case MotionEvent.ACTION_MOVE: {
852 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700853 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700854 mDragState.notifyMoveLw(newX, newY);
855 }
856 } break;
857
858 case MotionEvent.ACTION_UP: {
859 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
860 + newX + "," + newY);
861 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700862 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700863 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700864 } break;
865
866 case MotionEvent.ACTION_CANCEL: {
867 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
868 endDrag = true;
869 } break;
870 }
871
872 if (endDrag) {
873 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
874 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700875 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700876 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700877 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700878 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700879
880 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700881 }
882 } catch (Exception e) {
883 Slog.e(TAG, "Exception caught by drag handleMotion", e);
884 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700885 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700886 }
887 }
888 };
889
890 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 * Whether the UI is currently running in touch mode (not showing
892 * navigational focus because the user is directly pressing the screen).
893 */
894 boolean mInTouchMode = false;
895
896 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700897 private ArrayList<WindowChangeListener> mWindowChangeListeners =
898 new ArrayList<WindowChangeListener>();
899 private boolean mWindowsChanged = false;
900
901 public interface WindowChangeListener {
902 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700903 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905
Dianne Hackbornc485a602009-03-24 22:39:49 -0700906 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700907 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700908
909 // The frame use to limit the size of the app running in compatibility mode.
910 Rect mCompatibleScreenFrame = new Rect();
911 // The surface used to fill the outer rim of the app running in compatibility mode.
912 Surface mBackgroundFillerSurface = null;
913 boolean mBackgroundFillerShown = false;
914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 public static WindowManagerService main(Context context,
916 PowerManagerService pm, boolean haveInputMethods) {
917 WMThread thr = new WMThread(context, pm, haveInputMethods);
918 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 synchronized (thr) {
921 while (thr.mService == null) {
922 try {
923 thr.wait();
924 } catch (InterruptedException e) {
925 }
926 }
927 }
Romain Guy06882f82009-06-10 13:36:04 -0700928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 return thr.mService;
930 }
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 static class WMThread extends Thread {
933 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 private final Context mContext;
936 private final PowerManagerService mPM;
937 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 public WMThread(Context context, PowerManagerService pm,
940 boolean haveInputMethods) {
941 super("WindowManager");
942 mContext = context;
943 mPM = pm;
944 mHaveInputMethods = haveInputMethods;
945 }
Romain Guy06882f82009-06-10 13:36:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 public void run() {
948 Looper.prepare();
949 WindowManagerService s = new WindowManagerService(mContext, mPM,
950 mHaveInputMethods);
951 android.os.Process.setThreadPriority(
952 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700953 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 synchronized (this) {
956 mService = s;
957 notifyAll();
958 }
Romain Guy06882f82009-06-10 13:36:04 -0700959
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700960 // For debug builds, log event loop stalls to dropbox for analysis.
961 if (StrictMode.conditionallyEnableDebugLogging()) {
962 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
963 }
964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 Looper.loop();
966 }
967 }
968
969 static class PolicyThread extends Thread {
970 private final WindowManagerPolicy mPolicy;
971 private final WindowManagerService mService;
972 private final Context mContext;
973 private final PowerManagerService mPM;
974 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 public PolicyThread(WindowManagerPolicy policy,
977 WindowManagerService service, Context context,
978 PowerManagerService pm) {
979 super("WindowManagerPolicy");
980 mPolicy = policy;
981 mService = service;
982 mContext = context;
983 mPM = pm;
984 }
Romain Guy06882f82009-06-10 13:36:04 -0700985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 public void run() {
987 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800988 WindowManagerPolicyThread.set(this, Looper.myLooper());
989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800991 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 android.os.Process.setThreadPriority(
993 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700994 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 synchronized (this) {
998 mRunning = true;
999 notifyAll();
1000 }
Romain Guy06882f82009-06-10 13:36:04 -07001001
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001002 // For debug builds, log event loop stalls to dropbox for analysis.
1003 if (StrictMode.conditionallyEnableDebugLogging()) {
1004 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1005 }
1006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 Looper.loop();
1008 }
1009 }
1010
1011 private WindowManagerService(Context context, PowerManagerService pm,
1012 boolean haveInputMethods) {
1013 mContext = context;
1014 mHaveInputMethods = haveInputMethods;
1015 mLimitedAlphaCompositing = context.getResources().getBoolean(
1016 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 mPowerManager = pm;
1019 mPowerManager.setPolicy(mPolicy);
1020 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1021 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1022 "SCREEN_FROZEN");
1023 mScreenFrozenLock.setReferenceCounted(false);
1024
1025 mActivityManager = ActivityManagerNative.getDefault();
1026 mBatteryStats = BatteryStatsService.getService();
1027
1028 // Get persisted window scale setting
1029 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1030 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1031 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1032 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001033
Jim Miller284b62e2010-06-08 14:27:42 -07001034 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1035 IntentFilter filter = new IntentFilter();
1036 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1037 mContext.registerReceiver(mBroadcastReceiver, filter);
1038
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001039 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1040 "KEEP_SCREEN_ON_FLAG");
1041 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042
Jeff Browne33348b2010-07-15 23:54:05 -07001043 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1046 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 synchronized (thr) {
1049 while (!thr.mRunning) {
1050 try {
1051 thr.wait();
1052 } catch (InterruptedException e) {
1053 }
1054 }
1055 }
Romain Guy06882f82009-06-10 13:36:04 -07001056
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001057 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 // Add ourself to the Watchdog monitors.
1060 Watchdog.getInstance().addMonitor(this);
1061 }
1062
1063 @Override
1064 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1065 throws RemoteException {
1066 try {
1067 return super.onTransact(code, data, reply, flags);
1068 } catch (RuntimeException e) {
1069 // The window manager only throws security exceptions, so let's
1070 // log all others.
1071 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001072 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 }
1074 throw e;
1075 }
1076 }
1077
Jeff Browne33348b2010-07-15 23:54:05 -07001078 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001080 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 TAG, "Adding window " + window + " at "
1082 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1083 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001084 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 }
1086
Jeff Browne33348b2010-07-15 23:54:05 -07001087 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001089 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 TAG, "Adding window " + window + " at "
1091 + i + " of " + mWindows.size() + " (before " + pos + ")");
1092 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001093 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 }
1095
1096 //This method finds out the index of a window that has the same app token as
1097 //win. used for z ordering the windows in mWindows
1098 private int findIdxBasedOnAppTokens(WindowState win) {
1099 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001100 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 int jmax = localmWindows.size();
1102 if(jmax == 0) {
1103 return -1;
1104 }
1105 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001106 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 if(wentry.mAppToken == win.mAppToken) {
1108 return j;
1109 }
1110 }
1111 return -1;
1112 }
Romain Guy06882f82009-06-10 13:36:04 -07001113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1115 final IWindow client = win.mClient;
1116 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001117 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 final int N = localmWindows.size();
1120 final WindowState attached = win.mAttachedWindow;
1121 int i;
1122 if (attached == null) {
1123 int tokenWindowsPos = token.windows.size();
1124 if (token.appWindowToken != null) {
1125 int index = tokenWindowsPos-1;
1126 if (index >= 0) {
1127 // If this application has existing windows, we
1128 // simply place the new window on top of them... but
1129 // keep the starting window on top.
1130 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1131 // Base windows go behind everything else.
1132 placeWindowBefore(token.windows.get(0), win);
1133 tokenWindowsPos = 0;
1134 } else {
1135 AppWindowToken atoken = win.mAppToken;
1136 if (atoken != null &&
1137 token.windows.get(index) == atoken.startingWindow) {
1138 placeWindowBefore(token.windows.get(index), win);
1139 tokenWindowsPos--;
1140 } else {
1141 int newIdx = findIdxBasedOnAppTokens(win);
1142 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001143 //there is a window above this one associated with the same
1144 //apptoken note that the window could be a floating window
1145 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001147 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1148 Slog.v(TAG, "Adding window " + win + " at "
1149 + (newIdx+1) + " of " + N);
1150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001152 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 }
1155 }
1156 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001157 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 TAG, "Figuring out where to add app window "
1159 + client.asBinder() + " (token=" + token + ")");
1160 // Figure out where the window should go, based on the
1161 // order of applications.
1162 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001163 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 for (i=NA-1; i>=0; i--) {
1165 AppWindowToken t = mAppTokens.get(i);
1166 if (t == token) {
1167 i--;
1168 break;
1169 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001170
Dianne Hackborna8f60182009-09-01 19:01:50 -07001171 // We haven't reached the token yet; if this token
1172 // is not going to the bottom and has windows, we can
1173 // use it as an anchor for when we do reach the token.
1174 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 pos = t.windows.get(0);
1176 }
1177 }
1178 // We now know the index into the apps. If we found
1179 // an app window above, that gives us the position; else
1180 // we need to look some more.
1181 if (pos != null) {
1182 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001183 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 if (atoken != null) {
1185 final int NC = atoken.windows.size();
1186 if (NC > 0) {
1187 WindowState bottom = atoken.windows.get(0);
1188 if (bottom.mSubLayer < 0) {
1189 pos = bottom;
1190 }
1191 }
1192 }
1193 placeWindowBefore(pos, win);
1194 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001195 // Continue looking down until we find the first
1196 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 while (i >= 0) {
1198 AppWindowToken t = mAppTokens.get(i);
1199 final int NW = t.windows.size();
1200 if (NW > 0) {
1201 pos = t.windows.get(NW-1);
1202 break;
1203 }
1204 i--;
1205 }
1206 if (pos != null) {
1207 // Move in front of any windows attached to this
1208 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001209 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 if (atoken != null) {
1211 final int NC = atoken.windows.size();
1212 if (NC > 0) {
1213 WindowState top = atoken.windows.get(NC-1);
1214 if (top.mSubLayer >= 0) {
1215 pos = top;
1216 }
1217 }
1218 }
1219 placeWindowAfter(pos, win);
1220 } else {
1221 // Just search for the start of this layer.
1222 final int myLayer = win.mBaseLayer;
1223 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001224 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 if (w.mBaseLayer > myLayer) {
1226 break;
1227 }
1228 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001229 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1230 Slog.v(TAG, "Adding window " + win + " at "
1231 + i + " of " + N);
1232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001234 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 }
1236 }
1237 }
1238 } else {
1239 // Figure out where window should go, based on layer.
1240 final int myLayer = win.mBaseLayer;
1241 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001242 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 i++;
1244 break;
1245 }
1246 }
1247 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001248 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001249 TAG, "Adding window " + win + " at "
1250 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001252 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 }
1254 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001255 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 token.windows.add(tokenWindowsPos, win);
1257 }
1258
1259 } else {
1260 // Figure out this window's ordering relative to the window
1261 // it is attached to.
1262 final int NA = token.windows.size();
1263 final int sublayer = win.mSubLayer;
1264 int largestSublayer = Integer.MIN_VALUE;
1265 WindowState windowWithLargestSublayer = null;
1266 for (i=0; i<NA; i++) {
1267 WindowState w = token.windows.get(i);
1268 final int wSublayer = w.mSubLayer;
1269 if (wSublayer >= largestSublayer) {
1270 largestSublayer = wSublayer;
1271 windowWithLargestSublayer = w;
1272 }
1273 if (sublayer < 0) {
1274 // For negative sublayers, we go below all windows
1275 // in the same sublayer.
1276 if (wSublayer >= sublayer) {
1277 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001278 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 token.windows.add(i, win);
1280 }
1281 placeWindowBefore(
1282 wSublayer >= 0 ? attached : w, win);
1283 break;
1284 }
1285 } else {
1286 // For positive sublayers, we go above all windows
1287 // in the same sublayer.
1288 if (wSublayer > sublayer) {
1289 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001290 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 token.windows.add(i, win);
1292 }
1293 placeWindowBefore(w, win);
1294 break;
1295 }
1296 }
1297 }
1298 if (i >= NA) {
1299 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001300 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 token.windows.add(win);
1302 }
1303 if (sublayer < 0) {
1304 placeWindowBefore(attached, win);
1305 } else {
1306 placeWindowAfter(largestSublayer >= 0
1307 ? windowWithLargestSublayer
1308 : attached,
1309 win);
1310 }
1311 }
1312 }
Romain Guy06882f82009-06-10 13:36:04 -07001313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 if (win.mAppToken != null && addToToken) {
1315 win.mAppToken.allAppWindows.add(win);
1316 }
1317 }
Romain Guy06882f82009-06-10 13:36:04 -07001318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 static boolean canBeImeTarget(WindowState w) {
1320 final int fl = w.mAttrs.flags
1321 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001322 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
1323 || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
1324 if (DEBUG_INPUT_METHOD) {
1325 Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1326 if (!w.isVisibleOrAdding()) {
1327 Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface
1328 + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
1329 + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
1330 + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
1331 if (w.mAppToken != null) {
1332 Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1333 }
1334 }
1335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 return w.isVisibleOrAdding();
1337 }
1338 return false;
1339 }
Romain Guy06882f82009-06-10 13:36:04 -07001340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001342 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 final int N = localmWindows.size();
1344 WindowState w = null;
1345 int i = N;
1346 while (i > 0) {
1347 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001348 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001349
Dianne Hackborne75d8722011-01-27 19:37:40 -08001350 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
1351 + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001353 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001355 // Yet more tricksyness! If this window is a "starting"
1356 // window, we do actually want to be on top of it, but
1357 // it is not -really- where input will go. So if the caller
1358 // is not actually looking to move the IME, look down below
1359 // for a real window to target...
1360 if (!willMove
1361 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1362 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001363 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1365 i--;
1366 w = wb;
1367 }
1368 }
1369 break;
1370 }
1371 }
Romain Guy06882f82009-06-10 13:36:04 -07001372
Dianne Hackborne75d8722011-01-27 19:37:40 -08001373 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
1374
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001375 // Now, a special case -- if the last target's window is in the
1376 // process of exiting, and is above the new target, keep on the
1377 // last target to avoid flicker. Consider for example a Dialog with
1378 // the IME shown: when the Dialog is dismissed, we want to keep
1379 // the IME above it until it is completely gone so it doesn't drop
1380 // behind the dialog or its full-screen scrim.
1381 if (mInputMethodTarget != null && w != null
1382 && mInputMethodTarget.isDisplayedLw()
1383 && mInputMethodTarget.mExiting) {
1384 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1385 w = mInputMethodTarget;
1386 i = localmWindows.indexOf(w);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001387 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w);
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001388 }
1389 }
Romain Guy06882f82009-06-10 13:36:04 -07001390
Joe Onorato8a9b2202010-02-26 18:56:32 -08001391 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 if (willMove && w != null) {
1395 final WindowState curTarget = mInputMethodTarget;
1396 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 // Now some fun for dealing with window animations that
1399 // modify the Z order. We need to look at all windows below
1400 // the current target that are in this app, finding the highest
1401 // visible one in layering.
1402 AppWindowToken token = curTarget.mAppToken;
1403 WindowState highestTarget = null;
1404 int highestPos = 0;
1405 if (token.animating || token.animation != null) {
1406 int pos = 0;
1407 pos = localmWindows.indexOf(curTarget);
1408 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001409 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 if (win.mAppToken != token) {
1411 break;
1412 }
1413 if (!win.mRemoved) {
1414 if (highestTarget == null || win.mAnimLayer >
1415 highestTarget.mAnimLayer) {
1416 highestTarget = win;
1417 highestPos = pos;
1418 }
1419 }
1420 pos--;
1421 }
1422 }
Romain Guy06882f82009-06-10 13:36:04 -07001423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001425 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 + mNextAppTransition + " " + highestTarget
1427 + " animating=" + highestTarget.isAnimating()
1428 + " layer=" + highestTarget.mAnimLayer
1429 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001430
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001431 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 // If we are currently setting up for an animation,
1433 // hold everything until we can find out what will happen.
1434 mInputMethodTargetWaitingAnim = true;
1435 mInputMethodTarget = highestTarget;
1436 return highestPos + 1;
1437 } else if (highestTarget.isAnimating() &&
1438 highestTarget.mAnimLayer > w.mAnimLayer) {
1439 // If the window we are currently targeting is involved
1440 // with an animation, and it is on top of the next target
1441 // we will be over, then hold off on moving until
1442 // that is done.
Dianne Hackborne75d8722011-01-27 19:37:40 -08001443 mInputMethodTargetWaitingAnim = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 mInputMethodTarget = highestTarget;
1445 return highestPos + 1;
1446 }
1447 }
1448 }
1449 }
Romain Guy06882f82009-06-10 13:36:04 -07001450
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 if (w != null) {
1453 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001454 if (DEBUG_INPUT_METHOD) {
1455 RuntimeException e = null;
1456 if (!HIDE_STACK_CRAWLS) {
1457 e = new RuntimeException();
1458 e.fillInStackTrace();
1459 }
1460 Slog.w(TAG, "Moving IM target from "
1461 + mInputMethodTarget + " to " + w, e);
1462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 mInputMethodTarget = w;
Dianne Hackborne75d8722011-01-27 19:37:40 -08001464 mInputMethodTargetWaitingAnim = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 if (w.mAppToken != null) {
1466 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1467 } else {
1468 setInputMethodAnimLayerAdjustment(0);
1469 }
1470 }
1471 return i+1;
1472 }
1473 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001474 if (DEBUG_INPUT_METHOD) {
1475 RuntimeException e = null;
1476 if (!HIDE_STACK_CRAWLS) {
1477 e = new RuntimeException();
1478 e.fillInStackTrace();
1479 }
1480 Slog.w(TAG, "Moving IM target from "
1481 + mInputMethodTarget + " to null", e);
1482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 mInputMethodTarget = null;
1484 setInputMethodAnimLayerAdjustment(0);
1485 }
1486 return -1;
1487 }
Romain Guy06882f82009-06-10 13:36:04 -07001488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 void addInputMethodWindowToListLocked(WindowState win) {
1490 int pos = findDesiredInputMethodWindowIndexLocked(true);
1491 if (pos >= 0) {
1492 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001493 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001494 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001496 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 moveInputMethodDialogsLocked(pos+1);
1498 return;
1499 }
1500 win.mTargetAppToken = null;
1501 addWindowToListInOrderLocked(win, true);
1502 moveInputMethodDialogsLocked(pos);
1503 }
Romain Guy06882f82009-06-10 13:36:04 -07001504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001506 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 mInputMethodAnimLayerAdjustment = adj;
1508 WindowState imw = mInputMethodWindow;
1509 if (imw != null) {
1510 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001511 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 + " anim layer: " + imw.mAnimLayer);
1513 int wi = imw.mChildWindows.size();
1514 while (wi > 0) {
1515 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001516 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001518 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 + " anim layer: " + cw.mAnimLayer);
1520 }
1521 }
1522 int di = mInputMethodDialogs.size();
1523 while (di > 0) {
1524 di --;
1525 imw = mInputMethodDialogs.get(di);
1526 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001527 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 + " anim layer: " + imw.mAnimLayer);
1529 }
1530 }
Romain Guy06882f82009-06-10 13:36:04 -07001531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1533 int wpos = mWindows.indexOf(win);
1534 if (wpos >= 0) {
1535 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001536 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001538 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 int NC = win.mChildWindows.size();
1540 while (NC > 0) {
1541 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001542 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 int cpos = mWindows.indexOf(cw);
1544 if (cpos >= 0) {
1545 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001546 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001547 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 mWindows.remove(cpos);
1549 }
1550 }
1551 }
1552 return interestingPos;
1553 }
Romain Guy06882f82009-06-10 13:36:04 -07001554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 private void reAddWindowToListInOrderLocked(WindowState win) {
1556 addWindowToListInOrderLocked(win, false);
1557 // This is a hack to get all of the child windows added as well
1558 // at the right position. Child windows should be rare and
1559 // this case should be rare, so it shouldn't be that big a deal.
1560 int wpos = mWindows.indexOf(win);
1561 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001563 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001564 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001565 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 reAddWindowLocked(wpos, win);
1567 }
1568 }
Romain Guy06882f82009-06-10 13:36:04 -07001569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 void logWindowList(String prefix) {
1571 int N = mWindows.size();
1572 while (N > 0) {
1573 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001574 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 }
1576 }
Romain Guy06882f82009-06-10 13:36:04 -07001577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 void moveInputMethodDialogsLocked(int pos) {
1579 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001582 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 for (int i=0; i<N; i++) {
1584 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1585 }
1586 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001587 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 logWindowList(" ");
1589 }
Romain Guy06882f82009-06-10 13:36:04 -07001590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 if (pos >= 0) {
1592 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1593 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001594 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 if (wp == mInputMethodWindow) {
1596 pos++;
1597 }
1598 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001599 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 for (int i=0; i<N; i++) {
1601 WindowState win = dialogs.get(i);
1602 win.mTargetAppToken = targetAppToken;
1603 pos = reAddWindowLocked(pos, win);
1604 }
1605 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001606 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 logWindowList(" ");
1608 }
1609 return;
1610 }
1611 for (int i=0; i<N; i++) {
1612 WindowState win = dialogs.get(i);
1613 win.mTargetAppToken = null;
1614 reAddWindowToListInOrderLocked(win);
1615 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001616 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 logWindowList(" ");
1618 }
1619 }
1620 }
Romain Guy06882f82009-06-10 13:36:04 -07001621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1623 final WindowState imWin = mInputMethodWindow;
1624 final int DN = mInputMethodDialogs.size();
1625 if (imWin == null && DN == 0) {
1626 return false;
1627 }
Romain Guy06882f82009-06-10 13:36:04 -07001628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1630 if (imPos >= 0) {
1631 // In this case, the input method windows are to be placed
1632 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 // First check to see if the input method windows are already
1635 // located here, and contiguous.
1636 final int N = mWindows.size();
1637 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001638 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 // Figure out the actual input method window that should be
1641 // at the bottom of their stack.
1642 WindowState baseImWin = imWin != null
1643 ? imWin : mInputMethodDialogs.get(0);
1644 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001645 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 if (cw.mSubLayer < 0) baseImWin = cw;
1647 }
Romain Guy06882f82009-06-10 13:36:04 -07001648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 if (firstImWin == baseImWin) {
1650 // The windows haven't moved... but are they still contiguous?
1651 // First find the top IM window.
1652 int pos = imPos+1;
1653 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001654 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 break;
1656 }
1657 pos++;
1658 }
1659 pos++;
1660 // Now there should be no more input method windows above.
1661 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001662 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 break;
1664 }
1665 pos++;
1666 }
1667 if (pos >= N) {
1668 // All is good!
1669 return false;
1670 }
1671 }
Romain Guy06882f82009-06-10 13:36:04 -07001672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 if (imWin != null) {
1674 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001675 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676 logWindowList(" ");
1677 }
1678 imPos = tmpRemoveWindowLocked(imPos, imWin);
1679 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001680 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 logWindowList(" ");
1682 }
1683 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1684 reAddWindowLocked(imPos, imWin);
1685 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001686 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 logWindowList(" ");
1688 }
1689 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1690 } else {
1691 moveInputMethodDialogsLocked(imPos);
1692 }
Romain Guy06882f82009-06-10 13:36:04 -07001693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 } else {
1695 // In this case, the input method windows go in a fixed layer,
1696 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001698 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001699 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 tmpRemoveWindowLocked(0, imWin);
1701 imWin.mTargetAppToken = null;
1702 reAddWindowToListInOrderLocked(imWin);
1703 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001704 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 logWindowList(" ");
1706 }
1707 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1708 } else {
1709 moveInputMethodDialogsLocked(-1);;
1710 }
Romain Guy06882f82009-06-10 13:36:04 -07001711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001712 }
Romain Guy06882f82009-06-10 13:36:04 -07001713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 if (needAssignLayers) {
1715 assignLayersLocked();
1716 }
Romain Guy06882f82009-06-10 13:36:04 -07001717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 return true;
1719 }
Romain Guy06882f82009-06-10 13:36:04 -07001720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721 void adjustInputMethodDialogsLocked() {
1722 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1723 }
Romain Guy06882f82009-06-10 13:36:04 -07001724
Dianne Hackborn25994b42009-09-04 14:21:19 -07001725 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001726 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001727 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1728 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1729 ? wallpaperTarget.mAppToken.animation : null)
1730 + " upper=" + mUpperWallpaperTarget
1731 + " lower=" + mLowerWallpaperTarget);
1732 return (wallpaperTarget != null
1733 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1734 && wallpaperTarget.mAppToken.animation != null)))
1735 || mUpperWallpaperTarget != null
1736 || mLowerWallpaperTarget != null;
1737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001738
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001739 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1740 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001742 int adjustWallpaperWindowsLocked() {
1743 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001744
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001745 final int dw = mDisplay.getWidth();
1746 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001747
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001748 // First find top-most window that has asked to be on top of the
1749 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001750 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001751 int N = localmWindows.size();
1752 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001753 WindowState foundW = null;
1754 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001755 WindowState topCurW = null;
1756 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001757 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001758 int i = N;
1759 while (i > 0) {
1760 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001761 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001762 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1763 if (topCurW == null) {
1764 topCurW = w;
1765 topCurI = i;
1766 }
1767 continue;
1768 }
1769 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001770 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001771 // If this window's app token is hidden and not animating,
1772 // it is of no interest to us.
1773 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001774 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001775 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001776 continue;
1777 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001778 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001779 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001780 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1781 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001782 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001783 && (mWallpaperTarget == w
1784 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001785 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001786 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001787 foundW = w;
1788 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001789 if (w == mWallpaperTarget && ((w.mAppToken != null
1790 && w.mAppToken.animation != null)
1791 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001792 // The current wallpaper target is animating, so we'll
1793 // look behind it for another possible target and figure
1794 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001795 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001796 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001797 continue;
1798 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001799 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001800 } else if (w == mWindowDetachedWallpaper) {
1801 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001802 }
1803 }
1804
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001805 if (foundW == null && windowDetachedI >= 0) {
1806 if (DEBUG_WALLPAPER) Slog.v(TAG,
1807 "Found animating detached wallpaper activity: #" + i + "=" + w);
1808 foundW = w;
1809 foundI = windowDetachedI;
1810 }
1811
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001812 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001813 // If we are currently waiting for an app transition, and either
1814 // the current target or the next target are involved with it,
1815 // then hold off on doing anything with the wallpaper.
1816 // Note that we are checking here for just whether the target
1817 // is part of an app token... which is potentially overly aggressive
1818 // (the app token may not be involved in the transition), but good
1819 // enough (we'll just wait until whatever transition is pending
1820 // executes).
1821 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001822 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001823 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001824 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001825 }
1826 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001827 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001828 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001829 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001830 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001831 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001832
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001833 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001834 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001835 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001836 + " oldTarget: " + mWallpaperTarget);
1837 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001838
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001839 mLowerWallpaperTarget = null;
1840 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001842 WindowState oldW = mWallpaperTarget;
1843 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001844
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001845 // Now what is happening... if the current and new targets are
1846 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001847 if (foundW != null && oldW != null) {
1848 boolean oldAnim = oldW.mAnimation != null
1849 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1850 boolean foundAnim = foundW.mAnimation != null
1851 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001852 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001853 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001854 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001855 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001856 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001857 int oldI = localmWindows.indexOf(oldW);
1858 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001859 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001860 }
1861 if (oldI >= 0) {
1862 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001864 + "=" + oldW + "; new#" + foundI
1865 + "=" + foundW);
1866 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001867
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001868 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001869 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001871 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001872 }
1873 mWallpaperTarget = oldW;
1874 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001875
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001876 // Now set the upper and lower wallpaper targets
1877 // correctly, and make sure that we are positioning
1878 // the wallpaper below the lower.
1879 if (foundI > oldI) {
1880 // The new target is on top of the old one.
1881 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001882 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001883 }
1884 mUpperWallpaperTarget = foundW;
1885 mLowerWallpaperTarget = oldW;
1886 foundW = oldW;
1887 foundI = oldI;
1888 } else {
1889 // The new target is below the old one.
1890 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001891 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001892 }
1893 mUpperWallpaperTarget = oldW;
1894 mLowerWallpaperTarget = foundW;
1895 }
1896 }
1897 }
1898 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001899
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001900 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001901 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001902 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1903 || (mLowerWallpaperTarget.mAppToken != null
1904 && mLowerWallpaperTarget.mAppToken.animation != null);
1905 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1906 || (mUpperWallpaperTarget.mAppToken != null
1907 && mUpperWallpaperTarget.mAppToken.animation != null);
1908 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001909 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001910 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001911 }
1912 mLowerWallpaperTarget = null;
1913 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001914 }
1915 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001916
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001917 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001918 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001919 // The window is visible to the compositor... but is it visible
1920 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001921 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001922 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001923
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001924 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001925 // its layer adjustment. Only do this if we are not transfering
1926 // between two wallpaper targets.
1927 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001928 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001929 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001930
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001931 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1932 * TYPE_LAYER_MULTIPLIER
1933 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001934
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001935 // Now w is the window we are supposed to be behind... but we
1936 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001937 // AND any starting window associated with it, AND below the
1938 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001939 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001940 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001941 if (wb.mBaseLayer < maxLayer &&
1942 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001943 (foundW.mAttachedWindow == null ||
1944 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001945 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001946 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001947 // This window is not related to the previous one in any
1948 // interesting way, so stop here.
1949 break;
1950 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001951 foundW = wb;
1952 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001953 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001954 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001955 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001957
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001958 if (foundW == null && topCurW != null) {
1959 // There is no wallpaper target, so it goes at the bottom.
1960 // We will assume it is the same place as last time, if known.
1961 foundW = topCurW;
1962 foundI = topCurI+1;
1963 } else {
1964 // Okay i is the position immediately above the wallpaper. Look at
1965 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001966 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001967 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001968
Dianne Hackborn284ac932009-08-28 10:34:25 -07001969 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001970 if (mWallpaperTarget.mWallpaperX >= 0) {
1971 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001972 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001973 }
1974 if (mWallpaperTarget.mWallpaperY >= 0) {
1975 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001976 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001977 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001978 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001979
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001980 // Start stepping backwards from here, ensuring that our wallpaper windows
1981 // are correctly placed.
1982 int curTokenIndex = mWallpaperTokens.size();
1983 while (curTokenIndex > 0) {
1984 curTokenIndex--;
1985 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001986 if (token.hidden == visible) {
1987 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1988 token.hidden = !visible;
1989 // Need to do a layout to ensure the wallpaper now has the
1990 // correct size.
1991 mLayoutNeeded = true;
1992 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001993
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001994 int curWallpaperIndex = token.windows.size();
1995 while (curWallpaperIndex > 0) {
1996 curWallpaperIndex--;
1997 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001998
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001999 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002000 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002001 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002002
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002003 // First, make sure the client has the current visibility
2004 // state.
2005 if (wallpaper.mWallpaperVisible != visible) {
2006 wallpaper.mWallpaperVisible = visible;
2007 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002008 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002009 "Setting visibility of wallpaper " + wallpaper
2010 + ": " + visible);
2011 wallpaper.mClient.dispatchAppVisibility(visible);
2012 } catch (RemoteException e) {
2013 }
2014 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002015
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002016 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002017 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002018 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002019
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002020 // First, if this window is at the current index, then all
2021 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002022 if (wallpaper == foundW) {
2023 foundI--;
2024 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002025 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002026 continue;
2027 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002028
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002029 // The window didn't match... the current wallpaper window,
2030 // wherever it is, is in the wrong place, so make sure it is
2031 // not in the list.
2032 int oldIndex = localmWindows.indexOf(wallpaper);
2033 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002034 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002035 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002036 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002037 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002038 if (oldIndex < foundI) {
2039 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002040 }
2041 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002042
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002043 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002044 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2045 Slog.v(TAG, "Moving wallpaper " + wallpaper
2046 + " from " + oldIndex + " to " + foundI);
2047 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002048
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002049 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002050 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002051 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002052 }
2053 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002054
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002055 return changed;
2056 }
2057
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002058 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002059 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002060 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002061 mWallpaperAnimLayerAdjustment = adj;
2062 int curTokenIndex = mWallpaperTokens.size();
2063 while (curTokenIndex > 0) {
2064 curTokenIndex--;
2065 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2066 int curWallpaperIndex = token.windows.size();
2067 while (curWallpaperIndex > 0) {
2068 curWallpaperIndex--;
2069 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2070 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002071 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002072 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002073 }
2074 }
2075 }
2076
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002077 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2078 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002079 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002080 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002081 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002082 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002083 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2084 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2085 changed = wallpaperWin.mXOffset != offset;
2086 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002087 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 + wallpaperWin + " x: " + offset);
2089 wallpaperWin.mXOffset = offset;
2090 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002091 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002092 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002093 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002094 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002095 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002096
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002097 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002098 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002099 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2100 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2101 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002102 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002103 + wallpaperWin + " y: " + offset);
2104 changed = true;
2105 wallpaperWin.mYOffset = offset;
2106 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002107 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002108 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002109 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002110 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002112
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002113 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002114 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002115 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002116 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2117 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002118 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002119 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002120 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002121 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002122 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2123 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002124 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002125 if (mWaitingOnWallpaper != null) {
2126 long start = SystemClock.uptimeMillis();
2127 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2128 < start) {
2129 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002130 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002131 "Waiting for offset complete...");
2132 mWindowMap.wait(WALLPAPER_TIMEOUT);
2133 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002134 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002135 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002136 if ((start+WALLPAPER_TIMEOUT)
2137 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002138 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002139 + wallpaperWin);
2140 mLastWallpaperTimeoutTime = start;
2141 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002142 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002143 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002144 }
2145 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002146 } catch (RemoteException e) {
2147 }
2148 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002149
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002150 return changed;
2151 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002152
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002153 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002154 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002155 if (mWaitingOnWallpaper != null &&
2156 mWaitingOnWallpaper.mClient.asBinder() == window) {
2157 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002158 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002159 }
2160 }
2161 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002162
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002163 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002164 final int dw = mDisplay.getWidth();
2165 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002166
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002167 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002168
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002169 WindowState target = mWallpaperTarget;
2170 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002171 if (target.mWallpaperX >= 0) {
2172 mLastWallpaperX = target.mWallpaperX;
2173 } else if (changingTarget.mWallpaperX >= 0) {
2174 mLastWallpaperX = changingTarget.mWallpaperX;
2175 }
2176 if (target.mWallpaperY >= 0) {
2177 mLastWallpaperY = target.mWallpaperY;
2178 } else if (changingTarget.mWallpaperY >= 0) {
2179 mLastWallpaperY = changingTarget.mWallpaperY;
2180 }
2181 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002182
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002183 int curTokenIndex = mWallpaperTokens.size();
2184 while (curTokenIndex > 0) {
2185 curTokenIndex--;
2186 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2187 int curWallpaperIndex = token.windows.size();
2188 while (curWallpaperIndex > 0) {
2189 curWallpaperIndex--;
2190 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2191 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2192 wallpaper.computeShownFrameLocked();
2193 changed = true;
2194 // We only want to be synchronous with one wallpaper.
2195 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002196 }
2197 }
2198 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002199
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002200 return changed;
2201 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002202
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002203 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002204 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002205 final int dw = mDisplay.getWidth();
2206 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002207
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002208 int curTokenIndex = mWallpaperTokens.size();
2209 while (curTokenIndex > 0) {
2210 curTokenIndex--;
2211 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002212 if (token.hidden == visible) {
2213 token.hidden = !visible;
2214 // Need to do a layout to ensure the wallpaper now has the
2215 // correct size.
2216 mLayoutNeeded = true;
2217 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002218
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002219 int curWallpaperIndex = token.windows.size();
2220 while (curWallpaperIndex > 0) {
2221 curWallpaperIndex--;
2222 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2223 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002224 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002225 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002226
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002227 if (wallpaper.mWallpaperVisible != visible) {
2228 wallpaper.mWallpaperVisible = visible;
2229 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002230 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002231 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002232 + ": " + visible);
2233 wallpaper.mClient.dispatchAppVisibility(visible);
2234 } catch (RemoteException e) {
2235 }
2236 }
2237 }
2238 }
2239 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 public int addWindow(Session session, IWindow client,
2242 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002243 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 int res = mPolicy.checkAddPermission(attrs);
2245 if (res != WindowManagerImpl.ADD_OKAY) {
2246 return res;
2247 }
Romain Guy06882f82009-06-10 13:36:04 -07002248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 boolean reportNewConfig = false;
2250 WindowState attachedWindow = null;
2251 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002252 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002256 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 }
Romain Guy06882f82009-06-10 13:36:04 -07002258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002260 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2262 }
2263
2264 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002265 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002267 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 + attrs.token + ". Aborting.");
2269 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2270 }
2271 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2272 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002273 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002274 + attrs.token + ". Aborting.");
2275 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2276 }
2277 }
2278
2279 boolean addToken = false;
2280 WindowToken token = mTokenMap.get(attrs.token);
2281 if (token == null) {
2282 if (attrs.type >= FIRST_APPLICATION_WINDOW
2283 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002284 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 + attrs.token + ". Aborting.");
2286 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2287 }
2288 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002289 Slog.w(TAG, "Attempted to add input method 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 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002293 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002294 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002295 + attrs.token + ". Aborting.");
2296 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2297 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 token = new WindowToken(attrs.token, -1, false);
2299 addToken = true;
2300 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2301 && attrs.type <= LAST_APPLICATION_WINDOW) {
2302 AppWindowToken atoken = token.appWindowToken;
2303 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002304 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 + token + ". Aborting.");
2306 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2307 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002308 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 + token + ". Aborting.");
2310 return WindowManagerImpl.ADD_APP_EXITING;
2311 }
2312 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2313 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002314 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2316 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2317 }
2318 } else if (attrs.type == TYPE_INPUT_METHOD) {
2319 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002320 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 + attrs.token + ". Aborting.");
2322 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2323 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002324 } else if (attrs.type == TYPE_WALLPAPER) {
2325 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002326 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002327 + attrs.token + ". Aborting.");
2328 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 }
2331
2332 win = new WindowState(session, client, token,
2333 attachedWindow, attrs, viewVisibility);
2334 if (win.mDeathRecipient == null) {
2335 // Client has apparently died, so there is no reason to
2336 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002337 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 + " that is dead, aborting.");
2339 return WindowManagerImpl.ADD_APP_EXITING;
2340 }
2341
2342 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 res = mPolicy.prepareAddWindowLw(win, attrs);
2345 if (res != WindowManagerImpl.ADD_OKAY) {
2346 return res;
2347 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002348
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002349 if (outInputChannel != null) {
2350 String name = win.makeInputChannelName();
2351 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2352 win.mInputChannel = inputChannels[0];
2353 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2354
Jeff Brown928e0542011-01-10 11:17:36 -08002355 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002356 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357
2358 // From now on, no exceptions or errors allowed!
2359
2360 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002361
Dianne Hackborn5132b372010-07-29 12:51:35 -07002362 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 if (addToken) {
2365 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 }
2367 win.attach();
2368 mWindowMap.put(client.asBinder(), win);
2369
2370 if (attrs.type == TYPE_APPLICATION_STARTING &&
2371 token.appWindowToken != null) {
2372 token.appWindowToken.startingWindow = win;
2373 }
2374
2375 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 if (attrs.type == TYPE_INPUT_METHOD) {
2378 mInputMethodWindow = win;
2379 addInputMethodWindowToListLocked(win);
2380 imMayMove = false;
2381 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2382 mInputMethodDialogs.add(win);
2383 addWindowToListInOrderLocked(win, true);
2384 adjustInputMethodDialogsLocked();
2385 imMayMove = false;
2386 } else {
2387 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002388 if (attrs.type == TYPE_WALLPAPER) {
2389 mLastWallpaperTimeoutTime = 0;
2390 adjustWallpaperWindowsLocked();
2391 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002392 adjustWallpaperWindowsLocked();
2393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394 }
Romain Guy06882f82009-06-10 13:36:04 -07002395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 if (mInTouchMode) {
2401 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2402 }
2403 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2404 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2405 }
Romain Guy06882f82009-06-10 13:36:04 -07002406
Jeff Brown2e44b072011-01-24 15:21:56 -08002407 mInputMonitor.setUpdateInputWindowsNeededLw();
2408
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002409 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002411 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2412 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002413 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 imMayMove = false;
2415 }
2416 }
Romain Guy06882f82009-06-10 13:36:04 -07002417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002419 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 }
Romain Guy06882f82009-06-10 13:36:04 -07002421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 assignLayersLocked();
2423 // Don't do layout here, the window must call
2424 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 //dump();
2427
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002428 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002429 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002430 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002431 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002432
Joe Onorato8a9b2202010-02-26 18:56:32 -08002433 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002434 TAG, "New client " + client.asBinder()
2435 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002436
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002437 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002438 reportNewConfig = true;
2439 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 }
2441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 if (reportNewConfig) {
2443 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 return res;
2449 }
Romain Guy06882f82009-06-10 13:36:04 -07002450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 public void removeWindow(Session session, IWindow client) {
2452 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002453 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002454 if (win == null) {
2455 return;
2456 }
2457 removeWindowLocked(session, win);
2458 }
2459 }
Romain Guy06882f82009-06-10 13:36:04 -07002460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 public void removeWindowLocked(Session session, WindowState win) {
2462
Joe Onorato8a9b2202010-02-26 18:56:32 -08002463 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 TAG, "Remove " + win + " client="
2465 + Integer.toHexString(System.identityHashCode(
2466 win.mClient.asBinder()))
2467 + ", surface=" + win.mSurface);
2468
2469 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002470
2471 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002472
Joe Onorato8a9b2202010-02-26 18:56:32 -08002473 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2475 + " mExiting=" + win.mExiting
2476 + " isAnimating=" + win.isAnimating()
2477 + " app-animation="
2478 + (win.mAppToken != null ? win.mAppToken.animation : null)
2479 + " inPendingTransaction="
2480 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2481 + " mDisplayFrozen=" + mDisplayFrozen);
2482 // Visibility of the removed window. Will be used later to update orientation later on.
2483 boolean wasVisible = false;
2484 // First, see if we need to run an animation. If we do, we have
2485 // to hold off on removing the window until the animation is done.
2486 // If the display is frozen, just remove immediately, since the
2487 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002488 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 // If we are not currently running the exit animation, we
2490 // need to see about starting one.
2491 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2494 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2495 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2496 }
2497 // Try starting an animation.
2498 if (applyAnimationLocked(win, transit, false)) {
2499 win.mExiting = true;
2500 }
2501 }
2502 if (win.mExiting || win.isAnimating()) {
2503 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002504 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 win.mExiting = true;
2506 win.mRemoveOnExit = true;
2507 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002508 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2509 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002511 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 if (win.mAppToken != null) {
2513 win.mAppToken.updateReportedVisibilityLocked();
2514 }
2515 //dump();
2516 Binder.restoreCallingIdentity(origId);
2517 return;
2518 }
2519 }
2520
2521 removeWindowInnerLocked(session, win);
2522 // Removing a visible window will effect the computed orientation
2523 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002524 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002525 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002526 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002527 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002529 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 Binder.restoreCallingIdentity(origId);
2531 }
Romain Guy06882f82009-06-10 13:36:04 -07002532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002534 if (win.mRemoved) {
2535 // Nothing to do.
2536 return;
2537 }
2538
2539 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2540 WindowState cwin = win.mChildWindows.get(i);
2541 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2542 + win);
2543 removeWindowInnerLocked(cwin.mSession, cwin);
2544 }
2545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002548 if (mInputMethodTarget == win) {
2549 moveInputMethodWindowsIfNeededLocked(false);
2550 }
Romain Guy06882f82009-06-10 13:36:04 -07002551
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002552 if (false) {
2553 RuntimeException e = new RuntimeException("here");
2554 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002555 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002556 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 mPolicy.removeWindowLw(win);
2559 win.removeLocked();
2560
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002561 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 mWindowMap.remove(win.mClient.asBinder());
2563 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002564 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002565 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002566 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567
2568 if (mInputMethodWindow == win) {
2569 mInputMethodWindow = null;
2570 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2571 mInputMethodDialogs.remove(win);
2572 }
Romain Guy06882f82009-06-10 13:36:04 -07002573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002574 final WindowToken token = win.mToken;
2575 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002576 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 token.windows.remove(win);
2578 if (atoken != null) {
2579 atoken.allAppWindows.remove(win);
2580 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002581 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 TAG, "**** Removing window " + win + ": count="
2583 + token.windows.size());
2584 if (token.windows.size() == 0) {
2585 if (!token.explicit) {
2586 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 } else if (atoken != null) {
2588 atoken.firstWindowDrawn = false;
2589 }
2590 }
2591
2592 if (atoken != null) {
2593 if (atoken.startingWindow == win) {
2594 atoken.startingWindow = null;
2595 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2596 // If this is the last window and we had requested a starting
2597 // transition window, well there is no point now.
2598 atoken.startingData = null;
2599 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2600 // If this is the last window except for a starting transition
2601 // window, we need to get rid of the starting transition.
2602 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002603 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 + ": no more real windows");
2605 }
2606 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2607 mH.sendMessage(m);
2608 }
2609 }
Romain Guy06882f82009-06-10 13:36:04 -07002610
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002611 if (win.mAttrs.type == TYPE_WALLPAPER) {
2612 mLastWallpaperTimeoutTime = 0;
2613 adjustWallpaperWindowsLocked();
2614 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002615 adjustWallpaperWindowsLocked();
2616 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 if (!mInLayout) {
2619 assignLayersLocked();
2620 mLayoutNeeded = true;
2621 performLayoutAndPlaceSurfacesLocked();
2622 if (win.mAppToken != null) {
2623 win.mAppToken.updateReportedVisibilityLocked();
2624 }
2625 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002626
Jeff Brown2e44b072011-01-24 15:21:56 -08002627 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 }
2629
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002630 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2631 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2632 + ": " + msg + " / " + w.mAttrs.getTitle();
2633 if (where != null) {
2634 Slog.i(TAG, str, where);
2635 } else {
2636 Slog.i(TAG, str);
2637 }
2638 }
2639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002640 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2641 long origId = Binder.clearCallingIdentity();
2642 try {
2643 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002644 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002646 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2647 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 Surface.openTransaction();
2649 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002650 if (SHOW_TRANSACTIONS) logSurface(w,
2651 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 w.mSurface.setTransparentRegionHint(region);
2653 } finally {
2654 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002655 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2656 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 }
2658 }
2659 }
2660 } finally {
2661 Binder.restoreCallingIdentity(origId);
2662 }
2663 }
2664
2665 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002666 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002667 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 long origId = Binder.clearCallingIdentity();
2669 try {
2670 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002671 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 if (w != null) {
2673 w.mGivenInsetsPending = false;
2674 w.mGivenContentInsets.set(contentInsets);
2675 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002676 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 w.mTouchableInsets = touchableInsets;
2678 mLayoutNeeded = true;
2679 performLayoutAndPlaceSurfacesLocked();
2680 }
2681 }
2682 } finally {
2683 Binder.restoreCallingIdentity(origId);
2684 }
2685 }
Romain Guy06882f82009-06-10 13:36:04 -07002686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 public void getWindowDisplayFrame(Session session, IWindow client,
2688 Rect outDisplayFrame) {
2689 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002690 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 if (win == null) {
2692 outDisplayFrame.setEmpty();
2693 return;
2694 }
2695 outDisplayFrame.set(win.mDisplayFrame);
2696 }
2697 }
2698
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002699 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2700 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002701 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2702 window.mWallpaperX = x;
2703 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002704 window.mWallpaperXStep = xStep;
2705 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002706 if (updateWallpaperOffsetLocked(window, true)) {
2707 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002708 }
2709 }
2710 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002711
Dianne Hackborn75804932009-10-20 20:15:20 -07002712 void wallpaperCommandComplete(IBinder window, Bundle result) {
2713 synchronized (mWindowMap) {
2714 if (mWaitingOnWallpaper != null &&
2715 mWaitingOnWallpaper.mClient.asBinder() == window) {
2716 mWaitingOnWallpaper = null;
2717 mWindowMap.notifyAll();
2718 }
2719 }
2720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002721
Dianne Hackborn75804932009-10-20 20:15:20 -07002722 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2723 String action, int x, int y, int z, Bundle extras, boolean sync) {
2724 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2725 || window == mUpperWallpaperTarget) {
2726 boolean doWait = sync;
2727 int curTokenIndex = mWallpaperTokens.size();
2728 while (curTokenIndex > 0) {
2729 curTokenIndex--;
2730 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2731 int curWallpaperIndex = token.windows.size();
2732 while (curWallpaperIndex > 0) {
2733 curWallpaperIndex--;
2734 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2735 try {
2736 wallpaper.mClient.dispatchWallpaperCommand(action,
2737 x, y, z, extras, sync);
2738 // We only want to be synchronous with one wallpaper.
2739 sync = false;
2740 } catch (RemoteException e) {
2741 }
2742 }
2743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002744
Dianne Hackborn75804932009-10-20 20:15:20 -07002745 if (doWait) {
2746 // XXX Need to wait for result.
2747 }
2748 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002749
Dianne Hackborn75804932009-10-20 20:15:20 -07002750 return null;
2751 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 public int relayoutWindow(Session session, IWindow client,
2754 WindowManager.LayoutParams attrs, int requestedWidth,
2755 int requestedHeight, int viewVisibility, boolean insetsPending,
2756 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002757 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002758 boolean displayed = false;
2759 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002760 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002764 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 if (win == null) {
2766 return 0;
2767 }
2768 win.mRequestedWidth = requestedWidth;
2769 win.mRequestedHeight = requestedHeight;
2770
2771 if (attrs != null) {
2772 mPolicy.adjustWindowParamsLw(attrs);
2773 }
Romain Guy06882f82009-06-10 13:36:04 -07002774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 int attrChanges = 0;
2776 int flagChanges = 0;
2777 if (attrs != null) {
2778 flagChanges = win.mAttrs.flags ^= attrs.flags;
2779 attrChanges = win.mAttrs.copyFrom(attrs);
2780 }
2781
Joe Onorato8a9b2202010-02-26 18:56:32 -08002782 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783
2784 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2785 win.mAlpha = attrs.alpha;
2786 }
2787
2788 final boolean scaledWindow =
2789 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2790
2791 if (scaledWindow) {
2792 // requested{Width|Height} Surface's physical size
2793 // attrs.{width|height} Size on screen
2794 win.mHScale = (attrs.width != requestedWidth) ?
2795 (attrs.width / (float)requestedWidth) : 1.0f;
2796 win.mVScale = (attrs.height != requestedHeight) ?
2797 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002798 } else {
2799 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 }
2801
2802 boolean imMayMove = (flagChanges&(
2803 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2804 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 boolean focusMayChange = win.mViewVisibility != viewVisibility
2807 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2808 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002809
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002810 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2811 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 win.mRelayoutCalled = true;
2814 final int oldVisibility = win.mViewVisibility;
2815 win.mViewVisibility = viewVisibility;
2816 if (viewVisibility == View.VISIBLE &&
2817 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2818 displayed = !win.isVisibleLw();
2819 if (win.mExiting) {
2820 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002821 if (win.mAnimation != null) {
2822 win.mAnimation.cancel();
2823 win.mAnimation = null;
2824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 }
2826 if (win.mDestroying) {
2827 win.mDestroying = false;
2828 mDestroySurface.remove(win);
2829 }
2830 if (oldVisibility == View.GONE) {
2831 win.mEnterAnimationPending = true;
2832 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002833 if (displayed) {
2834 if (win.mSurface != null && !win.mDrawPending
2835 && !win.mCommitDrawPending && !mDisplayFrozen
2836 && mPolicy.isScreenOn()) {
2837 applyEnterAnimationLocked(win);
2838 }
2839 if ((win.mAttrs.flags
2840 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2841 if (DEBUG_VISIBILITY) Slog.v(TAG,
2842 "Relayout window turning screen on: " + win);
2843 win.mTurnOnScreen = true;
2844 }
2845 int diff = 0;
2846 if (win.mConfiguration != mCurConfiguration
2847 && (win.mConfiguration == null
2848 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2849 win.mConfiguration = mCurConfiguration;
2850 if (DEBUG_CONFIGURATION) {
2851 Slog.i(TAG, "Window " + win + " visible with new config: "
2852 + win.mConfiguration + " / 0x"
2853 + Integer.toHexString(diff));
2854 }
2855 outConfig.setTo(mCurConfiguration);
2856 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002857 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2859 // To change the format, we need to re-build the surface.
2860 win.destroySurfaceLocked();
2861 displayed = true;
2862 }
2863 try {
2864 Surface surface = win.createSurfaceLocked();
2865 if (surface != null) {
2866 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002867 win.mReportDestroySurface = false;
2868 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002869 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002870 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002872 // For some reason there isn't a surface. Clear the
2873 // caller's object so they see the same state.
2874 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 }
2876 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002877 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002878
Joe Onorato8a9b2202010-02-26 18:56:32 -08002879 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002880 + client + " (" + win.mAttrs.getTitle() + ")",
2881 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 Binder.restoreCallingIdentity(origId);
2883 return 0;
2884 }
2885 if (displayed) {
2886 focusMayChange = true;
2887 }
2888 if (win.mAttrs.type == TYPE_INPUT_METHOD
2889 && mInputMethodWindow == null) {
2890 mInputMethodWindow = win;
2891 imMayMove = true;
2892 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002893 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2894 && win.mAppToken != null
2895 && win.mAppToken.startingWindow != null) {
2896 // Special handling of starting window over the base
2897 // window of the app: propagate lock screen flags to it,
2898 // to provide the correct semantics while starting.
2899 final int mask =
2900 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002901 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2902 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002903 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2904 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 } else {
2907 win.mEnterAnimationPending = false;
2908 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002909 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002910 + ": mExiting=" + win.mExiting
2911 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 // If we are not currently running the exit animation, we
2913 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002914 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 // Try starting an animation; if there isn't one, we
2916 // can destroy the surface right away.
2917 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2918 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2919 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2920 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002921 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002923 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 } else if (win.isAnimating()) {
2926 // Currently in a hide animation... turn this into
2927 // an exit.
2928 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002929 } else if (win == mWallpaperTarget) {
2930 // If the wallpaper is currently behind this
2931 // window, we need to change both of them inside
2932 // of a transaction to avoid artifacts.
2933 win.mExiting = true;
2934 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 } else {
2936 if (mInputMethodWindow == win) {
2937 mInputMethodWindow = null;
2938 }
2939 win.destroySurfaceLocked();
2940 }
2941 }
2942 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002943
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002944 if (win.mSurface == null || (win.getAttrs().flags
2945 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2946 || win.mSurfacePendingDestroy) {
2947 // We are being called from a local process, which
2948 // means outSurface holds its current surface. Ensure the
2949 // surface object is cleared, but we don't want it actually
2950 // destroyed at this point.
2951 win.mSurfacePendingDestroy = false;
2952 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002953 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002954 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002955 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002956 "Keeping surface, will report destroy: " + win);
2957 win.mReportDestroySurface = true;
2958 outSurface.copyFrom(win.mSurface);
2959 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 }
2961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 if (focusMayChange) {
2963 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002964 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2965 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 imMayMove = false;
2967 }
2968 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2969 }
Romain Guy06882f82009-06-10 13:36:04 -07002970
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002971 // updateFocusedWindowLocked() already assigned layers so we only need to
2972 // reassign them at this point if the IM window state gets shuffled
2973 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002976 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2977 // Little hack here -- we -should- be able to rely on the
2978 // function to return true if the IME has moved and needs
2979 // its layer recomputed. However, if the IME was hidden
2980 // and isn't actually moved in the list, its layer may be
2981 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 assignLayers = true;
2983 }
2984 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002985 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002986 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002987 assignLayers = true;
2988 }
2989 }
Romain Guy06882f82009-06-10 13:36:04 -07002990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 mLayoutNeeded = true;
2992 win.mGivenInsetsPending = insetsPending;
2993 if (assignLayers) {
2994 assignLayersLocked();
2995 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002996 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002998 if (displayed && win.mIsWallpaper) {
2999 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07003000 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07003001 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 if (win.mAppToken != null) {
3003 win.mAppToken.updateReportedVisibilityLocked();
3004 }
3005 outFrame.set(win.mFrame);
3006 outContentInsets.set(win.mContentInsets);
3007 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003008 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07003010 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 + ", requestedHeight=" + requestedHeight
3012 + ", viewVisibility=" + viewVisibility
3013 + "\nRelayout returning frame=" + outFrame
3014 + ", surface=" + outSurface);
3015
Joe Onorato8a9b2202010-02-26 18:56:32 -08003016 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003017 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3018
3019 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003020
Jeff Brown2e44b072011-01-24 15:21:56 -08003021 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 }
3023
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003024 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 sendNewConfiguration();
3026 }
Romain Guy06882f82009-06-10 13:36:04 -07003027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003028 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3031 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3032 }
3033
3034 public void finishDrawingWindow(Session session, IWindow client) {
3035 final long origId = Binder.clearCallingIdentity();
3036 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003037 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003039 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3040 adjustWallpaperWindowsLocked();
3041 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 mLayoutNeeded = true;
3043 performLayoutAndPlaceSurfacesLocked();
3044 }
3045 }
3046 Binder.restoreCallingIdentity(origId);
3047 }
3048
3049 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003050 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051 + (lp != null ? lp.packageName : null)
3052 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3053 if (lp != null && lp.windowAnimations != 0) {
3054 // If this is a system resource, don't try to load it from the
3055 // application resources. It is nice to avoid loading application
3056 // resources if we can.
3057 String packageName = lp.packageName != null ? lp.packageName : "android";
3058 int resId = lp.windowAnimations;
3059 if ((resId&0xFF000000) == 0x01000000) {
3060 packageName = "android";
3061 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003062 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 + packageName);
3064 return AttributeCache.instance().get(packageName, resId,
3065 com.android.internal.R.styleable.WindowAnimation);
3066 }
3067 return null;
3068 }
Romain Guy06882f82009-06-10 13:36:04 -07003069
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003070 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003071 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003072 + packageName + " resId=0x" + Integer.toHexString(resId));
3073 if (packageName != null) {
3074 if ((resId&0xFF000000) == 0x01000000) {
3075 packageName = "android";
3076 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003077 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003078 + packageName);
3079 return AttributeCache.instance().get(packageName, resId,
3080 com.android.internal.R.styleable.WindowAnimation);
3081 }
3082 return null;
3083 }
3084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003085 private void applyEnterAnimationLocked(WindowState win) {
3086 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3087 if (win.mEnterAnimationPending) {
3088 win.mEnterAnimationPending = false;
3089 transit = WindowManagerPolicy.TRANSIT_ENTER;
3090 }
3091
3092 applyAnimationLocked(win, transit, true);
3093 }
3094
3095 private boolean applyAnimationLocked(WindowState win,
3096 int transit, boolean isEntrance) {
3097 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3098 // If we are trying to apply an animation, but already running
3099 // an animation of the same type, then just leave that one alone.
3100 return true;
3101 }
Romain Guy06882f82009-06-10 13:36:04 -07003102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003103 // Only apply an animation if the display isn't frozen. If it is
3104 // frozen, there is no reason to animate and it can cause strange
3105 // artifacts when we unfreeze the display if some different animation
3106 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003107 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003108 int anim = mPolicy.selectAnimationLw(win, transit);
3109 int attr = -1;
3110 Animation a = null;
3111 if (anim != 0) {
3112 a = AnimationUtils.loadAnimation(mContext, anim);
3113 } else {
3114 switch (transit) {
3115 case WindowManagerPolicy.TRANSIT_ENTER:
3116 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3117 break;
3118 case WindowManagerPolicy.TRANSIT_EXIT:
3119 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3120 break;
3121 case WindowManagerPolicy.TRANSIT_SHOW:
3122 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3123 break;
3124 case WindowManagerPolicy.TRANSIT_HIDE:
3125 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3126 break;
3127 }
3128 if (attr >= 0) {
3129 a = loadAnimation(win.mAttrs, attr);
3130 }
3131 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003132 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3134 + " mAnimation=" + win.mAnimation
3135 + " isEntrance=" + isEntrance);
3136 if (a != null) {
3137 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003138 RuntimeException e = null;
3139 if (!HIDE_STACK_CRAWLS) {
3140 e = new RuntimeException();
3141 e.fillInStackTrace();
3142 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003143 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 }
3145 win.setAnimation(a);
3146 win.mAnimationIsEntrance = isEntrance;
3147 }
3148 } else {
3149 win.clearAnimation();
3150 }
3151
3152 return win.mAnimation != null;
3153 }
3154
3155 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3156 int anim = 0;
3157 Context context = mContext;
3158 if (animAttr >= 0) {
3159 AttributeCache.Entry ent = getCachedAnimations(lp);
3160 if (ent != null) {
3161 context = ent.context;
3162 anim = ent.array.getResourceId(animAttr, 0);
3163 }
3164 }
3165 if (anim != 0) {
3166 return AnimationUtils.loadAnimation(context, anim);
3167 }
3168 return null;
3169 }
Romain Guy06882f82009-06-10 13:36:04 -07003170
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003171 private Animation loadAnimation(String packageName, int resId) {
3172 int anim = 0;
3173 Context context = mContext;
3174 if (resId >= 0) {
3175 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3176 if (ent != null) {
3177 context = ent.context;
3178 anim = resId;
3179 }
3180 }
3181 if (anim != 0) {
3182 return AnimationUtils.loadAnimation(context, anim);
3183 }
3184 return null;
3185 }
3186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 private boolean applyAnimationLocked(AppWindowToken wtoken,
3188 WindowManager.LayoutParams lp, int transit, boolean enter) {
3189 // Only apply an animation if the display isn't frozen. If it is
3190 // frozen, there is no reason to animate and it can cause strange
3191 // artifacts when we unfreeze the display if some different animation
3192 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003193 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003194 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003195 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003196 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003197 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003198 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003199 } else if (mNextAppTransitionPackage != null) {
3200 a = loadAnimation(mNextAppTransitionPackage, enter ?
3201 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003202 } else {
3203 int animAttr = 0;
3204 switch (transit) {
3205 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3206 animAttr = enter
3207 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3208 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3209 break;
3210 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3211 animAttr = enter
3212 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3213 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3214 break;
3215 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3216 animAttr = enter
3217 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3218 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3219 break;
3220 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3221 animAttr = enter
3222 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3223 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3224 break;
3225 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3226 animAttr = enter
3227 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3228 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3229 break;
3230 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3231 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003232 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003233 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3234 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003235 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003236 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003237 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3238 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003239 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003240 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003241 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003242 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3243 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3244 break;
3245 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3246 animAttr = enter
3247 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3248 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3249 break;
3250 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3251 animAttr = enter
3252 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3253 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003254 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003255 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003256 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003257 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003258 + " anim=" + a
3259 + " animAttr=0x" + Integer.toHexString(animAttr)
3260 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 if (a != null) {
3263 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003264 RuntimeException e = null;
3265 if (!HIDE_STACK_CRAWLS) {
3266 e = new RuntimeException();
3267 e.fillInStackTrace();
3268 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003269 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 }
3271 wtoken.setAnimation(a);
3272 }
3273 } else {
3274 wtoken.clearAnimation();
3275 }
3276
3277 return wtoken.animation != null;
3278 }
3279
3280 // -------------------------------------------------------------
3281 // Application Window Tokens
3282 // -------------------------------------------------------------
3283
3284 public void validateAppTokens(List tokens) {
3285 int v = tokens.size()-1;
3286 int m = mAppTokens.size()-1;
3287 while (v >= 0 && m >= 0) {
3288 AppWindowToken wtoken = mAppTokens.get(m);
3289 if (wtoken.removed) {
3290 m--;
3291 continue;
3292 }
3293 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003294 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3296 }
3297 v--;
3298 m--;
3299 }
3300 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003301 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 v--;
3303 }
3304 while (m >= 0) {
3305 AppWindowToken wtoken = mAppTokens.get(m);
3306 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003307 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 }
3309 m--;
3310 }
3311 }
3312
3313 boolean checkCallingPermission(String permission, String func) {
3314 // Quick check: if the calling permission is me, it's all okay.
3315 if (Binder.getCallingPid() == Process.myPid()) {
3316 return true;
3317 }
Romain Guy06882f82009-06-10 13:36:04 -07003318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 if (mContext.checkCallingPermission(permission)
3320 == PackageManager.PERMISSION_GRANTED) {
3321 return true;
3322 }
3323 String msg = "Permission Denial: " + func + " from pid="
3324 + Binder.getCallingPid()
3325 + ", uid=" + Binder.getCallingUid()
3326 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003327 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 return false;
3329 }
Romain Guy06882f82009-06-10 13:36:04 -07003330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 AppWindowToken findAppWindowToken(IBinder token) {
3332 WindowToken wtoken = mTokenMap.get(token);
3333 if (wtoken == null) {
3334 return null;
3335 }
3336 return wtoken.appWindowToken;
3337 }
Romain Guy06882f82009-06-10 13:36:04 -07003338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 public void addWindowToken(IBinder token, int type) {
3340 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3341 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003342 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 }
Romain Guy06882f82009-06-10 13:36:04 -07003344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 synchronized(mWindowMap) {
3346 WindowToken wtoken = mTokenMap.get(token);
3347 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003348 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 return;
3350 }
3351 wtoken = new WindowToken(token, type, true);
3352 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003353 if (type == TYPE_WALLPAPER) {
3354 mWallpaperTokens.add(wtoken);
3355 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 }
3357 }
Romain Guy06882f82009-06-10 13:36:04 -07003358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 public void removeWindowToken(IBinder token) {
3360 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3361 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003362 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 }
3364
3365 final long origId = Binder.clearCallingIdentity();
3366 synchronized(mWindowMap) {
3367 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 if (wtoken != null) {
3369 boolean delayed = false;
3370 if (!wtoken.hidden) {
3371 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 final int N = wtoken.windows.size();
3374 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 for (int i=0; i<N; i++) {
3377 WindowState win = wtoken.windows.get(i);
3378
3379 if (win.isAnimating()) {
3380 delayed = true;
3381 }
Romain Guy06882f82009-06-10 13:36:04 -07003382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 if (win.isVisibleNow()) {
3384 applyAnimationLocked(win,
3385 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 changed = true;
3387 }
3388 }
3389
3390 if (changed) {
3391 mLayoutNeeded = true;
3392 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003393 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3394 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 }
Romain Guy06882f82009-06-10 13:36:04 -07003396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 if (delayed) {
3398 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003399 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3400 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003401 }
3402 }
Romain Guy06882f82009-06-10 13:36:04 -07003403
Jeff Brown2e44b072011-01-24 15:21:56 -08003404 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003406 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 }
3408 }
3409 Binder.restoreCallingIdentity(origId);
3410 }
3411
3412 public void addAppToken(int addPos, IApplicationToken token,
3413 int groupId, int requestedOrientation, boolean fullscreen) {
3414 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3415 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003416 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417 }
Jeff Brown349703e2010-06-22 01:27:15 -07003418
3419 // Get the dispatching timeout here while we are not holding any locks so that it
3420 // can be cached by the AppWindowToken. The timeout value is used later by the
3421 // input dispatcher in code that does hold locks. If we did not cache the value
3422 // here we would run the chance of introducing a deadlock between the window manager
3423 // (which holds locks while updating the input dispatcher state) and the activity manager
3424 // (which holds locks while querying the application token).
3425 long inputDispatchingTimeoutNanos;
3426 try {
3427 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3428 } catch (RemoteException ex) {
3429 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3430 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3431 }
Romain Guy06882f82009-06-10 13:36:04 -07003432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433 synchronized(mWindowMap) {
3434 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3435 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003436 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 return;
3438 }
3439 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003440 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 wtoken.groupId = groupId;
3442 wtoken.appFullscreen = fullscreen;
3443 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003444 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003445 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 // Application tokens start out hidden.
3449 wtoken.hidden = true;
3450 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003452 //dump();
3453 }
3454 }
Romain Guy06882f82009-06-10 13:36:04 -07003455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 public void setAppGroupId(IBinder token, int groupId) {
3457 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3458 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003459 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 }
3461
3462 synchronized(mWindowMap) {
3463 AppWindowToken wtoken = findAppWindowToken(token);
3464 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003465 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 return;
3467 }
3468 wtoken.groupId = groupId;
3469 }
3470 }
Romain Guy06882f82009-06-10 13:36:04 -07003471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 public int getOrientationFromWindowsLocked() {
3473 int pos = mWindows.size() - 1;
3474 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003475 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 pos--;
3477 if (wtoken.mAppToken != null) {
3478 // We hit an application window. so the orientation will be determined by the
3479 // app window. No point in continuing further.
3480 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3481 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003482 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 continue;
3484 }
3485 int req = wtoken.mAttrs.screenOrientation;
3486 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3487 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3488 continue;
3489 } else {
3490 return req;
3491 }
3492 }
3493 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3494 }
Romain Guy06882f82009-06-10 13:36:04 -07003495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003497 int pos = mAppTokens.size() - 1;
3498 int curGroup = 0;
3499 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3500 boolean findingBehind = false;
3501 boolean haveGroup = false;
3502 boolean lastFullscreen = false;
3503 while (pos >= 0) {
3504 AppWindowToken wtoken = mAppTokens.get(pos);
3505 pos--;
3506 // if we're about to tear down this window and not seek for
3507 // the behind activity, don't use it for orientation
3508 if (!findingBehind
3509 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3510 continue;
3511 }
3512
3513 if (!haveGroup) {
3514 // We ignore any hidden applications on the top.
3515 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003516 continue;
3517 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003518 haveGroup = true;
3519 curGroup = wtoken.groupId;
3520 lastOrientation = wtoken.requestedOrientation;
3521 } else if (curGroup != wtoken.groupId) {
3522 // If we have hit a new application group, and the bottom
3523 // of the previous group didn't explicitly say to use
3524 // the orientation behind it, and the last app was
3525 // full screen, then we'll stick with the
3526 // user's orientation.
3527 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3528 && lastFullscreen) {
3529 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003532 int or = wtoken.requestedOrientation;
3533 // If this application is fullscreen, and didn't explicitly say
3534 // to use the orientation behind it, then just take whatever
3535 // orientation it has and ignores whatever is under it.
3536 lastFullscreen = wtoken.appFullscreen;
3537 if (lastFullscreen
3538 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3539 return or;
3540 }
3541 // If this application has requested an explicit orientation,
3542 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003543 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3544 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003545 return or;
3546 }
3547 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3548 }
3549 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 }
Romain Guy06882f82009-06-10 13:36:04 -07003551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003553 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003554 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3555 "updateOrientationFromAppTokens()")) {
3556 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003558
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003559 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003561
3562 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003563 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003564 if (freezeThisOneIfNeeded != null) {
3565 AppWindowToken wtoken = findAppWindowToken(
3566 freezeThisOneIfNeeded);
3567 if (wtoken != null) {
3568 startAppFreezingScreenLocked(wtoken,
3569 ActivityInfo.CONFIG_ORIENTATION);
3570 }
3571 }
3572 config = computeNewConfigurationLocked();
3573
3574 } else if (currentConfig != null) {
3575 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003576 // state mismatches the activity manager's, update it,
3577 // disregarding font scale, which should remain set to
3578 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003579 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003580 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003581 if (computeNewConfigurationLocked(mTempConfiguration)) {
3582 if (currentConfig.diff(mTempConfiguration) != 0) {
3583 mWaitingForConfig = true;
3584 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003585 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003586 config = new Configuration(mTempConfiguration);
3587 }
3588 }
3589 }
3590 }
3591
Dianne Hackborncfaef692009-06-15 14:24:44 -07003592 Binder.restoreCallingIdentity(ident);
3593 return config;
3594 }
3595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003597 * Determine the new desired orientation of the display, returning
3598 * a non-null new Configuration if it has changed from the current
3599 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3600 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3601 * SCREEN. This will typically be done for you if you call
3602 * sendNewConfiguration().
3603 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 * The orientation is computed from non-application windows first. If none of
3605 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003606 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3608 * android.os.IBinder)
3609 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003610 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3611 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003612 // If the display is frozen, some activities may be in the middle
3613 // of restarting, and thus have removed their old window. If the
3614 // window has the flag to hide the lock screen, then the lock screen
3615 // can re-appear and inflict its own orientation on us. Keep the
3616 // orientation stable until this all settles down.
3617 return false;
3618 }
3619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 long ident = Binder.clearCallingIdentity();
3622 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003623 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 mForcedAppOrientation = req;
3627 //send a message to Policy indicating orientation change to take
3628 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003629 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003630 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003631 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3632 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003633 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 }
3635 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003636
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003637 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 } finally {
3639 Binder.restoreCallingIdentity(ident);
3640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 }
Romain Guy06882f82009-06-10 13:36:04 -07003642
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003643 int computeForcedAppOrientationLocked() {
3644 int req = getOrientationFromWindowsLocked();
3645 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3646 req = getOrientationFromAppTokensLocked();
3647 }
3648 return req;
3649 }
Romain Guy06882f82009-06-10 13:36:04 -07003650
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003651 public void setNewConfiguration(Configuration config) {
3652 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3653 "setNewConfiguration()")) {
3654 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3655 }
3656
3657 synchronized(mWindowMap) {
3658 mCurConfiguration = new Configuration(config);
3659 mWaitingForConfig = false;
3660 performLayoutAndPlaceSurfacesLocked();
3661 }
3662 }
3663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3665 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3666 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003667 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 }
Romain Guy06882f82009-06-10 13:36:04 -07003669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 synchronized(mWindowMap) {
3671 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3672 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003673 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 return;
3675 }
Romain Guy06882f82009-06-10 13:36:04 -07003676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 wtoken.requestedOrientation = requestedOrientation;
3678 }
3679 }
Romain Guy06882f82009-06-10 13:36:04 -07003680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 public int getAppOrientation(IApplicationToken token) {
3682 synchronized(mWindowMap) {
3683 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3684 if (wtoken == null) {
3685 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3686 }
Romain Guy06882f82009-06-10 13:36:04 -07003687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 return wtoken.requestedOrientation;
3689 }
3690 }
Romain Guy06882f82009-06-10 13:36:04 -07003691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3693 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3694 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003695 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 }
3697
3698 synchronized(mWindowMap) {
3699 boolean changed = false;
3700 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003701 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 changed = mFocusedApp != null;
3703 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003704 if (changed) {
3705 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003706 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 } else {
3708 AppWindowToken newFocus = findAppWindowToken(token);
3709 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003710 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 return;
3712 }
3713 changed = mFocusedApp != newFocus;
3714 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003715 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003716 if (changed) {
3717 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003718 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 }
3720
3721 if (moveFocusNow && changed) {
3722 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003723 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 Binder.restoreCallingIdentity(origId);
3725 }
3726 }
3727 }
3728
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003729 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3731 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003732 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 }
Romain Guy06882f82009-06-10 13:36:04 -07003734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003736 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 TAG, "Prepare app transition: transit=" + transit
3738 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003739 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003740 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3741 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003743 } else if (!alwaysKeepCurrent) {
3744 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3745 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3746 // Opening a new task always supersedes a close for the anim.
3747 mNextAppTransition = transit;
3748 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3749 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3750 // Opening a new activity always supersedes a close for the anim.
3751 mNextAppTransition = transit;
3752 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 }
3754 mAppTransitionReady = false;
3755 mAppTransitionTimeout = false;
3756 mStartingIconInTransition = false;
3757 mSkipAppTransitionAnimation = false;
3758 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3759 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3760 5000);
3761 }
3762 }
3763 }
3764
3765 public int getPendingAppTransition() {
3766 return mNextAppTransition;
3767 }
Romain Guy06882f82009-06-10 13:36:04 -07003768
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003769 public void overridePendingAppTransition(String packageName,
3770 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003771 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003772 mNextAppTransitionPackage = packageName;
3773 mNextAppTransitionEnter = enterAnim;
3774 mNextAppTransitionExit = exitAnim;
3775 }
3776 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 public void executeAppTransition() {
3779 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3780 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003781 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 }
Romain Guy06882f82009-06-10 13:36:04 -07003783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003785 if (DEBUG_APP_TRANSITIONS) {
3786 RuntimeException e = new RuntimeException("here");
3787 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003788 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003789 + mNextAppTransition, e);
3790 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003791 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 mAppTransitionReady = true;
3793 final long origId = Binder.clearCallingIdentity();
3794 performLayoutAndPlaceSurfacesLocked();
3795 Binder.restoreCallingIdentity(origId);
3796 }
3797 }
3798 }
3799
3800 public void setAppStartingWindow(IBinder token, String pkg,
3801 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003802 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3804 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003805 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 }
3807
3808 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003809 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3811 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 AppWindowToken wtoken = findAppWindowToken(token);
3814 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003815 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 return;
3817 }
3818
3819 // If the display is frozen, we won't do anything until the
3820 // actual window is displayed so there is no reason to put in
3821 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003822 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 return;
3824 }
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 if (wtoken.startingData != null) {
3827 return;
3828 }
Romain Guy06882f82009-06-10 13:36:04 -07003829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 if (transferFrom != null) {
3831 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3832 if (ttoken != null) {
3833 WindowState startingWindow = ttoken.startingWindow;
3834 if (startingWindow != null) {
3835 if (mStartingIconInTransition) {
3836 // In this case, the starting icon has already
3837 // been displayed, so start letting windows get
3838 // shown immediately without any more transitions.
3839 mSkipAppTransitionAnimation = true;
3840 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003841 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 "Moving existing starting from " + ttoken
3843 + " to " + wtoken);
3844 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 // Transfer the starting window over to the new
3847 // token.
3848 wtoken.startingData = ttoken.startingData;
3849 wtoken.startingView = ttoken.startingView;
3850 wtoken.startingWindow = startingWindow;
3851 ttoken.startingData = null;
3852 ttoken.startingView = null;
3853 ttoken.startingWindow = null;
3854 ttoken.startingMoved = true;
3855 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003856 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003858 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003859 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003861 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003862 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3863 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 ttoken.windows.remove(startingWindow);
3865 ttoken.allAppWindows.remove(startingWindow);
3866 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 // Propagate other interesting state between the
3869 // tokens. If the old token is displayed, we should
3870 // immediately force the new one to be displayed. If
3871 // it is animating, we need to move that animation to
3872 // the new one.
3873 if (ttoken.allDrawn) {
3874 wtoken.allDrawn = true;
3875 }
3876 if (ttoken.firstWindowDrawn) {
3877 wtoken.firstWindowDrawn = true;
3878 }
3879 if (!ttoken.hidden) {
3880 wtoken.hidden = false;
3881 wtoken.hiddenRequested = false;
3882 wtoken.willBeHidden = false;
3883 }
3884 if (wtoken.clientHidden != ttoken.clientHidden) {
3885 wtoken.clientHidden = ttoken.clientHidden;
3886 wtoken.sendAppVisibilityToClients();
3887 }
3888 if (ttoken.animation != null) {
3889 wtoken.animation = ttoken.animation;
3890 wtoken.animating = ttoken.animating;
3891 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3892 ttoken.animation = null;
3893 ttoken.animLayerAdjustment = 0;
3894 wtoken.updateLayers();
3895 ttoken.updateLayers();
3896 }
Romain Guy06882f82009-06-10 13:36:04 -07003897
Jeff Brown3a22cd92011-01-21 13:59:04 -08003898 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3899 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003900 mLayoutNeeded = true;
3901 performLayoutAndPlaceSurfacesLocked();
3902 Binder.restoreCallingIdentity(origId);
3903 return;
3904 } else if (ttoken.startingData != null) {
3905 // The previous app was getting ready to show a
3906 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003907 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003908 "Moving pending starting from " + ttoken
3909 + " to " + wtoken);
3910 wtoken.startingData = ttoken.startingData;
3911 ttoken.startingData = null;
3912 ttoken.startingMoved = true;
3913 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3914 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3915 // want to process the message ASAP, before any other queued
3916 // messages.
3917 mH.sendMessageAtFrontOfQueue(m);
3918 return;
3919 }
3920 }
3921 }
3922
3923 // There is no existing starting window, and the caller doesn't
3924 // want us to create one, so that's it!
3925 if (!createIfNeeded) {
3926 return;
3927 }
Romain Guy06882f82009-06-10 13:36:04 -07003928
Dianne Hackborn284ac932009-08-28 10:34:25 -07003929 // If this is a translucent or wallpaper window, then don't
3930 // show a starting window -- the current effect (a full-screen
3931 // opaque starting window that fades away to the real contents
3932 // when it is ready) does not work for this.
3933 if (theme != 0) {
3934 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3935 com.android.internal.R.styleable.Window);
3936 if (ent.array.getBoolean(
3937 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3938 return;
3939 }
3940 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003941 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3942 return;
3943 }
3944 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003945 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3946 return;
3947 }
3948 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 mStartingIconInTransition = true;
3951 wtoken.startingData = new StartingData(
3952 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003953 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3955 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3956 // want to process the message ASAP, before any other queued
3957 // messages.
3958 mH.sendMessageAtFrontOfQueue(m);
3959 }
3960 }
3961
3962 public void setAppWillBeHidden(IBinder token) {
3963 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3964 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003965 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 }
3967
3968 AppWindowToken wtoken;
3969
3970 synchronized(mWindowMap) {
3971 wtoken = findAppWindowToken(token);
3972 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003973 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 -08003974 return;
3975 }
3976 wtoken.willBeHidden = true;
3977 }
3978 }
Romain Guy06882f82009-06-10 13:36:04 -07003979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3981 boolean visible, int transit, boolean performLayout) {
3982 boolean delayed = false;
3983
3984 if (wtoken.clientHidden == visible) {
3985 wtoken.clientHidden = !visible;
3986 wtoken.sendAppVisibilityToClients();
3987 }
Romain Guy06882f82009-06-10 13:36:04 -07003988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 wtoken.willBeHidden = false;
3990 if (wtoken.hidden == visible) {
3991 final int N = wtoken.allAppWindows.size();
3992 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003993 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3995 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003998
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003999 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 if (wtoken.animation == sDummyAnimation) {
4001 wtoken.animation = null;
4002 }
4003 applyAnimationLocked(wtoken, lp, transit, visible);
4004 changed = true;
4005 if (wtoken.animation != null) {
4006 delayed = runningAppAnimation = true;
4007 }
4008 }
Romain Guy06882f82009-06-10 13:36:04 -07004009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 for (int i=0; i<N; i++) {
4011 WindowState win = wtoken.allAppWindows.get(i);
4012 if (win == wtoken.startingWindow) {
4013 continue;
4014 }
4015
4016 if (win.isAnimating()) {
4017 delayed = true;
4018 }
Romain Guy06882f82009-06-10 13:36:04 -07004019
Joe Onorato8a9b2202010-02-26 18:56:32 -08004020 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004021 //win.dump(" ");
4022 if (visible) {
4023 if (!win.isVisibleNow()) {
4024 if (!runningAppAnimation) {
4025 applyAnimationLocked(win,
4026 WindowManagerPolicy.TRANSIT_ENTER, true);
4027 }
4028 changed = true;
4029 }
4030 } else if (win.isVisibleNow()) {
4031 if (!runningAppAnimation) {
4032 applyAnimationLocked(win,
4033 WindowManagerPolicy.TRANSIT_EXIT, false);
4034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 changed = true;
4036 }
4037 }
4038
4039 wtoken.hidden = wtoken.hiddenRequested = !visible;
4040 if (!visible) {
4041 unsetAppFreezingScreenLocked(wtoken, true, true);
4042 } else {
4043 // If we are being set visible, and the starting window is
4044 // not yet displayed, then make sure it doesn't get displayed.
4045 WindowState swin = wtoken.startingWindow;
4046 if (swin != null && (swin.mDrawPending
4047 || swin.mCommitDrawPending)) {
4048 swin.mPolicyVisibility = false;
4049 swin.mPolicyVisibilityAfterAnim = false;
4050 }
4051 }
Romain Guy06882f82009-06-10 13:36:04 -07004052
Joe Onorato8a9b2202010-02-26 18:56:32 -08004053 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4055 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004056
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004057 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004058 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004059 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004060 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004061 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4062 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004063 performLayoutAndPlaceSurfacesLocked();
4064 }
Jeff Brown2e44b072011-01-24 15:21:56 -08004065 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004066 }
4067 }
4068
4069 if (wtoken.animation != null) {
4070 delayed = true;
4071 }
Romain Guy06882f82009-06-10 13:36:04 -07004072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004073 return delayed;
4074 }
4075
4076 public void setAppVisibility(IBinder token, boolean visible) {
4077 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4078 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004079 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004080 }
4081
4082 AppWindowToken wtoken;
4083
4084 synchronized(mWindowMap) {
4085 wtoken = findAppWindowToken(token);
4086 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004087 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 return;
4089 }
4090
4091 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004092 RuntimeException e = null;
4093 if (!HIDE_STACK_CRAWLS) {
4094 e = new RuntimeException();
4095 e.fillInStackTrace();
4096 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004097 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 + "): mNextAppTransition=" + mNextAppTransition
4099 + " hidden=" + wtoken.hidden
4100 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4101 }
Romain Guy06882f82009-06-10 13:36:04 -07004102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004103 // If we are preparing an app transition, then delay changing
4104 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004105 if (!mDisplayFrozen && mPolicy.isScreenOn()
4106 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004107 // Already in requested state, don't do anything more.
4108 if (wtoken.hiddenRequested != visible) {
4109 return;
4110 }
4111 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004112
Joe Onorato8a9b2202010-02-26 18:56:32 -08004113 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 TAG, "Setting dummy animation on: " + wtoken);
4115 wtoken.setDummyAnimation();
4116 mOpeningApps.remove(wtoken);
4117 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004118 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 wtoken.inPendingTransaction = true;
4120 if (visible) {
4121 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004122 wtoken.startingDisplayed = false;
4123 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004124
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004125 // If the token is currently hidden (should be the
4126 // common case), then we need to set up to wait for
4127 // its windows to be ready.
4128 if (wtoken.hidden) {
4129 wtoken.allDrawn = false;
4130 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004131
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004132 if (wtoken.clientHidden) {
4133 // In the case where we are making an app visible
4134 // but holding off for a transition, we still need
4135 // to tell the client to make its windows visible so
4136 // they get drawn. Otherwise, we will wait on
4137 // performing the transition until all windows have
4138 // been drawn, they never will be, and we are sad.
4139 wtoken.clientHidden = false;
4140 wtoken.sendAppVisibilityToClients();
4141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004142 }
4143 } else {
4144 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004145
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004146 // If the token is currently visible (should be the
4147 // common case), then set up to wait for it to be hidden.
4148 if (!wtoken.hidden) {
4149 wtoken.waitingToHide = true;
4150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 }
4152 return;
4153 }
Romain Guy06882f82009-06-10 13:36:04 -07004154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004155 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004156 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004157 wtoken.updateReportedVisibilityLocked();
4158 Binder.restoreCallingIdentity(origId);
4159 }
4160 }
4161
4162 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4163 boolean unfreezeSurfaceNow, boolean force) {
4164 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004165 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 + " force=" + force);
4167 final int N = wtoken.allAppWindows.size();
4168 boolean unfrozeWindows = false;
4169 for (int i=0; i<N; i++) {
4170 WindowState w = wtoken.allAppWindows.get(i);
4171 if (w.mAppFreezing) {
4172 w.mAppFreezing = false;
4173 if (w.mSurface != null && !w.mOrientationChanging) {
4174 w.mOrientationChanging = true;
4175 }
4176 unfrozeWindows = true;
4177 }
4178 }
4179 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004180 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 wtoken.freezingScreen = false;
4182 mAppsFreezingScreen--;
4183 }
4184 if (unfreezeSurfaceNow) {
4185 if (unfrozeWindows) {
4186 mLayoutNeeded = true;
4187 performLayoutAndPlaceSurfacesLocked();
4188 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004189 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190 }
4191 }
4192 }
Romain Guy06882f82009-06-10 13:36:04 -07004193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4195 int configChanges) {
4196 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004197 RuntimeException e = null;
4198 if (!HIDE_STACK_CRAWLS) {
4199 e = new RuntimeException();
4200 e.fillInStackTrace();
4201 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004202 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004203 + ": hidden=" + wtoken.hidden + " freezing="
4204 + wtoken.freezingScreen, e);
4205 }
4206 if (!wtoken.hiddenRequested) {
4207 if (!wtoken.freezingScreen) {
4208 wtoken.freezingScreen = true;
4209 mAppsFreezingScreen++;
4210 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004211 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004212 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4213 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4214 5000);
4215 }
4216 }
4217 final int N = wtoken.allAppWindows.size();
4218 for (int i=0; i<N; i++) {
4219 WindowState w = wtoken.allAppWindows.get(i);
4220 w.mAppFreezing = true;
4221 }
4222 }
4223 }
Romain Guy06882f82009-06-10 13:36:04 -07004224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 public void startAppFreezingScreen(IBinder token, int configChanges) {
4226 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4227 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004228 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 }
4230
4231 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004232 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004233 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004234 return;
4235 }
Romain Guy06882f82009-06-10 13:36:04 -07004236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004237 AppWindowToken wtoken = findAppWindowToken(token);
4238 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004239 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004240 return;
4241 }
4242 final long origId = Binder.clearCallingIdentity();
4243 startAppFreezingScreenLocked(wtoken, configChanges);
4244 Binder.restoreCallingIdentity(origId);
4245 }
4246 }
Romain Guy06882f82009-06-10 13:36:04 -07004247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 public void stopAppFreezingScreen(IBinder token, boolean force) {
4249 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4250 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004251 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 }
4253
4254 synchronized(mWindowMap) {
4255 AppWindowToken wtoken = findAppWindowToken(token);
4256 if (wtoken == null || wtoken.appToken == null) {
4257 return;
4258 }
4259 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004260 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4262 unsetAppFreezingScreenLocked(wtoken, true, force);
4263 Binder.restoreCallingIdentity(origId);
4264 }
4265 }
Romain Guy06882f82009-06-10 13:36:04 -07004266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 public void removeAppToken(IBinder token) {
4268 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4269 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004270 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 }
4272
4273 AppWindowToken wtoken = null;
4274 AppWindowToken startingToken = null;
4275 boolean delayed = false;
4276
4277 final long origId = Binder.clearCallingIdentity();
4278 synchronized(mWindowMap) {
4279 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004281 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004282 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004283 wtoken.inPendingTransaction = false;
4284 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004285 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 if (mClosingApps.contains(wtoken)) {
4287 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004288 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004290 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 delayed = true;
4292 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004293 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 TAG, "Removing app " + wtoken + " delayed=" + delayed
4295 + " animation=" + wtoken.animation
4296 + " animating=" + wtoken.animating);
4297 if (delayed) {
4298 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004299 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4300 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004302 } else {
4303 // Make sure there is no animation running on this token,
4304 // so any windows associated with it will be removed as
4305 // soon as their animations are complete
4306 wtoken.animation = null;
4307 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004309 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4310 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 mAppTokens.remove(wtoken);
4312 wtoken.removed = true;
4313 if (wtoken.startingData != null) {
4314 startingToken = wtoken;
4315 }
4316 unsetAppFreezingScreenLocked(wtoken, true, true);
4317 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004318 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004320 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004321 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 }
4323 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004324 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Romain Guy06882f82009-06-10 13:36:04 -07004326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 if (!delayed && wtoken != null) {
4328 wtoken.updateReportedVisibilityLocked();
4329 }
4330 }
4331 Binder.restoreCallingIdentity(origId);
4332
4333 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004334 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 + startingToken + ": app token removed");
4336 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4337 mH.sendMessage(m);
4338 }
4339 }
4340
4341 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4342 final int NW = token.windows.size();
4343 for (int i=0; i<NW; i++) {
4344 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004345 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004347 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004348 int j = win.mChildWindows.size();
4349 while (j > 0) {
4350 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004351 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004352 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004353 "Tmp removing child window " + cwin);
4354 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 }
4356 }
4357 return NW > 0;
4358 }
4359
4360 void dumpAppTokensLocked() {
4361 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
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 void dumpWindowsLocked() {
4367 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004368 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 }
4370 }
Romain Guy06882f82009-06-10 13:36:04 -07004371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004372 private int findWindowOffsetLocked(int tokenPos) {
4373 final int NW = mWindows.size();
4374
4375 if (tokenPos >= mAppTokens.size()) {
4376 int i = NW;
4377 while (i > 0) {
4378 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004379 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004380 if (win.getAppToken() != null) {
4381 return i+1;
4382 }
4383 }
4384 }
4385
4386 while (tokenPos > 0) {
4387 // Find the first app token below the new position that has
4388 // a window displayed.
4389 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004390 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004391 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004392 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004393 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004394 "Skipping token -- currently sending to bottom");
4395 tokenPos--;
4396 continue;
4397 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 int i = wtoken.windows.size();
4399 while (i > 0) {
4400 i--;
4401 WindowState win = wtoken.windows.get(i);
4402 int j = win.mChildWindows.size();
4403 while (j > 0) {
4404 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004405 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004406 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004407 for (int pos=NW-1; pos>=0; pos--) {
4408 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004409 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 "Found child win @" + (pos+1));
4411 return pos+1;
4412 }
4413 }
4414 }
4415 }
4416 for (int pos=NW-1; pos>=0; pos--) {
4417 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004418 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004419 return pos+1;
4420 }
4421 }
4422 }
4423 tokenPos--;
4424 }
4425
4426 return 0;
4427 }
4428
4429 private final int reAddWindowLocked(int index, WindowState win) {
4430 final int NCW = win.mChildWindows.size();
4431 boolean added = false;
4432 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004433 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004434 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004435 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004436 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004437 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 mWindows.add(index, win);
4439 index++;
4440 added = true;
4441 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004443 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004444 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004445 mWindows.add(index, cwin);
4446 index++;
4447 }
4448 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004449 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004450 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004451 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452 mWindows.add(index, win);
4453 index++;
4454 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004455 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 return index;
4457 }
Romain Guy06882f82009-06-10 13:36:04 -07004458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4460 final int NW = token.windows.size();
4461 for (int i=0; i<NW; i++) {
4462 index = reAddWindowLocked(index, token.windows.get(i));
4463 }
4464 return index;
4465 }
4466
4467 public void moveAppToken(int index, IBinder token) {
4468 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4469 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004470 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 }
4472
4473 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004474 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 if (DEBUG_REORDER) dumpAppTokensLocked();
4476 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004477 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4478 "Start moving token " + wtoken + " initially at "
4479 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004481 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 + token + " (" + wtoken + ")");
4483 return;
4484 }
4485 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004486 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004487 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004491 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 if (DEBUG_REORDER) dumpWindowsLocked();
4493 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004494 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 if (DEBUG_REORDER) dumpWindowsLocked();
4496 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004497 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004499 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4500 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004502 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004503 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004504 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 }
4506 Binder.restoreCallingIdentity(origId);
4507 }
4508 }
4509
4510 private void removeAppTokensLocked(List<IBinder> tokens) {
4511 // XXX This should be done more efficiently!
4512 // (take advantage of the fact that both lists should be
4513 // ordered in the same way.)
4514 int N = tokens.size();
4515 for (int i=0; i<N; i++) {
4516 IBinder token = tokens.get(i);
4517 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004518 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4519 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004521 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 + token + " (" + wtoken + ")");
4523 i--;
4524 N--;
4525 }
4526 }
4527 }
4528
Dianne Hackborna8f60182009-09-01 19:01:50 -07004529 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4530 boolean updateFocusAndLayout) {
4531 // First remove all of the windows from the list.
4532 tmpRemoveAppWindowsLocked(wtoken);
4533
4534 // Where to start adding?
4535 int pos = findWindowOffsetLocked(tokenPos);
4536
4537 // And now add them back at the correct place.
4538 pos = reAddAppWindowsLocked(pos, wtoken);
4539
4540 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004541 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004542 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4543 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004544 assignLayersLocked();
4545 }
4546 mLayoutNeeded = true;
4547 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004548 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004549 }
4550 }
4551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004552 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4553 // First remove all of the windows from the list.
4554 final int N = tokens.size();
4555 int i;
4556 for (i=0; i<N; i++) {
4557 WindowToken token = mTokenMap.get(tokens.get(i));
4558 if (token != null) {
4559 tmpRemoveAppWindowsLocked(token);
4560 }
4561 }
4562
4563 // Where to start adding?
4564 int pos = findWindowOffsetLocked(tokenPos);
4565
4566 // And now add them back at the correct place.
4567 for (i=0; i<N; i++) {
4568 WindowToken token = mTokenMap.get(tokens.get(i));
4569 if (token != null) {
4570 pos = reAddAppWindowsLocked(pos, token);
4571 }
4572 }
4573
Jeff Brown2e44b072011-01-24 15:21:56 -08004574 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004575 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4576 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004577 assignLayersLocked();
4578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 mLayoutNeeded = true;
4580 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004581 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004582
4583 //dump();
4584 }
4585
4586 public void moveAppTokensToTop(List<IBinder> tokens) {
4587 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4588 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004589 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004590 }
4591
4592 final long origId = Binder.clearCallingIdentity();
4593 synchronized(mWindowMap) {
4594 removeAppTokensLocked(tokens);
4595 final int N = tokens.size();
4596 for (int i=0; i<N; i++) {
4597 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4598 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004599 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4600 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004601 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004602 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004603 mToTopApps.remove(wt);
4604 mToBottomApps.remove(wt);
4605 mToTopApps.add(wt);
4606 wt.sendingToBottom = false;
4607 wt.sendingToTop = true;
4608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004609 }
4610 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004611
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004612 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004613 moveAppWindowsLocked(tokens, mAppTokens.size());
4614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004615 }
4616 Binder.restoreCallingIdentity(origId);
4617 }
4618
4619 public void moveAppTokensToBottom(List<IBinder> tokens) {
4620 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4621 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004622 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 }
4624
4625 final long origId = Binder.clearCallingIdentity();
4626 synchronized(mWindowMap) {
4627 removeAppTokensLocked(tokens);
4628 final int N = tokens.size();
4629 int pos = 0;
4630 for (int i=0; i<N; i++) {
4631 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4632 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004633 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4634 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004636 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004637 mToTopApps.remove(wt);
4638 mToBottomApps.remove(wt);
4639 mToBottomApps.add(i, wt);
4640 wt.sendingToTop = false;
4641 wt.sendingToBottom = true;
4642 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004643 pos++;
4644 }
4645 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004646
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004647 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004648 moveAppWindowsLocked(tokens, 0);
4649 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004650 }
4651 Binder.restoreCallingIdentity(origId);
4652 }
4653
4654 // -------------------------------------------------------------
4655 // Misc IWindowSession methods
4656 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004657
Jim Miller284b62e2010-06-08 14:27:42 -07004658 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004659 {
Jim Miller284b62e2010-06-08 14:27:42 -07004660 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4661 // called before DevicePolicyManagerService has started.
4662 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4663 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4664 Context.DEVICE_POLICY_SERVICE);
4665 if (dpm != null) {
4666 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4667 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4668 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4669 }
Jim Millerd6b57052010-06-07 17:52:42 -07004670 }
Jim Miller284b62e2010-06-08 14:27:42 -07004671 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004672 }
4673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004674 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004675 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004676 != PackageManager.PERMISSION_GRANTED) {
4677 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4678 }
Jim Millerd6b57052010-06-07 17:52:42 -07004679
Jim Miller284b62e2010-06-08 14:27:42 -07004680 synchronized (mKeyguardTokenWatcher) {
4681 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004682 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 }
4684
4685 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004686 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004687 != PackageManager.PERMISSION_GRANTED) {
4688 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004690
Jim Miller284b62e2010-06-08 14:27:42 -07004691 synchronized (mKeyguardTokenWatcher) {
4692 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004693
Jim Miller284b62e2010-06-08 14:27:42 -07004694 if (!mKeyguardTokenWatcher.isAcquired()) {
4695 // If we are the last one to reenable the keyguard wait until
4696 // we have actually finished reenabling until returning.
4697 // It is possible that reenableKeyguard() can be called before
4698 // the previous disableKeyguard() is handled, in which case
4699 // neither mKeyguardTokenWatcher.acquired() or released() would
4700 // be called. In that case mKeyguardDisabled will be false here
4701 // and we have nothing to wait for.
4702 while (mKeyguardDisabled) {
4703 try {
4704 mKeyguardTokenWatcher.wait();
4705 } catch (InterruptedException e) {
4706 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 }
4708 }
4709 }
4710 }
4711 }
4712
4713 /**
4714 * @see android.app.KeyguardManager#exitKeyguardSecurely
4715 */
4716 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004717 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718 != PackageManager.PERMISSION_GRANTED) {
4719 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4720 }
4721 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4722 public void onKeyguardExitResult(boolean success) {
4723 try {
4724 callback.onKeyguardExitResult(success);
4725 } catch (RemoteException e) {
4726 // Client has died, we don't care.
4727 }
4728 }
4729 });
4730 }
4731
4732 public boolean inKeyguardRestrictedInputMode() {
4733 return mPolicy.inKeyguardRestrictedKeyInputMode();
4734 }
Romain Guy06882f82009-06-10 13:36:04 -07004735
Dianne Hackbornffa42482009-09-23 22:20:11 -07004736 public void closeSystemDialogs(String reason) {
4737 synchronized(mWindowMap) {
4738 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004739 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004740 if (w.mSurface != null) {
4741 try {
4742 w.mClient.closeSystemDialogs(reason);
4743 } catch (RemoteException e) {
4744 }
4745 }
4746 }
4747 }
4748 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004750 static float fixScale(float scale) {
4751 if (scale < 0) scale = 0;
4752 else if (scale > 20) scale = 20;
4753 return Math.abs(scale);
4754 }
Romain Guy06882f82009-06-10 13:36:04 -07004755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004756 public void setAnimationScale(int which, float scale) {
4757 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4758 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004759 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004760 }
4761
4762 if (scale < 0) scale = 0;
4763 else if (scale > 20) scale = 20;
4764 scale = Math.abs(scale);
4765 switch (which) {
4766 case 0: mWindowAnimationScale = fixScale(scale); break;
4767 case 1: mTransitionAnimationScale = fixScale(scale); break;
4768 }
Romain Guy06882f82009-06-10 13:36:04 -07004769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 // Persist setting
4771 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4772 }
Romain Guy06882f82009-06-10 13:36:04 -07004773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004774 public void setAnimationScales(float[] scales) {
4775 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4776 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004777 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 }
4779
4780 if (scales != null) {
4781 if (scales.length >= 1) {
4782 mWindowAnimationScale = fixScale(scales[0]);
4783 }
4784 if (scales.length >= 2) {
4785 mTransitionAnimationScale = fixScale(scales[1]);
4786 }
4787 }
Romain Guy06882f82009-06-10 13:36:04 -07004788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 // Persist setting
4790 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4791 }
Romain Guy06882f82009-06-10 13:36:04 -07004792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004793 public float getAnimationScale(int which) {
4794 switch (which) {
4795 case 0: return mWindowAnimationScale;
4796 case 1: return mTransitionAnimationScale;
4797 }
4798 return 0;
4799 }
Romain Guy06882f82009-06-10 13:36:04 -07004800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 public float[] getAnimationScales() {
4802 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4803 }
Romain Guy06882f82009-06-10 13:36:04 -07004804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 public int getSwitchState(int sw) {
4806 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4807 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004808 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004809 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004810 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 }
Romain Guy06882f82009-06-10 13:36:04 -07004812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 public int getSwitchStateForDevice(int devid, int sw) {
4814 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4815 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004816 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004817 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004818 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004819 }
Romain Guy06882f82009-06-10 13:36:04 -07004820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 public int getScancodeState(int sw) {
4822 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4823 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004824 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004826 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 }
Romain Guy06882f82009-06-10 13:36:04 -07004828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 public int getScancodeStateForDevice(int devid, int sw) {
4830 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4831 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004832 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004833 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004834 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 }
Romain Guy06882f82009-06-10 13:36:04 -07004836
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004837 public int getTrackballScancodeState(int sw) {
4838 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4839 "getTrackballScancodeState()")) {
4840 throw new SecurityException("Requires READ_INPUT_STATE permission");
4841 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004842 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004843 }
4844
4845 public int getDPadScancodeState(int sw) {
4846 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4847 "getDPadScancodeState()")) {
4848 throw new SecurityException("Requires READ_INPUT_STATE permission");
4849 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004850 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004851 }
4852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 public int getKeycodeState(int sw) {
4854 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4855 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004856 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004857 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004858 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859 }
Romain Guy06882f82009-06-10 13:36:04 -07004860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004861 public int getKeycodeStateForDevice(int devid, int sw) {
4862 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4863 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004864 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004865 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004866 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 }
Romain Guy06882f82009-06-10 13:36:04 -07004868
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004869 public int getTrackballKeycodeState(int sw) {
4870 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4871 "getTrackballKeycodeState()")) {
4872 throw new SecurityException("Requires READ_INPUT_STATE permission");
4873 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004874 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004875 }
4876
4877 public int getDPadKeycodeState(int sw) {
4878 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4879 "getDPadKeycodeState()")) {
4880 throw new SecurityException("Requires READ_INPUT_STATE permission");
4881 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004882 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004883 }
Jeff Browna41ca772010-08-11 14:46:32 -07004884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004885 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004886 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004887 }
Romain Guy06882f82009-06-10 13:36:04 -07004888
Jeff Browna41ca772010-08-11 14:46:32 -07004889 public InputChannel monitorInput(String inputChannelName) {
4890 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4891 "monitorInput()")) {
4892 throw new SecurityException("Requires READ_INPUT_STATE permission");
4893 }
4894 return mInputManager.monitorInput(inputChannelName);
4895 }
4896
Jeff Brown8d608662010-08-30 03:02:23 -07004897 public InputDevice getInputDevice(int deviceId) {
4898 return mInputManager.getInputDevice(deviceId);
4899 }
4900
4901 public int[] getInputDeviceIds() {
4902 return mInputManager.getInputDeviceIds();
4903 }
4904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004905 public void enableScreenAfterBoot() {
4906 synchronized(mWindowMap) {
4907 if (mSystemBooted) {
4908 return;
4909 }
4910 mSystemBooted = true;
4911 }
Romain Guy06882f82009-06-10 13:36:04 -07004912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 performEnableScreen();
4914 }
Romain Guy06882f82009-06-10 13:36:04 -07004915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 public void enableScreenIfNeededLocked() {
4917 if (mDisplayEnabled) {
4918 return;
4919 }
4920 if (!mSystemBooted) {
4921 return;
4922 }
4923 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4924 }
Romain Guy06882f82009-06-10 13:36:04 -07004925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 public void performEnableScreen() {
4927 synchronized(mWindowMap) {
4928 if (mDisplayEnabled) {
4929 return;
4930 }
4931 if (!mSystemBooted) {
4932 return;
4933 }
Romain Guy06882f82009-06-10 13:36:04 -07004934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 // Don't enable the screen until all existing windows
4936 // have been drawn.
4937 final int N = mWindows.size();
4938 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004939 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004940 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004941 return;
4942 }
4943 }
Romain Guy06882f82009-06-10 13:36:04 -07004944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 mDisplayEnabled = true;
4946 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004947 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004948 StringWriter sw = new StringWriter();
4949 PrintWriter pw = new PrintWriter(sw);
4950 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004951 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 }
4953 try {
4954 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4955 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004956 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004957 Parcel data = Parcel.obtain();
4958 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4959 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4960 data, null, 0);
4961 data.recycle();
4962 }
4963 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004964 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004965 }
4966 }
Romain Guy06882f82009-06-10 13:36:04 -07004967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004968 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004970 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004971 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4972 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004973 }
Romain Guy06882f82009-06-10 13:36:04 -07004974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 public void setInTouchMode(boolean mode) {
4976 synchronized(mWindowMap) {
4977 mInTouchMode = mode;
4978 }
4979 }
4980
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004981 // TODO: more accounting of which pid(s) turned it on, keep count,
4982 // only allow disables from pids which have count on, etc.
4983 public void showStrictModeViolation(boolean on) {
4984 int pid = Binder.getCallingPid();
4985 synchronized(mWindowMap) {
4986 // Ignoring requests to enable the red border from clients
4987 // which aren't on screen. (e.g. Broadcast Receivers in
4988 // the background..)
4989 if (on) {
4990 boolean isVisible = false;
4991 for (WindowState ws : mWindows) {
4992 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4993 isVisible = true;
4994 break;
4995 }
4996 }
4997 if (!isVisible) {
4998 return;
4999 }
5000 }
5001
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005002 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005003 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005004 try {
5005 if (mStrictModeFlash == null) {
5006 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
5007 }
5008 mStrictModeFlash.setVisibility(on);
5009 } finally {
5010 Surface.closeTransaction();
5011 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005012 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005013 }
5014 }
5015
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08005016 public void setStrictModeVisualIndicatorPreference(String value) {
5017 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
5018 }
5019
Dianne Hackbornd2835932010-12-13 16:28:46 -08005020 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005021 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5022 "screenshotApplications()")) {
5023 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5024 }
5025
5026 Bitmap rawss;
5027
Dianne Hackbornd2835932010-12-13 16:28:46 -08005028 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005029 final Rect frame = new Rect();
5030
5031 float scale;
5032 int sw, sh, dw, dh;
5033 int rot;
5034
5035 synchronized(mWindowMap) {
5036 long ident = Binder.clearCallingIdentity();
5037
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005038 dw = mDisplay.getWidth();
5039 dh = mDisplay.getHeight();
5040
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005041 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5042 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5043 + TYPE_LAYER_OFFSET;
5044 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5045
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005046 boolean isImeTarget = mInputMethodTarget != null
5047 && mInputMethodTarget.mAppToken != null
5048 && mInputMethodTarget.mAppToken.appToken != null
5049 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
5050
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005051 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005052 boolean including = false;
5053 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005054 WindowState ws = mWindows.get(i);
5055 if (ws.mSurface == null) {
5056 continue;
5057 }
5058 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08005059 continue;
5060 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005061 // When we will skip windows: when we are not including
5062 // ones behind a window we didn't skip, and we are actually
5063 // taking a screenshot of a specific app.
5064 if (!including && appToken != null) {
5065 // Also, we can possibly skip this window if it is not
5066 // an IME target or the application for the screenshot
5067 // is not the current IME target.
5068 if (!ws.mIsImWindow || !isImeTarget) {
5069 // And finally, this window is of no interest if it
5070 // is not associated with the screenshot app.
5071 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
5072 continue;
5073 }
5074 }
5075 }
5076
5077 // We keep on including windows until we go past a full-screen
5078 // window.
5079 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
5080
Dianne Hackbornd2835932010-12-13 16:28:46 -08005081 if (maxLayer < ws.mAnimLayer) {
5082 maxLayer = ws.mAnimLayer;
5083 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005084 final Rect wf = ws.mFrame;
5085 final Rect cr = ws.mContentInsets;
5086 int left = wf.left + cr.left;
5087 int top = wf.top + cr.top;
5088 int right = wf.right - cr.right;
5089 int bottom = wf.bottom - cr.bottom;
5090 frame.union(left, top, right, bottom);
5091 }
5092 Binder.restoreCallingIdentity(ident);
5093
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005094 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005095 return null;
5096 }
5097
5098 // The screenshot API does not apply the current screen rotation.
5099 rot = mDisplay.getRotation();
5100 int fw = frame.width();
5101 int fh = frame.height();
5102
5103 // First try reducing to fit in x dimension.
5104 scale = maxWidth/(float)fw;
5105 sw = maxWidth;
5106 sh = (int)(fh*scale);
5107 if (sh > maxHeight) {
5108 // y dimension became too long; constrain by that.
5109 scale = maxHeight/(float)fh;
5110 sw = (int)(fw*scale);
5111 sh = maxHeight;
5112 }
5113
5114 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005115 dw = (int)(dw*scale);
5116 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005117 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5118 int tmp = dw;
5119 dw = dh;
5120 dh = tmp;
5121 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5122 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005123 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005124 }
5125
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005126 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005127 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5128 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005129 return null;
5130 }
5131
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005132 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5133 Matrix matrix = new Matrix();
5134 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5135 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5136 Canvas canvas = new Canvas(bm);
5137 canvas.drawBitmap(rawss, matrix, null);
5138
5139 rawss.recycle();
5140 return bm;
5141 }
5142
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005143 public void freezeRotation() {
5144 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5145 "setRotation()")) {
5146 throw new SecurityException("Requires SET_ORIENTATION permission");
5147 }
5148
5149 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5150 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5151 }
5152
5153 public void thawRotation() {
5154 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5155 "setRotation()")) {
5156 throw new SecurityException("Requires SET_ORIENTATION permission");
5157 }
5158
5159 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5160 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5161 }
5162
Romain Guy06882f82009-06-10 13:36:04 -07005163 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005164 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005165 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005166 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005167 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005168 }
5169
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005170 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005171 }
Romain Guy06882f82009-06-10 13:36:04 -07005172
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005173 public void setRotationUnchecked(int rotation,
5174 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005175 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005176 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178 long origId = Binder.clearCallingIdentity();
5179 boolean changed;
5180 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005181 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005182 }
Romain Guy06882f82009-06-10 13:36:04 -07005183
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005184 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005185 sendNewConfiguration();
5186 }
Romain Guy06882f82009-06-10 13:36:04 -07005187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005188 Binder.restoreCallingIdentity(origId);
5189 }
Romain Guy06882f82009-06-10 13:36:04 -07005190
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005191 /**
5192 * Apply a new rotation to the screen, respecting the requests of
5193 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5194 * re-evaluate the desired rotation.
5195 *
5196 * Returns null if the rotation has been changed. In this case YOU
5197 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5198 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005199 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005200 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005201 // Potential rotation during a drag. Don't do the rotation now, but make
5202 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005203 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5204 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5205 mDeferredRotation = rotation;
5206 mDeferredRotationAnimFlags = animFlags;
5207 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005208 return false;
5209 }
5210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005211 boolean changed;
5212 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005213 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5214 rotation = mDeferredRotation;
5215 mRequestedRotation = rotation;
5216 mLastRotationFlags = mDeferredRotationAnimFlags;
5217 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005218 rotation = mRequestedRotation;
5219 } else {
5220 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005221 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005222 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005223 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005224 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005225 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005226 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005227 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005230 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005231 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005232 "Rotation changed to " + rotation
5233 + " from " + mRotation
5234 + " (forceApp=" + mForcedAppOrientation
5235 + ", req=" + mRequestedRotation + ")");
5236 mRotation = rotation;
5237 mWindowsFreezingScreen = true;
5238 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5239 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5240 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005241 mWaitingForConfig = true;
5242 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005243 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005244 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005245 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005246 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005247 if (CUSTOM_SCREEN_ROTATION) {
5248 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005249 if (!inTransaction) {
5250 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5251 ">>> OPEN TRANSACTION setRotationUnchecked");
5252 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005253 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005254 try {
5255 if (mScreenRotationAnimation != null) {
5256 mScreenRotationAnimation.setRotation(rotation);
5257 }
5258 } finally {
5259 if (!inTransaction) {
5260 Surface.closeTransaction();
5261 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5262 "<<< CLOSE TRANSACTION setRotationUnchecked");
5263 }
5264 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005265 Surface.setOrientation(0, rotation, animFlags);
5266 Surface.unfreezeDisplay(0);
5267 } else {
5268 Surface.setOrientation(0, rotation, animFlags);
5269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005270 }
5271 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005272 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005273 if (w.mSurface != null) {
5274 w.mOrientationChanging = true;
5275 }
5276 }
5277 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5278 try {
5279 mRotationWatchers.get(i).onRotationChanged(rotation);
5280 } catch (RemoteException e) {
5281 }
5282 }
5283 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005285 return changed;
5286 }
Romain Guy06882f82009-06-10 13:36:04 -07005287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005288 public int getRotation() {
5289 return mRotation;
5290 }
5291
5292 public int watchRotation(IRotationWatcher watcher) {
5293 final IBinder watcherBinder = watcher.asBinder();
5294 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5295 public void binderDied() {
5296 synchronized (mWindowMap) {
5297 for (int i=0; i<mRotationWatchers.size(); i++) {
5298 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005299 IRotationWatcher removed = mRotationWatchers.remove(i);
5300 if (removed != null) {
5301 removed.asBinder().unlinkToDeath(this, 0);
5302 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005303 i--;
5304 }
5305 }
5306 }
5307 }
5308 };
Romain Guy06882f82009-06-10 13:36:04 -07005309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005310 synchronized (mWindowMap) {
5311 try {
5312 watcher.asBinder().linkToDeath(dr, 0);
5313 mRotationWatchers.add(watcher);
5314 } catch (RemoteException e) {
5315 // Client died, no cleanup needed.
5316 }
Romain Guy06882f82009-06-10 13:36:04 -07005317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005318 return mRotation;
5319 }
5320 }
5321
5322 /**
5323 * Starts the view server on the specified port.
5324 *
5325 * @param port The port to listener to.
5326 *
5327 * @return True if the server was successfully started, false otherwise.
5328 *
5329 * @see com.android.server.ViewServer
5330 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5331 */
5332 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005333 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005334 return false;
5335 }
5336
5337 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5338 return false;
5339 }
5340
5341 if (port < 1024) {
5342 return false;
5343 }
5344
5345 if (mViewServer != null) {
5346 if (!mViewServer.isRunning()) {
5347 try {
5348 return mViewServer.start();
5349 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005350 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351 }
5352 }
5353 return false;
5354 }
5355
5356 try {
5357 mViewServer = new ViewServer(this, port);
5358 return mViewServer.start();
5359 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005360 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005361 }
5362 return false;
5363 }
5364
Romain Guy06882f82009-06-10 13:36:04 -07005365 private boolean isSystemSecure() {
5366 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5367 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5368 }
5369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005370 /**
5371 * Stops the view server if it exists.
5372 *
5373 * @return True if the server stopped, false if it wasn't started or
5374 * couldn't be stopped.
5375 *
5376 * @see com.android.server.ViewServer
5377 */
5378 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005379 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 return false;
5381 }
5382
5383 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5384 return false;
5385 }
5386
5387 if (mViewServer != null) {
5388 return mViewServer.stop();
5389 }
5390 return false;
5391 }
5392
5393 /**
5394 * Indicates whether the view server is running.
5395 *
5396 * @return True if the server is running, false otherwise.
5397 *
5398 * @see com.android.server.ViewServer
5399 */
5400 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005401 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005402 return false;
5403 }
5404
5405 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5406 return false;
5407 }
5408
5409 return mViewServer != null && mViewServer.isRunning();
5410 }
5411
5412 /**
5413 * Lists all availble windows in the system. The listing is written in the
5414 * specified Socket's output stream with the following syntax:
5415 * windowHashCodeInHexadecimal windowName
5416 * Each line of the ouput represents a different window.
5417 *
5418 * @param client The remote client to send the listing to.
5419 * @return False if an error occured, true otherwise.
5420 */
5421 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005422 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005423 return false;
5424 }
5425
5426 boolean result = true;
5427
Jeff Browne33348b2010-07-15 23:54:05 -07005428 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005429 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005430 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005431 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005432 }
5433
5434 BufferedWriter out = null;
5435
5436 // Any uncaught exception will crash the system process
5437 try {
5438 OutputStream clientStream = client.getOutputStream();
5439 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5440
5441 final int count = windows.length;
5442 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005443 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005444 out.write(Integer.toHexString(System.identityHashCode(w)));
5445 out.write(' ');
5446 out.append(w.mAttrs.getTitle());
5447 out.write('\n');
5448 }
5449
5450 out.write("DONE.\n");
5451 out.flush();
5452 } catch (Exception e) {
5453 result = false;
5454 } finally {
5455 if (out != null) {
5456 try {
5457 out.close();
5458 } catch (IOException e) {
5459 result = false;
5460 }
5461 }
5462 }
5463
5464 return result;
5465 }
5466
5467 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005468 * Returns the focused window in the following format:
5469 * windowHashCodeInHexadecimal windowName
5470 *
5471 * @param client The remote client to send the listing to.
5472 * @return False if an error occurred, true otherwise.
5473 */
5474 boolean viewServerGetFocusedWindow(Socket client) {
5475 if (isSystemSecure()) {
5476 return false;
5477 }
5478
5479 boolean result = true;
5480
5481 WindowState focusedWindow = getFocusedWindow();
5482
5483 BufferedWriter out = null;
5484
5485 // Any uncaught exception will crash the system process
5486 try {
5487 OutputStream clientStream = client.getOutputStream();
5488 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5489
5490 if(focusedWindow != null) {
5491 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5492 out.write(' ');
5493 out.append(focusedWindow.mAttrs.getTitle());
5494 }
5495 out.write('\n');
5496 out.flush();
5497 } catch (Exception e) {
5498 result = false;
5499 } finally {
5500 if (out != null) {
5501 try {
5502 out.close();
5503 } catch (IOException e) {
5504 result = false;
5505 }
5506 }
5507 }
5508
5509 return result;
5510 }
5511
5512 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005513 * Sends a command to a target window. The result of the command, if any, will be
5514 * written in the output stream of the specified socket.
5515 *
5516 * The parameters must follow this syntax:
5517 * windowHashcode extra
5518 *
5519 * Where XX is the length in characeters of the windowTitle.
5520 *
5521 * The first parameter is the target window. The window with the specified hashcode
5522 * will be the target. If no target can be found, nothing happens. The extra parameters
5523 * will be delivered to the target window and as parameters to the command itself.
5524 *
5525 * @param client The remote client to sent the result, if any, to.
5526 * @param command The command to execute.
5527 * @param parameters The command parameters.
5528 *
5529 * @return True if the command was successfully delivered, false otherwise. This does
5530 * not indicate whether the command itself was successful.
5531 */
5532 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005533 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005534 return false;
5535 }
5536
5537 boolean success = true;
5538 Parcel data = null;
5539 Parcel reply = null;
5540
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005541 BufferedWriter out = null;
5542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005543 // Any uncaught exception will crash the system process
5544 try {
5545 // Find the hashcode of the window
5546 int index = parameters.indexOf(' ');
5547 if (index == -1) {
5548 index = parameters.length();
5549 }
5550 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005551 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005552
5553 // Extract the command's parameter after the window description
5554 if (index < parameters.length()) {
5555 parameters = parameters.substring(index + 1);
5556 } else {
5557 parameters = "";
5558 }
5559
5560 final WindowManagerService.WindowState window = findWindow(hashCode);
5561 if (window == null) {
5562 return false;
5563 }
5564
5565 data = Parcel.obtain();
5566 data.writeInterfaceToken("android.view.IWindow");
5567 data.writeString(command);
5568 data.writeString(parameters);
5569 data.writeInt(1);
5570 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5571
5572 reply = Parcel.obtain();
5573
5574 final IBinder binder = window.mClient.asBinder();
5575 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5576 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5577
5578 reply.readException();
5579
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005580 if (!client.isOutputShutdown()) {
5581 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5582 out.write("DONE\n");
5583 out.flush();
5584 }
5585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005586 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005587 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005588 success = false;
5589 } finally {
5590 if (data != null) {
5591 data.recycle();
5592 }
5593 if (reply != null) {
5594 reply.recycle();
5595 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005596 if (out != null) {
5597 try {
5598 out.close();
5599 } catch (IOException e) {
5600
5601 }
5602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005603 }
5604
5605 return success;
5606 }
5607
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005608 public void addWindowChangeListener(WindowChangeListener listener) {
5609 synchronized(mWindowMap) {
5610 mWindowChangeListeners.add(listener);
5611 }
5612 }
5613
5614 public void removeWindowChangeListener(WindowChangeListener listener) {
5615 synchronized(mWindowMap) {
5616 mWindowChangeListeners.remove(listener);
5617 }
5618 }
5619
5620 private void notifyWindowsChanged() {
5621 WindowChangeListener[] windowChangeListeners;
5622 synchronized(mWindowMap) {
5623 if(mWindowChangeListeners.isEmpty()) {
5624 return;
5625 }
5626 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5627 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5628 }
5629 int N = windowChangeListeners.length;
5630 for(int i = 0; i < N; i++) {
5631 windowChangeListeners[i].windowsChanged();
5632 }
5633 }
5634
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005635 private void notifyFocusChanged() {
5636 WindowChangeListener[] windowChangeListeners;
5637 synchronized(mWindowMap) {
5638 if(mWindowChangeListeners.isEmpty()) {
5639 return;
5640 }
5641 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5642 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5643 }
5644 int N = windowChangeListeners.length;
5645 for(int i = 0; i < N; i++) {
5646 windowChangeListeners[i].focusChanged();
5647 }
5648 }
5649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005650 private WindowState findWindow(int hashCode) {
5651 if (hashCode == -1) {
5652 return getFocusedWindow();
5653 }
5654
5655 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005656 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005657 final int count = windows.size();
5658
5659 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005660 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005661 if (System.identityHashCode(w) == hashCode) {
5662 return w;
5663 }
5664 }
5665 }
5666
5667 return null;
5668 }
5669
5670 /*
5671 * Instruct the Activity Manager to fetch the current configuration and broadcast
5672 * that to config-changed listeners if appropriate.
5673 */
5674 void sendNewConfiguration() {
5675 try {
5676 mActivityManager.updateConfiguration(null);
5677 } catch (RemoteException e) {
5678 }
5679 }
Romain Guy06882f82009-06-10 13:36:04 -07005680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005681 public Configuration computeNewConfiguration() {
5682 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005683 Configuration config = computeNewConfigurationLocked();
5684 if (config == null && mWaitingForConfig) {
5685 // Nothing changed but we are waiting for something... stop that!
5686 mWaitingForConfig = false;
5687 performLayoutAndPlaceSurfacesLocked();
5688 }
5689 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005690 }
5691 }
Romain Guy06882f82009-06-10 13:36:04 -07005692
Dianne Hackbornc485a602009-03-24 22:39:49 -07005693 Configuration computeNewConfigurationLocked() {
5694 Configuration config = new Configuration();
5695 if (!computeNewConfigurationLocked(config)) {
5696 return null;
5697 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005698 return config;
5699 }
Romain Guy06882f82009-06-10 13:36:04 -07005700
Dianne Hackbornc485a602009-03-24 22:39:49 -07005701 boolean computeNewConfigurationLocked(Configuration config) {
5702 if (mDisplay == null) {
5703 return false;
5704 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005705
5706 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005707
5708 // Use the effective "visual" dimensions based on current rotation
5709 final boolean rotated = (mRotation == Surface.ROTATION_90
5710 || mRotation == Surface.ROTATION_270);
5711 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5712 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5713
Dianne Hackbornc485a602009-03-24 22:39:49 -07005714 int orientation = Configuration.ORIENTATION_SQUARE;
5715 if (dw < dh) {
5716 orientation = Configuration.ORIENTATION_PORTRAIT;
5717 } else if (dw > dh) {
5718 orientation = Configuration.ORIENTATION_LANDSCAPE;
5719 }
5720 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005721
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005722 DisplayMetrics dm = new DisplayMetrics();
5723 mDisplay.getMetrics(dm);
5724 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5725
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005726 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005727 // Note we only do this once because at this point we don't
5728 // expect the screen to change in this way at runtime, and want
5729 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005730 int longSize = dw;
5731 int shortSize = dh;
5732 if (longSize < shortSize) {
5733 int tmp = longSize;
5734 longSize = shortSize;
5735 shortSize = tmp;
5736 }
5737 longSize = (int)(longSize/dm.density);
5738 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005739
Dianne Hackborn723738c2009-06-25 19:48:04 -07005740 // These semi-magic numbers define our compatibility modes for
5741 // applications with different screens. Don't change unless you
5742 // make sure to test lots and lots of apps!
5743 if (longSize < 470) {
5744 // This is shorter than an HVGA normal density screen (which
5745 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005746 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5747 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005748 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005749 // What size is this screen screen?
5750 if (longSize >= 800 && shortSize >= 600) {
5751 // SVGA or larger screens at medium density are the point
5752 // at which we consider it to be an extra large screen.
5753 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005754 } else if (longSize >= 530 && shortSize >= 400) {
5755 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005756 // at which we consider it to be a large screen.
5757 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5758 } else {
5759 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Dianne Hackborne97a12e2011-01-29 13:22:02 -08005760 }
5761
5762 // If this screen is wider than normal HVGA, or taller
5763 // than FWVGA, then for old apps we want to run in size
5764 // compatibility mode.
5765 if (shortSize > 321 || longSize > 570) {
5766 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005768
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005769 // Is this a long screen?
5770 if (((longSize*3)/5) >= (shortSize-1)) {
5771 // Anything wider than WVGA (5:3) is considering to be long.
5772 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5773 } else {
5774 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5775 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005776 }
5777 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005778 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005779
Dianne Hackbornc485a602009-03-24 22:39:49 -07005780 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5781 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5782 mPolicy.adjustConfigurationLw(config);
Jeff Brown2992ea72011-01-28 22:04:14 -08005783
5784 // Adjust the hard keyboard configuration based on whether the hard keyboard is enabled.
5785 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5786 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5787 mHardKeyboardAvailable = hardKeyboardAvailable;
5788 mHardKeyboardEnabled = hardKeyboardAvailable;
5789
5790 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5791 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5792 }
5793 if (!mHardKeyboardEnabled) {
5794 config.keyboard = Configuration.KEYBOARD_NOKEYS;
5795 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5796 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005797 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005798 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005799
Jeff Brown2992ea72011-01-28 22:04:14 -08005800 public boolean isHardKeyboardAvailable() {
5801 synchronized (mWindowMap) {
5802 return mHardKeyboardAvailable;
5803 }
5804 }
5805
5806 public boolean isHardKeyboardEnabled() {
5807 synchronized (mWindowMap) {
5808 return mHardKeyboardEnabled;
5809 }
5810 }
5811
5812 public void setHardKeyboardEnabled(boolean enabled) {
5813 synchronized (mWindowMap) {
5814 if (mHardKeyboardEnabled != enabled) {
5815 mHardKeyboardEnabled = enabled;
5816 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5817 }
5818 }
5819 }
5820
5821 public void setOnHardKeyboardStatusChangeListener(
5822 OnHardKeyboardStatusChangeListener listener) {
5823 synchronized (mWindowMap) {
5824 mHardKeyboardStatusChangeListener = listener;
5825 }
5826 }
5827
5828 void notifyHardKeyboardStatusChange() {
5829 final boolean available, enabled;
5830 final OnHardKeyboardStatusChangeListener listener;
5831 synchronized (mWindowMap) {
5832 listener = mHardKeyboardStatusChangeListener;
5833 available = mHardKeyboardAvailable;
5834 enabled = mHardKeyboardEnabled;
5835 }
5836 if (listener != null) {
5837 listener.onHardKeyboardStatusChange(available, enabled);
5838 }
5839 }
5840
Christopher Tatea53146c2010-09-07 11:57:52 -07005841 // -------------------------------------------------------------
5842 // Drag and drop
5843 // -------------------------------------------------------------
5844
5845 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005846 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005847 if (DEBUG_DRAG) {
5848 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005849 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005850 + " asbinder=" + window.asBinder());
5851 }
5852
5853 final int callerPid = Binder.getCallingPid();
5854 final long origId = Binder.clearCallingIdentity();
5855 IBinder token = null;
5856
5857 try {
5858 synchronized (mWindowMap) {
5859 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005860 if (mDragState == null) {
5861 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5862 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5863 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005864 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005865 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005866 // TODO: preserve flags param in DragState
5867 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005868 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005869 token = mDragState.mToken = new Binder();
5870
5871 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005872 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5873 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005874 mH.sendMessageDelayed(msg, 5000);
5875 } else {
5876 Slog.w(TAG, "Drag already in progress");
5877 }
5878 } catch (Surface.OutOfResourcesException e) {
5879 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5880 if (mDragState != null) {
5881 mDragState.reset();
5882 mDragState = null;
5883 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005884 }
5885 }
5886 } finally {
5887 Binder.restoreCallingIdentity(origId);
5888 }
5889
5890 return token;
5891 }
5892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005893 // -------------------------------------------------------------
5894 // Input Events and Focus Management
5895 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005896
Jeff Brown349703e2010-06-22 01:27:15 -07005897 InputMonitor mInputMonitor = new InputMonitor();
5898
5899 /* Tracks the progress of input dispatch and ensures that input dispatch state
5900 * is kept in sync with changes in window focus, visibility, registration, and
5901 * other relevant Window Manager state transitions. */
5902 final class InputMonitor {
5903 // Current window with input focus for keys and other non-touch events. May be null.
5904 private WindowState mInputFocus;
5905
5906 // When true, prevents input dispatch from proceeding until set to false again.
5907 private boolean mInputDispatchFrozen;
5908
5909 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5910 private boolean mInputDispatchEnabled = true;
5911
Jeff Brown3a22cd92011-01-21 13:59:04 -08005912 // When true, need to call updateInputWindowsLw().
5913 private boolean mUpdateInputWindowsNeeded = true;
5914
Jeff Brown349703e2010-06-22 01:27:15 -07005915 // Temporary list of windows information to provide to the input dispatcher.
5916 private InputWindowList mTempInputWindows = new InputWindowList();
5917
5918 // Temporary input application object to provide to the input dispatcher.
5919 private InputApplication mTempInputApplication = new InputApplication();
5920
Jeff Brownb09abc12011-01-13 21:08:27 -08005921 // Set to true when the first input device configuration change notification
5922 // is received to indicate that the input devices are ready.
5923 private final Object mInputDevicesReadyMonitor = new Object();
5924 private boolean mInputDevicesReady;
5925
Jeff Brown349703e2010-06-22 01:27:15 -07005926 /* Notifies the window manager about a broken input channel.
5927 *
5928 * Called by the InputManager.
5929 */
Jeff Brown928e0542011-01-10 11:17:36 -08005930 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5931 if (inputWindowHandle == null) {
5932 return;
5933 }
5934
Jeff Brown349703e2010-06-22 01:27:15 -07005935 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005936 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005937 Slog.i(TAG, "WINDOW DIED " + windowState);
5938 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005939 }
5940 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005941
Jeff Brown519e0242010-09-15 15:18:56 -07005942 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005943 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005944 *
5945 * Called by the InputManager.
5946 */
Jeff Brown928e0542011-01-10 11:17:36 -08005947 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5948 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005949 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005950 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005951 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005952 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005953 if (windowState != null) {
5954 Slog.i(TAG, "Input event dispatching timed out sending to "
5955 + windowState.mAttrs.getTitle());
5956 appWindowToken = windowState.mAppToken;
5957 }
Jeff Brown349703e2010-06-22 01:27:15 -07005958 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005959 }
5960
Jeff Brown928e0542011-01-10 11:17:36 -08005961 if (appWindowToken == null && inputApplicationHandle != null) {
5962 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005963 Slog.i(TAG, "Input event dispatching timed out sending to application "
5964 + appWindowToken.stringName);
5965 }
Jeff Brown349703e2010-06-22 01:27:15 -07005966
Jeff Brown519e0242010-09-15 15:18:56 -07005967 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005968 try {
5969 // Notify the activity manager about the timeout and let it decide whether
5970 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005971 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005972 if (! abort) {
5973 // The activity manager declined to abort dispatching.
5974 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005975 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005976 }
Jeff Brown349703e2010-06-22 01:27:15 -07005977 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005978 }
5979 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005980 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005981 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005982
Chris Tatea32dcf72010-10-14 12:13:50 -07005983 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005984 final InputWindow inputWindow = windowList.add();
5985 inputWindow.inputChannel = mDragState.mServerChannel;
5986 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08005987 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07005988 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5989 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5990 inputWindow.visible = true;
5991 inputWindow.canReceiveKeys = false;
5992 inputWindow.hasFocus = true;
5993 inputWindow.hasWallpaper = false;
5994 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005995 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005996 inputWindow.ownerPid = Process.myPid();
5997 inputWindow.ownerUid = Process.myUid();
5998
5999 // The drag window covers the entire display
6000 inputWindow.frameLeft = 0;
6001 inputWindow.frameTop = 0;
6002 inputWindow.frameRight = mDisplay.getWidth();
6003 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07006004
Jeff Brownfbf09772011-01-16 14:06:57 -08006005 // The drag window cannot receive new touches.
6006 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07006007 }
6008
Jeff Brown3a22cd92011-01-21 13:59:04 -08006009 public void setUpdateInputWindowsNeededLw() {
6010 mUpdateInputWindowsNeeded = true;
6011 }
6012
Jeff Brown349703e2010-06-22 01:27:15 -07006013 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08006014 public void updateInputWindowsLw(boolean force) {
6015 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006016 return;
6017 }
6018 mUpdateInputWindowsNeeded = false;
6019
Jeff Brown349703e2010-06-22 01:27:15 -07006020 // Populate the input window list with information about all of the windows that
6021 // could potentially receive input.
6022 // As an optimization, we could try to prune the list of windows but this turns
6023 // out to be difficult because only the native code knows for sure which window
6024 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07006025 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07006026
6027 // If there's a drag in flight, provide a pseudowindow to catch drag input
6028 final boolean inDrag = (mDragState != null);
6029 if (inDrag) {
6030 if (DEBUG_DRAG) {
6031 Log.d(TAG, "Inserting drag window");
6032 }
Chris Tatea32dcf72010-10-14 12:13:50 -07006033 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07006034 }
6035
Jeff Brown7fbdc842010-06-17 20:52:56 -07006036 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07006037 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006038 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07006039 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07006040 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07006041 continue;
6042 }
6043
Jeff Brown349703e2010-06-22 01:27:15 -07006044 final int flags = child.mAttrs.flags;
6045 final int type = child.mAttrs.type;
6046
6047 final boolean hasFocus = (child == mInputFocus);
6048 final boolean isVisible = child.isVisibleLw();
6049 final boolean hasWallpaper = (child == mWallpaperTarget)
6050 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07006051
6052 // If there's a drag in progress and 'child' is a potential drop target,
6053 // make sure it's been told about the drag
6054 if (inDrag && isVisible) {
6055 mDragState.sendDragStartedIfNeededLw(child);
6056 }
6057
Jeff Brown349703e2010-06-22 01:27:15 -07006058 // Add a window to our list of input windows.
6059 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08006060 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006061 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07006062 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07006063 inputWindow.layoutParamsFlags = flags;
6064 inputWindow.layoutParamsType = type;
6065 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
6066 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07006067 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07006068 inputWindow.hasFocus = hasFocus;
6069 inputWindow.hasWallpaper = hasWallpaper;
6070 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07006071 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07006072 inputWindow.ownerPid = child.mSession.mPid;
6073 inputWindow.ownerUid = child.mSession.mUid;
6074
6075 final Rect frame = child.mFrame;
6076 inputWindow.frameLeft = frame.left;
6077 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006078 inputWindow.frameRight = frame.right;
6079 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006080
6081 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006082 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006083
Jeff Brown349703e2010-06-22 01:27:15 -07006084 // Send windows to native code.
6085 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006086
Jeff Brown349703e2010-06-22 01:27:15 -07006087 // Clear the list in preparation for the next round.
6088 // Also avoids keeping InputChannel objects referenced unnecessarily.
6089 mTempInputWindows.clear();
6090 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006091
6092 /* Notifies that the input device configuration has changed. */
6093 public void notifyConfigurationChanged() {
6094 sendNewConfiguration();
6095
6096 synchronized (mInputDevicesReadyMonitor) {
6097 if (!mInputDevicesReady) {
6098 mInputDevicesReady = true;
6099 mInputDevicesReadyMonitor.notifyAll();
6100 }
6101 }
6102 }
6103
6104 /* Waits until the built-in input devices have been configured. */
6105 public boolean waitForInputDevicesReady(long timeoutMillis) {
6106 synchronized (mInputDevicesReadyMonitor) {
6107 if (!mInputDevicesReady) {
6108 try {
6109 mInputDevicesReadyMonitor.wait(timeoutMillis);
6110 } catch (InterruptedException ex) {
6111 }
6112 }
6113 return mInputDevicesReady;
6114 }
6115 }
6116
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006117 /* Notifies that the lid switch changed state. */
6118 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6119 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6120 }
6121
Jeff Brown349703e2010-06-22 01:27:15 -07006122 /* Provides an opportunity for the window manager policy to intercept early key
6123 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006124 public int interceptKeyBeforeQueueing(
6125 KeyEvent event, int policyFlags, boolean isScreenOn) {
6126 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006127 }
6128
6129 /* Provides an opportunity for the window manager policy to process a key before
6130 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006131 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006132 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006133 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006134 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006135 }
6136
Jeff Brown3915bb82010-11-05 15:02:16 -07006137 /* Provides an opportunity for the window manager policy to process a key that
6138 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006139 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006140 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006141 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006142 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006143 }
6144
Jeff Brown349703e2010-06-22 01:27:15 -07006145 /* Called when the current input focus changes.
6146 * Layer assignment is assumed to be complete by the time this is called.
6147 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006148 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006149 if (DEBUG_INPUT) {
6150 Slog.d(TAG, "Input focus has changed to " + newWindow);
6151 }
6152
6153 if (newWindow != mInputFocus) {
6154 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006155 // Displaying a window implicitly causes dispatching to be unpaused.
6156 // This is to protect against bugs if someone pauses dispatching but
6157 // forgets to resume.
6158 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006159 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006160
Jeff Brown349703e2010-06-22 01:27:15 -07006161 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006162 setUpdateInputWindowsNeededLw();
6163
6164 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006165 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006166 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006167 }
6168 }
6169
Jeff Brown349703e2010-06-22 01:27:15 -07006170 public void setFocusedAppLw(AppWindowToken newApp) {
6171 // Focused app has changed.
6172 if (newApp == null) {
6173 mInputManager.setFocusedApplication(null);
6174 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006175 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006176 mTempInputApplication.name = newApp.toString();
6177 mTempInputApplication.dispatchingTimeoutNanos =
6178 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006179
Jeff Brown349703e2010-06-22 01:27:15 -07006180 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006181
6182 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006183 }
6184 }
6185
Jeff Brown349703e2010-06-22 01:27:15 -07006186 public void pauseDispatchingLw(WindowToken window) {
6187 if (! window.paused) {
6188 if (DEBUG_INPUT) {
6189 Slog.v(TAG, "Pausing WindowToken " + window);
6190 }
6191
6192 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006193 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006194 }
6195 }
6196
6197 public void resumeDispatchingLw(WindowToken window) {
6198 if (window.paused) {
6199 if (DEBUG_INPUT) {
6200 Slog.v(TAG, "Resuming WindowToken " + window);
6201 }
6202
6203 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006204 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006205 }
6206 }
6207
6208 public void freezeInputDispatchingLw() {
6209 if (! mInputDispatchFrozen) {
6210 if (DEBUG_INPUT) {
6211 Slog.v(TAG, "Freezing input dispatching");
6212 }
6213
6214 mInputDispatchFrozen = true;
6215 updateInputDispatchModeLw();
6216 }
6217 }
6218
6219 public void thawInputDispatchingLw() {
6220 if (mInputDispatchFrozen) {
6221 if (DEBUG_INPUT) {
6222 Slog.v(TAG, "Thawing input dispatching");
6223 }
6224
6225 mInputDispatchFrozen = false;
6226 updateInputDispatchModeLw();
6227 }
6228 }
6229
6230 public void setEventDispatchingLw(boolean enabled) {
6231 if (mInputDispatchEnabled != enabled) {
6232 if (DEBUG_INPUT) {
6233 Slog.v(TAG, "Setting event dispatching to " + enabled);
6234 }
6235
6236 mInputDispatchEnabled = enabled;
6237 updateInputDispatchModeLw();
6238 }
6239 }
6240
6241 private void updateInputDispatchModeLw() {
6242 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6243 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006246 public void pauseKeyDispatching(IBinder _token) {
6247 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6248 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006249 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250 }
6251
6252 synchronized (mWindowMap) {
6253 WindowToken token = mTokenMap.get(_token);
6254 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006255 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006256 }
6257 }
6258 }
6259
6260 public void resumeKeyDispatching(IBinder _token) {
6261 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6262 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006263 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006264 }
6265
6266 synchronized (mWindowMap) {
6267 WindowToken token = mTokenMap.get(_token);
6268 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006269 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270 }
6271 }
6272 }
6273
6274 public void setEventDispatching(boolean enabled) {
6275 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6276 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006277 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 }
6279
6280 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006281 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006282 }
6283 }
Romain Guy06882f82009-06-10 13:36:04 -07006284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 /**
6286 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006287 * Even when sync is false, this method may block while waiting for current
6288 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006289 *
6290 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006291 * {@link SystemClock#uptimeMillis()} as the timebase.)
6292 * @param sync If true, wait for the event to be completed before returning to the caller.
6293 * @return Returns true if event was dispatched, false if it was dropped for any reason
6294 */
6295 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6296 long downTime = ev.getDownTime();
6297 long eventTime = ev.getEventTime();
6298
6299 int action = ev.getAction();
6300 int code = ev.getKeyCode();
6301 int repeatCount = ev.getRepeatCount();
6302 int metaState = ev.getMetaState();
6303 int deviceId = ev.getDeviceId();
6304 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006305 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006306 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006307
6308 if (source == InputDevice.SOURCE_UNKNOWN) {
6309 source = InputDevice.SOURCE_KEYBOARD;
6310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006311
6312 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6313 if (downTime == 0) downTime = eventTime;
6314
6315 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006316 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006317
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006318 final int pid = Binder.getCallingPid();
6319 final int uid = Binder.getCallingUid();
6320 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006321
Jeff Brownbbda99d2010-07-28 15:48:59 -07006322 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6323 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6324 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6325 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006326
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006327 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006328 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 }
6330
6331 /**
6332 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006333 * Even when sync is false, this method may block while waiting for current
6334 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006335 *
6336 * @param ev A motion event describing the pointer (touch) action. (As noted in
6337 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 * {@link SystemClock#uptimeMillis()} as the timebase.)
6339 * @param sync If true, wait for the event to be completed before returning to the caller.
6340 * @return Returns true if event was dispatched, false if it was dropped for any reason
6341 */
6342 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006343 final int pid = Binder.getCallingPid();
6344 final int uid = Binder.getCallingUid();
6345 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006346
Jeff Brownc5ed5912010-07-14 18:48:53 -07006347 MotionEvent newEvent = MotionEvent.obtain(ev);
6348 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6349 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6350 }
6351
Jeff Brownbbda99d2010-07-28 15:48:59 -07006352 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6353 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6354 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6355 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006356
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006357 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006358 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 }
Romain Guy06882f82009-06-10 13:36:04 -07006360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006361 /**
6362 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006363 * Even when sync is false, this method may block while waiting for current
6364 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006365 *
6366 * @param ev A motion event describing the trackball action. (As noted in
6367 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 * {@link SystemClock#uptimeMillis()} as the timebase.)
6369 * @param sync If true, wait for the event to be completed before returning to the caller.
6370 * @return Returns true if event was dispatched, false if it was dropped for any reason
6371 */
6372 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006373 final int pid = Binder.getCallingPid();
6374 final int uid = Binder.getCallingUid();
6375 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006376
Jeff Brownc5ed5912010-07-14 18:48:53 -07006377 MotionEvent newEvent = MotionEvent.obtain(ev);
6378 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6379 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6380 }
6381
Jeff Brownbbda99d2010-07-28 15:48:59 -07006382 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6383 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6384 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6385 INJECTION_TIMEOUT_MILLIS);
6386
6387 Binder.restoreCallingIdentity(ident);
6388 return reportInjectionResult(result);
6389 }
6390
6391 /**
6392 * Inject an input event into the UI without waiting for dispatch to commence.
6393 * This variant is useful for fire-and-forget input event injection. It does not
6394 * block any longer than it takes to enqueue the input event.
6395 *
6396 * @param ev An input event. (Be sure to set the input source correctly.)
6397 * @return Returns true if event was dispatched, false if it was dropped for any reason
6398 */
6399 public boolean injectInputEventNoWait(InputEvent ev) {
6400 final int pid = Binder.getCallingPid();
6401 final int uid = Binder.getCallingUid();
6402 final long ident = Binder.clearCallingIdentity();
6403
6404 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6405 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6406 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006407
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006408 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006409 return reportInjectionResult(result);
6410 }
6411
6412 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006413 switch (result) {
6414 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6415 Slog.w(TAG, "Input event injection permission denied.");
6416 throw new SecurityException(
6417 "Injecting to another application requires INJECT_EVENTS permission");
6418 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006419 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006420 return true;
6421 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6422 Slog.w(TAG, "Input event injection timed out.");
6423 return false;
6424 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6425 default:
6426 Slog.w(TAG, "Input event injection failed.");
6427 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 }
Romain Guy06882f82009-06-10 13:36:04 -07006430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006431 private WindowState getFocusedWindow() {
6432 synchronized (mWindowMap) {
6433 return getFocusedWindowLocked();
6434 }
6435 }
6436
6437 private WindowState getFocusedWindowLocked() {
6438 return mCurrentFocus;
6439 }
Romain Guy06882f82009-06-10 13:36:04 -07006440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006442 if (!mInputMonitor.waitForInputDevicesReady(
6443 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6444 Slog.w(TAG, "Devices still not ready after waiting "
6445 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6446 + " milliseconds before attempting to detect safe mode.");
6447 }
6448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006449 mSafeMode = mPolicy.detectSafeMode();
6450 return mSafeMode;
6451 }
Romain Guy06882f82009-06-10 13:36:04 -07006452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006454 synchronized(mWindowMap) {
6455 if (mDisplay != null) {
6456 throw new IllegalStateException("Display already initialized");
6457 }
6458 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6459 mDisplay = wm.getDefaultDisplay();
6460 mInitialDisplayWidth = mDisplay.getWidth();
6461 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006462 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6463 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006464 }
6465
6466 try {
6467 mActivityManager.updateConfiguration(null);
6468 } catch (RemoteException e) {
6469 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006470
6471 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006472 }
6473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 // -------------------------------------------------------------
6475 // Client Session State
6476 // -------------------------------------------------------------
6477
6478 private final class Session extends IWindowSession.Stub
6479 implements IBinder.DeathRecipient {
6480 final IInputMethodClient mClient;
6481 final IInputContext mInputContext;
6482 final int mUid;
6483 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006484 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006485 SurfaceSession mSurfaceSession;
6486 int mNumWindow = 0;
6487 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006489 public Session(IInputMethodClient client, IInputContext inputContext) {
6490 mClient = client;
6491 mInputContext = inputContext;
6492 mUid = Binder.getCallingUid();
6493 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006494 StringBuilder sb = new StringBuilder();
6495 sb.append("Session{");
6496 sb.append(Integer.toHexString(System.identityHashCode(this)));
6497 sb.append(" uid ");
6498 sb.append(mUid);
6499 sb.append("}");
6500 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 synchronized (mWindowMap) {
6503 if (mInputMethodManager == null && mHaveInputMethods) {
6504 IBinder b = ServiceManager.getService(
6505 Context.INPUT_METHOD_SERVICE);
6506 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6507 }
6508 }
6509 long ident = Binder.clearCallingIdentity();
6510 try {
6511 // Note: it is safe to call in to the input method manager
6512 // here because we are not holding our lock.
6513 if (mInputMethodManager != null) {
6514 mInputMethodManager.addClient(client, inputContext,
6515 mUid, mPid);
6516 } else {
6517 client.setUsingInputMethod(false);
6518 }
6519 client.asBinder().linkToDeath(this, 0);
6520 } catch (RemoteException e) {
6521 // The caller has died, so we can just forget about this.
6522 try {
6523 if (mInputMethodManager != null) {
6524 mInputMethodManager.removeClient(client);
6525 }
6526 } catch (RemoteException ee) {
6527 }
6528 } finally {
6529 Binder.restoreCallingIdentity(ident);
6530 }
6531 }
Romain Guy06882f82009-06-10 13:36:04 -07006532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 @Override
6534 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6535 throws RemoteException {
6536 try {
6537 return super.onTransact(code, data, reply, flags);
6538 } catch (RuntimeException e) {
6539 // Log all 'real' exceptions thrown to the caller
6540 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006541 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 }
6543 throw e;
6544 }
6545 }
6546
6547 public void binderDied() {
6548 // Note: it is safe to call in to the input method manager
6549 // here because we are not holding our lock.
6550 try {
6551 if (mInputMethodManager != null) {
6552 mInputMethodManager.removeClient(mClient);
6553 }
6554 } catch (RemoteException e) {
6555 }
6556 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006557 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 mClientDead = true;
6559 killSessionLocked();
6560 }
6561 }
6562
6563 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006564 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6565 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6566 outInputChannel);
6567 }
6568
6569 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006571 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006572 }
Romain Guy06882f82009-06-10 13:36:04 -07006573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 public void remove(IWindow window) {
6575 removeWindow(this, window);
6576 }
Romain Guy06882f82009-06-10 13:36:04 -07006577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006578 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6579 int requestedWidth, int requestedHeight, int viewFlags,
6580 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006581 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006582 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6583 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006584 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006585 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006586 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6587 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006588 }
Romain Guy06882f82009-06-10 13:36:04 -07006589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 public void setTransparentRegion(IWindow window, Region region) {
6591 setTransparentRegionWindow(this, window, region);
6592 }
Romain Guy06882f82009-06-10 13:36:04 -07006593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006594 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006595 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006596 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006597 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006598 }
Romain Guy06882f82009-06-10 13:36:04 -07006599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6601 getWindowDisplayFrame(this, window, outDisplayFrame);
6602 }
Romain Guy06882f82009-06-10 13:36:04 -07006603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006604 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006605 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006606 TAG, "IWindow finishDrawing called for " + window);
6607 finishDrawingWindow(this, window);
6608 }
6609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006610 public void setInTouchMode(boolean mode) {
6611 synchronized(mWindowMap) {
6612 mInTouchMode = mode;
6613 }
6614 }
6615
6616 public boolean getInTouchMode() {
6617 synchronized(mWindowMap) {
6618 return mInTouchMode;
6619 }
6620 }
6621
6622 public boolean performHapticFeedback(IWindow window, int effectId,
6623 boolean always) {
6624 synchronized(mWindowMap) {
6625 long ident = Binder.clearCallingIdentity();
6626 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006627 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006628 windowForClientLocked(this, window, true),
6629 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006630 } finally {
6631 Binder.restoreCallingIdentity(ident);
6632 }
6633 }
6634 }
Romain Guy06882f82009-06-10 13:36:04 -07006635
Christopher Tatea53146c2010-09-07 11:57:52 -07006636 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006637 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006638 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006639 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006640 width, height, outSurface);
6641 }
6642
6643 public boolean performDrag(IWindow window, IBinder dragToken,
6644 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6645 ClipData data) {
6646 if (DEBUG_DRAG) {
6647 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6648 }
6649
6650 synchronized (mWindowMap) {
6651 if (mDragState == null) {
6652 Slog.w(TAG, "No drag prepared");
6653 throw new IllegalStateException("performDrag() without prepareDrag()");
6654 }
6655
6656 if (dragToken != mDragState.mToken) {
6657 Slog.w(TAG, "Performing mismatched drag");
6658 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6659 }
6660
6661 WindowState callingWin = windowForClientLocked(null, window, false);
6662 if (callingWin == null) {
6663 Slog.w(TAG, "Bad requesting window " + window);
6664 return false; // !!! TODO: throw here?
6665 }
6666
6667 // !!! TODO: if input is not still focused on the initiating window, fail
6668 // the drag initiation (e.g. an alarm window popped up just as the application
6669 // called performDrag()
6670
6671 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6672
Christopher Tate2c095f32010-10-04 14:13:40 -07006673 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6674 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006675
Chris Tateb478f462010-10-15 16:02:26 -07006676 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6677 // the actual drag event dispatch stuff in the dragstate
6678
Christopher Tatea53146c2010-09-07 11:57:52 -07006679 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006680 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006681 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6682 mDragState.mServerChannel)) {
6683 Slog.e(TAG, "Unable to transfer touch focus");
6684 mDragState.unregister();
6685 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006686 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006687 return false;
6688 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006689
6690 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006691 mDragState.mCurrentX = touchX;
6692 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006693 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006694
6695 // remember the thumb offsets for later
6696 mDragState.mThumbOffsetX = thumbCenterX;
6697 mDragState.mThumbOffsetY = thumbCenterY;
6698
6699 // Make the surface visible at the proper location
6700 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006701 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006702 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006703 try {
6704 surface.setPosition((int)(touchX - thumbCenterX),
6705 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006706 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006707 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006708 surface.show();
6709 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006710 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006711 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006712 }
6713 }
6714
6715 return true; // success!
6716 }
6717
Chris Tated4533f142010-10-19 15:15:08 -07006718 public void reportDropResult(IWindow window, boolean consumed) {
6719 IBinder token = window.asBinder();
6720 if (DEBUG_DRAG) {
6721 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6722 }
6723
6724 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006725 long ident = Binder.clearCallingIdentity();
6726 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006727 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006728 Slog.w(TAG, "Invalid drop-result claim by " + window);
6729 throw new IllegalStateException("reportDropResult() by non-recipient");
6730 }
6731
6732 // The right window has responded, even if it's no longer around,
6733 // so be sure to halt the timeout even if the later WindowState
6734 // lookup fails.
6735 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6736 WindowState callingWin = windowForClientLocked(null, window, false);
6737 if (callingWin == null) {
6738 Slog.w(TAG, "Bad result-reporting window " + window);
6739 return; // !!! TODO: throw here?
6740 }
6741
6742 mDragState.mDragResult = consumed;
6743 mDragState.endDragLw();
6744 } finally {
6745 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006746 }
Chris Tated4533f142010-10-19 15:15:08 -07006747 }
6748 }
6749
Christopher Tatea53146c2010-09-07 11:57:52 -07006750 public void dragRecipientEntered(IWindow window) {
6751 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006752 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006753 }
6754 }
6755
6756 public void dragRecipientExited(IWindow window) {
6757 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006758 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006759 }
6760 }
6761
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006762 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006763 synchronized(mWindowMap) {
6764 long ident = Binder.clearCallingIdentity();
6765 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006766 setWindowWallpaperPositionLocked(
6767 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006768 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006769 } finally {
6770 Binder.restoreCallingIdentity(ident);
6771 }
6772 }
6773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006774
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006775 public void wallpaperOffsetsComplete(IBinder window) {
6776 WindowManagerService.this.wallpaperOffsetsComplete(window);
6777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006778
Dianne Hackborn75804932009-10-20 20:15:20 -07006779 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6780 int z, Bundle extras, boolean sync) {
6781 synchronized(mWindowMap) {
6782 long ident = Binder.clearCallingIdentity();
6783 try {
6784 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006785 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006786 action, x, y, z, extras, sync);
6787 } finally {
6788 Binder.restoreCallingIdentity(ident);
6789 }
6790 }
6791 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006792
Dianne Hackborn75804932009-10-20 20:15:20 -07006793 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6794 WindowManagerService.this.wallpaperCommandComplete(window, result);
6795 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 void windowAddedLocked() {
6798 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006799 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 TAG, "First window added to " + this + ", creating SurfaceSession");
6801 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006802 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006803 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006804 mSessions.add(this);
6805 }
6806 mNumWindow++;
6807 }
6808
6809 void windowRemovedLocked() {
6810 mNumWindow--;
6811 killSessionLocked();
6812 }
Romain Guy06882f82009-06-10 13:36:04 -07006813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 void killSessionLocked() {
6815 if (mNumWindow <= 0 && mClientDead) {
6816 mSessions.remove(this);
6817 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006818 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006819 TAG, "Last window removed from " + this
6820 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006821 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006822 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 try {
6824 mSurfaceSession.kill();
6825 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006826 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 + mSurfaceSession + " in session " + this
6828 + ": " + e.toString());
6829 }
6830 mSurfaceSession = null;
6831 }
6832 }
6833 }
Romain Guy06882f82009-06-10 13:36:04 -07006834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006835 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006836 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6837 pw.print(" mClientDead="); pw.print(mClientDead);
6838 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006839 }
6840
6841 @Override
6842 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006843 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006844 }
6845 }
6846
6847 // -------------------------------------------------------------
6848 // Client Window State
6849 // -------------------------------------------------------------
6850
6851 private final class WindowState implements WindowManagerPolicy.WindowState {
6852 final Session mSession;
6853 final IWindow mClient;
6854 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006855 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 AppWindowToken mAppToken;
6857 AppWindowToken mTargetAppToken;
6858 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6859 final DeathRecipient mDeathRecipient;
6860 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006861 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862 final int mBaseLayer;
6863 final int mSubLayer;
6864 final boolean mLayoutAttached;
6865 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006866 final boolean mIsWallpaper;
6867 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006868 int mViewVisibility;
6869 boolean mPolicyVisibility = true;
6870 boolean mPolicyVisibilityAfterAnim = true;
6871 boolean mAppFreezing;
6872 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006873 boolean mReportDestroySurface;
6874 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006875 boolean mAttachedHidden; // is our parent window hidden?
6876 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006877 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 int mRequestedWidth;
6879 int mRequestedHeight;
6880 int mLastRequestedWidth;
6881 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006882 int mLayer;
6883 int mAnimLayer;
6884 int mLastLayer;
6885 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006886 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006887 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006888
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006889 int mLayoutSeq = -1;
6890
6891 Configuration mConfiguration = null;
6892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 // Actual frame shown on-screen (may be modified by animation)
6894 final Rect mShownFrame = new Rect();
6895 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006898 * Set when we have changed the size of the surface, to know that
6899 * we must tell them application to resize (and thus redraw itself).
6900 */
6901 boolean mSurfaceResized;
6902
6903 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006904 * Insets that determine the actually visible area
6905 */
6906 final Rect mVisibleInsets = new Rect();
6907 final Rect mLastVisibleInsets = new Rect();
6908 boolean mVisibleInsetsChanged;
6909
6910 /**
6911 * Insets that are covered by system windows
6912 */
6913 final Rect mContentInsets = new Rect();
6914 final Rect mLastContentInsets = new Rect();
6915 boolean mContentInsetsChanged;
6916
6917 /**
6918 * Set to true if we are waiting for this window to receive its
6919 * given internal insets before laying out other windows based on it.
6920 */
6921 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006923 /**
6924 * These are the content insets that were given during layout for
6925 * this window, to be applied to windows behind it.
6926 */
6927 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006929 /**
6930 * These are the visible insets that were given during layout for
6931 * this window, to be applied to windows behind it.
6932 */
6933 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006935 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006936 * This is the given touchable area relative to the window frame, or null if none.
6937 */
6938 final Region mGivenTouchableRegion = new Region();
6939
6940 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 * Flag indicating whether the touchable region should be adjusted by
6942 * the visible insets; if false the area outside the visible insets is
6943 * NOT touchable, so we must use those to adjust the frame during hit
6944 * tests.
6945 */
6946 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006949 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006950 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6951 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6952 float mHScale=1, mVScale=1;
6953 float mLastHScale=1, mLastVScale=1;
6954 final Matrix mTmpMatrix = new Matrix();
6955
6956 // "Real" frame that the application sees.
6957 final Rect mFrame = new Rect();
6958 final Rect mLastFrame = new Rect();
6959
6960 final Rect mContainingFrame = new Rect();
6961 final Rect mDisplayFrame = new Rect();
6962 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006963 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 final Rect mVisibleFrame = new Rect();
6965
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006966 boolean mContentChanged;
6967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 float mShownAlpha = 1;
6969 float mAlpha = 1;
6970 float mLastAlpha = 1;
6971
6972 // Set to true if, when the window gets displayed, it should perform
6973 // an enter animation.
6974 boolean mEnterAnimationPending;
6975
6976 // Currently running animation.
6977 boolean mAnimating;
6978 boolean mLocalAnimating;
6979 Animation mAnimation;
6980 boolean mAnimationIsEntrance;
6981 boolean mHasTransformation;
6982 boolean mHasLocalTransformation;
6983 final Transformation mTransformation = new Transformation();
6984
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006985 // If a window showing a wallpaper: the requested offset for the
6986 // wallpaper; if a wallpaper window: the currently applied offset.
6987 float mWallpaperX = -1;
6988 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006989
6990 // If a window showing a wallpaper: what fraction of the offset
6991 // range corresponds to a full virtual screen.
6992 float mWallpaperXStep = -1;
6993 float mWallpaperYStep = -1;
6994
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006995 // Wallpaper windows: pixels offset based on above variables.
6996 int mXOffset;
6997 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 // This is set after IWindowSession.relayout() has been called at
7000 // least once for the window. It allows us to detect the situation
7001 // where we don't yet have a surface, but should have one soon, so
7002 // we can give the window focus before waiting for the relayout.
7003 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007005 // This is set after the Surface has been created but before the
7006 // window has been drawn. During this time the surface is hidden.
7007 boolean mDrawPending;
7008
7009 // This is set after the window has finished drawing for the first
7010 // time but before its surface is shown. The surface will be
7011 // displayed when the next layout is run.
7012 boolean mCommitDrawPending;
7013
7014 // This is set during the time after the window's drawing has been
7015 // committed, and before its surface is actually shown. It is used
7016 // to delay showing the surface until all windows in a token are ready
7017 // to be shown.
7018 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007020 // Set when the window has been shown in the screen the first time.
7021 boolean mHasDrawn;
7022
7023 // Currently running an exit animation?
7024 boolean mExiting;
7025
7026 // Currently on the mDestroySurface list?
7027 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 // Completely remove from window manager after exit animation?
7030 boolean mRemoveOnExit;
7031
7032 // Set when the orientation is changing and this window has not yet
7033 // been updated for the new orientation.
7034 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007036 // Is this window now (or just being) removed?
7037 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007038
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007039 // Temp for keeping track of windows that have been removed when
7040 // rebuilding window list.
7041 boolean mRebuilding;
7042
Dianne Hackborn16064f92010-03-25 00:47:24 -07007043 // For debugging, this is the last information given to the surface flinger.
7044 boolean mSurfaceShown;
7045 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7046 int mSurfaceLayer;
7047 float mSurfaceAlpha;
7048
Jeff Brown928e0542011-01-10 11:17:36 -08007049 // Input channel and input window handle used by the input dispatcher.
7050 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007051 InputChannel mInputChannel;
7052
Mattias Petersson1622eee2010-12-21 10:15:11 +01007053 // Used to improve performance of toString()
7054 String mStringNameCache;
7055 CharSequence mLastTitle;
7056 boolean mWasPaused;
7057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007058 WindowState(Session s, IWindow c, WindowToken token,
7059 WindowState attachedWindow, WindowManager.LayoutParams a,
7060 int viewVisibility) {
7061 mSession = s;
7062 mClient = c;
7063 mToken = token;
7064 mAttrs.copyFrom(a);
7065 mViewVisibility = viewVisibility;
7066 DeathRecipient deathRecipient = new DeathRecipient();
7067 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007068 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007069 TAG, "Window " + this + " client=" + c.asBinder()
7070 + " token=" + token + " (" + mAttrs.token + ")");
7071 try {
7072 c.asBinder().linkToDeath(deathRecipient, 0);
7073 } catch (RemoteException e) {
7074 mDeathRecipient = null;
7075 mAttachedWindow = null;
7076 mLayoutAttached = false;
7077 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007078 mIsWallpaper = false;
7079 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007080 mBaseLayer = 0;
7081 mSubLayer = 0;
7082 return;
7083 }
7084 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7087 mAttrs.type <= LAST_SUB_WINDOW)) {
7088 // The multiplier here is to reserve space for multiple
7089 // windows in the same type layer.
7090 mBaseLayer = mPolicy.windowTypeToLayerLw(
7091 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7092 + TYPE_LAYER_OFFSET;
7093 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7094 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007095 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007096 mAttachedWindow.mChildWindows.add(this);
7097 mLayoutAttached = mAttrs.type !=
7098 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7099 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7100 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007101 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7102 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 } else {
7104 // The multiplier here is to reserve space for multiple
7105 // windows in the same type layer.
7106 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7107 * TYPE_LAYER_MULTIPLIER
7108 + TYPE_LAYER_OFFSET;
7109 mSubLayer = 0;
7110 mAttachedWindow = null;
7111 mLayoutAttached = false;
7112 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7113 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007114 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7115 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007116 }
7117
7118 WindowState appWin = this;
7119 while (appWin.mAttachedWindow != null) {
7120 appWin = mAttachedWindow;
7121 }
7122 WindowToken appToken = appWin.mToken;
7123 while (appToken.appWindowToken == null) {
7124 WindowToken parent = mTokenMap.get(appToken.token);
7125 if (parent == null || appToken == parent) {
7126 break;
7127 }
7128 appToken = parent;
7129 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007130 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007131 mAppToken = appToken.appWindowToken;
7132
7133 mSurface = null;
7134 mRequestedWidth = 0;
7135 mRequestedHeight = 0;
7136 mLastRequestedWidth = 0;
7137 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007138 mXOffset = 0;
7139 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007140 mLayer = 0;
7141 mAnimLayer = 0;
7142 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007143 mInputWindowHandle = new InputWindowHandle(
7144 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007145 }
7146
7147 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007148 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 TAG, "Attaching " + this + " token=" + mToken
7150 + ", list=" + mToken.windows);
7151 mSession.windowAddedLocked();
7152 }
7153
7154 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7155 mHaveFrame = true;
7156
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007157 final Rect container = mContainingFrame;
7158 container.set(pf);
7159
7160 final Rect display = mDisplayFrame;
7161 display.set(df);
7162
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007163 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007164 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007165 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7166 display.intersect(mCompatibleScreenFrame);
7167 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007168 }
7169
7170 final int pw = container.right - container.left;
7171 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007172
7173 int w,h;
7174 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7175 w = mAttrs.width < 0 ? pw : mAttrs.width;
7176 h = mAttrs.height< 0 ? ph : mAttrs.height;
7177 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007178 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7179 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007180 }
Romain Guy06882f82009-06-10 13:36:04 -07007181
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007182 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007183 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7184 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007185 mParentFrame.set(pf);
7186 mContentChanged = true;
7187 }
7188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007189 final Rect content = mContentFrame;
7190 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 final Rect visible = mVisibleFrame;
7193 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007196 final int fw = frame.width();
7197 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7200 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7201
7202 Gravity.apply(mAttrs.gravity, w, h, container,
7203 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7204 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7205
7206 //System.out.println("Out: " + mFrame);
7207
7208 // Now make sure the window fits in the overall display.
7209 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007211 // Make sure the content and visible frames are inside of the
7212 // final window frame.
7213 if (content.left < frame.left) content.left = frame.left;
7214 if (content.top < frame.top) content.top = frame.top;
7215 if (content.right > frame.right) content.right = frame.right;
7216 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7217 if (visible.left < frame.left) visible.left = frame.left;
7218 if (visible.top < frame.top) visible.top = frame.top;
7219 if (visible.right > frame.right) visible.right = frame.right;
7220 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007222 final Rect contentInsets = mContentInsets;
7223 contentInsets.left = content.left-frame.left;
7224 contentInsets.top = content.top-frame.top;
7225 contentInsets.right = frame.right-content.right;
7226 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228 final Rect visibleInsets = mVisibleInsets;
7229 visibleInsets.left = visible.left-frame.left;
7230 visibleInsets.top = visible.top-frame.top;
7231 visibleInsets.right = frame.right-visible.right;
7232 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007233
Dianne Hackborn284ac932009-08-28 10:34:25 -07007234 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7235 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007236 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007237 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239 if (localLOGV) {
7240 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7241 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007242 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007243 + mRequestedWidth + ", mRequestedheight="
7244 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7245 + "): frame=" + mFrame.toShortString()
7246 + " ci=" + contentInsets.toShortString()
7247 + " vi=" + visibleInsets.toShortString());
7248 //}
7249 }
7250 }
Romain Guy06882f82009-06-10 13:36:04 -07007251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 public Rect getFrameLw() {
7253 return mFrame;
7254 }
7255
7256 public Rect getShownFrameLw() {
7257 return mShownFrame;
7258 }
7259
7260 public Rect getDisplayFrameLw() {
7261 return mDisplayFrame;
7262 }
7263
7264 public Rect getContentFrameLw() {
7265 return mContentFrame;
7266 }
7267
7268 public Rect getVisibleFrameLw() {
7269 return mVisibleFrame;
7270 }
7271
7272 public boolean getGivenInsetsPendingLw() {
7273 return mGivenInsetsPending;
7274 }
7275
7276 public Rect getGivenContentInsetsLw() {
7277 return mGivenContentInsets;
7278 }
Romain Guy06882f82009-06-10 13:36:04 -07007279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007280 public Rect getGivenVisibleInsetsLw() {
7281 return mGivenVisibleInsets;
7282 }
Romain Guy06882f82009-06-10 13:36:04 -07007283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 public WindowManager.LayoutParams getAttrs() {
7285 return mAttrs;
7286 }
7287
7288 public int getSurfaceLayer() {
7289 return mLayer;
7290 }
Romain Guy06882f82009-06-10 13:36:04 -07007291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007292 public IApplicationToken getAppToken() {
7293 return mAppToken != null ? mAppToken.appToken : null;
7294 }
Jeff Brown349703e2010-06-22 01:27:15 -07007295
7296 public long getInputDispatchingTimeoutNanos() {
7297 return mAppToken != null
7298 ? mAppToken.inputDispatchingTimeoutNanos
7299 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301
7302 public boolean hasAppShownWindows() {
7303 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7304 }
7305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007306 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007307 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007308 TAG, "Setting animation in " + this + ": " + anim);
7309 mAnimating = false;
7310 mLocalAnimating = false;
7311 mAnimation = anim;
7312 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7313 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7314 }
7315
7316 public void clearAnimation() {
7317 if (mAnimation != null) {
7318 mAnimating = true;
7319 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007320 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 mAnimation = null;
7322 }
7323 }
Romain Guy06882f82009-06-10 13:36:04 -07007324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 Surface createSurfaceLocked() {
7326 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007327 mReportDestroySurface = false;
7328 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 mDrawPending = true;
7330 mCommitDrawPending = false;
7331 mReadyToShow = false;
7332 if (mAppToken != null) {
7333 mAppToken.allDrawn = false;
7334 }
7335
7336 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007337
7338 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7339 flags |= Surface.SECURE;
7340 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007341 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 TAG, "Creating surface in session "
7343 + mSession.mSurfaceSession + " window " + this
7344 + " w=" + mFrame.width()
7345 + " h=" + mFrame.height() + " format="
7346 + mAttrs.format + " flags=" + flags);
7347
7348 int w = mFrame.width();
7349 int h = mFrame.height();
7350 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7351 // for a scaled surface, we always want the requested
7352 // size.
7353 w = mRequestedWidth;
7354 h = mRequestedHeight;
7355 }
7356
Romain Guy9825ec62009-10-01 00:58:09 -07007357 // Something is wrong and SurfaceFlinger will not like this,
7358 // try to revert to sane values
7359 if (w <= 0) w = 1;
7360 if (h <= 0) h = 1;
7361
Dianne Hackborn16064f92010-03-25 00:47:24 -07007362 mSurfaceShown = false;
7363 mSurfaceLayer = 0;
7364 mSurfaceAlpha = 1;
7365 mSurfaceX = 0;
7366 mSurfaceY = 0;
7367 mSurfaceW = w;
7368 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007370 final boolean isHwAccelerated = (mAttrs.flags &
7371 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7372 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7373 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7374 flags |= Surface.OPAQUE;
7375 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007377 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007378 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007379 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007380 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007381 + mSurface + " IN SESSION "
7382 + mSession.mSurfaceSession
7383 + ": pid=" + mSession.mPid + " format="
7384 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007385 + Integer.toHexString(flags)
7386 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007388 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007389 reclaimSomeSurfaceMemoryLocked(this, "create");
7390 return null;
7391 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007392 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007393 return null;
7394 }
Romain Guy06882f82009-06-10 13:36:04 -07007395
Joe Onorato8a9b2202010-02-26 18:56:32 -08007396 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007397 TAG, "Got surface: " + mSurface
7398 + ", set left=" + mFrame.left + " top=" + mFrame.top
7399 + ", animLayer=" + mAnimLayer);
7400 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007401 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7402 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007403 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7404 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 }
7406 Surface.openTransaction();
7407 try {
7408 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007409 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007410 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007411 mSurface.setPosition(mSurfaceX, mSurfaceY);
7412 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007414 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 mSurface.hide();
7416 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007417 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 mSurface.setFlags(Surface.SURFACE_DITHER,
7419 Surface.SURFACE_DITHER);
7420 }
7421 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007422 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007423 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7424 }
7425 mLastHidden = true;
7426 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007428 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007430 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007431 TAG, "Created surface " + this);
7432 }
7433 return mSurface;
7434 }
Romain Guy06882f82009-06-10 13:36:04 -07007435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007437 if (mAppToken != null && this == mAppToken.startingWindow) {
7438 mAppToken.startingDisplayed = false;
7439 }
Romain Guy06882f82009-06-10 13:36:04 -07007440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007442 mDrawPending = false;
7443 mCommitDrawPending = false;
7444 mReadyToShow = false;
7445
7446 int i = mChildWindows.size();
7447 while (i > 0) {
7448 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007449 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007450 c.mAttachedHidden = true;
7451 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007452
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007453 if (mReportDestroySurface) {
7454 mReportDestroySurface = false;
7455 mSurfacePendingDestroy = true;
7456 try {
7457 mClient.dispatchGetNewSurface();
7458 // We'll really destroy on the next time around.
7459 return;
7460 } catch (RemoteException e) {
7461 }
7462 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007465 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007466 RuntimeException e = null;
7467 if (!HIDE_STACK_CRAWLS) {
7468 e = new RuntimeException();
7469 e.fillInStackTrace();
7470 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007471 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007472 + mSurface + ", session " + mSession, e);
7473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007475 RuntimeException e = null;
7476 if (!HIDE_STACK_CRAWLS) {
7477 e = new RuntimeException();
7478 e.fillInStackTrace();
7479 }
7480 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007482 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007484 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007485 + " surface " + mSurface + " session " + mSession
7486 + ": " + e.toString());
7487 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007488
Dianne Hackborn16064f92010-03-25 00:47:24 -07007489 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 }
7492 }
7493
7494 boolean finishDrawingLocked() {
7495 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007496 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 TAG, "finishDrawingLocked: " + mSurface);
7498 mCommitDrawPending = true;
7499 mDrawPending = false;
7500 return true;
7501 }
7502 return false;
7503 }
7504
7505 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007506 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007507 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007508 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007509 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 }
7511 mCommitDrawPending = false;
7512 mReadyToShow = true;
7513 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7514 final AppWindowToken atoken = mAppToken;
7515 if (atoken == null || atoken.allDrawn || starting) {
7516 performShowLocked();
7517 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007518 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007519 }
7520
7521 // This must be called while inside a transaction.
7522 boolean performShowLocked() {
7523 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007524 RuntimeException e = null;
7525 if (!HIDE_STACK_CRAWLS) {
7526 e = new RuntimeException();
7527 e.fillInStackTrace();
7528 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007529 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7531 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7532 }
7533 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007534 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7535 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007536 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007537 + " during animation: policyVis=" + mPolicyVisibility
7538 + " attHidden=" + mAttachedHidden
7539 + " tok.hiddenRequested="
7540 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007541 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007542 + (mAppToken != null ? mAppToken.hidden : false)
7543 + " animating=" + mAnimating
7544 + " tok animating="
7545 + (mAppToken != null ? mAppToken.animating : false));
7546 if (!showSurfaceRobustlyLocked(this)) {
7547 return false;
7548 }
7549 mLastAlpha = -1;
7550 mHasDrawn = true;
7551 mLastHidden = false;
7552 mReadyToShow = false;
7553 enableScreenIfNeededLocked();
7554
7555 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 int i = mChildWindows.size();
7558 while (i > 0) {
7559 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007560 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007561 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007563 if (c.mSurface != null) {
7564 c.performShowLocked();
7565 // It hadn't been shown, which means layout not
7566 // performed on it, so now we want to make sure to
7567 // do a layout. If called from within the transaction
7568 // loop, this will cause it to restart with a new
7569 // layout.
7570 mLayoutNeeded = true;
7571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 }
7573 }
Romain Guy06882f82009-06-10 13:36:04 -07007574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 if (mAttrs.type != TYPE_APPLICATION_STARTING
7576 && mAppToken != null) {
7577 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007578
Dianne Hackborn248b1882009-09-16 16:46:44 -07007579 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007580 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007581 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007583 // If this initial window is animating, stop it -- we
7584 // will do an animation to reveal it from behind the
7585 // starting window, so there is no need for it to also
7586 // be doing its own stuff.
7587 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007588 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007589 mAnimation = null;
7590 // Make sure we clean up the animation.
7591 mAnimating = true;
7592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 mFinishedStarting.add(mAppToken);
7594 mH.sendEmptyMessage(H.FINISHED_STARTING);
7595 }
7596 mAppToken.updateReportedVisibilityLocked();
7597 }
7598 }
7599 return true;
7600 }
Romain Guy06882f82009-06-10 13:36:04 -07007601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 // This must be called while inside a transaction. Returns true if
7603 // there is more animation to run.
7604 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007605 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007606 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007608 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7609 mHasTransformation = true;
7610 mHasLocalTransformation = true;
7611 if (!mLocalAnimating) {
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, "Starting animation in " + this +
7614 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7615 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7616 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7617 mAnimation.setStartTime(currentTime);
7618 mLocalAnimating = true;
7619 mAnimating = true;
7620 }
7621 mTransformation.clear();
7622 final boolean more = mAnimation.getTransformation(
7623 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007624 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007625 TAG, "Stepped animation in " + this +
7626 ": more=" + more + ", xform=" + mTransformation);
7627 if (more) {
7628 // we're not done!
7629 return true;
7630 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007631 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 TAG, "Finished animation in " + this +
7633 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007634
7635 if (mAnimation != null) {
7636 mAnimation.cancel();
7637 mAnimation = null;
7638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 //WindowManagerService.this.dump();
7640 }
7641 mHasLocalTransformation = false;
7642 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007643 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007644 // When our app token is animating, we kind-of pretend like
7645 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7646 // part of this check means that we will only do this if
7647 // our window is not currently exiting, or it is not
7648 // locally animating itself. The idea being that one that
7649 // is exiting and doing a local animation should be removed
7650 // once that animation is done.
7651 mAnimating = true;
7652 mHasTransformation = true;
7653 mTransformation.clear();
7654 return false;
7655 } else if (mHasTransformation) {
7656 // Little trick to get through the path below to act like
7657 // we have finished an animation.
7658 mAnimating = true;
7659 } else if (isAnimating()) {
7660 mAnimating = true;
7661 }
7662 } else if (mAnimation != null) {
7663 // If the display is frozen, and there is a pending animation,
7664 // clear it and make sure we run the cleanup code.
7665 mAnimating = true;
7666 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007667 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007668 mAnimation = null;
7669 }
Romain Guy06882f82009-06-10 13:36:04 -07007670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007671 if (!mAnimating && !mLocalAnimating) {
7672 return false;
7673 }
7674
Joe Onorato8a9b2202010-02-26 18:56:32 -08007675 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007676 TAG, "Animation done in " + this + ": exiting=" + mExiting
7677 + ", reportedVisible="
7678 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007680 mAnimating = false;
7681 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007682 if (mAnimation != null) {
7683 mAnimation.cancel();
7684 mAnimation = null;
7685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 mAnimLayer = mLayer;
7687 if (mIsImWindow) {
7688 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007689 } else if (mIsWallpaper) {
7690 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007691 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007692 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007693 + " anim layer: " + mAnimLayer);
7694 mHasTransformation = false;
7695 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007696 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7697 if (DEBUG_VISIBILITY) {
7698 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7699 + mPolicyVisibilityAfterAnim);
7700 }
7701 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7702 if (!mPolicyVisibility) {
7703 if (mCurrentFocus == this) {
7704 mFocusMayChange = true;
7705 }
7706 // Window is no longer visible -- make sure if we were waiting
7707 // for it to be displayed before enabling the display, that
7708 // we allow the display to be enabled now.
7709 enableScreenIfNeededLocked();
7710 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007711 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007712 mTransformation.clear();
7713 if (mHasDrawn
7714 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7715 && mAppToken != null
7716 && mAppToken.firstWindowDrawn
7717 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007718 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007719 + mToken + ": first real window done animating");
7720 mFinishedStarting.add(mAppToken);
7721 mH.sendEmptyMessage(H.FINISHED_STARTING);
7722 }
Romain Guy06882f82009-06-10 13:36:04 -07007723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 finishExit();
7725
7726 if (mAppToken != null) {
7727 mAppToken.updateReportedVisibilityLocked();
7728 }
7729
7730 return false;
7731 }
7732
7733 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007734 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007735 TAG, "finishExit in " + this
7736 + ": exiting=" + mExiting
7737 + " remove=" + mRemoveOnExit
7738 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007740 final int N = mChildWindows.size();
7741 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007742 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007743 }
Romain Guy06882f82009-06-10 13:36:04 -07007744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007745 if (!mExiting) {
7746 return;
7747 }
Romain Guy06882f82009-06-10 13:36:04 -07007748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007749 if (isWindowAnimating()) {
7750 return;
7751 }
7752
Joe Onorato8a9b2202010-02-26 18:56:32 -08007753 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007754 TAG, "Exit animation finished in " + this
7755 + ": remove=" + mRemoveOnExit);
7756 if (mSurface != null) {
7757 mDestroySurface.add(this);
7758 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007759 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007760 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 try {
7762 mSurface.hide();
7763 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007764 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 }
7766 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 }
7768 mExiting = false;
7769 if (mRemoveOnExit) {
7770 mPendingRemove.add(this);
7771 mRemoveOnExit = false;
7772 }
7773 }
Romain Guy06882f82009-06-10 13:36:04 -07007774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7776 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7777 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7778 if (dtdx < -.000001f || dtdx > .000001f) return false;
7779 if (dsdy < -.000001f || dsdy > .000001f) return false;
7780 return true;
7781 }
Romain Guy06882f82009-06-10 13:36:04 -07007782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 void computeShownFrameLocked() {
7784 final boolean selfTransformation = mHasLocalTransformation;
7785 Transformation attachedTransformation =
7786 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7787 ? mAttachedWindow.mTransformation : null;
7788 Transformation appTransformation =
7789 (mAppToken != null && mAppToken.hasTransformation)
7790 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007791
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007792 // Wallpapers are animated based on the "real" window they
7793 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007794 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007795 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007796 if (mWallpaperTarget.mHasLocalTransformation &&
7797 mWallpaperTarget.mAnimation != null &&
7798 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007799 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007800 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007801 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007802 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007803 }
7804 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007805 mWallpaperTarget.mAppToken.hasTransformation &&
7806 mWallpaperTarget.mAppToken.animation != null &&
7807 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007808 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007809 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007810 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007811 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007812 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007813 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007814
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007815 final boolean screenAnimation = mScreenRotationAnimation != null
7816 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007817 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007818 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007819 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007820 final Rect frame = mFrame;
7821 final float tmpFloats[] = mTmpFloats;
7822 final Matrix tmpMatrix = mTmpMatrix;
7823
7824 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007825 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007827 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007828 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007829 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007830 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007831 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007832 }
7833 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007834 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007835 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007836 if (screenAnimation) {
7837 tmpMatrix.postConcat(
7838 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7839 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007840
7841 // "convert" it into SurfaceFlinger's format
7842 // (a 2x2 matrix + an offset)
7843 // Here we must not transform the position of the surface
7844 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007845 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007846
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007847 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007848 tmpMatrix.getValues(tmpFloats);
7849 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007850 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7851 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007852 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007853 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7854 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 int w = frame.width();
7856 int h = frame.height();
7857 mShownFrame.set(x, y, x+w, y+h);
7858
7859 // Now set the alpha... but because our current hardware
7860 // can't do alpha transformation on a non-opaque surface,
7861 // turn it off if we are running an animation that is also
7862 // transforming since it is more important to have that
7863 // animation be smooth.
7864 mShownAlpha = mAlpha;
7865 if (!mLimitedAlphaCompositing
7866 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7867 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7868 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007869 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 if (selfTransformation) {
7871 mShownAlpha *= mTransformation.getAlpha();
7872 }
7873 if (attachedTransformation != null) {
7874 mShownAlpha *= attachedTransformation.getAlpha();
7875 }
7876 if (appTransformation != null) {
7877 mShownAlpha *= appTransformation.getAlpha();
7878 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007879 if (screenAnimation) {
7880 mShownAlpha *=
7881 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007883 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007884 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 }
Romain Guy06882f82009-06-10 13:36:04 -07007886
Joe Onorato8a9b2202010-02-26 18:56:32 -08007887 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007888 TAG, "Continuing animation in " + this +
7889 ": " + mShownFrame +
7890 ", alpha=" + mTransformation.getAlpha());
7891 return;
7892 }
Romain Guy06882f82009-06-10 13:36:04 -07007893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007895 if (mXOffset != 0 || mYOffset != 0) {
7896 mShownFrame.offset(mXOffset, mYOffset);
7897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007899 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007900 mDsDx = 1;
7901 mDtDx = 0;
7902 mDsDy = 0;
7903 mDtDy = 1;
7904 }
Romain Guy06882f82009-06-10 13:36:04 -07007905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007906 /**
7907 * Is this window visible? It is not visible if there is no
7908 * surface, or we are in the process of running an exit animation
7909 * that will remove the surface, or its app token has been hidden.
7910 */
7911 public boolean isVisibleLw() {
7912 final AppWindowToken atoken = mAppToken;
7913 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7914 && (atoken == null || !atoken.hiddenRequested)
7915 && !mExiting && !mDestroying;
7916 }
7917
7918 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007919 * Like {@link #isVisibleLw}, but also counts a window that is currently
7920 * "hidden" behind the keyguard as visible. This allows us to apply
7921 * things like window flags that impact the keyguard.
7922 * XXX I am starting to think we need to have ANOTHER visibility flag
7923 * for this "hidden behind keyguard" state rather than overloading
7924 * mPolicyVisibility. Ungh.
7925 */
7926 public boolean isVisibleOrBehindKeyguardLw() {
7927 final AppWindowToken atoken = mAppToken;
7928 return mSurface != null && !mAttachedHidden
7929 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007930 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007931 && !mExiting && !mDestroying;
7932 }
7933
7934 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007935 * Is this window visible, ignoring its app token? It is not visible
7936 * if there is no surface, or we are in the process of running an exit animation
7937 * that will remove the surface.
7938 */
7939 public boolean isWinVisibleLw() {
7940 final AppWindowToken atoken = mAppToken;
7941 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7942 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7943 && !mExiting && !mDestroying;
7944 }
7945
7946 /**
7947 * The same as isVisible(), but follows the current hidden state of
7948 * the associated app token, not the pending requested hidden state.
7949 */
7950 boolean isVisibleNow() {
7951 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007952 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007953 }
7954
7955 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007956 * Can this window possibly be a drag/drop target? The test here is
7957 * a combination of the above "visible now" with the check that the
7958 * Input Manager uses when discarding windows from input consideration.
7959 */
7960 boolean isPotentialDragTarget() {
7961 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7962 }
7963
7964 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007965 * Same as isVisible(), but we also count it as visible between the
7966 * call to IWindowSession.add() and the first relayout().
7967 */
7968 boolean isVisibleOrAdding() {
7969 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007970 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007971 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7972 && mPolicyVisibility && !mAttachedHidden
7973 && (atoken == null || !atoken.hiddenRequested)
7974 && !mExiting && !mDestroying;
7975 }
7976
7977 /**
7978 * Is this window currently on-screen? It is on-screen either if it
7979 * is visible or it is currently running an animation before no longer
7980 * being visible.
7981 */
7982 boolean isOnScreen() {
7983 final AppWindowToken atoken = mAppToken;
7984 if (atoken != null) {
7985 return mSurface != null && mPolicyVisibility && !mDestroying
7986 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007987 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007988 } else {
7989 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007990 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007991 }
7992 }
Romain Guy06882f82009-06-10 13:36:04 -07007993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007994 /**
7995 * Like isOnScreen(), but we don't return true if the window is part
7996 * of a transition that has not yet been started.
7997 */
7998 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007999 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008000 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008001 return false;
8002 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008003 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008004 final boolean animating = atoken != null
8005 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008006 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008007 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8008 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008009 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008010 }
8011
8012 /** Is the window or its container currently animating? */
8013 boolean isAnimating() {
8014 final WindowState attached = mAttachedWindow;
8015 final AppWindowToken atoken = mAppToken;
8016 return mAnimation != null
8017 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008018 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008019 (atoken.animation != null
8020 || atoken.inPendingTransaction));
8021 }
8022
8023 /** Is this window currently animating? */
8024 boolean isWindowAnimating() {
8025 return mAnimation != null;
8026 }
8027
8028 /**
8029 * Like isOnScreen, but returns false if the surface hasn't yet
8030 * been drawn.
8031 */
8032 public boolean isDisplayedLw() {
8033 final AppWindowToken atoken = mAppToken;
8034 return mSurface != null && mPolicyVisibility && !mDestroying
8035 && !mDrawPending && !mCommitDrawPending
8036 && ((!mAttachedHidden &&
8037 (atoken == null || !atoken.hiddenRequested))
8038 || mAnimating);
8039 }
8040
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008041 /**
8042 * Returns true if the window has a surface that it has drawn a
8043 * complete UI in to.
8044 */
8045 public boolean isDrawnLw() {
8046 final AppWindowToken atoken = mAppToken;
8047 return mSurface != null && !mDestroying
8048 && !mDrawPending && !mCommitDrawPending;
8049 }
8050
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008051 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008052 * Return true if the window is opaque and fully drawn. This indicates
8053 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008054 */
8055 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008056 return (mAttrs.format == PixelFormat.OPAQUE
8057 || mAttrs.type == TYPE_WALLPAPER)
8058 && mSurface != null && mAnimation == null
8059 && (mAppToken == null || mAppToken.animation == null)
8060 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008061 }
8062
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008063 /**
8064 * Return whether this window is wanting to have a translation
8065 * animation applied to it for an in-progress move. (Only makes
8066 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
8067 */
8068 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008069 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008070 && (mFrame.top != mLastFrame.top
8071 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008072 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008073 && mPolicy.isScreenOn();
8074 }
8075
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008076 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8077 return
8078 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008079 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8080 // only if it's visible
8081 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008082 // and only if the application fills the compatible screen
8083 mFrame.left <= mCompatibleScreenFrame.left &&
8084 mFrame.top <= mCompatibleScreenFrame.top &&
8085 mFrame.right >= mCompatibleScreenFrame.right &&
8086 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008087 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008088 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008089 }
8090
8091 boolean isFullscreen(int screenWidth, int screenHeight) {
8092 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008093 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 }
8095
8096 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008097 disposeInputChannel();
8098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008100 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008101 mAttachedWindow.mChildWindows.remove(this);
8102 }
8103 destroySurfaceLocked();
8104 mSession.windowRemovedLocked();
8105 try {
8106 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8107 } catch (RuntimeException e) {
8108 // Ignore if it has already been removed (usually because
8109 // we are doing this as part of processing a death note.)
8110 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008111 }
8112
8113 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008114 if (mInputChannel != null) {
8115 mInputManager.unregisterInputChannel(mInputChannel);
8116
8117 mInputChannel.dispose();
8118 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 }
8121
8122 private class DeathRecipient implements IBinder.DeathRecipient {
8123 public void binderDied() {
8124 try {
8125 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008126 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008127 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008128 if (win != null) {
8129 removeWindowLocked(mSession, win);
8130 }
8131 }
8132 } catch (IllegalArgumentException ex) {
8133 // This will happen if the window has already been
8134 // removed.
8135 }
8136 }
8137 }
8138
8139 /** Returns true if this window desires key events. */
8140 public final boolean canReceiveKeys() {
8141 return isVisibleOrAdding()
8142 && (mViewVisibility == View.VISIBLE)
8143 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8144 }
8145
8146 public boolean hasDrawnLw() {
8147 return mHasDrawn;
8148 }
8149
8150 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008151 return showLw(doAnimation, true);
8152 }
8153
8154 boolean showLw(boolean doAnimation, boolean requestAnim) {
8155 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8156 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008157 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008158 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008159 if (doAnimation) {
8160 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8161 + mPolicyVisibility + " mAnimation=" + mAnimation);
8162 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8163 doAnimation = false;
8164 } else if (mPolicyVisibility && mAnimation == null) {
8165 // Check for the case where we are currently visible and
8166 // not animating; we do not want to do animation at such a
8167 // point to become visible when we already are.
8168 doAnimation = false;
8169 }
8170 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008171 mPolicyVisibility = true;
8172 mPolicyVisibilityAfterAnim = true;
8173 if (doAnimation) {
8174 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8175 }
8176 if (requestAnim) {
8177 requestAnimationLocked(0);
8178 }
8179 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008180 }
8181
8182 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008183 return hideLw(doAnimation, true);
8184 }
8185
8186 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008187 if (doAnimation) {
8188 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8189 doAnimation = false;
8190 }
8191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8193 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008194 if (!current) {
8195 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008196 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008197 if (doAnimation) {
8198 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8199 if (mAnimation == null) {
8200 doAnimation = false;
8201 }
8202 }
8203 if (doAnimation) {
8204 mPolicyVisibilityAfterAnim = false;
8205 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008206 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008207 mPolicyVisibilityAfterAnim = false;
8208 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008209 // Window is no longer visible -- make sure if we were waiting
8210 // for it to be displayed before enabling the display, that
8211 // we allow the display to be enabled now.
8212 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008213 if (mCurrentFocus == this) {
8214 mFocusMayChange = true;
8215 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008216 }
8217 if (requestAnim) {
8218 requestAnimationLocked(0);
8219 }
8220 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008221 }
8222
Jeff Brownfbf09772011-01-16 14:06:57 -08008223 public void getTouchableRegion(Region outRegion) {
8224 final Rect frame = mFrame;
8225 switch (mTouchableInsets) {
8226 default:
8227 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8228 outRegion.set(frame);
8229 break;
8230 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8231 final Rect inset = mGivenContentInsets;
8232 outRegion.set(
8233 frame.left + inset.left, frame.top + inset.top,
8234 frame.right - inset.right, frame.bottom - inset.bottom);
8235 break;
8236 }
8237 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8238 final Rect inset = mGivenVisibleInsets;
8239 outRegion.set(
8240 frame.left + inset.left, frame.top + inset.top,
8241 frame.right - inset.right, frame.bottom - inset.bottom);
8242 break;
8243 }
8244 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8245 final Region givenTouchableRegion = mGivenTouchableRegion;
8246 outRegion.set(givenTouchableRegion);
8247 outRegion.translate(frame.left, frame.top);
8248 break;
8249 }
8250 }
8251 }
8252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008253 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008254 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8255 pw.print(" mClient="); pw.println(mClient.asBinder());
8256 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8257 if (mAttachedWindow != null || mLayoutAttached) {
8258 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8259 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8260 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008261 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8262 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8263 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008264 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8265 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008266 }
8267 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8268 pw.print(" mSubLayer="); pw.print(mSubLayer);
8269 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8270 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8271 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8272 pw.print("="); pw.print(mAnimLayer);
8273 pw.print(" mLastLayer="); pw.println(mLastLayer);
8274 if (mSurface != null) {
8275 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008276 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8277 pw.print(" layer="); pw.print(mSurfaceLayer);
8278 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8279 pw.print(" rect=("); pw.print(mSurfaceX);
8280 pw.print(","); pw.print(mSurfaceY);
8281 pw.print(") "); pw.print(mSurfaceW);
8282 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008283 }
8284 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8285 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8286 if (mAppToken != null) {
8287 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8288 }
8289 if (mTargetAppToken != null) {
8290 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8291 }
8292 pw.print(prefix); pw.print("mViewVisibility=0x");
8293 pw.print(Integer.toHexString(mViewVisibility));
8294 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008295 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8296 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008297 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8298 pw.print(prefix); pw.print("mPolicyVisibility=");
8299 pw.print(mPolicyVisibility);
8300 pw.print(" mPolicyVisibilityAfterAnim=");
8301 pw.print(mPolicyVisibilityAfterAnim);
8302 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8303 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008304 if (!mRelayoutCalled) {
8305 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8306 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008307 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008308 pw.print(" h="); pw.print(mRequestedHeight);
8309 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008310 if (mXOffset != 0 || mYOffset != 0) {
8311 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8312 pw.print(" y="); pw.println(mYOffset);
8313 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008314 pw.print(prefix); pw.print("mGivenContentInsets=");
8315 mGivenContentInsets.printShortString(pw);
8316 pw.print(" mGivenVisibleInsets=");
8317 mGivenVisibleInsets.printShortString(pw);
8318 pw.println();
8319 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8320 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8321 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8322 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008323 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008324 pw.print(prefix); pw.print("mShownFrame=");
8325 mShownFrame.printShortString(pw);
8326 pw.print(" last="); mLastShownFrame.printShortString(pw);
8327 pw.println();
8328 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8329 pw.print(" last="); mLastFrame.printShortString(pw);
8330 pw.println();
8331 pw.print(prefix); pw.print("mContainingFrame=");
8332 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008333 pw.print(" mParentFrame=");
8334 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008335 pw.print(" mDisplayFrame=");
8336 mDisplayFrame.printShortString(pw);
8337 pw.println();
8338 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8339 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8340 pw.println();
8341 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8342 pw.print(" last="); mLastContentInsets.printShortString(pw);
8343 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8344 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8345 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008346 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8347 || mAnimation != null) {
8348 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8349 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8350 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8351 pw.print(" mAnimation="); pw.println(mAnimation);
8352 }
8353 if (mHasTransformation || mHasLocalTransformation) {
8354 pw.print(prefix); pw.print("XForm: has=");
8355 pw.print(mHasTransformation);
8356 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8357 pw.print(" "); mTransformation.printShortString(pw);
8358 pw.println();
8359 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008360 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8361 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8362 pw.print(" mAlpha="); pw.print(mAlpha);
8363 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8364 }
8365 if (mHaveMatrix) {
8366 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8367 pw.print(" mDtDx="); pw.print(mDtDx);
8368 pw.print(" mDsDy="); pw.print(mDsDy);
8369 pw.print(" mDtDy="); pw.println(mDtDy);
8370 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008371 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8372 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8373 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8374 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8375 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8376 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8377 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8378 pw.print(" mDestroying="); pw.print(mDestroying);
8379 pw.print(" mRemoved="); pw.println(mRemoved);
8380 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008381 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008382 pw.print(prefix); pw.print("mOrientationChanging=");
8383 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008384 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8385 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008386 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008387 if (mHScale != 1 || mVScale != 1) {
8388 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8389 pw.print(" mVScale="); pw.println(mVScale);
8390 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008391 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008392 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8393 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8394 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008395 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8396 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8397 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008400
8401 String makeInputChannelName() {
8402 return Integer.toHexString(System.identityHashCode(this))
8403 + " " + mAttrs.getTitle();
8404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008405
8406 @Override
8407 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008408 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8409 || mWasPaused != mToken.paused) {
8410 mLastTitle = mAttrs.getTitle();
8411 mWasPaused = mToken.paused;
8412 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8413 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8414 }
8415 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008416 }
8417 }
Romain Guy06882f82009-06-10 13:36:04 -07008418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008419 // -------------------------------------------------------------
8420 // Window Token State
8421 // -------------------------------------------------------------
8422
8423 class WindowToken {
8424 // The actual token.
8425 final IBinder token;
8426
8427 // The type of window this token is for, as per WindowManager.LayoutParams.
8428 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008430 // Set if this token was explicitly added by a client, so should
8431 // not be removed when all windows are removed.
8432 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008433
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008434 // For printing.
8435 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 // If this is an AppWindowToken, this is non-null.
8438 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 // All of the windows associated with this token.
8441 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8442
8443 // Is key dispatching paused for this token?
8444 boolean paused = false;
8445
8446 // Should this token's windows be hidden?
8447 boolean hidden;
8448
8449 // Temporary for finding which tokens no longer have visible windows.
8450 boolean hasVisible;
8451
Dianne Hackborna8f60182009-09-01 19:01:50 -07008452 // Set to true when this token is in a pending transaction where it
8453 // will be shown.
8454 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008455
Dianne Hackborna8f60182009-09-01 19:01:50 -07008456 // Set to true when this token is in a pending transaction where it
8457 // will be hidden.
8458 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008459
Dianne Hackborna8f60182009-09-01 19:01:50 -07008460 // Set to true when this token is in a pending transaction where its
8461 // windows will be put to the bottom of the list.
8462 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008463
Dianne Hackborna8f60182009-09-01 19:01:50 -07008464 // Set to true when this token is in a pending transaction where its
8465 // windows will be put to the top of the list.
8466 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008468 WindowToken(IBinder _token, int type, boolean _explicit) {
8469 token = _token;
8470 windowType = type;
8471 explicit = _explicit;
8472 }
8473
8474 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008475 pw.print(prefix); pw.print("token="); pw.println(token);
8476 pw.print(prefix); pw.print("windows="); pw.println(windows);
8477 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8478 pw.print(" hidden="); pw.print(hidden);
8479 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008480 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8481 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8482 pw.print(" waitingToHide="); pw.print(waitingToHide);
8483 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8484 pw.print(" sendingToTop="); pw.println(sendingToTop);
8485 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 }
8487
8488 @Override
8489 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008490 if (stringName == null) {
8491 StringBuilder sb = new StringBuilder();
8492 sb.append("WindowToken{");
8493 sb.append(Integer.toHexString(System.identityHashCode(this)));
8494 sb.append(" token="); sb.append(token); sb.append('}');
8495 stringName = sb.toString();
8496 }
8497 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 }
8499 };
8500
8501 class AppWindowToken extends WindowToken {
8502 // Non-null only for application tokens.
8503 final IApplicationToken appToken;
8504
8505 // All of the windows and child windows that are included in this
8506 // application token. Note this list is NOT sorted!
8507 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8508
8509 int groupId = -1;
8510 boolean appFullscreen;
8511 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008512
8513 // The input dispatching timeout for this application token in nanoseconds.
8514 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 // These are used for determining when all windows associated with
8517 // an activity have been drawn, so they can be made visible together
8518 // at the same time.
8519 int lastTransactionSequence = mTransactionSequence-1;
8520 int numInterestingWindows;
8521 int numDrawnWindows;
8522 boolean inPendingTransaction;
8523 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008525 // Is this token going to be hidden in a little while? If so, it
8526 // won't be taken into account for setting the screen orientation.
8527 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 // Is this window's surface needed? This is almost like hidden, except
8530 // it will sometimes be true a little earlier: when the token has
8531 // been shown, but is still waiting for its app transition to execute
8532 // before making its windows shown.
8533 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 // Have we told the window clients to hide themselves?
8536 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 // Last visibility state we reported to the app token.
8539 boolean reportedVisible;
8540
8541 // Set to true when the token has been removed from the window mgr.
8542 boolean removed;
8543
8544 // Have we been asked to have this token keep the screen frozen?
8545 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 boolean animating;
8548 Animation animation;
8549 boolean hasTransformation;
8550 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 // Offset to the window of all layers in the token, for use by
8553 // AppWindowToken animations.
8554 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 // Information about an application starting window if displayed.
8557 StartingData startingData;
8558 WindowState startingWindow;
8559 View startingView;
8560 boolean startingDisplayed;
8561 boolean startingMoved;
8562 boolean firstWindowDrawn;
8563
Jeff Brown928e0542011-01-10 11:17:36 -08008564 // Input application handle used by the input dispatcher.
8565 InputApplicationHandle mInputApplicationHandle;
8566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008567 AppWindowToken(IApplicationToken _token) {
8568 super(_token.asBinder(),
8569 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8570 appWindowToken = this;
8571 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008572 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573 }
Romain Guy06882f82009-06-10 13:36:04 -07008574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008575 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008576 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008577 TAG, "Setting animation in " + this + ": " + anim);
8578 animation = anim;
8579 animating = false;
8580 anim.restrictDuration(MAX_ANIMATION_DURATION);
8581 anim.scaleCurrentDuration(mTransitionAnimationScale);
8582 int zorder = anim.getZAdjustment();
8583 int adj = 0;
8584 if (zorder == Animation.ZORDER_TOP) {
8585 adj = TYPE_LAYER_OFFSET;
8586 } else if (zorder == Animation.ZORDER_BOTTOM) {
8587 adj = -TYPE_LAYER_OFFSET;
8588 }
Romain Guy06882f82009-06-10 13:36:04 -07008589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 if (animLayerAdjustment != adj) {
8591 animLayerAdjustment = adj;
8592 updateLayers();
8593 }
8594 }
Romain Guy06882f82009-06-10 13:36:04 -07008595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 public void setDummyAnimation() {
8597 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008598 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 TAG, "Setting dummy animation in " + this);
8600 animation = sDummyAnimation;
8601 }
8602 }
8603
8604 public void clearAnimation() {
8605 if (animation != null) {
8606 animation = null;
8607 animating = true;
8608 }
8609 }
Romain Guy06882f82009-06-10 13:36:04 -07008610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 void updateLayers() {
8612 final int N = allAppWindows.size();
8613 final int adj = animLayerAdjustment;
8614 for (int i=0; i<N; i++) {
8615 WindowState w = allAppWindows.get(i);
8616 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008617 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 + w.mAnimLayer);
Dianne Hackborne75d8722011-01-27 19:37:40 -08008619 if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 setInputMethodAnimLayerAdjustment(adj);
8621 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008622 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008623 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008625 }
8626 }
Romain Guy06882f82009-06-10 13:36:04 -07008627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 void sendAppVisibilityToClients() {
8629 final int N = allAppWindows.size();
8630 for (int i=0; i<N; i++) {
8631 WindowState win = allAppWindows.get(i);
8632 if (win == startingWindow && clientHidden) {
8633 // Don't hide the starting window.
8634 continue;
8635 }
8636 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008637 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 "Setting visibility of " + win + ": " + (!clientHidden));
8639 win.mClient.dispatchAppVisibility(!clientHidden);
8640 } catch (RemoteException e) {
8641 }
8642 }
8643 }
Romain Guy06882f82009-06-10 13:36:04 -07008644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008645 void showAllWindowsLocked() {
8646 final int NW = allAppWindows.size();
8647 for (int i=0; i<NW; i++) {
8648 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008649 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008650 "performing show on: " + w);
8651 w.performShowLocked();
8652 }
8653 }
Romain Guy06882f82009-06-10 13:36:04 -07008654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 // This must be called while inside a transaction.
8656 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008657 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008658 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008660 if (animation == sDummyAnimation) {
8661 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008662 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008663 // when it is really time to animate, this will be set to
8664 // a real animation and the next call will execute normally.
8665 return false;
8666 }
Romain Guy06882f82009-06-10 13:36:04 -07008667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8669 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008670 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671 TAG, "Starting animation in " + this +
8672 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8673 + " scale=" + mTransitionAnimationScale
8674 + " allDrawn=" + allDrawn + " animating=" + animating);
8675 animation.initialize(dw, dh, dw, dh);
8676 animation.setStartTime(currentTime);
8677 animating = true;
8678 }
8679 transformation.clear();
8680 final boolean more = animation.getTransformation(
8681 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008682 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 TAG, "Stepped animation in " + this +
8684 ": more=" + more + ", xform=" + transformation);
8685 if (more) {
8686 // we're done!
8687 hasTransformation = true;
8688 return true;
8689 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008690 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008691 TAG, "Finished animation in " + this +
8692 " @ " + currentTime);
8693 animation = null;
8694 }
8695 } else if (animation != null) {
8696 // If the display is frozen, and there is a pending animation,
8697 // clear it and make sure we run the cleanup code.
8698 animating = true;
8699 animation = null;
8700 }
8701
8702 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 if (!animating) {
8705 return false;
8706 }
8707
8708 clearAnimation();
8709 animating = false;
Dianne Hackborne75d8722011-01-27 19:37:40 -08008710 if (animLayerAdjustment != 0) {
8711 animLayerAdjustment = 0;
8712 updateLayers();
8713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008714 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8715 moveInputMethodWindowsIfNeededLocked(true);
8716 }
Romain Guy06882f82009-06-10 13:36:04 -07008717
Joe Onorato8a9b2202010-02-26 18:56:32 -08008718 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 TAG, "Animation done in " + this
8720 + ": reportedVisible=" + reportedVisible);
8721
8722 transformation.clear();
Romain Guy06882f82009-06-10 13:36:04 -07008723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 final int N = windows.size();
8725 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008726 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008727 }
8728 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008730 return false;
8731 }
8732
8733 void updateReportedVisibilityLocked() {
8734 if (appToken == null) {
8735 return;
8736 }
Romain Guy06882f82009-06-10 13:36:04 -07008737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008738 int numInteresting = 0;
8739 int numVisible = 0;
8740 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008741
Joe Onorato8a9b2202010-02-26 18:56:32 -08008742 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008743 final int N = allAppWindows.size();
8744 for (int i=0; i<N; i++) {
8745 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008746 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008747 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008748 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8749 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008750 continue;
8751 }
8752 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008753 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008754 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008755 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008756 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008757 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008758 + " pv=" + win.mPolicyVisibility
8759 + " dp=" + win.mDrawPending
8760 + " cdp=" + win.mCommitDrawPending
8761 + " ah=" + win.mAttachedHidden
8762 + " th="
8763 + (win.mAppToken != null
8764 ? win.mAppToken.hiddenRequested : false)
8765 + " a=" + win.mAnimating);
8766 }
8767 }
8768 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008769 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008770 if (!win.isAnimating()) {
8771 numVisible++;
8772 }
8773 nowGone = false;
8774 } else if (win.isAnimating()) {
8775 nowGone = false;
8776 }
8777 }
Romain Guy06882f82009-06-10 13:36:04 -07008778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008779 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008780 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008781 + numInteresting + " visible=" + numVisible);
8782 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008783 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008784 TAG, "Visibility changed in " + this
8785 + ": vis=" + nowVisible);
8786 reportedVisible = nowVisible;
8787 Message m = mH.obtainMessage(
8788 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8789 nowVisible ? 1 : 0,
8790 nowGone ? 1 : 0,
8791 this);
8792 mH.sendMessage(m);
8793 }
8794 }
Romain Guy06882f82009-06-10 13:36:04 -07008795
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008796 WindowState findMainWindow() {
8797 int j = windows.size();
8798 while (j > 0) {
8799 j--;
8800 WindowState win = windows.get(j);
8801 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8802 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8803 return win;
8804 }
8805 }
8806 return null;
8807 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008809 void dump(PrintWriter pw, String prefix) {
8810 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008811 if (appToken != null) {
8812 pw.print(prefix); pw.println("app=true");
8813 }
8814 if (allAppWindows.size() > 0) {
8815 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8816 }
8817 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008818 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008819 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8820 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8821 pw.print(" clientHidden="); pw.print(clientHidden);
8822 pw.print(" willBeHidden="); pw.print(willBeHidden);
8823 pw.print(" reportedVisible="); pw.println(reportedVisible);
8824 if (paused || freezingScreen) {
8825 pw.print(prefix); pw.print("paused="); pw.print(paused);
8826 pw.print(" freezingScreen="); pw.println(freezingScreen);
8827 }
8828 if (numInterestingWindows != 0 || numDrawnWindows != 0
8829 || inPendingTransaction || allDrawn) {
8830 pw.print(prefix); pw.print("numInterestingWindows=");
8831 pw.print(numInterestingWindows);
8832 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8833 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8834 pw.print(" allDrawn="); pw.println(allDrawn);
8835 }
8836 if (animating || animation != null) {
8837 pw.print(prefix); pw.print("animating="); pw.print(animating);
8838 pw.print(" animation="); pw.println(animation);
8839 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008840 if (hasTransformation) {
8841 pw.print(prefix); pw.print("XForm: ");
8842 transformation.printShortString(pw);
8843 pw.println();
8844 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008845 if (animLayerAdjustment != 0) {
8846 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8847 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008848 if (startingData != null || removed || firstWindowDrawn) {
8849 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8850 pw.print(" removed="); pw.print(removed);
8851 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8852 }
8853 if (startingWindow != null || startingView != null
8854 || startingDisplayed || startingMoved) {
8855 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8856 pw.print(" startingView="); pw.print(startingView);
8857 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8858 pw.print(" startingMoved"); pw.println(startingMoved);
8859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008860 }
8861
8862 @Override
8863 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008864 if (stringName == null) {
8865 StringBuilder sb = new StringBuilder();
8866 sb.append("AppWindowToken{");
8867 sb.append(Integer.toHexString(System.identityHashCode(this)));
8868 sb.append(" token="); sb.append(token); sb.append('}');
8869 stringName = sb.toString();
8870 }
8871 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008872 }
8873 }
Romain Guy06882f82009-06-10 13:36:04 -07008874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 // -------------------------------------------------------------
8876 // DummyAnimation
8877 // -------------------------------------------------------------
8878
8879 // This is an animation that does nothing: it just immediately finishes
8880 // itself every time it is called. It is used as a stub animation in cases
8881 // where we want to synchronize multiple things that may be animating.
8882 static final class DummyAnimation extends Animation {
8883 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8884 return false;
8885 }
8886 }
8887 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008889 // -------------------------------------------------------------
8890 // Async Handler
8891 // -------------------------------------------------------------
8892
8893 static final class StartingData {
8894 final String pkg;
8895 final int theme;
8896 final CharSequence nonLocalizedLabel;
8897 final int labelRes;
8898 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008899 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008902 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008903 pkg = _pkg;
8904 theme = _theme;
8905 nonLocalizedLabel = _nonLocalizedLabel;
8906 labelRes = _labelRes;
8907 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008908 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008909 }
8910 }
8911
8912 private final class H extends Handler {
8913 public static final int REPORT_FOCUS_CHANGE = 2;
8914 public static final int REPORT_LOSING_FOCUS = 3;
8915 public static final int ANIMATE = 4;
8916 public static final int ADD_STARTING = 5;
8917 public static final int REMOVE_STARTING = 6;
8918 public static final int FINISHED_STARTING = 7;
8919 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008920 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8921 public static final int HOLD_SCREEN_CHANGED = 12;
8922 public static final int APP_TRANSITION_TIMEOUT = 13;
8923 public static final int PERSIST_ANIMATION_SCALE = 14;
8924 public static final int FORCE_GC = 15;
8925 public static final int ENABLE_SCREEN = 16;
8926 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008927 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008928 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008929 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008930 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08008931 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07008932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008933 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008935 public H() {
8936 }
Romain Guy06882f82009-06-10 13:36:04 -07008937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008938 @Override
8939 public void handleMessage(Message msg) {
8940 switch (msg.what) {
8941 case REPORT_FOCUS_CHANGE: {
8942 WindowState lastFocus;
8943 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008945 synchronized(mWindowMap) {
8946 lastFocus = mLastFocus;
8947 newFocus = mCurrentFocus;
8948 if (lastFocus == newFocus) {
8949 // Focus is not changing, so nothing to do.
8950 return;
8951 }
8952 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 // + " to " + newFocus);
8955 if (newFocus != null && lastFocus != null
8956 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008957 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008958 mLosingFocus.add(lastFocus);
8959 lastFocus = null;
8960 }
8961 }
8962
8963 if (lastFocus != newFocus) {
8964 //System.out.println("Changing focus from " + lastFocus
8965 // + " to " + newFocus);
8966 if (newFocus != null) {
8967 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008968 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008969 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8970 } catch (RemoteException e) {
8971 // Ignore if process has died.
8972 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008973 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008974 }
8975
8976 if (lastFocus != null) {
8977 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008978 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008979 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8980 } catch (RemoteException e) {
8981 // Ignore if process has died.
8982 }
8983 }
Joe Onorato664644d2011-01-23 17:53:23 -08008984
8985 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008986 }
8987 } break;
8988
8989 case REPORT_LOSING_FOCUS: {
8990 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008992 synchronized(mWindowMap) {
8993 losers = mLosingFocus;
8994 mLosingFocus = new ArrayList<WindowState>();
8995 }
8996
8997 final int N = losers.size();
8998 for (int i=0; i<N; i++) {
8999 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009000 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
9002 } catch (RemoteException e) {
9003 // Ignore if process has died.
9004 }
9005 }
9006 } break;
9007
9008 case ANIMATE: {
9009 synchronized(mWindowMap) {
9010 mAnimationPending = false;
9011 performLayoutAndPlaceSurfacesLocked();
9012 }
9013 } break;
9014
9015 case ADD_STARTING: {
9016 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9017 final StartingData sd = wtoken.startingData;
9018
9019 if (sd == null) {
9020 // Animation has been canceled... do nothing.
9021 return;
9022 }
Romain Guy06882f82009-06-10 13:36:04 -07009023
Joe Onorato8a9b2202010-02-26 18:56:32 -08009024 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009025 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07009026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009027 View view = null;
9028 try {
9029 view = mPolicy.addStartingWindow(
9030 wtoken.token, sd.pkg,
9031 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08009032 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009033 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009034 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 }
9036
9037 if (view != null) {
9038 boolean abort = false;
9039
9040 synchronized(mWindowMap) {
9041 if (wtoken.removed || wtoken.startingData == null) {
9042 // If the window was successfully added, then
9043 // we need to remove it.
9044 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009045 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009046 "Aborted starting " + wtoken
9047 + ": removed=" + wtoken.removed
9048 + " startingData=" + wtoken.startingData);
9049 wtoken.startingWindow = null;
9050 wtoken.startingData = null;
9051 abort = true;
9052 }
9053 } else {
9054 wtoken.startingView = view;
9055 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009056 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009057 "Added starting " + wtoken
9058 + ": startingWindow="
9059 + wtoken.startingWindow + " startingView="
9060 + wtoken.startingView);
9061 }
9062
9063 if (abort) {
9064 try {
9065 mPolicy.removeStartingWindow(wtoken.token, view);
9066 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009067 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009068 }
9069 }
9070 }
9071 } break;
9072
9073 case REMOVE_STARTING: {
9074 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9075 IBinder token = null;
9076 View view = null;
9077 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009078 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009079 + wtoken + ": startingWindow="
9080 + wtoken.startingWindow + " startingView="
9081 + wtoken.startingView);
9082 if (wtoken.startingWindow != null) {
9083 view = wtoken.startingView;
9084 token = wtoken.token;
9085 wtoken.startingData = null;
9086 wtoken.startingView = null;
9087 wtoken.startingWindow = null;
9088 }
9089 }
9090 if (view != null) {
9091 try {
9092 mPolicy.removeStartingWindow(token, view);
9093 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009094 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009095 }
9096 }
9097 } break;
9098
9099 case FINISHED_STARTING: {
9100 IBinder token = null;
9101 View view = null;
9102 while (true) {
9103 synchronized (mWindowMap) {
9104 final int N = mFinishedStarting.size();
9105 if (N <= 0) {
9106 break;
9107 }
9108 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9109
Joe Onorato8a9b2202010-02-26 18:56:32 -08009110 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009111 "Finished starting " + wtoken
9112 + ": startingWindow=" + wtoken.startingWindow
9113 + " startingView=" + wtoken.startingView);
9114
9115 if (wtoken.startingWindow == null) {
9116 continue;
9117 }
9118
9119 view = wtoken.startingView;
9120 token = wtoken.token;
9121 wtoken.startingData = null;
9122 wtoken.startingView = null;
9123 wtoken.startingWindow = null;
9124 }
9125
9126 try {
9127 mPolicy.removeStartingWindow(token, view);
9128 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009129 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009130 }
9131 }
9132 } break;
9133
9134 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9135 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9136
9137 boolean nowVisible = msg.arg1 != 0;
9138 boolean nowGone = msg.arg2 != 0;
9139
9140 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009141 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009142 TAG, "Reporting visible in " + wtoken
9143 + " visible=" + nowVisible
9144 + " gone=" + nowGone);
9145 if (nowVisible) {
9146 wtoken.appToken.windowsVisible();
9147 } else {
9148 wtoken.appToken.windowsGone();
9149 }
9150 } catch (RemoteException ex) {
9151 }
9152 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009154 case WINDOW_FREEZE_TIMEOUT: {
9155 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009156 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009157 int i = mWindows.size();
9158 while (i > 0) {
9159 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009160 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009161 if (w.mOrientationChanging) {
9162 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009163 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009164 }
9165 }
9166 performLayoutAndPlaceSurfacesLocked();
9167 }
9168 break;
9169 }
Romain Guy06882f82009-06-10 13:36:04 -07009170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 case HOLD_SCREEN_CHANGED: {
9172 Session oldHold;
9173 Session newHold;
9174 synchronized (mWindowMap) {
9175 oldHold = mLastReportedHold;
9176 newHold = (Session)msg.obj;
9177 mLastReportedHold = newHold;
9178 }
Romain Guy06882f82009-06-10 13:36:04 -07009179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009180 if (oldHold != newHold) {
9181 try {
9182 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009183 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 "window",
9185 BatteryStats.WAKE_TYPE_WINDOW);
9186 }
9187 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009188 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009189 "window",
9190 BatteryStats.WAKE_TYPE_WINDOW);
9191 }
9192 } catch (RemoteException e) {
9193 }
9194 }
9195 break;
9196 }
Romain Guy06882f82009-06-10 13:36:04 -07009197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009198 case APP_TRANSITION_TIMEOUT: {
9199 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009200 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009201 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009202 "*** APP TRANSITION TIMEOUT");
9203 mAppTransitionReady = true;
9204 mAppTransitionTimeout = true;
9205 performLayoutAndPlaceSurfacesLocked();
9206 }
9207 }
9208 break;
9209 }
Romain Guy06882f82009-06-10 13:36:04 -07009210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 case PERSIST_ANIMATION_SCALE: {
9212 Settings.System.putFloat(mContext.getContentResolver(),
9213 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9214 Settings.System.putFloat(mContext.getContentResolver(),
9215 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9216 break;
9217 }
Romain Guy06882f82009-06-10 13:36:04 -07009218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 case FORCE_GC: {
9220 synchronized(mWindowMap) {
9221 if (mAnimationPending) {
9222 // If we are animating, don't do the gc now but
9223 // delay a bit so we don't interrupt the animation.
9224 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9225 2000);
9226 return;
9227 }
9228 // If we are currently rotating the display, it will
9229 // schedule a new message when done.
9230 if (mDisplayFrozen) {
9231 return;
9232 }
9233 mFreezeGcPending = 0;
9234 }
9235 Runtime.getRuntime().gc();
9236 break;
9237 }
Romain Guy06882f82009-06-10 13:36:04 -07009238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009239 case ENABLE_SCREEN: {
9240 performEnableScreen();
9241 break;
9242 }
Romain Guy06882f82009-06-10 13:36:04 -07009243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244 case APP_FREEZE_TIMEOUT: {
9245 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009246 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 int i = mAppTokens.size();
9248 while (i > 0) {
9249 i--;
9250 AppWindowToken tok = mAppTokens.get(i);
9251 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009252 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 unsetAppFreezingScreenLocked(tok, true, true);
9254 }
9255 }
9256 }
9257 break;
9258 }
Romain Guy06882f82009-06-10 13:36:04 -07009259
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009260 case SEND_NEW_CONFIGURATION: {
9261 removeMessages(SEND_NEW_CONFIGURATION);
9262 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009263 break;
9264 }
Romain Guy06882f82009-06-10 13:36:04 -07009265
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009266 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009267 if (mWindowsChanged) {
9268 synchronized (mWindowMap) {
9269 mWindowsChanged = false;
9270 }
9271 notifyWindowsChanged();
9272 }
9273 break;
9274 }
9275
Christopher Tatea53146c2010-09-07 11:57:52 -07009276 case DRAG_START_TIMEOUT: {
9277 IBinder win = (IBinder)msg.obj;
9278 if (DEBUG_DRAG) {
9279 Slog.w(TAG, "Timeout starting drag by win " + win);
9280 }
9281 synchronized (mWindowMap) {
9282 // !!! TODO: ANR the app that has failed to start the drag in time
9283 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009284 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009285 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009286 mDragState.reset();
9287 mDragState = null;
9288 }
9289 }
Chris Tated4533f142010-10-19 15:15:08 -07009290 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009291 }
9292
Chris Tated4533f142010-10-19 15:15:08 -07009293 case DRAG_END_TIMEOUT: {
9294 IBinder win = (IBinder)msg.obj;
9295 if (DEBUG_DRAG) {
9296 Slog.w(TAG, "Timeout ending drag to win " + win);
9297 }
9298 synchronized (mWindowMap) {
9299 // !!! TODO: ANR the drag-receiving app
9300 mDragState.mDragResult = false;
9301 mDragState.endDragLw();
9302 }
9303 break;
9304 }
Jeff Brown2992ea72011-01-28 22:04:14 -08009305
9306 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
9307 notifyHardKeyboardStatusChange();
9308 break;
9309 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009310 }
9311 }
9312 }
9313
9314 // -------------------------------------------------------------
9315 // IWindowManager API
9316 // -------------------------------------------------------------
9317
9318 public IWindowSession openSession(IInputMethodClient client,
9319 IInputContext inputContext) {
9320 if (client == null) throw new IllegalArgumentException("null client");
9321 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009322 Session session = new Session(client, inputContext);
9323 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009324 }
9325
9326 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9327 synchronized (mWindowMap) {
9328 // The focus for the client is the window immediately below
9329 // where we would place the input method window.
9330 int idx = findDesiredInputMethodWindowIndexLocked(false);
9331 WindowState imFocus;
9332 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009333 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08009334 //Log.i(TAG, "Desired input method target: " + imFocus);
9335 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
9336 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009337 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08009338 // This may be a starting window, in which case we still want
9339 // to count it as okay.
9340 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
9341 && imFocus.mAppToken != null) {
9342 // The client has definitely started, so it really should
9343 // have a window in this app token. Let's look for it.
9344 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
9345 WindowState w = imFocus.mAppToken.windows.get(i);
9346 if (w != imFocus) {
9347 //Log.i(TAG, "Switching to real app window: " + w);
9348 imFocus = w;
9349 break;
9350 }
9351 }
9352 }
9353 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
9354 //if (imFocus.mSession.mClient != null) {
9355 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
9356 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
9357 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009358 if (imFocus.mSession.mClient != null &&
9359 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9360 return true;
9361 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08009362
9363 // Okay, how about this... what is the current focus?
9364 // It seems in some cases we may not have moved the IM
9365 // target window, such as when it was in a pop-up window,
9366 // so let's also look at the current focus. (An example:
9367 // go to Gmail, start searching so the keyboard goes up,
9368 // press home. Sometimes the IME won't go down.)
9369 // Would be nice to fix this more correctly, but it's
9370 // way at the end of a release, and this should be good enough.
9371 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
9372 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
9373 return true;
9374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009375 }
9376 }
9377 }
9378 return false;
9379 }
Romain Guy06882f82009-06-10 13:36:04 -07009380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009381 // -------------------------------------------------------------
9382 // Internals
9383 // -------------------------------------------------------------
9384
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009385 final WindowState windowForClientLocked(Session session, IWindow client,
9386 boolean throwOnError) {
9387 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009388 }
Romain Guy06882f82009-06-10 13:36:04 -07009389
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009390 final WindowState windowForClientLocked(Session session, IBinder client,
9391 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009392 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009393 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009394 TAG, "Looking up client " + client + ": " + win);
9395 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009396 RuntimeException ex = new IllegalArgumentException(
9397 "Requested window " + client + " does not exist");
9398 if (throwOnError) {
9399 throw ex;
9400 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009401 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009402 return null;
9403 }
9404 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009405 RuntimeException ex = new IllegalArgumentException(
9406 "Requested window " + client + " is in session " +
9407 win.mSession + ", not " + session);
9408 if (throwOnError) {
9409 throw ex;
9410 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009411 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009412 return null;
9413 }
9414
9415 return win;
9416 }
9417
Dianne Hackborna8f60182009-09-01 19:01:50 -07009418 final void rebuildAppWindowListLocked() {
9419 int NW = mWindows.size();
9420 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009421 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009422 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009423
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009424 if (mRebuildTmp.length < NW) {
9425 mRebuildTmp = new WindowState[NW+10];
9426 }
9427
Dianne Hackborna8f60182009-09-01 19:01:50 -07009428 // First remove all existing app windows.
9429 i=0;
9430 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009431 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009432 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009433 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009434 win.mRebuilding = true;
9435 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009436 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009437 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009438 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009439 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009440 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009441 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009442 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9443 && lastWallpaper == i-1) {
9444 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009445 }
9446 i++;
9447 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009448
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009449 // The wallpaper window(s) typically live at the bottom of the stack,
9450 // so skip them before adding app tokens.
9451 lastWallpaper++;
9452 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009453
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009454 // First add all of the exiting app tokens... these are no longer
9455 // in the main app list, but still have windows shown. We put them
9456 // in the back because now that the animation is over we no longer
9457 // will care about them.
9458 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009459 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009460 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9461 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009462
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009463 // And add in the still active app tokens in Z order.
9464 NT = mAppTokens.size();
9465 for (int j=0; j<NT; j++) {
9466 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009468
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009469 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009470 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009471 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009472 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009473 for (i=0; i<numRemoved; i++) {
9474 WindowState ws = mRebuildTmp[i];
9475 if (ws.mRebuilding) {
9476 StringWriter sw = new StringWriter();
9477 PrintWriter pw = new PrintWriter(sw);
9478 ws.dump(pw, "");
9479 pw.flush();
9480 Slog.w(TAG, "This window was lost: " + ws);
9481 Slog.w(TAG, sw.toString());
9482 }
9483 }
9484 Slog.w(TAG, "Current app token list:");
9485 dumpAppTokensLocked();
9486 Slog.w(TAG, "Final window list:");
9487 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009488 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009489 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 private final void assignLayersLocked() {
9492 int N = mWindows.size();
9493 int curBaseLayer = 0;
9494 int curLayer = 0;
9495 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009496
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009497 if (DEBUG_LAYERS) {
9498 RuntimeException here = new RuntimeException("here");
9499 here.fillInStackTrace();
9500 Log.v(TAG, "Assigning layers", here);
9501 }
9502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009504 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009505 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9506 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009507 curLayer += WINDOW_LAYER_MULTIPLIER;
9508 w.mLayer = curLayer;
9509 } else {
9510 curBaseLayer = curLayer = w.mBaseLayer;
9511 w.mLayer = curLayer;
9512 }
9513 if (w.mTargetAppToken != null) {
9514 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9515 } else if (w.mAppToken != null) {
9516 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9517 } else {
9518 w.mAnimLayer = w.mLayer;
9519 }
9520 if (w.mIsImWindow) {
9521 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009522 } else if (w.mIsWallpaper) {
9523 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009524 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009525 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009526 + w.mAnimLayer);
9527 //System.out.println(
9528 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9529 }
9530 }
9531
9532 private boolean mInLayout = false;
9533 private final void performLayoutAndPlaceSurfacesLocked() {
9534 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009535 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009536 throw new RuntimeException("Recursive call!");
9537 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009538 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 return;
9540 }
9541
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009542 if (mWaitingForConfig) {
9543 // Our configuration has changed (most likely rotation), but we
9544 // don't yet have the complete configuration to report to
9545 // applications. Don't do any window layout until we have it.
9546 return;
9547 }
9548
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009549 if (mDisplay == null) {
9550 // Not yet initialized, nothing to do.
9551 return;
9552 }
9553
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009554 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009555 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009556
9557 try {
9558 if (mForceRemoves != null) {
9559 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009560 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009561 for (int i=0; i<mForceRemoves.size(); i++) {
9562 WindowState ws = mForceRemoves.get(i);
9563 Slog.i(TAG, "Force removing: " + ws);
9564 removeWindowInnerLocked(ws.mSession, ws);
9565 }
9566 mForceRemoves = null;
9567 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9568 Object tmp = new Object();
9569 synchronized (tmp) {
9570 try {
9571 tmp.wait(250);
9572 } catch (InterruptedException e) {
9573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009574 }
9575 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009576 } catch (RuntimeException e) {
9577 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009578 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009580 try {
9581 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009582
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009583 int N = mPendingRemove.size();
9584 if (N > 0) {
9585 if (mPendingRemoveTmp.length < N) {
9586 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009587 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009588 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009590 for (int i=0; i<N; i++) {
9591 WindowState w = mPendingRemoveTmp[i];
9592 removeWindowInnerLocked(w.mSession, w);
9593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009594
9595 mInLayout = false;
9596 assignLayersLocked();
9597 mLayoutNeeded = true;
9598 performLayoutAndPlaceSurfacesLocked();
9599
9600 } else {
9601 mInLayout = false;
9602 if (mLayoutNeeded) {
9603 requestAnimationLocked(0);
9604 }
9605 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009606 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009607 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9608 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009610 } catch (RuntimeException e) {
9611 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009612 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 }
9614 }
9615
Jeff Brown3a22cd92011-01-21 13:59:04 -08009616 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009617 if (!mLayoutNeeded) {
9618 return 0;
9619 }
9620
9621 mLayoutNeeded = false;
9622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009623 final int dw = mDisplay.getWidth();
9624 final int dh = mDisplay.getHeight();
9625
9626 final int N = mWindows.size();
9627 int i;
9628
Joe Onorato8a9b2202010-02-26 18:56:32 -08009629 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009630 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9631
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009632 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009633
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009634 int seq = mLayoutSeq+1;
9635 if (seq < 0) seq = 0;
9636 mLayoutSeq = seq;
9637
9638 // First perform layout of any root windows (not attached
9639 // to another window).
9640 int topAttached = -1;
9641 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009642 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009643
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009644 // Don't do layout of a window if it is not visible, or
9645 // soon won't be visible, to avoid wasting time and funky
9646 // changes while a window is animating away.
9647 final AppWindowToken atoken = win.mAppToken;
9648 final boolean gone = win.mViewVisibility == View.GONE
9649 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009650 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009651 || (atoken != null && atoken.hiddenRequested)
9652 || win.mAttachedHidden
9653 || win.mExiting || win.mDestroying;
9654
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009655 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9656 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009657 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9658 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009659 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009660 + win.mViewVisibility + " mRelayoutCalled="
9661 + win.mRelayoutCalled + " hidden="
9662 + win.mRootToken.hidden + " hiddenRequested="
9663 + (atoken != null && atoken.hiddenRequested)
9664 + " mAttachedHidden=" + win.mAttachedHidden);
9665 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009666
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009667 // If this view is GONE, then skip it -- keep the current
9668 // frame, and let the caller know so they can ignore it
9669 // if they want. (We do the normal layout for INVISIBLE
9670 // windows, since that means "perform layout as normal,
9671 // just don't display").
9672 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009673 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009674 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009675 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009676 win.mContentChanged = false;
9677 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009678 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9679 win.mLayoutSeq = seq;
9680 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9681 + win.mFrame + " mContainingFrame="
9682 + win.mContainingFrame + " mDisplayFrame="
9683 + win.mDisplayFrame);
9684 } else {
9685 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009686 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009687 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009688 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009689
9690 // Now perform layout of attached windows, which usually
9691 // depend on the position of the window they are attached to.
9692 // XXX does not deal with windows that are attached to windows
9693 // that are themselves attached.
9694 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009695 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009696
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009697 if (win.mLayoutAttached) {
9698 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9699 + " mHaveFrame=" + win.mHaveFrame
9700 + " mViewVisibility=" + win.mViewVisibility
9701 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009702 // If this view is GONE, then skip it -- keep the current
9703 // frame, and let the caller know so they can ignore it
9704 // if they want. (We do the normal layout for INVISIBLE
9705 // windows, since that means "perform layout as normal,
9706 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009707 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9708 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009709 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009710 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009711 win.mContentChanged = false;
9712 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009713 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9714 win.mLayoutSeq = seq;
9715 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9716 + win.mFrame + " mContainingFrame="
9717 + win.mContainingFrame + " mDisplayFrame="
9718 + win.mDisplayFrame);
9719 }
9720 }
9721 }
Jeff Brown349703e2010-06-22 01:27:15 -07009722
9723 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009724 mInputMonitor.setUpdateInputWindowsNeededLw();
9725 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009726 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009727 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009728
9729 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009730 }
Romain Guy06882f82009-06-10 13:36:04 -07009731
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009732 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009733 private final void performLayoutAndPlaceSurfacesLockedInner(
9734 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009735 if (mDisplay == null) {
9736 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9737 return;
9738 }
9739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009740 final long currentTime = SystemClock.uptimeMillis();
9741 final int dw = mDisplay.getWidth();
9742 final int dh = mDisplay.getHeight();
9743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009744 int i;
9745
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009746 if (mFocusMayChange) {
9747 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009748 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9749 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009750 }
9751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009752 // Initialize state of exiting tokens.
9753 for (i=mExitingTokens.size()-1; i>=0; i--) {
9754 mExitingTokens.get(i).hasVisible = false;
9755 }
9756
9757 // Initialize state of exiting applications.
9758 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9759 mExitingAppTokens.get(i).hasVisible = false;
9760 }
9761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009762 boolean orientationChangeComplete = true;
9763 Session holdScreen = null;
9764 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009765 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009766 boolean focusDisplayed = false;
9767 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009768 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009769 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009770
9771 if (mFxSession == null) {
9772 mFxSession = new SurfaceSession();
9773 createWatermark = true;
9774 }
9775
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009776 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009777
9778 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009779
9780 if (createWatermark) {
9781 createWatermark();
9782 }
9783 if (mWatermark != null) {
9784 mWatermark.positionSurface(dw, dh);
9785 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009786 if (mStrictModeFlash != null) {
9787 mStrictModeFlash.positionSurface(dw, dh);
9788 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009790 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009791 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009792 int repeats = 0;
9793 int changes = 0;
9794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009796 repeats++;
9797 if (repeats > 6) {
9798 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9799 mLayoutNeeded = false;
9800 break;
9801 }
9802
9803 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9804 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9805 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9806 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9807 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9808 assignLayersLocked();
9809 mLayoutNeeded = true;
9810 }
9811 }
9812 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9813 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009814 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009815 mLayoutNeeded = true;
9816 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9817 }
9818 }
9819 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9820 mLayoutNeeded = true;
9821 }
9822 }
9823
9824 // FIRST LOOP: Perform a layout, if needed.
9825 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009826 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009827 if (changes != 0) {
9828 continue;
9829 }
9830 } else {
9831 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9832 changes = 0;
9833 }
9834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009835 final int transactionSequence = ++mTransactionSequence;
9836
9837 // Update animations of all applications, including those
9838 // associated with exiting/removed apps
9839 boolean tokensAnimating = false;
9840 final int NAT = mAppTokens.size();
9841 for (i=0; i<NAT; i++) {
9842 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9843 tokensAnimating = true;
9844 }
9845 }
9846 final int NEAT = mExitingAppTokens.size();
9847 for (i=0; i<NEAT; i++) {
9848 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9849 tokensAnimating = true;
9850 }
9851 }
9852
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009853 // SECOND LOOP: Execute animations and update visibility of windows.
9854
Joe Onorato8a9b2202010-02-26 18:56:32 -08009855 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009856 + transactionSequence + " tokensAnimating="
9857 + tokensAnimating);
9858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009860
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009861 if (mScreenRotationAnimation != null) {
9862 if (mScreenRotationAnimation.isAnimating()) {
9863 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9864 animating = true;
9865 } else {
9866 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009867 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009868 }
9869 }
9870 }
9871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009873 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009874 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009875 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009876
9877 mPolicy.beginAnimationLw(dw, dh);
9878
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009879 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009881 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009882 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883
9884 final WindowManager.LayoutParams attrs = w.mAttrs;
9885
9886 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009887 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009888 if (w.commitFinishDrawingLocked(currentTime)) {
9889 if ((w.mAttrs.flags
9890 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009891 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009892 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009893 wallpaperMayChange = true;
9894 }
9895 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009896
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009897 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009898
9899 int animDw = dw;
9900 int animDh = dh;
9901
9902 // If the window has moved due to its containing
9903 // content frame changing, then we'd like to animate
9904 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009905 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009906 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009907 // Frame has moved, containing content frame
9908 // has also moved, and we're not currently animating...
9909 // let's do something.
9910 Animation a = AnimationUtils.loadAnimation(mContext,
9911 com.android.internal.R.anim.window_move_from_decor);
9912 w.setAnimation(a);
9913 animDw = w.mLastFrame.left - w.mFrame.left;
9914 animDh = w.mLastFrame.top - w.mFrame.top;
9915 }
9916
9917 // Execute animation.
9918 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9919 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009920
9921 // If this window is animating, make a note that we have
9922 // an animating window and take care of a request to run
9923 // a detached wallpaper animation.
9924 if (nowAnimating) {
9925 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9926 windowDetachedWallpaper = w;
9927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009928 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009930
9931 // If this window's app token is running a detached wallpaper
9932 // animation, make a note so we can ensure the wallpaper is
9933 // displayed behind it.
9934 if (w.mAppToken != null && w.mAppToken.animation != null
9935 && w.mAppToken.animation.getDetachWallpaper()) {
9936 windowDetachedWallpaper = w;
9937 }
9938
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009939 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9940 wallpaperMayChange = true;
9941 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009942
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009943 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009944 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009945 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009946 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009947 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009948 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009949 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009950 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9951 forceHiding = true;
9952 }
9953 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9954 boolean changed;
9955 if (forceHiding) {
9956 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009957 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9958 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009959 } else {
9960 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009961 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9962 "Now policy shown: " + w);
9963 if (changed) {
9964 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009965 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009966 // Assume we will need to animate. If
9967 // we don't (because the wallpaper will
9968 // stay with the lock screen), then we will
9969 // clean up later.
9970 Animation a = mPolicy.createForceHideEnterAnimation();
9971 if (a != null) {
9972 w.setAnimation(a);
9973 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009974 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009975 if (mCurrentFocus == null ||
9976 mCurrentFocus.mLayer < w.mLayer) {
9977 // We are showing on to of the current
9978 // focus, so re-evaluate focus to make
9979 // sure it is correct.
9980 mFocusMayChange = true;
9981 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009982 }
9983 }
9984 if (changed && (attrs.flags
9985 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9986 wallpaperMayChange = true;
9987 }
9988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009990 mPolicy.animatingWindowLw(w, attrs);
9991 }
9992
9993 final AppWindowToken atoken = w.mAppToken;
9994 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9995 if (atoken.lastTransactionSequence != transactionSequence) {
9996 atoken.lastTransactionSequence = transactionSequence;
9997 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9998 atoken.startingDisplayed = false;
9999 }
10000 if ((w.isOnScreen() || w.mAttrs.type
10001 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
10002 && !w.mExiting && !w.mDestroying) {
10003 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010004 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010005 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010007 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010008 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010009 + " pv=" + w.mPolicyVisibility
10010 + " dp=" + w.mDrawPending
10011 + " cdp=" + w.mCommitDrawPending
10012 + " ah=" + w.mAttachedHidden
10013 + " th=" + atoken.hiddenRequested
10014 + " a=" + w.mAnimating);
10015 }
10016 }
10017 if (w != atoken.startingWindow) {
10018 if (!atoken.freezingScreen || !w.mAppFreezing) {
10019 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010020 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010022 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010023 "tokenMayBeDrawn: " + atoken
10024 + " freezingScreen=" + atoken.freezingScreen
10025 + " mAppFreezing=" + w.mAppFreezing);
10026 tokenMayBeDrawn = true;
10027 }
10028 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010029 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 atoken.startingDisplayed = true;
10031 }
10032 }
10033 } else if (w.mReadyToShow) {
10034 w.performShowLocked();
10035 }
10036 }
10037
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010038 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010039
10040 if (tokenMayBeDrawn) {
10041 // See if any windows have been drawn, so they (and others
10042 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010043 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010044 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010045 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 if (wtoken.freezingScreen) {
10047 int numInteresting = wtoken.numInterestingWindows;
10048 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010049 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 "allDrawn: " + wtoken
10051 + " interesting=" + numInteresting
10052 + " drawn=" + wtoken.numDrawnWindows);
10053 wtoken.showAllWindowsLocked();
10054 unsetAppFreezingScreenLocked(wtoken, false, true);
10055 orientationChangeComplete = true;
10056 }
10057 } else if (!wtoken.allDrawn) {
10058 int numInteresting = wtoken.numInterestingWindows;
10059 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010060 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010061 "allDrawn: " + wtoken
10062 + " interesting=" + numInteresting
10063 + " drawn=" + wtoken.numDrawnWindows);
10064 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010065 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010066
10067 // We can now show all of the drawn windows!
10068 if (!mOpeningApps.contains(wtoken)) {
10069 wtoken.showAllWindowsLocked();
10070 }
10071 }
10072 }
10073 }
10074 }
10075
10076 // If we are ready to perform an app transition, check through
10077 // all of the app tokens to be shown and see if they are ready
10078 // to go.
10079 if (mAppTransitionReady) {
10080 int NN = mOpeningApps.size();
10081 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010082 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010083 "Checking " + NN + " opening apps (frozen="
10084 + mDisplayFrozen + " timeout="
10085 + mAppTransitionTimeout + ")...");
10086 if (!mDisplayFrozen && !mAppTransitionTimeout) {
10087 // If the display isn't frozen, wait to do anything until
10088 // all of the apps are ready. Otherwise just go because
10089 // we'll unfreeze the display when everyone is ready.
10090 for (i=0; i<NN && goodToGo; i++) {
10091 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010092 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010093 "Check opening app" + wtoken + ": allDrawn="
10094 + wtoken.allDrawn + " startingDisplayed="
10095 + wtoken.startingDisplayed);
10096 if (!wtoken.allDrawn && !wtoken.startingDisplayed
10097 && !wtoken.startingMoved) {
10098 goodToGo = false;
10099 }
10100 }
10101 }
10102 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010103 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010104 int transit = mNextAppTransition;
10105 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010106 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010107 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010108 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010109 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010110 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010111 mAppTransitionTimeout = false;
10112 mStartingIconInTransition = false;
10113 mSkipAppTransitionAnimation = false;
10114
10115 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
10116
Dianne Hackborna8f60182009-09-01 19:01:50 -070010117 // If there are applications waiting to come to the
10118 // top of the stack, now is the time to move their windows.
10119 // (Note that we don't do apps going to the bottom
10120 // here -- we want to keep their windows in the old
10121 // Z-order until the animation completes.)
10122 if (mToTopApps.size() > 0) {
10123 NN = mAppTokens.size();
10124 for (i=0; i<NN; i++) {
10125 AppWindowToken wtoken = mAppTokens.get(i);
10126 if (wtoken.sendingToTop) {
10127 wtoken.sendingToTop = false;
10128 moveAppWindowsLocked(wtoken, NN, false);
10129 }
10130 }
10131 mToTopApps.clear();
10132 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010133
Dianne Hackborn25994b42009-09-04 14:21:19 -070010134 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010135
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010136 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010137 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010138
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010139 // The top-most window will supply the layout params,
10140 // and we will determine it below.
10141 LayoutParams animLp = null;
10142 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010143 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010144
Joe Onorato8a9b2202010-02-26 18:56:32 -080010145 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010146 "New wallpaper target=" + mWallpaperTarget
10147 + ", lower target=" + mLowerWallpaperTarget
10148 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010149 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010150 // Do a first pass through the tokens for two
10151 // things:
10152 // (1) Determine if both the closing and opening
10153 // app token sets are wallpaper targets, in which
10154 // case special animations are needed
10155 // (since the wallpaper needs to stay static
10156 // behind them).
10157 // (2) Find the layout params of the top-most
10158 // application window in the tokens, which is
10159 // what will control the animation theme.
10160 final int NC = mClosingApps.size();
10161 NN = NC + mOpeningApps.size();
10162 for (i=0; i<NN; i++) {
10163 AppWindowToken wtoken;
10164 int mode;
10165 if (i < NC) {
10166 wtoken = mClosingApps.get(i);
10167 mode = 1;
10168 } else {
10169 wtoken = mOpeningApps.get(i-NC);
10170 mode = 2;
10171 }
10172 if (mLowerWallpaperTarget != null) {
10173 if (mLowerWallpaperTarget.mAppToken == wtoken
10174 || mUpperWallpaperTarget.mAppToken == wtoken) {
10175 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010176 }
10177 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010178 if (wtoken.appFullscreen) {
10179 WindowState ws = wtoken.findMainWindow();
10180 if (ws != null) {
10181 // If this is a compatibility mode
10182 // window, we will always use its anim.
10183 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10184 animLp = ws.mAttrs;
10185 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010186 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010187 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010188 bestAnimLayer = ws.mLayer;
10189 }
10190 fullscreenAnim = true;
10191 }
10192 } else if (!fullscreenAnim) {
10193 WindowState ws = wtoken.findMainWindow();
10194 if (ws != null) {
10195 if (ws.mLayer > bestAnimLayer) {
10196 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010197 bestAnimLayer = ws.mLayer;
10198 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010199 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010200 }
10201 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010202
Dianne Hackborn25994b42009-09-04 14:21:19 -070010203 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010204 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010205 "Wallpaper animation!");
10206 switch (transit) {
10207 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10208 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10209 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10210 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10211 break;
10212 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10213 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10214 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10215 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10216 break;
10217 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010218 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010219 "New transit: " + transit);
10220 } else if (oldWallpaper != null) {
10221 // We are transitioning from an activity with
10222 // a wallpaper to one without.
10223 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010224 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010225 "New transit away from wallpaper: " + transit);
10226 } else if (mWallpaperTarget != null) {
10227 // We are transitioning from an activity without
10228 // a wallpaper to now showing the wallpaper
10229 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010230 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010231 "New transit into wallpaper: " + transit);
10232 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010233
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010234 // If all closing windows are obscured, then there is
10235 // no need to do an animation. This is the case, for
10236 // example, when this transition is being done behind
10237 // the lock screen.
10238 if (!mPolicy.allowAppAnimationsLw()) {
10239 animLp = null;
10240 }
10241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010242 NN = mOpeningApps.size();
10243 for (i=0; i<NN; i++) {
10244 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010245 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010246 "Now opening app" + wtoken);
10247 wtoken.reportedVisible = false;
10248 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010249 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010250 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010251 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010252 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010253 wtoken.showAllWindowsLocked();
10254 }
10255 NN = mClosingApps.size();
10256 for (i=0; i<NN; i++) {
10257 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010258 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010259 "Now closing app" + wtoken);
10260 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010261 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010262 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010263 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010264 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010265 // Force the allDrawn flag, because we want to start
10266 // this guy's animations regardless of whether it's
10267 // gotten drawn.
10268 wtoken.allDrawn = true;
10269 }
10270
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010271 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010273 mOpeningApps.clear();
10274 mClosingApps.clear();
10275
10276 // This has changed the visibility of windows, so perform
10277 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010278 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10279 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010281 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10282 assignLayersLocked();
10283 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010284 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10285 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010286 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010287 }
10288 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010289
Dianne Hackborn16064f92010-03-25 00:47:24 -070010290 int adjResult = 0;
10291
Dianne Hackborna8f60182009-09-01 19:01:50 -070010292 if (!animating && mAppTransitionRunning) {
10293 // We have finished the animation of an app transition. To do
10294 // this, we have delayed a lot of operations like showing and
10295 // hiding apps, moving apps in Z-order, etc. The app token list
10296 // reflects the correct Z-order, but the window list may now
10297 // be out of sync with it. So here we will just rebuild the
10298 // entire app window list. Fun!
10299 mAppTransitionRunning = false;
10300 // Clear information about apps that were moving.
10301 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010302
Dianne Hackborna8f60182009-09-01 19:01:50 -070010303 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010304 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010305 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010306 moveInputMethodWindowsIfNeededLocked(false);
10307 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010308 // Since the window list has been rebuilt, focus might
10309 // have to be recomputed since the actual order of windows
10310 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010311 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010313
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010314 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010315 // At this point, there was a window with a wallpaper that
10316 // was force hiding other windows behind it, but now it
10317 // is going away. This may be simple -- just animate
10318 // away the wallpaper and its window -- or it may be
10319 // hard -- the wallpaper now needs to be shown behind
10320 // something that was hidden.
10321 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010322 if (mLowerWallpaperTarget != null
10323 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010324 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010325 "wallpaperForceHiding changed with lower="
10326 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010327 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010328 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10329 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10330 if (mLowerWallpaperTarget.mAppToken.hidden) {
10331 // The lower target has become hidden before we
10332 // actually started the animation... let's completely
10333 // re-evaluate everything.
10334 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010335 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010336 }
10337 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010338 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010339 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010340 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010341 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010342 + " NEW: " + mWallpaperTarget
10343 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010344 if (mLowerWallpaperTarget == null) {
10345 // Whoops, we don't need a special wallpaper animation.
10346 // Clear them out.
10347 forceHiding = false;
10348 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010349 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010350 if (w.mSurface != null) {
10351 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010352 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010353 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010354 forceHiding = true;
10355 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10356 if (!w.mAnimating) {
10357 // We set the animation above so it
10358 // is not yet running.
10359 w.clearAnimation();
10360 }
10361 }
10362 }
10363 }
10364 }
10365 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010366
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010367 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10368 if (DEBUG_WALLPAPER) Slog.v(TAG,
10369 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10370 + windowDetachedWallpaper);
10371 mWindowDetachedWallpaper = windowDetachedWallpaper;
10372 wallpaperMayChange = true;
10373 }
10374
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010375 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010376 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010377 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010378 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010379 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010380
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010381 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010382 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010383 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010384 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010385 assignLayersLocked();
10386 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010387 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010388 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010389 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010390 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010391
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010392 if (mFocusMayChange) {
10393 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010394 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10395 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010396 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010397 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010398 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010399 }
10400
10401 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010402 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010404
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010405 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10406 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010407 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010408
10409 // THIRD LOOP: Update the surfaces of all windows.
10410
10411 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10412
10413 boolean obscured = false;
10414 boolean blurring = false;
10415 boolean dimming = false;
10416 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010417 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010418 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010419
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010420 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010422 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010423 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010424
10425 boolean displayed = false;
10426 final WindowManager.LayoutParams attrs = w.mAttrs;
10427 final int attrFlags = attrs.flags;
10428
10429 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010430 // XXX NOTE: The logic here could be improved. We have
10431 // the decision about whether to resize a window separated
10432 // from whether to hide the surface. This can cause us to
10433 // resize a surface even if we are going to hide it. You
10434 // can see this by (1) holding device in landscape mode on
10435 // home screen; (2) tapping browser icon (device will rotate
10436 // to landscape; (3) tap home. The wallpaper will be resized
10437 // in step 2 but then immediately hidden, causing us to
10438 // have to resize and then redraw it again in step 3. It
10439 // would be nice to figure out how to avoid this, but it is
10440 // difficult because we do need to resize surfaces in some
10441 // cases while they are hidden such as when first showing a
10442 // window.
10443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010444 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010445 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 TAG, "Placing surface #" + i + " " + w.mSurface
10447 + ": new=" + w.mShownFrame + ", old="
10448 + w.mLastShownFrame);
10449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010450 int width, height;
10451 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 // for a scaled surface, we just want to use
10453 // the requested size.
10454 width = w.mRequestedWidth;
10455 height = w.mRequestedHeight;
10456 w.mLastRequestedWidth = width;
10457 w.mLastRequestedHeight = height;
10458 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 width = w.mShownFrame.width();
10461 height = w.mShownFrame.height();
10462 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 }
10464
Jeff Brownfbae7222011-01-23 13:07:25 -080010465 if (w.mSurface != null) {
10466 if (w.mSurfaceX != w.mShownFrame.left
10467 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010468 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010469 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010470 "POS " + w.mShownFrame.left
10471 + ", " + w.mShownFrame.top, null);
10472 w.mSurfaceX = w.mShownFrame.left;
10473 w.mSurfaceY = w.mShownFrame.top;
10474 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10475 } catch (RuntimeException e) {
10476 Slog.w(TAG, "Error positioning surface of " + w
10477 + " pos=(" + w.mShownFrame.left
10478 + "," + w.mShownFrame.top + ")", e);
10479 if (!recoveringMemory) {
10480 reclaimSomeSurfaceMemoryLocked(w, "position");
10481 }
10482 }
10483 }
10484
10485 if (width < 1) {
10486 width = 1;
10487 }
10488 if (height < 1) {
10489 height = 1;
10490 }
10491
10492 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10493 try {
10494 if (SHOW_TRANSACTIONS) logSurface(w,
10495 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010496 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010497 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010498 w.mSurfaceW = width;
10499 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010500 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 } catch (RuntimeException e) {
10502 // If something goes wrong with the surface (such
10503 // as running out of memory), don't take down the
10504 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010505 Slog.e(TAG, "Error resizing surface of " + w
10506 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 if (!recoveringMemory) {
10508 reclaimSomeSurfaceMemoryLocked(w, "size");
10509 }
10510 }
10511 }
10512 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010513
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010514 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 w.mContentInsetsChanged =
10516 !w.mLastContentInsets.equals(w.mContentInsets);
10517 w.mVisibleInsetsChanged =
10518 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010519 boolean configChanged =
10520 w.mConfiguration != mCurConfiguration
10521 && (w.mConfiguration == null
10522 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010523 if (DEBUG_CONFIGURATION && configChanged) {
10524 Slog.v(TAG, "Win " + w + " config changed: "
10525 + mCurConfiguration);
10526 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010527 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010528 + ": configChanged=" + configChanged
10529 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010530 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10531 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010533 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010534 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010535 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010536 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10537 Slog.v(TAG, "Resize reasons: "
10538 + "frameChanged=" + frameChanged
10539 + " contentInsetsChanged=" + w.mContentInsetsChanged
10540 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10541 + " surfaceResized=" + w.mSurfaceResized
10542 + " configChanged=" + configChanged);
10543 }
10544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010545 w.mLastFrame.set(w.mFrame);
10546 w.mLastContentInsets.set(w.mContentInsets);
10547 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010548 // If the screen is currently frozen, then keep
10549 // it frozen until this window draws at its new
10550 // orientation.
10551 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010552 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010553 "Resizing while display frozen: " + w);
10554 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010555 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010556 mWindowsFreezingScreen = true;
10557 // XXX should probably keep timeout from
10558 // when we first froze the display.
10559 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10560 mH.sendMessageDelayed(mH.obtainMessage(
10561 H.WINDOW_FREEZE_TIMEOUT), 2000);
10562 }
10563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010564 // If the orientation is changing, then we need to
10565 // hold off on unfreezing the display until this
10566 // window has been redrawn; to do that, we need
10567 // to go through the process of getting informed
10568 // by the application when it has finished drawing.
10569 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010570 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010571 "Orientation start waiting for draw in "
10572 + w + ", surface " + w.mSurface);
10573 w.mDrawPending = true;
10574 w.mCommitDrawPending = false;
10575 w.mReadyToShow = false;
10576 if (w.mAppToken != null) {
10577 w.mAppToken.allDrawn = false;
10578 }
10579 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010580 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 "Resizing window " + w + " to " + w.mFrame);
10582 mResizingWindows.add(w);
10583 } else if (w.mOrientationChanging) {
10584 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010585 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010586 "Orientation not waiting for draw in "
10587 + w + ", surface " + w.mSurface);
10588 w.mOrientationChanging = false;
10589 }
10590 }
10591 }
10592
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010593 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 if (!w.mLastHidden) {
10595 //dump();
10596 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010597 if (SHOW_TRANSACTIONS) logSurface(w,
10598 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010600 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 try {
10602 w.mSurface.hide();
10603 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010604 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010605 }
10606 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010607 }
10608 // If we are waiting for this window to handle an
10609 // orientation change, well, it is hidden, so
10610 // doesn't really matter. Note that this does
10611 // introduce a potential glitch if the window
10612 // becomes unhidden before it has drawn for the
10613 // new orientation.
10614 if (w.mOrientationChanging) {
10615 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010616 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010617 "Orientation change skips hidden " + w);
10618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010619 } else if (w.mLastLayer != w.mAnimLayer
10620 || w.mLastAlpha != w.mShownAlpha
10621 || w.mLastDsDx != w.mDsDx
10622 || w.mLastDtDx != w.mDtDx
10623 || w.mLastDsDy != w.mDsDy
10624 || w.mLastDtDy != w.mDtDy
10625 || w.mLastHScale != w.mHScale
10626 || w.mLastVScale != w.mVScale
10627 || w.mLastHidden) {
10628 displayed = true;
10629 w.mLastAlpha = w.mShownAlpha;
10630 w.mLastLayer = w.mAnimLayer;
10631 w.mLastDsDx = w.mDsDx;
10632 w.mLastDtDx = w.mDtDx;
10633 w.mLastDsDy = w.mDsDy;
10634 w.mLastDtDy = w.mDtDy;
10635 w.mLastHScale = w.mHScale;
10636 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010637 if (SHOW_TRANSACTIONS) logSurface(w,
10638 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010639 + " matrix=[" + (w.mDsDx*w.mHScale)
10640 + "," + (w.mDtDx*w.mVScale)
10641 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010642 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010643 if (w.mSurface != null) {
10644 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010645 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010646 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010647 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010648 w.mSurface.setLayer(w.mAnimLayer);
10649 w.mSurface.setMatrix(
10650 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10651 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10652 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010653 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010654 if (!recoveringMemory) {
10655 reclaimSomeSurfaceMemoryLocked(w, "update");
10656 }
10657 }
10658 }
10659
10660 if (w.mLastHidden && !w.mDrawPending
10661 && !w.mCommitDrawPending
10662 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010663 if (SHOW_TRANSACTIONS) logSurface(w,
10664 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010665 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 + " during relayout");
10667 if (showSurfaceRobustlyLocked(w)) {
10668 w.mHasDrawn = true;
10669 w.mLastHidden = false;
10670 } else {
10671 w.mOrientationChanging = false;
10672 }
10673 }
10674 if (w.mSurface != null) {
10675 w.mToken.hasVisible = true;
10676 }
10677 } else {
10678 displayed = true;
10679 }
10680
10681 if (displayed) {
10682 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010683 if (attrs.width == LayoutParams.MATCH_PARENT
10684 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010685 covered = true;
10686 }
10687 }
10688 if (w.mOrientationChanging) {
10689 if (w.mDrawPending || w.mCommitDrawPending) {
10690 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010691 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010692 "Orientation continue waiting for draw in " + w);
10693 } else {
10694 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010695 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010696 "Orientation change complete in " + w);
10697 }
10698 }
10699 w.mToken.hasVisible = true;
10700 }
10701 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010702 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010703 "Orientation change skips hidden " + w);
10704 w.mOrientationChanging = false;
10705 }
10706
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010707 if (w.mContentChanged) {
10708 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10709 w.mContentChanged = false;
10710 }
10711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010712 final boolean canBeSeen = w.isDisplayedLw();
10713
10714 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10715 focusDisplayed = true;
10716 }
10717
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010718 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010720 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010721 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010722 if (w.mSurface != null) {
10723 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10724 holdScreen = w.mSession;
10725 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010726 if (!syswin && w.mAttrs.screenBrightness >= 0
10727 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010728 screenBrightness = w.mAttrs.screenBrightness;
10729 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010730 if (!syswin && w.mAttrs.buttonBrightness >= 0
10731 && buttonBrightness < 0) {
10732 buttonBrightness = w.mAttrs.buttonBrightness;
10733 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010734 if (canBeSeen
10735 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10736 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10737 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010738 syswin = true;
10739 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010740 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010741
Dianne Hackborn25994b42009-09-04 14:21:19 -070010742 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10743 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010744 // This window completely covers everything behind it,
10745 // so we want to leave all of them as unblurred (for
10746 // performance reasons).
10747 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010748 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010749 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010750 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010751 obscured = true;
10752 if (mBackgroundFillerSurface == null) {
10753 try {
10754 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010755 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010756 0, dw, dh,
10757 PixelFormat.OPAQUE,
10758 Surface.FX_SURFACE_NORMAL);
10759 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010760 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010761 }
10762 }
10763 try {
10764 mBackgroundFillerSurface.setPosition(0, 0);
10765 mBackgroundFillerSurface.setSize(dw, dh);
10766 // Using the same layer as Dim because they will never be shown at the
10767 // same time.
10768 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10769 mBackgroundFillerSurface.show();
10770 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010771 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010772 }
10773 backgroundFillerShown = true;
10774 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010775 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010776 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010777 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010778 + ": blurring=" + blurring
10779 + " obscured=" + obscured
10780 + " displayed=" + displayed);
10781 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10782 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010783 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010784 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010785 if (mDimAnimator == null) {
10786 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010787 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010788 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010789 mDimAnimator.updateParameters(mContext.getResources(),
10790 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010792 }
10793 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10794 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010795 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010798 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010799 + mBlurSurface + ": CREATE");
10800 try {
Romain Guy06882f82009-06-10 13:36:04 -070010801 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010802 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010803 -1, 16, 16,
10804 PixelFormat.OPAQUE,
10805 Surface.FX_SURFACE_BLUR);
10806 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010807 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010808 }
10809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010811 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10812 + mBlurSurface + ": pos=(0,0) (" +
10813 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010814 mBlurSurface.setPosition(0, 0);
10815 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010816 mBlurSurface.setLayer(w.mAnimLayer-2);
10817 if (!mBlurShown) {
10818 try {
10819 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10820 + mBlurSurface + ": SHOW");
10821 mBlurSurface.show();
10822 } catch (RuntimeException e) {
10823 Slog.w(TAG, "Failure showing blur surface", e);
10824 }
10825 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010826 }
10827 }
10828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010829 }
10830 }
10831 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010832
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010833 if (obscuredChanged && mWallpaperTarget == w) {
10834 // This is the wallpaper target and its obscured state
10835 // changed... make sure the current wallaper's visibility
10836 // has been updated accordingly.
10837 updateWallpaperVisibilityLocked();
10838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010839 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010840
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010841 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10842 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010843 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010844 try {
10845 mBackgroundFillerSurface.hide();
10846 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010847 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010848 }
10849 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010850
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010851 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010852 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10853 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010854 }
Romain Guy06882f82009-06-10 13:36:04 -070010855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010856 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010857 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010858 + ": HIDE");
10859 try {
10860 mBlurSurface.hide();
10861 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010862 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010863 }
10864 mBlurShown = false;
10865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010867 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010868 }
10869
10870 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010871
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010872 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10873
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010874 if (mWatermark != null) {
10875 mWatermark.drawIfNeeded();
10876 }
10877
Joe Onorato8a9b2202010-02-26 18:56:32 -080010878 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010879 "With display frozen, orientationChangeComplete="
10880 + orientationChangeComplete);
10881 if (orientationChangeComplete) {
10882 if (mWindowsFreezingScreen) {
10883 mWindowsFreezingScreen = false;
10884 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10885 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010886 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010887 }
Romain Guy06882f82009-06-10 13:36:04 -070010888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010889 i = mResizingWindows.size();
10890 if (i > 0) {
10891 do {
10892 i--;
10893 WindowState win = mResizingWindows.get(i);
10894 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010895 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10896 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010897 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010898 boolean configChanged =
10899 win.mConfiguration != mCurConfiguration
10900 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010901 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10902 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10903 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010904 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010905 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010906 + " / " + mCurConfiguration + " / 0x"
10907 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010908 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010909 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010910 win.mClient.resized(win.mFrame.width(),
10911 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010912 win.mLastVisibleInsets, win.mDrawPending,
10913 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010914 win.mContentInsetsChanged = false;
10915 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010916 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010917 } catch (RemoteException e) {
10918 win.mOrientationChanging = false;
10919 }
10920 } while (i > 0);
10921 mResizingWindows.clear();
10922 }
Romain Guy06882f82009-06-10 13:36:04 -070010923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010925 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010926 i = mDestroySurface.size();
10927 if (i > 0) {
10928 do {
10929 i--;
10930 WindowState win = mDestroySurface.get(i);
10931 win.mDestroying = false;
10932 if (mInputMethodWindow == win) {
10933 mInputMethodWindow = null;
10934 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010935 if (win == mWallpaperTarget) {
10936 wallpaperDestroyed = true;
10937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010938 win.destroySurfaceLocked();
10939 } while (i > 0);
10940 mDestroySurface.clear();
10941 }
10942
10943 // Time to remove any exiting tokens?
10944 for (i=mExitingTokens.size()-1; i>=0; i--) {
10945 WindowToken token = mExitingTokens.get(i);
10946 if (!token.hasVisible) {
10947 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010948 if (token.windowType == TYPE_WALLPAPER) {
10949 mWallpaperTokens.remove(token);
10950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010951 }
10952 }
10953
10954 // Time to remove any exiting applications?
10955 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10956 AppWindowToken token = mExitingAppTokens.get(i);
10957 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010958 // Make sure there is no animation running on this token,
10959 // so any windows associated with it will be removed as
10960 // soon as their animations are complete
10961 token.animation = null;
10962 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010963 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10964 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010965 mAppTokens.remove(token);
10966 mExitingAppTokens.remove(i);
10967 }
10968 }
10969
Dianne Hackborna8f60182009-09-01 19:01:50 -070010970 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010971
Dianne Hackborna8f60182009-09-01 19:01:50 -070010972 if (!animating && mAppTransitionRunning) {
10973 // We have finished the animation of an app transition. To do
10974 // this, we have delayed a lot of operations like showing and
10975 // hiding apps, moving apps in Z-order, etc. The app token list
10976 // reflects the correct Z-order, but the window list may now
10977 // be out of sync with it. So here we will just rebuild the
10978 // entire app window list. Fun!
10979 mAppTransitionRunning = false;
10980 needRelayout = true;
10981 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010982 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010983 // Clear information about apps that were moving.
10984 mToBottomApps.clear();
10985 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 if (focusDisplayed) {
10988 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10989 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010990 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010991 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010992 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010993 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010994 requestAnimationLocked(0);
10995 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010996 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10997 }
Jeff Browneb857f12010-07-16 10:06:33 -070010998
Jeff Brown3a22cd92011-01-21 13:59:04 -080010999 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080011000 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070011001
Jeff Brown8e03b752010-06-13 19:16:55 -070011002 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080011003 if (!mDisplayFrozen) {
11004 if (screenBrightness < 0 || screenBrightness > 1.0f) {
11005 mPowerManager.setScreenBrightnessOverride(-1);
11006 } else {
11007 mPowerManager.setScreenBrightnessOverride((int)
11008 (screenBrightness * Power.BRIGHTNESS_ON));
11009 }
11010 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
11011 mPowerManager.setButtonBrightnessOverride(-1);
11012 } else {
11013 mPowerManager.setButtonBrightnessOverride((int)
11014 (buttonBrightness * Power.BRIGHTNESS_ON));
11015 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050011016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011017 if (holdScreen != mHoldingScreenOn) {
11018 mHoldingScreenOn = holdScreen;
11019 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
11020 mH.sendMessage(m);
11021 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011022
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011023 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011024 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011025 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
11026 LocalPowerManager.BUTTON_EVENT, true);
11027 mTurnOnScreen = false;
11028 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011029
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011030 if (updateRotation) {
11031 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11032 boolean changed = setRotationUncheckedLocked(
11033 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11034 if (changed) {
11035 sendNewConfiguration();
11036 }
11037 }
11038
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011039 // Check to see if we are now in a state where the screen should
11040 // be enabled, because the window obscured flags have changed.
11041 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011042 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070011043
11044 /**
11045 * Must be called with the main window manager lock held.
11046 */
11047 void setHoldScreenLocked(boolean holding) {
11048 boolean state = mHoldingScreenWakeLock.isHeld();
11049 if (holding != state) {
11050 if (holding) {
11051 mHoldingScreenWakeLock.acquire();
11052 } else {
11053 mPolicy.screenOnStoppedLw();
11054 mHoldingScreenWakeLock.release();
11055 }
11056 }
11057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011058
11059 void requestAnimationLocked(long delay) {
11060 if (!mAnimationPending) {
11061 mAnimationPending = true;
11062 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
11063 }
11064 }
Romain Guy06882f82009-06-10 13:36:04 -070011065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011066 /**
11067 * Have the surface flinger show a surface, robustly dealing with
11068 * error conditions. In particular, if there is not enough memory
11069 * to show the surface, then we will try to get rid of other surfaces
11070 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070011071 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011072 * @return Returns true if the surface was successfully shown.
11073 */
11074 boolean showSurfaceRobustlyLocked(WindowState win) {
11075 try {
11076 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011077 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011078 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011079 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011080 if (DEBUG_VISIBILITY) Slog.v(TAG,
11081 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011082 win.mTurnOnScreen = false;
11083 mTurnOnScreen = true;
11084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011085 }
11086 return true;
11087 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011088 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011089 }
Romain Guy06882f82009-06-10 13:36:04 -070011090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011091 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070011092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011093 return false;
11094 }
Romain Guy06882f82009-06-10 13:36:04 -070011095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011096 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
11097 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070011098
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011099 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011100 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070011101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011102 if (mForceRemoves == null) {
11103 mForceRemoves = new ArrayList<WindowState>();
11104 }
Romain Guy06882f82009-06-10 13:36:04 -070011105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011106 long callingIdentity = Binder.clearCallingIdentity();
11107 try {
11108 // There was some problem... first, do a sanity check of the
11109 // window list to make sure we haven't left any dangling surfaces
11110 // around.
11111 int N = mWindows.size();
11112 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011113 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011114 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011115 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011116 if (ws.mSurface != null) {
11117 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011118 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011119 + ws + " surface=" + ws.mSurface
11120 + " token=" + win.mToken
11121 + " pid=" + ws.mSession.mPid
11122 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011123 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011124 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011125 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011126 ws.mSurface = null;
11127 mForceRemoves.add(ws);
11128 i--;
11129 N--;
11130 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011131 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011132 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011133 + ws + " surface=" + ws.mSurface
11134 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011135 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011136 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011137 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011138 ws.mSurface = null;
11139 leakedSurface = true;
11140 }
11141 }
11142 }
Romain Guy06882f82009-06-10 13:36:04 -070011143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011144 boolean killedApps = false;
11145 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011146 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011147 SparseIntArray pidCandidates = new SparseIntArray();
11148 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011149 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011150 if (ws.mSurface != null) {
11151 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11152 }
11153 }
11154 if (pidCandidates.size() > 0) {
11155 int[] pids = new int[pidCandidates.size()];
11156 for (int i=0; i<pids.length; i++) {
11157 pids[i] = pidCandidates.keyAt(i);
11158 }
11159 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011160 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011161 killedApps = true;
11162 }
11163 } catch (RemoteException e) {
11164 }
11165 }
11166 }
Romain Guy06882f82009-06-10 13:36:04 -070011167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011168 if (leakedSurface || killedApps) {
11169 // We managed to reclaim some memory, so get rid of the trouble
11170 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011171 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011172 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011173 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011174 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011175 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011176 win.mSurface = null;
11177 }
Romain Guy06882f82009-06-10 13:36:04 -070011178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011179 try {
11180 win.mClient.dispatchGetNewSurface();
11181 } catch (RemoteException e) {
11182 }
11183 }
11184 } finally {
11185 Binder.restoreCallingIdentity(callingIdentity);
11186 }
11187 }
Romain Guy06882f82009-06-10 13:36:04 -070011188
Jeff Brown3a22cd92011-01-21 13:59:04 -080011189 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011190 WindowState newFocus = computeFocusedWindowLocked();
11191 if (mCurrentFocus != newFocus) {
11192 // This check makes sure that we don't already have the focus
11193 // change message pending.
11194 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11195 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011196 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011197 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11198 final WindowState oldFocus = mCurrentFocus;
11199 mCurrentFocus = newFocus;
11200 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011202 final WindowState imWindow = mInputMethodWindow;
11203 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011204 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011205 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011206 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11207 mLayoutNeeded = true;
11208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011209 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011210 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011211 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11212 // Client will do the layout, but we need to assign layers
11213 // for handleNewWindowLocked() below.
11214 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011215 }
11216 }
Jeff Brown349703e2010-06-22 01:27:15 -070011217
11218 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11219 // If we defer assigning layers, then the caller is responsible for
11220 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011221 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011222 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011223 return true;
11224 }
11225 return false;
11226 }
Jeff Brown349703e2010-06-22 01:27:15 -070011227
Jeff Brown3a22cd92011-01-21 13:59:04 -080011228 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11229 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011231
11232 private WindowState computeFocusedWindowLocked() {
11233 WindowState result = null;
11234 WindowState win;
11235
11236 int i = mWindows.size() - 1;
11237 int nextAppIndex = mAppTokens.size()-1;
11238 WindowToken nextApp = nextAppIndex >= 0
11239 ? mAppTokens.get(nextAppIndex) : null;
11240
11241 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011242 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011243
Joe Onorato8a9b2202010-02-26 18:56:32 -080011244 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011245 TAG, "Looking for focus: " + i
11246 + " = " + win
11247 + ", flags=" + win.mAttrs.flags
11248 + ", canReceive=" + win.canReceiveKeys());
11249
11250 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011252 // If this window's application has been removed, just skip it.
11253 if (thisApp != null && thisApp.removed) {
11254 i--;
11255 continue;
11256 }
Romain Guy06882f82009-06-10 13:36:04 -070011257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011258 // If there is a focused app, don't allow focus to go to any
11259 // windows below it. If this is an application window, step
11260 // through the app tokens until we find its app.
11261 if (thisApp != null && nextApp != null && thisApp != nextApp
11262 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11263 int origAppIndex = nextAppIndex;
11264 while (nextAppIndex > 0) {
11265 if (nextApp == mFocusedApp) {
11266 // Whoops, we are below the focused app... no focus
11267 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011268 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011269 TAG, "Reached focused app: " + mFocusedApp);
11270 return null;
11271 }
11272 nextAppIndex--;
11273 nextApp = mAppTokens.get(nextAppIndex);
11274 if (nextApp == thisApp) {
11275 break;
11276 }
11277 }
11278 if (thisApp != nextApp) {
11279 // Uh oh, the app token doesn't exist! This shouldn't
11280 // happen, but if it does we can get totally hosed...
11281 // so restart at the original app.
11282 nextAppIndex = origAppIndex;
11283 nextApp = mAppTokens.get(nextAppIndex);
11284 }
11285 }
11286
11287 // Dispatch to this window if it is wants key events.
11288 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011289 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011290 TAG, "Found focus @ " + i + " = " + win);
11291 result = win;
11292 break;
11293 }
11294
11295 i--;
11296 }
11297
11298 return result;
11299 }
11300
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011301 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011302 if (mDisplayFrozen) {
11303 return;
11304 }
Romain Guy06882f82009-06-10 13:36:04 -070011305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011306 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011308 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011309 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011310 if (mFreezeGcPending != 0) {
11311 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011312 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011313 mH.removeMessages(H.FORCE_GC);
11314 Runtime.getRuntime().gc();
11315 mFreezeGcPending = now;
11316 }
11317 } else {
11318 mFreezeGcPending = now;
11319 }
Romain Guy06882f82009-06-10 13:36:04 -070011320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011321 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011322
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011323 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011324
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011325 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11326 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011327 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011328 mAppTransitionReady = true;
11329 }
Romain Guy06882f82009-06-10 13:36:04 -070011330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011331 if (PROFILE_ORIENTATION) {
11332 File file = new File("/data/system/frozen");
11333 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11334 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011335
11336 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011337 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11338 mScreenRotationAnimation.kill();
11339 mScreenRotationAnimation = null;
11340 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011341 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011342 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011343 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011344 }
11345 } else {
11346 Surface.freezeDisplay(0);
11347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011348 }
Romain Guy06882f82009-06-10 13:36:04 -070011349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011350 private void stopFreezingDisplayLocked() {
11351 if (!mDisplayFrozen) {
11352 return;
11353 }
Romain Guy06882f82009-06-10 13:36:04 -070011354
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011355 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11356 return;
11357 }
11358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011359 mDisplayFrozen = false;
11360 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11361 if (PROFILE_ORIENTATION) {
11362 Debug.stopMethodTracing();
11363 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011364
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011365 boolean updateRotation = false;
11366
Dianne Hackborna1111872010-11-23 20:55:11 -080011367 if (CUSTOM_SCREEN_ROTATION) {
11368 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011369 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11370 mTransitionAnimationScale)) {
11371 requestAnimationLocked(0);
11372 } else {
11373 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011374 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011375 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011376 }
11377 } else {
11378 Surface.unfreezeDisplay(0);
11379 }
Romain Guy06882f82009-06-10 13:36:04 -070011380
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011381 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011382
Dianne Hackborn420829e2011-01-28 11:30:35 -080011383 boolean configChanged;
11384
Christopher Tateb696aee2010-04-02 19:08:30 -070011385 // While the display is frozen we don't re-compute the orientation
11386 // to avoid inconsistent states. However, something interesting
11387 // could have actually changed during that time so re-evaluate it
11388 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -080011389 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -070011390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011391 // A little kludge: a lot could have happened while the
11392 // display was frozen, so now that we are coming back we
11393 // do a gc so that any remote references the system
11394 // processes holds on others can be released if they are
11395 // no longer needed.
11396 mH.removeMessages(H.FORCE_GC);
11397 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11398 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011400 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011401
11402 if (updateRotation) {
11403 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -080011404 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011405 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -080011406 }
11407
11408 if (configChanged) {
11409 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011411 }
Romain Guy06882f82009-06-10 13:36:04 -070011412
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011413 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11414 DisplayMetrics dm) {
11415 if (index < tokens.length) {
11416 String str = tokens[index];
11417 if (str != null && str.length() > 0) {
11418 try {
11419 int val = Integer.parseInt(str);
11420 return val;
11421 } catch (Exception e) {
11422 }
11423 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011424 }
11425 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11426 return defDps;
11427 }
11428 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11429 return val;
11430 }
11431
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011432 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011433 final String[] mTokens;
11434 final String mText;
11435 final Paint mTextPaint;
11436 final int mTextWidth;
11437 final int mTextHeight;
11438 final int mTextAscent;
11439 final int mTextDescent;
11440 final int mDeltaX;
11441 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011442
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011443 Surface mSurface;
11444 int mLastDW;
11445 int mLastDH;
11446 boolean mDrawNeeded;
11447
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011448 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011449 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011450 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011451
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011452 if (false) {
11453 Log.i(TAG, "*********************** WATERMARK");
11454 for (int i=0; i<tokens.length; i++) {
11455 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11456 }
11457 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011458
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011459 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011460
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011461 StringBuilder builder = new StringBuilder(32);
11462 int len = mTokens[0].length();
11463 len = len & ~1;
11464 for (int i=0; i<len; i+=2) {
11465 int c1 = mTokens[0].charAt(i);
11466 int c2 = mTokens[0].charAt(i+1);
11467 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11468 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11469 else c1 -= '0';
11470 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11471 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11472 else c2 -= '0';
11473 builder.append((char)(255-((c1*16)+c2)));
11474 }
11475 mText = builder.toString();
11476 if (false) {
11477 Log.i(TAG, "Final text: " + mText);
11478 }
11479
11480 int fontSize = getPropertyInt(tokens, 1,
11481 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11482
11483 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11484 mTextPaint.setTextSize(fontSize);
11485 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11486
11487 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11488 mTextWidth = (int)mTextPaint.measureText(mText);
11489 mTextAscent = fm.ascent;
11490 mTextDescent = fm.descent;
11491 mTextHeight = fm.descent - fm.ascent;
11492
11493 mDeltaX = getPropertyInt(tokens, 2,
11494 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11495 mDeltaY = getPropertyInt(tokens, 3,
11496 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11497 int shadowColor = getPropertyInt(tokens, 4,
11498 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11499 int color = getPropertyInt(tokens, 5,
11500 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11501 int shadowRadius = getPropertyInt(tokens, 6,
11502 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11503 int shadowDx = getPropertyInt(tokens, 8,
11504 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11505 int shadowDy = getPropertyInt(tokens, 9,
11506 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11507
11508 mTextPaint.setColor(color);
11509 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011510
11511 try {
11512 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011513 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011514 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011515 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011516 mSurface.show();
11517 } catch (OutOfResourcesException e) {
11518 }
11519 }
11520
11521 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011522 if (mLastDW != dw || mLastDH != dh) {
11523 mLastDW = dw;
11524 mLastDH = dh;
11525 mSurface.setSize(dw, dh);
11526 mDrawNeeded = true;
11527 }
11528 }
11529
11530 void drawIfNeeded() {
11531 if (mDrawNeeded) {
11532 final int dw = mLastDW;
11533 final int dh = mLastDH;
11534
11535 mDrawNeeded = false;
11536 Rect dirty = new Rect(0, 0, dw, dh);
11537 Canvas c = null;
11538 try {
11539 c = mSurface.lockCanvas(dirty);
11540 } catch (IllegalArgumentException e) {
11541 } catch (OutOfResourcesException e) {
11542 }
11543 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011544 c.drawColor(0, PorterDuff.Mode.CLEAR);
11545
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011546 int deltaX = mDeltaX;
11547 int deltaY = mDeltaY;
11548
11549 // deltaX shouldn't be close to a round fraction of our
11550 // x step, or else things will line up too much.
11551 int div = (dw+mTextWidth)/deltaX;
11552 int rem = (dw+mTextWidth) - (div*deltaX);
11553 int qdelta = deltaX/4;
11554 if (rem < qdelta || rem > (deltaX-qdelta)) {
11555 deltaX += deltaX/3;
11556 }
11557
11558 int y = -mTextHeight;
11559 int x = -mTextWidth;
11560 while (y < (dh+mTextHeight)) {
11561 c.drawText(mText, x, y, mTextPaint);
11562 x += deltaX;
11563 if (x >= dw) {
11564 x -= (dw+mTextWidth);
11565 y += deltaY;
11566 }
11567 }
11568 mSurface.unlockCanvasAndPost(c);
11569 }
11570 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011571 }
11572 }
11573
11574 void createWatermark() {
11575 if (mWatermark != null) {
11576 return;
11577 }
11578
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011579 File file = new File("/system/etc/setup.conf");
11580 FileInputStream in = null;
11581 try {
11582 in = new FileInputStream(file);
11583 DataInputStream ind = new DataInputStream(in);
11584 String line = ind.readLine();
11585 if (line != null) {
11586 String[] toks = line.split("%");
11587 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011588 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011589 }
11590 }
11591 } catch (FileNotFoundException e) {
11592 } catch (IOException e) {
11593 } finally {
11594 if (in != null) {
11595 try {
11596 in.close();
11597 } catch (IOException e) {
11598 }
11599 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011600 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011601 }
11602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011603 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011604 public void statusBarVisibilityChanged(int visibility) {
11605 synchronized (mWindowMap) {
11606 final int N = mWindows.size();
11607 for (int i = 0; i < N; i++) {
11608 WindowState ws = mWindows.get(i);
11609 try {
11610 if (ws.getAttrs().hasSystemUiListeners) {
11611 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11612 }
11613 } catch (RemoteException e) {
11614 // so sorry
11615 }
11616 }
11617 }
11618 }
11619
11620 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011621 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11622 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11623 != PackageManager.PERMISSION_GRANTED) {
11624 pw.println("Permission Denial: can't dump WindowManager from from pid="
11625 + Binder.getCallingPid()
11626 + ", uid=" + Binder.getCallingUid());
11627 return;
11628 }
Romain Guy06882f82009-06-10 13:36:04 -070011629
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011630 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011631 pw.println(" ");
11632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011633 synchronized(mWindowMap) {
11634 pw.println("Current Window Manager state:");
11635 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011636 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011637 pw.print(" Window #"); pw.print(i); pw.print(' ');
11638 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011639 w.dump(pw, " ");
11640 }
11641 if (mInputMethodDialogs.size() > 0) {
11642 pw.println(" ");
11643 pw.println(" Input method dialogs:");
11644 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11645 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011646 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011647 }
11648 }
11649 if (mPendingRemove.size() > 0) {
11650 pw.println(" ");
11651 pw.println(" Remove pending for:");
11652 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11653 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011654 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11655 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011656 w.dump(pw, " ");
11657 }
11658 }
11659 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11660 pw.println(" ");
11661 pw.println(" Windows force removing:");
11662 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11663 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011664 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11665 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011666 w.dump(pw, " ");
11667 }
11668 }
11669 if (mDestroySurface.size() > 0) {
11670 pw.println(" ");
11671 pw.println(" Windows waiting to destroy their surface:");
11672 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11673 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011674 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11675 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011676 w.dump(pw, " ");
11677 }
11678 }
11679 if (mLosingFocus.size() > 0) {
11680 pw.println(" ");
11681 pw.println(" Windows losing focus:");
11682 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11683 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011684 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11685 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011686 w.dump(pw, " ");
11687 }
11688 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011689 if (mResizingWindows.size() > 0) {
11690 pw.println(" ");
11691 pw.println(" Windows waiting to resize:");
11692 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11693 WindowState w = mResizingWindows.get(i);
11694 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11695 pw.print(w); pw.println(":");
11696 w.dump(pw, " ");
11697 }
11698 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011699 if (mSessions.size() > 0) {
11700 pw.println(" ");
11701 pw.println(" All active sessions:");
11702 Iterator<Session> it = mSessions.iterator();
11703 while (it.hasNext()) {
11704 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011705 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011706 s.dump(pw, " ");
11707 }
11708 }
11709 if (mTokenMap.size() > 0) {
11710 pw.println(" ");
11711 pw.println(" All tokens:");
11712 Iterator<WindowToken> it = mTokenMap.values().iterator();
11713 while (it.hasNext()) {
11714 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011715 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011716 token.dump(pw, " ");
11717 }
11718 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011719 if (mWallpaperTokens.size() > 0) {
11720 pw.println(" ");
11721 pw.println(" Wallpaper tokens:");
11722 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11723 WindowToken token = mWallpaperTokens.get(i);
11724 pw.print(" Wallpaper #"); pw.print(i);
11725 pw.print(' '); pw.print(token); pw.println(':');
11726 token.dump(pw, " ");
11727 }
11728 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011729 if (mAppTokens.size() > 0) {
11730 pw.println(" ");
11731 pw.println(" Application tokens in Z order:");
11732 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011733 pw.print(" App #"); pw.print(i); pw.print(": ");
11734 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011735 }
11736 }
11737 if (mFinishedStarting.size() > 0) {
11738 pw.println(" ");
11739 pw.println(" Finishing start of application tokens:");
11740 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11741 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011742 pw.print(" Finished Starting #"); pw.print(i);
11743 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011744 token.dump(pw, " ");
11745 }
11746 }
11747 if (mExitingTokens.size() > 0) {
11748 pw.println(" ");
11749 pw.println(" Exiting tokens:");
11750 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11751 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011752 pw.print(" Exiting #"); pw.print(i);
11753 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011754 token.dump(pw, " ");
11755 }
11756 }
11757 if (mExitingAppTokens.size() > 0) {
11758 pw.println(" ");
11759 pw.println(" Exiting application tokens:");
11760 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11761 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011762 pw.print(" Exiting App #"); pw.print(i);
11763 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011764 token.dump(pw, " ");
11765 }
11766 }
11767 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011768 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11769 pw.print(" mLastFocus="); pw.println(mLastFocus);
11770 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11771 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11772 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011773 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011774 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11775 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11776 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11777 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011778 if (mWindowDetachedWallpaper != null) {
11779 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11780 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011781 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11782 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11783 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011784 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11785 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11786 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11787 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011788 if (mDimAnimator != null) {
11789 mDimAnimator.printTo(pw);
11790 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011791 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011792 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011793 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011794 pw.print(mInputMethodAnimLayerAdjustment);
11795 pw.print(" mWallpaperAnimLayerAdjustment=");
11796 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011797 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11798 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011799 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11800 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011801 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11802 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011803 pw.print(" mRotation="); pw.print(mRotation);
11804 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11805 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011806 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11807 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011808 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11809 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11810 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11811 pw.print(" mNextAppTransition=0x");
11812 pw.print(Integer.toHexString(mNextAppTransition));
11813 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011814 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011815 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011816 if (mNextAppTransitionPackage != null) {
11817 pw.print(" mNextAppTransitionPackage=");
11818 pw.print(mNextAppTransitionPackage);
11819 pw.print(", mNextAppTransitionEnter=0x");
11820 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11821 pw.print(", mNextAppTransitionExit=0x");
11822 pw.print(Integer.toHexString(mNextAppTransitionExit));
11823 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011824 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11825 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11826 if (mOpeningApps.size() > 0) {
11827 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11828 }
11829 if (mClosingApps.size() > 0) {
11830 pw.print(" mClosingApps="); pw.println(mClosingApps);
11831 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011832 if (mToTopApps.size() > 0) {
11833 pw.print(" mToTopApps="); pw.println(mToTopApps);
11834 }
11835 if (mToBottomApps.size() > 0) {
11836 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11837 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011838 if (mDisplay != null) {
11839 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11840 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11841 } else {
11842 pw.println(" NO DISPLAY");
11843 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011844 pw.println(" Policy:");
11845 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011846 }
11847 }
11848
Jeff Brown349703e2010-06-22 01:27:15 -070011849 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011850 public void monitor() {
11851 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011852 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011853 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011854
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011855 /**
11856 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011857 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011858 */
11859 private static class DimAnimator {
11860 Surface mDimSurface;
11861 boolean mDimShown = false;
11862 float mDimCurrentAlpha;
11863 float mDimTargetAlpha;
11864 float mDimDeltaPerMs;
11865 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011866
11867 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011868
11869 DimAnimator (SurfaceSession session) {
11870 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011871 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011872 + mDimSurface + ": CREATE");
11873 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011874 mDimSurface = new Surface(session, 0,
11875 "DimSurface",
11876 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011877 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011878 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011879 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011880 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011881 }
11882 }
11883 }
11884
11885 /**
11886 * Show the dim surface.
11887 */
11888 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011889 if (!mDimShown) {
11890 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11891 dw + "x" + dh + ")");
11892 mDimShown = true;
11893 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011894 mLastDimWidth = dw;
11895 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011896 mDimSurface.setPosition(0, 0);
11897 mDimSurface.setSize(dw, dh);
11898 mDimSurface.show();
11899 } catch (RuntimeException e) {
11900 Slog.w(TAG, "Failure showing dim surface", e);
11901 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011902 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11903 mLastDimWidth = dw;
11904 mLastDimHeight = dh;
11905 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011906 }
11907 }
11908
11909 /**
11910 * Set's the dim surface's layer and update dim parameters that will be used in
11911 * {@link updateSurface} after all windows are examined.
11912 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011913 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011914 mDimSurface.setLayer(w.mAnimLayer-1);
11915
11916 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011917 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011918 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011919 if (mDimTargetAlpha != target) {
11920 // If the desired dim level has changed, then
11921 // start an animation to it.
11922 mLastDimAnimTime = currentTime;
11923 long duration = (w.mAnimating && w.mAnimation != null)
11924 ? w.mAnimation.computeDurationHint()
11925 : DEFAULT_DIM_DURATION;
11926 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011927 TypedValue tv = new TypedValue();
11928 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11929 tv, true);
11930 if (tv.type == TypedValue.TYPE_FRACTION) {
11931 duration = (long)tv.getFraction((float)duration, (float)duration);
11932 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11933 && tv.type <= TypedValue.TYPE_LAST_INT) {
11934 duration = tv.data;
11935 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011936 }
11937 if (duration < 1) {
11938 // Don't divide by zero
11939 duration = 1;
11940 }
11941 mDimTargetAlpha = target;
11942 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11943 }
11944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011945
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011946 /**
11947 * Updating the surface's alpha. Returns true if the animation continues, or returns
11948 * false when the animation is finished and the dim surface is hidden.
11949 */
11950 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11951 if (!dimming) {
11952 if (mDimTargetAlpha != 0) {
11953 mLastDimAnimTime = currentTime;
11954 mDimTargetAlpha = 0;
11955 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11956 }
11957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011958
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011959 boolean animating = false;
11960 if (mLastDimAnimTime != 0) {
11961 mDimCurrentAlpha += mDimDeltaPerMs
11962 * (currentTime-mLastDimAnimTime);
11963 boolean more = true;
11964 if (displayFrozen) {
11965 // If the display is frozen, there is no reason to animate.
11966 more = false;
11967 } else if (mDimDeltaPerMs > 0) {
11968 if (mDimCurrentAlpha > mDimTargetAlpha) {
11969 more = false;
11970 }
11971 } else if (mDimDeltaPerMs < 0) {
11972 if (mDimCurrentAlpha < mDimTargetAlpha) {
11973 more = false;
11974 }
11975 } else {
11976 more = false;
11977 }
11978
11979 // Do we need to continue animating?
11980 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011981 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011982 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11983 mLastDimAnimTime = currentTime;
11984 mDimSurface.setAlpha(mDimCurrentAlpha);
11985 animating = true;
11986 } else {
11987 mDimCurrentAlpha = mDimTargetAlpha;
11988 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011989 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011990 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11991 mDimSurface.setAlpha(mDimCurrentAlpha);
11992 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011993 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011994 + ": HIDE");
11995 try {
11996 mDimSurface.hide();
11997 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011998 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011999 }
12000 mDimShown = false;
12001 }
12002 }
12003 }
12004 return animating;
12005 }
12006
12007 public void printTo(PrintWriter pw) {
12008 pw.print(" mDimShown="); pw.print(mDimShown);
12009 pw.print(" current="); pw.print(mDimCurrentAlpha);
12010 pw.print(" target="); pw.print(mDimTargetAlpha);
12011 pw.print(" delta="); pw.print(mDimDeltaPerMs);
12012 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
12013 }
12014 }
12015
12016 /**
12017 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
12018 * This is used for opening/closing transition for apps in compatible mode.
12019 */
12020 private static class FadeInOutAnimation extends Animation {
12021 int mWidth;
12022 boolean mFadeIn;
12023
12024 public FadeInOutAnimation(boolean fadeIn) {
12025 setInterpolator(new AccelerateInterpolator());
12026 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
12027 mFadeIn = fadeIn;
12028 }
12029
12030 @Override
12031 protected void applyTransformation(float interpolatedTime, Transformation t) {
12032 float x = interpolatedTime;
12033 if (!mFadeIn) {
12034 x = 1.0f - x; // reverse the interpolation for fade out
12035 }
12036 if (x < 0.5) {
12037 // move the window out of the screen.
12038 t.getMatrix().setTranslate(mWidth, 0);
12039 } else {
12040 t.getMatrix().setTranslate(0, 0);// show
12041 t.setAlpha((x - 0.5f) * 2);
12042 }
12043 }
12044
12045 @Override
12046 public void initialize(int width, int height, int parentWidth, int parentHeight) {
12047 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
12048 mWidth = width;
12049 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012050
12051 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070012052 public int getZAdjustment() {
12053 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012054 }
12055 }
Jeff Brown2992ea72011-01-28 22:04:14 -080012056
12057 public interface OnHardKeyboardStatusChangeListener {
12058 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
12059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012060}